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