dolibarr 21.0.3
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
3 * Copyright (C) 2013-2017 Florian Henry <florian.henry@open-concept.pro>
4 * Copyright (C) 2013-2024 Alexandre Spangaro <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';
38require_once DOL_DOCUMENT_ROOT.'/accountancy/class/lettering.class.php';
39
48// Load translation files required by the page
49$langs->loadLangs(array("accountancy", "bills", "compta"));
50
51$action = GETPOST('action', 'aZ09');
52$cancel = GETPOST('cancel', 'aZ09');
53$confirm = GETPOST('confirm', 'alpha');
54
55$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
56
57$id = GETPOSTINT('id'); // id of record
58$mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
59$piece_num = GETPOSTINT("piece_num") ? GETPOSTINT("piece_num") : GETPOST('ref'); // id of transaction (several lines share the same transaction id)
60
61$accountingaccount = new AccountingAccount($db);
62$accountingjournal = new AccountingJournal($db);
63
64$accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml');
65$accountingaccount->fetch(0, $accountingaccount_number, true);
66$accountingaccount_label = $accountingaccount->label;
67
68$journal_code = GETPOST('code_journal', 'alpha');
69$accountingjournal->fetch(0, $journal_code);
70$journal_label = $accountingjournal->label;
71
72$subledger_account = GETPOST('subledger_account', 'alphanohtml');
73if ($subledger_account == -1) {
74 $subledger_account = null;
75}
76$subledger_label = GETPOST('subledger_label', 'alphanohtml');
77
78$label_operation = GETPOST('label_operation', 'alphanohtml');
79$debit = (float) price2num(GETPOST('debit', 'alpha'));
80$credit = (float) price2num(GETPOST('credit', 'alpha'));
81
82$save = GETPOST('save', 'alpha');
83if (!empty($save)) {
84 $action = 'add';
85}
86$update = GETPOST('update', 'alpha');
87if (!empty($update)) {
88 $action = 'confirm_update';
89}
90
91// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
92$hookmanager->initHooks(array('bookkeepingcard', 'globalcard'));
93
94$object = new BookKeeping($db);
95
96// Security check
97if (!isModEnabled('accounting')) {
99}
100if ($user->socid > 0) {
102}
103if (!$user->hasRight('accounting', 'mouvements', 'lire')) {
105}
106
107$permissiontoadd = $user->hasRight('accounting', 'mouvements', 'creer');
108$permissiontodelete = $user->hasRight('accounting', 'mouvements', 'supprimer');
109
110
111/*
112 * Actions
113 */
114
115$parameters = array();
116$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
117if ($reshook < 0) {
118 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
119}
120if (empty($reshook)) {
121 $error = 0;
122
123 if ($cancel) {
124 header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php');
125 exit;
126 }
127
128 if ($action == "confirm_update" && $permissiontoadd) {
129 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
130 $error++;
131 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
132 $action = 'update';
133 }
134 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
135 $error++;
136 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
137 $action = 'update';
138 }
139
140 if (!$error) {
141 $object = new BookKeeping($db);
142
143 $result = $object->fetch($id, null, $mode);
144 if ($result < 0) {
145 $error++;
146 setEventMessages($object->error, $object->errors, 'errors');
147 } else {
148 $object->numero_compte = $accountingaccount_number;
149 $object->subledger_account = $subledger_account;
150 $object->subledger_label = $subledger_label;
151 $object->label_compte = $accountingaccount_label;
152 $object->label_operation = $label_operation;
153 $object->debit = $debit;
154 $object->credit = $credit;
155
156 if ((float) $debit != 0.0) {
157 $object->montant = $debit; // deprecated
158 $object->amount = $debit;
159 $object->sens = 'D';
160 }
161 if ((float) $credit != 0.0) {
162 $object->montant = $credit; // deprecated
163 $object->amount = $credit;
164 $object->sens = 'C';
165 }
166
167 $result = $object->update($user, false, $mode);
168 if ($result < 0) {
169 setEventMessages($object->error, $object->errors, 'errors');
170 } else {
171 if ($mode != '_tmp') {
172 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
173 }
174
175 $debit = 0;
176 $credit = 0;
177
178 $action = '';
179 }
180 }
181 }
182 } elseif ($action == "add" && $permissiontoadd) {
183 if (((float) $debit != 0.0) && ((float) $credit != 0.0)) {
184 $error++;
185 setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
186 $action = '';
187 }
188 if (empty($accountingaccount_number) || $accountingaccount_number == '-1') {
189 $error++;
190 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
191 $action = '';
192 }
193
194 if (!$error) {
195 if (GETPOSTINT('doc_datemonth') && GETPOSTINT('doc_dateday') && GETPOSTINT('doc_dateyear')) {
196 $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
197 } else {
198 $datedoc = (int) GETPOSTINT('doc_date'); // TODO Use instead the mode day-month-year
199 }
200
201 $object = new BookKeeping($db);
202
203 $object->numero_compte = $accountingaccount_number;
204 $object->subledger_account = $subledger_account;
205 $object->subledger_label = $subledger_label;
206 $object->label_compte = $accountingaccount_label;
207 $object->label_operation = $label_operation;
208 $object->debit = $debit;
209 $object->credit = $credit;
210 $object->doc_date = $datedoc;
211 $object->doc_type = (string) GETPOST('doc_type', 'alpha');
212 $object->piece_num = $piece_num;
213 $object->doc_ref = (string) GETPOST('doc_ref', 'alpha');
214 $object->code_journal = $journal_code;
215 $object->journal_label = $journal_label;
216 $object->fk_doc = GETPOSTINT('fk_doc');
217 $object->fk_docdet = GETPOSTINT('fk_docdet');
218
219 if ((float) $debit != 0.0) {
220 $object->montant = $debit; // deprecated
221 $object->amount = $debit;
222 $object->sens = 'D';
223 }
224
225 if ((float) $credit != 0.0) {
226 $object->montant = $credit; // deprecated
227 $object->amount = $credit;
228 $object->sens = 'C';
229 }
230
231 $result = $object->createStd($user, false, $mode);
232
233 if ($result < 0) {
234 setEventMessages($object->error, $object->errors, 'errors');
235 } else {
236 if ($mode != '_tmp') {
237 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
238 }
239
240 $debit = 0;
241 $credit = 0;
242
243 $action = '';
244 }
245 }
246 } elseif ($action == "confirm_delete" && $permissiontoadd) { // Delete line
247 $object = new BookKeeping($db);
248
249 $result = $object->fetch($id, null, $mode);
250 $piece_num = (int) $object->piece_num;
251 if ($result < 0) {
252 setEventMessages($object->error, $object->errors, 'errors');
253
254 $action = 'create';
255 } elseif ($result > 0) {
256 $result = $object->delete($user, 0, $mode);
257 if ($result < 0) {
258 setEventMessages($object->error, $object->errors, 'errors');
259 }
260 }
261 $action = '';
262 } elseif ($action == "confirm_create" && $permissiontoadd) {
263 $object = new BookKeeping($db);
264
265 if (!$journal_code || $journal_code == '-1') {
266 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
267 $action = 'create';
268 $error++;
269 }
270 if (!GETPOST('doc_ref', 'alpha')) {
271 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
272 $action = 'create';
273 $error++;
274 }
275
276 if (!$error) {
277 $date_start = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
278
279 $object->label_compte = '';
280 $object->debit = 0;
281 $object->credit = 0;
282 $object->doc_date = $date_start;
283 $object->doc_type = GETPOST('doc_type', 'alpha');
284 $object->piece_num = GETPOSTINT('next_num_mvt');
285 $object->doc_ref = GETPOST('doc_ref', 'alpha');
286 $object->code_journal = $journal_code;
287 $object->journal_label = $journal_label;
288 $object->fk_doc = 0;
289 $object->fk_docdet = 0;
290 $object->montant = 0; // deprecated
291 $object->amount = 0;
292
293 $result = $object->createStd($user, 0, $mode);
294
295 if ($result < 0) {
296 setEventMessages($object->error, $object->errors, 'errors');
297
298 $action = 'create';
299 } else {
300 $reshook = $hookmanager->executeHooks('afterCreateBookkeeping', $parameters, $object, $action);
301
302 if ($mode != '_tmp') {
303 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
304 }
305 $action = '';
306 $id = $object->id;
307 $piece_num = (int) $object->piece_num;
308 }
309 }
310 }
311
312 if ($action == 'setdate' && $permissiontoadd) {
313 $datedoc = dol_mktime(0, 0, 0, GETPOSTINT('doc_datemonth'), GETPOSTINT('doc_dateday'), GETPOSTINT('doc_dateyear'));
314 $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode);
315 if ($result < 0) {
316 setEventMessages($object->error, $object->errors, 'errors');
317 } else {
318 if ($mode != '_tmp') {
319 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
320 }
321 $action = '';
322 }
323 }
324
325 if ($action == 'setjournal' && $permissiontoadd) {
326 $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode);
327 $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode);
328 if ($result < 0) {
329 setEventMessages($object->error, $object->errors, 'errors');
330 } else {
331 if ($mode != '_tmp') {
332 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
333 }
334 $action = '';
335 }
336 }
337
338 if ($action == 'setdocref' && $permissiontoadd) {
339 $refdoc = GETPOST('doc_ref', 'alpha');
340 $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
341 if ($result < 0) {
342 setEventMessages($object->error, $object->errors, 'errors');
343 } else {
344 if ($mode != '_tmp') {
345 setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
346 }
347 $action = '';
348 }
349 }
350
351 // Validate transaction
352 if ($action == 'valid' && $permissiontoadd) {
353 $result = $object->transformTransaction(0, $piece_num);
354 if ($result < 0) {
355 setEventMessages($object->error, $object->errors, 'errors');
356 } else {
357 header("Location: list.php?sortfield=t.piece_num&sortorder=asc");
358 exit;
359 }
360 }
361
362 // Delete all lines into the transaction
363 $toselect = explode(',', GETPOST('toselect', 'alphanohtml'));
364
365 if ($action == 'deletebookkeepingwriting' && $confirm == "yes" && $permissiontodelete) {
366 $db->begin();
367
368 if (getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING')) {
369 $lettering = new Lettering($db);
370 $nb_lettering = $lettering->bookkeepingLetteringAll($toselect, true);
371 if ($nb_lettering < 0) {
372 setEventMessages('', $lettering->errors, 'errors');
373 $error++;
374 }
375 }
376
377 $nbok = 0;
378 $result = 0;
379 if (!$error) {
380 foreach ($toselect as $toselectid) {
381 $result = $object->fetch($toselectid);
382 if ($result >= 0 && (!isset($object->date_validation) || $object->date_validation === '')) {
383 $result = $object->deleteMvtNum($object->piece_num);
384 if ($result >= 0) {
385 $nbok += $result;
386 } else {
387 setEventMessages($object->error, $object->errors, 'errors');
388 $error++;
389 break;
390 }
391 } elseif ($result < 0) {
392 setEventMessages($object->error, $object->errors, 'errors');
393 $error++;
394 break;
395 } elseif (isset($object->date_validation) && $object->date_validation != '') {
396 setEventMessages($langs->trans("ValidatedRecordWhereFound"), null, 'errors');
397 $error++;
398 break;
399 }
400 }
401 }
402
403 if (!$error) {
404 $db->commit();
405
406 // Message for elements well deleted
407 if ($nbok > 1) {
408 setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs');
409 } elseif ($nbok > 0) {
410 setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs');
411 } else {
412 setEventMessages($langs->trans("NoRecordDeleted"), null, 'mesgs');
413 }
414
415 header("Location: ".DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?noreset=1');
416 exit;
417 } else {
418 $db->rollback();
419 }
420 }
421}
422
423
424
425/*
426 * View
427 */
428
429$form = new Form($db);
430$formaccounting = new FormAccounting($db);
431
432$title = $langs->trans("CreateMvts");
433$help_url = 'EN:Module_Double_Entry_Accounting|FR:Module_Comptabilit&eacute;_en_Partie_Double';
434
435llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-accountancy accountancy-consultation page-card');
436
437// Confirmation to delete the command
438if ($action == 'delete') {
439 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1);
440 print $formconfirm;
441}
442
443if ($action == 'create') {
444 print load_fiche_titre($title);
445
446 $object = new BookKeeping($db);
447 $next_num_mvt = $object->getNextNumMvt('_tmp');
448
449 if (empty($next_num_mvt)) {
450 dol_print_error(null, 'Failed to get next piece number');
451 }
452
453 print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
454 if ($optioncss != '') {
455 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
456 }
457 print '<input type="hidden" name="token" value="'.newToken().'">';
458 print '<input type="hidden" name="action" value="confirm_create">'."\n";
459 print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
460 print '<input type="hidden" name="mode" value="_tmp">'."\n";
461
462 print dol_get_fiche_head();
463
464 print '<table class="border centpercent">';
465
466 /*print '<tr>';
467 print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
468 print '<td>' . $next_num_mvt . '</td>';
469 print '</tr>';*/
470
471 print '<tr>';
472 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>';
473 print '<td>';
474 print $form->selectDate('', 'doc_date', 0, 0, 0, "create_mvt", 1, 1);
475 print '</td>';
476 print '</tr>';
477
478 print '<tr>';
479 print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
480 print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
481 print '</tr>';
482
483 print '<tr>';
484 print '<td class="fieldrequired">'.$langs->trans("Piece").'</td>';
485 print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
486 print '</tr>';
487
488 /*
489 print '<tr>';
490 print '<td>' . $langs->trans("Doctype") . '</td>';
491 print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>';
492 print '</tr>';
493 */
494 $reshookAddLine = $hookmanager->executeHooks('bookkeepingAddLine', $parameters, $object, $action);
495
496 print '</table>';
497
498 print dol_get_fiche_end();
499
500 print $form->buttonsSaveCancel("Create");
501
502 print '</form>';
503} else {
504 $object = new BookKeeping($db);
505
506 $result = $object->fetchPerMvt($piece_num, $mode);
507 if ($result < 0) {
508 setEventMessages($object->error, $object->errors, 'errors');
509 }
510
511 if (!empty($object->piece_num)) {
512 $backlink = '<a href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?restore_lastsearch_values=1">'.$langs->trans('BackToList').'</a>';
513
514 /*if ($mode == '_tmp') {
515 print load_fiche_titre($langs->trans("CreateMvts"), $backlink);
516 } else {
517 print load_fiche_titre($langs->trans("UpdateMvts"), $backlink);
518 }*/
519
520 $head = array();
521 $h = 0;
522 $head[$h][0] = $_SERVER['PHP_SELF'].'?piece_num='.((int) $object->piece_num).($mode ? '&mode='.$mode : '');
523 $head[$h][1] = $langs->trans("Transaction");
524 $head[$h][2] = 'transaction';
525 $h++;
526
527 print dol_get_fiche_head($head, 'transaction', '', -1);
528
529 $object->ref = (string) $object->piece_num;
530 $object->label = $object->doc_ref;
531
532 $morehtmlref = '<div style="clear: both;"></div>';
533 $morehtmlref .= '<div class="refidno opacitymedium">';
534 $morehtmlref .= $object->label;
535 $morehtmlref .= '</div>';
536
537 dol_banner_tab($object, 'ref', $backlink, 1, 'piece_num', 'piece_num', $morehtmlref);
538
539 print '<div class="fichecenter">';
540
541 print '<div class="fichehalfleft">';
542
543 print '<div class="underbanner clearboth"></div>';
544 print '<table class="border tableforfield centpercent">';
545
546 // Account movement
547 print '<tr>';
548 print '<td class="titlefield">'.$langs->trans("NumMvts").'</td>';
549 print '<td>'.($mode == '_tmp' ? '<span class="opacitymedium" title="Id tmp '.$object->piece_num.'">'.$langs->trans("Draft").'</span>' : $object->piece_num).'</td>';
550 print '</tr>';
551
552 // Ref document
553 print '<tr><td>';
554 print '<table class="nobordernopadding centpercent"><tr><td>';
555 print $langs->trans('Piece');
556 print '</td>';
557 if ($action != 'editdocref') {
558 print '<td class="right">';
559 if ($permissiontoadd) {
560 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>';
561 }
562 print '</td>';
563 }
564 print '</tr></table>';
565 print '</td><td>';
566 if ($action == 'editdocref') {
567 print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
568 if ($optioncss != '') {
569 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
570 }
571 print '<input type="hidden" name="token" value="'.newToken().'">';
572 print '<input type="hidden" name="action" value="setdocref">';
573 print '<input type="hidden" name="mode" value="'.$mode.'">';
574 print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
575 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
576 print '</form>';
577 } else {
578 print $object->doc_ref;
579 }
580 print '</td>';
581 print '</tr>';
582
583 // Date
584 print '<tr><td>';
585 print '<table class="nobordernopadding centpercent"><tr><td>';
586 print $langs->trans('Docdate');
587 print '</td>';
588 if ($action != 'editdate') {
589 print '<td class="right">';
590 if ($permissiontoadd) {
591 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>';
592 }
593 print '</td>';
594 }
595 print '</tr></table>';
596 print '</td><td colspan="3">';
597 if ($action == 'editdate') {
598 print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
599 if ($optioncss != '') {
600 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
601 }
602 print '<input type="hidden" name="token" value="'.newToken().'">';
603 print '<input type="hidden" name="action" value="setdate">';
604 print '<input type="hidden" name="mode" value="'.$mode.'">';
605 print $form->selectDate($object->doc_date ? $object->doc_date : -1, 'doc_date', 0, 0, 0, "setdate");
606 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
607 print '</form>';
608 } else {
609 print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
610 }
611 print '</td>';
612 print '</tr>';
613
614 // Journal
615 print '<tr><td>';
616 print '<table class="nobordernopadding" width="100%"><tr><td>';
617 print $langs->trans('Codejournal');
618 print '</td>';
619 if ($action != 'editjournal') {
620 print '<td class="right">';
621 if ($permissiontoadd) {
622 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>';
623 }
624 print '</td>';
625 }
626 print '</tr></table>';
627 print '</td><td>';
628 if ($action == 'editjournal') {
629 print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
630 if ($optioncss != '') {
631 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
632 }
633 print '<input type="hidden" name="token" value="'.newToken().'">';
634 print '<input type="hidden" name="action" value="setjournal">';
635 print '<input type="hidden" name="mode" value="'.$mode.'">';
636 print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, 0, 1, 1);
637 print '<input type="submit" class="button button-edit" value="'.$langs->trans('Modify').'">';
638 print '</form>';
639 } else {
640 print $object->code_journal;
641 }
642 print '</td>';
643 print '</tr>';
644
645 print '</table>';
646
647 print '</div>';
648
649
650 print '<div class="fichehalfright">';
651
652 print '<div class="underbanner clearboth"></div>';
653 print '<table class="border tableforfield centpercent">';
654
655 // Doc type
656 if (!empty($object->doc_type)) {
657 print '<tr>';
658 print '<td class="titlefield">'.$langs->trans("Doctype").'</td>';
659 print '<td>'.$object->doc_type.'</td>';
660 print '</tr>';
661 }
662
663 // Date document creation
664 print '<tr>';
665 print '<td class="titlefield">'.$langs->trans("DateCreation").'</td>';
666 print '<td>';
667 print $object->date_creation ? dol_print_date($object->date_creation, 'day') : '&nbsp;';
668 print '</td>';
669 print '</tr>';
670
671 // Due date (if invoice)
672 //if (in_array($object->doc_type, array('customer_invoice', 'supplier_invoice'))) {
673 print '<tr>';
674 print '<td class="titlefield">' . $form->textwithpicto($langs->trans('DateDue'), $langs->trans("IfTransactionHasDueDate")) . '</td>';
675 print '<td>';
676 print $object->date_lim_reglement ? dol_print_date($object->date_lim_reglement, 'day') : '&nbsp;';
677 print '</td>';
678 print '</tr>';
679 //}
680
681 // Don't show in tmp mode, inevitably empty
682 if ($mode != "_tmp") {
683 // Date document export
684 print '<tr>';
685 print '<td class="titlefield">' . $langs->trans("DateExport") . '</td>';
686 print '<td>';
687 print $object->date_export ? dol_print_date($object->date_export, 'dayhour') : '&nbsp;';
688 print '</td>';
689 print '</tr>';
690
691 // Date document validation
692 print '<tr>';
693 print '<td class="titlefield">' . $langs->trans("DateValidation") . '</td>';
694 print '<td>';
695 print $object->date_validation ? dol_print_date($object->date_validation, 'dayhour') : '&nbsp;';
696 print '</td>';
697 print '</tr>';
698
699 // Id_import
700 if (!empty($object->import_key)) {
701 print '<tr>';
702 print '<td class="titlefield">' . $langs->trans("ImportId") . '</td>';
703 print '<td>';
704 print $object->import_key;
705 print '</td>';
706 print '</tr>';
707 }
708 }
709
710 // Validate
711 /*
712 print '<tr>';
713 print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
714 print '<td>';
715 if (empty($object->validated)) {
716 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable&token='.newToken().'">';
717 print img_picto($langs->trans("Disabled"), 'switch_off');
718 print '</a>';
719 } else {
720 print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable&token='.newToken().'">';
721 print img_picto($langs->trans("Activated"), 'switch_on');
722 print '</a>';
723 }
724 print '</td>';
725 print '</tr>';
726 */
727
728 // check data
729 /*
730 print '<tr>';
731 print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
732 if ($object->doc_type == 'customer_invoice')
733 {
734 $sqlmid = 'SELECT rowid as ref';
735 $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
736 $sqlmid .= " WHERE fac.rowid=" . ((int) $object->fk_doc);
737 dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
738 $resultmid = $db->query($sqlmid);
739 if ($resultmid) {
740 $objmid = $db->fetch_object($resultmid);
741 $invoicestatic = new Facture($db);
742 $invoicestatic->fetch($objmid->ref);
743 $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
744 }
745 else dol_print_error($db);
746 }
747 print '<td>' . $ref .'</td>';
748 print '</tr>';
749 */
750 print "</table>\n";
751
752 print '</div>';
753
754 print '</div>';
755 print '<div class="clearboth"></div>';
756
757
758 print dol_get_fiche_end();
759
760
761 $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
762
763 if ($result < 0) {
764 setEventMessages($object->error, $object->errors, 'errors');
765 } else {
766 // Variable that contains all transaction lines
767 $tmptoselect = array();
768 $atleastonevalidated = 0;
769 $atleastoneexported = 0;
770 foreach ($object->linesmvt as $line) {
771 $tmptoselect[] = $line->id;
772 if (!empty($line->date_validation)) {
773 $atleastonevalidated = 1;
774 }
775 if (!empty($line->date_export) || !empty($line->date_validation)) {
776 $atleastoneexported = 1;
777 }
778 }
779
780 if ($mode != '_tmp' && !$atleastonevalidated) {
781 print "\n".'<div class="tabsAction">'."\n";
782
783 $parameters = array();
784 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
785 if (empty($reshook)) {
786 if ($permissiontodelete) {
787 if (!isset($hookmanager->resArray['no_button_edit']) || $hookmanager->resArray['no_button_edit'] != 1) {
788 print dolGetButtonAction('', $langs->trans('Delete'), 'delete', DOL_URL_ROOT.'/accountancy/bookkeeping/card.php?action=deletebookkeepingwriting&confirm=yes&token='.newToken().'&piece_num='.((int) $object->piece_num).'&toselect='.implode(',', $tmptoselect), '', $permissiontodelete);
789 }
790 }
791 }
792
793 print '</div>';
794 }
795
796 // List of movements
797 print load_fiche_titre($langs->trans("ListeMvts"), '', '');
798
799 print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'" method="POST">';
800 if ($optioncss != '') {
801 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
802 }
803 print '<input type="hidden" name="token" value="'.newToken().'">';
804 print '<input type="hidden" name="doc_date" value="'.$object->doc_date.'">'."\n";
805 print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'">'."\n";
806 print '<input type="hidden" name="doc_ref" value="'.$object->doc_ref.'">'."\n";
807 print '<input type="hidden" name="code_journal" value="'.$object->code_journal.'">'."\n";
808 print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'">'."\n";
809 print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'">'."\n";
810 print '<input type="hidden" name="mode" value="'.$mode.'">'."\n";
811
812 if (count($object->linesmvt) > 0) {
813 print '<div class="div-table-responsive-no-min">';
814 print '<table class="noborder centpercent">';
815
816 $total_debit = 0;
817 $total_credit = 0;
818
819 print '<tr class="liste_titre">';
820
821 print_liste_field_titre("AccountAccountingShort");
822 print_liste_field_titre("SubledgerAccount");
823 print_liste_field_titre("LabelOperation");
824 print_liste_field_titre("AccountingDebit", "", "", "", "", 'class="right"');
825 print_liste_field_titre("AccountingCredit", "", "", "", "", 'class="right"');
826 if (empty($object->date_validation)) {
827 print_liste_field_titre("Action", "", "", "", "", 'width="60"', "", "", 'center ');
828 } else {
830 }
831
832 print "</tr>\n";
833
834 // Add an empty line if there is not yet
835 if (!empty($object->linesmvt[0])) {
836 $tmpline = $object->linesmvt[0];
837 if (!empty($tmpline->numero_compte)) {
838 $line = new BookKeepingLine($db);
839 $object->linesmvt[] = $line;
840 }
841 }
842
843 foreach ($object->linesmvt as $line) {
844 $total_debit += $line->debit;
845 $total_credit += $line->credit;
846
847 if ($action == 'update' && $line->id == $id) {
848 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
849 print '<!-- td columns in edit mode -->';
850 print '<td>';
851 print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
852 print '</td>';
853 print '<td>';
854 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
855 // - It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
856 // - Also, it is not possible to use a value that is not in the list.
857 // - Also, the label is not automatically filled when a value is selected.
858 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
859 print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
860 } else {
861 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")).'">';
862 }
863 // Add also input for subledger label
864 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")).'">';
865 print '</td>';
866 print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
867 print '<td class="right"><input type="text" class="right width50" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
868 print '<td class="right"><input type="text" class="right width50" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
869 print '<td>';
870 print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
871 print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
872 print '</td>';
873 print "</tr>\n";
874 } elseif (empty($line->numero_compte) || (empty($line->debit) && empty($line->credit))) {
875 if (($action == "" || $action == 'add') && $permissiontoadd) {
876 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
877 print '<!-- td columns in add mode -->';
878 print '<td>';
879 print $formaccounting->select_account($action == 'add' ? GETPOST('accountingaccount_number') : '', 'accountingaccount_number', 1, array(), 1, 1, 'minwidth200 maxwidth500');
880 print '</td>';
881 print '<td>';
882 // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
883 // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
884 // Also, it is not possible to use a value that is not in the list.
885 // Also, the label is not automatically filled when a value is selected.
886 if (getDolGlobalString('ACCOUNTANCY_COMBO_FOR_AUX')) {
887 print $formaccounting->select_auxaccount('', 'subledger_account', 1, 'maxwidth250', '', 'subledger_label');
888 } else {
889 print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccount")) . '">';
890 }
891 print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="' . dol_escape_htmltag($langs->trans("SubledgerAccountLabel")) . '">';
892 print '</td>';
893 print '<td><input type="text" class="minwidth200" name="label_operation" value="' . dol_escape_htmltag($label_operation) . '"/></td>';
894 print '<td class="right"><input type="text" class="right width50" name="debit" value=""/></td>';
895 print '<td class="right"><input type="text" class="right width50" name="credit" value=""/></td>';
896 print '<td class="center"><input type="submit" class="button small" name="save" value="' . $langs->trans("Add") . '"></td>';
897 print "</tr>\n";
898 }
899 } else {
900 print '<tr class="oddeven" data-lineid="'.((int) $line->id).'">';
901 print '<!-- td columns in display mode -->';
902 $resultfetch = $accountingaccount->fetch(0, $line->numero_compte, true);
903 print '<td>';
904 if ($resultfetch > 0) {
905 print $accountingaccount->getNomUrl(0, 1, 1, '', 0);
906 } else {
907 print dol_escape_htmltag($line->numero_compte).' <span class="warning">('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')</span>';
908 }
909 print '</td>';
910 print '<td>'.length_accounta($line->subledger_account);
911 if ($line->subledger_label) {
912 print ' - <span class="opacitymedium">'.dol_escape_htmltag($line->subledger_label).'</span>';
913 }
914 print '</td>';
915 print '<td>'.$line->label_operation.'</td>';
916 print '<td class="right nowraponall amount">'.($line->debit != 0 ? price($line->debit) : '').'</td>';
917 print '<td class="right nowraponall amount">'.($line->credit != 0 ? price($line->credit) : '').'</td>';
918
919 print '<td class="center nowraponall">';
920 if ($permissiontoadd) {
921 if (empty($line->date_export) && empty($line->date_validation)) {
922 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()) . '">';
923 print img_edit('', 0, 'class="marginrightonly"');
924 print '</a> &nbsp;';
925 } else {
926 print '<a class="editfielda nohover cursornotallowed reposition disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
927 print img_edit($langs->trans("ForbiddenTransactionAlreadyExported"), 0, 'class="marginrightonly"');
928 print '</a> &nbsp;';
929 }
930
931 if (empty($line->date_validation)) {
932 $actiontodelete = 'delete';
933 if ($mode == '_tmp' || $action != 'delmouv') {
934 $actiontodelete = 'confirm_delete';
935 }
936
937 print '<a href="' . $_SERVER["PHP_SELF"] . '?action=' . $actiontodelete . '&id=' . $line->id . '&piece_num=' . ((int) $line->piece_num) . '&mode=' . urlencode((string) $mode) . '&token=' . urlencode(newToken()) . '">';
938 print img_delete();
939 print '</a>';
940 } else {
941 print '<a class="editfielda nohover cursornotallowed disabled" href="#" title="'.dol_escape_htmltag($langs->trans("ForbiddenTransactionAlreadyExported")).'">';
942 print img_delete($langs->trans("ForbiddenTransactionAlreadyValidated"));
943 print '</a>';
944 }
945 }
946 print '</td>';
947 print "</tr>\n";
948 }
949 }
950
951 $total_debit = price2num($total_debit, 'MT');
952 $total_credit = price2num($total_credit, 'MT');
953
954 if ($total_debit != $total_credit) {
955 setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
956 }
957
958 print '</table>';
959 print '</div>';
960
961 if ($mode == '_tmp' && $action == '' && $permissiontoadd) {
962 print '<br>';
963 print '<div class="center">';
964 if (empty($total_debit) && empty($total_credit)) {
965 print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("EnterNonEmptyLinesFirst")).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'">';
966 } elseif ($total_debit == $total_credit) {
967 print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.((int) $object->piece_num).'&action=valid&token='.newToken().'">'.$langs->trans("ValidTransaction").'</a>';
968 } else {
969 print '<input type="submit" class="button" disabled="disabled" href="#" title="'.dol_escape_htmltag($langs->trans("MvtNotCorrectlyBalanced", $total_debit, $total_credit)).'" value="'.dol_escape_htmltag($langs->trans("ValidTransaction")).'">';
970 }
971
972 print ' &nbsp; ';
973 print '<a class="button button-cancel" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">'.$langs->trans("Cancel").'</a>';
974
975 print "</div>";
976 }
977 }
978
979 print '</form>';
980 }
981 } else {
982 print $langs->trans("NoRecordFound");
983 }
984}
985
986print dol_get_fiche_end();
987
988// End of page
989llxFooter();
990$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
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.
Class Lettering.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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.
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 a 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.