27require
'../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
29require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancysystem.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
36$langs->loadLangs(array(
'accountancy',
'bills',
'compta'));
38$action =
GETPOST(
'action',
'aZ09');
39$backtopage =
GETPOST(
'backtopage',
'alpha');
42$rowid =
GETPOST(
'rowid',
'int');
43$cancel =
GETPOST(
'cancel',
'alpha');
45$account_number =
GETPOST(
'account_number',
'alphanohtml');
46$label =
GETPOST(
'label',
'alpha');
49if ($user->socid > 0) {
52if (!$user->hasRight(
'accounting',
'chartofaccount')) {
64if (
GETPOST(
'cancel',
'alpha')) {
65 $urltogo = $backtopage ? $backtopage : DOL_URL_ROOT.
'/accountancy/admin/account.php';
66 header(
"Location: ".$urltogo);
70if ($action ==
'add' && $user->hasRight(
'accounting',
'chartofaccount')) {
72 if (!$account_number) {
73 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountNumber")),
null,
'errors');
76 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label")),
null,
'errors');
79 $sql =
"SELECT pcg_version FROM " . MAIN_DB_PREFIX .
"accounting_system WHERE rowid = ".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS'));
81 dol_syslog(
'accountancy/admin/card.php:: $sql=' . $sql);
82 $result = $db->query($sql);
83 $obj = $db->fetch_object($result);
89 $account_number = $account_number;
94 if (
GETPOST(
'account_parent',
'int') <= 0) {
97 $account_parent =
GETPOST(
'account_parent',
'int');
100 $object->fk_pcg_version = $obj->pcg_version;
101 $object->pcg_type =
GETPOST(
'pcg_type',
'alpha');
102 $object->account_number = $account_number;
103 $object->account_parent = $account_parent;
104 $object->account_category =
GETPOST(
'account_category',
'alpha');
105 $object->label = $label;
106 $object->labelshort =
GETPOST(
'labelshort',
'alpha');
109 $res = $object->create($user);
114 } elseif ($res == -4) {
118 } elseif ($res < 0) {
125 $urltogo = $backtopage ? $backtopage : DOL_URL_ROOT.
'/accountancy/admin/account.php';
126 header(
"Location: " . $urltogo);
131} elseif ($action ==
'edit' && $user->hasRight(
'accounting',
'chartofaccount')) {
133 if (!$account_number) {
134 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountNumber")),
null,
'errors');
137 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label")),
null,
'errors');
140 $result = $object->fetch($id);
142 $sql =
"SELECT pcg_version FROM ".MAIN_DB_PREFIX.
"accounting_system WHERE rowid=".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS'));
144 dol_syslog(
'accountancy/admin/card.php:: $sql=' . $sql);
145 $result2 = $db->query($sql);
146 $obj = $db->fetch_object($result2);
152 $account_number = $account_number;
157 if (
GETPOST(
'account_parent',
'int') <= 0) {
160 $account_parent =
GETPOST(
'account_parent',
'int');
163 $object->fk_pcg_version = $obj->pcg_version;
164 $object->pcg_type =
GETPOST(
'pcg_type',
'alpha');
165 $object->account_number = $account_number;
166 $object->account_parent = $account_parent;
167 $object->account_category =
GETPOST(
'account_category',
'alpha');
168 $object->label = $label;
169 $object->labelshort =
GETPOST(
'labelshort',
'alpha');
171 $result = $object->update($user);
174 $urltogo = $backtopage ? $backtopage : ($_SERVER[
"PHP_SELF"] .
"?id=" . $id);
175 header(
"Location: " . $urltogo);
177 } elseif ($result == -2) {
178 setEventMessages($langs->trans(
"ErrorAccountNumberAlreadyExists", $object->account_number),
null,
'errors');
184 $urltogo = $backtopage ? $backtopage : ($_SERVER[
"PHP_SELF"].
"?id=".$id);
185 header(
"Location: ".$urltogo);
188} elseif ($action ==
'delete' && $user->hasRight(
'accounting',
'chartofaccount')) {
189 $result = $object->fetch($id);
191 if (!empty($object->id)) {
192 $result = $object->delete($user);
195 header(
"Location: account.php");
210$form =
new Form($db);
216$title = $langs->trans(
'AccountAccounting').
" - ".$langs->trans(
'Card');
218$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
220llxheader(
'', $title, $help_url);
224if ($action ==
'create') {
227 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">'.
"\n";
228 print
'<input type="hidden" name="token" value="'.newToken().
'">';
229 print
'<input type="hidden" name="action" value="add">';
233 print
'<table class="border centpercent">';
236 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
"Chartofaccounts").
'</span></td>';
238 print $accountsystem->ref;
242 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
"AccountNumber").
'</span></td>';
243 print
'<td><input name="account_number" size="30" value="'.$account_number.
'"></td></tr>';
246 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Label").
'</span></td>';
247 print
'<td><input name="label" size="70" value="'.$object->label.
'"></td></tr>';
250 print
'<tr><td>'.$langs->trans(
"LabelToShow").
'</td>';
251 print
'<td><input name="labelshort" size="70" value="'.$object->labelshort.
'"></td></tr>';
254 print
'<tr><td>'.$langs->trans(
"Accountparent").
'</td>';
256 print $formaccounting->select_account($object->account_parent,
'account_parent', 1,
null, 0, 0,
'minwidth200');
261 print $form->textwithpicto($langs->trans(
"Pcgtype"), $langs->transnoentitiesnoconv(
"PcgtypeDesc"));
264 print
'<input type="text" name="pcg_type" list="pcg_type_datalist" value="'.dol_escape_htmltag(GETPOSTISSET(
'pcg_type') ?
GETPOST(
'pcg_type',
'alpha') : $object->pcg_type).
'">';
266 print
'<datalist id="pcg_type_datalist">';
267 $sql =
"SELECT DISTINCT pcg_type FROM " . MAIN_DB_PREFIX .
"accounting_account";
268 $sql .=
" WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) .
"'";
269 $sql .=
' AND entity in ('.getEntity(
'accounting_account', 0).
')';
270 $sql .=
' LIMIT 50000';
271 $resql = $db->query($sql);
273 while ($obj = $db->fetch_object($resql)) {
282 print $form->textwithpicto($langs->trans(
"AccountingCategory"), $langs->transnoentitiesnoconv(
"AccountingAccountGroupsDesc"));
285 print $formaccounting->select_accounting_category($object->account_category,
'account_category', 1, 0, 1);
292 print
'<div class="center">';
293 print
'<input class="button button-save" type="submit" value="'.$langs->trans(
"Save").
'">';
294 print
' ';
295 print
'<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
299} elseif ($id > 0 || $ref) {
300 $result = $object->fetch($id, $ref, 1);
306 if ($action ==
'update') {
307 print
dol_get_fiche_head($head,
'card', $langs->trans(
'AccountAccounting'), 0,
'accounting_account');
309 print
'<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">'.
"\n";
310 print
'<input type="hidden" name="token" value="'.newToken().
'">';
311 print
'<input type="hidden" name="action" value="edit">';
312 print
'<input type="hidden" name="id" value="'.$id.
'">';
313 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
315 print
'<table class="border centpercent">';
318 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
"AccountNumber").
'</span></td>';
319 print
'<td><input name="account_number" size="30" value="'.$object->account_number.
'"</td></tr>';
322 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Label").
'</span></td>';
323 print
'<td><input name="label" size="70" value="'.$object->label.
'"</td></tr>';
326 print
'<tr><td>'.$langs->trans(
"LabelToShow").
'</td>';
327 print
'<td><input name="labelshort" size="70" value="'.$object->labelshort.
'"</td></tr>';
330 print
'<tr><td>'.$langs->trans(
"Accountparent").
'</td>';
333 print $formaccounting->select_account($object->account_parent,
'account_parent', 1, array(), 0, 0,
'minwidth100 maxwidth300 maxwidthonsmartphone', 1,
'');
338 print $form->textwithpicto($langs->trans(
"Pcgtype"), $langs->transnoentitiesnoconv(
"PcgtypeDesc"));
341 print
'<input type="text" name="pcg_type" list="pcg_type_datalist" value="'.dol_escape_htmltag(GETPOSTISSET(
'pcg_type') ?
GETPOST(
'pcg_type',
'alpha') : $object->pcg_type).
'">';
343 print
'<datalist id="pcg_type_datalist">';
344 $sql =
'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX .
'accounting_account';
345 $sql .=
" WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) .
"'";
346 $sql .=
' AND entity in ('.getEntity(
'accounting_account', 0).
')';
347 $sql .=
' LIMIT 50000';
348 $resql = $db->query($sql);
350 while ($obj = $db->fetch_object($resql)) {
359 print $form->textwithpicto($langs->trans(
"AccountingCategory"), $langs->transnoentitiesnoconv(
"AccountingAccountGroupsDesc"));
362 print $formaccounting->select_accounting_category($object->account_category,
'account_category', 1);
369 print $form->buttonsSaveCancel();
374 $linkback =
'<a href="'.DOL_URL_ROOT.
'/accountancy/admin/account.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
376 print
dol_get_fiche_head($head,
'card', $langs->trans(
'AccountAccounting'), -1,
'accounting_account');
378 dol_banner_tab($object,
'ref', $linkback, 1,
'account_number',
'ref');
381 print
'<div class="fichecenter">';
382 print
'<div class="underbanner clearboth"></div>';
384 print
'<table class="border centpercent tableforfield">';
387 print
'<tr><td class="titlefield">'.$langs->trans(
"Label").
'</td>';
388 print
'<td colspan="2">'.$object->label.
'</td></tr>';
391 print
'<tr><td class="titlefield">'.$langs->trans(
"LabelToShow").
'</td>';
392 print
'<td colspan="2">'.$object->labelshort.
'</td></tr>';
396 if (!empty($object->account_parent)) {
397 $accp->fetch($object->account_parent,
'');
399 print
'<tr><td>'.$langs->trans(
"Accountparent").
'</td>';
400 print
'<td colspan="2">'.$accp->account_number.
' - '.$accp->label.
'</td></tr>';
404 print $form->textwithpicto($langs->trans(
"Pcgtype"), $langs->transnoentitiesnoconv(
"PcgtypeDesc"));
406 print
'<td colspan="2">'.$object->pcg_type.
'</td></tr>';
410 print $form->textwithpicto($langs->trans(
"AccountingCategory"), $langs->transnoentitiesnoconv(
"AccountingAccountGroupsDesc"));
411 print
"</td><td colspan='2'>".$object->account_category_label.
"</td>";
422 print
'<div class="tabsAction">';
424 if ($user->hasRight(
'accounting',
'chartofaccount')) {
425 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=update&token='.newToken().
'&id='.$object->id.
'">'.$langs->trans(
'Modify').
'</a>';
427 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
'Modify').
'</a>';
431 $permissiontodelete = $user->hasRight(
'accounting',
'chartofaccount');
432 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken(),
'delete', $permissiontodelete);
accounting_prepare_head(AccountingAccount $object)
Prepare array with list of tabs.
clean_account($account)
Return accounting account without zero on the right.
Class to manage accountancy systems.
Class to manage accounting accounts.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.