dolibarr  18.0.6
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-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
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
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34 require_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
46 if (!$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');
61 if (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
127 complete_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 
136 if (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
141 if (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  // Recupere id libre pour insertion
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  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
303 }
304 
305 if (GETPOST('actioncancel', 'alpha')) {
306  //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
307 }
308 
309 if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
310  if ($tabrowid[$id]) {
311  $rowidcol = $tabrowid[$id];
312  } else {
313  $rowidcol = "rowid";
314  }
315 
316  $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
317 
318  dol_syslog("delete", LOG_DEBUG);
319  $result = $db->query($sql);
320  if (!$result) {
321  if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
322  setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
323  } else {
324  dol_print_error($db);
325  }
326  }
327 }
328 
329 // activate
330 if ($action == $acts[0]) {
331  if ($tabrowid[$id]) {
332  $rowidcol = $tabrowid[$id];
333  } else {
334  $rowidcol = "rowid";
335  }
336 
337  if ($rowid) {
338  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = ".((int) $rowid);
339  } elseif ($code) {
340  $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code = '".$db->escape($code)."'";
341  }
342 
343  $result = $db->query($sql);
344  if (!$result) {
345  dol_print_error($db);
346  }
347 }
348 
349 // disable
350 if ($action == $acts[1]) {
351  if ($tabrowid[$id]) {
352  $rowidcol = $tabrowid[$id];
353  } else {
354  $rowidcol = "rowid";
355  }
356 
357  if ($rowid) {
358  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = ".((int) $rowid);
359  } elseif ($code) {
360  $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code = '".$db->escape($code)."'";
361  }
362 
363  $result = $db->query($sql);
364  if (!$result) {
365  dol_print_error($db);
366  }
367 }
368 
369 // favorite
370 if ($action == 'activate_favorite') {
371  if ($tabrowid[$id]) {
372  $rowidcol = $tabrowid[$id];
373  } else {
374  $rowidcol = "rowid";
375  }
376 
377  if ($rowid) {
378  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol." = ".((int) $rowid);
379  } elseif ($code) {
380  $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code = '".$db->escape($code)."'";
381  }
382 
383  $result = $db->query($sql);
384  if (!$result) {
385  dol_print_error($db);
386  }
387 }
388 
389 // disable favorite
390 if ($action == 'disable_favorite') {
391  if ($tabrowid[$id]) {
392  $rowidcol = $tabrowid[$id];
393  } else {
394  $rowidcol = "rowid";
395  }
396 
397  if ($rowid) {
398  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol." = ".((int) $rowid);
399  } elseif ($code) {
400  $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code = '".$db->escape($code)."'";
401  }
402 
403  $result = $db->query($sql);
404  if (!$result) {
405  dol_print_error($db);
406  }
407 }
408 
409 
410 /*
411  * View
412  */
413 
414 $form = new Form($db);
415 $formadmin = new FormAdmin($db);
416 
417 llxHeader('', $langs->trans('DictionaryAccountancyCategory'));
418 
419 $titre = $langs->trans($tablib[$id]);
420 $linkback = '';
421 $titlepicto = 'setup';
422 
423 print load_fiche_titre($titre, $linkback, $titlepicto);
424 
425 print '<span class="opacitymedium">'.$langs->trans("AccountingAccountGroupsDesc", $langs->transnoentitiesnoconv("ByPersonalizedAccountGroups")).'</span><br><br>';
426 
427 // Confirmation of the deletion of the line
428 if ($action == 'delete') {
429  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);
430 }
431 
432 // Complete search query with sorting criteria
433 $sql = $tabsql[$id];
434 
435 if ($search_country_id > 0) {
436  if (preg_match('/ WHERE /', $sql)) {
437  $sql .= " AND ";
438  } else {
439  $sql .= " WHERE ";
440  }
441  $sql .= " (a.fk_country = ".((int) $search_country_id)." OR a.fk_country = 0)";
442 }
443 
444 // If sort order is "country", we use country_code instead
445 if ($sortfield == 'country') {
446  $sortfield = 'country_code';
447 }
448 if (empty($sortfield)) {
449  $sortfield = 'position';
450 }
451 
452 $sql .= $db->order($sortfield, $sortorder);
453 $sql .= $db->plimit($listlimit + 1, $offset);
454 
455 
456 $fieldlist = explode(',', $tabfield[$id]);
457 
458 $param = '&id='.$id;
459 if ($search_country_id > 0) {
460  $param .= '&search_country_id='.urlencode($search_country_id);
461 }
462 $paramwithsearch = $param;
463 if ($sortorder) {
464  $paramwithsearch .= '&sortorder='.urlencode($sortorder);
465 }
466 if ($sortfield) {
467  $paramwithsearch .= '&sortfield='.urlencode($sortfield);
468 }
469 if (GETPOST('from', 'alpha')) {
470  $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
471 }
472 if ($listlimit) {
473  $paramwithsearch .= '&listlimit='.urlencode(GETPOST('listlimit', 'int'));
474 }
475 print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
476 print '<input type="hidden" name="token" value="'.newToken().'">';
477 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
478 print '<input type="hidden" name="sortfield" value="'.dol_escape_htmltag($sortfield).'">';
479 print '<input type="hidden" name="sortorder" value="'.dol_escape_htmltag($sortorder).'">';
480 
481 
482 print '<div class="div-table-responsive-no-min">';
483 print '<table class="noborder centpercent">';
484 
485 // Form to add a new line
486 if ($tabname[$id]) {
487  $fieldlist = explode(',', $tabfield[$id]);
488 
489  // Line for title
490  print '<tr class="liste_titre">';
491  // Action column
492  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
493  print '<td></td>';
494  }
495  foreach ($fieldlist as $field => $value) {
496  // Determine le nom du champ par rapport aux noms possibles
497  // dans les dictionnaires de donnees
498  $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
499  $valuetoshow = $langs->trans($valuetoshow); // try to translate
500  $class = "left";
501  if ($fieldlist[$field] == 'type') {
502  if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") {
503  $valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
504  } else {
505  $valuetoshow = $langs->trans("Type");
506  }
507  }
508  if ($fieldlist[$field] == 'code') {
509  $valuetoshow = $langs->trans("Code");
510  }
511  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
512  $valuetoshow = $langs->trans("Label");
513  }
514  if ($fieldlist[$field] == 'libelle_facture') {
515  $valuetoshow = $langs->trans("LabelOnDocuments");
516  }
517  if ($fieldlist[$field] == 'country') {
518  $valuetoshow = $langs->trans("Country");
519  }
520  if ($fieldlist[$field] == 'accountancy_code') {
521  $valuetoshow = $langs->trans("AccountancyCode");
522  }
523  if ($fieldlist[$field] == 'accountancy_code_sell') {
524  $valuetoshow = $langs->trans("AccountancyCodeSell");
525  }
526  if ($fieldlist[$field] == 'accountancy_code_buy') {
527  $valuetoshow = $langs->trans("AccountancyCodeBuy");
528  }
529  if ($fieldlist[$field] == 'pcg_version' || $fieldlist[$field] == 'fk_pcg_version') {
530  $valuetoshow = $langs->trans("Pcg_version");
531  }
532  if ($fieldlist[$field] == 'range_account') {
533  $valuetoshow = $langs->trans("Comment");
534  $class = 'width75';
535  }
536  if ($fieldlist[$field] == 'category_type') {
537  $valuetoshow = $langs->trans("Calculated");
538  }
539 
540  if ($valuetoshow != '') {
541  print '<td class="'.$class.'">';
542  if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
543  print '<a href="'.$tabhelp[$id][$value].'">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
544  } elseif (!empty($tabhelp[$id][$value])) {
545  print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
546  } else {
547  print $valuetoshow;
548  }
549  print '</td>';
550  }
551  }
552 
553  print '<td>';
554  print '<input type="hidden" name="id" value="'.$id.'">';
555  print '</td>';
556  print '<td></td>';
557  // Action column
558  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
559  print '<td></td>';
560  }
561  print '</tr>';
562 
563  // Line to enter new values
564  print '<tr class="oddeven nodrag nodrop nohover">';
565 
566  // Action column
567  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
568  print '<td></td>';
569  }
570 
571  $obj = new stdClass();
572  // If data was already input, we define them in obj to populate input fields.
573  if (GETPOST('actionadd', 'alpha')) {
574  foreach ($fieldlist as $key => $val) {
575  if (GETPOST($val) != '') {
576  $obj->$val = GETPOST($val);
577  }
578  }
579  }
580 
581  $tmpaction = 'create';
582  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
583  $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
584  $error = $hookmanager->error; $errors = $hookmanager->errors;
585 
586  if (empty($reshook)) {
587  fieldListAccountingCategories($fieldlist, $obj, $tabname[$id], 'add');
588  }
589 
590  print '<td colspan="2" class="right">';
591  print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
592  print '</td>';
593 
594  // Action column
595  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
596  print '<td></td>';
597  }
598 
599  print "</tr>";
600 
601  $colspan = count($fieldlist) + 3;
602  if ($id == 32) {
603  $colspan++;
604  }
605 }
606 
607 print '</table>';
608 print '</div>';
609 
610 print '<div class="div-table-responsive">';
611 print '<table class="noborder centpercent">';
612 
613 // List of available record in database
614 dol_syslog("htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
615 
616 $resql = $db->query($sql);
617 if ($resql) {
618  $num = $db->num_rows($resql);
619  $i = 0;
620 
621  // There is several pages
622  if ($num > $listlimit) {
623  print '<tr class="none"><td class="right" colspan="'.(2 + count($fieldlist)).'">';
624  print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
625  print '</td></tr>';
626  }
627 
628  $filterfound = 0;
629  foreach ($fieldlist as $field => $value) {
630  $showfield = 1; // By defaut
631  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
632  $showfield = 0;
633  }
634  if ($showfield) {
635  if ($value == 'country') {
636  $filterfound++;
637  }
638  }
639  }
640 
641  // Title line with search boxes
642  print '<tr class="liste_titre liste_titre_add liste_titre_filter">';
643 
644  // Action column
645  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
646  print '<td class="liste_titre center">';
647  if ($filterfound) {
648  $searchpicto = $form->showFilterAndCheckAddButtons(0);
649  print $searchpicto;
650  }
651  print '</td>';
652  }
653 
654  $filterfound = 0;
655  foreach ($fieldlist as $field => $value) {
656  $showfield = 1; // By defaut
657 
658  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
659  $showfield = 0;
660  }
661 
662  if ($showfield) {
663  if ($value == 'country') {
664  print '<td class="liste_titre">';
665  print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
666  print '</td>';
667  $filterfound++;
668  } else {
669  print '<td class="liste_titre"></td>';
670  }
671  }
672  }
673  print '<td class="liste_titre"></td>';
674  print '<td class="liste_titre"></td>';
675  // Action column
676  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
677  print '<td class="liste_titre center">';
678  if ($filterfound) {
679  $searchpicto = $form->showFilterAndCheckAddButtons(0);
680  print $searchpicto;
681  }
682  print '</td>';
683  }
684  print '</tr>';
685 
686  // Title of lines
687  print '<tr class="liste_titre">';
688  // Action column
689  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
690  print getTitleFieldOfList('');
691  }
692  foreach ($fieldlist as $field => $value) {
693  // Determines the name of the field in relation to the possible names
694  // in data dictionaries
695  $showfield = 1; // By default
696  $class = "left";
697  $sortable = 1;
698  $valuetoshow = '';
699 
700  $valuetoshow = ucfirst($fieldlist[$field]); // By default
701  $valuetoshow = $langs->trans($valuetoshow); // try to translate
702  if ($fieldlist[$field] == 'source') {
703  $valuetoshow = $langs->trans("Contact");
704  }
705  if ($fieldlist[$field] == 'price') {
706  $valuetoshow = $langs->trans("PriceUHT");
707  }
708  if ($fieldlist[$field] == 'taux') {
709  if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") {
710  $valuetoshow = $langs->trans("Rate");
711  } else {
712  $valuetoshow = $langs->trans("Amount");
713  }
714  $class = 'center';
715  }
716  if ($fieldlist[$field] == 'type') {
717  $valuetoshow = $langs->trans("Type");
718  }
719  if ($fieldlist[$field] == 'code') {
720  $valuetoshow = $langs->trans("Code");
721  }
722  if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
723  $valuetoshow = $langs->trans("Label");
724  }
725  if ($fieldlist[$field] == 'country') {
726  $valuetoshow = $langs->trans("Country");
727  }
728  if ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
729  $showfield = 0;
730  }
731  if ($fieldlist[$field] == 'accountancy_code') {
732  $valuetoshow = $langs->trans("AccountancyCode");
733  }
734  if ($fieldlist[$field] == 'accountancy_code_sell') {
735  $valuetoshow = $langs->trans("AccountancyCodeSell");
736  $sortable = 0;
737  }
738  if ($fieldlist[$field] == 'accountancy_code_buy') {
739  $valuetoshow = $langs->trans("AccountancyCodeBuy");
740  $sortable = 0;
741  }
742  if ($fieldlist[$field] == 'fk_pcg_version') {
743  $valuetoshow = $langs->trans("Pcg_version");
744  }
745  if ($fieldlist[$field] == 'account_parent') {
746  $valuetoshow = $langs->trans("Accountsparent");
747  }
748  if ($fieldlist[$field] == 'pcg_type') {
749  $valuetoshow = $langs->trans("Pcg_type");
750  }
751  if ($fieldlist[$field] == 'type_template') {
752  $valuetoshow = $langs->trans("TypeOfTemplate");
753  }
754  if ($fieldlist[$field] == 'range_account') {
755  $valuetoshow = $langs->trans("Comment");
756  }
757  if ($fieldlist[$field] == 'category_type') {
758  $valuetoshow = $langs->trans("Calculated");
759  }
760  // Affiche nom du champ
761  if ($showfield) {
762  print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $fieldlist[$field] : ''), ($page ? 'page='.$page.'&' : ''), $param, "", $sortfield, $sortorder, $class.' ');
763  }
764  }
765  print getTitleFieldOfList($langs->trans("ListOfAccounts"), 0, $_SERVER["PHP_SELF"], "", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, '');
766  print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
767  // Action column
768  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
769  print getTitleFieldOfList('');
770  }
771  print '</tr>';
772 
773 
774  if ($num) {
775  $imaxinloop = ($listlimit ? min($num, $listlimit) : $num);
776 
777  // Lines with values
778  while ($i < $imaxinloop) {
779  $obj = $db->fetch_object($resql);
780 
781  //print_r($obj);
782  print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
783  if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
784  $tmpaction = 'edit';
785  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
786  $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
787  $error = $hookmanager->error; $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; $canbedisabled = 1; $canbemodified = 1; // true by default
814  if (isset($obj->code)) {
815  if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
816  $iserasable = 0; $canbedisabled = 0;
817  }
818  }
819  $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) : '');
820  if ($param) {
821  $url .= '&'.$param;
822  }
823  $url .= '&';
824 
825  $canbemodified = $iserasable;
826 
827  $tmpaction = 'view';
828  $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
829  $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
830 
831  $error = $hookmanager->error; $errors = $hookmanager->errors;
832 
833  // Actions
834  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
835  print '<td class="center">';
836  if ($canbemodified) {
837  print '<a class="reposition editfielda marginleftonly marginrightonly" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
838  }
839  if ($iserasable) {
840  if ($user->admin) {
841  print '<a class="marginleftonly marginrightonly" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
842  }
843  }
844  print '</td>';
845  }
846 
847  if (empty($reshook)) {
848  foreach ($fieldlist as $field => $value) {
849  $showfield = 1;
850  $title = '';
851  $class = 'tddict';
852 
853  $tmpvar = $fieldlist[$field];
854  $valuetoshow = $obj->$tmpvar;
855  if ($value == 'category_type') {
856  $valuetoshow = yn($valuetoshow);
857  } elseif ($valuetoshow == 'all') {
858  $valuetoshow = $langs->trans('All');
859  } elseif ($fieldlist[$field] == 'country') {
860  if (empty($obj->country_code)) {
861  $valuetoshow = '-';
862  } else {
863  $key = $langs->trans("Country".strtoupper($obj->country_code));
864  $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
865  }
866  } elseif (in_array($fieldlist[$field], array('label', 'range_account', 'formula'))) {
867  $class = "tdoverflowmax250";
868  $title = $valuetoshow;
869  } elseif ($fieldlist[$field] == 'region_id' || $fieldlist[$field] == 'country_id') {
870  $showfield = 0;
871  }
872 
873  // Show value for field
874  if ($showfield) {
875  print '<!-- '.$fieldlist[$field].' --><td class="'.$class.'"'.($title ? ' title="'.dol_escape_htmltag($title).'"': '').'>'.dol_escape_htmltag($valuetoshow).'</td>';
876  }
877  }
878  }
879 
880  // Link to setup the group
881  print '<td>';
882  if (empty($obj->formula)) {
883  // Count number of accounts into group
884  $nbofaccountintogroup = 0;
885  $listofaccountintogroup = $accountingcategory->getCptsCat($obj->rowid);
886  $nbofaccountintogroup = count($listofaccountintogroup);
887 
888  print '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories.php?action=display&save_lastsearch_values=1&account_category='.$obj->rowid.'">';
889  print $langs->trans("NAccounts", $nbofaccountintogroup);
890  print '</a>';
891  } else {
892  print '<span class="opacitymedium">'.$langs->trans("Formula").'</span>';
893  }
894  print '</td>';
895 
896  // Active
897  print '<td class="center" class="nowrap">';
898  if ($canbedisabled) {
899  print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
900  } else {
901  print $langs->trans("AlwaysActive");
902  }
903  print "</td>";
904 
905  // Actions
906  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
907  print '<td class="center">';
908  if ($canbemodified) {
909  print '<a class="reposition editfielda paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a>';
910  }
911  if ($iserasable) {
912  if ($user->admin) {
913  print '<a class="paddingleft marginleftonly marginrightonly paddingright" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
914  }
915  }
916  print '</td>';
917  }
918  }
919  print "</tr>\n";
920  $i++;
921  }
922  } else {
923  $colspan = 10;
924  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</td></tr>';
925  }
926 } else {
927  dol_print_error($db);
928 }
929 
930 print '</table>';
931 print '</div>';
932 
933 print '</form>';
934 
935 print '<br>';
936 
937 // End of page
938 llxFooter();
939 $db->close();
940 
941 
951 function fieldListAccountingCategories($fieldlist, $obj = '', $tabname = '', $context = '')
952 {
953  global $conf, $langs, $db;
954  global $form, $mysoc;
955 
956  $formadmin = new FormAdmin($db);
957  $formcompany = new FormCompany($db);
958  if (isModEnabled('accounting')) {
959  $formaccounting = new FormAccounting($db);
960  }
961 
962  foreach ($fieldlist as $field => $value) {
963  if ($fieldlist[$field] == 'country') {
964  print '<td>';
965  $fieldname = 'country';
966  if ($context == 'add') {
967  $fieldname = 'country_id';
968  $preselectcountrycode = GETPOSTISSET('country_id') ? GETPOST('country_id', 'int') : $mysoc->country_code;
969  print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
970  } else {
971  $preselectcountrycode = (empty($obj->country_code) ? (empty($obj->country) ? $mysoc->country_code : $obj->country) : $obj->country_code);
972  print $form->select_country($preselectcountrycode, $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
973  }
974  print '</td>';
975  } elseif ($fieldlist[$field] == 'country_id') {
976  if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
977  $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
978  print '<td>';
979  print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
980  print '</td>';
981  }
982  } elseif ($fieldlist[$field] == 'category_type') {
983  print '<td>';
984  print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:''), 1);
985  print '</td>';
986  } elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
987  print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
988  } else {
989  print '<td>';
990  $class = '';
991  if (in_array($fieldlist[$field], array('code', 'range_account', 'label', 'formula'))) {
992  $class = 'maxwidth100';
993  }
994  if ($fieldlist[$field] == 'position') {
995  $class = 'maxwidth50';
996  }
997  print '<input type="text" class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
998  print '</td>';
999  }
1000  }
1001 }
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
Add external modules to list of dictionaries.
Definition: admin.lib.php:1324
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
fieldListAccountingCategories($fieldlist, $obj='', $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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.