dolibarr 19.0.3
categories_list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2023 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2011-2024 Alexandre Spangaro <aspangaro@easya.solutions>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountancycategory.class.php';
35
36// Load translation files required by the page
37$langs->loadLangs(array("errors", "admin", "companies", "resource", "holiday", "accountancy", "hrm"));
38
39$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
40$confirm = GETPOST('confirm', 'alpha');
41$id = 32;
42$rowid = GETPOST('rowid', 'alpha');
43$code = GETPOST('code', 'alpha');
44
45// Security access
46if (!$user->hasRight('accounting', 'chartofaccount')) {
48}
49
50$acts[0] = "activate";
51$acts[1] = "disable";
52$actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
53$actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
54
55$listoffset = GETPOST('listoffset', 'alpha');
56$listlimit = GETPOST('listlimit', 'int') > 0 ? GETPOST('listlimit', 'int') : 1000;
57
58$sortfield = GETPOST("sortfield", 'aZ09comma');
59$sortorder = GETPOST("sortorder", 'aZ09comma');
60$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
61if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
62 // If $page is not defined, or '' or -1 or if we click on clear filters
63 $page = 0;
64}
65$offset = $listlimit * $page;
66$pageprev = $page - 1;
67$pagenext = $page + 1;
68
69$search_country_id = GETPOST('search_country_id', 'int');
70
71// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
72$hookmanager->initHooks(array('admin'));
73
74// This page is a generic page to edit dictionaries
75// Put here declaration of dictionaries properties
76
77// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
78$taborder = array(32);
79
80// Name of SQL tables of dictionaries
81$tabname = array();
82$tabname[32] = MAIN_DB_PREFIX."c_accounting_category";
83
84// Dictionary labels
85$tablib = array();
86$tablib[32] = "DictionaryAccountancyCategory";
87
88// Requests to extract data
89$tabsql = array();
90$tabsql[32] = "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.category_type, a.formula, a.position as position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1";
91
92// Criteria to sort dictionaries
93$tabsqlsort = array();
94$tabsqlsort[32] = "position ASC";
95
96// Name of the fields in the result of select to display the dictionary
97$tabfield = array();
98$tabfield[32] = "code,label,range_account,category_type,formula,position,country";
99
100// Name of editing fields for record modification
101$tabfieldvalue = array();
102$tabfieldvalue[32] = "code,label,range_account,category_type,formula,position,country_id";
103
104// Name of the fields in the table for inserting a record
105$tabfieldinsert = array();
106$tabfieldinsert[32] = "code,label,range_account,category_type,formula,position,fk_country";
107
108// Name of the rowid if the field is not of type autoincrement
109// Example: "" if id field is "rowid" and has autoincrement on
110// "nameoffield" if id field is not "rowid" or has not autoincrement on
111$tabrowid = array();
112$tabrowid[32] = "";
113
114// Condition to show dictionary in setup page
115$tabcond = array();
116$tabcond[32] = isModEnabled('accounting');
117
118// List of help for fields
119$tabhelp = array();
120$tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"), 'category_type'=>$langs->trans("SetToYesIfGroupIsComputationOfOtherGroups"), 'formula'=>$langs->trans("EnterCalculationRuleIfPreviousFieldIsYes"));
121
122// List of check for fields (NOT USED YET)
123$tabfieldcheck = array();
124$tabfieldcheck[32] = array();
125
126// Complete all arrays with entries found into modules
127complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
128
129$accountingcategory = new AccountancyCategory($db);
130
131
132/*
133 * Actions
134 */
135
136if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
137 $search_country_id = '';
138}
139
140// Actions add or modify an entry into a dictionary
141if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) {
142 $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
143 $listfieldinsert = explode(',', $tabfieldinsert[$id]);
144 $listfieldmodify = explode(',', $tabfieldinsert[$id]);
145 $listfieldvalue = explode(',', $tabfieldvalue[$id]);
146
147 // Check that all fields are filled
148 $ok = 1;
149 foreach ($listfield as $f => $value) {
150 if ($value == 'formula' && !GETPOST('formula')) {
151 continue;
152 }
153 if ($value == 'range_account' && !GETPOST('range_account')) {
154 continue;
155 }
156 if (($value == 'country' || $value == 'country_id') && GETPOST('country_id')) {
157 continue;
158 }
159 if (!GETPOSTISSET($value) || GETPOST($value) == '') {
160 $ok = 0;
161 $fieldnamekey = $listfield[$f];
162 // We take translate key of field
163 if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
164 $fieldnamekey = 'Label';
165 }
166 if ($fieldnamekey == 'code') {
167 $fieldnamekey = 'Code';
168 }
169 if ($fieldnamekey == 'note') {
170 $fieldnamekey = 'Note';
171 }
172 if ($fieldnamekey == 'type') {
173 $fieldnamekey = 'Type';
174 }
175 if ($fieldnamekey == 'position') {
176 $fieldnamekey = 'Position';
177 }
178 if ($fieldnamekey == 'category_type') {
179 $fieldnamekey = 'Calculated';
180 }
181 if ($fieldnamekey == 'country') {
182 $fieldnamekey = 'Country';
183 }
184
185 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
186 }
187 }
188 if (GETPOSTISSET("code")) {
189 if (GETPOST("code") == '0') {
190 $ok = 0;
191 setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
192 }
193 }
194 if (GETPOST('position') && !is_numeric(GETPOST('position', 'alpha'))) {
195 $langs->loadLangs(array("errors"));
196 $ok = 0;
197 setEventMessages($langs->transnoentities('ErrorFieldMustBeANumeric', $langs->transnoentities("Position")), null, 'errors');
198 }
199
200 // Si verif ok et action add, on ajoute la ligne
201 if ($ok && GETPOST('actionadd', 'alpha')) {
202 if ($tabrowid[$id]) {
203 // Get free id for insert
204 $newid = 0;
205 $sql = "SELECT MAX(".$tabrowid[$id].") newid from ".$tabname[$id];
206 $result = $db->query($sql);
207 if ($result) {
208 $obj = $db->fetch_object($result);
209 $newid = ($obj->newid + 1);
210 } else {
211 dol_print_error($db);
212 }
213 }
214
215 // Add new entry
216 $sql = "INSERT INTO ".$tabname[$id]." (";
217 // List of fields
218 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
219 $sql .= $tabrowid[$id].",";
220 }
221 $sql .= $tabfieldinsert[$id];
222 $sql .= ",active)";
223 $sql .= " VALUES(";
224
225 // List of values
226 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
227 $sql .= $newid.",";
228 }
229 $i = 0;
230 foreach ($listfieldinsert as $f => $value) {
231 if ($value == 'entity') {
232 $_POST[$listfieldvalue[$i]] = $conf->entity;
233 }
234 if ($i) {
235 $sql .= ",";
236 }
237 if (GETPOST($listfieldvalue[$i]) == '' && !$listfieldvalue[$i] == 'formula') {
238 $sql .= "null"; // For vat, we want/accept code = ''
239 } else {
240 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
241 }
242 $i++;
243 }
244 $sql .= ",1)";
245
246 dol_syslog("actionadd", LOG_DEBUG);
247 $result = $db->query($sql);
248 if ($result) { // Add is ok
249 setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
250 $_POST = array('id'=>$id); // Clean $_POST array, we keep only
251 } else {
252 if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
253 setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
254 } else {
255 dol_print_error($db);
256 }
257 }
258 }
259
260 // If check ok and action modify, we modify the line
261 if ($ok && GETPOST('actionmodify', 'alpha')) {
262 if ($tabrowid[$id]) {
263 $rowidcol = $tabrowid[$id];
264 } else {
265 $rowidcol = "rowid";
266 }
267
268 // Modify entry
269 $sql = "UPDATE ".$tabname[$id]." SET ";
270 // Modifie valeur des champs
271 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
272 $sql .= $tabrowid[$id]."=";
273 $sql .= "'".$db->escape($rowid)."', ";
274 }
275 $i = 0;
276 foreach ($listfieldmodify as $field) {
277 if ($field == 'fk_country' && GETPOST('country') > 0) {
278 $_POST[$listfieldvalue[$i]] = GETPOST('country');
279 } elseif ($field == 'entity') {
280 $_POST[$listfieldvalue[$i]] = $conf->entity;
281 }
282 if ($i) {
283 $sql .= ",";
284 }
285 $sql .= $field."=";
286 if (GETPOST($listfieldvalue[$i]) == '' && !$listfieldvalue[$i] == 'range_account') {
287 $sql .= "null"; // For range_account, we want/accept code = ''
288 } else {
289 $sql .= "'".$db->escape(GETPOST($listfieldvalue[$i]))."'";
290 }
291 $i++;
292 }
293 $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
294
295 dol_syslog("actionmodify", LOG_DEBUG);
296 //print $sql;
297 $resql = $db->query($sql);
298 if (!$resql) {
299 setEventMessages($db->error(), null, 'errors');
300 }
301 }
302}
303
304if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
305 if ($tabrowid[$id]) {
306 $rowidcol = $tabrowid[$id];
307 } else {
308 $rowidcol = "rowid";
309 }
310
311 $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
312
313 dol_syslog("delete", LOG_DEBUG);
314 $result = $db->query($sql);
315 if (!$result) {
316 if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
317 setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
318 } else {
319 dol_print_error($db);
320 }
321 }
322}
323
324// activate
325if ($action == $acts[0]) {
326 if ($tabrowid[$id]) {
327 $rowidcol = $tabrowid[$id];
328 } else {
329 $rowidcol = "rowid";
330 }
331
332 if ($rowid) {
333 $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = ".((int) $rowid);
334 } elseif ($code) {
335 $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code = '".$db->escape($code)."'";
336 }
337
338 $result = $db->query($sql);
339 if (!$result) {
340 dol_print_error($db);
341 }
342}
343
344// disable
345if ($action == $acts[1]) {
346 if ($tabrowid[$id]) {
347 $rowidcol = $tabrowid[$id];
348 } else {
349 $rowidcol = "rowid";
350 }
351
352 if ($rowid) {
353 $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = ".((int) $rowid);
354 } elseif ($code) {
355 $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code = '".$db->escape($code)."'";
356 }
357
358 $result = $db->query($sql);
359 if (!$result) {
360 dol_print_error($db);
361 }
362}
363
364// favorite
365if ($action == 'activate_favorite') {
366 if ($tabrowid[$id]) {
367 $rowidcol = $tabrowid[$id];
368 } else {
369 $rowidcol = "rowid";
370 }
371
372 if ($rowid) {
373 $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol." = ".((int) $rowid);
374 } elseif ($code) {
375 $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code = '".$db->escape($code)."'";
376 }
377
378 $result = $db->query($sql);
379 if (!$result) {
380 dol_print_error($db);
381 }
382}
383
384// disable favorite
385if ($action == 'disable_favorite') {
386 if ($tabrowid[$id]) {
387 $rowidcol = $tabrowid[$id];
388 } else {
389 $rowidcol = "rowid";
390 }
391
392 if ($rowid) {
393 $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol." = ".((int) $rowid);
394 } elseif ($code) {
395 $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code = '".$db->escape($code)."'";
396 }
397
398 $result = $db->query($sql);
399 if (!$result) {
400 dol_print_error($db);
401 }
402}
403
404
405/*
406 * View
407 */
408
409$form = new Form($db);
410$formadmin = new FormAdmin($db);
411
412$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
413
414llxHeader('', $langs->trans('DictionaryAccountancyCategory'), $help_url);
415
416$titre = $langs->trans($tablib[$id]);
417$linkback = '';
418$titlepicto = 'setup';
419
420print load_fiche_titre($titre, $linkback, $titlepicto);
421
422print '<span class="opacitymedium">'.$langs->trans("AccountingAccountGroupsDesc", $langs->transnoentitiesnoconv("ByPersonalizedAccountGroups")).'</span><br><br>';
423
424// Confirmation of the deletion of the line
425if ($action == 'delete') {
426 print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id.($search_country_id > 0 ? '&search_country_id='.$search_country_id : ''), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
427}
428
429// Complete search query with sorting criteria
430$sql = $tabsql[$id];
431
432if ($search_country_id > 0) {
433 if (preg_match('/ WHERE /', $sql)) {
434 $sql .= " AND ";
435 } else {
436 $sql .= " WHERE ";
437 }
438 $sql .= " (a.fk_country = ".((int) $search_country_id)." OR a.fk_country = 0)";
439}
440
441// If sort order is "country", we use country_code instead
442if ($sortfield == 'country') {
443 $sortfield = 'country_code';
444}
445if (empty($sortfield)) {
446 $sortfield = 'position';
447}
448
449$sql .= $db->order($sortfield, $sortorder);
450$sql .= $db->plimit($listlimit + 1, $offset);
451
452
453$fieldlist = explode(',', $tabfield[$id]);
454
455$param = '&id='.$id;
456if ($search_country_id > 0) {
457 $param .= '&search_country_id='.urlencode($search_country_id);
458}
459$paramwithsearch = $param;
460if ($sortorder) {
461 $paramwithsearch .= '&sortorder='.urlencode($sortorder);
462}
463if ($sortfield) {
464 $paramwithsearch .= '&sortfield='.urlencode($sortfield);
465}
466if (GETPOST('from', 'alpha')) {
467 $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
468}
469if ($listlimit) {
470 $paramwithsearch .= '&listlimit='.urlencode(GETPOST('listlimit', 'int'));
471}
472print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
473print '<input type="hidden" name="token" value="'.newToken().'">';
474print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
475print '<input type="hidden" name="sortfield" value="'.dol_escape_htmltag($sortfield).'">';
476print '<input type="hidden" name="sortorder" value="'.dol_escape_htmltag($sortorder).'">';
477
478
479print '<div class="div-table-responsive-no-min">';
480print '<table class="noborder centpercent">';
481
482// Form to add a new line
483if ($tabname[$id]) {
484 $fieldlist = explode(',', $tabfield[$id]);
485
486 // Line for title
487 print '<tr class="liste_titre">';
488 // Action column
489 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
490 print '<td></td>';
491 }
492 foreach ($fieldlist as $field => $value) {
493 // Determine le nom du champ par rapport aux noms possibles
494 // dans les dictionnaires de donnees
495 $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
496 $valuetoshow = $langs->trans($valuetoshow); // try to translate
497 $class = "left";
498 if ($fieldlist[$field] == 'type') {
499 if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") {
500 $valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
501 } else {
502 $valuetoshow = $langs->trans("Type");
503 }
504 }
505 if ($fieldlist[$field] == 'code') {
506 $valuetoshow = $langs->trans("Code");
507 $class = 'width75';
508 }
509 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
510 $valuetoshow = $langs->trans("Label");
511 }
512 if ($fieldlist[$field] == 'libelle_facture') {
513 $valuetoshow = $langs->trans("LabelOnDocuments");
514 }
515 if ($fieldlist[$field] == 'country') {
516 $valuetoshow = $langs->trans("Country");
517 }
518 if ($fieldlist[$field] == 'accountancy_code') {
519 $valuetoshow = $langs->trans("AccountancyCode");
520 }
521 if ($fieldlist[$field] == 'accountancy_code_sell') {
522 $valuetoshow = $langs->trans("AccountancyCodeSell");
523 }
524 if ($fieldlist[$field] == 'accountancy_code_buy') {
525 $valuetoshow = $langs->trans("AccountancyCodeBuy");
526 }
527 if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
528 $valuetoshow = $langs->trans("Pcg_version");
529 }
530 if ($fieldlist[$field] == 'range_account') {
531 $valuetoshow = $langs->trans("Comment");
532 $class = 'width75';
533 }
534 if ($fieldlist[$field] == 'category_type') {
535 $valuetoshow = $langs->trans("Calculated");
536 }
537
538 if ($valuetoshow != '') {
539 print '<td class="'.$class.'">';
540 if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
541 print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
542 } elseif (!empty($tabhelp[$id][$value])) {
543 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
544 } else {
545 print $valuetoshow;
546 }
547 print '</td>';
548 }
549 }
550
551 print '<td>';
552 print '<input type="hidden" name="id" value="'.$id.'">';
553 print '</td>';
554 print '<td></td>';
555 // Action column
556 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
557 print '<td></td>';
558 }
559 print '</tr>';
560
561 // Line to enter new values
562 print '<tr class="oddeven nodrag nodrop nohover">';
563
564 // Action column
565 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
566 print '<td></td>';
567 }
568
569 $obj = new stdClass();
570 // If data was already input, we define them in obj to populate input fields.
571 if (GETPOST('actionadd', 'alpha')) {
572 foreach ($fieldlist as $key => $val) {
573 if (GETPOST($val) != '') {
574 $obj->$val = GETPOST($val);
575 }
576 }
577 }
578
579 $tmpaction = 'create';
580 $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
581 $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
582 $error = $hookmanager->error;
583 $errors = $hookmanager->errors;
584
585 if (empty($reshook)) {
586 fieldListAccountingCategories($fieldlist, $obj, $tabname[$id], 'add');
587 }
588
589 print '<td colspan="2" class="right">';
590 print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
591 print '</td>';
592
593 // Action column
594 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
595 print '<td></td>';
596 }
597
598 print "</tr>";
599
600 $colspan = count($fieldlist) + 3;
601 if ($id == 32) {
602 $colspan++;
603 }
604}
605
606print '</table>';
607print '</div>';
608
609print '<div class="div-table-responsive">';
610print '<table class="noborder centpercent">';
611
612// List of available record in database
613dol_syslog("htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
614
615$resql = $db->query($sql);
616if ($resql) {
617 $num = $db->num_rows($resql);
618 $i = 0;
619
620 // There is several pages
621 if ($num > $listlimit) {
622 print '<tr class="none"><td class="right" colspan="'.(2 + count($fieldlist)).'">';
623 print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
624 print '</td></tr>';
625 }
626
627 $filterfound = 0;
628 foreach ($fieldlist as $field => $value) {
629 $showfield = 1; // By defaut
630 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
631 $showfield = 0;
632 }
633 if ($showfield) {
634 if ($value == 'country') {
635 $filterfound++;
636 }
637 }
638 }
639
640 // Title line with search boxes
641 print '<tr class="liste_titre liste_titre_add liste_titre_filter">';
642
643 // Action column
644 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
645 print '<td class="liste_titre center">';
646 if ($filterfound) {
647 $searchpicto = $form->showFilterAndCheckAddButtons(0);
648 print $searchpicto;
649 }
650 print '</td>';
651 }
652
653 $filterfound = 0;
654 foreach ($fieldlist as $field => $value) {
655 $showfield = 1; // By defaut
656
657 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
658 $showfield = 0;
659 }
660
661 if ($showfield) {
662 if ($value == 'country') {
663 print '<td class="liste_titre">';
664 print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
665 print '</td>';
666 $filterfound++;
667 } else {
668 print '<td class="liste_titre"></td>';
669 }
670 }
671 }
672 print '<td class="liste_titre"></td>';
673 print '<td class="liste_titre"></td>';
674 // Action column
675 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
676 print '<td class="liste_titre center">';
677 if ($filterfound) {
678 $searchpicto = $form->showFilterAndCheckAddButtons(0);
679 print $searchpicto;
680 }
681 print '</td>';
682 }
683 print '</tr>';
684
685 // Title of lines
686 print '<tr class="liste_titre">';
687 // Action column
688 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
689 print getTitleFieldOfList('');
690 }
691 foreach ($fieldlist as $field => $value) {
692 // Determines the name of the field in relation to the possible names
693 // in data dictionaries
694 $showfield = 1; // By default
695 $class = "left";
696 $sortable = 1;
697 $valuetoshow = '';
698
699 $valuetoshow = ucfirst($fieldlist[$field]); // By default
700 $valuetoshow = $langs->trans($valuetoshow); // try to translate
701 if ($fieldlist[$field] == 'source') {
702 $valuetoshow = $langs->trans("Contact");
703 }
704 if ($fieldlist[$field] == 'price') {
705 $valuetoshow = $langs->trans("PriceUHT");
706 }
707 if ($fieldlist[$field] == 'taux') {
708 if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") {
709 $valuetoshow = $langs->trans("Rate");
710 } else {
711 $valuetoshow = $langs->trans("Amount");
712 }
713 $class = 'center';
714 }
715 if ($fieldlist[$field] == 'type') {
716 $valuetoshow = $langs->trans("Type");
717 }
718 if ($fieldlist[$field] == 'code') {
719 $valuetoshow = $langs->trans("Code");
720 }
721 if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
722 $valuetoshow = $langs->trans("Label");
723 }
724 if ($fieldlist[$field] == 'country') {
725 $valuetoshow = $langs->trans("Country");
726 }
727 if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
728 $showfield = 0;
729 }
730 if ($fieldlist[$field] == 'accountancy_code') {
731 $valuetoshow = $langs->trans("AccountancyCode");
732 }
733 if ($fieldlist[$field] == 'accountancy_code_sell') {
734 $valuetoshow = $langs->trans("AccountancyCodeSell");
735 $sortable = 0;
736 }
737 if ($fieldlist[$field] == 'accountancy_code_buy') {
738 $valuetoshow = $langs->trans("AccountancyCodeBuy");
739 $sortable = 0;
740 }
741 if ($fieldlist[$field] == 'fk_pcg_version') {
742 $valuetoshow = $langs->trans("Pcg_version");
743 }
744 if ($fieldlist[$field] == 'account_parent') {
745 $valuetoshow = $langs->trans("Accountsparent");
746 }
747 if ($fieldlist[$field] == 'pcg_type') {
748 $valuetoshow = $langs->trans("Pcg_type");
749 }
750 if ($fieldlist[$field] == 'type_template') {
751 $valuetoshow = $langs->trans("TypeOfTemplate");
752 }
753 if ($fieldlist[$field] == 'range_account') {
754 $valuetoshow = $langs->trans("Comment");
755 }
756 if ($fieldlist[$field] == 'category_type') {
757 $valuetoshow = $langs->trans("Calculated");
758 }
759 // Affiche nom du champ
760 if ($showfield) {
761 print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
762 }
763 }
764 print getTitleFieldOfList($langs->trans("ListOfAccounts"), 0, $_SERVER["PHP_SELF"], "", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
765 print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
766 // Action column
767 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
768 print getTitleFieldOfList('');
769 }
770 print '</tr>';
771
772
773 if ($num) {
774 $imaxinloop = ($listlimit ? min($num, $listlimit) : $num);
775
776 // Lines with values
777 while ($i < $imaxinloop) {
778 $obj = $db->fetch_object($resql);
779
780 //print_r($obj);
781 print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
782 if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
783 $tmpaction = 'edit';
784 $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
785 $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
786 $error = $hookmanager->error;
787 $errors = $hookmanager->errors;
788
789 // Actions
790 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
791 print '<td></td>';
792 }
793
794 // Show fields
795 if (empty($reshook)) {
796 fieldListAccountingCategories($fieldlist, $obj, $tabname[$id], 'edit');
797 }
798
799 print '<td></td>';
800 print '<td class="center">';
801 print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
802 print '<input type="hidden" name="page" value="'.$page.'">';
803 print '<input type="hidden" name="rowid" value="'.$rowid.'">';
804 print '<input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans("Modify").'">';
805 print '<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans("Cancel").'">';
806 print '</td>';
807 // Actions
808 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
809 print '<td></td>';
810 }
811 } else {
812 // Can an entry be erased or disabled ?
813 $iserasable = 1;
814 $canbedisabled = 1;
815 $canbemodified = 1; // true by default
816 if (isset($obj->code)) {
817 if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
818 $iserasable = 0;
819 $canbedisabled = 0;
820 }
821 }
822 $url = $_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code : '')).'&code='.(!empty($obj->code) ? urlencode($obj->code) : '');
823 if ($param) {
824 $url .= '&'.$param;
825 }
826 $url .= '&';
827
828 $canbemodified = $iserasable;
829
830 $tmpaction = 'view';
831 $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
832 $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
833
834 $error = $hookmanager->error;
835 $errors = $hookmanager->errors;
836
837 // Actions
838 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
839 print '<td class="center">';
840 if ($canbemodified) {
841 print '<a class="reposition editfielda marginleftonly marginrightonly" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
842 }
843 if ($iserasable) {
844 if ($user->admin) {
845 print '<a class="marginleftonly marginrightonly" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
846 }
847 }
848 print '</td>';
849 }
850
851 if (empty($reshook)) {
852 foreach ($fieldlist as $field => $value) {
853 $showfield = 1;
854 $title = '';
855 $class = 'tddict';
856
857 $tmpvar = $fieldlist[$field];
858 $valuetoshow = $obj->$tmpvar;
859 if ($value == 'category_type') {
860 $valuetoshow = yn($valuetoshow);
861 } elseif ($valuetoshow == 'all') {
862 $valuetoshow = $langs->trans('All');
863 } elseif ($fieldlist[$field] == 'country') {
864 if (empty($obj->country_code)) {
865 $valuetoshow = '-';
866 } else {
867 $key = $langs->trans("Country".strtoupper($obj->country_code));
868 $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
869 }
870 } elseif (in_array($fieldlist[$field], array('label', 'formula'))) {
871 $class = "tdoverflowmax250";
872 $title = $valuetoshow;
873 } elseif (in_array($fieldlist[$field], array('range_account'))) {
874 $class = "tdoverflowmax250 small";
875 $title = $valuetoshow;
876 } elseif ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
877 $showfield = 0;
878 }
879
880 // Show value for field
881 if ($showfield) {
882 print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'"'.($title ? ' title="'.dol_escape_htmltag($title).'"' : '').'>'.dol_escape_htmltag($valuetoshow).'</td>';
883 }
884 }
885 }
886
887 // Link to setup the group
888 print '<td>';
889 if (empty($obj->formula)) {
890 // Count number of accounts into group
891 $nbofaccountintogroup = 0;
892 $listofaccountintogroup = $accountingcategory->getCptsCat($obj->rowid);
893 $nbofaccountintogroup = count($listofaccountintogroup);
894
895 print '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories.php?action=display&save_lastsearch_values=1&account_category='.$obj->rowid.'">';
896 print $langs->trans("NAccounts", $nbofaccountintogroup);
897 print '</a>';
898 } else {
899 print '<span class="opacitymedium">'.$langs->trans("Formula").'</span>';
900 }
901 print '</td>';
902
903 // Active
904 print '<td class="center" class="nowrap">';
905 if ($canbedisabled) {
906 print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
907 } else {
908 print $langs->trans("AlwaysActive");
909 }
910 print "</td>";
911
912 // Actions
913 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
914 print '<td class="center">';
915 if ($canbemodified) {
916 print '<a class="reposition editfielda paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
917 }
918 if ($iserasable) {
919 if ($user->admin) {
920 print '<a class="paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
921 }
922 }
923 print '</td>';
924 }
925 }
926 print "</tr>\n";
927 $i++;
928 }
929 } else {
930 $colspan = 10;
931 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
932 }
933} else {
934 dol_print_error($db);
935}
936
937print '</table>';
938print '</div>';
939
940print '</form>';
941
942print '<br>';
943
944// End of page
945llxFooter();
946$db->close();
947
948
958function fieldListAccountingCategories($fieldlist, $obj = null, $tabname = '', $context = '')
959{
960 global $conf, $langs, $db;
961 global $form, $mysoc;
962
963 $formadmin = new FormAdmin($db);
964 $formcompany = new FormCompany($db);
965 if (isModEnabled('accounting')) {
966 $formaccounting = new FormAccounting($db);
967 }
968
969 foreach ($fieldlist as $field => $value) {
970 if ($fieldlist[$field] == 'country') {
971 print '<td>';
972 $fieldname = 'country';
973 if ($context == 'add') {
974 $fieldname = 'country_id';
975 $preselectcountrycode = GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : $mysoc->country_code;
976 print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
977 } else {
978 $preselectcountrycode = (empty($obj->country_code) ? (empty($obj->country) ? $mysoc->country_code : $obj->country) : $obj->country_code);
979 print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
980 }
981 print '</td>';
982 } elseif ($fieldlist[$field] == 'country_id') {
983 if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
984 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
985 print '<td>';
986 print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
987 print '</td>';
988 }
989 } elseif ($fieldlist[$field] == 'category_type') {
990 print '<td>';
991 print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : ''), 1);
992 print '</td>';
993 } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
994 print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'"></td>';
995 } else {
996 print '<td>';
997 $class = '';
998 if (in_array($fieldlist[$field], array('code', 'formula'))) {
999 $class = 'maxwidth75';
1000 }
1001 if (in_array($fieldlist[$field], array('label', 'range_account'))) {
1002 $class = 'maxwidth150';
1003 }
1004 if ($fieldlist[$field] == 'position') {
1005 $class = 'maxwidth50';
1006 }
1007 print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" name="'.$fieldlist[$field].'">';
1008 print '</td>';
1009 }
1010 }
1011}
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
Add external modules to list of dictionaries.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
fieldListAccountingCategories($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
Class to manage categories of an accounting account.
Class to manage generation of HTML components for accounting management.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.