dolibarr 21.0.0-beta
account.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2024 Alexandre Spangaro <aspangaro@easya.solutions>
4 * Copyright (C) 2016-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
34
43// Load translation files required by the page
44$langs->loadLangs(array('accountancy', 'admin', 'bills', 'compta', 'salaries'));
45
46$action = GETPOST('action', 'aZ09');
47$cancel = GETPOST('cancel', 'alpha');
49$rowid = GETPOSTINT('rowid');
50$massaction = GETPOST('massaction', 'aZ09');
51$optioncss = GETPOST('optioncss', 'alpha');
52$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'accountingaccountlist'; // To manage different context of search
53$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
54
55$search_account = GETPOST('search_account', 'alpha');
56$search_label = GETPOST('search_label', 'alpha');
57$search_labelshort = GETPOST('search_labelshort', 'alpha');
58$search_accountparent = GETPOST('search_accountparent', 'alpha');
59$search_pcgtype = GETPOST('search_pcgtype', 'alpha');
60$search_import_key = GETPOST('search_import_key', 'alpha');
61$toselect = GETPOST('toselect', 'array');
62$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
63$confirm = GETPOST('confirm', 'alpha');
64
65$chartofaccounts = GETPOSTINT('chartofaccounts');
66
67$permissiontoadd = $user->hasRight('accounting', 'chartofaccount');
68$permissiontodelete = $user->hasRight('accounting', 'chartofaccount');
69
70// Security check
71if ($user->socid > 0) {
73}
74if (!$permissiontoadd) {
76}
77// now $permissiontoadd or $user->hasRight('accounting', 'chartofaccount') are always equal to 1
78
79// Load variable for pagination
80$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
81$sortfield = GETPOST('sortfield', 'aZ09comma');
82$sortorder = GETPOST('sortorder', 'aZ09comma');
83$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
84if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
85 // If $page is not defined, or '' or -1 or if we click on clear filters
86 $page = 0;
87}
88$offset = $limit * $page;
89$pageprev = $page - 1;
90$pagenext = $page + 1;
91if (!$sortfield) {
92 $sortfield = "aa.account_number";
93}
94if (!$sortorder) {
95 $sortorder = "ASC";
96}
97
98$arrayfields = array(
99 'aa.account_number' => array('label' => "AccountNumber", 'checked' => 1),
100 'aa.label' => array('label' => "Label", 'checked' => 1),
101 'aa.labelshort' => array('label' => "LabelToShow", 'checked' => 1),
102 'aa.account_parent' => array('label' => "Accountparent", 'checked' => 1),
103 'aa.pcg_type' => array('label' => "Pcgtype", 'checked' => 1, 'help' => 'PcgtypeDesc'),
104 'categories' => array('label' => "AccountingCategories", 'checked' => -1, 'help' => 'AccountingCategoriesDesc'),
105 'aa.reconcilable' => array('label' => "Reconcilable", 'checked' => 1),
106 'aa.import_key' => array('label' => "ImportId", 'checked' => -1, 'help' => ''),
107 'aa.active' => array('label' => "Activated", 'checked' => 1)
108);
109
110if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
111 unset($arrayfields['categories']);
112 unset($arrayfields['aa.reconcilable']);
113}
114
115$accounting = new AccountingAccount($db);
116
117// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
118$hookmanager->initHooks(array('accountancyadminaccount'));
119
120
121/*
122 * Actions
123 */
124
125if (GETPOST('cancel', 'alpha')) {
126 $action = 'list';
127 $massaction = '';
128}
129if (!GETPOST('confirmmassaction', 'alpha')) {
130 $massaction = '';
131}
132
133$parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
134$reshook = $hookmanager->executeHooks('doActions', $parameters, $accounting, $action); // Note that $action and $object may have been monowraponalldified by some hooks
135if ($reshook < 0) {
136 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
137}
138
139if (empty($reshook)) {
140 if (!empty($cancel)) {
141 $action = '';
142 }
143
144 $objectclass = 'AccountingAccount';
145 $uploaddir = $conf->accounting->multidir_output[$conf->entity];
146 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
147
148 if ($action == "delete") {
149 $action = "";
150 }
151 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
152
153 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
154 $search_account = "";
155 $search_label = "";
156 $search_labelshort = "";
157 $search_accountparent = "";
158 $search_pcgtype = "";
159 $search_import_key = "";
160 $search_array_options = array();
161 }
162 if ((GETPOSTINT('valid_change_chart') && GETPOSTINT('chartofaccounts') > 0) // explicit click on button 'Change and load' with js on
163 || (GETPOSTINT('chartofaccounts') > 0 && GETPOSTINT('chartofaccounts') != getDolGlobalInt('CHARTOFACCOUNTS'))) { // a submit of form is done and chartofaccounts combo has been modified
164 $error = 0;
165
166 if ($chartofaccounts > 0 /* && $permissiontoadd */) {
167 $country_code = '';
168 // Get language code for this $chartofaccounts
169 $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_country as c, '.MAIN_DB_PREFIX.'accounting_system as a';
170 $sql .= ' WHERE c.rowid = a.fk_country AND a.rowid = '.(int) $chartofaccounts;
171 $resql = $db->query($sql);
172 if ($resql) {
173 $obj = $db->fetch_object($resql);
174 if ($obj) {
175 $country_code = $obj->code;
176 }
177 } else {
178 dol_print_error($db);
179 }
180
181 // Try to load sql file
182 if ($country_code) {
183 $sqlfile = DOL_DOCUMENT_ROOT.'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).'.sql';
184
185 $offsetforchartofaccount = 0;
186 // Get the comment line '-- ADD CCCNNNNN to rowid...' to find CCCNNNNN (CCC is country num, NNNNN is id of accounting account)
187 // and pass CCCNNNNN + (num of company * 100 000 000) as offset to the run_sql as a new parameter to say to update sql on the fly to add offset to rowid and account_parent value.
188 // This is to be sure there is no conflict for each chart of account, whatever is country, whatever is company when multicompany is used.
189 $tmp = file_get_contents($sqlfile);
190 $reg = array();
191 if (preg_match('/-- ADD (\d+) to rowid/ims', $tmp, $reg)) {
192 $offsetforchartofaccount += $reg[1];
193 }
194 $offsetforchartofaccount += ($conf->entity * 100000000);
195
196 $result = run_sql($sqlfile, 1, $conf->entity, 1, '', 'default', 32768, 0, $offsetforchartofaccount);
197
198 if ($result > 0) {
199 setEventMessages($langs->trans("ChartLoaded"), null, 'mesgs');
200 } else {
201 setEventMessages($langs->trans("ErrorDuringChartLoad"), null, 'warnings');
202 }
203 }
204
205 if (!dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
206 $error++;
207 }
208 } else {
209 $error++;
210 }
211 }
212
213 if ($action == 'disable' /* && $permissiontoadd */) {
214 if ($accounting->fetch($id)) {
215 $mode = GETPOSTINT('mode');
216 $result = $accounting->accountDeactivate($id, $mode);
217 if ($result < 0) {
218 setEventMessages($accounting->error, $accounting->errors, 'errors');
219 }
220 }
221
222 $action = 'update';
223 } elseif ($action == 'enable' /* && $permissiontoadd */) {
224 if ($accounting->fetch($id)) {
225 $mode = GETPOSTINT('mode');
226 $result = $accounting->accountActivate($id, $mode);
227 if ($result < 0) {
228 setEventMessages($accounting->error, $accounting->errors, 'errors');
229 }
230 }
231 $action = 'update';
232 }
233}
234
235
236/*
237 * View
238 */
239$form = new Form($db);
240$formaccounting = new FormAccounting($db);
241
242$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
243
244llxHeader('', $langs->trans("ListAccounts"), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_account');
245
246if ($action == 'delete') {
247 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1);
248 print $formconfirm;
249}
250
251$pcgver = getDolGlobalInt('CHARTOFACCOUNTS');
252
253$sql = "SELECT aa.rowid, aa.fk_pcg_version, aa.pcg_type, aa.account_number, aa.account_parent, aa.label, aa.labelshort, aa.fk_accounting_category,";
254$sql .= " aa.reconcilable, aa.active, aa.import_key,";
255$sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
256
257// Add fields from hooks
258$parameters = array();
259$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
260$sql .= $hookmanager->resPrint;
261$sql = preg_replace('/,\s*$/', '', $sql);
262
263$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
264$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".((int) $conf->entity);
265$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".((int) $conf->entity);
266
267// Add table from hooks
268$parameters = array();
269$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
270$sql .= $hookmanager->resPrint;
271
272$sql .= " WHERE asy.rowid = ".((int) $pcgver);
273
274if (strlen(trim($search_account))) {
275 $lengthpaddingaccount = 0;
276 if (getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT') || getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT')) {
277 $lengthpaddingaccount = max(getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT'), getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT'));
278 }
279 $search_account_tmp = $search_account;
280 $weremovedsomezero = 0;
281 if (strlen($search_account_tmp) <= $lengthpaddingaccount) {
282 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
283 if (preg_match('/0$/', $search_account_tmp)) {
284 $weremovedsomezero++;
285 $search_account_tmp = preg_replace('/0$/', '', $search_account_tmp);
286 }
287 }
288 }
289
290 //var_dump($search_account); exit;
291 if ($search_account_tmp) {
292 if ($weremovedsomezero) {
293 $search_account_tmp_clean = $search_account_tmp;
294 $search_account_clean = $search_account;
295 $startchar = '%';
296 if (substr($search_account_tmp, 0, 1) === '^') {
297 $startchar = '';
298 $search_account_tmp_clean = preg_replace('/^\^/', '', $search_account_tmp);
299 $search_account_clean = preg_replace('/^\^/', '', $search_account);
300 }
301 $sql .= " AND (aa.account_number LIKE '".$db->escape($startchar.$search_account_tmp_clean)."'";
302 $sql .= " OR aa.account_number LIKE '".$db->escape($startchar.$search_account_clean)."%')";
303 } else {
304 $sql .= natural_search("aa.account_number", $search_account_tmp);
305 }
306 }
307}
308if (strlen(trim($search_label))) {
309 $sql .= natural_search("aa.label", $search_label);
310}
311if (strlen(trim($search_labelshort))) {
312 $sql .= natural_search("aa.labelshort", $search_labelshort);
313}
314if (strlen(trim($search_accountparent)) && $search_accountparent != '-1') {
315 $sql .= natural_search("aa.account_parent", $search_accountparent, 2);
316}
317if (strlen(trim($search_pcgtype))) {
318 $sql .= natural_search("aa.pcg_type", $search_pcgtype);
319}
320if (strlen(trim($search_import_key))) {
321 $sql .= natural_search("aa.import_key", $search_import_key);
322}
323
324// Add where from hooks
325$parameters = array();
326$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
327$sql .= $hookmanager->resPrint;
328
329$sql .= $db->order($sortfield, $sortorder);
330//print $sql;
331
332// Count total nb of records
333$nbtotalofrecords = '';
334if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
335 $resql = $db->query($sql);
336 $nbtotalofrecords = $db->num_rows($resql);
337 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
338 $page = 0;
339 $offset = 0;
340 }
341}
342
343$sql .= $db->plimit($limit + 1, $offset);
344
345dol_syslog("accountancy/admin/account.php:: sql=".$sql);
346$resql = $db->query($sql);
347
348if ($resql) {
349 $num = $db->num_rows($resql);
350
351 $arrayofselected = is_array($toselect) ? $toselect : array();
352
353 $param = '';
354 // if null contextpage is forced to 'accountingaccountlist' so never empty
355 if (/* !empty($contextpage) && */$contextpage != $_SERVER["PHP_SELF"]) {
356 $param .= '&contextpage='.urlencode($contextpage);
357 }
358 if ($limit > 0 && $limit != $conf->liste_limit) {
359 $param .= '&limit='.((int) $limit);
360 }
361 if ($search_account) {
362 $param .= '&search_account='.urlencode($search_account);
363 }
364 if ($search_label) {
365 $param .= '&search_label='.urlencode($search_label);
366 }
367 if ($search_labelshort) {
368 $param .= '&search_labelshort='.urlencode($search_labelshort);
369 }
370 if ($search_accountparent > 0 || $search_accountparent == '0') {
371 $param .= '&search_accountparent='.urlencode($search_accountparent);
372 }
373 if ($search_pcgtype) {
374 $param .= '&search_pcgtype='.urlencode($search_pcgtype);
375 }
376 if ($search_import_key) {
377 $param .= '&search_import_key='.urlencode($search_import_key);
378 }
379 if ($optioncss != '') {
380 $param .= '&optioncss='.urlencode($optioncss);
381 }
382
383 // Add $param from hooks
384 $parameters = array();
385 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
386 $param .= $hookmanager->resPrint;
387
388 if (!empty($conf->use_javascript_ajax)) {
389 print '<!-- Add javascript to reload page when we click "Change plan" -->
390 <script type="text/javascript">
391 $(document).ready(function () {
392 $("#change_chart").on("click", function (e) {
393 console.log("chartofaccounts selected = "+$("#chartofaccounts").val());
394 // reload page
395 window.location.href = "'.$_SERVER["PHP_SELF"].'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
396 });
397 });
398 </script>';
399 }
400
401 // List of mass actions available
402 $arrayofmassactions = array();
403 // if ($permissiontoadd) { // test is always true
404 $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
405 // }
406 if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
407 $arrayofmassactions = array();
408 }
409
410 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
411
412 $newcardbutton = '';
413 $newcardbutton = dolGetButtonTitle($langs->trans('Addanaccount'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/accountancy/admin/card.php?action=create', '', $permissiontoadd);
414
415
416 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
417 if ($optioncss != '') {
418 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
419 }
420 print '<input type="hidden" name="token" value="'.newToken().'">';
421 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
422 print '<input type="hidden" name="action" value="list">';
423 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
424 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
425 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
426
427 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
428 print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accounting_account', 0, $newcardbutton, '', $limit, 0, 0, 1);
429
430 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
431
432 // Box to select active chart of account
433 print $langs->trans("Selectchartofaccounts")." : ";
434 print '<select class="flat minwidth200" name="chartofaccounts" id="chartofaccounts">';
435 $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code";
436 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
437 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country = c.rowid AND c.active = 1";
438 $sql .= " WHERE a.active = 1";
439
440 dol_syslog("accountancy/admin/account.php sql=".$sql);
441
442 $resqlchart = $db->query($sql);
443 if ($resqlchart) {
444 $numbis = $db->num_rows($resqlchart);
445 $i = 0;
446 print '<option value="-1">&nbsp;</option>';
447 while ($i < $numbis) {
448 $obj = $db->fetch_object($resqlchart);
449 if ($obj) {
450 print '<option value="'.$obj->rowid.'"';
451 print ($pcgver == $obj->rowid) ? ' selected' : '';
452 print '>'.$obj->pcg_version.' - '.$obj->label.' - ('.$obj->country_code.')</option>';
453 }
454 $i++;
455 }
456 } else {
457 dol_print_error($db);
458 }
459 print "</select>";
460 print ajax_combobox("chartofaccounts");
461 print '<input type="'.(empty($conf->use_javascript_ajax) ? 'submit' : 'button').'" class="button button-edit small" name="change_chart" id="change_chart" value="'.dol_escape_htmltag($langs->trans("ChangeAndLoad")).'">';
462
463 print '<br>';
464
465 $parameters = array();
466 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
467 print $hookmanager->resPrint;
468
469 print '<br>';
470
471 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
472 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
473 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
474 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
475
476 $accountstatic = new AccountingAccount($db);
477 $accountparent = new AccountingAccount($db);
478 $totalarray = array();
479 $totalarray['nbfield'] = 0;
480
481 $moreforfilter = '';
482 // if ($moreforfilter) {
483 // print '<div class="liste_titre liste_titre_bydiv centpercent">';
484 // print $moreforfilter;
485 // print '</div>';
486 // }
487
488 print '<div class="div-table-responsive">';
489 // print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
490 print '<table class="tagtable liste">'."\n";
491
492 // Fields title search
493 // --------------------------------------------------------------------
494 print '<tr class="liste_titre_filter">';
495
496 // Action column
497 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
498 print '<td class="liste_titre center maxwidthsearch">';
499 $searchpicto = $form->showFilterButtons('left');
500 print $searchpicto;
501 print '</td>';
502 }
503 if (!empty($arrayfields['aa.account_number']['checked'])) {
504 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_account" value="'.$search_account.'"></td>';
505 }
506 if (!empty($arrayfields['aa.label']['checked'])) {
507 print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="'.$search_label.'"></td>';
508 }
509 if (!empty($arrayfields['aa.labelshort']['checked'])) {
510 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_labelshort" value="'.$search_labelshort.'"></td>';
511 }
512 if (!empty($arrayfields['aa.account_parent']['checked'])) {
513 print '<td class="liste_titre">';
514 print $formaccounting->select_account($search_accountparent, 'search_accountparent', 2, array(), 0, 0, 'maxwidth150');
515 print '</td>';
516 }
517 // Predefined group
518 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
519 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_pcgtype" value="'.$search_pcgtype.'"></td>';
520 }
521 // Custom groups
522 if (!empty($arrayfields['categories']['checked'])) {
523 print '<td class="liste_titre"></td>';
524 }
525
526 // Fields from hook
527 $parameters = array('arrayfields' => $arrayfields);
528 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
529 print $hookmanager->resPrint;
530
531 // Import key
532 if (!empty($arrayfields['aa.import_key']['checked'])) {
533 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_import_key" value="'.$search_import_key.'"></td>';
534 }
535 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
536 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
537 print '<td class="liste_titre">&nbsp;</td>';
538 }
539 }
540 if (!empty($arrayfields['aa.active']['checked'])) {
541 print '<td class="liste_titre">&nbsp;</td>';
542 }
543 // Action column
544 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
545 print '<td class="liste_titre center maxwidthsearch">';
546 $searchpicto = $form->showFilterButtons();
547 print $searchpicto;
548 print '</td>';
549 }
550 print '</tr>'."\n";
551
552 $totalarray = array();
553 $totalarray['nbfield'] = 0;
554
555 // Fields title label
556 // --------------------------------------------------------------------
557 print '<tr class="liste_titre">';
558 // Action column
559 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
560 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn ');
561 $totalarray['nbfield']++;
562 }
563 if (!empty($arrayfields['aa.account_number']['checked'])) {
564 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
565 $totalarray['nbfield']++;
566 }
567 if (!empty($arrayfields['aa.label']['checked'])) {
568 print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder);
569 $totalarray['nbfield']++;
570 }
571 if (!empty($arrayfields['aa.labelshort']['checked'])) {
572 print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder);
573 $totalarray['nbfield']++;
574 }
575 if (!empty($arrayfields['aa.account_parent']['checked'])) {
576 print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left ');
577 $totalarray['nbfield']++;
578 }
579 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
580 print_liste_field_titre($arrayfields['aa.pcg_type']['label'], $_SERVER["PHP_SELF"], 'aa.pcg_type,aa.account_number', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.pcg_type']['help'], 1);
581 $totalarray['nbfield']++;
582 }
583 if (!empty($arrayfields['categories']['checked'])) {
584 print_liste_field_titre($arrayfields['categories']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '', $arrayfields['categories']['help'], 1);
585 $totalarray['nbfield']++;
586 }
587
588 // Hook fields
589 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
590 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
591 print $hookmanager->resPrint;
592
593 if (!empty($arrayfields['aa.import_key']['checked'])) {
594 print_liste_field_titre($arrayfields['aa.import_key']['label'], $_SERVER["PHP_SELF"], 'aa.import_key', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.import_key']['help'], 1);
595 $totalarray['nbfield']++;
596 }
597 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
598 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
599 print_liste_field_titre($arrayfields['aa.reconcilable']['label'], $_SERVER["PHP_SELF"], 'aa.reconcilable', '', $param, '', $sortfield, $sortorder);
600 $totalarray['nbfield']++;
601 }
602 }
603 if (!empty($arrayfields['aa.active']['checked'])) {
604 print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder);
605 $totalarray['nbfield']++;
606 }
607 // Action column
608 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
609 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
610 $totalarray['nbfield']++;
611 }
612 print "</tr>\n";
613
614 // Loop on record
615 // --------------------------------------------------------------------
616 $i = 0;
617 while ($i < min($num, $limit)) {
618 $obj = $db->fetch_object($resql);
619
620 $accountstatic->id = $obj->rowid;
621 $accountstatic->label = $obj->label;
622 $accountstatic->account_number = $obj->account_number;
623
624 print '<tr class="oddeven">';
625
626 // Action column
627 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
628 print '<td class="center nowraponall">';
629 // if ($permissiontoadd) { // test is always true
630 print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
631 print img_edit();
632 print '</a>';
633 print '&nbsp;';
634 print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
635 print img_delete();
636 print '</a>';
637 print '&nbsp;';
638 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
639 $selected = 0;
640 if (in_array($obj->rowid, $arrayofselected)) {
641 $selected = 1;
642 }
643 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
644 }
645 // }
646 print '</td>'."\n";
647 if (!$i) {
648 $totalarray['nbfield']++;
649 }
650 }
651
652 // Account number
653 if (!empty($arrayfields['aa.account_number']['checked'])) {
654 print "<td>";
655 print $accountstatic->getNomUrl(1, 0, 0, '', 0, 1, 0, 'accountcard');
656 print "</td>\n";
657 if (!$i) {
658 $totalarray['nbfield']++;
659 }
660 }
661
662 // Account label
663 if (!empty($arrayfields['aa.label']['checked'])) {
664 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->label).'">';
665 print dol_escape_htmltag($obj->label);
666 print "</td>\n";
667 if (!$i) {
668 $totalarray['nbfield']++;
669 }
670 }
671
672 // Account label to show (label short)
673 if (!empty($arrayfields['aa.labelshort']['checked'])) {
674 print "<td>";
675 print dol_escape_htmltag($obj->labelshort);
676 print "</td>\n";
677 if (!$i) {
678 $totalarray['nbfield']++;
679 }
680 }
681
682 // Account parent
683 if (!empty($arrayfields['aa.account_parent']['checked'])) {
684 // Note: obj->account_parent is a foreign key to a rowid. It is field in child table and obj->rowid2 is same, but in parent table.
685 // So for orphans, obj->account_parent is set but not obj->rowid2
686 if (!empty($obj->account_parent) && !empty($obj->rowid2)) {
687 print "<td>";
688 print '<!-- obj->account_parent = '.$obj->account_parent.' obj->rowid2 = '.$obj->rowid2.' -->';
689 $accountparent->id = $obj->rowid2;
690 $accountparent->label = $obj->label2;
691 $accountparent->account_number = $obj->account_number2; // Store an account number for output
692 print $accountparent->getNomUrl(1);
693 print "</td>\n";
694 if (!$i) {
695 $totalarray['nbfield']++;
696 }
697 } else {
698 print '<td>';
699 if (!empty($obj->account_parent)) {
700 print '<!-- Bad value for obj->account_parent = '.$obj->account_parent.': is a rowid that does not exists -->';
701 }
702 print '</td>';
703 if (!$i) {
704 $totalarray['nbfield']++;
705 }
706 }
707 }
708
709 // Predefined group (deprecated)
710 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
711 print "<td>";
712 print dol_escape_htmltag($obj->pcg_type);
713 print "</td>\n";
714 if (!$i) {
715 $totalarray['nbfield']++;
716 }
717 }
718 // Custom accounts
719 if (!empty($arrayfields['categories']['checked'])) {
720 print "<td>";
721 // TODO Get all custom groups labels the account is in
722 print dol_escape_htmltag($obj->fk_accounting_category);
723 print "</td>\n";
724 if (!$i) {
725 $totalarray['nbfield']++;
726 }
727 }
728
729 // Fields from hook
730 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
731 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
732 print $hookmanager->resPrint;
733
734 // Import id
735 if (!empty($arrayfields['aa.import_key']['checked'])) {
736 print "<td>";
737 print dol_escape_htmltag($obj->import_key);
738 print "</td>\n";
739 if (!$i) {
740 $totalarray['nbfield']++;
741 }
742 }
743
744 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
745 // Activated or not reconciliation on an accounting account
746 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
747 print '<td class="center">';
748 if (empty($obj->reconcilable)) {
749 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=1&token='.newToken().'">';
750 print img_picto($langs->trans("Disabled"), 'switch_off');
751 print '</a>';
752 } else {
753 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=1&token='.newToken().'">';
754 print img_picto($langs->trans("Activated"), 'switch_on');
755 print '</a>';
756 }
757 print '</td>';
758 if (!$i) {
759 $totalarray['nbfield']++;
760 }
761 }
762 }
763
764 // Activated or not
765 if (!empty($arrayfields['aa.active']['checked'])) {
766 print '<td class="center">';
767 if (empty($obj->active)) {
768 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=0&token='.newToken().'">';
769 print img_picto($langs->trans("Disabled"), 'switch_off');
770 print '</a>';
771 } else {
772 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=0&token='.newToken().'">';
773 print img_picto($langs->trans("Activated"), 'switch_on');
774 print '</a>';
775 }
776 print '</td>';
777 if (!$i) {
778 $totalarray['nbfield']++;
779 }
780 }
781
782 // Action column
783 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
784 print '<td class="center nowraponall">';
785 // if ($permissiontoadd) { // test is always true
786 print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
787 print img_edit();
788 print '</a>';
789 print '&nbsp;';
790 print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
791 print img_delete();
792 print '</a>';
793 print '&nbsp;';
794 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
795 $selected = 0;
796 if (in_array($obj->rowid, $arrayofselected)) {
797 $selected = 1;
798 }
799 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
800 }
801 // }
802 print '</td>'."\n";
803 if (!$i) {
804 $totalarray['nbfield']++;
805 }
806 }
807
808 print "</tr>\n";
809 $i++;
810 }
811
812 if ($num == 0) {
813 $colspan = 1;
814 foreach ($arrayfields as $key => $val) {
815 if (!empty($val['checked'])) {
816 $colspan++;
817 }
818 }
819 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
820 }
821
822 $db->free($resql);
823
824 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
825 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
826 print $hookmanager->resPrint;
827
828 print '</table>'."\n";
829 print '</div>'."\n";
830
831 print '</form>'."\n";
832} else {
833 dol_print_error($db);
834}
835
836// End of page
837llxFooter();
838$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
run_sql($sqlfile, $silent=1, $entity=0, $usesavepoint=1, $handler='', $okerror='default', $linelengthlimit=32768, $nocommentremoval=0, $offsetforchartofaccount=0, $colspan=0, $onlysqltoimportwebsite=0, $database='')
Launch a sql file.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:459
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
Class to manage accounting accounts.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show 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...
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.