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';
50$langs->loadLangs(array(
"admin",
"compta",
"accountancy"));
52$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
53$confirm =
GETPOST(
'confirm',
'alpha');
55$rowid =
GETPOST(
'rowid',
'alpha');
56$code =
GETPOST(
'code',
'alpha');
59if (!$user->hasRight(
'accounting',
'chartofaccount')) {
67$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
68$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
70$listoffset =
GETPOST(
'listoffset',
'alpha');
74$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
75$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
77if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
81$offset = $listlimit * $page;
84if (empty($sortfield)) {
87if (empty($sortorder)) {
93$search_country_id =
GETPOST(
'search_country_id',
'int');
96$hookmanager->initHooks(array(
'admin'));
102$taborder = array(35);
106$tabname[35] = MAIN_DB_PREFIX.
"accounting_journal";
110$tablib[35] =
"DictionaryAccountancyJournal";
114$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";
117$tabsqlsort = array();
118$tabsqlsort[35] =
"code ASC";
122$tabfield[35] =
"code,label,nature";
125$tabfieldvalue = array();
126$tabfieldvalue[35] =
"code,label,nature";
129$tabfieldinsert = array();
130$tabfieldinsert[35] =
"code,label,nature";
144$tabhelp[35] = array(
'code' => $langs->trans(
"EnterAnyCode"));
147$tabfieldcheck = array();
148$tabfieldcheck[35] = array();
151complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
155$elementList = array();
158 '1' => $langs->trans(
'AccountingJournalType1'),
159 '2' => $langs->trans(
'AccountingJournalType2'),
160 '3' => $langs->trans(
'AccountingJournalType3'),
161 '4' => $langs->trans(
'AccountingJournalType4'),
162 '5' => $langs->trans(
'AccountingJournalType5'),
163 '8' => $langs->trans(
'AccountingJournalType8'),
164 '9' => $langs->trans(
'AccountingJournalType9'),
171if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha')) {
172 $search_country_id =
'';
176if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
177 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
178 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
179 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
180 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
186 if (GETPOSTISSET(
"code")) {
189 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'),
null,
'errors');
192 if (!
GETPOST(
'label',
'alpha')) {
193 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
198 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
200 if ($tabrowid[$id]) {
202 $sql =
"SELECT MAX(".$db->sanitize($tabrowid[$id]).
") newid FROM ".$db->sanitize($tabname[$id]);
203 $result = $db->query($sql);
205 $obj = $db->fetch_object($result);
206 $newid = ($obj->newid + 1);
213 $sql =
"INSERT INTO ".$db->sanitize($tabname[$id]).
" (";
215 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
216 $sql .= $tabrowid[
$id].
",";
218 $sql .= $db->sanitize($tabfieldinsert[$id]);
219 $sql .=
",active,entity)";
223 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
227 foreach ($listfieldinsert as $f => $value) {
231 if (
GETPOST($listfieldvalue[$i]) ==
'') {
234 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
238 $sql .=
",1,".$conf->entity.
")";
241 $result = $db->query($sql);
244 $_POST = array(
'id' => $id);
246 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
247 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
255 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
256 if ($tabrowid[$id]) {
257 $rowidcol = $tabrowid[
$id];
263 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET ";
265 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
266 $sql .= $db->sanitize($tabrowid[$id]).
" = ";
267 $sql .=
"'".$db->escape($rowid).
"', ";
270 foreach ($listfieldmodify as $field) {
274 $sql .= $field.
" = ";
275 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
278 $sql .=
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
279 $sql .=
" AND entity = ".((int) $conf->entity);
283 $resql = $db->query($sql);
290if ($action ==
'confirm_delete' && $confirm ==
'yes') {
291 if ($tabrowid[$id]) {
292 $rowidcol = $tabrowid[
$id];
297 $sql =
"DELETE from ".$db->sanitize($tabname[$id]).
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
298 $sql .=
" AND entity = ".((int) $conf->entity);
301 $result = $db->query($sql);
303 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
304 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
312if ($action == $acts[0]) {
314 if ($tabrowid[$id]) {
315 $rowidcol = $tabrowid[
$id];
321 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
323 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE code = '".$db->escape($code).
"'";
325 $sql .=
" AND entity = ".$conf->entity;
327 $result = $db->query($sql);
334if ($action == $acts[1]) {
336 if ($tabrowid[$id]) {
337 $rowidcol = $tabrowid[
$id];
343 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
345 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE code='".$db->escape($code).
"'";
347 $sql .=
" AND entity = ".$conf->entity;
349 $result = $db->query($sql);
360$form =
new Form($db);
363$title = $langs->trans(
'AccountingJournals');
364$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
365llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-admin_journals_list');
367$titre = $langs->trans(
"DictionarySetup");
370$titre .=
' - '.$langs->trans($tablib[$id]);
371$titlepicto =
'title_accountancy';
377if ($action ==
'delete') {
378 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);
387$sql .=
" WHERE a.entity = ".((int) $conf->entity);
390if ($sortfield ==
'country') {
391 $sortfield =
'country_code';
393$sql .= $db->order($sortfield, $sortorder);
394$sql .= $db->plimit($listlimit + 1, $offset);
396$fieldlist = explode(
',', $tabfield[$id]);
398print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'" method="POST">';
399print
'<input type="hidden" name="token" value="'.newToken().
'">';
400print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
402print
'<div class="div-table-responsive">';
403print
'<table class="noborder centpercent">';
407 $fieldlist = explode(
',', $tabfield[$id]);
410 print
'<tr class="liste_titre">';
411 foreach ($fieldlist as $field => $value) {
414 $valuetoshow = ucfirst($fieldlist[$field]);
415 $valuetoshow = $langs->trans($valuetoshow);
417 if ($fieldlist[$field] ==
'code') {
418 $valuetoshow = $langs->trans(
"Code");
420 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
421 $valuetoshow = $langs->trans(
"Label");
423 if ($fieldlist[$field] ==
'nature') {
424 $valuetoshow = $langs->trans(
"NatureOfJournal");
427 if ($valuetoshow !=
'') {
428 print
'<td class="'.$class.
'">';
429 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
430 print
'<a href="'.$tabhelp[
$id][$value].
'">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
431 } elseif (!empty($tabhelp[$id][$value])) {
432 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
441 print
'<input type="hidden" name="id" value="'.$id.
'">';
449 print
'<tr class="oddeven nodrag nodrop nohover">';
453 if (
GETPOST(
'actionadd',
'alpha')) {
454 foreach ($fieldlist as $key => $val) {
461 $tmpaction =
'create';
462 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
463 $reshook = $hookmanager->executeHooks(
'createDictionaryFieldlist', $parameters, $obj, $tmpaction);
464 $error = $hookmanager->error;
465 $errors = $hookmanager->errors;
467 if (empty($reshook)) {
471 print
'<td colspan="4" class="right">';
472 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
476 print
'<tr><td colspan="7"> </td></tr>';
483$resql = $db->query($sql);
485 $num = $db->num_rows($resql);
488 $param =
'&id='.((int) $id);
489 if ($search_country_id > 0) {
490 $param .=
'&search_country_id='.urlencode((
string) ($search_country_id));
492 $paramwithsearch = $param;
493 $paramwithsearch .=
'&sortorder='.$sortorder;
494 $paramwithsearch .=
'&sortfield='.$sortfield;
496 if (
GETPOST(
'from',
'alpha')) {
497 $paramwithsearch .=
'&from='.GETPOST(
'from',
'alpha');
501 if ($num > $listlimit) {
502 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
503 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit ? 1 : 0),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
523 print
'<tr class="liste_titre liste_titre_add">';
524 foreach ($fieldlist as $field => $value) {
536 $valuetoshow = ucfirst($fieldlist[$field]);
537 $valuetoshow = $langs->trans($valuetoshow);
538 if ($fieldlist[$field] ==
'code') {
539 $valuetoshow = $langs->trans(
"Code");
541 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
542 $valuetoshow = $langs->trans(
"Label");
544 if ($fieldlist[$field] ==
'nature') {
545 $valuetoshow = $langs->trans(
"NatureOfJournal");
549 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) {
594 $tmpvar = $fieldlist[$field];
595 $valuetoshow = $obj->$tmpvar;
596 if ($valuetoshow ==
'all') {
597 $valuetoshow = $langs->trans(
'All');
598 } elseif ($fieldlist[$field] ==
'nature' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
599 $key = $langs->trans(
"AccountingJournalType".strtoupper($obj->nature));
600 $valuetoshow = ($obj->nature && $key !=
"AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
601 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
602 $valuetoshow = $langs->trans($obj->label);
607 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.
dol_escape_htmltag($valuetoshow).
'</td>';
615 if (isset($obj->code) && $id != 10) {
616 if (($obj->code ==
'0' || $obj->code ==
'' || preg_match(
'/unknown/i', $obj->code))) {
622 $canbemodified = $iserasable;
624 $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) :
'');
629 print
'<td class="nowrap center">';
630 if ($canbedisabled) {
631 print
'<a href="'.$url.
'action='.$acts[$obj->active].
'&token='.
newToken().
'">'.$actl[$obj->active].
'</a>';
633 print $langs->trans(
"AlwaysActive");
638 if ($canbemodified) {
639 print
'<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
641 print
'<td> </td>';
646 print
'<td class="center">';
653 print
'<td> </td>';
693 global $conf, $langs, $db;
696 global $elementList, $sourceList, $localtax_typeList;
702 foreach ($fieldlist as $field => $value) {
703 if ($fieldlist[$field] ==
'nature') {
705 print $form->selectarray(
'nature', $sourceList, (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
''));
707 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
708 print
'<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
'').
'" name="'.$fieldlist[$field].
'"></td>';
713 if ($fieldlist[$field] ==
'code') {
714 $class =
'maxwidth100';
716 if ($fieldlist[$field] ==
'label') {
717 $class =
'quatrevingtpercent';
719 if ($fieldlist[$field] ==
'sortorder' || $fieldlist[$field] ==
'sens' || $fieldlist[$field] ==
'category_type') {
722 print
'<input type="text" '.$size.
'class="flat'.($class ?
' '.$class :
'').
'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
'').
'" name="'.$fieldlist[$field].
'">';
$id
Support class for third parties, contacts, members, users or resources.
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.
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_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)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.