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