26if (!defined(
'CSRFCHECK_WITH_TOKEN')) {
27 define(
'CSRFCHECK_WITH_TOKEN',
'1');
31require
'../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
41$langs->loadLangs(array(
"admin",
"compta",
"accountancy"));
43$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
44$confirm =
GETPOST(
'confirm',
'alpha');
46$rowid =
GETPOST(
'rowid',
'alpha');
47$code =
GETPOST(
'code',
'alpha');
50if (!$user->hasRight(
'accounting',
'chartofaccount')) {
58$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
59$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
61$listoffset =
GETPOST(
'listoffset',
'alpha');
65$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
66$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
68if (empty($page) || $page == -1) {
71$offset = $listlimit * $page;
74if (empty($sortfield)) {
77if (empty($sortorder)) {
83$search_country_id =
GETPOST(
'search_country_id',
'int');
86$hookmanager->initHooks(array(
'admin'));
96$tabname[35] = MAIN_DB_PREFIX.
"accounting_journal";
100$tablib[35] =
"DictionaryAccountancyJournal";
104$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";
107$tabsqlsort = array();
108$tabsqlsort[35] =
"code ASC";
112$tabfield[35] =
"code,label,nature";
115$tabfieldvalue = array();
116$tabfieldvalue[35] =
"code,label,nature";
119$tabfieldinsert = array();
120$tabfieldinsert[35] =
"code,label,nature";
130$tabcond[35] = isModEnabled(
'accounting');
134$tabhelp[35] = array(
'code' => $langs->trans(
"EnterAnyCode"));
137$tabfieldcheck = array();
138$tabfieldcheck[35] = array();
141complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
145$elementList = array();
148 '1' => $langs->trans(
'AccountingJournalType1'),
149 '2' => $langs->trans(
'AccountingJournalType2'),
150 '3' => $langs->trans(
'AccountingJournalType3'),
151 '4' => $langs->trans(
'AccountingJournalType4'),
152 '5' => $langs->trans(
'AccountingJournalType5'),
153 '8' => $langs->trans(
'AccountingJournalType8'),
154 '9' => $langs->trans(
'AccountingJournalType9'),
161if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha')) {
162 $search_country_id =
'';
166if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
167 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
168 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
169 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
170 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
176 if (GETPOSTISSET(
"code")) {
179 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'),
null,
'errors');
182 if (!
GETPOST(
'label',
'alpha')) {
183 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
188 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
190 if ($tabrowid[$id]) {
192 $sql =
"SELECT MAX(".$db->sanitize($tabrowid[$id]).
") newid FROM ".$db->sanitize($tabname[$id]);
193 $result = $db->query($sql);
195 $obj = $db->fetch_object($result);
196 $newid = ($obj->newid + 1);
203 $sql =
"INSERT INTO ".$db->sanitize($tabname[$id]).
" (";
205 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
206 $sql .= $tabrowid[$id].
",";
208 $sql .= $db->sanitize($tabfieldinsert[$id]);
209 $sql .=
",active,entity)";
213 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
217 foreach ($listfieldinsert as $f => $value) {
221 if (
GETPOST($listfieldvalue[$i]) ==
'') {
224 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
228 $sql .=
",1,".$conf->entity.
")";
231 $result = $db->query($sql);
234 $_POST = array(
'id' => $id);
236 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
237 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
245 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
246 if ($tabrowid[$id]) {
247 $rowidcol = $tabrowid[$id];
253 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET ";
255 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
256 $sql .= $db->sanitize($tabrowid[$id]).
" = ";
257 $sql .=
"'".$db->escape($rowid).
"', ";
260 foreach ($listfieldmodify as $field) {
264 $sql .= $field.
" = ";
265 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
268 $sql .=
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
269 $sql .=
" AND entity = ".((int) $conf->entity);
273 $resql = $db->query($sql);
280if ($action ==
'confirm_delete' && $confirm ==
'yes') {
281 if ($tabrowid[$id]) {
282 $rowidcol = $tabrowid[$id];
287 $sql =
"DELETE from ".$db->sanitize($tabname[$id]).
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
288 $sql .=
" AND entity = ".((int) $conf->entity);
291 $result = $db->query($sql);
293 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
294 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
302if ($action == $acts[0]) {
303 if ($tabrowid[$id]) {
304 $rowidcol = $tabrowid[$id];
310 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
312 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE code = '".$db->escape($code).
"'";
314 $sql .=
" AND entity = ".$conf->entity;
316 $result = $db->query($sql);
323if ($action == $acts[1]) {
324 if ($tabrowid[$id]) {
325 $rowidcol = $tabrowid[$id];
331 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
333 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE code='".$db->escape($code).
"'";
335 $sql .=
" AND entity = ".$conf->entity;
337 $result = $db->query($sql);
348$form =
new Form($db);
351$title = $langs->trans(
'AccountingJournals');
352$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
355$titre = $langs->trans(
"DictionarySetup");
358 $titre .=
' - '.$langs->trans($tablib[$id]);
359 $titlepicto =
'title_accountancy';
368if ($action ==
'delete') {
369 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">';
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;
456 $errors = $hookmanager->errors;
458 if (empty($reshook)) {
462 print
'<td colspan="4" class="right">';
463 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
467 print
'<tr><td colspan="7"> </td></tr>';
474 $resql = $db->query($sql);
476 $num = $db->num_rows($resql);
479 $param =
'&id='.((int) $id);
480 if ($search_country_id > 0) {
481 $param .=
'&search_country_id='.urlencode((
string) ($search_country_id));
483 $paramwithsearch = $param;
485 $paramwithsearch .=
'&sortorder='.$sortorder;
488 $paramwithsearch .=
'&sortfield='.$sortfield;
490 if (
GETPOST(
'from',
'alpha')) {
491 $paramwithsearch .=
'&from='.GETPOST(
'from',
'alpha');
495 if ($num > $listlimit) {
496 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
497 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
517 print
'<tr class="liste_titre liste_titre_add">';
518 foreach ($fieldlist as $field => $value) {
532 $valuetoshow = ucfirst($fieldlist[$field]);
533 $valuetoshow = $langs->trans($valuetoshow);
534 if ($fieldlist[$field] ==
'code') {
535 $valuetoshow = $langs->trans(
"Code");
537 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
538 $valuetoshow = $langs->trans(
"Label");
540 if ($fieldlist[$field] ==
'nature') {
541 $valuetoshow = $langs->trans(
"NatureOfJournal");
546 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''), $param,
"", $sortfield, $sortorder, $class.
' ');
549 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
558 $obj = $db->fetch_object($resql);
560 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
561 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
563 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
564 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
565 $error = $hookmanager->error;
566 $errors = $hookmanager->errors;
569 if (empty($reshook)) {
573 print
'<td class="center" colspan="4">';
574 print
'<input type="hidden" name="page" value="'.$page.
'">';
575 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
576 print
'<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
577 print
'<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
578 print
'<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"></div>';
582 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
583 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
585 $error = $hookmanager->error;
586 $errors = $hookmanager->errors;
588 if (empty($reshook)) {
589 $langs->load(
"accountancy");
590 foreach ($fieldlist as $field => $value) {
593 $tmpvar = $fieldlist[$field];
594 $valuetoshow = $obj->$tmpvar;
595 if ($valuetoshow ==
'all') {
596 $valuetoshow = $langs->trans(
'All');
597 } elseif ($fieldlist[$field] ==
'nature' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
598 $key = $langs->trans(
"AccountingJournalType".strtoupper($obj->nature));
599 $valuetoshow = ($obj->nature && $key !=
"AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
600 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
601 $valuetoshow = $langs->trans($obj->label);
607 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.
dol_escape_htmltag($valuetoshow).
'</td>';
616 if (isset($obj->code) && $id != 10) {
617 if (($obj->code ==
'0' || $obj->code ==
'' || preg_match(
'/unknown/i', $obj->code))) {
623 $canbemodified = $iserasable;
625 $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) :
'');
632 print
'<td class="nowrap center">';
633 if ($canbedisabled) {
634 print
'<a href="'.$url.
'action='.$acts[$obj->active].
'&token='.
newToken().
'">'.$actl[$obj->active].
'</a>';
636 print $langs->trans(
"AlwaysActive");
641 if ($canbemodified) {
642 print
'<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
644 print
'<td> </td>';
649 print
'<td class="center">';
656 print
'<td> </td>';
696 global $conf, $langs, $db;
697 global $form, $mysoc;
699 global $elementList, $sourceList, $localtax_typeList;
705 foreach ($fieldlist as $field => $value) {
706 if ($fieldlist[$field] ==
'nature') {
708 print $form->selectarray(
'nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
''));
710 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
711 print
'<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
'').
'" name="'.$fieldlist[$field].
'"></td>';
716 if ($fieldlist[$field] ==
'code') {
717 $class =
'maxwidth100';
719 if ($fieldlist[$field] ==
'label') {
720 $class =
'quatrevingtpercent';
722 if ($fieldlist[$field] ==
'sortorder' || $fieldlist[$field] ==
'sens' || $fieldlist[$field] ==
'category_type') {
725 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($title, $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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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.
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.
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.
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.
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...
fieldListJournal($fieldlist, $obj=null, $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.