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