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