dolibarr 18.0.6
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-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 ((floatval($debit) != 0.0) && (floatval($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 (floatval($debit) != 0.0) {
134 $object->montant = $debit; // deprecated
135 $object->amount = $debit;
136 $object->sens = 'D';
137 }
138 if (floatval($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 ((floatval($debit) != 0.0) && (floatval($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 (floatval($debit) != 0.0) {
193 $object->montant = $debit; // deprecated
194 $object->amount = $debit;
195 $object->sens = 'D';
196 }
197
198 if (floatval($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 } else {
208 if ($mode != '_tmp') {
209 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
210 }
211
212 $debit = 0;
213 $credit = 0;
214
215 $action = '';
216 }
217 }
218} elseif ($action == "confirm_delete") {
219 $object = new BookKeeping($db);
220
221 $result = $object->fetch($id, null, $mode);
222 $piece_num = $object->piece_num;
223
224 if ($result < 0) {
225 setEventMessages($object->error, $object->errors, 'errors');
226 } else {
227 $result = $object->delete($user, false, $mode);
228 if ($result < 0) {
229 setEventMessages($object->error, $object->errors, 'errors');
230 }
231 }
232 $action = '';
233} elseif ($action == "confirm_create") {
234 $error = 0;
235
236 $object = new BookKeeping($db);
237
238 if (!$journal_code || $journal_code == '-1') {
239 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
240 $action = 'create';
241 $error++;
242 }
243 if (!GETPOST('doc_ref', 'alpha')) {
244 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
245 $action = 'create';
246 $error++;
247 }
248
249 if (!$error) {
250 $object->label_compte = '';
251 $object->debit = 0;
252 $object->credit = 0;
253 $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
254 $object->doc_type = GETPOST('doc_type', 'alpha');
255 $object->piece_num = GETPOST('next_num_mvt', 'alpha');
256 $object->doc_ref = GETPOST('doc_ref', 'alpha');
257 $object->code_journal = $journal_code;
258 $object->journal_label = $journal_label;
259 $object->fk_doc = 0;
260 $object->fk_docdet = 0;
261 $object->montant = 0; // deprecated
262 $object->amount = 0;
263
264 $result = $object->createStd($user, 0, $mode);
265 if ($result < 0) {
266 setEventMessages($object->error, $object->errors, 'errors');
267 } else {
268 if ($mode != '_tmp') {
269 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
270 }
271 $action = '';
272 $id = $object->id;
273 $piece_num = $object->piece_num;
274 }
275 }
276}
277
278if ($action == 'setdate') {
279 $datedoc = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
280 $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode);
281 if ($result < 0) {
282 setEventMessages($object->error, $object->errors, 'errors');
283 } else {
284 if ($mode != '_tmp') {
285 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
286 }
287 $action = '';
288 }
289}
290
291if ($action == 'setjournal') {
292 $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode);
293 $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode);
294 if ($result < 0) {
295 setEventMessages($object->error, $object->errors, 'errors');
296 } else {
297 if ($mode != '_tmp') {
298 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
299 }
300 $action = '';
301 }
302}
303
304if ($action == 'setdocref') {
305 $refdoc = GETPOST('doc_ref', 'alpha');
306 $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
307 if ($result < 0) {
308 setEventMessages($object->error, $object->errors, 'errors');
309 } else {
310 if ($mode != '_tmp') {
311 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
312 }
313 $action = '';
314 }
315}
316
317// Validate transaction
318if ($action == 'valid') {
319 $result = $object->transformTransaction(0, $piece_num);
320 if ($result < 0) {
321 setEventMessages($object->error, $object->errors, 'errors');
322 } else {
323 header("Location: list.php?sortfield=t.piece_num&sortorder=asc");
324 exit;
325 }
326}
327
328
329/*
330 * View
331 */
332
333$form = new Form($db);
334$formaccounting = new FormAccounting($db);
335
336$title = $langs->trans("CreateMvts");
337
338llxHeader('', $title);
339
340// Confirmation to delete the command
341if ($action == 'delete') {
342 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1);
343 print $formconfirm;
344}
345
346if ($action == 'create') {
347 print load_fiche_titre($title);
348
349 $object = new BookKeeping($db);
350 $next_num_mvt = $object->getNextNumMvt('_tmp');
351
352 if (empty($next_num_mvt)) {
353 dol_print_error('', 'Failed to get next piece number');
354 }
355
356 print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
357 if ($optioncss != '') {
358 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
359 }
360 print '<input type="hidden" name="token" value="'.newToken().'">';
361 print '<input type="hidden" name="action" value="confirm_create">'."\n";
362 print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
363 print '<input type="hidden" name="mode" value="_tmp">'."\n";
364
365 print dol_get_fiche_head();
366
367 print '<table class="border centpercent">';
368
369 /*print '<tr>';
370 print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
371 print '<td>' . $next_num_mvt . '</td>';
372 print '</tr>';*/
373
374 print '<tr>';
375 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>';
376 print '<td>';
377 print $form->selectDate('', 'doc_date', '', '', '', "create_mvt", 1, 1);
378 print '</td>';
379 print '</tr>';
380
381 print '<tr>';
382 print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
383 print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
384 print '</tr>';
385
386 print '<tr>';
387 print '<td class="fieldrequired">'.$langs->trans("Piece").'</td>';
388 print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
389 print '</tr>';
390
391 /*
392 print '<tr>';
393 print '<td>' . $langs->trans("Doctype") . '</td>';
394 print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>';
395 print '</tr>';
396 */
397
398 print '</table>';
399
400 print dol_get_fiche_end();
401
402 print $form->buttonsSaveCancel("Create");
403
404 print '</form>';
405} else {
406 $object = new BookKeeping($db);
407 $result = $object->fetchPerMvt($piece_num, $mode);
408 if ($result < 0) {
409 setEventMessages($object->error, $object->errors, 'errors');
410 }
411
412 if (!empty($object->piece_num)) {
413 $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
414
415 if ($mode == '_tmp') {
416 print load_fiche_titre($langs->trans("CreateMvts"), $backlink);
417 } else {
418 print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
419 }
420
421 $head = array();
422 $h = 0;
423 $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.$object->piece_num.($mode ? '&mode='.$mode : '');
424 $head[$h][1] = $langs->trans("Transaction");
425 $head[$h][2] = 'transaction';
426 $h++;
427
428 print dol_get_fiche_head($head, 'transaction', '', -1);
429
430 //dol_banner_tab($object, '', $backlink);
431
432 print '<div class="fichecenter">';
433 print '<div class="fichehalfleft">';
434
435 print '<div class="underbanner clearboth"></div>';
436 print '<table class="border tableforfield" width="100%">';
437
438 // Account movement
439 print '<tr>';
440 print '<td class="titlefield">'.$langs->trans("NumMvts").'</td>';
441 print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
442 print '</tr>';
443
444 // Date
445 print '<tr><td>';
446 print '<table class="nobordernopadding centpercent"><tr><td>';
447 print $langs->trans('Docdate');
448 print '</td>';
449 if ($action != 'editdate') {
450 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>';
451 }
452 print '</tr></table>';
453 print '</td><td colspan="3">';
454 if ($action == 'editdate') {
455 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
456 if ($optioncss != '') {
457 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
458 }
459 print '<input type="hidden" name="token" value="'.newToken().'">';
460 print '<input type="hidden" name="action" value="setdate">';
461 print '<input type="hidden" name="mode" value="'.$mode.'">';
462 print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', '', '', '', "setdate");
463 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
464 print '</form>';
465 } else {
466 print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
467 }
468 print '</td>';
469 print '</tr>';
470
471 // Journal
472 print '<tr><td>';
473 print '<table class="nobordernopadding" width="100%"><tr><td>';
474 print $langs->trans('Codejournal');
475 print '</td>';
476 if ($action != 'editjournal') {
477 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>';
478 }
479 print '</tr></table>';
480 print '</td><td>';
481 if ($action == 'editjournal') {
482 print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
483 if ($optioncss != '') {
484 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
485 }
486 print '<input type="hidden" name="token" value="'.newToken().'">';
487 print '<input type="hidden" name="action" value="setjournal">';
488 print '<input type="hidden" name="mode" value="'.$mode.'">';
489 print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, array(), 1, 1);
490 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
491 print '</form>';
492 } else {
493 print $object->code_journal;
494 }
495 print '</td>';
496 print '</tr>';
497
498 // Ref document
499 print '<tr><td>';
500 print '<table class="nobordernopadding centpercent"><tr><td>';
501 print $langs->trans('Piece');
502 print '</td>';
503 if ($action != 'editdocref') {
504 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>';
505 }
506 print '</tr></table>';
507 print '</td><td>';
508 if ($action == 'editdocref') {
509 print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
510 if ($optioncss != '') {
511 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
512 }
513 print '<input type="hidden" name="token" value="'.newToken().'">';
514 print '<input type="hidden" name="action" value="setdocref">';
515 print '<input type="hidden" name="mode" value="'.$mode.'">';
516 print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
517 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
518 print '</form>';
519 } else {
520 print $object->doc_ref;
521 }
522 print '</td>';
523 print '</tr>';
524
525 print '</table>';
526
527 print '</div>';
528
529 print '<div class="fichehalfright">';
530
531 print '<div class="underbanner clearboth"></div>';
532 print '<table class="border tableforfield centpercent">';
533
534 // Doc type
535 if (!empty($object->doc_type)) {
536 print '<tr>';
537 print '<td class="titlefield">'.$langs->trans("Doctype").'</td>';
538 print '<td>'.$object->doc_type.'</td>';
539 print '</tr>';
540 }
541
542 // Date document creation
543 print '<tr>';
544 print '<td class="titlefield">'.$langs->trans("DateCreation").'</td>';
545 print '<td>';
546 print $object->date_creation ? dol_print_date($object->date_creation, 'day') : '&nbsp;';
547 print '</td>';
548 print '</tr>';
549
550 // Don't show in tmp mode, inevitably empty
551 if ($mode != "_tmp") {
552 // Date document export
553 print '<tr>';
554 print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>';
555 print '<td>';
556 print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
557 print '</td>';
558 print '</tr>';
559
560 // Date document validation
561 print '<tr>';
562 print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>';
563 print '<td>';
564 print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
565 print '</td>';
566 print '</tr>';
567 }
568
569 // Validate
570 /*
571 print '<tr>';
572 print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
573 print '<td>';
574 if (empty($object->validated)) {
575 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">';
576 print img_picto($langs->trans("Disabled"), 'switch_off');
577 print '</a>';
578 } else {
579 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">';
580 print img_picto($langs->trans("Activated"), 'switch_on');
581 print '</a>';
582 }
583 print '</td>';
584 print '</tr>';
585 */
586
587 // check data
588 /*
589 print '<tr>';
590 print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
591 if ($object->doc_type == 'customer_invoice')
592 {
593 $sqlmid = 'SELECT rowid as ref';
594 $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
595 $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
596 dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
597 $resultmid = $db->query($sqlmid);
598 if ($resultmid) {
599 $objmid = $db->fetch_object($resultmid);
600 $invoicestatic = new Facture($db);
601 $invoicestatic->fetch($objmid->ref);
602 $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
603 }
604 else dol_print_error($db);
605 }
606 print '<td>' . $ref .'</td>';
607 print '</tr>';
608 */
609 print "</table>\n";
610
611 print '</div>';
612
613 print dol_get_fiche_end();
614
615 print '<div class="clearboth"></div>';
616
617 print '<br>';
618
619 $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
620
621 if ($result < 0) {
622 setEventMessages($object->error, $object->errors, 'errors');
623 } else {
624 // List of movements
625 print load_fiche_titre($langs->trans("ListeMvts"), '', '');
626
627 print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
628 if ($optioncss != '') {
629 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
630 }
631 print '<input type="hidden" name="token" value="'.newToken().'">';
632 print '<input type="hidden" name="doc_date" value="'.$object->doc_date.'">'."\n";
633 print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'">'."\n";
634 print '<input type="hidden" name="doc_ref" value="'.$object->doc_ref.'">'."\n";
635 print '<input type="hidden" name="code_journal" value="'.$object->code_journal.'">'."\n";
636 print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'">'."\n";
637 print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'">'."\n";
638 print '<input type="hidden" name="mode" value="'.$mode.'">'."\n";
639
640 if (count($object->linesmvt) > 0) {
641 print '<div class="div-table-responsive-no-min">';
642 print '<table class="noborder centpercent">';
643
644 $total_debit = 0;
645 $total_credit = 0;
646
647 print '<tr class="liste_titre">';
648
649 print_liste_field_titre("AccountAccountingShort");
650 print_liste_field_titre("SubledgerAccount");
651 print_liste_field_titre("LabelOperation");
652 print_liste_field_titre("AccountingDebit", "", "", "", "", 'class="right"');
653 print_liste_field_titre("AccountingCredit", "", "", "", "", 'class="right"');
654 if (empty($object->date_validation)) {
655 print_liste_field_titre("Action", "", "", "", "", 'width="60"', "", "", 'center ');
656 } else {
658 }
659
660 print "</tr>\n";
661
662 // Add an empty line if there is not yet
663 if (!empty($object->linesmvt[0])) {
664 $tmpline = $object->linesmvt[0];
665 if (!empty($tmpline->numero_compte)) {
666 $line = new BookKeepingLine();
667 $object->linesmvt[] = $line;
668 }
669 }
670
671 foreach ($object->linesmvt as $line) {
672 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
673 $total_debit += $line->debit;
674 $total_credit += $line->credit;
675
676 if ($action == 'update' && $line->id == $id) {
677 print '<!-- td columns in edit mode -->';
678 print '<td>';
679 print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
680 print '</td>';
681 print '<td>';
682 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
683 // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
684 // Also, it is not possible to use a value that is not in the list.
685 // Also, the label is not automatically filled when a value is selected.
686 if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
687 print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
688 } else {
689 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")).'">';
690 }
691 // Add also input for subledger label
692 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")).'">';
693 print '</td>';
694 print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
695 print '<td class="right"><input type="text" size="6" class="right" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
696 print '<td class="right"><input type="text" size="6" class="right" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
697 print '<td>';
698 print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
699 print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
700 print '</td>';
701 } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) {
702 if ($action == "" || $action == 'add') {
703 print '<!-- td columns in add mode -->';
704 print '<td>';
705 print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
706 print '</td>';
707 print '<td>';
708 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
709 // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
710 // Also, it is not possible to use a value that is not in the list.
711 // Also, the label is not automatically filled when a value is selected.
712 if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
713 print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
714 } else {
715 print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">';
716 }
717 print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
718 print '</td>';
719 print '<td><input type="text" class="minwidth200" name="label_operation" value="' . $label_operation . '"/></td>';
720 print '<td class="right"><input type="text" size="6" class="right" name="debit" value=""/></td>';
721 print '<td class="right"><input type="text" size="6" class="right" name="credit" value=""/></td>';
722 print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>';
723 }
724 } else {
725 print '<!-- td columns in display mode -->';
726 $resultfetch = $accountingaccount->fetch(null, $line->numero_compte, true);
727 print '<td>';
728 if ($resultfetch > 0) {
729 print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
730 } else {
731 print $line->numero_compte.' <span class="warning">('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')</span>';
732 }
733 print '</td>';
734 print '<td>'.length_accounta($line->subledger_account);
735 if ($line->subledger_label) {
736 print ' - <span class="opacitymedium">'.$line->subledger_label.'</span>';
737 }
738 print '</td>';
739 print '<td>'.$line->label_operation.'</td>';
740 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
741 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
742
743 print '<td class="center nowraponall">';
744 if (empty($line->date_export) && empty($line->date_validation)) {
745 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()) . '">';
746 print img_edit('', 0, 'class="marginrightonly"');
747 print '</a> &nbsp;';
748 } else {
749 print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
750 print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"');
751 print '</a> &nbsp;';
752 }
753
754 if (empty($line->date_validation)) {
755 $actiontodelete = 'delete';
756 if ($mode == '_tmp' || $action != 'delmouv') {
757 $actiontodelete = 'confirm_delete';
758 }
759
760 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . urlencode($line->piece_num) . '&mode=' . urlencode($mode) . '&token=' . urlencode(newToken()) . '">';
761 print img_delete();
762 print '</a>';
763 } else {
764 print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
765 print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated"));
766 print '</a>';
767 }
768
769 print '</td>';
770 }
771 print "</tr>\n";
772 }
773
774 $total_debit = price2num($total_debit, 'MT');
775 $total_credit = price2num($total_credit, 'MT');
776
777 if ($total_debit != $total_credit) {
778 setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
779 }
780
781 print '</table>';
782 print '</div>';
783
784 if ($mode == '_tmp' && $action == '') {
785 print '<br>';
786 print '<div class="center">';
787 if ($total_debit == $total_credit) {
788 print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'&action=valid">'.$langs->trans("ValidTransaction").'</a>';
789 } else {
790 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")).'">';
791 }
792
793 print ' &nbsp; ';
794 print '<a class="button button-cancel" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">'.$langs->trans("Cancel").'</a>';
795
796 print "</div>";
797 }
798 }
799
800 print '</form>';
801 }
802 } else {
803 print load_fiche_titre($langs->trans("NoRecords"));
804 }
805}
806
807print dol_get_fiche_end();
808
809// End of page
810llxFooter();
811$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage accounting accounts.
Class to manage accounting accounts.
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.
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.