28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/lib/accounting.lib.php';
30require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountingaccount.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/accountancy/class/accountancysystem.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formaccounting.class.php';
45$langs->loadLangs(array(
'accountancy',
'bills',
'compta'));
47$action =
GETPOST(
'action',
'aZ09');
48$backtopage =
GETPOST(
'backtopage',
'alpha');
52$cancel =
GETPOST(
'cancel',
'alpha');
54$account_number =
GETPOST(
'account_number',
'alphanohtml');
55$label =
GETPOST(
'label',
'alpha');
58if ($user->socid > 0) {
61if (!$user->hasRight(
'accounting',
'chartofaccount')) {
73if (
GETPOST(
'cancel',
'alpha')) {
74 $urltogo = $backtopage ? $backtopage : DOL_URL_ROOT.
'/accountancy/admin/account.php';
75 header(
"Location: ".$urltogo);
79if ($action ==
'add' && $user->hasRight(
'accounting',
'chartofaccount')) {
81 if (!$account_number) {
82 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountNumber")),
null,
'errors');
85 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label")),
null,
'errors');
88 $sql =
"SELECT pcg_version FROM " . MAIN_DB_PREFIX .
"accounting_system WHERE rowid = ".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS'));
90 dol_syslog(
'accountancy/admin/card.php:: $sql=' . $sql);
91 $result = $db->query($sql);
92 $obj = $db->fetch_object($result);
103 $object->fk_pcg_version = $obj->pcg_version;
105 $object->account_number = $account_number;
106 $object->account_parent = $account_parent;
117 } elseif ($res == -4) {
121 } elseif ($res < 0) {
128 $urltogo = $backtopage ? $backtopage : DOL_URL_ROOT.
'/accountancy/admin/account.php';
129 header(
"Location: " . $urltogo);
134} elseif ($action ==
'edit' && $user->hasRight(
'accounting',
'chartofaccount')) {
136 if (!$account_number) {
137 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"AccountNumber")),
null,
'errors');
140 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label")),
null,
'errors');
145 $sql =
"SELECT pcg_version FROM ".MAIN_DB_PREFIX.
"accounting_system WHERE rowid=".((int)
getDolGlobalInt(
'CHARTOFACCOUNTS'));
147 dol_syslog(
'accountancy/admin/card.php:: $sql=' . $sql);
148 $result2 = $db->query($sql);
149 $obj = $db->fetch_object($result2);
160 $object->fk_pcg_version = $obj->pcg_version;
162 $object->account_number = $account_number;
163 $object->account_parent = $account_parent;
168 $result =
$object->update($user);
171 $urltogo = $backtopage ? $backtopage : ($_SERVER[
"PHP_SELF"] .
"?id=" .
$id);
172 header(
"Location: " . $urltogo);
174 } elseif ($result == -2) {
181 $urltogo = $backtopage ? $backtopage : ($_SERVER[
"PHP_SELF"].
"?id=".
$id);
182 header(
"Location: ".$urltogo);
185} elseif ($action ==
'delete' && $user->hasRight(
'accounting',
'chartofaccount')) {
189 $result =
$object->delete($user);
192 header(
"Location: account.php");
207$form =
new Form($db);
213$title = $langs->trans(
'AccountAccounting').
" - ".$langs->trans(
'Card');
215$help_url =
'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilité_en_Partie_Double#Configuration';
217llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-admin_card');
221if ($action ==
'create') {
224 print
'<form name="add" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">'.
"\n";
225 print
'<input type="hidden" name="token" value="'.newToken().
'">';
226 print
'<input type="hidden" name="action" value="add">';
230 print
'<table class="border centpercent">';
233 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
"Chartofaccounts").
'</span></td>';
235 print $accountsystem->ref;
239 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
"AccountNumber").
'</span></td>';
240 print
'<td><input name="account_number" size="30" value="'.$account_number.
'"></td></tr>';
243 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Label").
'</span></td>';
244 print
'<td><input name="label" size="70" value="'.$object->label.
'"></td></tr>';
247 print
'<tr><td>'.$langs->trans(
"LabelToShow").
'</td>';
248 print
'<td><input name="labelshort" size="70" value="'.$object->labelshort.
'"></td></tr>';
251 print
'<tr><td>'.$langs->trans(
"Accountparent").
'</td>';
253 print $formaccounting->select_account(
$object->account_parent,
'account_parent', 1, [], 0, 0,
'minwidth200');
258 print $form->textwithpicto($langs->trans(
"Pcgtype"), $langs->transnoentitiesnoconv(
"PcgtypeDesc"));
261 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).
'">';
263 print
'<datalist id="pcg_type_datalist">';
264 $sql =
"SELECT DISTINCT pcg_type FROM " . MAIN_DB_PREFIX .
"accounting_account";
265 $sql .=
" WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) .
"'";
266 $sql .=
' AND entity in ('.getEntity(
'accounting_account', 0).
')';
267 $sql .=
' LIMIT 50000';
268 $resql = $db->query($sql);
270 while ($obj = $db->fetch_object($resql)) {
279 print $form->textwithpicto($langs->trans(
"AccountingCategory"), $langs->transnoentitiesnoconv(
"AccountingAccountGroupsDesc"));
282 print $formaccounting->select_accounting_category(
$object->account_category,
'account_category', 1, 0, 1);
289 print
'<div class="center">';
290 print
'<input class="button button-save" type="submit" value="'.$langs->trans(
"Save").
'">';
291 print
' ';
292 print
'<input class="button button-cancel" type="submit" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
296} elseif ($id > 0 || $ref) {
297 $result =
$object->fetch($id, $ref, 1);
303 if ($action ==
'update') {
304 print
dol_get_fiche_head($head,
'card', $langs->trans(
'AccountAccounting'), 0,
'accounting_account');
306 print
'<form name="update" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">'.
"\n";
307 print
'<input type="hidden" name="token" value="'.newToken().
'">';
308 print
'<input type="hidden" name="action" value="edit">';
309 print
'<input type="hidden" name="id" value="'.$id.
'">';
310 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
312 print
'<table class="border centpercent">';
315 print
'<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans(
"AccountNumber").
'</span></td>';
316 print
'<td><input name="account_number" size="30" value="'.$object->account_number.
'"></td></tr>';
319 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Label").
'</span></td>';
320 print
'<td><input name="label" size="70" value="'.$object->label.
'"></td></tr>';
323 print
'<tr><td>'.$langs->trans(
"LabelToShow").
'</td>';
324 print
'<td><input name="labelshort" size="70" value="'.$object->labelshort.
'"></td></tr>';
327 print
'<tr><td>'.$langs->trans(
"Accountparent").
'</td>';
330 print $formaccounting->select_account(
$object->account_parent,
'account_parent', 1, array(), 0, 0,
'minwidth100 maxwidth300 maxwidthonsmartphone', 1,
'');
335 print $form->textwithpicto($langs->trans(
"Pcgtype"), $langs->transnoentitiesnoconv(
"PcgtypeDesc"));
338 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).
'">';
340 print
'<datalist id="pcg_type_datalist">';
341 $sql =
'SELECT DISTINCT pcg_type FROM ' . MAIN_DB_PREFIX .
'accounting_account';
342 $sql .=
" WHERE fk_pcg_version = '" . $db->escape($accountsystem->ref) .
"'";
343 $sql .=
' AND entity in ('.getEntity(
'accounting_account', 0).
')';
344 $sql .=
' LIMIT 50000';
345 $resql = $db->query($sql);
347 while ($obj = $db->fetch_object($resql)) {
356 print $form->textwithpicto($langs->trans(
"AccountingCategory"), $langs->transnoentitiesnoconv(
"AccountingAccountGroupsDesc"));
359 print $formaccounting->select_accounting_category(
$object->account_category,
'account_category', 1);
366 print $form->buttonsSaveCancel();
371 $linkback =
'<a href="'.DOL_URL_ROOT.
'/accountancy/admin/account.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
373 print
dol_get_fiche_head($head,
'card', $langs->trans(
'AccountAccounting'), -1,
'accounting_account');
375 dol_banner_tab(
$object,
'ref', $linkback, 1,
'account_number',
'ref');
378 print
'<div class="fichecenter">';
379 print
'<div class="underbanner clearboth"></div>';
381 print
'<table class="border centpercent tableforfield">';
384 print
'<tr><td class="titlefield">'.$langs->trans(
"Label").
'</td>';
385 print
'<td colspan="2">'.$object->label.
'</td></tr>';
388 print
'<tr><td class="titlefield">'.$langs->trans(
"LabelToShow").
'</td>';
389 print
'<td colspan="2">'.$object->labelshort.
'</td></tr>';
393 if (!empty(
$object->account_parent)) {
394 $accp->fetch(
$object->account_parent,
'');
396 print
'<tr><td>'.$langs->trans(
"Accountparent").
'</td>';
397 print
'<td colspan="2">'.$accp->account_number.
' - '.$accp->label.
'</td></tr>';
401 print $form->textwithpicto($langs->trans(
"Pcgtype"), $langs->transnoentitiesnoconv(
"PcgtypeDesc"));
403 print
'<td colspan="2">'.$object->pcg_type.
'</td></tr>';
407 print $form->textwithpicto($langs->trans(
"AccountingCategory"), $langs->transnoentitiesnoconv(
"AccountingAccountGroupsDesc"));
408 print
"</td><td colspan='2'>".$object->account_category_label.
"</td>";
419 print
'<div class="tabsAction">';
421 if ($user->hasRight(
'accounting',
'chartofaccount')) {
422 print
'<a class="butAction" href="'.$_SERVER[
"PHP_SELF"].
'?action=update&token='.
newToken().
'&id='.
$object->id.
'">'.$langs->trans(
'Modify').
'</a>';
424 print
'<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans(
"NotAllowed")).
'">'.$langs->trans(
'Modify').
'</a>';
428 $permissiontodelete = $user->hasRight(
'accounting',
'chartofaccount');
429 print
dolGetButtonAction($langs->trans(
"Delete"),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'delete', $permissiontodelete);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
accounting_prepare_head(AccountingAccount $object)
Prepare array with list of tabs.
clean_account($account)
Return accounting account without zero on the right.
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.
Class to manage accountancy systems.
Class to manage accounting accounts.
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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_get_fiche_end($notab=0)
Return tab footer of a card.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a 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.