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);
277if ($action ==
'confirm_delete' && $confirm ==
'yes') {
278 if ($tabrowid[$id]) {
279 $rowidcol = $tabrowid[$id];
284 $sql =
"DELETE from ".$tabname[$id].
" WHERE ".$rowidcol.
" = ".((int) $rowid);
285 $sql .=
" AND entity = ".((int) $conf->entity);
288 $result = $db->query($sql);
290 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
291 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
299if ($action == $acts[0]) {
300 if ($tabrowid[$id]) {
301 $rowidcol = $tabrowid[$id];
307 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE ".$rowidcol.
" = ".((int) $rowid);
309 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE code='".$db->escape($code).
"'";
311 $sql .=
" AND entity = ".$conf->entity;
313 $result = $db->query($sql);
320if ($action == $acts[1]) {
321 if ($tabrowid[$id]) {
322 $rowidcol = $tabrowid[$id];
328 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE ".$rowidcol.
" = ".((int) $rowid);
330 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE code='".$db->escape($code).
"'";
332 $sql .=
" AND entity = ".$conf->entity;
334 $result = $db->query($sql);
345$form =
new Form($db);
348$title = $langs->trans(
'AccountingJournals');
349$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
352$titre = $langs->trans(
"DictionarySetup");
355 $titre .=
' - '.$langs->trans($tablib[$id]);
356 $titlepicto =
'title_accountancy';
363if ($action ==
'delete') {
364 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);
373 $sql .=
" WHERE a.entity = ".((int) $conf->entity);
376 if ($sortfield ==
'country') {
377 $sortfield =
'country_code';
379 $sql .= $db->order($sortfield, $sortorder);
380 $sql .= $db->plimit($listlimit + 1, $offset);
382 $fieldlist = explode(
',', $tabfield[$id]);
384 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
385 print
'<input type="hidden" name="token" value="'.newToken().
'">';
386 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
388 print
'<div class="div-table-responsive">';
389 print
'<table class="noborder centpercent">';
393 $fieldlist = explode(
',', $tabfield[$id]);
396 print
'<tr class="liste_titre">';
397 foreach ($fieldlist as $field => $value) {
400 $valuetoshow = ucfirst($fieldlist[$field]);
401 $valuetoshow = $langs->trans($valuetoshow);
403 if ($fieldlist[$field] ==
'code') {
404 $valuetoshow = $langs->trans(
"Code");
406 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
407 $valuetoshow = $langs->trans(
"Label");
409 if ($fieldlist[$field] ==
'nature') {
410 $valuetoshow = $langs->trans(
"NatureOfJournal");
413 if ($valuetoshow !=
'') {
414 print
'<td class="'.$class.
'">';
415 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
416 print
'<a href="'.$tabhelp[$id][$value].
'">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
417 } elseif (!empty($tabhelp[$id][$value])) {
418 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
427 print
'<input type="hidden" name="id" value="'.$id.
'">';
435 print
'<tr class="oddeven nodrag nodrap nohover">';
439 if (
GETPOST(
'actionadd',
'alpha')) {
440 foreach ($fieldlist as $key => $val) {
447 $tmpaction =
'create';
448 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
449 $reshook = $hookmanager->executeHooks(
'createDictionaryFieldlist', $parameters, $obj, $tmpaction);
450 $error = $hookmanager->error;
451 $errors = $hookmanager->errors;
453 if (empty($reshook)) {
457 print
'<td colspan="4" class="right">';
458 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
462 print
'<tr><td colspan="7"> </td></tr>';
469 $resql = $db->query($sql);
471 $num = $db->num_rows($resql);
474 $param =
'&id='.((int) $id);
475 if ($search_country_id > 0) {
476 $param .=
'&search_country_id='.urlencode($search_country_id);
478 $paramwithsearch = $param;
480 $paramwithsearch .=
'&sortorder='.$sortorder;
483 $paramwithsearch .=
'&sortfield='.$sortfield;
485 if (
GETPOST(
'from',
'alpha')) {
486 $paramwithsearch .=
'&from='.GETPOST(
'from',
'alpha');
490 if ($num > $listlimit) {
491 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
492 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
512 print
'<tr class="liste_titre liste_titre_add">';
513 foreach ($fieldlist as $field => $value) {
527 $valuetoshow = ucfirst($fieldlist[$field]);
528 $valuetoshow = $langs->trans($valuetoshow);
529 if ($fieldlist[$field] ==
'code') {
530 $valuetoshow = $langs->trans(
"Code");
532 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
533 $valuetoshow = $langs->trans(
"Label");
535 if ($fieldlist[$field] ==
'nature') {
536 $valuetoshow = $langs->trans(
"NatureOfJournal");
541 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''), $param,
"", $sortfield, $sortorder, $class.
' ');
544 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
553 $obj = $db->fetch_object($resql);
555 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
556 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
558 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
559 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
560 $error = $hookmanager->error;
561 $errors = $hookmanager->errors;
564 if (empty($reshook)) {
568 print
'<td class="center" colspan="4">';
569 print
'<input type="hidden" name="page" value="'.$page.
'">';
570 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
571 print
'<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
572 print
'<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
573 print
'<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"></div>';
577 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
578 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
580 $error = $hookmanager->error;
581 $errors = $hookmanager->errors;
583 if (empty($reshook)) {
584 $langs->load(
"accountancy");
585 foreach ($fieldlist as $field => $value) {
588 $tmpvar = $fieldlist[$field];
589 $valuetoshow = $obj->$tmpvar;
590 if ($valuetoshow ==
'all') {
591 $valuetoshow = $langs->trans(
'All');
592 } elseif ($fieldlist[$field] ==
'nature' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
593 $key = $langs->trans(
"AccountingJournalType".strtoupper($obj->nature));
594 $valuetoshow = ($obj->nature && $key !=
"AccountingJournalType".strtoupper($langs->trans($obj->nature)) ? $key : $obj->{$fieldlist[$field]});
595 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'accounting_journal') {
596 $valuetoshow = $langs->trans($obj->label);
602 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.
dol_escape_htmltag($valuetoshow).
'</td>';
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>';
711 if ($fieldlist[$field] ==
'code') {
712 $class =
'maxwidth100';
714 if ($fieldlist[$field] ==
'label') {
715 $class =
'quatrevingtpercent';
717 if ($fieldlist[$field] ==
'sortorder' || $fieldlist[$field] ==
'sens' || $fieldlist[$field] ==
'category_type') {
720 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=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.