26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formadmin.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancycategory.class.php';
37 $langs->loadLangs(array(
"errors",
"admin",
"companies",
"resource",
"holiday",
"accountancy",
"hrm"));
39 $action =
GETPOST(
'action',
'aZ09') ?
GETPOST(
'action',
'aZ09') :
'view';
40 $confirm =
GETPOST(
'confirm',
'alpha');
42 $rowid =
GETPOST(
'rowid',
'alpha');
43 $code =
GETPOST(
'code',
'alpha');
46 if (!$user->hasRight(
'accounting',
'chartofaccount')) {
50 $acts[0] =
"activate";
52 $actl[0] =
img_picto($langs->trans(
"Disabled"),
'switch_off',
'class="size15x"');
53 $actl[1] =
img_picto($langs->trans(
"Activated"),
'switch_on',
'class="size15x"');
55 $listoffset =
GETPOST(
'listoffset',
'alpha');
56 $listlimit =
GETPOST(
'listlimit',
'int') > 0 ?
GETPOST(
'listlimit',
'int') : 1000;
58 $sortfield =
GETPOST(
"sortfield",
'aZ09comma');
59 $sortorder =
GETPOST(
"sortorder",
'aZ09comma');
61 if (empty($page) || $page == -1) {
64 $offset = $listlimit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
68 $search_country_id =
GETPOST(
'search_country_id',
'int');
71 $hookmanager->initHooks(array(
'admin'));
77 $taborder = array(32);
81 $tabname[32] = MAIN_DB_PREFIX.
"c_accounting_category";
85 $tablib[32] =
"DictionaryAccountancyCategory";
89 $tabsql[32] =
"SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.category_type, a.formula, a.position as position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX.
"c_accounting_category as a, ".MAIN_DB_PREFIX.
"c_country as c WHERE a.fk_country=c.rowid and c.active=1";
92 $tabsqlsort = array();
93 $tabsqlsort[32] =
"position ASC";
97 $tabfield[32] =
"code,label,range_account,category_type,formula,position,country";
100 $tabfieldvalue = array();
101 $tabfieldvalue[32] =
"code,label,range_account,category_type,formula,position,country_id";
104 $tabfieldinsert = array();
105 $tabfieldinsert[32] =
"code,label,range_account,category_type,formula,position,fk_country";
119 $tabhelp[32] = array(
'code'=>$langs->trans(
"EnterAnyCode"),
'category_type'=>$langs->trans(
"SetToYesIfGroupIsComputationOfOtherGroups"),
'formula'=>$langs->trans(
"EnterCalculationRuleIfPreviousFieldIsYes"));
122 $tabfieldcheck = array();
123 $tabfieldcheck[32] = array();
126 complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabfieldcheck);
135 if (
GETPOST(
'button_removefilter',
'alpha') ||
GETPOST(
'button_removefilter.x',
'alpha') ||
GETPOST(
'button_removefilter_x',
'alpha')) {
136 $search_country_id =
'';
140 if (
GETPOST(
'actionadd',
'alpha') ||
GETPOST(
'actionmodify',
'alpha')) {
141 $listfield = explode(
',', str_replace(
' ',
'', $tabfield[$id]));
142 $listfieldinsert = explode(
',', $tabfieldinsert[$id]);
143 $listfieldmodify = explode(
',', $tabfieldinsert[$id]);
144 $listfieldvalue = explode(
',', $tabfieldvalue[$id]);
148 foreach ($listfield as $f => $value) {
149 if ($value ==
'formula' && !
GETPOST(
'formula')) {
152 if ($value ==
'range_account' && !
GETPOST(
'range_account')) {
155 if (($value ==
'country' || $value ==
'country_id') &&
GETPOST(
'country_id')) {
160 $fieldnamekey = $listfield[$f];
162 if ($fieldnamekey ==
'libelle' || ($fieldnamekey ==
'label')) {
163 $fieldnamekey =
'Label';
165 if ($fieldnamekey ==
'code') {
166 $fieldnamekey =
'Code';
168 if ($fieldnamekey ==
'note') {
169 $fieldnamekey =
'Note';
171 if ($fieldnamekey ==
'type') {
172 $fieldnamekey =
'Type';
174 if ($fieldnamekey ==
'position') {
175 $fieldnamekey =
'Position';
177 if ($fieldnamekey ==
'category_type') {
178 $fieldnamekey =
'Calculated';
180 if ($fieldnamekey ==
'country') {
181 $fieldnamekey =
'Country';
184 setEventMessages($langs->transnoentities(
"ErrorFieldRequired", $langs->transnoentities($fieldnamekey)),
null,
'errors');
190 setEventMessages($langs->transnoentities(
'ErrorCodeCantContainZero'),
null,
'errors');
193 if (
GETPOST(
'position') && !is_numeric(
GETPOST(
'position',
'alpha'))) {
194 $langs->loadLangs(array(
"errors"));
196 setEventMessages($langs->transnoentities(
'ErrorFieldMustBeANumeric', $langs->transnoentities(
"Position")),
null,
'errors');
200 if ($ok &&
GETPOST(
'actionadd',
'alpha')) {
201 if ($tabrowid[$id]) {
204 $sql =
"SELECT max(".$tabrowid[$id].
") newid from ".$tabname[$id];
205 $result = $db->query($sql);
207 $obj = $db->fetch_object($result);
208 $newid = ($obj->newid + 1);
215 $sql =
"INSERT INTO ".$tabname[$id].
" (";
217 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
218 $sql .= $tabrowid[$id].
",";
220 $sql .= $tabfieldinsert[$id];
225 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
229 foreach ($listfieldinsert as $f => $value) {
230 if ($value ==
'entity') {
231 $_POST[$listfieldvalue[$i]] = $conf->entity;
236 if (
GETPOST($listfieldvalue[$i]) ==
'' && !$listfieldvalue[$i] ==
'formula') {
239 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
246 $result = $db->query($sql);
249 $_POST = array(
'id'=>$id);
251 if ($db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
252 setEventMessages($langs->transnoentities(
"ErrorRecordAlreadyExists"),
null,
'errors');
260 if ($ok &&
GETPOST(
'actionmodify',
'alpha')) {
261 if ($tabrowid[$id]) {
262 $rowidcol = $tabrowid[$id];
268 $sql =
"UPDATE ".$tabname[$id].
" SET ";
270 if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
271 $sql .= $tabrowid[$id].
"=";
272 $sql .=
"'".$db->escape($rowid).
"', ";
275 foreach ($listfieldmodify as $field) {
276 if ($field ==
'fk_country' &&
GETPOST(
'country') > 0) {
277 $_POST[$listfieldvalue[$i]] =
GETPOST(
'country');
278 } elseif ($field ==
'entity') {
279 $_POST[$listfieldvalue[$i]] = $conf->entity;
285 if (
GETPOST($listfieldvalue[$i]) ==
'' && !$listfieldvalue[$i] ==
'range_account') {
288 $sql .=
"'".$db->escape(
GETPOST($listfieldvalue[$i])).
"'";
292 $sql .=
" WHERE ".$rowidcol.
" = ".((int) $rowid);
296 $resql = $db->query($sql);
304 if (
GETPOST(
'actioncancel',
'alpha')) {
308 if ($action ==
'confirm_delete' && $confirm ==
'yes') {
309 if ($tabrowid[$id]) {
310 $rowidcol = $tabrowid[$id];
315 $sql =
"DELETE from ".$tabname[$id].
" WHERE ".$rowidcol.
" = ".((int) $rowid);
318 $result = $db->query($sql);
320 if ($db->errno() ==
'DB_ERROR_CHILD_EXISTS') {
321 setEventMessages($langs->transnoentities(
"ErrorRecordIsUsedByChild"),
null,
'errors');
329 if ($action == $acts[0]) {
330 if ($tabrowid[$id]) {
331 $rowidcol = $tabrowid[$id];
337 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE ".$rowidcol.
" = ".((int) $rowid);
339 $sql =
"UPDATE ".$tabname[$id].
" SET active = 1 WHERE code = '".$db->escape($code).
"'";
342 $result = $db->query($sql);
349 if ($action == $acts[1]) {
350 if ($tabrowid[$id]) {
351 $rowidcol = $tabrowid[$id];
357 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE ".$rowidcol.
" = ".((int) $rowid);
359 $sql =
"UPDATE ".$tabname[$id].
" SET active = 0 WHERE code = '".$db->escape($code).
"'";
362 $result = $db->query($sql);
369 if ($action ==
'activate_favorite') {
370 if ($tabrowid[$id]) {
371 $rowidcol = $tabrowid[$id];
377 $sql =
"UPDATE ".$tabname[$id].
" SET favorite = 1 WHERE ".$rowidcol.
" = ".((int) $rowid);
379 $sql =
"UPDATE ".$tabname[$id].
" SET favorite = 1 WHERE code = '".$db->escape($code).
"'";
382 $result = $db->query($sql);
389 if ($action ==
'disable_favorite') {
390 if ($tabrowid[$id]) {
391 $rowidcol = $tabrowid[$id];
397 $sql =
"UPDATE ".$tabname[$id].
" SET favorite = 0 WHERE ".$rowidcol.
" = ".((int) $rowid);
399 $sql =
"UPDATE ".$tabname[$id].
" SET favorite = 0 WHERE code = '".$db->escape($code).
"'";
402 $result = $db->query($sql);
416 llxHeader(
'', $langs->trans(
'DictionaryAccountancyCategory'));
418 $titre = $langs->trans($tablib[$id]);
420 $titlepicto =
'setup';
424 print
'<span class="opacitymedium">'.$langs->trans(
"AccountingAccountGroupsDesc", $langs->transnoentitiesnoconv(
"ByPersonalizedAccountGroups")).
'</span><br><br>';
427 if ($action ==
'delete') {
428 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?'.($page ?
'page='.$page.
'&' :
'').
'sortfield='.$sortfield.
'&sortorder='.$sortorder.
'&rowid='.$rowid.
'&code='.$code.
'&id='.$id.($search_country_id > 0 ?
'&search_country_id='.$search_country_id :
''), $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_delete',
'', 0, 1);
434 if ($search_country_id > 0) {
435 if (preg_match(
'/ WHERE /', $sql)) {
440 $sql .=
" (a.fk_country = ".((int) $search_country_id).
" OR a.fk_country = 0)";
444 if ($sortfield ==
'country') {
445 $sortfield =
'country_code';
447 $sql .= $db->order($sortfield, $sortorder);
448 $sql .= $db->plimit($listlimit + 1, $offset);
451 $fieldlist = explode(
',', $tabfield[$id]);
453 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$id.
'" method="POST">';
454 print
'<input type="hidden" name="token" value="'.newToken().
'">';
455 print
'<input type="hidden" name="from" value="'.dol_escape_htmltag(
GETPOST(
'from',
'alpha')).
'">';
457 print
'<div class="div-table-responsive">';
458 print
'<table class="noborder centpercent">';
462 $fieldlist = explode(
',', $tabfield[$id]);
465 print
'<tr class="liste_titre">';
466 foreach ($fieldlist as $field => $value) {
469 $valuetoshow = ucfirst($fieldlist[$field]);
470 $valuetoshow = $langs->trans($valuetoshow);
472 if ($fieldlist[$field] ==
'type') {
473 if ($tabname[$id] == MAIN_DB_PREFIX.
"c_paiement") {
474 $valuetoshow =
$form->textwithtooltip($langs->trans(
"Type"), $langs->trans(
"TypePaymentDesc"), 2, 1,
img_help(1,
''));
476 $valuetoshow = $langs->trans(
"Type");
479 if ($fieldlist[$field] ==
'code') {
480 $valuetoshow = $langs->trans(
"Code");
482 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
483 $valuetoshow = $langs->trans(
"Label");
485 if ($fieldlist[$field] ==
'libelle_facture') {
486 $valuetoshow = $langs->trans(
"LabelOnDocuments");
488 if ($fieldlist[$field] ==
'country') {
489 $valuetoshow = $langs->trans(
"Country");
491 if ($fieldlist[$field] ==
'accountancy_code') {
492 $valuetoshow = $langs->trans(
"AccountancyCode");
494 if ($fieldlist[$field] ==
'accountancy_code_sell') {
495 $valuetoshow = $langs->trans(
"AccountancyCodeSell");
497 if ($fieldlist[$field] ==
'accountancy_code_buy') {
498 $valuetoshow = $langs->trans(
"AccountancyCodeBuy");
500 if ($fieldlist[$field] ==
'pcg_version' || $fieldlist[$field] ==
'fk_pcg_version') {
501 $valuetoshow = $langs->trans(
"Pcg_version");
503 if ($fieldlist[$field] ==
'range_account') {
504 $valuetoshow = $langs->trans(
"Comment");
506 if ($fieldlist[$field] ==
'category_type') {
507 $valuetoshow = $langs->trans(
"Calculated");
510 if ($valuetoshow !=
'') {
511 print
'<td class="'.$class.
'">';
512 if (!empty($tabhelp[$id][$value]) && preg_match(
'/^http(s*):/i', $tabhelp[$id][$value])) {
513 print
'<a href="'.$tabhelp[$id][$value].
'">'.$valuetoshow.
' '.
img_help(1, $valuetoshow).
'</a>';
514 } elseif (!empty($tabhelp[$id][$value])) {
515 print
$form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
524 print
'<input type="hidden" name="id" value="'.$id.
'">';
526 print
'<td style="min-width: 26px;"></td>';
527 print
'<td style="min-width: 26px;"></td>';
528 print
'<td style="min-width: 26px;"></td>';
532 print
'<tr class="oddeven nodrag nodrop nohover">';
534 $obj =
new stdClass();
536 if (
GETPOST(
'actionadd',
'alpha')) {
537 foreach ($fieldlist as $key => $val) {
544 $tmpaction =
'create';
545 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
546 $reshook = $hookmanager->executeHooks(
'createDictionaryFieldlist', $parameters, $obj, $tmpaction);
547 $error = $hookmanager->error; $errors = $hookmanager->errors;
549 if (empty($reshook)) {
553 print
'<td colspan="4" class="right">';
554 print
'<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans(
"Add").
'">';
558 $colspan = count($fieldlist) + 3;
563 print
'<tr><td colspan="'.$colspan.
'"> </td></tr>';
567 dol_syslog(
"htdocs/accountancy/admin/categories_list.php", LOG_DEBUG);
569 $resql = $db->query($sql);
571 $num = $db->num_rows(
$resql);
575 if ($search_country_id > 0) {
576 $param .=
'&search_country_id='.urlencode($search_country_id);
578 $paramwithsearch = $param;
580 $paramwithsearch .=
'&sortorder='.$sortorder;
583 $paramwithsearch .=
'&sortfield='.$sortfield;
585 if (
GETPOST(
'from',
'alpha')) {
586 $paramwithsearch .=
'&from='.GETPOST(
'from',
'alpha');
589 if ($num > $listlimit) {
590 print
'<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).
'">';
591 print_fleche_navigation($page, $_SERVER[
"PHP_SELF"], $paramwithsearch, ($num > $listlimit),
'<li class="pagination"><span>'.$langs->trans(
"Page").
' '.($page + 1).
'</span></li>');
596 print
'<tr class="liste_titre liste_titre_add liste_titre_filter">';
598 foreach ($fieldlist as $field => $value) {
601 if ($fieldlist[$field] ==
'region_id' || $fieldlist[$field] ==
'country_id') {
606 if ($value ==
'country') {
607 print
'<td class="liste_titre">';
608 print
$form->select_country($search_country_id,
'search_country_id',
'', 28,
'maxwidth150 maxwidthonsmartphone');
612 print
'<td class="liste_titre"></td>';
616 print
'<td class="liste_titre"></td>';
617 print
'<td class="liste_titre"></td>';
618 print
'<td class="liste_titre"></td>';
619 print
'<td class="liste_titre center">';
621 $searchpicto =
$form->showFilterAndCheckAddButtons(0);
628 print
'<tr class="liste_titre">';
629 foreach ($fieldlist as $field => $value) {
637 $valuetoshow = ucfirst($fieldlist[$field]);
638 $valuetoshow = $langs->trans($valuetoshow);
639 if ($fieldlist[$field] ==
'source') {
640 $valuetoshow = $langs->trans(
"Contact");
642 if ($fieldlist[$field] ==
'price') {
643 $valuetoshow = $langs->trans(
"PriceUHT");
645 if ($fieldlist[$field] ==
'taux') {
646 if ($tabname[$id] != MAIN_DB_PREFIX.
"c_revenuestamp") {
647 $valuetoshow = $langs->trans(
"Rate");
649 $valuetoshow = $langs->trans(
"Amount");
653 if ($fieldlist[$field] ==
'type') {
654 $valuetoshow = $langs->trans(
"Type");
656 if ($fieldlist[$field] ==
'code') {
657 $valuetoshow = $langs->trans(
"Code");
659 if ($fieldlist[$field] ==
'libelle' || $fieldlist[$field] ==
'label') {
660 $valuetoshow = $langs->trans(
"Label");
662 if ($fieldlist[$field] ==
'country') {
663 $valuetoshow = $langs->trans(
"Country");
665 if ($fieldlist[$field] ==
'region_id' || $fieldlist[$field] ==
'country_id') {
668 if ($fieldlist[$field] ==
'accountancy_code') {
669 $valuetoshow = $langs->trans(
"AccountancyCode");
671 if ($fieldlist[$field] ==
'accountancy_code_sell') {
672 $valuetoshow = $langs->trans(
"AccountancyCodeSell");
675 if ($fieldlist[$field] ==
'accountancy_code_buy') {
676 $valuetoshow = $langs->trans(
"AccountancyCodeBuy");
679 if ($fieldlist[$field] ==
'fk_pcg_version') {
680 $valuetoshow = $langs->trans(
"Pcg_version");
682 if ($fieldlist[$field] ==
'account_parent') {
683 $valuetoshow = $langs->trans(
"Accountsparent");
685 if ($fieldlist[$field] ==
'pcg_type') {
686 $valuetoshow = $langs->trans(
"Pcg_type");
688 if ($fieldlist[$field] ==
'type_template') {
689 $valuetoshow = $langs->trans(
"TypeOfTemplate");
691 if ($fieldlist[$field] ==
'range_account') {
692 $valuetoshow = $langs->trans(
"Comment");
694 if ($fieldlist[$field] ==
'category_type') {
695 $valuetoshow = $langs->trans(
"Calculated");
699 print
getTitleFieldOfList($valuetoshow, 0, $_SERVER[
"PHP_SELF"], ($sortable ? $fieldlist[$field] :
''), ($page ?
'page='.$page.
'&' :
''), $param,
"", $sortfield, $sortorder, $class.
' ');
702 print
getTitleFieldOfList($langs->trans(
"Status"), 0, $_SERVER[
"PHP_SELF"],
"active", ($page ?
'page='.$page.
'&' :
''), $param,
'', $sortfield, $sortorder,
'center ');
711 $obj = $db->fetch_object(
$resql);
713 print
'<tr class="oddeven" id="rowid-'.$obj->rowid.
'">';
714 if ($action ==
'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
716 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
717 $reshook = $hookmanager->executeHooks(
'editDictionaryFieldlist', $parameters, $obj, $tmpaction);
718 $error = $hookmanager->error; $errors = $hookmanager->errors;
721 if (empty($reshook)) {
727 print
'<td class="center">';
728 print
'<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).
'"></div>';
729 print
'<input type="hidden" name="page" value="'.$page.
'">';
730 print
'<input type="hidden" name="rowid" value="'.$rowid.
'">';
731 print
'<input type="submit" class="button button-edit smallpaddingimp" name="actionmodify" value="'.$langs->trans(
"Modify").
'">';
732 print
'<input type="submit" class="button button-cancel smallpaddingimp" name="actioncancel" value="'.$langs->trans(
"Cancel").
'">';
737 $parameters = array(
'fieldlist'=>$fieldlist,
'tabname'=>$tabname[$id]);
738 $reshook = $hookmanager->executeHooks(
'viewDictionaryFieldlist', $parameters, $obj, $tmpaction);
740 $error = $hookmanager->error; $errors = $hookmanager->errors;
742 if (empty($reshook)) {
743 foreach ($fieldlist as $field => $value) {
746 $valuetoshow = $obj->{$fieldlist[$field]};
747 if ($value ==
'category_type') {
748 $valuetoshow =
yn($valuetoshow);
749 } elseif ($valuetoshow ==
'all') {
750 $valuetoshow = $langs->trans(
'All');
751 } elseif ($fieldlist[$field] ==
'country') {
752 if (empty($obj->country_code)) {
755 $key = $langs->trans(
"Country".strtoupper($obj->country_code));
756 $valuetoshow = ($key !=
"Country".strtoupper($obj->country_code) ? $obj->country_code.
" - ".$key : $obj->country);
758 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'c_country') {
759 $key = $langs->trans(
"Country".strtoupper($obj->code));
760 $valuetoshow = ($obj->code && $key !=
"Country".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
761 } elseif ($fieldlist[$field] ==
'label' && $tabname[$id] == MAIN_DB_PREFIX.
'c_availability') {
762 $langs->loadLangs(array(
"propal"));
763 $key = $langs->trans(
"AvailabilityType".strtoupper($obj->code));
764 $valuetoshow = ($obj->code && $key !=
"AvailabilityType".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
765 } elseif ($fieldlist[$field] ==
'libelle' && $tabname[$id] == MAIN_DB_PREFIX.
'c_actioncomm') {
766 $key = $langs->trans(
"Action".strtoupper($obj->code));
767 $valuetoshow = ($obj->code && $key !=
"Action".strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
768 } elseif ($fieldlist[$field] ==
'region_id' || $fieldlist[$field] ==
'country_id') {
775 print
'<!-- '.$fieldlist[$field].
' --><td class="'.$class.
'">'.
dol_escape_htmltag($valuetoshow).
'</td>';
781 $iserasable = 1; $canbedisabled = 1; $canbemodified = 1;
782 if (isset($obj->code)) {
783 if (($obj->code ==
'0' || $obj->code ==
'' || preg_match(
'/unknown/i', $obj->code))) {
784 $iserasable = 0; $canbedisabled = 0;
788 $canbemodified = $iserasable;
790 $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) :
'');
797 print
'<td class="center" class="nowrap">';
798 if ($canbedisabled) {
799 print
'<a href="'.$url.
'action='.$acts[$obj->active].
'">'.$actl[$obj->active].
'</a>';
801 print $langs->trans(
"AlwaysActive");
806 if ($canbemodified) {
807 print
'<td class="center"><a class="reposition editfielda" href="'.$url.
'action=edit&token='.
newToken().
'">'.
img_edit().
'</a></td>';
809 print
'<td> </td>';
814 print
'<td class="center">';
821 print
'<td> </td>';
825 print
'<td class="center">';
826 if (empty($obj->formula)) {
827 print
'<a href="'.DOL_URL_ROOT.
'/accountancy/admin/categories.php?action=display&save_lastsearch_values=1&account_category='.$obj->rowid.
'">';
828 print $langs->trans(
"ListOfAccounts");
832 $nbofaccountintogroup = 0;
833 $listofaccountintogroup = $accountingcategory->getCptsCat($obj->rowid);
834 $nbofaccountintogroup = count($listofaccountintogroup);
836 print
' <span class="opacitymedium">('.$langs->trans(
"NAccounts", $nbofaccountintogroup).
')</span>';
874 global $conf, $langs, $db;
875 global
$form, $mysoc;
883 foreach ($fieldlist as $field => $value) {
884 if ($fieldlist[$field] ==
'country') {
886 $fieldname =
'country';
887 if ($context ==
'add') {
888 $fieldname =
'country_id';
889 $preselectcountrycode =
GETPOSTISSET(
'country_id') ?
GETPOST(
'country_id',
'int') : $mysoc->country_code;
890 print
$form->select_country($preselectcountrycode, $fieldname,
'', 28,
'maxwidth150 maxwidthonsmartphone');
892 $preselectcountrycode = (empty($obj->country_code) ? (empty($obj->country) ? $mysoc->country_code : $obj->country) : $obj->country_code);
893 print
$form->select_country($preselectcountrycode, $fieldname,
'', 28,
'maxwidth150 maxwidthonsmartphone');
896 } elseif ($fieldlist[$field] ==
'country_id') {
897 if (!in_array(
'country', $fieldlist)) {
898 $country_id = (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
900 print
'<input type="hidden" name="'.$fieldlist[$field].
'" value="'.$country_id.
'">';
903 } elseif ($fieldlist[$field] ==
'category_type') {
905 print
$form->selectyesno($fieldlist[$field], (!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
''), 1);
907 } elseif ($fieldlist[$field] ==
'code' && isset($obj->{$fieldlist[$field]})) {
908 print
'<td><input type="text" class="flat minwidth100" value="'.(!empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
'').
'" name="'.$fieldlist[$field].
'"></td>';
911 $size =
''; $class =
'';
912 if ($fieldlist[$field] ==
'code') {
913 $class =
'maxwidth100';
915 if ($fieldlist[$field] ==
'position') {
916 $class =
'maxwidth50';
918 if ($fieldlist[$field] ==
'libelle') {
919 $class =
'quatrevingtpercent';
921 if ($fieldlist[$field] ==
'sortorder' || $fieldlist[$field] ==
'category_type') {
924 print
'<input type="text" '.$size.
'class="flat'.($class ?
' '.$class :
'').
'" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]}:
'').
'" name="'.$fieldlist[$field].
'">';