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