25if (!defined(
'CSRFCHECK_WITH_TOKEN')) {
26 define(
'CSRFCHECK_WITH_TOKEN',
'1');
30require
'../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
40$langs->loadLangs(array(
"admin",
"compta",
"accountancy"));
42$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
43$confirm =
GETPOST(
'confirm',
'alpha');
45$rowid =
GETPOST(
'rowid',
'alpha');
46$code =
GETPOST(
'code',
'alpha');
49if (!$user->hasRight(
'accounting',
'chartofaccount')) {
55$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
56$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
58$listoffset =
GETPOST(
'listoffset',
'alpha');
59$listlimit =
GETPOST(
'listlimit',
'int') > 0 ?
GETPOST(
'listlimit',
'int') : 1000;
62$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
63$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
64$page = GETPOSTISSET(
'pageplusone') ? (
GETPOST(
'pageplusone') - 1) :
GETPOST(
"page",
'int');
65if (empty($page) || $page == -1) {
68$offset = $listlimit * $page;
71if (empty($sortfield)) {
74if (empty($sortorder)) {
80$search_country_id =
GETPOST(
'search_country_id',
'int');
83$hookmanager->initHooks(array(
'admin'));
93$tabname[35] = MAIN_DB_PREFIX.
"accounting_journal";
97$tablib[35] =
"DictionaryAccountancyJournal";
101$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";
104$tabsqlsort = array();
105$tabsqlsort[35] =
"code ASC";
109$tabfield[35] =
"code,label,nature";
112$tabfieldvalue = array();
113$tabfieldvalue[35] =
"code,label,nature";
116$tabfieldinsert = array();
117$tabfieldinsert[35] =
"code,label,nature";
127$tabcond[35] = isModEnabled(
'accounting');
131$tabhelp[35] = array(
'code'=>$langs->trans(
"EnterAnyCode"));
134$tabfieldcheck = array();
135$tabfieldcheck[35] = array();
138complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
142$elementList = array();
145 '1' => $langs->trans(
'AccountingJournalType1'),
146 '2' => $langs->trans(
'AccountingJournalType2'),
147 '3' => $langs->trans(
'AccountingJournalType3'),
148 '4' => $langs->trans(
'AccountingJournalType4'),
149 '5' => $langs->trans(
'AccountingJournalType5'),
150 '8' => $langs->trans(
'AccountingJournalType8'),
151 '9' => $langs->trans(
'AccountingJournalType9'),
158if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha')) {
159 $search_country_id =
'';
163if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
164 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
165 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
166 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
167 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
173 if (GETPOSTISSET(
"code")) {
176 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'),
null,
'errors');
179 if (!
GETPOST(
'label',
'alpha')) {
180 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
185 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
186 if ($tabrowid[$id]) {
189 $sql =
"SELECT max(".$tabrowid[$id].
") newid from ".$tabname[$id];
190 $result = $db->query($sql);
192 $obj = $db->fetch_object($result);
193 $newid = ($obj->newid + 1);
200 $sql =
"INSERT INTO ".$tabname[$id].
" (";
202 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
203 $sql .= $tabrowid[$id].
",";
205 $sql .= $tabfieldinsert[$id];
206 $sql .=
",active,entity)";
210 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
214 foreach ($listfieldinsert as $f => $value) {
218 if (
GETPOST($listfieldvalue[$i]) ==
'') {
221 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
225 $sql .=
",1,".$conf->entity.
")";
228 $result = $db->query($sql);
231 $_POST = array(
'id'=>$id);
233 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
234 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
242 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
243 if ($tabrowid[$id]) {
244 $rowidcol = $tabrowid[$id];
250 $sql =
"UPDATE ".$tabname[$id].
" SET ";
252 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
253 $sql .= $tabrowid[$id].
"=";
254 $sql .=
"'".$db->escape($rowid).
"', ";
257 foreach ($listfieldmodify as $field) {
261 $sql .= $field.
" = ";
262 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
265 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
266 $sql .=
" AND entity = ".((int) $conf->entity);
270 $resql = $db->query($sql);
283if ($action ==
'confirm_delete' && $confirm ==
'yes') {
284 if ($tabrowid[$id]) {
285 $rowidcol = $tabrowid[$id];
290 $sql =
"DELETE from ".$tabname[$id].
" WHERE ".$rowidcol.
" = ".((int) $rowid);
291 $sql .=
" AND entity = ".((int) $conf->entity);
294 $result = $db->query($sql);
296 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
297 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
305if ($action == $acts[0]) {
306 if ($tabrowid[$id]) {
307 $rowidcol = $tabrowid[$id];
313 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE ".$rowidcol.
" = ".((int) $rowid);
315 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE code='".$db->escape($code).
"'";
317 $sql .=
" AND entity = ".$conf->entity;
319 $result = $db->query($sql);
326if ($action == $acts[1]) {
327 if ($tabrowid[$id]) {
328 $rowidcol = $tabrowid[$id];
334 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE ".$rowidcol.
" = ".((int) $rowid);
336 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE code='".$db->escape($code).
"'";
338 $sql .=
" AND entity = ".$conf->entity;
340 $result = $db->query($sql);
351$form =
new Form($db);
356$titre = $langs->trans(
"DictionarySetup");
359 $titre .=
' - '.$langs->trans($tablib[$id]);
360 $titlepicto =
'title_accountancy';
367if ($action ==
'delete') {
368 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);
378 $sql .=
" WHERE a.entity = ".((int) $conf->entity);
381 if ($sortfield ==
'country') {
382 $sortfield =
'country_code';
384 $sql .= $db->order($sortfield, $sortorder);
385 $sql .= $db->plimit($listlimit + 1, $offset);
387 $fieldlist = explode(
',', $tabfield[$id]);
389 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
390 print
'<input type="hidden" name="token" value="'.newToken().
'">';
391 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
393 print
'<div class="div-table-responsive">';
394 print
'<table class="noborder centpercent">';
398 $fieldlist = explode(
',', $tabfield[$id]);
401 print
'<tr class="liste_titre">';
402 foreach ($fieldlist as $field => $value) {
405 $valuetoshow = ucfirst($fieldlist[$field]);
406 $valuetoshow = $langs->trans($valuetoshow);
408 if ($fieldlist[$field] ==
'code') {
409 $valuetoshow = $langs->trans(
"Code");
411 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
412 $valuetoshow = $langs->trans(
"Label");
414 if ($fieldlist[$field] ==
'nature') {
415 $valuetoshow = $langs->trans(
"NatureOfJournal");
418 if ($valuetoshow !=
'') {
419 print
'<td class="'.$class.
'">';
420 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
421 print
'<a href="'.$tabhelp[$id][$value].
'">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
422 } elseif (!empty($tabhelp[$id][$value])) {
423 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
432 print
'<input type="hidden" name="id" value="'.$id.
'">';
440 print
'<tr class="oddeven nodrag nodrap nohover">';
442 $obj =
new stdClass();
444 if (
GETPOST(
'actionadd',
'alpha')) {
445 foreach ($fieldlist as $key => $val) {
452 $tmpaction =
'create';
453 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
454 $reshook = $hookmanager->executeHooks(
'createDictionaryFieldlist', $parameters, $obj, $tmpaction);
455 $error = $hookmanager->error; $errors = $hookmanager->errors;
457 if (empty($reshook)) {
461 print
'<td colspan="4" class="right">';
462 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
466 print
'<tr><td colspan="7"> </td></tr>';
473 $resql = $db->query($sql);
475 $num = $db->num_rows($resql);
478 $param =
'&id='.((int) $id);
479 if ($search_country_id > 0) {
480 $param .=
'&search_country_id='.urlencode($search_country_id);
482 $paramwithsearch = $param;
484 $paramwithsearch .=
'&sortorder='.$sortorder;
487 $paramwithsearch .=
'&sortfield='.$sortfield;
489 if (
GETPOST(
'from',
'alpha')) {
490 $paramwithsearch .=
'&from='.GETPOST(
'from',
'alpha');
494 if ($num > $listlimit) {
495 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
496 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
516 print
'<tr class="liste_titre liste_titre_add">';
517 foreach ($fieldlist as $field => $value) {
531 $valuetoshow = ucfirst($fieldlist[$field]);
532 $valuetoshow = $langs->trans($valuetoshow);
533 if ($fieldlist[$field] ==
'code') {
534 $valuetoshow = $langs->trans(
"Code");
536 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
537 $valuetoshow = $langs->trans(
"Label");
539 if ($fieldlist[$field] ==
'nature') {
540 $valuetoshow = $langs->trans(
"NatureOfJournal");
545 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''), $param,
"", $sortfield, $sortorder, $class.
' ');
548 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
557 $obj = $db->fetch_object($resql);
559 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
560 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
562 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
563 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
564 $error = $hookmanager->error; $errors = $hookmanager->errors;
567 if (empty($reshook)) {
571 print
'<td class="center" colspan="4">';
572 print
'<input type="hidden" name="page" value="'.$page.
'">';
573 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
574 print
'<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
575 print
'<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
576 print
'<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"></div>';
580 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
581 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
583 $error = $hookmanager->error; $errors = $hookmanager->errors;
585 if (empty($reshook)) {
586 $langs->load(
"accountancy");
587 foreach ($fieldlist as $field => $value) {
590 $tmpvar = $fieldlist[$field];
591 $valuetoshow = $obj->$tmpvar;
592 if ($valuetoshow ==
'all') {
593 $valuetoshow = $langs->trans(
'All');
594 } elseif ($fieldlist[$field] ==
'nature' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
595 $key = $langs->trans(
"AccountingJournalType".strtoupper($obj->nature));
596 $valuetoshow = ($obj->nature && $key !=
"AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
597 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
598 $valuetoshow = $langs->trans($obj->label);
604 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.
dol_escape_htmltag($valuetoshow).
'</td>';
610 $iserasable = 1; $canbedisabled = 1; $canbemodified = 1;
611 if (isset($obj->code) && $id != 10) {
612 if (($obj->code ==
'0' || $obj->code ==
'' || preg_match(
'/unknown/i', $obj->code))) {
618 $canbemodified = $iserasable;
620 $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) :
'');
627 print
'<td class="nowrap center">';
628 if ($canbedisabled) {
629 print
'<a href="'.$url.
'action='.$acts[$obj->active].
'&token='.newToken().
'">'.$actl[$obj->active].
'</a>';
631 print $langs->trans(
"AlwaysActive");
636 if ($canbemodified) {
637 print
'<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.newToken().
'">'.
img_edit().
'</a></td>';
639 print
'<td> </td>';
644 print
'<td class="center">';
646 print
'<a href="'.$url.
'action=delete&token='.newToken().
'">'.
img_delete().
'</a>';
651 print
'<td> </td>';
691 global $conf, $langs, $db;
692 global $form, $mysoc;
694 global $elementList, $sourceList, $localtax_typeList;
700 foreach ($fieldlist as $field => $value) {
701 if ($fieldlist[$field] ==
'nature') {
703 print $form->selectarray(
'nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
''));
705 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
706 print
'<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
'').
'" name="'.$fieldlist[$field].
'"></td>';
709 $size =
''; $class =
'';
710 if ($fieldlist[$field] ==
'code') {
711 $class =
'maxwidth100';
713 if ($fieldlist[$field] ==
'label') {
714 $class =
'quatrevingtpercent';
716 if ($fieldlist[$field] ==
'sortorder' || $fieldlist[$field] ==
'sens' || $fieldlist[$field] ==
'category_type') {
719 print
'<input type="text" '.$size.
'class="flat'.($class ?
' '.$class :
'').
'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
'').
'" name="'.$fieldlist[$field].
'">';
complete_dictionary_with_modules(&$taborder, &$tabname, &$tablib, &$tabsql, &$tabsqlsort, &$tabfield, &$tabfieldvalue, &$tabfieldinsert, &$tabrowid, &$tabcond, &$tabhelp, &$tabcomplete)
Add external modules to list of dictionaries.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $hideselectlimit=0, $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier 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...
fieldListJournal($fieldlist, $obj='', $tabname='', $context='')
Show fields in insert/edit mode.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.