38require
'../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
45if (isModEnabled(
'accounting')) {
46 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
50$langs->loadLangs(array(
'accountancy',
'admin',
'companies',
'compta',
'errors',
'holiday',
'hrm',
'resource'));
52$action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
53$confirm =
GETPOST(
'confirm',
'alpha');
55$rowid =
GETPOST(
'rowid',
'alpha');
56$code =
GETPOST(
'code',
'alpha');
62$actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
63$actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
65$listoffset =
GETPOST(
'listoffset',
'alpha');
69$sortfield =
GETPOST(
"sortfield",
'aZ09comma');
70$sortorder =
GETPOST(
"sortorder",
'aZ09comma');
72if (empty($page) || $page < 0 ||
GETPOST(
'button_search',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
76$offset = $listlimit * $page;
80$search_country_id =
GETPOST(
'search_country_id',
'int');
84if ($user->socid > 0) {
87if (!$user->hasRight(
'accounting',
'chartofaccount')) {
93$hookmanager->initHooks(array(
'admin'));
101$tabname[31] = MAIN_DB_PREFIX.
"accounting_system";
105$tablib[31] =
"Pcg_version";
109$tabsql[31] =
"SELECT s.rowid as rowid, pcg_version, s.label, s.fk_country as country_id, c.code as country_code, c.label as country, s.active FROM ".MAIN_DB_PREFIX.
"accounting_system as s, ".MAIN_DB_PREFIX.
"c_country as c WHERE s.fk_country=c.rowid and c.active=1";
112$tabsqlsort = array();
113$tabsqlsort[31] =
"pcg_version ASC";
117$tabfield[31] =
"pcg_version,label,country_id,country";
120$tabfieldvalue = array();
121$tabfieldvalue[31] =
"pcg_version,label,country";
124$tabfieldinsert = array();
125$tabfieldinsert[31] =
"pcg_version,label,fk_country";
135$tabhelp[31] = array(
'pcg_version' => $langs->trans(
"EnterAnyCode"));
143if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha')) {
144 $search_country_id =
'';
148if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
149 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
150 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
151 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
152 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
156 foreach ($listfield as $f => $value) {
157 if ($value ==
'country_id' && in_array($tablib[$id], array(
'Pcg_version'))) {
160 if ((!GETPOSTISSET($value)) ||
GETPOST($value) ==
'') {
162 $fieldnamekey = $listfield[$f];
165 if ($fieldnamekey ==
'pcg_version') {
166 $fieldnamekey =
'Pcg_version';
168 if ($fieldnamekey ==
'label') {
169 $fieldnamekey =
'Label';
171 if ($fieldnamekey ==
'country') {
172 $fieldnamekey =
"Country";
175 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
179 if (GETPOSTISSET(
"pcg_version")) {
180 if (
GETPOST(
"pcg_version") ==
'0') {
182 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'),
null,
'errors');
185 if (GETPOSTISSET(
"country") &&
GETPOST(
"country") ==
'0') {
187 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities(
"Country")),
null,
'errors');
191 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
193 if ($tabrowid[$id]) {
195 $sql =
"SELECT MAX(".$db->sanitize($tabrowid[$id]).
") as newid FROM ".$db->sanitize($tabname[$id]);
196 $result = $db->query($sql);
198 $obj = $db->fetch_object($result);
199 $newid = ($obj->newid + 1);
206 $sql =
"INSERT INTO ".$db->sanitize($tabname[$id]).
" (";
208 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
209 $sql .= $db->sanitize($tabrowid[$id]).
",";
211 $sql .= $db->sanitize($tabfieldinsert[$id]);
216 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
220 foreach ($listfieldinsert as $f => $value) {
221 if ($value ==
'price' || preg_match(
'/^amount/i', $value) || $value ==
'taux') {
222 $_POST[$listfieldvalue[$i]] =
price2num(
GETPOST($listfieldvalue[$i]),
'MU');
223 } elseif ($value ==
'entity') {
224 $_POST[$listfieldvalue[$i]] = $conf->entity;
229 if (
GETPOST($listfieldvalue[$i]) ==
'') {
232 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
239 $result = $db->query($sql);
242 $_POST = array(
'id' => $id);
244 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
245 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
253 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
254 if ($tabrowid[$id]) {
255 $rowidcol = $tabrowid[
$id];
261 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET ";
263 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
264 $sql .= $db->sanitize($tabrowid[$id]).
" = ";
265 $sql .=
"'".$db->escape($rowid).
"', ";
268 foreach ($listfieldmodify as $field) {
269 if ($field ==
'price' || preg_match(
'/^amount/i', $field) || $field ==
'taux') {
270 $_POST[$listfieldvalue[$i]] =
price2num(
GETPOST($listfieldvalue[$i]),
'MU');
271 } elseif ($field ==
'entity') {
272 $_POST[$listfieldvalue[$i]] = $conf->entity;
278 if (
GETPOST($listfieldvalue[$i]) ==
'') {
281 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
285 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
289 $resql = $db->query($sql);
296if ($action ==
'confirm_delete' && $confirm ==
'yes') {
297 if ($tabrowid[$id]) {
298 $rowidcol = $tabrowid[
$id];
303 $sql =
"DELETE from ".$db->sanitize($tabname[$id]).
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
306 $result = $db->query($sql);
308 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
309 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
317if ($action ==
'activate') {
318 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE rowid = ".((int) $rowid);
319 $result = $db->query($sql);
326if ($action == $acts[1]) {
327 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE rowid = ".((int) $rowid);
328 $result = $db->query($sql);
339$form =
new Form($db);
342$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
344llxHeader(
'', $langs->trans(
"Pcg_version"), $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-admin_accountmodel');
346$titre = $langs->trans($tablib[$id]);
353if ($action ==
'delete') {
354 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.urlencode((
string) ($page)).
'&' :
'').
'sortfield='.urlencode((string) ($sortfield)).
'&sortorder='.urlencode((string) ($sortorder)).
'&rowid='.urlencode((string) ($rowid)).
'&code='.urlencode((string) ($code)).
'&id='.urlencode((string) (
$id)), $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_delete',
'', 0, 1);
361if ($search_country_id > 0) {
362 if (preg_match(
'/ WHERE /', $sql)) {
367 $sql .=
" c.rowid = ".((int) $search_country_id);
371if ($sortfield ==
'country') {
372 $sortfield =
'country_code';
374$sql .= $db->order($sortfield, $sortorder);
375$sql .= $db->plimit($listlimit + 1, $offset);
378$fieldlist = explode(
',', $tabfield[$id]);
380print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'" method="POST">';
381print
'<input type="hidden" name="token" value="'.newToken().
'">';
383print
'<div class="div-table-responsive">';
384print
'<table class="noborder centpercent">';
388$fieldlist = explode(
',', $tabfield[$id]);
391print
'<tr class="liste_titre">';
392foreach ($fieldlist as $field => $value) {
395 $valuetoshow = ucfirst($fieldlist[$field]);
396 $valuetoshow = $langs->trans($valuetoshow);
398 if ($fieldlist[$field] ==
'code') {
399 $valuetoshow = $langs->trans(
"Code");
401 if ($fieldlist[$field] ==
'label') {
402 $valuetoshow = $langs->trans(
"Label");
403 $class =
'minwidth300';
405 if ($fieldlist[$field] ==
'country') {
406 if (in_array(
'region_id', $fieldlist)) {
407 print
'<td> </td>';
410 $valuetoshow = $langs->trans(
"Country");
412 if ($fieldlist[$field] ==
'country_id') {
415 if ($fieldlist[$field] ==
'pcg_version' || $fieldlist[$field] ==
'fk_pcg_version') {
416 $valuetoshow = $langs->trans(
"Pcg_version");
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]);
434print
'<input type="hidden" name="id" value="'.$id.
'">';
441print
'<tr class="oddeven">';
445if (
GETPOST(
'actionadd',
'alpha')) {
446 foreach ($fieldlist as $key => $val) {
453$tmpaction =
'create';
454$parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
455$reshook = $hookmanager->executeHooks(
'createDictionaryFieldlist', $parameters, $obj, $tmpaction);
456$error = $hookmanager->error;
457$errors = $hookmanager->errors;
459if (empty($reshook)) {
463print
'<td colspan="3" class="right">';
464print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
468$colspan = count($fieldlist) + 3;
470print
'<tr><td colspan="'.$colspan.
'"> </td></tr>';
476$resql = $db->query($sql);
478 $num = $db->num_rows($resql);
481 $param =
'&id='.urlencode((
string) ($id));
482 if ($search_country_id > 0) {
483 $param .=
'&search_country_id='.urlencode((
string) ($search_country_id));
485 $paramwithsearch = $param;
487 $paramwithsearch .=
'&sortorder='.urlencode($sortorder);
490 $paramwithsearch .=
'&sortfield='.urlencode($sortfield);
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 ? 1 : 0),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
501 print
'<tr class="liste_titre liste_titre_add">';
502 foreach ($fieldlist as $field => $value) {
505 if ($fieldlist[$field] ==
'region_id' || $fieldlist[$field] ==
'country_id') {
510 if ($value ==
'country') {
511 print
'<td class="liste_titre">';
512 print $form->select_country($search_country_id,
'search_country_id',
'', 28,
'maxwidth200 maxwidthonsmartphone');
515 print
'<td class="liste_titre"></td>';
519 print
'<td class="liste_titre"></td>';
520 print
'<td class="liste_titre right" colspan="2">';
521 $searchpicto = $form->showFilterAndCheckAddButtons(0);
527 print
'<tr class="liste_titre">';
528 print
getTitleFieldOfList($langs->trans(
"Pcg_version"), 0, $_SERVER[
"PHP_SELF"],
"pcg_version", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'');
529 print
getTitleFieldOfList($langs->trans(
"Label"), 0, $_SERVER[
"PHP_SELF"],
"label", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'');
530 print
getTitleFieldOfList($langs->trans(
"Country"), 0, $_SERVER[
"PHP_SELF"],
"country_code", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'');
531 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
540 $obj = $db->fetch_object($resql);
543 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
544 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
545 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$id.
'" method="POST">';
546 print
'<input type="hidden" name="token" value="'.newToken().
'">';
547 print
'<input type="hidden" name="page" value="'.$page.
'">';
548 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
551 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
552 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
553 $error = $hookmanager->error;
554 $errors = $hookmanager->errors;
556 if (empty($reshook)) {
560 print
'<td colspan="3" class="right">';
561 print
'<a name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"> </a><input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
562 print
' <input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
566 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
567 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
569 $error = $hookmanager->error;
570 $errors = $hookmanager->errors;
572 if (empty($reshook)) {
573 foreach ($fieldlist as $field => $value) {
576 $tmpvar = $fieldlist[$field];
577 $valuetoshow = $obj->$tmpvar;
578 if ($valuetoshow ==
'all') {
579 $valuetoshow = $langs->trans(
'All');
580 } elseif ($fieldlist[$field] ==
'country') {
581 if (empty($obj->country_code)) {
584 $key = $langs->trans(
"Country".strtoupper($obj->country_code));
585 $valuetoshow = ($key !=
"Country".strtoupper($obj->country_code) ? $obj->country_code.
" - ".$key : $obj->country);
587 } elseif ($fieldlist[$field] ==
'country_id') {
592 if ($fieldlist[$field] ==
'tracking') {
593 $class .=
' tdoverflowauto';
597 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.$valuetoshow.
'</td>';
607 $url = $_SERVER[
"PHP_SELF"].
'?token='.
newToken().($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) :
'');
608 $url .=
'&'.$param.
'&';
611 print
'<td class="center nowrap">';
612 if ($canbedisabled) {
613 print
'<a href="'.$url.
'action='.$acts[$obj->active].
'">'.$actl[$obj->active].
'</a>';
615 print $langs->trans(
"AlwaysActive");
620 if ($canbemodified) {
621 print
'<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
623 print
'<td> </td>';
628 print
'<td class="center"><a href="'.$url.
'action=delete&token='.
newToken().
'">'.
img_delete().
'</a></td>';
630 print
'<td> </td>';
639 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
675 foreach ($fieldlist as $field => $value) {
676 if ($fieldlist[$field] ==
'country') {
677 if (in_array(
'region_id', $fieldlist)) {
684 $fieldname =
'country';
685 print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country :
'')), $fieldname,
'', 28,
'maxwidth200 maxwidthonsmartphone');
687 } elseif ($fieldlist[$field] ==
'country_id') {
688 if (!in_array(
'country', $fieldlist)) {
689 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
691 print
'<input type="hidden" name="'.$fieldlist[$field].
'" value="'.$country_id.
'">';
694 } elseif ($fieldlist[$field] ==
'type_cdr') {
695 if ($fieldlist[$field] ==
'type_cdr') {
696 print
'<td class="center">';
700 if ($fieldlist[$field] ==
'type_cdr') {
701 print $form->selectarray($fieldlist[$field], array(0 => $langs->trans(
'None'), 1 => $langs->trans(
'AtEndOfMonth'), 2 => $langs->trans(
'CurrentNext')), (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
''));
703 print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
''), 1);
706 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
707 print
'<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
'').
'" size="10" name="'.$fieldlist[$field].
'"></td>';
711 if ($fieldlist[$field] ==
'pcg_version') {
714 if ($fieldlist[$field] ==
'label') {
717 print
'<input type="text" class="flat'.($class ?
' '.$class :
'').
'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
'').
'" name="'.$fieldlist[$field].
'">';
fieldListAccountModel($fieldlist, $obj=null, $tabname='', $context='')
Show fields in insert/edit mode.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
$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.