dolibarr 24.0.0-beta
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-2026 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.'/expensereport/class/expensereport.class.php';
38require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
39require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
40require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
41require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeepingtemplate.class.php';
42require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeepingtemplateline.class.php';
43
52// Load translation files required by the page
53$langs->loadLangs(array("accountancy", "bills", "compta"));
54
55$action = GETPOST('action', 'aZ09');
56$cancel = GETPOST('cancel', 'alpha');
57$confirm = GETPOST('confirm', 'alpha');
58
59$type = GETPOST('type', 'alpha');
60$backtopage = GETPOST('backtopage', 'alpha');
61if (empty($backtopage)) {
62 $backtopage = DOL_URL_ROOT . '/accountancy/bookkeeping/list.php';
63}
64
65$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
66
67$id = GETPOSTINT('id'); // id of record
68$mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
69$piece_num = GETPOSTINT("piece_num") ? GETPOSTINT("piece_num") : GETPOST('ref'); // id of transaction (several lines share the same transaction id)
70$clonedate = (int) GETPOSTINT('clonedate');
71
72$accountingaccount = new AccountingAccount($db);
73$accountingjournal = new AccountingJournal($db);
74
75$accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml');
76$accountingaccount->fetch(0, $accountingaccount_number, true);
77$accountingaccount_label = $accountingaccount->label;
78
79$journal_code = GETPOST('code_journal', 'alpha');
80$accountingjournal->fetch(0, $journal_code);
81$journal_label = $accountingjournal->label;
82
83$subledger_account = GETPOST('subledger_account', 'alphanohtml');
84if ($subledger_account == -1) {
85 $subledger_account = null;
86}
87$subledger_label = GETPOST('subledger_label', 'alphanohtml');
88
89$label_operation = GETPOST('label_operation', 'alphanohtml');
90$debit = (float) price2num(GETPOST('debit', 'alpha'));
91$credit = (float) price2num(GETPOST('credit', 'alpha'));
92
93$save = GETPOST('save', 'alpha');
94if (!empty($save)) {
95 $action = 'add';
96}
97$update = GETPOST('update', 'alpha');
98if (!empty($update)) {
99 $action = 'confirm_update';
100}
101
102// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
103$hookmanager->initHooks(array('bookkeepingcard', 'globalcard'));
104
105$object = new BookKeeping($db);
106
107// Security check
108if (!isModEnabled('accounting')) {
110}
111if ($user->socid > 0) {
113}
114if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
116}
117
118$permissiontoadd = $user->hasRight('accounting', 'mouvements', 'creer');
119$permissiontodelete = $user->hasRight('accounting', 'mouvements', 'supprimer');
120$numRefModel = getDolGlobalString('BOOKKEEPING_ADDON', 'mod_bookkeeping_neon');
121
122/*
123 * Actions
124 */
125
126$parameters = array();
127$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
128if ($reshook < 0) {
129 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
130}
131if (empty($reshook)) {
132 $error = 0;
133
134 if ($cancel) {
135 header("Location: ". $backtopage . (!empty($type) ? '?type=sub' : ''));
136 exit;
137 }
138
139 if ($action == "confirm_update" && $permissiontoadd) {
140 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
141 $error++;
142 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
143 $action = 'update';
144 }
145 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
146 $error++;
147 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
148 $action = 'update';
149 }
150
151 if (!$error) {
152 $object = new BookKeeping($db);
153
154 $result = $object->fetch($id, null, $mode);
155 if ($result < 0) {
156 $error++;
157 setEventMessages($object->error, $object->errors, 'errors');
158 } else {
159 $object->numero_compte = $accountingaccount_number;
160 $object->subledger_account = $subledger_account;
161 $object->subledger_label = $subledger_label;
162 $object->label_compte = $accountingaccount_label;
163 $object->label_operation = $label_operation;
164 $object->debit = $debit;
165 $object->credit = $credit;
166
167 if ((float) $debit != 0.0) {
168 $object->montant = $debit; // deprecated
169 $object->amount = $debit;
170 $object->sens = 'D';
171 }
172 if ((float) $credit != 0.0) {
173 $object->montant = $credit; // deprecated
174 $object->amount = $credit;
175 $object->sens = 'C';
176 }
177
178 $result = $object->update($user, 0, $mode);
179 if ($result < 0) {
180 setEventMessages($object->error, $object->errors, 'errors');
181 } else {
182 if ($mode != '_tmp') {
183 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
184 }
185
186 $debit = 0;
187 $credit = 0;
188
189 $action = '';
190 }
191 }
192 }
193 } elseif ($action == "add" && $permissiontoadd) {
194 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
195 $error++;
196 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
197 $action = '';
198 }
199 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
200 $error++;
201 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
202 $action = '';
203 }
204 $subledger_account_str = is_array($subledger_account) ? reset($subledger_account) : (string) $subledger_account;
205 if (!checkGeneralAccountAllowsAuxiliary($db, $accountingaccount_number, $subledger_account_str)) {
206 $error++;
207 setEventMessages($langs->trans("ErrorAccountNotCentralized"). ". " . $langs->trans("RemoveSubsidiaryAccountOrAdjustTheGeneralAccount"), null, 'errors');
208 }
209
210 if (!$error) {
211 if (GETPOSTINT('doc_datemonth') && GETPOSTINT('doc_dateday') && GETPOSTINT('doc_dateyear')) {
212 $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
213 } else {
214 $datedoc = (int) GETPOSTINT('doc_date'); // TODO Use instead the mode day-month-year
215 }
216
217 $object = new BookKeeping($db);
218
219 $object->numero_compte = $accountingaccount_number;
220 $object->subledger_account = $subledger_account;
221 $object->subledger_label = $subledger_label;
222 $object->label_compte = $accountingaccount_label;
223 $object->label_operation = $label_operation;
224 $object->debit = $debit;
225 $object->credit = $credit;
226 $object->doc_date = $datedoc;
227 $object->doc_type = (string) GETPOST('doc_type', 'alpha');
228 $object->piece_num = $piece_num;
229 $object->doc_ref = (string) GETPOST('doc_ref', 'alpha');
230 $object->ref = (string) GETPOST('ref', 'alpha');
231 $object->code_journal = $journal_code;
232 $object->journal_label = $journal_label;
233 $object->fk_doc = GETPOSTINT('fk_doc');
234 $object->fk_docdet = GETPOSTINT('fk_docdet');
235
236 if ((float) $debit != 0.0) {
237 $object->montant = $debit; // deprecated
238 $object->amount = $debit;
239 $object->sens = 'D';
240 }
241
242 if ((float) $credit != 0.0) {
243 $object->montant = $credit; // deprecated
244 $object->amount = $credit;
245 $object->sens = 'C';
246 }
247
248 $result = $object->createStd($user, 0, $mode);
249
250 if ($result < 0) {
251 setEventMessages($object->error, $object->errors, 'errors');
252 } else {
253 if ($mode != '_tmp') {
254 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
255 }
256
257 $debit = 0;
258 $credit = 0;
259
260 $action = '';
261 }
262 }
263 } elseif ($action == "confirm_delete" && $permissiontoadd) { // Delete line
264 $object = new BookKeeping($db);
265
266 $result = $object->fetch($id, null, $mode);
267 $piece_num = (int) $object->piece_num;
268 if ($result < 0) {
269 setEventMessages($object->error, $object->errors, 'errors');
270
271 $action = 'create';
272 } elseif ($result > 0) {
273 $result = $object->delete($user, 0, $mode);
274 if ($result < 0) {
275 setEventMessages($object->error, $object->errors, 'errors');
276 }
277 }
278 $action = '';
279 } elseif ($action == "confirm_create" && $permissiontoadd) {
280 $object = new BookKeeping($db);
281
282 if (!$journal_code || $journal_code == '-1') {
283 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
284 $action = 'create';
285 $error++;
286 }
287 if (!GETPOST('doc_ref', 'alpha')) {
288 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
289 $action = 'create';
290 $error++;
291 }
292
293 if (!$error) {
294 $date_start = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
295
296 $object->label_compte = '';
297 $object->debit = 0;
298 $object->credit = 0;
299 $object->doc_date = $date_start;
300 $object->doc_type = GETPOST('doc_type', 'alpha');
301 $object->piece_num = GETPOSTINT('next_num_mvt');
302 $object->doc_ref = GETPOST('doc_ref', 'alpha');
303 $object->code_journal = $journal_code;
304 $object->journal_label = $journal_label;
305 $object->fk_doc = 0;
306 $object->fk_docdet = 0;
307 $object->ref = (GETPOST('ref', 'alpha') ? GETPOST('ref', 'alpha') : $object->getNextNumRef());
308 $object->montant = 0; // deprecated
309 $object->amount = 0;
310
311 $result = $object->createStd($user, 0, $mode);
312
313 if ($result < 0) {
314 setEventMessages($object->error, $object->errors, 'errors');
315
316 $action = 'create';
317 } else {
318 // Transaction created successfully
319 $piece_num = $object->piece_num;
320
321 // Check if a template was selected
322 $template_id = GETPOSTINT('template_id');
323
324 if ($template_id > 0) {
325 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeepingtemplate.class.php';
326 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeepingtemplateline.class.php';
327
328 $template = new BookkeepingTemplate($db);
329 $result_template = $template->fetch($template_id);
330
331 if ($result_template > 0 && !empty($template->lines)) {
332 $db->begin();
333 $error_template = 0;
334
335 foreach ($template->lines as $templateline) {
336 $bookkeeping = new BookKeeping($db);
337
338 // Set common fields from the form
339 $bookkeeping->doc_date = $date_start;
340 $bookkeeping->doc_type = GETPOST('doctype', 'alpha');
341 $bookkeeping->piece_num = $piece_num;
342 $bookkeeping->doc_ref = GETPOST('docref', 'alpha');
343 $bookkeeping->code_journal = $journal_code;
344 $bookkeeping->journal_label = $journal_label;
345 $bookkeeping->fk_doc = 0;
346 $bookkeeping->fk_docdet = 0;
347 $bookkeeping->ref = GETPOST('ref', 'alpha') ? GETPOST('ref', 'alpha') : $object->ref;
348
349 // Set fields from template line
350 $bookkeeping->numero_compte = $templateline->general_account;
351 $bookkeeping->label_compte = $templateline->general_label;
352 $bookkeeping->subledger_account = $templateline->subledger_account;
353 $bookkeeping->subledger_label = $templateline->subledger_label;
354 $bookkeeping->label_operation = $templateline->operation_label;
355 $bookkeeping->debit = (float) $templateline->debit;
356 $bookkeeping->credit = (float) $templateline->credit;
357
358 // Backward compatibility
359 if ((float) $bookkeeping->debit != 0.0) {
360 $bookkeeping->montant = $bookkeeping->debit;
361 $bookkeeping->amount = $bookkeeping->debit;
362 $bookkeeping->sens = 'D';
363 }
364 if ((float) $bookkeeping->credit != 0.0) {
365 $bookkeeping->montant = $bookkeeping->credit;
366 $bookkeeping->amount = $bookkeeping->credit;
367 $bookkeeping->sens = 'C';
368 }
369
370 $result_line = $bookkeeping->createStd($user, 0, '_tmp');
371
372 if ($result_line < 0) {
373 $error_template++;
374 setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
375 break;
376 }
377 }
378
379 if (!$error_template) {
380 $db->commit();
381 setEventMessages($langs->trans('TemplateLinesLoaded', count($template->lines)), null, 'mesgs');
382 } else {
383 $db->rollback();
384 }
385 }
386 }
387
388 // Redirect to the transaction
389 header("Location: ".$_SERVER["PHP_SELF"]."?piece_num=".$piece_num."&mode=_tmp");
390 exit;
391 }
392 }
393 }
394
395 if ($action == 'setdate' && $permissiontoadd) {
396 $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
397 $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode);
398 if ($result < 0) {
399 setEventMessages($object->error, $object->errors, 'errors');
400 } else {
401 if ($mode != '_tmp') {
402 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
403 }
404 $action = '';
405 }
406 }
407
408 if ($action == 'setjournal' && $permissiontoadd) {
409 $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode);
410 $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode);
411 if ($result < 0) {
412 setEventMessages($object->error, $object->errors, 'errors');
413 } else {
414 if ($mode != '_tmp') {
415 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
416 }
417 $action = '';
418 }
419 }
420
421 if ($action == 'setdocref' && $permissiontoadd) {
422 $refdoc = GETPOST('doc_ref', 'alpha');
423 $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
424 if ($result < 0) {
425 setEventMessages($object->error, $object->errors, 'errors');
426 } else {
427 if ($mode != '_tmp') {
428 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
429 }
430 $action = '';
431 }
432 }
433
434 if ($action == 'setref' && $permissiontoadd && $numRefModel === 'mod_bookkeeping_neon') {
435 $newref = GETPOST('ref', 'alpha');
436 $result = $object->updateByMvt($piece_num, 'ref', $newref, $mode);
437 if ($result < 0) {
438 setEventMessages($object->error, $object->errors, 'errors');
439 } else {
440 if ($mode != '_tmp') {
441 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
442 }
443 $action = '';
444 }
445 }
446
447 // Validate transaction
448 if ($action == 'valid' && $permissiontoadd) {
449 $result = $object->transformTransaction(0, $piece_num);
450 if ($result < 0) {
451 setEventMessages($object->error, $object->errors, 'errors');
452 } else {
453 // Retrieve the actual final part number (not the temporary number)
454 $piece_num = $object->piece_num;
455
456 $linkEntry = '<a href="'.$_SERVER["PHP_SELF"].'?piece_num='.(int) $piece_num.'">'.$langs->trans('NumMvts').': '.(int) $piece_num.'</a>';
457 setEventMessages($langs->trans('RecordSaved').' - '.$linkEntry, null, 'mesgs', '', 1);
458
459 if (getDolGlobalInt('ACCOUNTANCY_VALID_REDIRECT_TO_CARD')) {
460 // Redirection to the validated entry record
461 header("Location: ".$_SERVER["PHP_SELF"]."?piece_num=".(int) $piece_num);
462 } else {
463 // Default behavior: return on journal view
464 header("Location: ".$backtopage."?sortfield=t.piece_num&sortorder=asc".($type ? '&type='.$type : ''));
465 }
466 exit;
467 }
468 }
469
470 // Delete all lines into the transaction
471 $toselect_str = explode(',', GETPOST('toselect', 'alphanohtml'));
472 $toselect = array();
473 foreach ($toselect_str as $i) {
474 $toselect[] = (int) $i;
475 }
476
477 if ($action == 'deletebookkeepingwriting' && $confirm == "yes" && $permissiontodelete) {
478 $db->begin();
479
480 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
481 $lettering = new Lettering($db);
482 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
483 if ($nb_lettering < 0) {
484 setEventMessages('', $lettering->errors, 'errors');
485 $error++;
486 }
487 }
488
489 $nbok = 0;
490 $result = 0;
491 if (!$error) {
492 foreach ($toselect as $toselectid) {
493 $result = $object->fetch($toselectid);
494 if ($result >= 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
495 $result = $object->deleteMvtNum($object->piece_num);
496 if ($result >= 0) {
497 $nbok += $result;
498 } else {
499 setEventMessages($object->error, $object->errors, 'errors');
500 $error++;
501 break;
502 }
503 } elseif ($result < 0) {
504 setEventMessages($object->error, $object->errors, 'errors');
505 $error++;
506 break;
507 } elseif (isset($object->date_validation) && $object->date_validation != '') {
508 setEventMessages($langs->trans("ValidatedRecordWhereFound"), null, 'errors');
509 $error++;
510 break;
511 }
512 }
513 }
514
515 if (!$error) {
516 $db->commit();
517
518 // Message for elements well deleted
519 if ($nbok > 1) {
520 setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
521 } elseif ($nbok > 0) {
522 setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
523 } else {
524 setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
525 }
526
527 header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?noreset=1');
528 exit;
529 } else {
530 $db->rollback();
531 }
532 }
533
534 if ($action == 'clonebookkeepingwriting' && $confirm == "yes" && $permissiontoadd) {
535 // Reread the values sent by the validated form
536 $piece_num = GETPOST('piece_num', 'alpha');
537 $journal_code = GETPOST('code_journal', 'alpha');
538
539 // Reconstruct the selected date
540 $clonedate = dol_mktime(0, 0, 0, GETPOSTINT('clonedatemonth'), GETPOSTINT('clonedateday'), GETPOSTINT('clonedateyear'));
541
542 $result = $object->newClone($piece_num, $journal_code, $clonedate);
543
544 if ($result == -1) {
545 $error++;
546 }
547
548 if (!$error) {
549 $db->commit();
550 header("Location: " . $_SERVER['PHP_SELF'] . "?piece_num=" . ($object->getNextNumMvt() - 1));
551 exit();
552 } else {
553 $db->rollback();
554 }
555 }
556}
557
558
559
560/*
561 * View
562 */
563
564$form = new Form($db);
565$formaccounting = new FormAccounting($db);
566
567$title = $langs->trans("CreateMvts");
568$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double';
569
570llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-consultation page-card');
571
572// Confirmation to delete the command
573if ($action == 'delete') {
574 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1);
575 print $formconfirm;
576}
577
578// Update fields properties in realtime
579if (!empty($conf->use_javascript_ajax)) {
580 print "\n" . '<script type="text/javascript">';
581 print '$(document).ready(function () {
582 function toggleSubledger() {
583 var isCentral = $("#accountingaccount_number option:selected").data("centralized");
584 console.log("the selected general ledger account is centralised?", isCentral);
585
586 var isAjaxMode = $("#search_subledger_account").length > 0;
587 var $visibleSubledger = isAjaxMode
588 ? $("#search_subledger_account")
589 : $("#subledger_account");
590
591 if (isCentral) {
592 $visibleSubledger.prop("disabled", false);
593 if (!isAjaxMode) {
594 $("#subledger_account").prop("disabled", false).trigger("change");
595 }
596 $("#subledger_label").prop("disabled", false);
597 } else {
598 $visibleSubledger.prop("disabled", true).val("");
599 if (!isAjaxMode) {
600 $("#subledger_account").val("").prop("disabled", true).trigger("change");
601 } else {
602 $("#subledger_account").val("");
603 }
604 $("#subledger_label").val("").prop("disabled", true);
605 }
606 }
607
608 toggleSubledger();
609
610 $("#accountingaccount_number").on("change", toggleSubledger);
611 $("#accountingaccount_number").on("select2:select", toggleSubledger);
612 ';
613 print ' });' . "\n";
614 print ' </script>' . "\n";
615}
616
617if ($action == 'create') {
618 print load_fiche_titre($title);
619
620 $object = new BookKeeping($db);
621 $next_num_mvt = $object->getNextNumMvt('_tmp');
622
623 if (empty($next_num_mvt)) {
624 dol_print_error(null, 'Failed to get next piece number');
625 }
626
627 print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
628 if ($optioncss != '') {
629 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
630 }
631 print '<input type="hidden" name="token" value="'.newToken().'">';
632 print '<input type="hidden" name="action" value="confirm_create">'."\n";
633 print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
634 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
635 print '<input type="hidden" name="type" value="'.$type.'">';
636 print '<input type="hidden" name="mode" value="_tmp">'."\n";
637
638 print dol_get_fiche_head();
639
640 print '<table class="border centpercent">';
641
642 print '<tr>';
643 print '<td class="fieldrequired">'.$langs->trans("Docdate").'</td>';
644 print '<td>';
645 print $form->selectDate('', 'doc_date', 0, 0, 0, "create_mvt", 1, 1);
646 print '</td>';
647 print '</tr>';
648
649 print '<tr>';
650 print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
651 print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
652 print '</tr>';
653
654 print '<tr>';
655 print '<td class="fieldrequired">'.$form->textwithpicto($langs->trans("Piece"), $langs->trans("PieceDesc")).'</td>';
656 print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
657 print '</tr>';
658
659 // Piece number
660 print '<tr>';
661 print '<td>'.$form->textwithpicto($langs->trans("Ref"), $langs->trans("BankTransactionRef")).'</td>';
662 print '<td>';
663 if ($numRefModel === 'mod_bookkeeping_neon') {
664 print '<input type="text" class="minwidth200" name="ref" value="">';
665 } else {
666 print '<span class="opacitymedium">'.$langs->trans("Automatic").'</span>';
667 }
668 print '</td>';
669
670 // Template
671 print '<tr>';
672 print '<td>'.$langs->trans("BookkeepingTemplate").'</td>';
673 print '<td>';
674 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeepingtemplate.class.php';
675
676 $sql = "SELECT rowid, code, label";
677 $sql .= " FROM ".MAIN_DB_PREFIX."accounting_transaction_template";
678 $sql .= " WHERE entity IN (".getEntity('accounting').")";
679 $sql .= " ORDER BY code ASC";
680
681 $resql = $db->query($sql);
682 $templates = array();
683
684 if ($resql) {
685 $num = $db->num_rows($resql);
686 $i = 0;
687 while ($i < $num) {
688 $obj = $db->fetch_object($resql);
689 $templates[$obj->rowid] = $obj->code.' - '.$obj->label;
690 $i++;
691 }
692 $db->free($resql);
693 }
694
695 if (count($templates) > 0) {
696 print '<select class="flat minwidth300" name="template_id" id="template_id">';
697 print '<option value=""></option>';
698 foreach ($templates as $key => $label) {
699 print '<option value="'.$key.'">'.dol_escape_htmltag($label).'</option>';
700 }
701 print '</select>';
702 } else {
703 print '<span class="opacitymedium">'.$langs->trans("NoTemplateAvailable").'</span>';
704 }
705
706 print '</td>';
707 print '</tr>';
708
709 $reshookAddLine = $hookmanager->executeHooks('bookkeepingAddLine', $parameters, $object, $action);
710
711 print '</table>';
712
713 print dol_get_fiche_end();
714
715 print $form->buttonsSaveCancel("Create");
716
717 print '</form>';
718} else {
719 $object = new BookKeeping($db);
720
721 $result = $object->fetchPerMvt($piece_num, $mode);
722 if ($result < 0) {
723 setEventMessages($object->error, $object->errors, 'errors');
724 }
725
726 if (!empty($object->piece_num)) {
727 $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
728
729 /*if ($mode == '_tmp') {
730 print load_fiche_titre($langs->trans("CreateMvts"), $backlink);
731 } else {
732 print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
733 }*/
734
735 $head = accounting_transaction_prepare_head($object, $mode, $type, $backtopage);
736
737 print dol_get_fiche_head($head, 'transaction', '', -1);
738
739 //$object->label = $object->doc_ref;
740 if ($mode == '_tmp') {
741 $object->context['mode'] = $mode;
742 $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.
743 }
744 $object->label = $object->ref;
745
746 $morehtmlref = '<div style="clear: both;"></div>';
747 $morehtmlref .= '<div class="refidno opacitymedium">';
748 $morehtmlref .= $object->label;
749 $morehtmlref .= '</div>';
750
751 dol_banner_tab($object, 'ref', $backlink, 1, 'piece_num', 'piece_num', $morehtmlref);
752
753
754 if ($action == 'clonebookkeepingwriting' && $confirm != 'yes' && $permissiontoadd) {
755 $piece_num = GETPOST('piece_num', 'alpha');
756 $formaccounting = new FormAccounting($db);
757
758 $form = new Form($db);
759 $input1 = $form->selectDate('', 'clonedate', 0, 0, 0, "", 1, 1);
760 $input2 = $formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1);
761
762 $formquestion = array(
763 array(
764 'type' => 'other',
765 'name' => 'clonedate',
766 'label' => '<span class="fieldrequired">' . $langs->trans("Docdate") . '</span>',
767 'value' => $input1
768 )
769 );
770
771 $formquestion[] = array('type' => 'hidden', 'name' => 'piece_num', 'value' => $piece_num);
772
773 if (getDolGlobalString('ACCOUNTING_CLONING_ENABLE_INPUT_JOURNAL')) {
774 $formquestion[] = array(
775 'type' => 'text',
776 'name' => 'code_journal',
777 'label' => '<span class="fieldrequired">' . $langs->trans("Codejournal") . '</span>',
778 'value' => $input2
779 );
780 }
781
782 print $form->formconfirm(
783 $_SERVER["PHP_SELF"],
784 $langs->trans("ConfirmMassCloneBookkeepingWriting"),
785 $langs->trans("ConfirmMassCloneBookkeepingWritingQuestion", 1),
786 "clonebookkeepingwriting",
787 $formquestion,
788 '', 0, 300, 1000, 0
789 );
790 }
791
792
793 print '<div class="fichecenter">';
794
795 print '<div class="fichehalfleft">';
796
797 print '<div class="underbanner clearboth"></div>';
798 print '<table class="border tableforfield centpercent">';
799
800 // Account movement
801 /*
802 print '<tr>';
803 print '<td class="titlefieldmiddle">'.$langs->trans("NumMvts").'</td>';
804 print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
805 print '</tr>';
806 */
807
808 // Account movement ref. Edit allowed only for free ref num model.
809 print '<tr><td class="titlefieldmiddle">';
810 print '<table class="nobordernopadding centpercent"><tr><td>';
811 print $langs->trans('Ref');
812 print '</td>';
813 if ($action != 'editref' && empty($object->date_validation)) {
814 print '<td class="right">';
815 if ($permissiontoadd && $numRefModel === 'mod_bookkeeping_neon') {
816 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>';
817 }
818 print '</td>';
819 }
820 print '</tr></table>';
821 print '</td><td>';
822 if ($action == 'editref' && empty($object->date_validation)) {
823 print '<form name="setref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
824 if ($optioncss != '') {
825 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
826 }
827 print '<input type="hidden" name="token" value="'.newToken().'">';
828 print '<input type="hidden" name="action" value="setref">';
829 print '<input type="hidden" name="mode" value="'.$mode.'">';
830 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
831 print '<input type="hidden" name="type" value="'.$type.'">';
832 print '<input type="text" size="20" name="ref" value="'.dol_escape_htmltag($object->ref).'">';
833 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
834 print '</form>';
835 } else {
836 print $object->ref;
837 }
838 print '</td>';
839 print '</tr>';
840
841 // Ref document
842 print '<tr><td>';
843 print '<table class="nobordernopadding centpercent"><tr><td>';
844 print $form->textwithpicto($langs->trans('Piece'), $langs->trans('PieceDesc'));
845 print '</td>';
846 if ($action != 'editdocref') {
847 print '<td class="right">';
848 if ($permissiontoadd && empty($object->date_validation)) {
849 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>';
850 }
851 print '</td>';
852 }
853 print '</tr></table>';
854 print '</td><td>';
855 if ($action == 'editdocref' && empty($object->date_validation)) {
856 print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
857 if ($optioncss != '') {
858 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
859 }
860 print '<input type="hidden" name="token" value="'.newToken().'">';
861 print '<input type="hidden" name="action" value="setdocref">';
862 print '<input type="hidden" name="mode" value="'.$mode.'">';
863 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
864 print '<input type="hidden" name="type" value="'.$type.'">';
865 print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
866 print '<input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans('Modify').'">';
867 print '</form>';
868 } else {
869 // Get information of an element
870 if ($object->doc_type === 'customer_invoice' && !empty($object->fk_doc)) {
871 $invoicestatic = new Facture($db);
872 $result = $invoicestatic->fetch($object->fk_doc);
873
874 if ($result > 0) {
875 $label_element = $invoicestatic->getNomUrl(1);
876 } else {
877 $label_element = $object->doc_ref;
878 }
879 } elseif ($object->doc_type === 'supplier_invoice' && !empty($object->fk_doc)) {
880 $supplierinvoicestatic = new FactureFournisseur($db);
881 $result = $supplierinvoicestatic->fetch($object->fk_doc);
882
883 if ($result > 0) {
884 $label_element = $supplierinvoicestatic->getNomUrl(1);
885 } else {
886 $label_element = $object->doc_ref;
887 }
888 } elseif ($object->doc_type === 'expense_report' && !empty($object->fk_doc)) {
889 $expensereportstatic = new ExpenseReport($db);
890 $result = $expensereportstatic->fetch($object->fk_doc);
891
892 if ($result > 0) {
893 $label_element = $expensereportstatic->getNomUrl(1);
894 } else {
895 $label_element = $object->doc_ref;
896 }
897 } else {
898 $label_element = $object->doc_ref;
899 }
900 print $label_element;
901 }
902 print '</td>';
903 print '</tr>';
904
905 // Date
906 print '<tr><td>';
907 print '<table class="nobordernopadding centpercent"><tr><td>';
908 print $langs->trans('Docdate');
909 print '</td>';
910 if ($action != 'editdate') {
911 print '<td class="right">';
912 if ($permissiontoadd && empty($object->date_validation)) {
913 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>';
914 }
915 print '</td>';
916 }
917 print '</tr></table>';
918 print '</td><td colspan="3">';
919 if ($action == 'editdate' && empty($object->date_validation)) {
920 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
921 if ($optioncss != '') {
922 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
923 }
924 print '<input type="hidden" name="token" value="'.newToken().'">';
925 print '<input type="hidden" name="action" value="setdate">';
926 print '<input type="hidden" name="mode" value="'.$mode.'">';
927 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
928 print '<input type="hidden" name="type" value="'.$type.'">';
929 print $form->selectDate($object->doc_date ? $object->doc_date : -1, 'doc_date', 0, 0, 0, "setdate");
930 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
931 print '</form>';
932 } else {
933 print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
934 }
935 print '</td>';
936 print '</tr>';
937
938 // Journal
939 print '<tr><td>';
940 print '<table class="nobordernopadding centpercent"><tr><td>';
941 print $langs->trans('Codejournal');
942 print '</td>';
943 if ($action != 'editjournal') {
944 print '<td class="right">';
945 if ($permissiontoadd && empty($object->date_validation)) {
946 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>';
947 }
948 print '</td>';
949 }
950 print '</tr></table>';
951 print '</td><td>';
952 if ($action == 'editjournal' && empty($object->date_validation)) {
953 print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
954 if ($optioncss != '') {
955 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
956 }
957 print '<input type="hidden" name="token" value="'.newToken().'">';
958 print '<input type="hidden" name="action" value="setjournal">';
959 print '<input type="hidden" name="mode" value="'.$mode.'">';
960 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
961 print '<input type="hidden" name="type" value="'.$type.'">';
962 print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, 0, 1, '');
963 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
964 print '</form>';
965 } else {
966 // Get information of a journal
967 $accountingjournalstatic = new AccountingJournal($db);
968 $accountingjournalstatic->fetch(0, $object->code_journal);
969 $journal = $accountingjournalstatic->code;
970 $journal_label = $accountingjournalstatic->label;
971
972 print $accountingjournalstatic->getNomUrl(1, 1, 1);
973 }
974 print '</td>';
975 print '</tr>';
976
977 print '</table>';
978
979 print '</div>';
980
981
982 print '<div class="fichehalfright">';
983
984 print '<div class="underbanner clearboth"></div>';
985 print '<table class="border tableforfield centpercent">';
986
987 // Doc type
988 if (!empty($object->doc_type)) {
989 print '<tr>';
990 print '<td class="titlefield">'.$langs->trans("Doctype").'</td>';
991 print '<td>'.$object->doc_type.'</td>';
992 print '</tr>';
993 }
994
995 // Date document creation
996 print '<tr>';
997 print '<td class="titlefield">'.$langs->trans("DateCreation").'</td>';
998 print '<td>';
999 print $object->date_creation ? dol_print_date($object->date_creation, 'day') : '&nbsp;';
1000 print '</td>';
1001 print '</tr>';
1002
1003 // Due date (if invoice)
1004 //if (in_array($object->doc_type, array('customer_invoice', 'supplier_invoice'))) {
1005 print '<tr>';
1006 print '<td class="titlefield">' . $form->textwithpicto($langs->trans('DateDue'), $langs->trans("IfTransactionHasDueDate")) . '</td>';
1007 print '<td>';
1008 print $object->date_lim_reglement ? dol_print_date($object->date_lim_reglement, 'day') : '&nbsp;';
1009 print '</td>';
1010 print '</tr>';
1011 //}
1012
1013 // Don't show in tmp mode, inevitably empty
1014 if ($mode != "_tmp") {
1015 // Date document export
1016 print '<tr>';
1017 print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>';
1018 print '<td>';
1019 print $object->date_export ? img_picto($langs->trans("TransactionExportDesc"), 'fa-file-export', 'class="pictofixedwidth opacitymedium"').dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
1020 print '</td>';
1021 print '</tr>';
1022
1023 // Date document validation
1024 print '<tr>';
1025 print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>';
1026 print '<td>';
1027 print $object->date_validation ? img_picto($langs->trans("TransactionBlockedLockedDesc"), 'fa-lock', 'class="pictofixedwidth opacitymedium"').dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
1028 print '</td>';
1029 print '</tr>';
1030
1031 // Id_import
1032 if (!empty($object->import_key)) {
1033 print '<tr>';
1034 print '<td class="titlefield">' . $langs->trans("ImportId") . '</td>';
1035 print '<td>';
1036 print $object->import_key;
1037 print '</td>';
1038 print '</tr>';
1039 }
1040 }
1041
1042 // Validate
1043 /*
1044 print '<tr>';
1045 print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
1046 print '<td>';
1047 if (empty($object->validated)) {
1048 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">';
1049 print img_picto($langs->trans("Disabled"), 'switch_off');
1050 print '</a>';
1051 } else {
1052 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">';
1053 print img_picto($langs->trans("Activated"), 'switch_on');
1054 print '</a>';
1055 }
1056 print '</td>';
1057 print '</tr>';
1058 */
1059
1060 // check data
1061 /*
1062 print '<tr>';
1063 print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
1064 if ($object->doc_type == 'customer_invoice')
1065 {
1066 $sqlmid = 'SELECT rowid as ref';
1067 $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
1068 $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
1069 dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
1070 $resultmid = $db->query($sqlmid);
1071 if ($resultmid) {
1072 $objmid = $db->fetch_object($resultmid);
1073 $invoicestatic = new Facture($db);
1074 $invoicestatic->fetch($objmid->ref);
1075 $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
1076 }
1077 else dol_print_error($db);
1078 }
1079 print '<td>' . $ref .'</td>';
1080 print '</tr>';
1081 */
1082 print "</table>\n";
1083
1084 print '</div>';
1085
1086 print '</div>';
1087 print '<div class="clearboth"></div>';
1088
1089
1090 print dol_get_fiche_end();
1091
1092
1093 $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
1094
1095 if ($result < 0) {
1096 setEventMessages($object->error, $object->errors, 'errors');
1097 } else {
1098 // Variable that contains all transaction lines
1099 $tmptoselect = array();
1100 $atleastonevalidated = 0;
1101 $atleastoneexported = 0;
1102 foreach ($object->linesmvt as $line) {
1103 $tmptoselect[] = $line->id;
1104 if (!empty($line->date_validation)) {
1105 $atleastonevalidated = 1;
1106 }
1107 if (!empty($line->date_export) || !empty($line->date_validation)) {
1108 $atleastoneexported = 1;
1109 }
1110 }
1111
1112 if ($mode != '_tmp' && !$atleastonevalidated) {
1113 print "\n".'<div class="tabsAction">'."\n";
1114
1115 $parameters = array();
1116 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1117 if (empty($reshook)) {
1118 if ($permissiontodelete) {
1119 if (!isset($hookmanager->resArray['no_button_edit']) || $hookmanager->resArray['no_button_edit'] != 1) {
1120 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);
1121 }
1122 }
1123 if ($permissiontoadd) {
1124 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);
1125 }
1126 }
1127
1128 print '</div>';
1129 }
1130
1131 // List of movements
1132 print load_fiche_titre($langs->trans("ListeMvts"), '', '');
1133
1134 if (empty($object->date_validation)) {
1135 print '<form action="' . $_SERVER["PHP_SELF"] . '?piece_num=' . ((int) $object->piece_num) . '" method="POST">';
1136 if ($optioncss != '') {
1137 print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
1138 }
1139 print '<input type="hidden" name="token" value="' . newToken() . '">';
1140 print '<input type="hidden" name="doc_date" value="' . $object->doc_date . '">' . "\n";
1141 print '<input type="hidden" name="doc_type" value="' . $object->doc_type . '">' . "\n";
1142 print '<input type="hidden" name="doc_ref" value="' . $object->doc_ref . '">' . "\n";
1143 print '<input type="hidden" name="ref" value="' . $object->ref . '">' . "\n";
1144 print '<input type="hidden" name="code_journal" value="' . $object->code_journal . '">' . "\n";
1145 print '<input type="hidden" name="fk_doc" value="' . $object->fk_doc . '">' . "\n";
1146 print '<input type="hidden" name="fk_docdet" value="' . $object->fk_docdet . '">' . "\n";
1147 print '<input type="hidden" name="mode" value="' . $mode . '">' . "\n";
1148 print '<input type="hidden" name="backtopage" value="' . $backtopage . '">';
1149 print '<input type="hidden" name="type" value="' . $type . '">';
1150 }
1151
1152 if (count($object->linesmvt) > 0) {
1153 print '<div class="div-table-responsive-no-min">';
1154 print '<table class="noborder centpercent">';
1155
1156 $total_debit = 0;
1157 $total_credit = 0;
1158
1159 print '<tr class="liste_titre">';
1160
1161 print_liste_field_titre("AccountAccountingShort");
1162 print_liste_field_titre("SubledgerAccount");
1163 print_liste_field_titre("LabelOperation");
1164 print_liste_field_titre("AccountingDebit", "", "", "", "", 'class="right"');
1165 print_liste_field_titre("AccountingCredit", "", "", "", "", 'class="right"');
1166 if (empty($object->date_validation)) {
1167 print_liste_field_titre("Action", "", "", "", "", 'width="60"', "", "", 'center ');
1168 } else {
1170 }
1171
1172 print "</tr>\n";
1173
1174 // Add an empty line if there is not yet
1175 if (!empty($object->linesmvt[0]) && empty($object->date_validation)) {
1176 $tmpline = $object->linesmvt[0];
1177 if (!empty($tmpline->numero_compte)) {
1178 $line = new BookKeepingLine($db);
1179 $object->linesmvt[] = $line;
1180 }
1181 }
1182
1183 foreach ($object->linesmvt as $line) {
1184 $total_debit += $line->debit;
1185 $total_credit += $line->credit;
1186
1187 if ($action == 'update' && $line->id == $id && empty($object->date_validation)) {
1188 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
1189 print '<!-- td columns in edit mode -->';
1190 print '<td>';
1191 print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
1192 print '</td>';
1193 print '<td>';
1194 print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
1195 // Add also input for subledger label
1196 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")).'">';
1197 print '</td>';
1198 print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
1199 print '<td class="right"><input type="text" class="right width50" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
1200 print '<td class="right"><input type="text" class="right width50" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
1201 print '<td>';
1202 print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
1203 print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
1204 print '</td>';
1205 print "</tr>\n";
1206 } elseif ((empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) && empty($object->date_validation)) {
1207 if (($action == "" || $action == 'add') && $permissiontoadd) {
1208 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
1209 print '<!-- td columns in add mode -->';
1210 print '<td>';
1211 print $formaccounting->select_account($action == 'add' ? GETPOST('accountingaccount_number') : '', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
1212 print '</td>';
1213 print '<td>';
1214 print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
1215 print '<br><input type="text" class="maxwidth150" name="subledger_label" id="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
1216 print '</td>';
1217 print '<td><input type="text" class="minwidth200" name="label_operation" value="' . dol_escape_htmltag($label_operation) . '"/></td>';
1218 print '<td class="right"><input type="text" class="right width50" name="debit" value=""/></td>';
1219 print '<td class="right"><input type="text" class="right width50" name="credit" value=""/></td>';
1220 print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>';
1221 print "</tr>\n";
1222 }
1223 } else {
1224 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
1225 print '<!-- td columns in display mode -->';
1226 $resultfetch = $accountingaccount->fetch(0, $line->numero_compte, true);
1227 print '<td>';
1228 if ($resultfetch > 0) {
1229 print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
1230 } else {
1231 print dol_escape_htmltag($line->numero_compte).' <span class="warning">('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')</span>';
1232 }
1233 print '</td>';
1234 print '<td>'.length_accounta($line->subledger_account);
1235 if ($line->subledger_label) {
1236 print ' - <span class="opacitymedium">'.dol_escape_htmltag($line->subledger_label).'</span>';
1237 }
1238 print '</td>';
1239 print '<td>'.$line->label_operation.'</td>';
1240 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
1241 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
1242
1243 print '<td class="center nowraponall">';
1244 if ($permissiontoadd) {
1245 if (empty($line->date_export) && empty($line->date_validation)) {
1246 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()) . '">';
1247 print img_edit('', 0, 'class="marginrightonly"');
1248 print '</a> &nbsp;';
1249 } else {
1250 print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
1251 print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"');
1252 print '</a> &nbsp;';
1253 }
1254
1255 if (empty($line->date_validation)) {
1256 $actiontodelete = 'delete';
1257 if ($mode == '_tmp' || $action != 'delmouv') {
1258 $actiontodelete = 'confirm_delete';
1259 }
1260
1261 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . ((int) $line->piece_num) . '&mode=' . urlencode((string) $mode) . '&token=' . urlencode(newToken()) . '">';
1262 print img_delete();
1263 print '</a>';
1264 } else {
1265 print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
1266 print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated"));
1267 print '</a>';
1268 }
1269 }
1270 print '</td>';
1271 print "</tr>\n";
1272 }
1273 }
1274
1275 $total_debit = price2num($total_debit, 'MT');
1276 $total_credit = price2num($total_credit, 'MT');
1277
1278 if ($total_debit != $total_credit) {
1279 setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
1280 }
1281
1282 print '</table>';
1283 print '</div>';
1284
1285 if ($mode == '_tmp' && $action == '' && $permissiontoadd) {
1286 print '<br>';
1287 print '<div class="center">';
1288 if (empty($total_debit) && empty($total_credit)) {
1289 print '<a class="button disabled cursornotallowed" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("EnterNonEmptyLinesFirst")).'">'.dol_escape_htmltag($langs->trans("ValidTransaction")).'</a>';
1290 } elseif ($total_debit == $total_credit) {
1291 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>';
1292 } else {
1293 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>';
1294 }
1295
1296 print ' &nbsp; ';
1297 print '<a class="button button-cancel" href="'.$backtopage.(!empty($type) ? '?type=sub' : '').'">'.$langs->trans("Cancel").'</a>';
1298
1299 print "</div>";
1300 }
1301 }
1302
1303 print '</form>';
1304 }
1305 } else {
1306 print $langs->trans("NoRecordFound");
1307 }
1308}
1309
1310print dol_get_fiche_end();
1311
1312// End of page
1313llxFooter();
1314$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
$object ref
Definition info.php:90
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class BookKeepingLine.
Class for BookkeepingTemplate.
Class to manage Trips and Expenses.
Class to manage suppliers invoices.
Class to manage invoices.
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
$date_start
Variables from include:
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.
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.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.