29require
'../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
41$langs->loadLangs(array(
"accountancy",
"admin",
"bills",
"compta",
"errors",
"hrm",
"salaries"));
43$action =
GETPOST(
'action',
'aZ09');
44$cancel =
GETPOST(
'cancel',
'alpha');
45$massaction =
GETPOST(
'massaction',
'aZ09');
46$optioncss =
GETPOST(
'optioncss',
'alpha');
48$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') : str_replace(
'_',
'', basename(dirname(__FILE__)).basename(__FILE__,
'.php'));
53$search_subaccount =
GETPOST(
'search_subaccount',
'alpha');
54$search_label =
GETPOST(
'search_label',
'alpha');
55$search_type =
GETPOST(
'search_type',
'intcomma');
59$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
60$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
62if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
66$offset = $limit * $page;
77 'subaccount' => array(
'label' => $langs->trans(
"AccountNumber"),
'checked' =>
'1'),
78 'label' => array(
'label' => $langs->trans(
"Label"),
'checked' =>
'1'),
79 'type' => array(
'label' => $langs->trans(
"Type"),
'checked' =>
'1'),
80 'reconcilable' => array(
'label' => $langs->trans(
"Reconcilable"),
'checked' =>
'1')
84 unset($arrayfields[
'reconcilable']);
88if ($user->socid > 0) {
91if (!$user->hasRight(
'accounting',
'chartofaccount')) {
100if (
GETPOST(
'cancel',
'alpha')) {
104if (!
GETPOST(
'confirmmassaction',
'alpha')) {
108$parameters = array();
109$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
114if (empty($reshook)) {
115 if (!empty($cancel)) {
119 include DOL_DOCUMENT_ROOT.
'/core/actions_changeselectedfields.inc.php';
121 if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
122 $search_subaccount =
"";
125 $search_array_options = array();
128 if ($action ==
'enable' ) {
131 if ($action ==
'disable' ) {
145$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
146$title = $langs->trans(
'ChartOfIndividualAccountsOfSubsidiaryLedger');
148llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-admin_subaccount');
152$sql =
"SELECT sa.rowid, sa.nom as label, sa.code_compta as subaccount, '1' as type, sa.entity, sa.client as nature, sa.fournisseur as nature2";
153$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe sa";
154$sql .=
" WHERE sa.entity IN (".getEntity(
'societe').
")";
155$sql .=
" AND sa.code_compta <> ''";
157if (strlen(trim($search_subaccount))) {
158 $lengthpaddingaccount = 0;
162 $search_subaccount_tmp = $search_subaccount;
163 $weremovedsomezero = 0;
164 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
165 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
166 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
167 $weremovedsomezero++;
168 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
173 if ($search_subaccount_tmp) {
174 if ($weremovedsomezero) {
175 $search_subaccount_tmp_clean = $search_subaccount_tmp;
176 $search_subaccount_clean = $search_subaccount;
178 if (strpos($search_subaccount_tmp,
'^') === 0) {
180 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
181 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
183 $sql .=
" AND (sa.code_compta LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
184 $sql .=
" OR sa.code_compta LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
190if (strlen(trim($search_label))) {
193if (!empty($search_type) && $search_type >= 0) {
194 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
199$sql .=
" SELECT sa.rowid, sa.nom as label, sa.code_compta_fournisseur as subaccount, '2' as type, sa.entity, sa.client as nature, sa.fournisseur as nature2";
200$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe sa";
201$sql .=
" WHERE sa.entity IN (".getEntity(
'societe').
")";
202$sql .=
" AND sa.code_compta_fournisseur <> ''";
204if (strlen(trim($search_subaccount))) {
205 $lengthpaddingaccount = 0;
209 $search_subaccount_tmp = $search_subaccount;
210 $weremovedsomezero = 0;
211 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
212 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
213 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
214 $weremovedsomezero++;
215 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
221 if ($search_subaccount_tmp) {
222 if ($weremovedsomezero) {
223 $search_subaccount_tmp_clean = $search_subaccount_tmp;
224 $search_subaccount_clean = $search_subaccount;
226 if (strpos($search_subaccount_tmp,
'^') === 0) {
228 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
229 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
231 $sql .=
" AND (sa.code_compta_fournisseur LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
232 $sql .=
" OR sa.code_compta_fournisseur LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
234 $sql .=
natural_search(
"sa.code_compta_fournisseur", $search_subaccount_tmp);
238if (strlen(trim($search_label))) {
241if (!empty($search_type) && $search_type >= 0) {
242 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
247$sql .=
" SELECT u.rowid, u.lastname as label, u.accountancy_code as subaccount, '3' as type, u.entity, '0' as nature, '0' as nature2";
248$sql .=
" FROM ".MAIN_DB_PREFIX.
"user u";
249$sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
250$sql .=
" AND u.accountancy_code <> ''";
252if (strlen(trim($search_subaccount))) {
253 $lengthpaddingaccount = 0;
257 $search_subaccount_tmp = $search_subaccount;
258 $weremovedsomezero = 0;
259 if (strlen($search_subaccount_tmp) <= $lengthpaddingaccount) {
260 for ($i = 0; $i < $lengthpaddingaccount; $i++) {
261 if (preg_match(
'/0$/', $search_subaccount_tmp)) {
262 $weremovedsomezero++;
263 $search_subaccount_tmp = preg_replace(
'/0$/',
'', $search_subaccount_tmp);
269 if ($search_subaccount_tmp) {
270 if ($weremovedsomezero) {
271 $search_subaccount_tmp_clean = $search_subaccount_tmp;
272 $search_subaccount_clean = $search_subaccount;
274 if (strpos($search_subaccount_tmp,
'^') === 0) {
276 $search_subaccount_tmp_clean = preg_replace(
'/^\^/',
'', $search_subaccount_tmp);
277 $search_subaccount_clean = preg_replace(
'/^\^/',
'', $search_subaccount);
279 $sql .=
" AND (u.accountancy_code LIKE '".$db->escape($startchar.$search_subaccount_tmp_clean).
"'";
280 $sql .=
" OR u.accountancy_code LIKE '".$db->escape($startchar.$search_subaccount_clean).
"%')";
282 $sql .=
natural_search(
"u.accountancy_code", $search_subaccount_tmp);
286if (strlen(trim($search_label))) {
289if (!empty($search_type) && $search_type >= 0) {
290 $sql .=
" HAVING type LIKE '".$db->escape($search_type).
"'";
293$sql .=
$db->order($sortfield, $sortorder);
296$nbtotalofrecords =
'';
298 $resql =
$db->query($sql);
299 $nbtotalofrecords =
$db->num_rows($resql);
300 if (($page * $limit) > (
int) $nbtotalofrecords) {
306$sql .=
$db->plimit($limit + 1, $offset);
308dol_syslog(
"accountancy/admin/subaccount.php:: sql=".$sql);
309$resql =
$db->query($sql);
312 $num =
$db->num_rows($resql);
315 if (!empty($contextpage) && $contextpage != $_SERVER[
"PHP_SELF"]) {
316 $param .=
'&contextpage='.urlencode($contextpage);
318 if ($limit > 0 && $limit !=
$conf->liste_limit) {
319 $param .=
'&limit='.((int) $limit);
321 if ($optioncss !=
'') {
322 $param .=
'&optioncss='.urlencode($optioncss);
324 if ($search_subaccount) {
325 $param .=
'&search_subaccount='.urlencode($search_subaccount);
328 $param .=
'&search_label='.urlencode($search_label);
331 $param .=
'&search_type='.urlencode($search_type);
335 $arrayofmassactions = array();
337 print
'<form method="POST" id="searchFormList" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
338 if ($optioncss !=
'') {
339 print
'<input type="hidden" name="optioncss" value="'.$optioncss.
'">';
341 print
'<input type="hidden" name="token" value="'.newToken().
'">';
342 print
'<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
343 print
'<input type="hidden" name="action" value="list">';
344 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'">';
345 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'">';
346 print
'<input type="hidden" name="contextpage" value="'.$contextpage.
'">';
348 print_barre_liste($title, $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
'', $num, $nbtotalofrecords,
'accounting_account', 0,
'',
'', $limit, 0, 0, 1);
350 print
'<div class="info">'.$langs->trans(
"WarningCreateSubAccounts").
'</div>';
353 $varpage = empty($contextpage) ? $_SERVER[
"PHP_SELF"] : $contextpage;
354 $htmlofselectarray = $form->multiSelectArrayWithCheckbox(
'selectedfields', $arrayfields, $varpage,
$conf->main_checkbox_left_column);
355 $selectedfields = ($mode !=
'kanban' ? $htmlofselectarray :
'');
356 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons(
'checkforselect', 1) :
'');
359 $massactionbutton =
'';
361 print
'<div class="div-table-responsive">';
362 print
'<table class="tagtable liste'.($moreforfilter ?
" listwithfilterbefore" :
"").
'">'.
"\n";
365 print
'<tr class="liste_titre_filter">';
367 if (
$conf->main_checkbox_left_column) {
368 print
'<td class="liste_titre center maxwidthsearch">';
369 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
373 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
374 print
'<td class="liste_titre"><input type="text" class="flat" size="10" name="search_subaccount" value="'.$search_subaccount.
'"></td>';
376 if (!empty($arrayfields[
'label'][
'checked'])) {
377 print
'<td class="liste_titre"><input type="text" class="flat" size="20" name="search_label" value="'.$search_label.
'"></td>';
379 if (!empty($arrayfields[
'type'][
'checked'])) {
380 print
'<td class="liste_titre center">'.$form->selectarray(
'search_type', array(
'1' => $langs->trans(
'Customer').
' / '.$langs->trans(
"Prospect"),
'2' => $langs->trans(
'Supplier'),
'3' => $langs->trans(
'Employee')), $search_type, 1).
'</td>';
383 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
384 print
'<td class="liste_titre"> </td>';
388 if (!
$conf->main_checkbox_left_column) {
389 print
'<td class="liste_titre maxwidthsearch">';
390 $searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0,
'checkforselect', 1);
396 print
'<tr class="liste_titre">';
398 if (
$conf->main_checkbox_left_column) {
399 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'', $param,
'', $sortfield, $sortorder,
'center maxwidthsearch ');
401 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
402 print_liste_field_titre($arrayfields[
'subaccount'][
'label'], $_SERVER[
"PHP_SELF"],
"subaccount",
"", $param,
'', $sortfield, $sortorder);
404 if (!empty($arrayfields[
'label'][
'checked'])) {
405 print_liste_field_titre($arrayfields[
'label'][
'label'], $_SERVER[
"PHP_SELF"],
"label",
"", $param,
'', $sortfield, $sortorder);
407 if (!empty($arrayfields[
'type'][
'checked'])) {
408 print_liste_field_titre($arrayfields[
'type'][
'label'], $_SERVER[
"PHP_SELF"],
"type",
"", $param,
'', $sortfield, $sortorder,
'center ');
411 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
412 print_liste_field_titre($arrayfields[
'reconcilable'][
'label'], $_SERVER[
"PHP_SELF"],
'reconcilable',
'', $param,
'', $sortfield, $sortorder,
'center ');
416 if (!
$conf->main_checkbox_left_column) {
417 print_liste_field_titre($selectedfields, $_SERVER[
"PHP_SELF"],
"",
'', $param,
'', $sortfield, $sortorder,
'center maxwidthsearch ');
426 while ($i < min($num, $limit)) {
427 $obj =
$db->fetch_object($resql);
429 if ($obj->type == 1) {
430 $companystatic->id = $obj->rowid;
431 $companystatic->client = $obj->nature;
432 $companystatic->fournisseur = 0;
434 if ($obj->type == 2) {
435 $companystatic->id = $obj->rowid;
436 $companystatic->client = 0;
437 $companystatic->fournisseur = $obj->nature2;
440 print
'<tr class="oddeven">';
443 if (
$conf->main_checkbox_left_column) {
444 print
'<td class="center">';
448 if ($obj->type == 1) {
449 $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>';
450 } elseif ($obj->type == 2) {
452 $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>';
453 } elseif ($obj->type == 3) {
455 $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>';
465 if (!empty($arrayfields[
'subaccount'][
'checked'])) {
475 if (!empty($arrayfields[
'label'][
'checked'])) {
485 if (!empty($arrayfields[
'type'][
'checked'])) {
486 print
'<td class="center">';
490 if ($obj->type == 1) {
491 $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.
'">';
492 $s .= $langs->trans(
"Customer");
494 if ($obj->nature == 2) {
495 $s .=
' <span class="warning">('.$langs->trans(
"Prospect").
')</span>';
497 } elseif ($obj->type == 2) {
499 $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>';
500 } elseif ($obj->type == 3) {
502 $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>';
513 if (!empty($arrayfields[
'reconcilable'][
'checked'])) {
514 print
'<td class="center">';
515 if (empty($obj->reconcilable)) {
516 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=enable&mode=1&page='.$page.
'&token='.newToken().
'">';
517 print
img_picto($langs->trans(
"Disabled"),
'switch_off');
520 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$obj->rowid.
'&action=disable&mode=1&page='.$page.
'&token='.newToken().
'">';
521 print
img_picto($langs->trans(
"Activated"),
'switch_on');
532 if (!
$conf->main_checkbox_left_column) {
533 print
'<td class="center">';
537 if ($obj->type == 1) {
538 $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>';
539 } elseif ($obj->type == 2) {
541 $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>';
542 } elseif ($obj->type == 3) {
544 $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>';
560 foreach ($arrayfields as $key => $val) {
561 if (!empty($val[
'checked'])) {
565 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
570 $parameters = array(
'arrayfields' => $arrayfields,
'sql' => $sql);
571 $reshook = $hookmanager->executeHooks(
'printFieldListFooter', $parameters);
572 print $hookmanager->resPrint;
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
length_accounta($accounta)
Return Auxiliary accounting account of thirdparties with defined length.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage third parties objects (customers, suppliers, prospects...)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify 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.