26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
31 $langs->loadLangs(array(
"compta",
"bills",
"admin",
"accountancy",
"salaries",
"hrm",
"errors"));
34 $action =
GETPOST(
'action',
'aZ09');
35 $cancel =
GETPOST(
'cancel',
'alpha');
37 $rowid =
GETPOST(
'rowid',
'int');
38 $massaction =
GETPOST(
'massaction',
'aZ09');
39 $optioncss =
GETPOST(
'optioncss',
'alpha');
40 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'accountingsubaccountlist';
42 $search_subaccount =
GETPOST(
'search_subaccount',
'alpha');
43 $search_label =
GETPOST(
'search_label',
'alpha');
44 $search_type =
GETPOST(
'search_type',
'int');
47 if ($user->socid > 0) {
50 if (empty($user->rights->accounting->chartofaccount)) {
55 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
56 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
57 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
59 if (empty($page) || $page == -1) {
62 $offset = $limit * $page;
63 $pageprev = $page - 1;
64 $pagenext = $page + 1;
73 'subaccount'=>array(
'label'=>$langs->trans(
"AccountNumber"),
'checked'=>1),
74 'label'=>array(
'label'=>$langs->trans(
"Label"),
'checked'=>1),
75 'type'=>array(
'label'=>$langs->trans(
"Type"),
'checked'=>1),
76 'reconcilable'=>array(
'label'=>$langs->trans(
"Reconcilable"),
'checked'=>1)
79 if ($conf->global->MAIN_FEATURES_LEVEL < 2) {
80 unset($arrayfields[
'reconcilable']);
87 if (
GETPOST(
'cancel',
'alpha')) {
88 $action =
'list'; $massaction =
'';
90 if (!
GETPOST(
'confirmmassaction',
'alpha')) {
94 $parameters = array();
95 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
100 if (empty($reshook)) {
101 if (!empty($cancel)) {
105 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
107 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
108 $search_subaccount =
"";
111 $search_array_options = array();
123 $title = $langs->trans(
'ChartOfIndividualAccountsOfSubsidiaryLedger');
128 $sql =
"SELECT sa.rowid, sa.nom as label, sa.code_compta as subaccount, '1' as type, sa.entity";
129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe sa";
130 $sql .=
" WHERE sa.entity IN (".getEntity(
'societe').
")";
131 $sql .=
" AND sa.code_compta <> ''";
133 if (strlen(trim($search_subaccount))) {
134 $lengthpaddingaccount = 0;
135 if ($conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
136 $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_AACCOUNT);
138 $search_subaccount_tmp = $search_subaccount;
139 $weremovedsomezero = 0;
140 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
141 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
142 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
143 $weremovedsomezero++;
144 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
150 if ($search_subaccount_tmp) {
151 if ($weremovedsomezero) {
152 $search_subaccount_tmp_clean = $search_subaccount_tmp;
153 $search_subaccount_clean = $search_subaccount;
155 if (strpos($search_subaccount_tmp,
'^') === 0) {
157 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
158 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
160 $sql .=
" AND (sa.code_compta LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
161 $sql .=
" OR sa.code_compta LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
167 if (strlen(trim($search_label))) {
170 if (!empty($search_type) && $search_type >= 0) {
171 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
176 $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";
177 $sql .=
" WHERE sa.entity IN (".getEntity(
'societe').
")";
178 $sql .=
" AND sa.code_compta_fournisseur <> ''";
180 if (strlen(trim($search_subaccount))) {
181 $lengthpaddingaccount = 0;
182 if ($conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
183 $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_AACCOUNT);
185 $search_subaccount_tmp = $search_subaccount;
186 $weremovedsomezero = 0;
187 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
188 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
189 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
190 $weremovedsomezero++;
191 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
197 if ($search_subaccount_tmp) {
198 if ($weremovedsomezero) {
199 $search_subaccount_tmp_clean = $search_subaccount_tmp;
200 $search_subaccount_clean = $search_subaccount;
202 if (strpos($search_subaccount_tmp,
'^') === 0) {
204 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
205 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
207 $sql .=
" AND (sa.code_compta_fournisseur LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
208 $sql .=
" OR sa.code_compta_fournisseur LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
210 $sql .=
natural_search(
"sa.code_compta_fournisseur", $search_subaccount_tmp);
214 if (strlen(trim($search_label))) {
217 if (!empty($search_type) && $search_type >= 0) {
218 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
223 $sql .=
" SELECT u.rowid, u.lastname as label, u.accountancy_code as subaccount, '3' as type, u.entity FROM ".MAIN_DB_PREFIX.
"user u";
224 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
225 $sql .=
" AND u.accountancy_code <> ''";
227 if (strlen(trim($search_subaccount))) {
228 $lengthpaddingaccount = 0;
229 if ($conf->global->ACCOUNTING_LENGTH_AACCOUNT) {
230 $lengthpaddingaccount = max($conf->global->ACCOUNTING_LENGTH_AACCOUNT);
232 $search_subaccount_tmp = $search_subaccount;
233 $weremovedsomezero = 0;
234 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
235 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
236 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
237 $weremovedsomezero++;
238 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
244 if ($search_subaccount_tmp) {
245 if ($weremovedsomezero) {
246 $search_subaccount_tmp_clean = $search_subaccount_tmp;
247 $search_subaccount_clean = $search_subaccount;
249 if (strpos($search_subaccount_tmp,
'^') === 0) {
251 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
252 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
254 $sql .=
" AND (u.accountancy_code LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
255 $sql .=
" OR u.accountancy_code LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
257 $sql .=
natural_search(
"u.accountancy_code", $search_subaccount_tmp);
261 if (strlen(trim($search_label))) {
264 if (!empty($search_type) && $search_type >= 0) {
265 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
268 $sql .= $db->order($sortfield, $sortorder);
271 $nbtotalofrecords =
'';
272 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
273 $resql = $db->query($sql);
274 $nbtotalofrecords = $db->num_rows(
$resql);
275 if (($page * $limit) > $nbtotalofrecords) {
281 $sql .= $db->plimit($limit + 1, $offset);
283 dol_syslog(
'accountancy/admin/subaccount.php:: $sql='.$sql);
284 $resql = $db->query($sql);
287 $num = $db->num_rows(
$resql);
290 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
291 $param .=
'&contextpage='.urlencode($contextpage);
293 if ($limit > 0 && $limit != $conf->liste_limit) {
294 $param .=
'&limit='.urlencode($limit);
296 if ($search_subaccount) {
297 $param .=
'&search_subaccount='.urlencode($search_subaccount);
300 $param .=
'&search_label='.urlencode($search_label);
302 if ($optioncss !=
'') {
303 $param .=
'&optioncss='.urlencode($optioncss);
306 print
'<form method="POST" id="searchFormList" action="'.$_SERVER[
"PHP_SELF"].
'">';
307 if ($optioncss !=
'') {
308 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
310 print
'<input type="hidden" name="token" value="'.newToken().
'">';
311 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
312 print
'<input type="hidden" name="action" value="list">';
313 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
314 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
315 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
317 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'title_accountancy', 0,
'',
'', $limit, 0, 0, 1);
319 print
'<div class="info">'.$langs->trans(
"WarningCreateSubAccounts").
'</div>';
321 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
322 $selectedfields =
$form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage);
325 $massactionbutton =
'';
327 print
'<div class="div-table-responsive">';
328 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
331 print
'<tr class="liste_titre_filter">';
332 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
333 print
'<td class="liste_titre"><input type="text" class="flat" size="10" name="search_subaccount" value="'.$search_subaccount.
'"></td>';
335 if (!empty($arrayfields[
'label'][
'checked'])) {
336 print
'<td class="liste_titre"><input type="text" class="flat" size="20" name="search_label" value="'.$search_label.
'"></td>';
338 if (!empty($arrayfields[
'type'][
'checked'])) {
339 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>';
341 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
342 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
343 print
'<td class="liste_titre"> </td>';
346 print
'<td class="liste_titre maxwidthsearch">';
347 $searchpicto =
$form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
352 print
'<tr class="liste_titre">';
353 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
354 print_liste_field_titre($arrayfields[
'subaccount'][
'label'], $_SERVER[
"PHP_SELF"],
"subaccount",
"", $param,
'', $sortfield, $sortorder);
356 if (!empty($arrayfields[
'label'][
'checked'])) {
357 print_liste_field_titre($arrayfields[
'label'][
'label'], $_SERVER[
"PHP_SELF"],
"label",
"", $param,
'', $sortfield, $sortorder);
359 if (!empty($arrayfields[
'type'][
'checked'])) {
360 print_liste_field_titre($arrayfields[
'type'][
'label'], $_SERVER[
"PHP_SELF"],
"type",
"", $param,
'', $sortfield, $sortorder,
'center ');
362 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
363 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
364 print_liste_field_titre($arrayfields[
'reconcilable'][
'label'], $_SERVER[
"PHP_SELF"],
'reconcilable',
'', $param,
'', $sortfield, $sortorder,
'center ');
367 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'',
'',
'', $sortfield, $sortorder,
'center maxwidthsearch ');
370 $totalarray = array();
371 $totalarray[
'nbfield'] = 0;
373 while ($i < min($num, $limit)) {
374 $obj = $db->fetch_object(
$resql);
376 print
'<tr class="oddeven">';
379 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
384 $totalarray[
'nbfield']++;
389 if (!empty($arrayfields[
'label'][
'checked'])) {
394 $totalarray[
'nbfield']++;
399 if (!empty($arrayfields[
'type'][
'checked'])) {
400 print
'<td class="center">';
403 if ($obj->type == 1) {
404 $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>';
405 } elseif ($obj->type == 2) {
407 $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>';
408 } elseif ($obj->type == 3) {
410 $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->id.
'">'.$langs->trans(
"Employee").
'</a>';
415 $totalarray[
'nbfield']++;
419 if ($conf->global->MAIN_FEATURES_LEVEL >= 2) {
421 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
422 print
'<td class="center">';
423 if (empty($obj->reconcilable)) {
424 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=enable&mode=1&token='.
newToken().
'">';
425 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
428 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=disable&mode=1&token='.
newToken().
'">';
429 print
img_picto($langs->trans(
"Activated"),
'switch_on');
434 $totalarray[
'nbfield']++;
440 print
'<td class="center">';
443 if ($obj->type == 1) {
444 $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>';
445 } elseif ($obj->type == 2) {
447 $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>';
448 } elseif ($obj->type == 3) {
450 $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>';
455 $totalarray[
'nbfield']++;
464 $parameters = array(
'arrayfields'=>$arrayfields,
'sql'=>$sql);
465 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters);
466 print $hookmanager->resPrint;