27require
'../../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formcompany.class.php';
37require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formfile.class.php';
38require_once DOL_DOCUMENT_ROOT .
'/core/class/html.formaccounting.class.php';
39require_once DOL_DOCUMENT_ROOT .
'/core/lib/accounting.lib.php';
40require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/accountingaccount.class.php';
41require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/bookkeepingtemplate.class.php';
42require_once DOL_DOCUMENT_ROOT .
'/accountancy/class/bookkeepingtemplateline.class.php';
45$langs->loadLangs(array(
"accountancy",
"other"));
53$code =
GETPOST(
'code',
'alpha');
55$action =
GETPOST(
'action',
'aZ09');
56$confirm =
GETPOST(
'confirm',
'alpha');
57$cancel =
GETPOST(
'cancel',
'aZ09');
58$contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'bookkeepingtemplatecard';
59$backtopage =
GETPOST(
'backtopage',
'alpha');
60$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
64$diroutputmassaction =
$conf->accounting->dir_output .
'/temp/massgeneration/' . $user->id;
65$hookmanager->initHooks(array(
$object->element .
'card',
'globalcard'));
68$extrafields->fetch_name_optionals_label(
$object->table_element);
70$search_array_options = $extrafields->getOptionalsFromPost(
$object->table_element,
'',
'search_');
73$search_all = trim(
GETPOST(
"search_all",
'alpha'));
75foreach (
$object->fields as $key => $val) {
76 if (
GETPOST(
'search_' . $key,
'alpha')) {
77 $search[$key] =
GETPOST(
'search_' . $key,
'alpha');
81if (empty($action) && empty($id) && empty($code)) {
86include DOL_DOCUMENT_ROOT .
'/core/actions_fetchobject.inc.php';
88if ($id > 0 && empty(
$object->id)) {
93$permissiontoread = $user->hasRight(
'accounting',
'chartofaccount');
94$permissiontoadd = $user->hasRight(
'accounting',
'chartofaccount');
95$permissiontodelete = $user->hasRight(
'accounting',
'chartofaccount');
96$permissionnote = $user->hasRight(
'accounting',
'chartofaccount');
97$permissiondellink = $user->hasRight(
'accounting',
'chartofaccount');
99$upload_dir =
$conf->accounting->multidir_output[isset(
$object->entity) ?
$object->entity : 1];
101if (!$permissiontoread) {
112$parameters = array();
113$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
118if (empty($reshook)) {
121 $backurlforlist = DOL_URL_ROOT .
'/accountancy/admin/template/list.php';
123 if (empty($backtopage) || ($cancel && empty($id))) {
124 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
125 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
126 $backtopage = $backurlforlist;
128 $backtopage = DOL_URL_ROOT .
'/accountancy/admin/template/card.php?id=' . ((!empty($id) &&
$id > 0) ? $id :
'__ID__');
133 $triggermodname =
'ACCOUNTING_BOOKKEEPINGTEMPLATE_MODIFY';
136 include DOL_DOCUMENT_ROOT .
'/core/actions_addupdatedelete.inc.php';
139 include DOL_DOCUMENT_ROOT .
'/core/actions_dellink.inc.php';
142 include DOL_DOCUMENT_ROOT .
'/core/actions_printing.inc.php';
145 include DOL_DOCUMENT_ROOT .
'/core/actions_builddoc.inc.php';
148 $triggersendname =
'ACCOUNTING_BOOKKEEPINGTEMPLATE_SENTBYMAIL';
149 $autocopy =
'MAIN_MAIL_AUTOCOPY_BOOKKEEPINGTEMPLATE_TO';
150 $trackid =
'bookkeepingtemplate' .
$object->id;
151 include DOL_DOCUMENT_ROOT .
'/core/actions_sendmails.inc.php';
155if ($action ==
'addline' && $permissiontoadd) {
159 $general_account =
GETPOST(
'general_account',
'alphanohtml');
160 $subledger_account =
GETPOST(
'subledger_account',
'alphanohtml');
161 if ($subledger_account ==
'-1') {
162 $subledger_account =
null;
164 $subledger_label =
GETPOST(
'subledger_label',
'alphanohtml');
165 $operation_label =
GETPOST(
'operation_label',
'alphanohtml');
170 if (((
float) $debit != 0.0) && ((
float) $credit != 0.0)) {
176 if (empty($general_account) || $general_account ==
'-1') {
178 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"AccountNumber")),
null,
'errors');
184 $accountingaccount->fetch(0, $general_account, 1);
185 $general_label = $accountingaccount->label;
189 $line->fk_transaction_template =
$object->id;
190 $line->general_account = $general_account;
191 $line->general_label = $general_label;
192 $line->subledger_account = $subledger_account;
193 $line->subledger_label = $subledger_label;
194 $line->operation_label = $operation_label;
195 $line->debit = $debit;
196 $line->credit = $credit;
198 $result = $line->create($user, 0);
206 header(
"Location: " . $_SERVER[
"PHP_SELF"] .
"?id=" .
$object->id);
213if ($action ==
'updateline' && $permissiontoadd) {
217 $general_account =
GETPOST(
'general_account',
'alphanohtml');
218 $subledger_account =
GETPOST(
'subledger_account',
'alphanohtml');
219 if ($subledger_account ==
'-1') {
220 $subledger_account =
null;
222 $subledger_label =
GETPOST(
'subledger_label',
'alphanohtml');
223 $operation_label =
GETPOST(
'operation_label',
'alphanohtml');
228 if (((
float) $debit != 0.0) && ((
float) $credit != 0.0)) {
231 $action =
'editline';
234 if (empty($general_account) || $general_account ==
'-1') {
236 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"AccountNumber")),
null,
'errors');
237 $action =
'editline';
242 $accountingaccount->fetch(0, $general_account, 1);
243 $general_label = $accountingaccount->label;
247 $result = $line->fetch($lineid);
250 $line->general_account = $general_account;
251 $line->general_label = $general_label;
252 $line->subledger_account = $subledger_account;
253 $line->subledger_label = $subledger_label;
254 $line->operation_label = $operation_label;
255 $line->debit = $debit;
256 $line->credit = $credit;
258 $result = $line->update($user, 0);
263 $action =
'editline';
266 header(
"Location: " . $_SERVER[
"PHP_SELF"] .
"?id=" .
$object->id);
277if ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $permissiontodelete) {
278 $result =
$object->deleteLine($user, $lineid);
281 header(
"Location: " . $_SERVER[
"PHP_SELF"] .
"?id=" .
$object->id);
292$title = $langs->trans(
'BookkeepingTemplate') .
" - " . $langs->trans(
'Card');
293if ($action ==
'create') {
294 $title = $langs->trans(
"NewBookkeepingTemplate");
298llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-accountancy page-admin-template-card');
301if (!empty(
$conf->use_javascript_ajax)) {
302 print
"\n" .
'<script type="text/javascript">';
303 print
'$(document).ready(function () {
304 function toggleSubledger() {
305 var isCentral = $("#accountingaccount_number option:selected").data("centralized");
306 console.log("the selected general ledger account is centralised?", isCentral);
308 $("#subledger_account, #subledger_label").prop("disabled", false);
310 $("#subledger_account, #subledger_label").prop("disabled", true);
316 $("#accountingaccount_number").on("change", toggleSubledger);
317 $("#accountingaccount_number").on("select2:select", toggleSubledger);
320 print
' </script>' .
"\n";
324if ($action ==
'create') {
325 if (empty($permissiontoadd)) {
331 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
332 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
333 print
'<input type="hidden" name="action" value="add">';
335 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
337 if ($backtopageforcancel) {
338 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
343 print
'<table class="border centpercent tableforfieldcreate">' .
"\n";
346 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_add.tpl.php';
349 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_add.tpl.php';
351 print
'</table>' .
"\n";
355 print $form->buttonsSaveCancel(
"Create");
363if (($id || $code) && $action ==
'edit') {
366 print
'<form method="POST" action="' . $_SERVER[
"PHP_SELF"] .
'">';
367 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
368 print
'<input type="hidden" name="action" value="update">';
369 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
371 print
'<input type="hidden" name="backtopage" value="' . $backtopage .
'">';
373 if ($backtopageforcancel) {
374 print
'<input type="hidden" name="backtopageforcancel" value="' . $backtopageforcancel .
'">';
379 print
'<table class="border centpercent tableforfieldedit">' .
"\n";
382 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_edit.tpl.php';
385 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_edit.tpl.php';
391 print $form->buttonsSaveCancel();
397if (
$object->id > 0 && (empty($action) || ($action !=
'edit' && $action !=
'create'))) {
400 print
dol_get_fiche_head($head,
'card', $langs->trans(
"BookkeepingTemplate"), -1,
$object->picto, 0,
'',
'', 0,
'', 1);
405 if ($action ==
'delete') {
406 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id, $langs->trans(
'DeleteBookkeepingTemplate'), $langs->trans(
'ConfirmDeleteObject'),
'confirm_delete',
'', 0, 1);
410 if ($action ==
'deleteline') {
411 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&lineid=' . $lineid, $langs->trans(
'DeleteLine'), $langs->trans(
'ConfirmDeleteLine'),
'confirm_deleteline',
'', 0, 1);
415 if ($action ==
'clone') {
417 $formquestion = array();
418 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneAsk',
$object->code),
'confirm_clone', $formquestion,
'yes', 1);
422 $parameters = array(
'formConfirm' => $formconfirm,
'lineid' => $lineid);
423 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
424 if (empty($reshook)) {
425 $formconfirm .= $hookmanager->resPrint;
426 } elseif ($reshook > 0) {
427 $formconfirm = $hookmanager->resPrint;
434 $linkback =
'<a href="' . DOL_URL_ROOT .
'/accountancy/admin/template/list.php?restore_lastsearch_values=1">' . $langs->trans(
"BackToList") .
'</a>';
436 $morehtmlref =
'<div class="refidno">';
437 $morehtmlref .=
'</div>';
439 dol_banner_tab($object,
'id', $linkback, 1,
'rowid',
'code', $morehtmlref);
441 print
'<div class="fichecenter">';
442 print
'<div class="fichehalfleft">';
443 print
'<div class="underbanner clearboth"></div>';
444 print
'<table class="border centpercent tableforfield">' .
"\n";
448 include DOL_DOCUMENT_ROOT .
'/core/tpl/commonfields_view.tpl.php';
451 include DOL_DOCUMENT_ROOT .
'/core/tpl/extrafields_view.tpl.php';
457 print
'<div class="clearboth"></div>';
462 if ($action !=
'presend' && $action !=
'editline' && $action !=
'addline') {
463 print
'<div class="tabsAction">' .
"\n";
464 $parameters = array();
465 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
470 if (empty($reshook)) {
472 if ($permissiontoadd) {
473 print dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=edit&token=' . newToken(),
'', $permissiontoadd);
477 if ($permissiontoadd) {
478 print dolGetButtonAction($langs->trans(
'ToClone'),
'',
'clone', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id .
'&action=clone&token=' . newToken(),
'', $permissiontoadd);
482 print dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
'PHP_SELF'] .
'?id=' .
$object->id .
'&action=delete&token=' . newToken(),
'', $permissiontodelete);
484 print
'</div>' .
"\n";
488 print
'<div class="div-table-responsive-no-min">';
489 if (!empty(
$object->table_element_line)) {
491 $result =
$object->getLinesArray();
493 print
'<form name="addproduct" id="addproduct" action="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id . (($action !=
'editline') ?
'' :
'#line_' .
GETPOST(
'lineid',
'int')) .
'" method="POST">';
494 print
'<input type="hidden" name="token" value="' . newToken() .
'">';
495 print
'<input type="hidden" name="action" value="' . (($action !=
'editline') ?
'addline' :
'updateline') .
'">';
496 print
'<input type="hidden" name="mode" value="">';
497 print
'<input type="hidden" name="page_y" value="">';
498 print
'<input type="hidden" name="id" value="' .
$object->id .
'">';
500 if (!empty(
$conf->use_javascript_ajax) &&
$object->status == 0) {
502 $fk_element =
'fk_transaction_template';
503 $table_element_line =
$object->table_element_line;
504 include DOL_DOCUMENT_ROOT .
'/core/tpl/ajaxrow.tpl.php';
507 print
'<div class="div-table-responsive-no-min">';
508 print
'<table id="tablelines" class="noborder noshadow centpercent">';
511 print
'<tr class="liste_titre">';
523 foreach (
$object->lines as $line) {
525 if ($action !=
'editline' ||
GETPOST(
'lineid',
'int') != $line->id) {
526 print
'<tr class="oddeven" id="row-' . $line->id .
'">';
527 print
'<!-- td columns in display mode -->';
528 $resultfetch = $accountingaccount->fetch(0, $line->general_account,
true);
530 if ($resultfetch > 0) {
531 print $accountingaccount->getNomUrl(0, 1, 1,
'', 0);
533 print
dol_escape_htmltag($line->general_account).
' <span class="warning">('.$langs->trans(
"AccountRemovedFromCurrentChartOfAccount").
')</span>';
536 print
'<td>'.length_accounta($line->subledger_account ??
'');
537 if (!empty($line->subledger_label)) {
538 print
' - <span class="opacitymedium">'.dol_escape_htmltag($line->subledger_label).
'</span>';
541 print
'<td>' . ($line->operation_label ?
dol_escape_htmltag($line->operation_label) :
'') .
'</td>';
542 print
'<td class="right">' . ($line->debit ?
price($line->debit) :
'') .
'</td>';
543 print
'<td class="right">' . ($line->credit ?
price($line->credit) :
'') .
'</td>';
546 print
'<td class="center">';
547 if ($permissiontoadd) {
548 print
'<a class="editfielda reposition" href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=editline&token=' . newToken() .
'&lineid=' . $line->id .
'#line_' . $line->id .
'">';
549 print
img_edit(
'', 0,
'class="marginrightonly"');
554 if ($permissiontodelete) {
555 print
'<a class="reposition" href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=deleteline&token=' . newToken() .
'&lineid=' . $line->id .
'">';
564 if ($action ==
'editline' &&
GETPOST(
'lineid',
'int') == $line->id) {
565 print
'<tr class="oddeven" data-lineid="'.((int) $line->id).
'">';
566 print
'<input type="hidden" name="lineid" value="' .
GETPOST(
'lineid',
'int') .
'">';
570 print $formaccounting->select_account((GETPOSTISSET(
"accountingaccount_number") ?
GETPOST(
"accountingaccount_number",
"alpha") : $line->general_account),
'general_account', 1, array(), 1, 1,
'minwidth200 maxwidth500');
579 print $formaccounting->select_auxaccount((GETPOSTISSET(
"subledger_account") ?
GETPOST(
"subledger_account",
"alpha") : $line->subledger_account),
'subledger_account', 1,
'maxwidth250',
'',
'subledger_label');
581 print
'<br><input type="text" class="maxwidth150" name="subledger_label" value="'.(GETPOSTISSET(
"subledger_label") ?
GETPOST(
"subledger_label",
"alpha") : $line->subledger_label).
'" placeholder="'.
dol_escape_htmltag($langs->trans(
"SubledgerAccountLabel")).
'">';
586 print
'<input type="text" class="minwidth200" name="operation_label" value="'.(GETPOSTISSET(
"operation_label") ?
GETPOST(
"operation_label",
"alpha") : $line->operation_label).
'">';
590 print
'<td class="right">';
591 print
'<input type="text" name="debit" class="flat right maxwidth75" value="' . ($line->debit ?
price($line->debit) :
'') .
'">';
595 print
'<td class="right">';
596 print
'<input type="text" name="credit" class="flat right maxwidth75" value="' . ($line->credit ?
price($line->credit) :
'') .
'">';
600 print
'<td class="center" colspan="2">';
601 print
'<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="' . $langs->trans(
"Save") .
'">';
603 print
'<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="' . $langs->trans(
"Cancel") .
'">';
613 if ($action !=
'editline' && $permissiontoadd) {
614 print
'<tr class="liste_titre nodrag nodrop">';
616 print $formaccounting->select_account(
'',
'general_account', 1, [], 1, 1,
'maxwidth300');
619 print $formaccounting->select_auxaccount(
'',
'subledger_account', 1,
'maxwidth250',
'',
'subledger_label');
620 print
'<br><input type="text" class="maxwidth150" name="new_subledger_label" value="" placeholder="' .
dol_escape_htmltag($langs->trans(
"SubledgerAccountLabel")) .
'">';
622 print
'<td><input type="text" name="operation_label" class="flat minwidth150"></td>';
623 print
'<td class="right"><input type="text" name="debit" class="flat right maxwidth75"></td>';
624 print
'<td class="right"><input type="text" name="credit" class="flat right maxwidth75"></td>';
625 print
'<td class="center" colspan="2"><input type="submit" class="button buttongen marginbottomonly" name="addline" value="' . $langs->trans(
"Add") .
'"></td>';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
accountingTransactionTemplatePrepareHead(BookkeepingTemplate $object)
Prepare array with list of tabs for accounting transaction template.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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 accounting accounts.
Class for BookkeepingTemplate.
Class for BookkeepingTemplateLine.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
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, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
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.