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';
34 $langs->loadLangs(array(
'accountancy',
'admin',
'bills',
'compta',
'salaries'));
36 $action =
GETPOST(
'action',
'aZ09');
37 $cancel =
GETPOST(
'cancel',
'alpha');
39 $rowid =
GETPOST(
'rowid',
'int');
40 $massaction =
GETPOST(
'massaction',
'aZ09');
41 $optioncss =
GETPOST(
'optioncss',
'alpha');
42 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'accountingaccountlist';
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');
54 $chartofaccounts =
GETPOST(
'chartofaccounts',
'int');
56 $permissiontoadd = $user->hasRight(
'accounting',
'chartofaccount');
57 $permissiontodelete = $user->hasRight(
'accounting',
'chartofaccount');
60 if ($user->socid > 0) {
63 if (!$user->hasRight(
'accounting',
'chartofaccount')) {
68 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
69 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
70 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
72 if (empty($page) || $page == -1) {
75 $offset = $limit * $page;
76 $pageprev = $page - 1;
77 $pagenext = $page + 1;
79 $sortfield =
"aa.account_number";
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)
98 unset($arrayfields[
'categories']);
99 unset($arrayfields[
'aa.reconcilable']);
105 $hookmanager->initHooks(array(
'accountancyadminaccount'));
112 if (
GETPOST(
'cancel',
'alpha')) {
113 $action =
'list'; $massaction =
'';
115 if (!
GETPOST(
'confirmmassaction',
'alpha')) {
119 $parameters = array(
'chartofaccounts' => $chartofaccounts,
'permissiontoadd' => $permissiontoadd,
'permissiontodelete' => $permissiontodelete);
120 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $accounting, $action);
125 if (empty($reshook)) {
126 if (!empty($cancel)) {
130 $objectclass =
'AccountingAccount';
131 $uploaddir = $conf->accounting->multidir_output[$conf->entity];
132 include DOL_DOCUMENT_ROOT.
'/core/actions_massactions.inc.php';
134 if ($action ==
"delete") {
137 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
139 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
140 $search_account =
"";
142 $search_labelshort =
"";
143 $search_accountparent =
"";
144 $search_pcgtype =
"";
145 $search_array_options = array();
147 if ((
GETPOST(
'valid_change_chart',
'alpha') &&
GETPOST(
'chartofaccounts',
'int') > 0)
149 if ($chartofaccounts > 0 && $permissiontoadd) {
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);
155 $obj = $db->fetch_object($resql);
157 $country_code = $obj->code;
165 $sqlfile = DOL_DOCUMENT_ROOT.
'/install/mysql/data/llx_accounting_account_'.strtolower($country_code).
'.sql';
167 $offsetforchartofaccount = 0;
171 $tmp = file_get_contents($sqlfile);
173 if (preg_match(
'/-- ADD (\d+) to rowid/ims', $tmp, $reg)) {
174 $offsetforchartofaccount += $reg[1];
176 $offsetforchartofaccount += ($conf->entity * 100000000);
178 $result =
run_sql($sqlfile, 1, $conf->entity, 1,
'',
'default', 32768, 0, $offsetforchartofaccount);
187 if (!
dolibarr_set_const($db,
'CHARTOFACCOUNTS', $chartofaccounts,
'chaine', 0,
'', $conf->entity)) {
195 if ($action ==
'disable' && $permissiontoadd) {
196 if ($accounting->fetch($id)) {
197 $mode =
GETPOST(
'mode',
'int');
198 $result = $accounting->accountDeactivate($id, $mode);
205 } elseif ($action ==
'enable' && $permissiontoadd) {
206 if ($accounting->fetch($id)) {
207 $mode =
GETPOST(
'mode',
'int');
208 $result = $accounting->accountActivate($id, $mode);
225 llxHeader(
'', $langs->trans(
"ListAccounts"));
227 if ($action ==
'delete') {
228 $formconfirm = $html->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$id, $langs->trans(
'DeleteAccount'), $langs->trans(
'ConfirmDeleteAccount'),
'confirm_delete',
'', 0, 1);
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);
242 if (strlen(trim($search_account))) {
243 $lengthpaddingaccount = 0;
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);
259 if ($search_account_tmp) {
260 if ($weremovedsomezero) {
261 $search_account_tmp_clean = $search_account_tmp;
262 $search_account_clean = $search_account;
264 if (substr($search_account_tmp, 0, 1) ===
'^') {
266 $search_account_tmp_clean = preg_replace(
'/^\^/',
'', $search_account_tmp);
267 $search_account_clean = preg_replace(
'/^\^/',
'', $search_account);
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).
"%')";
276 if (strlen(trim($search_label))) {
279 if (strlen(trim($search_labelshort))) {
282 if (strlen(trim($search_accountparent)) && $search_accountparent !=
'-1') {
285 if (strlen(trim($search_pcgtype))) {
288 $sql .= $db->order($sortfield, $sortorder);
292 $nbtotalofrecords =
'';
294 $resql = $db->query(
$sql);
295 $nbtotalofrecords = $db->num_rows($resql);
296 if (($page * $limit) > $nbtotalofrecords) {
303 if ($user->hasRight(
'accounting',
'chartofaccount')) {
304 $arrayofmassactions[
'predelete'] =
'<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans(
"Delete");
306 if (in_array($massaction, array(
'presend',
'predelete',
'closed'))) {
307 $arrayofmassactions = array();
310 $massactionbutton =
$form->selectMassAction(
'', $arrayofmassactions);
311 $arrayofselected = is_array($toselect) ? $toselect : array();
312 $sql .= $db->plimit($limit + 1, $offset);
315 $resql = $db->query(
$sql);
318 $num = $db->num_rows($resql);
321 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
322 $param .=
'&contextpage='.urlencode($contextpage);
324 if ($limit > 0 && $limit != $conf->liste_limit) {
325 $param .=
'&limit='.((int) $limit);
327 if ($search_account) {
328 $param .=
'&search_account='.urlencode($search_account);
331 $param .=
'&search_label='.urlencode($search_label);
333 if ($search_labelshort) {
334 $param .=
'&search_labelshort='.urlencode($search_labelshort);
336 if ($search_accountparent > 0 || $search_accountparent ==
'0') {
337 $param .=
'&search_accountparent='.urlencode($search_accountparent);
339 if ($search_pcgtype) {
340 $param .=
'&search_pcgtype='.urlencode($search_pcgtype);
342 if ($optioncss !=
'') {
343 $param .=
'&search_import_key='.urlencode($search_import_key);
345 if ($optioncss !=
'') {
346 $param .=
'&optioncss='.urlencode($optioncss);
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());
356 window.location.href = "'.$_SERVER[
"PHP_SELF"].
'?valid_change_chart=1&chartofaccounts="+$("#chartofaccounts").val();
364 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
365 if ($optioncss !=
'') {
366 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
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.
'">';
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);
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";
388 $resqlchart = $db->query(
$sql);
390 $numbis = $db->num_rows($resqlchart);
392 print
'<option value="-1"> </option>';
393 while ($i < $numbis) {
394 $obj = $db->fetch_object($resqlchart);
396 print
'<option value="'.$obj->rowid.
'"';
397 print ($pcgver == $obj->rowid) ?
' selected' :
'';
398 print
'>'.$obj->pcg_version.
' - '.$obj->label.
' - ('.$obj->country_code.
')</option>';
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")).
'">';
411 $parameters = array(
'chartofaccounts' => $chartofaccounts,
'permissiontoadd' => $permissiontoadd,
'permissiontodelete' => $permissiontodelete);
412 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $accounting, $action);
413 print $hookmanager->resPrint;
417 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
418 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
419 $selectedfields .= (count($arrayofmassactions) ?
$form->showCheckAddButtons(
'checkforselect', 1) :
'');
425 $totalarray = array();
426 $totalarray[
'nbfield'] = 0;
428 print
'<div class="div-table-responsive">';
429 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
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>';
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>';
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>';
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');
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>';
452 if (!empty($arrayfields[
'categories'][
'checked'])) {
453 print
'<td class="liste_titre"></td>';
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>';
459 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
460 if (!empty($arrayfields[
'aa.reconcilable'][
'checked'])) {
461 print
'<td class="liste_titre"> </td>';
464 if (!empty($arrayfields[
'aa.active'][
'checked'])) {
465 print
'<td class="liste_titre"> </td>';
467 print
'<td class="liste_titre maxwidthsearch">';
468 $searchpicto =
$form->showFilterButtons();
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);
476 if (!empty($arrayfields[
'aa.label'][
'checked'])) {
477 print_liste_field_titre($arrayfields[
'aa.label'][
'label'], $_SERVER[
"PHP_SELF"],
"aa.label",
"", $param,
'', $sortfield, $sortorder);
479 if (!empty($arrayfields[
'aa.labelshort'][
'checked'])) {
480 print_liste_field_titre($arrayfields[
'aa.labelshort'][
'label'], $_SERVER[
"PHP_SELF"],
"aa.labelshort",
"", $param,
'', $sortfield, $sortorder);
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 ');
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);
488 if (!empty($arrayfields[
'categories'][
'checked'])) {
489 print_liste_field_titre($arrayfields[
'categories'][
'label'], $_SERVER[
"PHP_SELF"],
'',
'', $param,
'', $sortfield, $sortorder,
'', $arrayfields[
'categories'][
'help'], 1);
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);
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);
499 if (!empty($arrayfields[
'aa.active'][
'checked'])) {
500 print_liste_field_titre($arrayfields[
'aa.active'][
'label'], $_SERVER[
"PHP_SELF"],
'aa.active',
'', $param,
'', $sortfield, $sortorder);
502 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ');
506 while ($i < min($num, $limit)) {
507 $obj = $db->fetch_object($resql);
509 $accountstatic->id = $obj->rowid;
510 $accountstatic->label = $obj->label;
511 $accountstatic->account_number = $obj->account_number;
513 print
'<tr class="oddeven">';
516 if (!empty($arrayfields[
'aa.account_number'][
'checked'])) {
518 print $accountstatic->getNomUrl(1, 0, 0,
'', 0, 1, 0,
'accountcard');
521 $totalarray[
'nbfield']++;
526 if (!empty($arrayfields[
'aa.label'][
'checked'])) {
531 $totalarray[
'nbfield']++;
536 if (!empty($arrayfields[
'aa.labelshort'][
'checked'])) {
541 $totalarray[
'nbfield']++;
546 if (!empty($arrayfields[
'aa.account_parent'][
'checked'])) {
549 if (!empty($obj->account_parent) && !empty($obj->rowid2)) {
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;
555 print $accountparent->getNomUrl(1);
558 $totalarray[
'nbfield']++;
562 if (!empty($obj->account_parent)) {
563 print
'<!-- Bad value for obj->account_parent = '.$obj->account_parent.
': is a rowid that does not exists -->';
567 $totalarray[
'nbfield']++;
573 if (!empty($arrayfields[
'aa.pcg_type'][
'checked'])) {
578 $totalarray[
'nbfield']++;
582 if (!empty($arrayfields[
'categories'][
'checked'])) {
588 $totalarray[
'nbfield']++;
593 if (!empty($arrayfields[
'aa.import_key'][
'checked'])) {
598 $totalarray[
'nbfield']++;
602 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
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');
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');
617 $totalarray[
'nbfield']++;
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');
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');
636 $totalarray[
'nbfield']++;
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).
'">';
647 print
'<a class="marginleftonly" href="./card.php?action=delete&token='.newToken().
'&id='.$obj->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?'.$param).
'">';
651 if ($massactionbutton || $massaction) {
653 if (in_array($obj->rowid, $arrayofselected)) {
656 print
'<input id="cb'.$obj->rowid.
'" class="flat checkforselect marginleftonly" type="checkbox" name="toselect[]" value="'.$obj->rowid.
'"'.($selected ?
' checked="checked"' :
'').
'>';
661 $totalarray[
'nbfield']++;
670 foreach ($arrayfields as $key => $val) {
671 if (!empty($val[
'checked'])) {
675 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';