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