dolibarr 19.0.3
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-2024 Alexandre Spangaro <aspangaro@easya.solutions>
5 * Copyright (C) 2017 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
33require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
35require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
36require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
37
38// Load translation files required by the page
39$langs->loadLangs(array("accountancy", "bills", "compta"));
40
41$action = GETPOST('action', 'aZ09');
42$cancel = GETPOST('cancel', 'aZ09');
43
44$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
45
46$id = GETPOST('id', 'int'); // id of record
47$mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
48$piece_num = GETPOST("piece_num", 'int'); // id of transaction (several lines share the same transaction id)
49
50$accountingaccount = new AccountingAccount($db);
51$accountingjournal = new AccountingJournal($db);
52
53$accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml');
54$accountingaccount->fetch(null, $accountingaccount_number, true);
55$accountingaccount_label = $accountingaccount->label;
56
57$journal_code = GETPOST('code_journal', 'alpha');
58$accountingjournal->fetch(null, $journal_code);
59$journal_label = $accountingjournal->label;
60
61$subledger_account = GETPOST('subledger_account', 'alphanohtml');
62if ($subledger_account == -1) {
63 $subledger_account = null;
64}
65$subledger_label = GETPOST('subledger_label', 'alphanohtml');
66
67$label_operation = GETPOST('label_operation', 'alphanohtml');
68$debit = price2num(GETPOST('debit', 'alpha'));
69$credit = price2num(GETPOST('credit', 'alpha'));
70
71$save = GETPOST('save', 'alpha');
72if (!empty($save)) {
73 $action = 'add';
74}
75$update = GETPOST('update', 'alpha');
76if (!empty($update)) {
77 $action = 'confirm_update';
78}
79
80$object = new BookKeeping($db);
81
82// Security check
83if (!isModEnabled('accounting')) {
85}
86if ($user->socid > 0) {
88}
89if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
91}
92
93
94/*
95 * Actions
96 */
97
98if ($cancel) {
99 header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php');
100 exit;
101}
102
103if ($action == "confirm_update") {
104 $error = 0;
105
106 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
107 $error++;
108 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
109 $action = 'update';
110 }
111 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
112 $error++;
113 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
114 $action = 'update';
115 }
116
117 if (!$error) {
118 $object = new BookKeeping($db);
119
120 $result = $object->fetch($id, null, $mode);
121 if ($result < 0) {
122 $error++;
123 setEventMessages($object->error, $object->errors, 'errors');
124 } else {
125 $object->numero_compte = $accountingaccount_number;
126 $object->subledger_account = $subledger_account;
127 $object->subledger_label = $subledger_label;
128 $object->label_compte = $accountingaccount_label;
129 $object->label_operation = $label_operation;
130 $object->debit = $debit;
131 $object->credit = $credit;
132
133 if ((float) $debit != 0.0) {
134 $object->montant = $debit; // deprecated
135 $object->amount = $debit;
136 $object->sens = 'D';
137 }
138 if ((float) $credit != 0.0) {
139 $object->montant = $credit; // deprecated
140 $object->amount = $credit;
141 $object->sens = 'C';
142 }
143
144 $result = $object->update($user, false, $mode);
145 if ($result < 0) {
146 setEventMessages($object->error, $object->errors, 'errors');
147 } else {
148 if ($mode != '_tmp') {
149 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
150 }
151
152 $debit = 0;
153 $credit = 0;
154
155 $action = '';
156 }
157 }
158 }
159} elseif ($action == "add") {
160 $error = 0;
161
162 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
163 $error++;
164 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
165 $action = '';
166 }
167 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
168 $error++;
169 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
170 $action = '';
171 }
172
173 if (!$error) {
174 $object = new BookKeeping($db);
175
176 $object->numero_compte = $accountingaccount_number;
177 $object->subledger_account = $subledger_account;
178 $object->subledger_label = $subledger_label;
179 $object->label_compte = $accountingaccount_label;
180 $object->label_operation = $label_operation;
181 $object->debit = $debit;
182 $object->credit = $credit;
183 $object->doc_date = (string) GETPOST('doc_date', 'alpha');
184 $object->doc_type = (string) GETPOST('doc_type', 'alpha');
185 $object->piece_num = $piece_num;
186 $object->doc_ref = (string) GETPOST('doc_ref', 'alpha');
187 $object->code_journal = $journal_code;
188 $object->journal_label = $journal_label;
189 $object->fk_doc = GETPOSTINT('fk_doc');
190 $object->fk_docdet = GETPOSTINT('fk_docdet');
191
192 if ((float) $debit != 0.0) {
193 $object->montant = $debit; // deprecated
194 $object->amount = $debit;
195 $object->sens = 'D';
196 }
197
198 if ((float) $credit != 0.0) {
199 $object->montant = $credit; // deprecated
200 $object->amount = $credit;
201 $object->sens = 'C';
202 }
203
204 $result = $object->createStd($user, false, $mode);
205 if ($result < 0) {
206 setEventMessages($object->error, $object->errors, 'errors');
207
208 $action = 'create';
209 } else {
210 if ($mode != '_tmp') {
211 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
212 }
213
214 $debit = 0;
215 $credit = 0;
216
217 $action = '';
218 }
219 }
220} elseif ($action == "confirm_delete") {
221 $object = new BookKeeping($db);
222
223 $result = $object->fetch($id, null, $mode);
224 $piece_num = $object->piece_num;
225
226 if ($result < 0) {
227 setEventMessages($object->error, $object->errors, 'errors');
228 } else {
229 $result = $object->delete($user, false, $mode);
230 if ($result < 0) {
231 setEventMessages($object->error, $object->errors, 'errors');
232 }
233 }
234 $action = '';
235} elseif ($action == "confirm_create") {
236 $error = 0;
237
238 $object = new BookKeeping($db);
239
240 if (!$journal_code || $journal_code == '-1') {
241 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
242 $action = 'create';
243 $error++;
244 }
245 if (!GETPOST('doc_ref', 'alpha')) {
246 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
247 $action = 'create';
248 $error++;
249 }
250
251 if (!$error) {
252 $object->label_compte = '';
253 $object->debit = 0;
254 $object->credit = 0;
255 $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
256 $object->doc_type = GETPOST('doc_type', 'alpha');
257 $object->piece_num = GETPOST('next_num_mvt', 'alpha');
258 $object->doc_ref = GETPOST('doc_ref', 'alpha');
259 $object->code_journal = $journal_code;
260 $object->journal_label = $journal_label;
261 $object->fk_doc = 0;
262 $object->fk_docdet = 0;
263 $object->montant = 0; // deprecated
264 $object->amount = 0;
265
266 $result = $object->createStd($user, 0, $mode);
267 if ($result < 0) {
268 setEventMessages($object->error, $object->errors, 'errors');
269 } else {
270 if ($mode != '_tmp') {
271 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
272 }
273 $action = '';
274 $id = $object->id;
275 $piece_num = $object->piece_num;
276 }
277 }
278}
279
280if ($action == 'setdate') {
281 $datedoc = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
282 $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode);
283 if ($result < 0) {
284 setEventMessages($object->error, $object->errors, 'errors');
285 } else {
286 if ($mode != '_tmp') {
287 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
288 }
289 $action = '';
290 }
291}
292
293if ($action == 'setjournal') {
294 $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode);
295 $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode);
296 if ($result < 0) {
297 setEventMessages($object->error, $object->errors, 'errors');
298 } else {
299 if ($mode != '_tmp') {
300 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
301 }
302 $action = '';
303 }
304}
305
306if ($action == 'setdocref') {
307 $refdoc = GETPOST('doc_ref', 'alpha');
308 $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
309 if ($result < 0) {
310 setEventMessages($object->error, $object->errors, 'errors');
311 } else {
312 if ($mode != '_tmp') {
313 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
314 }
315 $action = '';
316 }
317}
318
319// Validate transaction
320if ($action == 'valid') {
321 $result = $object->transformTransaction(0, $piece_num);
322 if ($result < 0) {
323 setEventMessages($object->error, $object->errors, 'errors');
324 } else {
325 header("Location: list.php?sortfield=t.piece_num&sortorder=asc");
326 exit;
327 }
328}
329
330
331/*
332 * View
333 */
334
335$form = new Form($db);
336$formaccounting = new FormAccounting($db);
337
338$title = $langs->trans("CreateMvts");
339$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double';
340llxHeader('', $title, $help_url);
341
342// Confirmation to delete the command
343if ($action == 'delete') {
344 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1);
345 print $formconfirm;
346}
347
348if ($action == 'create') {
349 print load_fiche_titre($title);
350
351 $object = new BookKeeping($db);
352 $next_num_mvt = $object->getNextNumMvt('_tmp');
353
354 if (empty($next_num_mvt)) {
355 dol_print_error('', 'Failed to get next piece number');
356 }
357
358 print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
359 if ($optioncss != '') {
360 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
361 }
362 print '<input type="hidden" name="token" value="'.newToken().'">';
363 print '<input type="hidden" name="action" value="confirm_create">'."\n";
364 print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
365 print '<input type="hidden" name="mode" value="_tmp">'."\n";
366
367 print dol_get_fiche_head();
368
369 print '<table class="border centpercent">';
370
371 /*print '<tr>';
372 print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
373 print '<td>' . $next_num_mvt . '</td>';
374 print '</tr>';*/
375
376 print '<tr>';
377 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>';
378 print '<td>';
379 print $form->selectDate('', 'doc_date', '', '', '', "create_mvt", 1, 1);
380 print '</td>';
381 print '</tr>';
382
383 print '<tr>';
384 print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
385 print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
386 print '</tr>';
387
388 print '<tr>';
389 print '<td class="fieldrequired">'.$langs->trans("Piece").'</td>';
390 print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
391 print '</tr>';
392
393 /*
394 print '<tr>';
395 print '<td>' . $langs->trans("Doctype") . '</td>';
396 print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>';
397 print '</tr>';
398 */
399
400 print '</table>';
401
402 print dol_get_fiche_end();
403
404 print $form->buttonsSaveCancel("Create");
405
406 print '</form>';
407} else {
408 $object = new BookKeeping($db);
409
410 $result = $object->fetchPerMvt($piece_num, $mode);
411 if ($result < 0) {
412 setEventMessages($object->error, $object->errors, 'errors');
413 }
414
415 if (!empty($object->piece_num)) {
416 $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
417
418 if ($mode == '_tmp') {
419 print load_fiche_titre($langs->trans("CreateMvts"), $backlink);
420 } else {
421 print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
422 }
423
424 $head = array();
425 $h = 0;
426 $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$object->piece_num.($mode ? '&mode='.$mode : '');
427 $head[$h][1] = $langs->trans("Transaction");
428 $head[$h][2] = 'transaction';
429 $h++;
430
431 print dol_get_fiche_head($head, 'transaction', '', -1);
432
433 //dol_banner_tab($object, '', $backlink);
434
435 print '<div class="fichecenter">';
436 print '<div class="fichehalfleft">';
437
438 print '<div class="underbanner clearboth"></div>';
439 print '<table class="border tableforfield" width="100%">';
440
441 // Account movement
442 print '<tr>';
443 print '<td class="titlefield">'.$langs->trans("NumMvts").'</td>';
444 print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
445 print '</tr>';
446
447 // Date
448 print '<tr><td>';
449 print '<table class="nobordernopadding centpercent"><tr><td>';
450 print $langs->trans('Docdate');
451 print '</td>';
452 if ($action != 'editdate') {
453 print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdate&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('SetDate'), 1).'</a></td>';
454 }
455 print '</tr></table>';
456 print '</td><td colspan="3">';
457 if ($action == 'editdate') {
458 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
459 if ($optioncss != '') {
460 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
461 }
462 print '<input type="hidden" name="token" value="'.newToken().'">';
463 print '<input type="hidden" name="action" value="setdate">';
464 print '<input type="hidden" name="mode" value="'.$mode.'">';
465 print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', '', '', '', "setdate");
466 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
467 print '</form>';
468 } else {
469 print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
470 }
471 print '</td>';
472 print '</tr>';
473
474 // Journal
475 print '<tr><td>';
476 print '<table class="nobordernopadding" width="100%"><tr><td>';
477 print $langs->trans('Codejournal');
478 print '</td>';
479 if ($action != 'editjournal') {
480 print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editjournal&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
481 }
482 print '</tr></table>';
483 print '</td><td>';
484 if ($action == 'editjournal') {
485 print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
486 if ($optioncss != '') {
487 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
488 }
489 print '<input type="hidden" name="token" value="'.newToken().'">';
490 print '<input type="hidden" name="action" value="setjournal">';
491 print '<input type="hidden" name="mode" value="'.$mode.'">';
492 print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, array(), 1, 1);
493 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
494 print '</form>';
495 } else {
496 print $object->code_journal;
497 }
498 print '</td>';
499 print '</tr>';
500
501 // Ref document
502 print '<tr><td>';
503 print '<table class="nobordernopadding centpercent"><tr><td>';
504 print $langs->trans('Piece');
505 print '</td>';
506 if ($action != 'editdocref') {
507 print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdocref&token='.newToken().'&piece_num='.urlencode($object->piece_num).'&mode='.urlencode($mode).'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
508 }
509 print '</tr></table>';
510 print '</td><td>';
511 if ($action == 'editdocref') {
512 print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
513 if ($optioncss != '') {
514 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
515 }
516 print '<input type="hidden" name="token" value="'.newToken().'">';
517 print '<input type="hidden" name="action" value="setdocref">';
518 print '<input type="hidden" name="mode" value="'.$mode.'">';
519 print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
520 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
521 print '</form>';
522 } else {
523 print $object->doc_ref;
524 }
525 print '</td>';
526 print '</tr>';
527
528 print '</table>';
529
530 print '</div>';
531
532 print '<div class="fichehalfright">';
533
534 print '<div class="underbanner clearboth"></div>';
535 print '<table class="border tableforfield centpercent">';
536
537 // Doc type
538 if (!empty($object->doc_type)) {
539 print '<tr>';
540 print '<td class="titlefield">'.$langs->trans("Doctype").'</td>';
541 print '<td>'.$object->doc_type.'</td>';
542 print '</tr>';
543 }
544
545 // Date document creation
546 print '<tr>';
547 print '<td class="titlefield">'.$langs->trans("DateCreation").'</td>';
548 print '<td>';
549 print $object->date_creation ? dol_print_date($object->date_creation, 'day') : '&nbsp;';
550 print '</td>';
551 print '</tr>';
552
553 // Don't show in tmp mode, inevitably empty
554 if ($mode != "_tmp") {
555 // Date document export
556 print '<tr>';
557 print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>';
558 print '<td>';
559 print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
560 print '</td>';
561 print '</tr>';
562
563 // Date document validation
564 print '<tr>';
565 print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>';
566 print '<td>';
567 print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
568 print '</td>';
569 print '</tr>';
570 }
571
572 // Validate
573 /*
574 print '<tr>';
575 print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
576 print '<td>';
577 if (empty($object->validated)) {
578 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">';
579 print img_picto($langs->trans("Disabled"), 'switch_off');
580 print '</a>';
581 } else {
582 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">';
583 print img_picto($langs->trans("Activated"), 'switch_on');
584 print '</a>';
585 }
586 print '</td>';
587 print '</tr>';
588 */
589
590 // check data
591 /*
592 print '<tr>';
593 print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
594 if ($object->doc_type == 'customer_invoice')
595 {
596 $sqlmid = 'SELECT rowid as ref';
597 $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
598 $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
599 dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
600 $resultmid = $db->query($sqlmid);
601 if ($resultmid) {
602 $objmid = $db->fetch_object($resultmid);
603 $invoicestatic = new Facture($db);
604 $invoicestatic->fetch($objmid->ref);
605 $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
606 }
607 else dol_print_error($db);
608 }
609 print '<td>' . $ref .'</td>';
610 print '</tr>';
611 */
612 print "</table>\n";
613
614 print '</div>';
615
616 print dol_get_fiche_end();
617
618 print '<div class="clearboth"></div>';
619
620 print '<br>';
621
622 $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
623
624 if ($result < 0) {
625 setEventMessages($object->error, $object->errors, 'errors');
626 } else {
627 // List of movements
628 print load_fiche_titre($langs->trans("ListeMvts"), '', '');
629
630 print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
631 if ($optioncss != '') {
632 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
633 }
634 print '<input type="hidden" name="token" value="'.newToken().'">';
635 print '<input type="hidden" name="doc_date" value="'.$object->doc_date.'">'."\n";
636 print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'">'."\n";
637 print '<input type="hidden" name="doc_ref" value="'.$object->doc_ref.'">'."\n";
638 print '<input type="hidden" name="code_journal" value="'.$object->code_journal.'">'."\n";
639 print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'">'."\n";
640 print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'">'."\n";
641 print '<input type="hidden" name="mode" value="'.$mode.'">'."\n";
642
643 if (count($object->linesmvt) > 0) {
644 print '<div class="div-table-responsive-no-min">';
645 print '<table class="noborder centpercent">';
646
647 $total_debit = 0;
648 $total_credit = 0;
649
650 print '<tr class="liste_titre">';
651
652 print_liste_field_titre("AccountAccountingShort");
653 print_liste_field_titre("SubledgerAccount");
654 print_liste_field_titre("LabelOperation");
655 print_liste_field_titre("AccountingDebit", "", "", "", "", 'class="right"');
656 print_liste_field_titre("AccountingCredit", "", "", "", "", 'class="right"');
657 if (empty($object->date_validation)) {
658 print_liste_field_titre("Action", "", "", "", "", 'width="60"', "", "", 'center ');
659 } else {
661 }
662
663 print "</tr>\n";
664
665 // Add an empty line if there is not yet
666 if (!empty($object->linesmvt[0])) {
667 $tmpline = $object->linesmvt[0];
668 if (!empty($tmpline->numero_compte)) {
669 $line = new BookKeepingLine();
670 $object->linesmvt[] = $line;
671 }
672 }
673
674 foreach ($object->linesmvt as $line) {
675 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
676 $total_debit += $line->debit;
677 $total_credit += $line->credit;
678
679 if ($action == 'update' && $line->id == $id) {
680 print '<!-- td columns in edit mode -->';
681 print '<td>';
682 print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
683 print '</td>';
684 print '<td>';
685 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
686 // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
687 // Also, it is not possible to use a value that is not in the list.
688 // Also, the label is not automatically filled when a value is selected.
689 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
690 print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
691 } else {
692 print '<input type="text" class="maxwidth150" name="subledger_account" value="'.(GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccount")).'">';
693 }
694 // Add also input for subledger label
695 print '<br><input type="text" class="maxwidth150" name="subledger_label" value="'.(GETPOSTISSET("subledger_label") ? GETPOST("subledger_label", "alpha") : $line->subledger_label).'" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccountLabel")).'">';
696 print '</td>';
697 print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
698 print '<td class="right"><input type="text" size="6" class="right" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
699 print '<td class="right"><input type="text" size="6" class="right" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
700 print '<td>';
701 print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
702 print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
703 print '</td>';
704 } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) {
705 if ($action == "" || $action == 'add') {
706 print '<!-- td columns in add mode -->';
707 print '<td>';
708 print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
709 print '</td>';
710 print '<td>';
711 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
712 // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
713 // Also, it is not possible to use a value that is not in the list.
714 // Also, the label is not automatically filled when a value is selected.
715 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
716 print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
717 } else {
718 print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">';
719 }
720 print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
721 print '</td>';
722 print '<td><input type="text" class="minwidth200" name="label_operation" value="' . $label_operation . '"/></td>';
723 print '<td class="right"><input type="text" size="6" class="right" name="debit" value=""/></td>';
724 print '<td class="right"><input type="text" size="6" class="right" name="credit" value=""/></td>';
725 print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>';
726 }
727 } else {
728 print '<!-- td columns in display mode -->';
729 $resultfetch = $accountingaccount->fetch(null, $line->numero_compte, true);
730 print '<td>';
731 if ($resultfetch > 0) {
732 print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
733 } else {
734 print $line->numero_compte.' <span class="warning">('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')</span>';
735 }
736 print '</td>';
737 print '<td>'.length_accounta($line->subledger_account);
738 if ($line->subledger_label) {
739 print ' - <span class="opacitymedium">'.$line->subledger_label.'</span>';
740 }
741 print '</td>';
742 print '<td>'.$line->label_operation.'</td>';
743 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
744 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
745
746 print '<td class="center nowraponall">';
747 if (empty($line->date_export) && empty($line->date_validation)) {
748 print '<a class="editfielda reposition" href="' . $_SERVER["PHP_SELF"] . '?action=update&id=' . $line->id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode($mode) . '&token=' . urlencode(newToken()) . '">';
749 print img_edit('', 0, 'class="marginrightonly"');
750 print '</a> &nbsp;';
751 } else {
752 print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
753 print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"');
754 print '</a> &nbsp;';
755 }
756
757 if (empty($line->date_validation)) {
758 $actiontodelete = 'delete';
759 if ($mode == '_tmp' || $action != 'delmouv') {
760 $actiontodelete = 'confirm_delete';
761 }
762
763 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode($mode) . '&token=' . urlencode(newToken()) . '">';
764 print img_delete();
765 print '</a>';
766 } else {
767 print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
768 print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated"));
769 print '</a>';
770 }
771
772 print '</td>';
773 }
774 print "</tr>\n";
775 }
776
777 $total_debit = price2num($total_debit, 'MT');
778 $total_credit = price2num($total_credit, 'MT');
779
780 if ($total_debit != $total_credit) {
781 setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
782 }
783
784 print '</table>';
785 print '</div>';
786
787 if ($mode == '_tmp' && $action == '') {
788 print '<br>';
789 print '<div class="center">';
790 if ($total_debit == $total_credit) {
791 print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'&action=valid">'.$langs->trans("ValidTransaction").'</a>';
792 } else {
793 print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $debit, $credit)).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'">';
794 }
795
796 print ' &nbsp; ';
797 print '<a class="button button-cancel" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">'.$langs->trans("Cancel").'</a>';
798
799 print "</div>";
800 }
801 }
802
803 print '</form>';
804 }
805 } else {
806 print load_fiche_titre($langs->trans("NoRecords"));
807 }
808}
809
810print dol_get_fiche_end();
811
812// End of page
813llxFooter();
814$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage accounting accounts.
Class to manage accounting journals.
Class to manage Ledger (General Ledger and Subledger)
Class BookKeepingLine.
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.