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