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 == -1) {
75$offset = $listlimit * $page;
79$search_country_id =
GETPOST(
'search_country_id',
'int');
83if ($user->socid > 0) {
86if (!$user->hasRight(
'accounting',
'chartofaccount')) {
92$hookmanager->initHooks(array(
'admin'));
100$tabname[31] = MAIN_DB_PREFIX.
"accounting_system";
104$tablib[31] =
"Pcg_version";
108$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";
111$tabsqlsort = array();
112$tabsqlsort[31] =
"pcg_version ASC";
116$tabfield[31] =
"pcg_version,label,country_id,country";
119$tabfieldvalue = array();
120$tabfieldvalue[31] =
"pcg_version,label,country";
123$tabfieldinsert = array();
124$tabfieldinsert[31] =
"pcg_version,label,fk_country";
134$tabhelp[31] = array(
'pcg_version' => $langs->trans(
"EnterAnyCode"));
142if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha')) {
143 $search_country_id =
'';
147if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
148 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
149 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
150 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
151 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
155 foreach ($listfield as $f => $value) {
156 if ($value ==
'country_id' && in_array($tablib[$id], array(
'Pcg_version'))) {
159 if ((!GETPOSTISSET($value)) ||
GETPOST($value) ==
'') {
161 $fieldnamekey = $listfield[$f];
164 if ($fieldnamekey ==
'pcg_version') {
165 $fieldnamekey =
'Pcg_version';
167 if ($fieldnamekey ==
'label') {
168 $fieldnamekey =
'Label';
170 if ($fieldnamekey ==
'country') {
171 $fieldnamekey =
"Country";
174 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
178 if (GETPOSTISSET(
"pcg_version")) {
179 if (
GETPOST(
"pcg_version") ==
'0') {
181 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'),
null,
'errors');
184 if (GETPOSTISSET(
"country") &&
GETPOST(
"country") ==
'0') {
186 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities(
"Country")),
null,
'errors');
190 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
192 if ($tabrowid[$id]) {
194 $sql =
"SELECT MAX(".$db->sanitize($tabrowid[$id]).
") as 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 .= $db->sanitize($tabrowid[$id]).
",";
210 $sql .= $db->sanitize($tabfieldinsert[$id]);
215 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
219 foreach ($listfieldinsert as $f => $value) {
220 if ($value ==
'price' || preg_match(
'/^amount/i', $value) || $value ==
'taux') {
221 $_POST[$listfieldvalue[$i]] =
price2num(
GETPOST($listfieldvalue[$i]),
'MU');
222 } elseif ($value ==
'entity') {
223 $_POST[$listfieldvalue[$i]] = $conf->entity;
228 if (
GETPOST($listfieldvalue[$i]) ==
'') {
231 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
238 $result = $db->query($sql);
241 $_POST = array(
'id' => $id);
243 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
244 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
252 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
253 if ($tabrowid[$id]) {
254 $rowidcol = $tabrowid[$id];
260 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET ";
262 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
263 $sql .= $db->sanitize($tabrowid[$id]).
" = ";
264 $sql .=
"'".$db->escape($rowid).
"', ";
267 foreach ($listfieldmodify as $field) {
268 if ($field ==
'price' || preg_match(
'/^amount/i', $field) || $field ==
'taux') {
269 $_POST[$listfieldvalue[$i]] =
price2num(
GETPOST($listfieldvalue[$i]),
'MU');
270 } elseif ($field ==
'entity') {
271 $_POST[$listfieldvalue[$i]] = $conf->entity;
277 if (
GETPOST($listfieldvalue[$i]) ==
'') {
280 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
284 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
288 $resql = $db->query($sql);
295if ($action ==
'confirm_delete' && $confirm ==
'yes') {
296 if ($tabrowid[$id]) {
297 $rowidcol = $tabrowid[$id];
302 $sql =
"DELETE from ".$db->sanitize($tabname[$id]).
" WHERE ".$db->sanitize($rowidcol).
" = ".((int) $rowid);
305 $result = $db->query($sql);
307 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
308 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
316if ($action ==
'activate') {
317 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 1 WHERE rowid = ".((int) $rowid);
318 $result = $db->query($sql);
325if ($action == $acts[1]) {
326 $sql =
"UPDATE ".$db->sanitize($tabname[$id]).
" SET active = 0 WHERE rowid = ".((int) $rowid);
327 $result = $db->query($sql);
338$form =
new Form($db);
341$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
343llxHeader(
'', $langs->trans(
"Pcg_version"), $help_url);
345$titre = $langs->trans($tablib[$id]);
352if ($action ==
'delete') {
353 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);
360if ($search_country_id > 0) {
361 if (preg_match(
'/ WHERE /', $sql)) {
366 $sql .=
" c.rowid = ".((int) $search_country_id);
370if ($sortfield ==
'country') {
371 $sortfield =
'country_code';
373$sql .= $db->order($sortfield, $sortorder);
374$sql .= $db->plimit($listlimit + 1, $offset);
377$fieldlist = explode(
',', $tabfield[$id]);
379print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
380print
'<input type="hidden" name="token" value="'.newToken().
'">';
382print
'<div class="div-table-responsive">';
383print
'<table class="noborder centpercent">';
387$fieldlist = explode(
',', $tabfield[$id]);
390print
'<tr class="liste_titre">';
391foreach ($fieldlist as $field => $value) {
394 $valuetoshow = ucfirst($fieldlist[$field]);
395 $valuetoshow = $langs->trans($valuetoshow);
397 if ($fieldlist[$field] ==
'code') {
398 $valuetoshow = $langs->trans(
"Code");
400 if ($fieldlist[$field] ==
'label') {
401 $valuetoshow = $langs->trans(
"Label");
402 $class =
'minwidth300';
404 if ($fieldlist[$field] ==
'country') {
405 if (in_array(
'region_id', $fieldlist)) {
406 print
'<td> </td>';
409 $valuetoshow = $langs->trans(
"Country");
411 if ($fieldlist[$field] ==
'country_id') {
414 if ($fieldlist[$field] ==
'pcg_version' || $fieldlist[$field] ==
'fk_pcg_version') {
415 $valuetoshow = $langs->trans(
"Pcg_version");
419 if ($valuetoshow !=
'') {
420 print
'<td class="'.$class.
'">';
421 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
422 print
'<a href="'.$tabhelp[$id][$value].
'">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
423 } elseif (!empty($tabhelp[$id][$value])) {
424 print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
433print
'<input type="hidden" name="id" value="'.$id.
'">';
440print
'<tr class="oddeven">';
444if (
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;
458if (empty($reshook)) {
462print
'<td colspan="3" class="right">';
463print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
467$colspan = count($fieldlist) + 3;
469print
'<tr><td colspan="'.$colspan.
'"> </td></tr>';
475$resql = $db->query($sql);
477 $num = $db->num_rows($resql);
480 $param =
'&id='.urlencode((
string) ($id));
481 if ($search_country_id > 0) {
482 $param .=
'&search_country_id='.urlencode((
string) ($search_country_id));
484 $paramwithsearch = $param;
486 $paramwithsearch .=
'&sortorder='.urlencode($sortorder);
489 $paramwithsearch .=
'&sortfield='.urlencode($sortfield);
493 if ($num > $listlimit) {
494 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
495 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
500 print
'<tr class="liste_titre liste_titre_add">';
501 foreach ($fieldlist as $field => $value) {
504 if ($fieldlist[$field] ==
'region_id' || $fieldlist[$field] ==
'country_id') {
509 if ($value ==
'country') {
510 print
'<td class="liste_titre">';
511 print $form->select_country($search_country_id,
'search_country_id',
'', 28,
'maxwidth200 maxwidthonsmartphone');
514 print
'<td class="liste_titre"></td>';
518 print
'<td class="liste_titre"></td>';
519 print
'<td class="liste_titre right" colspan="2">';
520 $searchpicto = $form->showFilterAndCheckAddButtons(0);
526 print
'<tr class="liste_titre">';
527 print
getTitleFieldOfList($langs->trans(
"Pcg_version"), 0, $_SERVER[
"PHP_SELF"],
"pcg_version", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'');
528 print
getTitleFieldOfList($langs->trans(
"Label"), 0, $_SERVER[
"PHP_SELF"],
"label", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'');
529 print
getTitleFieldOfList($langs->trans(
"Country"), 0, $_SERVER[
"PHP_SELF"],
"country_code", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'');
530 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
539 $obj = $db->fetch_object($resql);
542 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
543 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
544 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
545 print
'<input type="hidden" name="token" value="'.newToken().
'">';
546 print
'<input type="hidden" name="page" value="'.$page.
'">';
547 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
550 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
551 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
552 $error = $hookmanager->error;
553 $errors = $hookmanager->errors;
555 if (empty($reshook)) {
559 print
'<td colspan="3" class="right">';
560 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").
'">';
561 print
' <input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
565 $parameters = array(
'fieldlist' => $fieldlist,
'tabname' => $tabname[$id]);
566 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
568 $error = $hookmanager->error;
569 $errors = $hookmanager->errors;
571 if (empty($reshook)) {
572 foreach ($fieldlist as $field => $value) {
575 $tmpvar = $fieldlist[$field];
576 $valuetoshow = $obj->$tmpvar;
577 if ($valuetoshow ==
'all') {
578 $valuetoshow = $langs->trans(
'All');
579 } elseif ($fieldlist[$field] ==
'country') {
580 if (empty($obj->country_code)) {
583 $key = $langs->trans(
"Country".strtoupper($obj->country_code));
584 $valuetoshow = ($key !=
"Country".strtoupper($obj->country_code) ? $obj->country_code.
" - ".$key : $obj->country);
586 } elseif ($fieldlist[$field] ==
'country_id') {
591 if ($fieldlist[$field] ==
'tracking') {
592 $class .=
' tdoverflowauto';
596 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.$valuetoshow.
'</td>';
606 $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) :
'');
607 $url .=
'&'.$param.
'&';
610 print
'<td class="center nowrap">';
611 if ($canbedisabled) {
612 print
'<a href="'.$url.
'action='.$acts[$obj->active].
'">'.$actl[$obj->active].
'</a>';
614 print $langs->trans(
"AlwaysActive");
619 if ($canbemodified) {
620 print
'<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
622 print
'<td> </td>';
627 print
'<td class="center"><a href="'.$url.
'action=delete&token='.
newToken().
'">'.
img_delete().
'</a></td>';
629 print
'<td> </td>';
638 print
'<tr><td colspan="6"><span class="opacitymedium">'.$langs->trans(
"NoRecordFound").
'</span></td></tr>';
674 foreach ($fieldlist as $field => $value) {
675 if ($fieldlist[$field] ==
'country') {
676 if (in_array(
'region_id', $fieldlist)) {
683 $fieldname =
'country';
684 print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country :
'')), $fieldname,
'', 28,
'maxwidth200 maxwidthonsmartphone');
686 } elseif ($fieldlist[$field] ==
'country_id') {
687 if (!in_array(
'country', $fieldlist)) {
688 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
690 print
'<input type="hidden" name="'.$fieldlist[$field].
'" value="'.$country_id.
'">';
693 } elseif ($fieldlist[$field] ==
'type_cdr') {
694 if ($fieldlist[$field] ==
'type_cdr') {
695 print
'<td class="center">';
699 if ($fieldlist[$field] ==
'type_cdr') {
700 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]} :
''));
702 print $form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
''), 1);
705 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
706 print
'<td><input type="text" class="flat" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} :
'').
'" size="10" name="'.$fieldlist[$field].
'"></td>';
710 if ($fieldlist[$field] ==
'pcg_version') {
713 if ($fieldlist[$field] ==
'label') {
716 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()
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.
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.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.