dolibarr 21.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2017 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2013-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 // Due date
611 print '<tr>';
612 print '<td class="titlefield">' . $langs->trans('DateDue') . '</td>';
613 print '<td>';
614 print $object->date_lim_reglement ? dol_print_date($object->date_lim_reglement, 'day') : '&nbsp;';
615 print '</td>';
616 print '</tr>';
617
618 // Validate
619 /*
620 print '<tr>';
621 print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
622 print '<td>';
623 if (empty($object->validated)) {
624 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">';
625 print img_picto($langs->trans("Disabled"), 'switch_off');
626 print '</a>';
627 } else {
628 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">';
629 print img_picto($langs->trans("Activated"), 'switch_on');
630 print '</a>';
631 }
632 print '</td>';
633 print '</tr>';
634 */
635
636 // check data
637 /*
638 print '<tr>';
639 print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
640 if ($object->doc_type == 'customer_invoice')
641 {
642 $sqlmid = 'SELECT rowid as ref';
643 $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
644 $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
645 dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
646 $resultmid = $db->query($sqlmid);
647 if ($resultmid) {
648 $objmid = $db->fetch_object($resultmid);
649 $invoicestatic = new Facture($db);
650 $invoicestatic->fetch($objmid->ref);
651 $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
652 }
653 else dol_print_error($db);
654 }
655 print '<td>' . $ref .'</td>';
656 print '</tr>';
657 */
658 print "</table>\n";
659
660 print '</div>';
661
662 print dol_get_fiche_end();
663
664 print '<div class="clearboth"></div>';
665
666 print '<br>';
667
668 $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
669
670 if ($result < 0) {
671 setEventMessages($object->error, $object->errors, 'errors');
672 } else {
673 // List of movements
674 print load_fiche_titre($langs->trans("ListeMvts"), '', '');
675
676 print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="post">';
677 if ($optioncss != '') {
678 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
679 }
680 print '<input type="hidden" name="token" value="'.newToken().'">';
681 print '<input type="hidden" name="doc_date" value="'.$object->doc_date.'">'."\n";
682 print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'">'."\n";
683 print '<input type="hidden" name="doc_ref" value="'.$object->doc_ref.'">'."\n";
684 print '<input type="hidden" name="code_journal" value="'.$object->code_journal.'">'."\n";
685 print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'">'."\n";
686 print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'">'."\n";
687 print '<input type="hidden" name="mode" value="'.$mode.'">'."\n";
688
689 if (count($object->linesmvt) > 0) {
690 print '<div class="div-table-responsive-no-min">';
691 print '<table class="noborder centpercent">';
692
693 $total_debit = 0;
694 $total_credit = 0;
695
696 print '<tr class="liste_titre">';
697
698 print_liste_field_titre("AccountAccountingShort");
699 print_liste_field_titre("SubledgerAccount");
700 print_liste_field_titre("LabelOperation");
701 print_liste_field_titre("AccountingDebit", "", "", "", "", 'class="right"');
702 print_liste_field_titre("AccountingCredit", "", "", "", "", 'class="right"');
703 if (empty($object->date_validation)) {
704 print_liste_field_titre("Action", "", "", "", "", 'width="60"', "", "", 'center ');
705 } else {
707 }
708
709 print "</tr>\n";
710
711 // Add an empty line if there is not yet
712 if (!empty($object->linesmvt[0])) {
713 $tmpline = $object->linesmvt[0];
714 if (!empty($tmpline->numero_compte)) {
715 $line = new BookKeepingLine($db);
716 $object->linesmvt[] = $line;
717 }
718 }
719
720 foreach ($object->linesmvt as $line) {
721 $total_debit += $line->debit;
722 $total_credit += $line->credit;
723
724 if ($action == 'update' && $line->id == $id) {
725 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
726 print '<!-- td columns in edit mode -->';
727 print '<td>';
728 print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
729 print '</td>';
730 print '<td>';
731 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
732 // - It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
733 // - Also, it is not possible to use a value that is not in the list.
734 // - Also, the label is not automatically filled when a value is selected.
735 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
736 print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
737 } else {
738 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")).'">';
739 }
740 // Add also input for subledger label
741 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")).'">';
742 print '</td>';
743 print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
744 print '<td class="right"><input type="text" class="right width50" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
745 print '<td class="right"><input type="text" class="right width50" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
746 print '<td>';
747 print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
748 print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
749 print '</td>';
750 print "</tr>\n";
751 } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) {
752 if (($action == "" || $action == 'add') && $permissiontoadd) {
753 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
754 print '<!-- td columns in add mode -->';
755 print '<td>';
756 print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
757 print '</td>';
758 print '<td>';
759 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
760 // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
761 // Also, it is not possible to use a value that is not in the list.
762 // Also, the label is not automatically filled when a value is selected.
763 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
764 print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
765 } else {
766 print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">';
767 }
768 print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
769 print '</td>';
770 print '<td><input type="text" class="minwidth200" name="label_operation" value="' . dol_escape_htmltag($label_operation) . '"/></td>';
771 print '<td class="right"><input type="text" class="right width50" name="debit" value=""/></td>';
772 print '<td class="right"><input type="text" class="right width50" name="credit" value=""/></td>';
773 print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>';
774 print "</tr>\n";
775 }
776 } else {
777 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
778 print '<!-- td columns in display mode -->';
779 $resultfetch = $accountingaccount->fetch(null, $line->numero_compte, true);
780 print '<td>';
781 if ($resultfetch > 0) {
782 print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
783 } else {
784 print dol_escape_htmltag($line->numero_compte).' <span class="warning">('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')</span>';
785 }
786 print '</td>';
787 print '<td>'.length_accounta($line->subledger_account);
788 if ($line->subledger_label) {
789 print ' - <span class="opacitymedium">'.dol_escape_htmltag($line->subledger_label).'</span>';
790 }
791 print '</td>';
792 print '<td>'.$line->label_operation.'</td>';
793 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
794 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
795
796 print '<td class="center nowraponall">';
797 if ($permissiontoadd) {
798 if (empty($line->date_export) && empty($line->date_validation)) {
799 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()) . '">';
800 print img_edit('', 0, 'class="marginrightonly"');
801 print '</a> &nbsp;';
802 } else {
803 print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
804 print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"');
805 print '</a> &nbsp;';
806 }
807
808 if (empty($line->date_validation)) {
809 $actiontodelete = 'delete';
810 if ($mode == '_tmp' || $action != 'delmouv') {
811 $actiontodelete = 'confirm_delete';
812 }
813
814 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . ((int) $line->piece_num) . '&mode=' . urlencode((string) $mode) . '&token=' . urlencode(newToken()) . '">';
815 print img_delete();
816 print '</a>';
817 } else {
818 print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
819 print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated"));
820 print '</a>';
821 }
822 }
823 print '</td>';
824 print "</tr>\n";
825 }
826 }
827
828 $total_debit = price2num($total_debit, 'MT');
829 $total_credit = price2num($total_credit, 'MT');
830
831 if ($total_debit != $total_credit) {
832 setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
833 }
834
835 print '</table>';
836 print '</div>';
837
838 if ($mode == '_tmp' && $action == '' && $permissiontoadd) {
839 print '<br>';
840 print '<div class="center">';
841 if ($total_debit == $total_credit) {
842 print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'&action=valid">'.$langs->trans("ValidTransaction").'</a>';
843 } else {
844 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")).'">';
845 }
846
847 print ' &nbsp; ';
848 print '<a class="button button-cancel" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">'.$langs->trans("Cancel").'</a>';
849
850 print "</div>";
851 }
852 }
853
854 print '</form>';
855 }
856 } else {
857 print load_fiche_titre($langs->trans("NoRecords"));
858 }
859}
860
861print dol_get_fiche_end();
862
863// End of page
864llxFooter();
865$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
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.
llxFooter()
Footer empty.
Definition document.php:107
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).
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.