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