dolibarr 18.0.6
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-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
4 * Copyright (C) 2016-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
32
33// Load translation files required by the page
34$langs->loadLangs(array('accountancy', 'admin', 'bills', 'compta', 'salaries'));
35
36$action = GETPOST('action', 'aZ09');
37$cancel = GETPOST('cancel', 'alpha');
38$id = GETPOST('id', 'int');
39$rowid = GETPOST('rowid', 'int');
40$massaction = GETPOST('massaction', 'aZ09');
41$optioncss = GETPOST('optioncss', 'alpha');
42$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'accountingaccountlist'; // To manage different context of search
43$mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
44
45$search_account = GETPOST('search_account', 'alpha');
46$search_label = GETPOST('search_label', 'alpha');
47$search_labelshort = GETPOST('search_labelshort', 'alpha');
48$search_accountparent = GETPOST('search_accountparent', 'alpha');
49$search_pcgtype = GETPOST('search_pcgtype', 'alpha');
50$search_import_key = GETPOST('search_import_key', 'alpha');
51$toselect = GETPOST('toselect', 'array');
52$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
53$confirm = GETPOST('confirm', 'alpha');
54
55$chartofaccounts = GETPOST('chartofaccounts', 'int');
56
57$permissiontoadd = $user->hasRight('accounting', 'chartofaccount');
58$permissiontodelete = $user->hasRight('accounting', 'chartofaccount');
59
60// Security check
61if ($user->socid > 0) {
63}
64if (!$user->hasRight('accounting', 'chartofaccount')) {
66}
67
68// Load variable for pagination
69$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
70$sortfield = GETPOST('sortfield', 'aZ09comma');
71$sortorder = GETPOST('sortorder', 'aZ09comma');
72$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
73if (empty($page) || $page == -1) {
74 $page = 0;
75} // If $page is not defined, or '' or -1
76$offset = $limit * $page;
77$pageprev = $page - 1;
78$pagenext = $page + 1;
79if (!$sortfield) {
80 $sortfield = "aa.account_number";
81}
82if (!$sortorder) {
83 $sortorder = "ASC";
84}
85
86$arrayfields = array(
87 'aa.account_number'=>array('label'=>"AccountNumber", 'checked'=>1),
88 'aa.label'=>array('label'=>"Label", 'checked'=>1),
89 'aa.labelshort'=>array('label'=>"LabelToShow", 'checked'=>1),
90 'aa.account_parent'=>array('label'=>"Accountparent", 'checked'=>1),
91 'aa.pcg_type'=>array('label'=>"Pcgtype", 'checked'=>1, 'help'=>'PcgtypeDesc'),
92 'categories'=>array('label'=>"AccountingCategories", 'checked'=>-1, 'help'=>'AccountingCategoriesDesc'),
93 'aa.reconcilable'=>array('label'=>"Reconcilable", 'checked'=>1),
94 'aa.import_key'=>array('label'=>"ImportId", 'checked'=>-1, 'help'=>''),
95 'aa.active'=>array('label'=>"Activated", 'checked'=>1)
96);
97
98if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
99 unset($arrayfields['categories']);
100 unset($arrayfields['aa.reconcilable']);
101}
102
103$accounting = new AccountingAccount($db);
104
105// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
106$hookmanager->initHooks(array('accountancyadminaccount'));
107
108
109/*
110 * Actions
111 */
112
113if (GETPOST('cancel', 'alpha')) {
114 $action = 'list'; $massaction = '';
115}
116if (!GETPOST('confirmmassaction', 'alpha')) {
117 $massaction = '';
118}
119
120$parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
121$reshook = $hookmanager->executeHooks('doActions', $parameters, $accounting, $action); // Note that $action and $object may have been monowraponalldified by some hooks
122if ($reshook < 0) {
123 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
124}
125
126if (empty($reshook)) {
127 if (!empty($cancel)) {
128 $action = '';
129 }
130
131 $objectclass = 'AccountingAccount';
132 $uploaddir = $conf->accounting->multidir_output[$conf->entity];
133 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
134
135 if ($action == "delete") {
136 $action = "";
137 }
138 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
139
140 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
141 $search_account = "";
142 $search_label = "";
143 $search_labelshort = "";
144 $search_accountparent = "";
145 $search_pcgtype = "";
146 $search_array_options = array();
147 }
148 if ((GETPOST('valid_change_chart', 'alpha') && GETPOST('chartofaccounts', 'int') > 0) // explicit click on button 'Change and load' with js on
149 || (GETPOST('chartofaccounts', 'int') > 0 && GETPOST('chartofaccounts', 'int') != getDolGlobalInt('CHARTOFACCOUNTS'))) { // a submit of form is done and chartofaccounts combo has been modified
150 if ($chartofaccounts > 0 && $permissiontoadd) {
151 // Get language code for this $chartofaccounts
152 $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_country as c, '.MAIN_DB_PREFIX.'accounting_system as a';
153 $sql .= ' WHERE c.rowid = a.fk_country AND a.rowid = '.(int) $chartofaccounts;
154 $resql = $db->query($sql);
155 if ($resql) {
156 $obj = $db->fetch_object($resql);
157 $country_code = $obj->code;
158 } else {
159 dol_print_error($db);
160 }
161
162 // Try to load sql file
163 if ($country_code) {
164 $sqlfile = DOL_DOCUMENT_ROOT.'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).'.sql';
165
166 $offsetforchartofaccount = 0;
167 // Get the comment line '-- ADD CCCNNNNN to rowid...' to find CCCNNNNN (CCC is country num, NNNNN is id of accounting account)
168 // 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.
169 // This is to be sure there is no conflict for each chart of account, whatever is country, whatever is company when multicompany is used.
170 $tmp = file_get_contents($sqlfile);
171 $reg = array();
172 if (preg_match('/-- ADD (\d+) to rowid/ims', $tmp, $reg)) {
173 $offsetforchartofaccount += $reg[1];
174 }
175 $offsetforchartofaccount += ($conf->entity * 100000000);
176
177 $result = run_sql($sqlfile, 1, $conf->entity, 1, '', 'default', 32768, 0, $offsetforchartofaccount);
178
179 if ($result > 0) {
180 setEventMessages($langs->trans("ChartLoaded"), null, 'mesgs');
181 } else {
182 setEventMessages($langs->trans("ErrorDuringChartLoad"), null, 'warnings');
183 }
184 }
185
186 if (!dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
187 $error++;
188 }
189 } else {
190 $error++;
191 }
192 }
193
194 if ($action == 'disable' && $permissiontoadd) {
195 if ($accounting->fetch($id)) {
196 $mode = GETPOST('mode', 'int');
197 $result = $accounting->accountDeactivate($id, $mode);
198 }
199
200 $action = 'update';
201 if ($result < 0) {
202 setEventMessages($accounting->error, $accounting->errors, 'errors');
203 }
204 } elseif ($action == 'enable' && $permissiontoadd) {
205 if ($accounting->fetch($id)) {
206 $mode = GETPOST('mode', 'int');
207 $result = $accounting->accountActivate($id, $mode);
208 }
209 $action = 'update';
210 if ($result < 0) {
211 setEventMessages($accounting->error, $accounting->errors, 'errors');
212 }
213 }
214}
215
216
217/*
218 * View
219 */
220
221$form = new Form($db);
222$formaccounting = new FormAccounting($db);
223
224llxHeader('', $langs->trans("ListAccounts"));
225
226if ($action == 'delete') {
227 $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteAccount'), $langs->trans('ConfirmDeleteAccount'), 'confirm_delete', '', 0, 1);
228 print $formconfirm;
229}
230
231$pcgver = getDolGlobalInt('CHARTOFACCOUNTS');
232
233$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,";
234$sql .= " aa.reconcilable, aa.active, aa.import_key,";
235$sql .= " a2.rowid as rowid2, a2.label as label2, a2.account_number as account_number2";
236$sql .= " FROM ".MAIN_DB_PREFIX."accounting_account as aa";
237$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version AND aa.entity = ".((int) $conf->entity);
238$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as a2 ON a2.rowid = aa.account_parent AND a2.entity = ".((int) $conf->entity);
239$sql .= " WHERE asy.rowid = ".((int) $pcgver);
240//print $sql;
241if (strlen(trim($search_account))) {
242 $lengthpaddingaccount = 0;
243 if (getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT') || getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT')) {
244 $lengthpaddingaccount = max(getDolGlobalInt('ACCOUNTING_LENGTH_GACCOUNT'), getDolGlobalInt('ACCOUNTING_LENGTH_AACCOUNT'));
245 }
246 $search_account_tmp = $search_account;
247 $weremovedsomezero = 0;
248 if (strlen($search_account_tmp) <= $lengthpaddingaccount) {
249 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
250 if (preg_match('/0$/', $search_account_tmp)) {
251 $weremovedsomezero++;
252 $search_account_tmp = preg_replace('/0$/', '', $search_account_tmp);
253 }
254 }
255 }
256
257 //var_dump($search_account); exit;
258 if ($search_account_tmp) {
259 if ($weremovedsomezero) {
260 $search_account_tmp_clean = $search_account_tmp;
261 $search_account_clean = $search_account;
262 $startchar = '%';
263 if (strpos($search_account_tmp, '^') === 0) {
264 $startchar = '';
265 $search_account_tmp_clean = preg_replace('/^\^/', '', $search_account_tmp);
266 $search_account_clean = preg_replace('/^\^/', '', $search_account);
267 }
268 $sql .= " AND (aa.account_number LIKE '".$db->escape($startchar.$search_account_tmp_clean)."'";
269 $sql .= " OR aa.account_number LIKE '".$db->escape($startchar.$search_account_clean)."%')";
270 } else {
271 $sql .= natural_search("aa.account_number", $search_account_tmp);
272 }
273 }
274}
275if (strlen(trim($search_label))) {
276 $sql .= natural_search("aa.label", $search_label);
277}
278if (strlen(trim($search_labelshort))) {
279 $sql .= natural_search("aa.labelshort", $search_labelshort);
280}
281if (strlen(trim($search_accountparent)) && $search_accountparent != '-1') {
282 $sql .= natural_search("aa.account_parent", $search_accountparent, 2);
283}
284if (strlen(trim($search_pcgtype))) {
285 $sql .= natural_search("aa.pcg_type", $search_pcgtype);
286}
287$sql .= $db->order($sortfield, $sortorder);
288//print $sql;
289
290// Count total nb of records
291$nbtotalofrecords = '';
292if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
293 $resql = $db->query($sql);
294 $nbtotalofrecords = $db->num_rows($resql);
295 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
296 $page = 0;
297 $offset = 0;
298 }
299}
300
301// List of mass actions available
302if ($user->hasRight('accounting', 'chartofaccount')) {
303 $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
304}
305if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
306 $arrayofmassactions = array();
307}
308
309$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
310$arrayofselected = is_array($toselect) ? $toselect : array();
311$sql .= $db->plimit($limit + 1, $offset);
312
313dol_syslog('accountancy/admin/account.php:: $sql='.$sql);
314$resql = $db->query($sql);
315
316if ($resql) {
317 $num = $db->num_rows($resql);
318
319 $param = '';
320 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
321 $param .= '&contextpage='.urlencode($contextpage);
322 }
323 if ($limit > 0 && $limit != $conf->liste_limit) {
324 $param .= '&limit='.((int) $limit);
325 }
326 if ($search_account) {
327 $param .= '&search_account='.urlencode($search_account);
328 }
329 if ($search_label) {
330 $param .= '&search_label='.urlencode($search_label);
331 }
332 if ($search_labelshort) {
333 $param .= '&search_labelshort='.urlencode($search_labelshort);
334 }
335 if ($search_accountparent > 0 || $search_accountparent == '0') {
336 $param .= '&search_accountparent='.urlencode($search_accountparent);
337 }
338 if ($search_pcgtype) {
339 $param .= '&search_pcgtype='.urlencode($search_pcgtype);
340 }
341 if ($optioncss != '') {
342 $param .= '&search_import_key='.urlencode($search_import_key);
343 }
344 if ($optioncss != '') {
345 $param .= '&optioncss='.urlencode($optioncss);
346 }
347
348 if (!empty($conf->use_javascript_ajax)) {
349 print '<!-- Add javascript to reload page when we click "Change plan" -->
350 <script type="text/javascript">
351 $(document).ready(function () {
352 $("#change_chart").on("click", function (e) {
353 console.log("chartofaccounts seleted = "+$("#chartofaccounts").val());
354 // reload page
355 window.location.href = "'.$_SERVER["PHP_SELF"].'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
356 });
357 });
358 </script>';
359 }
360
361 $newcardbutton = '';
362
363 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
364 if ($optioncss != '') {
365 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
366 }
367 print '<input type="hidden" name="token" value="'.newToken().'">';
368 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
369 print '<input type="hidden" name="action" value="list">';
370 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
371 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
372 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
373
374 $newcardbutton .= dolGetButtonTitle($langs->trans("New"), $langs->trans("Addanaccount"), 'fa fa-plus-circle', './card.php?action=create');
375 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
376 print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accounting_account', 0, $newcardbutton, '', $limit, 0, 0, 1);
377
378 // Box to select active chart of account
379 print $langs->trans("Selectchartofaccounts")." : ";
380 print '<select class="flat minwidth200" name="chartofaccounts" id="chartofaccounts">';
381 $sql = "SELECT a.rowid, a.pcg_version, a.label, a.active, c.code as country_code";
382 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_system as a";
383 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country = c.rowid AND c.active = 1";
384 $sql .= " WHERE a.active = 1";
385 dol_syslog('accountancy/admin/account.php $sql='.$sql);
386
387 $resqlchart = $db->query($sql);
388 if ($resqlchart) {
389 $numbis = $db->num_rows($resqlchart);
390 $i = 0;
391 print '<option value="-1">&nbsp;</option>';
392 while ($i < $numbis) {
393 $obj = $db->fetch_object($resqlchart);
394
395 print '<option value="'.$obj->rowid.'"';
396 print ($pcgver == $obj->rowid) ? ' selected' : '';
397 print '>'.$obj->pcg_version.' - '.$obj->label.' - ('.$obj->country_code.')</option>';
398
399 $i++;
400 }
401 } else {
402 dol_print_error($db);
403 }
404 print "</select>";
405 print ajax_combobox("chartofaccounts");
406 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")).'">';
407
408 print '<br>';
409
410 $parameters = array('chartofaccounts' => $chartofaccounts, 'permissiontoadd' => $permissiontoadd, 'permissiontodelete' => $permissiontodelete);
411 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $accounting, $action); // Note that $action and $object may have been modified by hook
412 print $hookmanager->resPrint;
413
414 print '<br>';
415
416 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
417 $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
418 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
419
420 $moreforfilter = '';
421
422 $accountstatic = new AccountingAccount($db);
423 $accountparent = new AccountingAccount($db);
424 $totalarray = array();
425 $totalarray['nbfield'] = 0;
426
427 print '<div class="div-table-responsive">';
428 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
429
430 // Line for search fields
431 print '<tr class="liste_titre_filter">';
432 // Action column
433 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
434 print '<td class="liste_titre maxwidthsearch">';
435 $searchpicto = $form->showFilterButtons();
436 print $searchpicto;
437 print '</td>';
438 }
439 if (!empty($arrayfields['aa.account_number']['checked'])) {
440 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_account" value="'.$search_account.'"></td>';
441 }
442 if (!empty($arrayfields['aa.label']['checked'])) {
443 print '<td class="liste_titre"><input type="text" class="flat width150" name="search_label" value="'.$search_label.'"></td>';
444 }
445 if (!empty($arrayfields['aa.labelshort']['checked'])) {
446 print '<td class="liste_titre"><input type="text" class="flat width100" name="search_labelshort" value="'.$search_labelshort.'"></td>';
447 }
448 if (!empty($arrayfields['aa.account_parent']['checked'])) {
449 print '<td class="liste_titre">';
450 print $formaccounting->select_account($search_accountparent, 'search_accountparent', 2, array(), 0, 0, 'maxwidth150');
451 print '</td>';
452 }
453 // Predefined group
454 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
455 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_pcgtype" value="'.$search_pcgtype.'"></td>';
456 }
457 // Custom groups
458 if (!empty($arrayfields['categories']['checked'])) {
459 print '<td class="liste_titre"></td>';
460 }
461 // Import key
462 if (!empty($arrayfields['aa.import_key']['checked'])) {
463 print '<td class="liste_titre"><input type="text" class="flat width75" name="search_import_key" value="'.$search_import_key.'"></td>';
464 }
465 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
466 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
467 print '<td class="liste_titre">&nbsp;</td>';
468 }
469 }
470 if (!empty($arrayfields['aa.active']['checked'])) {
471 print '<td class="liste_titre">&nbsp;</td>';
472 }
473 // Action column
474 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
475 print '<td class="liste_titre maxwidthsearch">';
476 $searchpicto = $form->showFilterButtons();
477 print $searchpicto;
478 print '</td>';
479 }
480 print '</tr>';
481 print '<tr class="liste_titre">';
482 // Action column
483 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
484 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
485 }
486 if (!empty($arrayfields['aa.account_number']['checked'])) {
487 print_liste_field_titre($arrayfields['aa.account_number']['label'], $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
488 }
489 if (!empty($arrayfields['aa.label']['checked'])) {
490 print_liste_field_titre($arrayfields['aa.label']['label'], $_SERVER["PHP_SELF"], "aa.label", "", $param, '', $sortfield, $sortorder);
491 }
492 if (!empty($arrayfields['aa.labelshort']['checked'])) {
493 print_liste_field_titre($arrayfields['aa.labelshort']['label'], $_SERVER["PHP_SELF"], "aa.labelshort", "", $param, '', $sortfield, $sortorder);
494 }
495 if (!empty($arrayfields['aa.account_parent']['checked'])) {
496 print_liste_field_titre($arrayfields['aa.account_parent']['label'], $_SERVER["PHP_SELF"], "aa.account_parent", "", $param, '', $sortfield, $sortorder, 'left ');
497 }
498 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
499 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);
500 }
501 if (!empty($arrayfields['categories']['checked'])) {
502 print_liste_field_titre($arrayfields['categories']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '', $arrayfields['categories']['help'], 1);
503 }
504 if (!empty($arrayfields['aa.import_key']['checked'])) {
505 print_liste_field_titre($arrayfields['aa.import_key']['label'], $_SERVER["PHP_SELF"], 'aa.import_key', '', $param, '', $sortfield, $sortorder, '', $arrayfields['aa.import_key']['help'], 1);
506 }
507 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
508 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
509 print_liste_field_titre($arrayfields['aa.reconcilable']['label'], $_SERVER["PHP_SELF"], 'aa.reconcilable', '', $param, '', $sortfield, $sortorder);
510 }
511 }
512 if (!empty($arrayfields['aa.active']['checked'])) {
513 print_liste_field_titre($arrayfields['aa.active']['label'], $_SERVER["PHP_SELF"], 'aa.active', '', $param, '', $sortfield, $sortorder);
514 }
515 // Action column
516 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
517 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
518 }
519 print "</tr>\n";
520
521 $i = 0;
522 while ($i < min($num, $limit)) {
523 $obj = $db->fetch_object($resql);
524
525 $accountstatic->id = $obj->rowid;
526 $accountstatic->label = $obj->label;
527 $accountstatic->account_number = $obj->account_number;
528
529 print '<tr class="oddeven">';
530
531 // Action column
532 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
533 print '<td class="center nowraponall">';
534 if ($user->hasRight('accounting', 'chartofaccount')) {
535 print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
536 print img_edit();
537 print '</a>';
538 print '&nbsp;';
539 print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
540 print img_delete();
541 print '</a>';
542 print '&nbsp;';
543 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
544 $selected = 0;
545 if (in_array($obj->rowid, $arrayofselected)) {
546 $selected = 1;
547 }
548 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
549 }
550 }
551 print '</td>'."\n";
552 if (!$i) {
553 $totalarray['nbfield']++;
554 }
555 }
556
557 // Account number
558 if (!empty($arrayfields['aa.account_number']['checked'])) {
559 print "<td>";
560 print $accountstatic->getNomUrl(1, 0, 0, '', 0, 1, 0, 'accountcard');
561 print "</td>\n";
562 if (!$i) {
563 $totalarray['nbfield']++;
564 }
565 }
566
567 // Account label
568 if (!empty($arrayfields['aa.label']['checked'])) {
569 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->label).'">';
570 print dol_escape_htmltag($obj->label);
571 print "</td>\n";
572 if (!$i) {
573 $totalarray['nbfield']++;
574 }
575 }
576
577 // Account label to show (label short)
578 if (!empty($arrayfields['aa.labelshort']['checked'])) {
579 print "<td>";
580 print dol_escape_htmltag($obj->labelshort);
581 print "</td>\n";
582 if (!$i) {
583 $totalarray['nbfield']++;
584 }
585 }
586
587 // Account parent
588 if (!empty($arrayfields['aa.account_parent']['checked'])) {
589 // 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.
590 // So for orphans, obj->account_parent is set but not obj->rowid2
591 if (!empty($obj->account_parent) && !empty($obj->rowid2)) {
592 print "<td>";
593 print '<!-- obj->account_parent = '.$obj->account_parent.' obj->rowid2 = '.$obj->rowid2.' -->';
594 $accountparent->id = $obj->rowid2;
595 $accountparent->label = $obj->label2;
596 $accountparent->account_number = $obj->account_number2; // Sotre an account number for output
597 print $accountparent->getNomUrl(1);
598 print "</td>\n";
599 if (!$i) {
600 $totalarray['nbfield']++;
601 }
602 } else {
603 print '<td>';
604 if (!empty($obj->account_parent)) {
605 print '<!-- Bad value for obj->account_parent = '.$obj->account_parent.': is a rowid that does not exists -->';
606 }
607 print '</td>';
608 if (!$i) {
609 $totalarray['nbfield']++;
610 }
611 }
612 }
613
614 // Predefined group (deprecated)
615 if (!empty($arrayfields['aa.pcg_type']['checked'])) {
616 print "<td>";
617 print dol_escape_htmltag($obj->pcg_type);
618 print "</td>\n";
619 if (!$i) {
620 $totalarray['nbfield']++;
621 }
622 }
623 // Custom accounts
624 if (!empty($arrayfields['categories']['checked'])) {
625 print "<td>";
626 // TODO Get all custom groups labels the account is in
627 print dol_escape_htmltag($obj->fk_accounting_category);
628 print "</td>\n";
629 if (!$i) {
630 $totalarray['nbfield']++;
631 }
632 }
633
634 // Import id
635 if (!empty($arrayfields['aa.import_key']['checked'])) {
636 print "<td>";
637 print dol_escape_htmltag($obj->import_key);
638 print "</td>\n";
639 if (!$i) {
640 $totalarray['nbfield']++;
641 }
642 }
643
644 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
645 // Activated or not reconciliation on accounting account
646 if (!empty($arrayfields['aa.reconcilable']['checked'])) {
647 print '<td class="center">';
648 if (empty($obj->reconcilable)) {
649 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=1&token='.newToken().'">';
650 print img_picto($langs->trans("Disabled"), 'switch_off');
651 print '</a>';
652 } else {
653 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=1&token='.newToken().'">';
654 print img_picto($langs->trans("Activated"), 'switch_on');
655 print '</a>';
656 }
657 print '</td>';
658 if (!$i) {
659 $totalarray['nbfield']++;
660 }
661 }
662 }
663
664 // Activated or not
665 if (!empty($arrayfields['aa.active']['checked'])) {
666 print '<td class="center">';
667 if (empty($obj->active)) {
668 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=enable&mode=0&token='.newToken().'">';
669 print img_picto($langs->trans("Disabled"), 'switch_off');
670 print '</a>';
671 } else {
672 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$obj->rowid.'&action=disable&mode=0&token='.newToken().'">';
673 print img_picto($langs->trans("Activated"), 'switch_on');
674 print '</a>';
675 }
676 print '</td>';
677 if (!$i) {
678 $totalarray['nbfield']++;
679 }
680 }
681
682 // Action column
683 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
684 print '<td class="center nowraponall">';
685 if ($user->hasRight('accounting', 'chartofaccount')) {
686 print '<a class="editfielda" href="./card.php?action=update&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
687 print img_edit();
688 print '</a>';
689 print '&nbsp;';
690 print '<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?'.$param).'">';
691 print img_delete();
692 print '</a>';
693 print '&nbsp;';
694 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
695 $selected = 0;
696 if (in_array($obj->rowid, $arrayofselected)) {
697 $selected = 1;
698 }
699 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
700 }
701 }
702 print '</td>'."\n";
703 if (!$i) {
704 $totalarray['nbfield']++;
705 }
706 }
707
708 print "</tr>\n";
709 $i++;
710 }
711
712 if ($num == 0) {
713 $colspan = 1;
714 foreach ($arrayfields as $key => $val) {
715 if (!empty($val['checked'])) {
716 $colspan++;
717 }
718 }
719 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
720 }
721
722 print "</table>";
723 print "</div>";
724 print '</form>';
725} else {
726 dol_print_error($db);
727}
728
729// End of page
730llxFooter();
731$db->close();
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:464
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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 dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.