dolibarr 23.0.4
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2017 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2013-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
5 * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2025 Nicolas Barrouillet <nicolas@pragma-tech.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
36require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
37require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
38require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
39require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
40
49// Load translation files required by the page
50$langs->loadLangs(array("accountancy", "bills", "compta", "errors"));
51
52$action = GETPOST('action', 'aZ09');
53$cancel = GETPOST('cancel', 'alpha');
54$confirm = GETPOST('confirm', 'alpha');
55
56$type = GETPOST('type', 'alpha');
57$backtopage = GETPOST('backtopage', 'alpha');
58if (empty($backtopage)) {
59 $backtopage = DOL_URL_ROOT . '/accountancy/bookkeeping/list.php';
60}
61
62$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
63
64$id = GETPOSTINT('id'); // id of record
65$mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
66$piece_num = GETPOSTINT("piece_num") ? GETPOSTINT("piece_num") : GETPOST('ref'); // id of transaction (several lines share the same transaction id)
67$clonedate = (int) GETPOSTINT('clonedate');
68
69$accountingaccount = new AccountingAccount($db);
70$accountingjournal = new AccountingJournal($db);
71
72$accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml');
73$accountingaccount->fetch(0, $accountingaccount_number, true);
74$accountingaccount_label = $accountingaccount->label;
75
76$journal_code = GETPOST('code_journal', 'alpha');
77$accountingjournal->fetch(0, $journal_code);
78$journal_label = $accountingjournal->label;
79
80$subledger_account = GETPOST('subledger_account', 'alphanohtml');
81if ($subledger_account == -1) {
82 $subledger_account = null;
83}
84$subledger_label = GETPOST('subledger_label', 'alphanohtml');
85
86$label_operation = GETPOST('label_operation', 'alphanohtml');
87$debit = (float) price2num(GETPOST('debit', 'alpha'));
88$credit = (float) price2num(GETPOST('credit', 'alpha'));
89
90$save = GETPOST('save', 'alpha');
91if (!empty($save)) {
92 $action = 'add';
93}
94$update = GETPOST('update', 'alpha');
95if (!empty($update)) {
96 $action = 'confirm_update';
97}
98
99// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
100$hookmanager->initHooks(array('bookkeepingcard', 'globalcard'));
101
102$object = new BookKeeping($db);
103
104// Security check
105if (!isModEnabled('accounting')) {
107}
108if ($user->socid > 0) {
110}
111if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
113}
114
115$permissiontoadd = $user->hasRight('accounting', 'mouvements', 'creer');
116$permissiontodelete = $user->hasRight('accounting', 'mouvements', 'supprimer');
117$numRefModel = getDolGlobalString('BOOKKEEPING_ADDON', 'mod_bookkeeping_neon');
118
119/*
120 * Actions
121 */
122
123$parameters = array();
124$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
125if ($reshook < 0) {
126 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
127}
128if (empty($reshook)) {
129 $error = 0;
130
131 if ($cancel) {
132 header("Location: ". $backtopage . (!empty($type) ? '?type=sub' : ''));
133 exit;
134 }
135
136 if ($action == "confirm_update" && $permissiontoadd) {
137 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
138 $error++;
139 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
140 $action = 'update';
141 }
142 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
143 $error++;
144 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
145 $action = 'update';
146 }
147
148 if (!$error) {
149 $object = new BookKeeping($db);
150
151 $result = $object->fetch($id, null, $mode);
152 if ($result < 0) {
153 $error++;
154 setEventMessages($object->error, $object->errors, 'errors');
155 } else {
156 $object->numero_compte = $accountingaccount_number;
157 $object->subledger_account = $subledger_account;
158 $object->subledger_label = $subledger_label;
159 $object->label_compte = $accountingaccount_label;
160 $object->label_operation = $label_operation;
161 $object->debit = $debit;
162 $object->credit = $credit;
163
164 if ((float) $debit != 0.0) {
165 $object->montant = $debit; // deprecated
166 $object->amount = $debit;
167 $object->sens = 'D';
168 }
169 if ((float) $credit != 0.0) {
170 $object->montant = $credit; // deprecated
171 $object->amount = $credit;
172 $object->sens = 'C';
173 }
174
175 $result = $object->update($user, 0, $mode);
176 if ($result < 0) {
177 setEventMessages($object->error, $object->errors, 'errors');
178 } else {
179 if ($mode != '_tmp') {
180 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
181 }
182
183 $debit = 0;
184 $credit = 0;
185
186 $action = '';
187 }
188 }
189 }
190 } elseif ($action == "add" && $permissiontoadd) {
191 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
192 $error++;
193 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
194 $action = '';
195 }
196 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
197 $error++;
198 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
199 $action = '';
200 }
201 $subledger_account_str = is_array($subledger_account) ? reset($subledger_account) : (string) $subledger_account;
202 if (!checkGeneralAccountAllowsAuxiliary($db, $accountingaccount_number, $subledger_account_str)) {
203 $error++;
204 setEventMessages($langs->trans("ErrorAccountNotCentralized"). ". " . $langs->trans("RemoveSubsidiaryAccountOrAdjustTheGeneralAccount"), null, 'errors');
205 }
206
207 if (!$error) {
208 if (GETPOSTINT('doc_datemonth') && GETPOSTINT('doc_dateday') && GETPOSTINT('doc_dateyear')) {
209 $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
210 } else {
211 $datedoc = (int) GETPOSTINT('doc_date'); // TODO Use instead the mode day-month-year
212 }
213
214 $object = new BookKeeping($db);
215
216 $object->numero_compte = $accountingaccount_number;
217 $object->subledger_account = $subledger_account;
218 $object->subledger_label = $subledger_label;
219 $object->label_compte = $accountingaccount_label;
220 $object->label_operation = $label_operation;
221 $object->debit = $debit;
222 $object->credit = $credit;
223 $object->doc_date = $datedoc;
224 $object->doc_type = (string) GETPOST('doc_type', 'alpha');
225 $object->piece_num = $piece_num;
226 $object->doc_ref = (string) GETPOST('doc_ref', 'alpha');
227 $object->ref = (string) GETPOST('ref', 'alpha');
228 $object->code_journal = $journal_code;
229 $object->journal_label = $journal_label;
230 $object->fk_doc = GETPOSTINT('fk_doc');
231 $object->fk_docdet = GETPOSTINT('fk_docdet');
232
233 if ((float) $debit != 0.0) {
234 $object->montant = $debit; // deprecated
235 $object->amount = $debit;
236 $object->sens = 'D';
237 }
238
239 if ((float) $credit != 0.0) {
240 $object->montant = $credit; // deprecated
241 $object->amount = $credit;
242 $object->sens = 'C';
243 }
244
245 $result = $object->createStd($user, 0, $mode);
246
247 if ($result < 0) {
248 setEventMessages($object->error, $object->errors, 'errors');
249 } else {
250 if ($mode != '_tmp') {
251 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
252 }
253
254 $debit = 0;
255 $credit = 0;
256
257 $action = '';
258 }
259 }
260 } elseif ($action == "confirm_delete" && $permissiontoadd) { // Delete line
261 $object = new BookKeeping($db);
262
263 $result = $object->fetch($id, null, $mode);
264 $piece_num = (int) $object->piece_num;
265 if ($result < 0) {
266 setEventMessages($object->error, $object->errors, 'errors');
267
268 $action = 'create';
269 } elseif ($result > 0) {
270 $result = $object->delete($user, 0, $mode);
271 if ($result < 0) {
272 setEventMessages($object->error, $object->errors, 'errors');
273 }
274 }
275 $action = '';
276 } elseif ($action == "confirm_create" && $permissiontoadd) {
277 $object = new BookKeeping($db);
278
279 if (!$journal_code || $journal_code == '-1') {
280 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
281 $action = 'create';
282 $error++;
283 }
284 if (!GETPOST('doc_ref', 'alpha')) {
285 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
286 $action = 'create';
287 $error++;
288 }
289 if (dol_strlen(GETPOST('ref', 'alpha')) > 30) { // Size of field ref in database
290 setEventMessages($langs->trans("ErrorFieldTooLong", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
291 $action = 'create';
292 $error++;
293 }
294
295 if (!$error) {
296 $date_start = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
297
298 $object->label_compte = '';
299 $object->debit = 0;
300 $object->credit = 0;
301 $object->doc_date = $date_start;
302 $object->doc_type = GETPOST('doc_type', 'alpha');
303 $object->piece_num = GETPOSTINT('next_num_mvt');
304 $object->doc_ref = GETPOST('doc_ref', 'alpha');
305 $object->code_journal = $journal_code;
306 $object->journal_label = $journal_label;
307 $object->fk_doc = 0;
308 $object->fk_docdet = 0;
309 $object->ref = (GETPOST('ref', 'alpha') ? GETPOST('ref', 'alpha') : $object->getNextNumRef());
310 $object->montant = 0; // deprecated
311 $object->amount = 0;
312
313 $result = $object->createStd($user, 0, $mode);
314
315 if ($result < 0) {
316 setEventMessages($object->error, $object->errors, 'errors');
317
318 $action = 'create';
319 } else {
320 $reshook = $hookmanager->executeHooks('afterCreateBookkeeping', $parameters, $object, $action);
321
322 if ($mode != '_tmp') {
323 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
324 }
325 $action = '';
326 $id = $object->id;
327 $piece_num = (int) $object->piece_num;
328 }
329 }
330 }
331
332 if ($action == 'setdate' && $permissiontoadd) {
333 $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
334 $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode);
335 if ($result < 0) {
336 setEventMessages($object->error, $object->errors, 'errors');
337 } else {
338 if ($mode != '_tmp') {
339 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
340 }
341 $action = '';
342 }
343 }
344
345 if ($action == 'setjournal' && $permissiontoadd) {
346 $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode);
347 $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode);
348 if ($result < 0) {
349 setEventMessages($object->error, $object->errors, 'errors');
350 } else {
351 if ($mode != '_tmp') {
352 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
353 }
354 $action = '';
355 }
356 }
357
358 if ($action == 'setdocref' && $permissiontoadd) {
359 $refdoc = GETPOST('doc_ref', 'alpha');
360 $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
361 if ($result < 0) {
362 setEventMessages($object->error, $object->errors, 'errors');
363 } else {
364 if ($mode != '_tmp') {
365 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
366 }
367 $action = '';
368 }
369 }
370
371 if ($action == 'setref' && $permissiontoadd && $numRefModel === 'mod_bookkeeping_neon') {
372 $newref = GETPOST('ref', 'alpha');
373 if (dol_strlen($newref) > 30) { // Size of field ref in database
374 $result = -1;
375 $object->error = $langs->trans("ErrorFieldTooLong", $langs->transnoentitiesnoconv("Ref"));
376 $object->errors = array();
377 } else {
378 $result = $object->updateByMvt($piece_num, 'ref', $newref, $mode);
379 }
380 if ($result < 0) {
381 setEventMessages($object->error, $object->errors, 'errors');
382 } else {
383 if ($mode != '_tmp') {
384 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
385 }
386 $action = '';
387 }
388 }
389
390 // Validate transaction
391 if ($action == 'valid' && $permissiontoadd) {
392 $result = $object->transformTransaction(0, $piece_num);
393 if ($result < 0) {
394 setEventMessages($object->error, $object->errors, 'errors');
395 } else {
396 header("Location: " . $backtopage . "?sortfield=t.piece_num&sortorder=asc" . ($type ? '&type='.$type : ''));
397 exit;
398 }
399 }
400
401 // Delete all lines into the transaction
402 $toselect_str = explode(',', GETPOST('toselect', 'alphanohtml'));
403 $toselect = array();
404 foreach ($toselect_str as $i) {
405 $toselect[] = (int) $i;
406 }
407
408 if ($action == 'deletebookkeepingwriting' && $confirm == "yes" && $permissiontodelete) {
409 $db->begin();
410
411 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
412 $lettering = new Lettering($db);
413 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
414 if ($nb_lettering < 0) {
415 setEventMessages('', $lettering->errors, 'errors');
416 $error++;
417 }
418 }
419
420 $nbok = 0;
421 $result = 0;
422 if (!$error) {
423 foreach ($toselect as $toselectid) {
424 $result = $object->fetch($toselectid);
425 if ($result >= 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
426 $result = $object->deleteMvtNum($object->piece_num);
427 if ($result >= 0) {
428 $nbok += $result;
429 } else {
430 setEventMessages($object->error, $object->errors, 'errors');
431 $error++;
432 break;
433 }
434 } elseif ($result < 0) {
435 setEventMessages($object->error, $object->errors, 'errors');
436 $error++;
437 break;
438 } elseif (isset($object->date_validation) && $object->date_validation != '') {
439 setEventMessages($langs->trans("ValidatedRecordWhereFound"), null, 'errors');
440 $error++;
441 break;
442 }
443 }
444 }
445
446 if (!$error) {
447 $db->commit();
448
449 // Message for elements well deleted
450 if ($nbok > 1) {
451 setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
452 } elseif ($nbok > 0) {
453 setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
454 } else {
455 setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
456 }
457
458 header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?noreset=1');
459 exit;
460 } else {
461 $db->rollback();
462 }
463 }
464
465 if ($action == 'clonebookkeepingwriting' && $confirm == "yes" && $permissiontoadd) {
466 // Reread the values sent by the validated form
467 $piece_num = GETPOST('piece_num', 'alpha');
468 $journal_code = GETPOST('code_journal', 'alpha');
469
470 // Reconstruct the selected date
471 $clonedate = dol_mktime(0, 0, 0, GETPOSTINT('clonedatemonth'), GETPOSTINT('clonedateday'), GETPOSTINT('clonedateyear'));
472
473 $result = $object->newClone($piece_num, $journal_code, $clonedate);
474
475 if ($result == -1) {
476 $error++;
477 }
478
479 if (!$error) {
480 $db->commit();
481 header("Location: " . $_SERVER['PHP_SELF'] . "?piece_num=" . ($object->getNextNumMvt() - 1));
482 exit();
483 } else {
484 $db->rollback();
485 }
486 }
487}
488
489
490
491/*
492 * View
493 */
494
495$form = new Form($db);
496$formaccounting = new FormAccounting($db);
497
498$title = $langs->trans("CreateMvts");
499$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double';
500
501llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-consultation page-card');
502
503// Confirmation to delete the command
504if ($action == 'delete') {
505 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1);
506 print $formconfirm;
507}
508
509// Update fields properties in realtime
510if (!empty($conf->use_javascript_ajax)) {
511 print "\n" . '<script type="text/javascript">';
512 print '$(document).ready(function () {
513 function toggleSubledger() {
514 var isCentral = $("#accountingaccount_number option:selected").data("centralized");
515 console.log("the selected general ledger account is centralised?", isCentral);
516 if (isCentral) {
517 $("#subledger_account, #subledger_label").prop("disabled", false);
518 } else {
519 $("#subledger_account, #subledger_label").prop("disabled", true);
520 }
521 }
522
523 toggleSubledger();
524
525 $("#accountingaccount_number").on("change", toggleSubledger);
526 $("#accountingaccount_number").on("select2:select", toggleSubledger);
527 ';
528 print ' });' . "\n";
529 print ' </script>' . "\n";
530}
531
532if ($action == 'create') {
533 print load_fiche_titre($title);
534
535 $object = new BookKeeping($db);
536 $next_num_mvt = $object->getNextNumMvt('_tmp');
537
538 if (empty($next_num_mvt)) {
539 dol_print_error(null, 'Failed to get next piece number');
540 }
541
542 print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
543 if ($optioncss != '') {
544 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
545 }
546 print '<input type="hidden" name="token" value="'.newToken().'">';
547 print '<input type="hidden" name="action" value="confirm_create">'."\n";
548 print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
549 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
550 print '<input type="hidden" name="type" value="'.$type.'">';
551 print '<input type="hidden" name="mode" value="_tmp">'."\n";
552
553 print dol_get_fiche_head();
554
555 print '<table class="border centpercent">';
556
557 print '<tr>';
558 print '<td class="fieldrequired">'.$langs->trans("Docdate").'</td>';
559 print '<td>';
560 print $form->selectDate('', 'doc_date', 0, 0, 0, "create_mvt", 1, 1);
561 print '</td>';
562 print '</tr>';
563
564 print '<tr>';
565 print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
566 print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
567 print '</tr>';
568
569 print '<tr>';
570 print '<td class="fieldrequired">'.$form->textwithpicto($langs->trans("Piece"), $langs->trans("PieceDesc")).'</td>';
571 print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
572 print '</tr>';
573
574 // Piece number
575 print '<tr>';
576 print '<td>'.$form->textwithpicto($langs->trans("Ref"), $langs->trans("BankTransactionRef")).'</td>';
577 print '<td>';
578 if ($numRefModel === 'mod_bookkeeping_neon') {
579 print '<input type="text" class="minwidth200" name="ref" maxlength="30" value="">';
580 } else {
581 print '<span class="opacitymedium">'.$langs->trans("Automatic").'</span>';
582 }
583 print '</td>';
584 print '</tr>';
585
586 /*
587 print '<tr>';
588 print '<td>' . $langs->trans("Doctype") . '</td>';
589 print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>';
590 print '</tr>';
591 */
592 $reshookAddLine = $hookmanager->executeHooks('bookkeepingAddLine', $parameters, $object, $action);
593
594 print '</table>';
595
596 print dol_get_fiche_end();
597
598 print $form->buttonsSaveCancel("Create");
599
600 print '</form>';
601} else {
602 $object = new BookKeeping($db);
603
604 $result = $object->fetchPerMvt($piece_num, $mode);
605 if ($result < 0) {
606 setEventMessages($object->error, $object->errors, 'errors');
607 }
608
609 if (!empty($object->piece_num)) {
610 $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
611
612 /*if ($mode == '_tmp') {
613 print load_fiche_titre($langs->trans("CreateMvts"), $backlink);
614 } else {
615 print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
616 }*/
617
618 $head = accounting_transaction_prepare_head($object, $mode, $type, $backtopage);
619
620 print dol_get_fiche_head($head, 'transaction', '', -1);
621
622 //$object->label = $object->doc_ref;
623 if ($mode == '_tmp') {
624 $object->context['mode'] = $mode;
625 $object->next_prev_filter = '1=0'; // Add a test always false to disable navigation into the dol_banner_tab. In tmp mode, we just want to create/edit lines of bank transaction.
626 }
627 $object->label = $object->ref;
628
629 $morehtmlref = '<div style="clear: both;"></div>';
630 $morehtmlref .= '<div class="refidno opacitymedium">';
631 $morehtmlref .= $object->label;
632 $morehtmlref .= '</div>';
633
634 dol_banner_tab($object, 'ref', $backlink, 1, 'piece_num', 'piece_num', $morehtmlref);
635
636
637 if ($action == 'clonebookkeepingwriting' && $confirm != 'yes' && $permissiontoadd) {
638 $piece_num = GETPOST('piece_num', 'alpha');
639 $formaccounting = new FormAccounting($db);
640
641 $form = new Form($db);
642 $input1 = $form->selectDate('', 'clonedate', 0, 0, 0, "", 1, 1);
643 $input2 = $formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1);
644
645 $formquestion = array(
646 array(
647 'type' => 'other',
648 'name' => 'clonedate',
649 'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>',
650 'value' => $input1
651 )
652 );
653
654 $formquestion[] = array('type' => 'hidden', 'name' => 'piece_num', 'value' => $piece_num);
655
656 if (getDolGlobalString('ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL')) {
657 $formquestion[] = array(
658 'type' => 'text',
659 'name' => 'code_journal',
660 'label' => '<span class="fieldrequired">' . $langs->trans("Codejournal") . '</span>',
661 'value' => $input2
662 );
663 }
664
665 print $form->formconfirm(
666 $_SERVER["PHP_SELF"],
667 $langs->trans("ConfirmMassCloneBookkeepingWriting"),
668 $langs->trans("ConfirmMassCloneBookkeepingWritingQuestion", 1),
669 "clonebookkeepingwriting",
670 $formquestion,
671 '', 0, 300, 1000, 0
672 );
673 }
674
675
676 print '<div class="fichecenter">';
677
678 print '<div class="fichehalfleft">';
679
680 print '<div class="underbanner clearboth"></div>';
681 print '<table class="border tableforfield centpercent">';
682
683 // Account movement
684 /*
685 print '<tr>';
686 print '<td class="titlefieldmiddle">'.$langs->trans("NumMvts").'</td>';
687 print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
688 print '</tr>';
689 */
690
691 // Account movement ref. Edit allowed only for free ref num model.
692 print '<tr><td class="titlefieldmiddle">';
693 print '<table class="nobordernopadding centpercent"><tr><td>';
694 print $langs->trans('Ref');
695 print '</td>';
696 if ($action != 'editref' && empty($object->date_validation)) {
697 print '<td class="right">';
698 if ($permissiontoadd && $numRefModel === 'mod_bookkeeping_neon') {
699 print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editref&token='.newToken().'&piece_num='.((int) $object->piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a>';
700 }
701 print '</td>';
702 }
703 print '</tr></table>';
704 print '</td><td>';
705 if ($action == 'editref' && empty($object->date_validation)) {
706 print '<form name="setref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
707 if ($optioncss != '') {
708 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
709 }
710 print '<input type="hidden" name="token" value="'.newToken().'">';
711 print '<input type="hidden" name="action" value="setref">';
712 print '<input type="hidden" name="mode" value="'.$mode.'">';
713 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
714 print '<input type="hidden" name="type" value="'.$type.'">';
715 print '<input type="text" size="20" name="ref" maxlength="30" value="'.dol_escape_htmltag($object->ref).'">';
716 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
717 print '</form>';
718 } else {
719 print $object->ref;
720 }
721 print '</td>';
722 print '</tr>';
723
724 // Ref document
725 print '<tr><td>';
726 print '<table class="nobordernopadding centpercent"><tr><td>';
727 print $form->textwithpicto($langs->trans('Piece'), $langs->trans('PieceDesc'));
728 print '</td>';
729 if ($action != 'editdocref') {
730 print '<td class="right">';
731 if ($permissiontoadd && empty($object->date_validation)) {
732 print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdocref&token='.newToken().'&piece_num='.((int) $object->piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a>';
733 }
734 print '</td>';
735 }
736 print '</tr></table>';
737 print '</td><td>';
738 if ($action == 'editdocref' && empty($object->date_validation)) {
739 print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
740 if ($optioncss != '') {
741 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
742 }
743 print '<input type="hidden" name="token" value="'.newToken().'">';
744 print '<input type="hidden" name="action" value="setdocref">';
745 print '<input type="hidden" name="mode" value="'.$mode.'">';
746 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
747 print '<input type="hidden" name="type" value="'.$type.'">';
748 print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
749 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
750 print '</form>';
751 } else {
752 print $object->doc_ref;
753 }
754 print '</td>';
755 print '</tr>';
756
757 // Date
758 print '<tr><td>';
759 print '<table class="nobordernopadding centpercent"><tr><td>';
760 print $langs->trans('Docdate');
761 print '</td>';
762 if ($action != 'editdate') {
763 print '<td class="right">';
764 if ($permissiontoadd && empty($object->date_validation)) {
765 print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdate&token='.newToken().'&piece_num='.((int) $object->piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('SetDate'), 1).'</a>';
766 }
767 print '</td>';
768 }
769 print '</tr></table>';
770 print '</td><td colspan="3">';
771 if ($action == 'editdate' && empty($object->date_validation)) {
772 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
773 if ($optioncss != '') {
774 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
775 }
776 print '<input type="hidden" name="token" value="'.newToken().'">';
777 print '<input type="hidden" name="action" value="setdate">';
778 print '<input type="hidden" name="mode" value="'.$mode.'">';
779 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
780 print '<input type="hidden" name="type" value="'.$type.'">';
781 print $form->selectDate($object->doc_date ? $object->doc_date : -1, 'doc_date', 0, 0, 0, "setdate");
782 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
783 print '</form>';
784 } else {
785 print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
786 }
787 print '</td>';
788 print '</tr>';
789
790 // Journal
791 print '<tr><td>';
792 print '<table class="nobordernopadding centpercent"><tr><td>';
793 print $langs->trans('Codejournal');
794 print '</td>';
795 if ($action != 'editjournal') {
796 print '<td class="right">';
797 if ($permissiontoadd && empty($object->date_validation)) {
798 print '<a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editjournal&token='.newToken().'&piece_num='.((int) $object->piece_num).'&mode='.urlencode((string) $mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a>';
799 }
800 print '</td>';
801 }
802 print '</tr></table>';
803 print '</td><td>';
804 if ($action == 'editjournal' && empty($object->date_validation)) {
805 print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
806 if ($optioncss != '') {
807 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
808 }
809 print '<input type="hidden" name="token" value="'.newToken().'">';
810 print '<input type="hidden" name="action" value="setjournal">';
811 print '<input type="hidden" name="mode" value="'.$mode.'">';
812 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
813 print '<input type="hidden" name="type" value="'.$type.'">';
814 print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, 0, 1, '');
815 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
816 print '</form>';
817 } else {
818 print $object->code_journal;
819 }
820 print '</td>';
821 print '</tr>';
822
823 print '</table>';
824
825 print '</div>';
826
827
828 print '<div class="fichehalfright">';
829
830 print '<div class="underbanner clearboth"></div>';
831 print '<table class="border tableforfield centpercent">';
832
833 // Doc type
834 if (!empty($object->doc_type)) {
835 print '<tr>';
836 print '<td class="titlefield">'.$langs->trans("Doctype").'</td>';
837 print '<td>'.$object->doc_type.'</td>';
838 print '</tr>';
839 }
840
841 // Date document creation
842 print '<tr>';
843 print '<td class="titlefield">'.$langs->trans("DateCreation").'</td>';
844 print '<td>';
845 print $object->date_creation ? dol_print_date($object->date_creation, 'day') : '&nbsp;';
846 print '</td>';
847 print '</tr>';
848
849 // Due date (if invoice)
850 //if (in_array($object->doc_type, array('customer_invoice', 'supplier_invoice'))) {
851 print '<tr>';
852 print '<td class="titlefield">' . $form->textwithpicto($langs->trans('DateDue'), $langs->trans("IfTransactionHasDueDate")) . '</td>';
853 print '<td>';
854 print $object->date_lim_reglement ? dol_print_date($object->date_lim_reglement, 'day') : '&nbsp;';
855 print '</td>';
856 print '</tr>';
857 //}
858
859 // Don't show in tmp mode, inevitably empty
860 if ($mode != "_tmp") {
861 // Date document export
862 print '<tr>';
863 print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>';
864 print '<td>';
865 print $object->date_export ? img_picto($langs->trans("TransactionExportDesc"), 'fa-file-export', 'class="pictofixedwidth opacitymedium"').dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
866 print '</td>';
867 print '</tr>';
868
869 // Date document validation
870 print '<tr>';
871 print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>';
872 print '<td>';
873 print $object->date_validation ? img_picto($langs->trans("TransactionBlockedLockedDesc"), 'fa-lock', 'class="pictofixedwidth opacitymedium"').dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
874 print '</td>';
875 print '</tr>';
876
877 // Id_import
878 if (!empty($object->import_key)) {
879 print '<tr>';
880 print '<td class="titlefield">' . $langs->trans("ImportId") . '</td>';
881 print '<td>';
882 print $object->import_key;
883 print '</td>';
884 print '</tr>';
885 }
886 }
887
888 // Validate
889 /*
890 print '<tr>';
891 print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
892 print '<td>';
893 if (empty($object->validated)) {
894 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">';
895 print img_picto($langs->trans("Disabled"), 'switch_off');
896 print '</a>';
897 } else {
898 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">';
899 print img_picto($langs->trans("Activated"), 'switch_on');
900 print '</a>';
901 }
902 print '</td>';
903 print '</tr>';
904 */
905
906 // check data
907 /*
908 print '<tr>';
909 print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
910 if ($object->doc_type == 'customer_invoice')
911 {
912 $sqlmid = 'SELECT rowid as ref';
913 $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
914 $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
915 dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
916 $resultmid = $db->query($sqlmid);
917 if ($resultmid) {
918 $objmid = $db->fetch_object($resultmid);
919 $invoicestatic = new Facture($db);
920 $invoicestatic->fetch($objmid->ref);
921 $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
922 }
923 else dol_print_error($db);
924 }
925 print '<td>' . $ref .'</td>';
926 print '</tr>';
927 */
928 print "</table>\n";
929
930 print '</div>';
931
932 print '</div>';
933 print '<div class="clearboth"></div>';
934
935
936 print dol_get_fiche_end();
937
938
939 $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
940
941 if ($result < 0) {
942 setEventMessages($object->error, $object->errors, 'errors');
943 } else {
944 // Variable that contains all transaction lines
945 $tmptoselect = array();
946 $atleastonevalidated = 0;
947 $atleastoneexported = 0;
948 foreach ($object->linesmvt as $line) {
949 $tmptoselect[] = $line->id;
950 if (!empty($line->date_validation)) {
951 $atleastonevalidated = 1;
952 }
953 if (!empty($line->date_export) || !empty($line->date_validation)) {
954 $atleastoneexported = 1;
955 }
956 }
957
958 if ($mode != '_tmp' && !$atleastonevalidated) {
959 print "\n".'<div class="tabsAction">'."\n";
960
961 $parameters = array();
962 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
963 if (empty($reshook)) {
964 if ($permissiontodelete) {
965 if (!isset($hookmanager->resArray['no_button_edit']) || $hookmanager->resArray['no_button_edit'] != 1) {
966 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=deletebookkeepingwriting&confirm=yes&token='.newToken().'&piece_num='.((int) $object->piece_num).'&toselect='.implode(',', $tmptoselect), '', $permissiontodelete);
967 }
968 }
969 if ($permissiontoadd) {
970 print dolGetButtonAction('', $langs->trans('Clone'), 'clone', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=clonebookkeepingwriting&token=' . newToken() . '&piece_num=' . ((int) $object->piece_num) . '&toselect=' . implode(',', $tmptoselect), 'action-clone', $permissiontoadd);
971 }
972 }
973
974 print '</div>';
975 }
976
977 // List of movements
978 print load_fiche_titre($langs->trans("ListeMvts"), '', '');
979
980 if (empty($object->date_validation)) {
981 print '<form action="' . $_SERVER["PHP_SELF"] . '?piece_num=' . ((int) $object->piece_num) . '" method="POST">';
982 if ($optioncss != '') {
983 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
984 }
985 print '<input type="hidden" name="token" value="' . newToken() . '">';
986 print '<input type="hidden" name="doc_date" value="' . $object->doc_date . '">' . "\n";
987 print '<input type="hidden" name="doc_type" value="' . $object->doc_type . '">' . "\n";
988 print '<input type="hidden" name="doc_ref" value="' . $object->doc_ref . '">' . "\n";
989 print '<input type="hidden" name="ref" value="' . $object->ref . '">' . "\n";
990 print '<input type="hidden" name="code_journal" value="' . $object->code_journal . '">' . "\n";
991 print '<input type="hidden" name="fk_doc" value="' . $object->fk_doc . '">' . "\n";
992 print '<input type="hidden" name="fk_docdet" value="' . $object->fk_docdet . '">' . "\n";
993 print '<input type="hidden" name="mode" value="' . $mode . '">' . "\n";
994 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
995 print '<input type="hidden" name="type" value="' . $type . '">';
996 }
997
998 if (count($object->linesmvt) > 0) {
999 print '<div class="div-table-responsive-no-min">';
1000 print '<table class="noborder centpercent">';
1001
1002 $total_debit = 0;
1003 $total_credit = 0;
1004
1005 print '<tr class="liste_titre">';
1006
1007 print_liste_field_titre("AccountAccountingShort");
1008 print_liste_field_titre("SubledgerAccount");
1009 print_liste_field_titre("LabelOperation");
1010 print_liste_field_titre("AccountingDebit", "", "", "", "", 'class="right"');
1011 print_liste_field_titre("AccountingCredit", "", "", "", "", 'class="right"');
1012 if (empty($object->date_validation)) {
1013 print_liste_field_titre("Action", "", "", "", "", 'width="60"', "", "", 'center ');
1014 } else {
1016 }
1017
1018 print "</tr>\n";
1019
1020 // Add an empty line if there is not yet
1021 if (!empty($object->linesmvt[0]) && empty($object->date_validation)) {
1022 $tmpline = $object->linesmvt[0];
1023 if (!empty($tmpline->numero_compte)) {
1024 $line = new BookKeepingLine($db);
1025 $object->linesmvt[] = $line;
1026 }
1027 }
1028
1029 foreach ($object->linesmvt as $line) {
1030 $total_debit += $line->debit;
1031 $total_credit += $line->credit;
1032
1033 if ($action == 'update' && $line->id == $id && empty($object->date_validation)) {
1034 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
1035 print '<!-- td columns in edit mode -->';
1036 print '<td>';
1037 print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
1038 print '</td>';
1039 print '<td>';
1040 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
1041 // - It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
1042 // - Also, it is not possible to use a value that is not in the list.
1043 // - Also, the label is not automatically filled when a value is selected.
1044 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
1045 print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
1046 } else {
1047 print '<input type="text" class="maxwidth150" name="subledger_account" value="'.(GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccount")).'">';
1048 }
1049 // Add also input for subledger label
1050 print '<br><input type="text" class="maxwidth150" name="subledger_label" id="subledger_label" value="'.(GETPOSTISSET("subledger_label") ? GETPOST("subledger_label", "alpha") : $line->subledger_label).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccountLabel")).'">';
1051 print '</td>';
1052 print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
1053 print '<td class="right"><input type="text" class="right width50" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
1054 print '<td class="right"><input type="text" class="right width50" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
1055 print '<td>';
1056 print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
1057 print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
1058 print '</td>';
1059 print "</tr>\n";
1060 } elseif ((empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) && empty($object->date_validation)) {
1061 if (($action == "" || $action == 'add') && $permissiontoadd) {
1062 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
1063 print '<!-- td columns in add mode -->';
1064 print '<td>';
1065 print $formaccounting->select_account($action == 'add' ? GETPOST('accountingaccount_number') : '', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
1066 print '</td>';
1067 print '<td>';
1068 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
1069 // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
1070 // Also, it is not possible to use a value that is not in the list.
1071 // Also, the label is not automatically filled when a value is selected.
1072 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
1073 print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
1074 } else {
1075 print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">';
1076 }
1077 print '<br><input type="text" class="maxwidth150" name="subledger_label" id="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
1078 print '</td>';
1079 print '<td><input type="text" class="minwidth200" name="label_operation" value="' . dol_escape_htmltag($label_operation) . '"/></td>';
1080 print '<td class="right"><input type="text" class="right width50" name="debit" value=""/></td>';
1081 print '<td class="right"><input type="text" class="right width50" name="credit" value=""/></td>';
1082 print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>';
1083 print "</tr>\n";
1084 }
1085 } else {
1086 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
1087 print '<!-- td columns in display mode -->';
1088 $resultfetch = $accountingaccount->fetch(0, $line->numero_compte, true);
1089 print '<td>';
1090 if ($resultfetch > 0) {
1091 print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
1092 } else {
1093 print dol_escape_htmltag($line->numero_compte).' <span class="warning">('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')</span>';
1094 }
1095 print '</td>';
1096 print '<td>'.length_accounta($line->subledger_account);
1097 if ($line->subledger_label) {
1098 print ' - <span class="opacitymedium">'.dol_escape_htmltag($line->subledger_label).'</span>';
1099 }
1100 print '</td>';
1101 print '<td>'.$line->label_operation.'</td>';
1102 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
1103 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
1104
1105 print '<td class="center nowraponall">';
1106 if ($permissiontoadd) {
1107 if (empty($line->date_export) && empty($line->date_validation)) {
1108 print '<a class="editfielda reposition" href="' . $_SERVER["PHP_SELF"] . '?action=update&id=' . $line->id . '&piece_num=' . ((int) $line->piece_num) . '&mode=' . urlencode((string) $mode) . '&token=' . urlencode(newToken()) . '">';
1109 print img_edit('', 0, 'class="marginrightonly"');
1110 print '</a> &nbsp;';
1111 } else {
1112 print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
1113 print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"');
1114 print '</a> &nbsp;';
1115 }
1116
1117 if (empty($line->date_validation)) {
1118 $actiontodelete = 'delete';
1119 if ($mode == '_tmp' || $action != 'delmouv') {
1120 $actiontodelete = 'confirm_delete';
1121 }
1122
1123 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . ((int) $line->piece_num) . '&mode=' . urlencode((string) $mode) . '&token=' . urlencode(newToken()) . '">';
1124 print img_delete();
1125 print '</a>';
1126 } else {
1127 print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
1128 print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated"));
1129 print '</a>';
1130 }
1131 }
1132 print '</td>';
1133 print "</tr>\n";
1134 }
1135 }
1136
1137 $total_debit = price2num($total_debit, 'MT');
1138 $total_credit = price2num($total_credit, 'MT');
1139
1140 if ($total_debit != $total_credit) {
1141 setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
1142 }
1143
1144 print '</table>';
1145 print '</div>';
1146
1147 if ($mode == '_tmp' && $action == '' && $permissiontoadd) {
1148 print '<br>';
1149 print '<div class="center">';
1150 if (empty($total_debit) && empty($total_credit)) {
1151 print '<a class="button disabled cursornotallowed" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("EnterNonEmptyLinesFirst")).'">'.dol_escape_htmltag($langs->trans("ValidTransaction")).'</a>';
1152 } elseif ($total_debit == $total_credit) {
1153 print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).(!empty($type) ? '&type=sub' : '').'&backtopage='.urlencode($backtopage).'&action=valid&token='.newToken().'">'.$langs->trans("ValidTransaction").'</a>';
1154 } else {
1155 print '<a class="button disabled cursornotallowed" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $total_debit, $total_credit)).'">'.dol_escape_htmltag($langs->trans("ValidTransaction")).'</a>';
1156 }
1157
1158 print ' &nbsp; ';
1159 print '<a class="button button-cancel" href="'.$backtopage.(!empty($type) ? '?type=sub' : '').'">'.$langs->trans("Cancel").'</a>';
1160
1161 print "</div>";
1162 }
1163 }
1164
1165 print '</form>';
1166 }
1167 } else {
1168 print $langs->trans("NoRecordFound");
1169 }
1170}
1171
1172print dol_get_fiche_end();
1173
1174// End of page
1175llxFooter();
1176$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
accounting_transaction_prepare_head(BookKeeping $object, $mode='', $type='', $backtopage='/accountancy/bookkeeping/listbyaccount.php')
Prepare array with list of tabs for accounting transaction.
checkGeneralAccountAllowsAuxiliary($db, $general_account, $auxiliary_account, $general_account_id=0)
Check if a general accounting account allows the use of an auxiliary account.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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.
Definition wrapper.php:73
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class BookKeepingLine.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
Class Lettering.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.
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_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.