27if (!defined(
'CSRFCHECK_WITH_TOKEN')) {
28 define(
'CSRFCHECK_WITH_TOKEN',
'1');
32require
'../../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingjournal.class.php';
42$langs->loadLangs(array(
"admin",
"compta",
"accountancy"));
44$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
45$confirm =
GETPOST(
'confirm',
'alpha');
47$rowid =
GETPOST(
'rowid',
'alpha');
48$code =
GETPOST(
'code',
'alpha');
51if (!$user->hasRight(
'accounting',
'chartofaccount')) {
59$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
60$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
62$listoffset =
GETPOST(
'listoffset',
'alpha');
66$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
67$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
69if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
73$offset = $listlimit * $page;
76if (empty($sortfield)) {
79if (empty($sortorder)) {
85$search_country_id =
GETPOST(
'search_country_id',
'int');
88$hookmanager->initHooks(array(
'admin'));
98$tabname[35] = MAIN_DB_PREFIX.
"accounting_journal";
102$tablib[35] =
"DictionaryAccountancyJournal";
106$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";
109$tabsqlsort = array();
110$tabsqlsort[35] =
"code ASC";
114$tabfield[35] =
"code,label,nature";
117$tabfieldvalue = array();
118$tabfieldvalue[35] =
"code,label,nature";
121$tabfieldinsert = array();
122$tabfieldinsert[35] =
"code,label,nature";
132$tabcond[35] = isModEnabled(
'accounting');
136$tabhelp[35] = array(
'code' => $langs->trans(
"EnterAnyCode"));
139$tabfieldcheck = array();
140$tabfieldcheck[35] = array();
143complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
147$elementList = array();
150 '1' => $langs->trans(
'AccountingJournalType1'),
151 '2' => $langs->trans(
'AccountingJournalType2'),
152 '3' => $langs->trans(
'AccountingJournalType3'),
153 '4' => $langs->trans(
'AccountingJournalType4'),
154 '5' => $langs->trans(
'AccountingJournalType5'),
155 '8' => $langs->trans(
'AccountingJournalType8'),
156 '9' => $langs->trans(
'AccountingJournalType9'),
163if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha')) {
164 $search_country_id =
'';
168if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
169 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
170 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
171 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
172 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
178 if (GETPOSTISSET(
"code")) {
181 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'),
null,
'errors');
184 if (!
GETPOST(
'label',
'alpha')) {
185 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
190 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
192 if ($tabrowid[$id]) {
194 $sql =
"SELECT MAX(".$db->sanitize($tabrowid[$id]).
") newid FROM ".$db->sanitize($tabname[$id]);
195 $result = $db->query($sql);
197 $obj = $db->fetch_object($result);
198 $newid = ($obj->newid + 1);
205 $sql =
"INSERT INTO ".$db->sanitize($tabname[$id]).
" (";
207 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
208 $sql .= $tabrowid[
$id].
",";
210 $sql .= $db->sanitize($tabfieldinsert[$id]);
211 $sql .=
",active,entity)";
215 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
219 foreach ($listfieldinsert as $f => $value) {
223 if (
GETPOST($listfieldvalue[$i]) ==
'') {
226 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
230 $sql .=
",1,".$conf->entity.
")";
233 $result = $db->query($sql);
236 $_POST = array(
'id' => $id);
238 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
239 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
247 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
248 if ($tabrowid[$id]) {
249 $rowidcol = $tabrowid[
$id];
255 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET ";
257 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
258 $sql .= $db->sanitize($tabrowid[$id]).
" = ";
259 $sql .=
"'".$db->escape($rowid).
"', ";
262 foreach ($listfieldmodify as $field) {
266 $sql .= $field.
" = ";
267 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
270 $sql .=
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
271 $sql .=
" AND entity = ".((int) $conf->entity);
275 $resql = $db->query($sql);
282if ($action ==
'confirm_delete' && $confirm ==
'yes') {
283 if ($tabrowid[$id]) {
284 $rowidcol = $tabrowid[
$id];
289 $sql =
"DELETE from ".$db->sanitize($tabname[$id]).
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
290 $sql .=
" AND entity = ".((int) $conf->entity);
293 $result = $db->query($sql);
295 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
296 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
304if ($action == $acts[0]) {
305 if ($tabrowid[$id]) {
306 $rowidcol = $tabrowid[
$id];
312 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
314 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE code = '".$db->escape($code).
"'";
316 $sql .=
" AND entity = ".$conf->entity;
318 $result = $db->query($sql);
325if ($action == $acts[1]) {
326 if ($tabrowid[$id]) {
327 $rowidcol = $tabrowid[
$id];
333 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
335 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE code='".$db->escape($code).
"'";
337 $sql .=
" AND entity = ".$conf->entity;
339 $result = $db->query($sql);
350$form =
new Form($db);
353$title = $langs->trans(
'AccountingJournals');
354$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
355llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-admin_journals_list');
357$titre = $langs->trans(
"DictionarySetup");
360 $titre .=
' - '.$langs->trans($tablib[$id]);
361 $titlepicto =
'title_accountancy';
370if ($action ==
'delete') {
371 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);
380 $sql .=
" WHERE a.entity = ".((int) $conf->entity);
383 if ($sortfield ==
'country') {
384 $sortfield =
'country_code';
386 $sql .= $db->order($sortfield, $sortorder);
387 $sql .= $db->plimit($listlimit + 1, $offset);
389 $fieldlist = explode(
',', $tabfield[$id]);
391 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'" method="POST">';
392 print
'<input type="hidden" name="token" value="'.newToken().
'">';
393 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
395 print
'<div class="div-table-responsive">';
396 print
'<table class="noborder centpercent">';
400 $fieldlist = explode(
',', $tabfield[$id]);
403 print
'<tr class="liste_titre">';
404 foreach ($fieldlist as $field => $value) {
407 $valuetoshow = ucfirst($fieldlist[$field]);
408 $valuetoshow = $langs->trans($valuetoshow);
410 if ($fieldlist[$field] ==
'code') {
411 $valuetoshow = $langs->trans(
"Code");
413 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
414 $valuetoshow = $langs->trans(
"Label");
416 if ($fieldlist[$field] ==
'nature') {
417 $valuetoshow = $langs->trans(
"NatureOfJournal");
420 if ($valuetoshow !=
'') {
421 print
'<td class="'.$class.
'">';
422 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
423 print
'<a href="'.$tabhelp[
$id][$value].
'">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
424 } elseif (!empty($tabhelp[$id][$value])) {
425 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
434 print
'<input type="hidden" name="id" value="'.$id.
'">';
442 print
'<tr class="oddeven nodrag nodrop nohover">';
446 if (
GETPOST(
'actionadd',
'alpha')) {
447 foreach ($fieldlist as $key => $val) {
454 $tmpaction =
'create';
455 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
456 $reshook = $hookmanager->executeHooks(
'createDictionaryFieldlist', $parameters, $obj, $tmpaction);
457 $error = $hookmanager->error;
458 $errors = $hookmanager->errors;
460 if (empty($reshook)) {
464 print
'<td colspan="4" class="right">';
465 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
469 print
'<tr><td colspan="7"> </td></tr>';
476 $resql = $db->query($sql);
478 $num = $db->num_rows($resql);
481 $param =
'&id='.((int) $id);
482 if ($search_country_id > 0) {
483 $param .=
'&search_country_id='.urlencode((
string) ($search_country_id));
485 $paramwithsearch = $param;
487 $paramwithsearch .=
'&sortorder='.$sortorder;
490 $paramwithsearch .=
'&sortfield='.$sortfield;
492 if (
GETPOST(
'from',
'alpha')) {
493 $paramwithsearch .=
'&from='.GETPOST(
'from',
'alpha');
497 if ($num > $listlimit) {
498 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
499 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
519 print
'<tr class="liste_titre liste_titre_add">';
520 foreach ($fieldlist as $field => $value) {
534 $valuetoshow = ucfirst($fieldlist[$field]);
535 $valuetoshow = $langs->trans($valuetoshow);
536 if ($fieldlist[$field] ==
'code') {
537 $valuetoshow = $langs->trans(
"Code");
539 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
540 $valuetoshow = $langs->trans(
"Label");
542 if ($fieldlist[$field] ==
'nature') {
543 $valuetoshow = $langs->trans(
"NatureOfJournal");
548 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''), $param,
"", $sortfield, $sortorder, $class.
' ');
551 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
560 $obj = $db->fetch_object($resql);
562 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
563 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
565 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
566 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
567 $error = $hookmanager->error;
568 $errors = $hookmanager->errors;
571 if (empty($reshook)) {
575 print
'<td class="center" colspan="4">';
576 print
'<input type="hidden" name="page" value="'.$page.
'">';
577 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
578 print
'<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
579 print
'<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
580 print
'<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"></div>';
584 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
585 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
587 $error = $hookmanager->error;
588 $errors = $hookmanager->errors;
590 if (empty($reshook)) {
591 $langs->load(
"accountancy");
592 foreach ($fieldlist as $field => $value) {
595 $tmpvar = $fieldlist[$field];
596 $valuetoshow = $obj->$tmpvar;
597 if ($valuetoshow ==
'all') {
598 $valuetoshow = $langs->trans(
'All');
599 } elseif ($fieldlist[$field] ==
'nature' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
600 $key = $langs->trans(
"AccountingJournalType".strtoupper($obj->nature));
601 $valuetoshow = ($obj->nature && $key !=
"AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
602 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
603 $valuetoshow = $langs->trans($obj->label);
609 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.
dol_escape_htmltag($valuetoshow).
'</td>';
618 if (isset($obj->code) && $id != 10) {
619 if (($obj->code ==
'0' || $obj->code ==
'' || preg_match(
'/unknown/i', $obj->code))) {
625 $canbemodified = $iserasable;
627 $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) :
'');
634 print
'<td class="nowrap center">';
635 if ($canbedisabled) {
636 print
'<a href="'.$url.
'action='.$acts[$obj->active].
'&token='.
newToken().
'">'.$actl[$obj->active].
'</a>';
638 print $langs->trans(
"AlwaysActive");
643 if ($canbemodified) {
644 print
'<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
646 print
'<td> </td>';
651 print
'<td class="center">';
658 print
'<td> </td>';
698 global $conf, $langs, $db;
699 global $form, $mysoc;
701 global $elementList, $sourceList, $localtax_typeList;
707 foreach ($fieldlist as $field => $value) {
708 if ($fieldlist[$field] ==
'nature') {
710 print $form->selectarray(
'nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
''));
712 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
713 print
'<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
'').
'" name="'.$fieldlist[$field].
'"></td>';
718 if ($fieldlist[$field] ==
'code') {
719 $class =
'maxwidth100';
721 if ($fieldlist[$field] ==
'label') {
722 $class =
'quatrevingtpercent';
724 if ($fieldlist[$field] ==
'sortorder' || $fieldlist[$field] ==
'sens' || $fieldlist[$field] ==
'category_type') {
727 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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
print_fleche_navigation($page, $file, $options='', $nextpage=0, $betweenarrows='', $afterarrows='', $limit=-1, $totalnboflines=0, $selectlimitsuffix='', $beforearrows='', $hidenavigation=0)
Function to show navigation arrows into lists.
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.
$context
@method int call_trigger(string $triggerName, User $user)
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.