25 if (!defined(
'CSRFCHECK_WITH_TOKEN')) define(
'CSRFCHECK_WITH_TOKEN',
'1');
27 require
'../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
37 $langs->loadLangs(array(
"admin",
"compta",
"accountancy"));
39 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
40 $confirm =
GETPOST(
'confirm',
'alpha');
42 $rowid =
GETPOST(
'rowid',
'alpha');
43 $code =
GETPOST(
'code',
'alpha');
46 if (empty($user->rights->accounting->chartofaccount))
51 $acts[0] =
"activate";
53 $actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off');
54 $actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on');
56 $listoffset =
GETPOST(
'listoffset',
'alpha');
57 $listlimit =
GETPOST(
'listlimit',
'int') > 0 ?
GETPOST(
'listlimit',
'int') : 1000;
60 $sortfield =
GETPOST(
"sortfield",
'alpha');
61 $sortorder =
GETPOST(
"sortorder",
'alpha');
63 if (empty($page) || $page == -1) { $page = 0; }
64 $offset = $listlimit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 if (empty($sortfield)) $sortfield =
'code';
68 if (empty($sortorder)) $sortorder =
'ASC';
73 $hookmanager->initHooks(array(
'admin'));
79 $taborder = array(35);
83 $tabname[35] = MAIN_DB_PREFIX.
"accounting_journal";
87 $tablib[35] =
"DictionaryAccountancyJournal";
91 $tabsql[35] =
"SELECT a.rowid as rowid, a.code as code, a.label, a.nature, a.active FROM ".MAIN_DB_PREFIX.
"accounting_journal as a";
94 $tabsqlsort = array();
95 $tabsqlsort[35] =
"code ASC";
99 $tabfield[35] =
"code,label,nature";
102 $tabfieldvalue = array();
103 $tabfieldvalue[35] =
"code,label,nature";
106 $tabfieldinsert = array();
107 $tabfieldinsert[35] =
"code,label,nature";
117 $tabcond[35] = !empty($conf->accounting->enabled);
121 $tabhelp[35] = array(
'code'=>$langs->trans(
"EnterAnyCode"));
124 $tabfieldcheck = array();
125 $tabfieldcheck[35] = array();
128 complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
132 $elementList = array();
135 '1' => $langs->trans(
'AccountingJournalType1'),
136 '2' => $langs->trans(
'AccountingJournalType2'),
137 '3' => $langs->trans(
'AccountingJournalType3'),
138 '4' => $langs->trans(
'AccountingJournalType4'),
139 '5' => $langs->trans(
'AccountingJournalType5'),
140 '8' => $langs->trans(
'AccountingJournalType8'),
141 '9' => $langs->trans(
'AccountingJournalType9'),
148 if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha'))
150 $search_country_id =
'';
154 if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha'))
156 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
157 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
158 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
159 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
163 foreach ($listfield as $f => $value)
165 if ($fieldnamekey ==
'libelle' || ($fieldnamekey ==
'label')) $fieldnamekey =
'Label';
166 if ($fieldnamekey ==
'code') $fieldnamekey =
'Code';
167 if ($fieldnamekey ==
'nature') $fieldnamekey =
'NatureOfJournal';
175 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'), null,
'errors');
183 if (!
GETPOST(
'label',
'alpha'))
185 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")), null,
'errors');
190 if ($_POST[
"accountancy_code"] <= 0) $_POST[
"accountancy_code"] =
'';
191 if ($_POST[
"accountancy_code_sell"] <= 0) $_POST[
"accountancy_code_sell"] =
'';
192 if ($_POST[
"accountancy_code_buy"] <= 0) $_POST[
"accountancy_code_buy"] =
'';
195 if ($ok &&
GETPOST(
'actionadd',
'alpha'))
201 $sql =
"SELECT max(".$tabrowid[$id].
") newid from ".$tabname[$id];
202 $result = $db->query($sql);
205 $obj = $db->fetch_object($result);
206 $newid = ($obj->newid + 1);
213 $sql =
"INSERT INTO ".$tabname[$id].
" (";
215 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert))
216 $sql .= $tabrowid[$id].
",";
217 $sql .= $tabfieldinsert[$id];
218 $sql .=
",active,entity)";
222 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert))
225 foreach ($listfieldinsert as $f => $value)
227 if ($value ==
'entity') {
228 $_POST[$listfieldvalue[$i]] = $conf->entity;
231 if ($_POST[$listfieldvalue[$i]] ==
'') $sql .=
"null";
232 else $sql .=
"'".$db->escape($_POST[$listfieldvalue[$i]]).
"'";
235 $sql .=
",1,".$conf->entity.
")";
238 $result = $db->query($sql);
242 $_POST = array(
'id'=>$id);
244 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
245 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"), null,
'errors');
253 if ($ok &&
GETPOST(
'actionmodify',
'alpha'))
255 if ($tabrowid[$id]) { $rowidcol = $tabrowid[$id]; }
else { $rowidcol =
"rowid"; }
258 $sql =
"UPDATE ".$tabname[$id].
" SET ";
260 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify))
262 $sql .= $tabrowid[$id].
"=";
263 $sql .=
"'".$db->escape($rowid).
"', ";
266 foreach ($listfieldmodify as $field)
268 if ($field ==
'price' || preg_match(
'/^amount/i', $field) || $field ==
'taux') {
269 $_POST[$listfieldvalue[$i]] =
price2num($_POST[$listfieldvalue[$i]],
'MU');
270 } elseif ($field ==
'entity') {
271 $_POST[$listfieldvalue[$i]] = $conf->entity;
275 if ($_POST[$listfieldvalue[$i]] ==
'' && !($listfieldvalue[$i] ==
'code' && $id == 10)) $sql .=
"null";
276 else $sql .=
"'".$db->escape($_POST[$listfieldvalue[$i]]).
"'";
279 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
280 $sql .=
" AND entity = ".$conf->entity;
284 $resql = $db->query($sql);
298 if ($action ==
'confirm_delete' && $confirm ==
'yes')
300 if ($tabrowid[$id]) { $rowidcol = $tabrowid[$id]; }
else { $rowidcol =
"rowid"; }
302 $sql =
"DELETE from ".$tabname[$id].
" WHERE ".$rowidcol.
" = ".((int) $rowid);
303 $sql .=
" AND entity = ".$conf->entity;
306 $result = $db->query($sql);
309 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS')
311 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"), null,
'errors');
319 if ($action == $acts[0])
321 if ($tabrowid[$id]) { $rowidcol = $tabrowid[$id]; }
else { $rowidcol =
"rowid"; }
324 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE ".$rowidcol.
" = ".((int) $rowid);
326 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE code='".$db->escape($code).
"'";
328 $sql .=
" AND entity = ".$conf->entity;
330 $result = $db->query($sql);
338 if ($action == $acts[1])
340 if ($tabrowid[$id]) { $rowidcol = $tabrowid[$id]; }
else { $rowidcol =
"rowid"; }
343 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE ".$rowidcol.
" = ".((int) $rowid);
345 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE code='".$db->escape($code).
"'";
347 $sql .=
" AND entity = ".$conf->entity;
349 $result = $db->query($sql);
361 $form =
new Form($db);
366 $titre = $langs->trans(
"DictionarySetup");
370 $titre .=
' - '.$langs->trans($tablib[$id]);
371 $titlepicto =
'title_accountancy';
378 if ($action ==
'delete')
380 print $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.$rowid.
'&code='.$code.
'&id='.$id, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_delete',
'', 0, 1);
391 $sql .=
" WHERE a.entity = ".$conf->entity;
394 if ($sortfield ==
'country') $sortfield =
'country_code';
395 $sql .= $db->order($sortfield, $sortorder);
396 $sql .= $db->plimit($listlimit + 1, $offset);
398 $fieldlist = explode(
',', $tabfield[$id]);
400 print '<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
401 print '<input type="hidden" name="token" value="'.newToken().
'">';
402 print '<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
404 print '<div class="div-table-responsive">';
405 print '<table class="noborder centpercent">';
410 $fieldlist = explode(
',', $tabfield[$id]);
413 print '<tr class="liste_titre">';
414 foreach ($fieldlist as $field => $value)
418 $valuetoshow = ucfirst($fieldlist[$field]);
419 $valuetoshow = $langs->trans($valuetoshow);
421 if ($fieldlist[$field] ==
'code') {
422 $valuetoshow = $langs->trans(
"Code");
424 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
425 $valuetoshow = $langs->trans(
"Label");
427 if ($fieldlist[$field] ==
'nature') {
428 $valuetoshow = $langs->trans(
"NatureOfJournal");
431 if ($valuetoshow !=
'') {
432 print '<td class="'.$class.
'">';
433 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value]))
print '<a href="'.$tabhelp[$id][$value].
'" target="_blank">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
434 elseif (!empty($tabhelp[$id][$value]))
print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
435 else print $valuetoshow;
441 print '<input type="hidden" name="id" value="'.$id.
'">';
443 print '<td style="min-width: 26px;"></td>';
444 print '<td style="min-width: 26px;"></td>';
445 print '<td style="min-width: 26px;"></td>';
449 print '<tr class="oddeven nodrag nodrap nohover">';
451 $obj =
new stdClass();
453 if (
GETPOST(
'actionadd',
'alpha'))
455 foreach ($fieldlist as $key=>$val)
462 $tmpaction =
'create';
463 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
464 $reshook = $hookmanager->executeHooks(
'createDictionaryFieldlist', $parameters, $obj, $tmpaction);
465 $error = $hookmanager->error; $errors = $hookmanager->errors;
472 print '<td colspan="4" class="right">';
473 print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans(
"Add").
'">';
477 print '<tr><td colspan="7"> </td></tr>';
484 $resql = $db->query($sql);
487 $num = $db->num_rows(
$resql);
491 if ($search_country_id > 0) $param .=
'&search_country_id='.$search_country_id;
492 $paramwithsearch = $param;
493 if ($sortorder) $paramwithsearch .=
'&sortorder='.$sortorder;
494 if ($sortfield) $paramwithsearch .=
'&sortfield='.$sortfield;
495 if (
GETPOST(
'from',
'alpha')) $paramwithsearch .=
'&from='.GETPOST(
'from',
'alpha');
498 if ($num > $listlimit)
500 print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
501 print_fleche_navigation($page,
$_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
521 print '<tr class="liste_titre liste_titre_add">';
522 foreach ($fieldlist as $field => $value)
537 $valuetoshow = ucfirst($fieldlist[$field]);
538 $valuetoshow = $langs->trans($valuetoshow);
539 if ($fieldlist[$field] ==
'code') {
540 $valuetoshow = $langs->trans(
"Code");
542 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
543 $valuetoshow = $langs->trans(
"Label");
545 if ($fieldlist[$field] ==
'nature') {
546 $valuetoshow = $langs->trans(
"NatureOfJournal");
551 print getTitleFieldOfList($valuetoshow, 0,
$_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''), $param,
"", $sortfield, $sortorder, $class.
' ');
554 print getTitleFieldOfList($langs->trans(
"Status"), 0,
$_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
565 $obj = $db->fetch_object(
$resql);
567 print '<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
568 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code)))
571 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
572 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
573 $error = $hookmanager->error; $errors = $hookmanager->errors;
576 if (empty($reshook))
fieldListJournal($fieldlist, $obj, $tabname[$id],
'edit');
578 print '<td class="center" colspan="4">';
579 print '<input type="hidden" name="page" value="'.$page.
'">';
580 print '<input type="hidden" name="rowid" value="'.$rowid.
'">';
581 print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
582 print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
583 print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"></div>';
587 $parameters = array(
'var'=>$var,
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
588 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
590 $error = $hookmanager->error; $errors = $hookmanager->errors;
594 $langs->load(
"accountancy");
595 foreach ($fieldlist as $field => $value)
599 $valuetoshow = $obj->{$fieldlist[$field]};
600 if ($valuetoshow ==
'all') {
601 $valuetoshow = $langs->trans(
'All');
602 } elseif ($fieldlist[$field] ==
'nature' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
603 $key = $langs->trans(
"AccountingJournalType".strtoupper($obj->nature));
604 $valuetoshow = ($obj->nature && $key !=
"AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
605 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
606 $valuetoshow = $langs->trans($obj->label);
611 if ($showfield)
print '<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.$valuetoshow.
'</td>';
616 $iserasable = 1; $canbedisabled = 1; $canbemodified = 1;
617 if (isset($obj->code) && $id != 10) {
618 if (($obj->code ==
'0' || $obj->code ==
'' || preg_match(
'/unknown/i', $obj->code))) {
621 } elseif ($obj->code ==
'RECEP') {
624 } elseif ($obj->code ==
'EF0') {
630 $canbemodified = $iserasable;
632 $url =
$_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code :
'')).
'&code='.(!empty($obj->code) ?urlencode($obj->code) :
'');
633 if ($param) $url .=
'&'.$param;
637 print '<td class="nowrap center">';
638 if ($canbedisabled)
print '<a href="'.$url.
'action='.$acts[$obj->active].
'&token='.
newToken().
'">'.$actl[$obj->active].
'</a>';
639 else print $langs->trans(
"AlwaysActive");
643 if ($canbemodified)
print '<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
644 else print '<td> </td>';
649 print '<td class="center">';
653 }
else print '<td> </td>';
692 global $conf, $langs, $db;
693 global $form, $mysoc;
695 global $elementList, $sourceList, $localtax_typeList;
701 foreach ($fieldlist as $field => $value)
703 if ($fieldlist[$field] ==
'nature')
706 print $form->selectarray(
'nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
''));
708 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
709 print '<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
'').
'" name="'.$fieldlist[$field].
'"></td>';
712 $size =
''; $class =
'';
713 if ($fieldlist[$field] ==
'code') $class =
'maxwidth100';
714 if ($fieldlist[$field] ==
'label') $class =
'quatrevingtpercent';
715 if ($fieldlist[$field] ==
'sortorder' || $fieldlist[$field] ==
'sens' || $fieldlist[$field] ==
'category_type') $size =
'size="2" ';
716 print '<input type="text" '.$size.
'class="flat'.($class ?
' '.$class :
'').
'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
'').
'" name="'.$fieldlist[$field].
'">';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
fieldListJournal($fieldlist, $obj= '', $tabname= '', $context= '')
Show fields in insert/edit mode.
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabfieldcheck)
Add external modules to list of dictionaries.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
print_fleche_navigation($page, $file, $options= '', $nextpage=0, $betweenarrows= '', $afterarrows= '', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows= '')
Function to show navigation arrows into lists.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.