27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
33 $langs->loadLangs(array(
"accountancy",
"admin",
"bills",
"compta",
"errors",
"hrm",
"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') :
'accountingsubaccountlist';
44 $search_subaccount =
GETPOST(
'search_subaccount',
'alpha');
45 $search_label =
GETPOST(
'search_label',
'alpha');
46 $search_type =
GETPOST(
'search_type',
'int');
49 if ($user->socid > 0) {
52 if (!$user->hasRight(
'accounting',
'chartofaccount')) {
57 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
58 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
59 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
61 if (empty($page) || $page == -1) {
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
75 'subaccount'=>array(
'label'=>$langs->trans(
"AccountNumber"),
'checked'=>1),
76 'label'=>array(
'label'=>$langs->trans(
"Label"),
'checked'=>1),
77 'type'=>array(
'label'=>$langs->trans(
"Type"),
'checked'=>1),
78 'reconcilable'=>array(
'label'=>$langs->trans(
"Reconcilable"),
'checked'=>1)
81 if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
82 unset($arrayfields[
'reconcilable']);
90 if (
GETPOST(
'cancel',
'alpha')) {
91 $action =
'list'; $massaction =
'';
93 if (!
GETPOST(
'confirmmassaction',
'alpha')) {
97 $parameters = array();
98 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
103 if (empty($reshook)) {
104 if (!empty($cancel)) {
108 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
110 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
111 $search_subaccount =
"";
114 $search_array_options = array();
127 $help_url =
'EN:Module_Double_Entry_Accounting#Setup';
128 $title = $langs->trans(
'ChartOfIndividualAccountsOfSubsidiaryLedger');
133 $sql =
"SELECT sa.rowid, sa.nom as label, sa.code_compta as subaccount, '1' as type, sa.entity";
134 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe sa";
135 $sql .=
" WHERE sa.entity IN (".getEntity(
'societe').
")";
136 $sql .=
" AND sa.code_compta <> ''";
138 if (strlen(trim($search_subaccount))) {
139 $lengthpaddingaccount = 0;
140 if ($conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
141 $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_AACCOUNT);
143 $search_subaccount_tmp = $search_subaccount;
144 $weremovedsomezero = 0;
145 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
146 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
147 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
148 $weremovedsomezero++;
149 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
155 if ($search_subaccount_tmp) {
156 if ($weremovedsomezero) {
157 $search_subaccount_tmp_clean = $search_subaccount_tmp;
158 $search_subaccount_clean = $search_subaccount;
160 if (strpos($search_subaccount_tmp,
'^') === 0) {
162 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
163 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
165 $sql .=
" AND (sa.code_compta LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
166 $sql .=
" OR sa.code_compta LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
172 if (strlen(trim($search_label))) {
175 if (!empty($search_type) && $search_type >= 0) {
176 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
181 $sql .=
" SELECT sa.rowid, sa.nom as label, sa.code_compta_fournisseur as subaccount, '2' as type, sa.entity FROM ".MAIN_DB_PREFIX.
"societe sa";
182 $sql .=
" WHERE sa.entity IN (".getEntity(
'societe').
")";
183 $sql .=
" AND sa.code_compta_fournisseur <> ''";
185 if (strlen(trim($search_subaccount))) {
186 $lengthpaddingaccount = 0;
187 if ($conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
188 $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_AACCOUNT);
190 $search_subaccount_tmp = $search_subaccount;
191 $weremovedsomezero = 0;
192 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
193 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
194 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
195 $weremovedsomezero++;
196 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
202 if ($search_subaccount_tmp) {
203 if ($weremovedsomezero) {
204 $search_subaccount_tmp_clean = $search_subaccount_tmp;
205 $search_subaccount_clean = $search_subaccount;
207 if (strpos($search_subaccount_tmp,
'^') === 0) {
209 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
210 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
212 $sql .=
" AND (sa.code_compta_fournisseur LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
213 $sql .=
" OR sa.code_compta_fournisseur LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
219 if (strlen(trim($search_label))) {
222 if (!empty($search_type) && $search_type >= 0) {
223 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
228 $sql .=
" SELECT u.rowid, u.lastname as label, u.accountancy_code as subaccount, '3' as type, u.entity FROM ".MAIN_DB_PREFIX.
"user u";
229 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
230 $sql .=
" AND u.accountancy_code <> ''";
232 if (strlen(trim($search_subaccount))) {
233 $lengthpaddingaccount = 0;
234 if ($conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
235 $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_AACCOUNT);
237 $search_subaccount_tmp = $search_subaccount;
238 $weremovedsomezero = 0;
239 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
240 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
241 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
242 $weremovedsomezero++;
243 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
249 if ($search_subaccount_tmp) {
250 if ($weremovedsomezero) {
251 $search_subaccount_tmp_clean = $search_subaccount_tmp;
252 $search_subaccount_clean = $search_subaccount;
254 if (strpos($search_subaccount_tmp,
'^') === 0) {
256 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
257 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
259 $sql .=
" AND (u.accountancy_code LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
260 $sql .=
" OR u.accountancy_code LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
266 if (strlen(trim($search_label))) {
269 if (!empty($search_type) && $search_type >= 0) {
270 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
273 $sql .= $db->order($sortfield, $sortorder);
277 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
278 $resql = $db->query(
$sql);
286 $sql .= $db->plimit($limit + 1, $offset);
289 $resql = $db->query(
$sql);
292 $num = $db->num_rows($resql);
295 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
296 $param .=
'&contextpage='.urlencode($contextpage);
298 if ($limit > 0 && $limit != $conf->liste_limit) {
299 $param .=
'&limit='.urlencode($limit);
301 if ($search_subaccount) {
302 $param .=
'&search_subaccount='.urlencode($search_subaccount);
305 $param .=
'&search_label='.urlencode($search_label);
307 if ($optioncss !=
'') {
308 $param .=
'&optioncss='.urlencode($optioncss);
311 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
312 if ($optioncss !=
'') {
313 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
315 print
'<input type="hidden" name="token" value="'.newToken().
'">';
316 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
317 print
'<input type="hidden" name="action" value="list">';
318 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
319 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
320 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
322 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num,
$nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit, 0, 0, 1);
324 print
'<div class="info">'.$langs->trans(
"WarningCreateSubAccounts").
'</div>';
326 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
327 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
330 $massactionbutton =
'';
332 print
'<div class="div-table-responsive">';
333 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
336 print
'<tr class="liste_titre_filter">';
337 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
338 print
'<td class="liste_titre"><input type="text" class="flat" size="10" name="search_subaccount" value="'.$search_subaccount.
'"></td>';
340 if (!empty($arrayfields[
'label'][
'checked'])) {
341 print
'<td class="liste_titre"><input type="text" class="flat" size="20" name="search_label" value="'.$search_label.
'"></td>';
343 if (!empty($arrayfields[
'type'][
'checked'])) {
344 print
'<td class="liste_titre center">'.$form->selectarray(
'search_type', array(
'1'=>$langs->trans(
'Customer'),
'2'=>$langs->trans(
'Supplier'),
'3'=>$langs->trans(
'Employee')), $search_type, 1).
'</td>';
346 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
347 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
348 print
'<td class="liste_titre"> </td>';
351 print
'<td class="liste_titre maxwidthsearch">';
352 $searchpicto =
$form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
357 print
'<tr class="liste_titre">';
358 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
359 print_liste_field_titre($arrayfields[
'subaccount'][
'label'], $_SERVER[
"PHP_SELF"],
"subaccount",
"", $param,
'', $sortfield, $sortorder);
361 if (!empty($arrayfields[
'label'][
'checked'])) {
362 print_liste_field_titre($arrayfields[
'label'][
'label'], $_SERVER[
"PHP_SELF"],
"label",
"", $param,
'', $sortfield, $sortorder);
364 if (!empty($arrayfields[
'type'][
'checked'])) {
365 print_liste_field_titre($arrayfields[
'type'][
'label'], $_SERVER[
"PHP_SELF"],
"type",
"", $param,
'', $sortfield, $sortorder,
'center ');
367 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
368 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
369 print_liste_field_titre($arrayfields[
'reconcilable'][
'label'], $_SERVER[
"PHP_SELF"],
'reconcilable',
'', $param,
'', $sortfield, $sortorder,
'center ');
372 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ');
375 $totalarray = array();
376 $totalarray[
'nbfield'] = 0;
378 while ($i < min($num, $limit)) {
379 $obj = $db->fetch_object($resql);
381 print
'<tr class="oddeven">';
384 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
389 $totalarray[
'nbfield']++;
394 if (!empty($arrayfields[
'label'][
'checked'])) {
399 $totalarray[
'nbfield']++;
404 if (!empty($arrayfields[
'type'][
'checked'])) {
405 print
'<td class="center">';
409 if ($obj->type == 1) {
410 $s .=
'<a class="customer-back" style="padding-left: 6px; padding-right: 6px" title="'.$langs->trans(
"Customer").
'" href="'.DOL_URL_ROOT.
'/comm/card.php?socid='.$obj->rowid.
'">'.$langs->trans(
"Customer").
'</a>';
411 } elseif ($obj->type == 2) {
413 $s .=
'<a class="vendor-back" style="padding-left: 6px; padding-right: 6px" title="'.$langs->trans(
"Supplier").
'" href="'.DOL_URL_ROOT.
'/fourn/card.php?socid='.$obj->rowid.
'">'.$langs->trans(
"Supplier").
'</a>';
414 } elseif ($obj->type == 3) {
416 $s .=
'<a class="user-back" style="padding-left: 6px; padding-right: 6px" title="'.$langs->trans(
"Employee").
'" href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->rowid.
'">'.$langs->trans(
"Employee").
'</a>';
421 $totalarray[
'nbfield']++;
425 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
427 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
428 print
'<td class="center">';
429 if (empty($obj->reconcilable)) {
430 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=enable&mode=1&token='.
newToken().
'">';
431 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
434 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=disable&mode=1&token='.
newToken().
'">';
435 print
img_picto($langs->trans(
"Activated"),
'switch_on');
440 $totalarray[
'nbfield']++;
446 print
'<td class="center">';
450 if ($obj->type == 1) {
451 $e .=
'<a class="editfielda" title="'.$langs->trans(
"Customer").
'" href="'.DOL_URL_ROOT.
'/societe/card.php?action=edit&token='.
newToken().
'&socid='.$obj->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'">'.
img_edit().
'</a>';
452 } elseif ($obj->type == 2) {
454 $e .=
'<a class="editfielda" title="'.$langs->trans(
"Supplier").
'" href="'.DOL_URL_ROOT.
'/societe/card.php?action=edit&token='.
newToken().
'&socid='.$obj->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'">'.
img_edit().
'</a>';
455 } elseif ($obj->type == 3) {
457 $e .=
'<a class="editfielda" title="'.$langs->trans(
"Employee").
'" href="'.DOL_URL_ROOT.
'/user/card.php?action=edit&token='.
newToken().
'&id='.$obj->rowid.
'&backtopage='.urlencode($_SERVER[
"PHP_SELF"]).
'">'.
img_edit().
'</a>';
462 $totalarray[
'nbfield']++;
471 $parameters = array(
'arrayfields'=>$arrayfields,
'sql'=>
$sql);
472 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters);
473 print $hookmanager->resPrint;