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