dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2017 Olivier Geffroy <jeff@jeffinfo.com>
3  * Copyright (C) 2013-2017 Florian Henry <florian.henry@open-concept.pro>
4  * Copyright (C) 2013-2018 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 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
42 
43 $id = GETPOST('id', 'int'); // id of record
44 $mode = GETPOST('mode', 'aZ09'); // '' or '_tmp'
45 $piece_num = GETPOST("piece_num", 'int'); // id of transaction (several lines share the same transaction id)
46 
47 // Security check
48 if ($user->socid > 0) {
50 }
51 
52 $mesg = '';
53 
54 $accountingaccount = new AccountingAccount($db);
55 $accountingjournal = new AccountingJournal($db);
56 
57 $accountingaccount_number = GETPOST('accountingaccount_number', 'alphanohtml');
58 $accountingaccount->fetch(null, $accountingaccount_number, true);
59 $accountingaccount_label = $accountingaccount->label;
60 
61 $journal_code = GETPOST('code_journal', 'alpha');
62 $accountingjournal->fetch(null, $journal_code);
63 $journal_label = $accountingjournal->label;
64 
65 $subledger_account = GETPOST('subledger_account', 'alphanohtml');
66 if ($subledger_account == -1) {
67  $subledger_account = null;
68 }
69 $subledger_label = GETPOST('subledger_label', 'alphanohtml');
70 
71 $label_operation = GETPOST('label_operation', 'alphanohtml');
72 $debit = price2num(GETPOST('debit', 'alpha'));
73 $credit = price2num(GETPOST('credit', 'alpha'));
74 
75 $save = GETPOST('save', 'alpha');
76 if (!empty($save)) $action = 'add';
77 $update = GETPOST('update', 'alpha');
78 if (!empty($update)) $action = 'confirm_update';
79 
80 $object = new BookKeeping($db);
81 
82 
83 /*
84  * Actions
85  */
86 
87 if ($action == "confirm_update") {
88  $error = 0;
89 
90  if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) {
91  $error++;
92  setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
93  $action = 'update';
94  }
95  if (empty($accountingaccount_number) || $accountingaccount_number == '-1')
96  {
97  $error++;
98  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
99  $action = 'update';
100  }
101 
102  if (!$error)
103  {
104  $object = new BookKeeping($db);
105 
106  $result = $object->fetch($id, null, $mode);
107  if ($result < 0) {
108  $error++;
109  setEventMessages($object->error, $object->errors, 'errors');
110  } else {
111  $object->numero_compte = $accountingaccount_number;
112  $object->subledger_account = $subledger_account;
113  $object->subledger_label = $subledger_label;
114  $object->label_compte = $accountingaccount_label;
115  $object->label_operation = $label_operation;
116  $object->debit = $debit;
117  $object->credit = $credit;
118 
119  if (floatval($debit) != 0.0) {
120  $object->montant = $debit; // deprecated
121  $object->amount = $debit;
122  $object->sens = 'D';
123  }
124  if (floatval($credit) != 0.0) {
125  $object->montant = $credit; // deprecated
126  $object->amount = $credit;
127  $object->sens = 'C';
128  }
129 
130  $result = $object->update($user, false, $mode);
131  if ($result < 0) {
132  setEventMessages($object->error, $object->errors, 'errors');
133  } else {
134  if ($mode != '_tmp') {
135  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
136  }
137 
138  $debit = 0;
139  $credit = 0;
140 
141  $action = '';
142  }
143  }
144  }
145 } elseif ($action == "add") {
146  $error = 0;
147 
148  if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0))
149  {
150  $error++;
151  setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors');
152  $action = '';
153  }
154  if (empty($accountingaccount_number) || $accountingaccount_number == '-1')
155  {
156  $error++;
157  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("AccountAccountingShort")), null, 'errors');
158  $action = '';
159  }
160 
161  if (!$error) {
162  $object = new BookKeeping($db);
163 
164  $object->numero_compte = $accountingaccount_number;
165  $object->subledger_account = $subledger_account;
166  $object->subledger_label = $subledger_label;
167  $object->label_compte = $accountingaccount_label;
168  $object->label_operation = $label_operation;
169  $object->debit = $debit;
170  $object->credit = $credit;
171  $object->doc_date = (string) GETPOST('doc_date', 'alpha');
172  $object->doc_type = (string) GETPOST('doc_type', 'alpha');
173  $object->piece_num = $piece_num;
174  $object->doc_ref = (string) GETPOST('doc_ref', 'alpha');
175  $object->code_journal = $journal_code;
176  $object->journal_label = $journal_label;
177  $object->fk_doc = GETPOSTINT('fk_doc');
178  $object->fk_docdet = GETPOSTINT('fk_docdet');
179 
180  if (floatval($debit) != 0.0) {
181  $object->montant = $debit; // deprecated
182  $object->amount = $debit;
183  $object->sens = 'D';
184  }
185 
186  if (floatval($credit) != 0.0) {
187  $object->montant = $credit; // deprecated
188  $object->amount = $credit;
189  $object->sens = 'C';
190  }
191 
192  $result = $object->createStd($user, false, $mode);
193  if ($result < 0) {
194  setEventMessages($object->error, $object->errors, 'errors');
195  } else {
196  if ($mode != '_tmp') {
197  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
198  }
199 
200  $debit = 0;
201  $credit = 0;
202 
203  $action = '';
204  }
205  }
206 } elseif ($action == "confirm_delete") {
207  $object = new BookKeeping($db);
208 
209  $result = $object->fetch($id, null, $mode);
210  $piece_num = $object->piece_num;
211 
212  if ($result < 0) {
213  setEventMessages($object->error, $object->errors, 'errors');
214  } else {
215  $result = $object->delete($user, false, $mode);
216  if ($result < 0) {
217  setEventMessages($object->error, $object->errors, 'errors');
218  }
219  }
220  $action = '';
221 } elseif ($action == "confirm_create") {
222  $error = 0;
223 
224  $object = new BookKeeping($db);
225 
226  if (!$journal_code || $journal_code == '-1') {
227  setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Journal")), null, 'errors');
228  $action = 'create';
229  $error++;
230  }
231  if (!GETPOST('doc_ref', 'alpha'))
232  {
233  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Piece")), null, 'errors');
234  $action = 'create';
235  $error++;
236  }
237 
238  if (!$error)
239  {
240  $object->label_compte = '';
241  $object->debit = 0;
242  $object->credit = 0;
243  $object->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
244  $object->doc_type = GETPOST('doc_type', 'alpha');
245  $object->piece_num = GETPOST('next_num_mvt', 'alpha');
246  $object->doc_ref = GETPOST('doc_ref', 'alpha');
247  $object->code_journal = $journal_code;
248  $object->journal_label = $journal_label;
249  $object->fk_doc = 0;
250  $object->fk_docdet = 0;
251  $object->montant = 0; // deprecated
252  $object->amount = 0;
253 
254  $result = $object->createStd($user, 0, $mode);
255  if ($result < 0) {
256  setEventMessages($object->error, $object->errors, 'errors');
257  } else {
258  if ($mode != '_tmp')
259  {
260  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
261  }
262  $action = 'update';
263  $id = $object->id;
264  $piece_num = $object->piece_num;
265  }
266  }
267 }
268 
269 if ($action == 'setdate') {
270  $datedoc = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int'));
271  $result = $object->updateByMvt($piece_num, 'doc_date', $db->idate($datedoc), $mode);
272  if ($result < 0) {
273  setEventMessages($object->error, $object->errors, 'errors');
274  } else {
275  if ($mode != '_tmp')
276  {
277  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
278  }
279  $action = '';
280  }
281 }
282 
283 if ($action == 'setjournal') {
284  $result = $object->updateByMvt($piece_num, 'code_journal', $journal_code, $mode);
285  $result = $object->updateByMvt($piece_num, 'journal_label', $journal_label, $mode);
286  if ($result < 0) {
287  setEventMessages($object->error, $object->errors, 'errors');
288  } else {
289  if ($mode != '_tmp')
290  {
291  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
292  }
293  $action = '';
294  }
295 }
296 
297 if ($action == 'setdocref') {
298  $refdoc = GETPOST('doc_ref', 'alpha');
299  $result = $object->updateByMvt($piece_num, 'doc_ref', $refdoc, $mode);
300  if ($result < 0) {
301  setEventMessages($object->error, $object->errors, 'errors');
302  } else {
303  if ($mode != '_tmp')
304  {
305  setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
306  }
307  $action = '';
308  }
309 }
310 
311 // Validate transaction
312 if ($action == 'valid') {
313  $result = $object->transformTransaction(0, $piece_num);
314  if ($result < 0) {
315  setEventMessages($object->error, $object->errors, 'errors');
316  } else {
317  header("Location: list.php?sortfield=t.piece_num&sortorder=asc");
318  exit;
319  }
320 }
321 
322 
323 /*
324  * View
325  */
326 
327 $html = new Form($db);
328 $formaccounting = new FormAccounting($db);
329 
330 llxHeader('', $langs->trans("CreateMvts"));
331 
332 // Confirmation to delete the command
333 if ($action == 'delete') {
334  $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"].'?id='.$id.'&mode='.$mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt', $langs->transnoentitiesnoconv("RegistrationInAccounting")), 'confirm_delete', '', 0, 1);
335  print $formconfirm;
336 }
337 
338 if ($action == 'create')
339 {
340  print load_fiche_titre($langs->trans("CreateMvts"));
341 
342  $object = new BookKeeping($db);
343  $next_num_mvt = $object->getNextNumMvt('_tmp');
344 
345  if (empty($next_num_mvt))
346  {
347  dol_print_error('', 'Failed to get next piece number');
348  }
349 
350  print '<form action="'.$_SERVER["PHP_SELF"].'" name="create_mvt" method="POST">';
351  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
352  print '<input type="hidden" name="token" value="'.newToken().'">';
353  print '<input type="hidden" name="action" value="confirm_create">'."\n";
354  print '<input type="hidden" name="next_num_mvt" value="'.$next_num_mvt.'">'."\n";
355  print '<input type="hidden" name="mode" value="_tmp">'."\n";
356 
358 
359  print '<table class="border centpercent">';
360 
361  /*print '<tr>';
362  print '<td class="titlefieldcreate fieldrequired">' . $langs->trans("NumPiece") . '</td>';
363  print '<td>' . $next_num_mvt . '</td>';
364  print '</tr>';*/
365 
366  print '<tr>';
367  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Docdate").'</td>';
368  print '<td>';
369  print $html->selectDate('', 'doc_date', '', '', '', "create_mvt", 1, 1);
370  print '</td>';
371  print '</tr>';
372 
373  print '<tr>';
374  print '<td class="fieldrequired">'.$langs->trans("Codejournal").'</td>';
375  print '<td>'.$formaccounting->select_journal($journal_code, 'code_journal', 0, 0, 1, 1).'</td>';
376  print '</tr>';
377 
378  print '<tr>';
379  print '<td class="fieldrequired">'.$langs->trans("Piece").'</td>';
380  print '<td><input type="text" class="minwidth200" name="doc_ref" value="'.GETPOST('doc_ref', 'alpha').'"></td>';
381  print '</tr>';
382 
383  /*
384  print '<tr>';
385  print '<td>' . $langs->trans("Doctype") . '</td>';
386  print '<td><input type="text" class="minwidth200 name="doc_type" value=""/></td>';
387  print '</tr>';
388  */
389 
390  print '</table>';
391 
393 
394  print '<div class="center">';
395  print '<input type="submit" class="button" value="'.$langs->trans("Create").'">';
396  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
397  print '<input type="button" value="'.$langs->trans("Cancel").'" class="button button-cancel" onclick="history.go(-1)" />';
398  print '</div>';
399 
400  print '</form>';
401 } else {
402  $object = new BookKeeping($db);
403  $result = $object->fetchPerMvt($piece_num, $mode);
404  if ($result < 0) {
405  setEventMessages($object->error, $object->errors, 'errors');
406  }
407 
408  if (!empty($object->piece_num))
409  {
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>'.$object->piece_num.'</td>';
435  print '</tr>';
436 
437  // Date
438  print '<tr><td>';
439  print '<table class="nobordernopadding" width="100%"><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&amp;piece_num='.$object->piece_num.'&amp;mode='.$mode.'">'.img_edit($langs->transnoentitiesnoconv('SetDate'), 1).'</a></td>';
444  print '</tr></table>';
445  print '</td><td colspan="3">';
446  if ($action == 'editdate') {
447  print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
448  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
449  print '<input type="hidden" name="token" value="'.newToken().'">';
450  print '<input type="hidden" name="action" value="setdate">';
451  print '<input type="hidden" name="mode" value="'.$mode.'">';
452  print $form->selectDate($object->doc_date ? $object->doc_date : - 1, 'doc_date', '', '', '', "setdate");
453  print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
454  print '</form>';
455  } else {
456  print $object->doc_date ? dol_print_date($object->doc_date, 'day') : '&nbsp;';
457  }
458  print '</td>';
459  print '</tr>';
460 
461  // Journal
462  print '<tr><td>';
463  print '<table class="nobordernopadding" width="100%"><tr><td>';
464  print $langs->trans('Codejournal');
465  print '</td>';
466  if ($action != 'editjournal')
467  print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editjournal&amp;piece_num='.$object->piece_num.'&amp;mode='.$mode.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
468  print '</tr></table>';
469  print '</td><td>';
470  if ($action == 'editjournal') {
471  print '<form name="setjournal" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
472  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
473  print '<input type="hidden" name="token" value="'.newToken().'">';
474  print '<input type="hidden" name="action" value="setjournal">';
475  print '<input type="hidden" name="mode" value="'.$mode.'">';
476  print $formaccounting->select_journal($object->code_journal, 'code_journal', 0, 0, array(), 1, 1);
477  print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
478  print '</form>';
479  } else {
480  print $object->code_journal;
481  }
482  print '</td>';
483  print '</tr>';
484 
485  // Ref document
486  print '<tr><td>';
487  print '<table class="nobordernopadding" width="100%"><tr><td>';
488  print $langs->trans('Piece');
489  print '</td>';
490  if ($action != 'editdocref')
491  print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editdocref&amp;piece_num='.$object->piece_num.'&amp;mode='.$mode.'">'.img_edit($langs->transnoentitiesnoconv('Edit'), 1).'</a></td>';
492  print '</tr></table>';
493  print '</td><td>';
494  if ($action == 'editdocref') {
495  print '<form name="setdocref" action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
496  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
497  print '<input type="hidden" name="token" value="'.newToken().'">';
498  print '<input type="hidden" name="action" value="setdocref">';
499  print '<input type="hidden" name="mode" value="'.$mode.'">';
500  print '<input type="text" size="20" name="doc_ref" value="'.dol_escape_htmltag($object->doc_ref).'">';
501  print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
502  print '</form>';
503  } else {
504  print $object->doc_ref;
505  }
506  print '</td>';
507  print '</tr>';
508 
509  print '</table>';
510 
511  print '</div>';
512 
513  print '<div class="fichehalfright"><div class="ficheaddleft">';
514 
515  print '<div class="underbanner clearboth"></div>';
516  print '<table class="border tableforfield" width="100%">';
517 
518  // Doc type
519  if (!empty($object->doc_type))
520  {
521  print '<tr>';
522  print '<td class="titlefield">'.$langs->trans("Doctype").'</td>';
523  print '<td>'.$object->doc_type.'</td>';
524  print '</tr>';
525  }
526 
527  // Date document creation
528  print '<tr>';
529  print '<td class="titlefield">'.$langs->trans("DateCreation").'</td>';
530  print '<td>';
531  print $object->date_creation ? dol_print_date($object->date_creation, 'day') : '&nbsp;';
532  print '</td>';
533  print '</tr>';
534 
535  // Validate
536  /*
537  print '<tr>';
538  print '<td class="titlefield">' . $langs->trans("Status") . '</td>';
539  print '<td>';
540  if (empty($object->validated)) {
541  print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=enable">';
542  print img_picto($langs->trans("Disabled"), 'switch_off');
543  print '</a>';
544  } else {
545  print '<a class="reposition" href="' . $_SERVER["PHP_SELF"] . '?piece_num=' . $line->id . '&action=disable">';
546  print img_picto($langs->trans("Activated"), 'switch_on');
547  print '</a>';
548  }
549  print '</td>';
550  print '</tr>';
551  */
552 
553  // check data
554  /*
555  print '<tr>';
556  print '<td class="titlefield">' . $langs->trans("Control") . '</td>';
557  if ($object->doc_type == 'customer_invoice')
558  {
559  $sqlmid = 'SELECT rowid as ref';
560  $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac";
561  $sqlmid .= " WHERE fac.rowid=" . $object->fk_doc;
562  dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG);
563  $resultmid = $db->query($sqlmid);
564  if ($resultmid) {
565  $objmid = $db->fetch_object($resultmid);
566  $invoicestatic = new Facture($db);
567  $invoicestatic->fetch($objmid->ref);
568  $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1);
569  }
570  else dol_print_error($db);
571  }
572  print '<td>' . $ref .'</td>';
573  print '</tr>';
574  */
575  print "</table>\n";
576 
577  print '</div></div><!-ee-->';
578 
579  print dol_get_fiche_end();
580 
581  print '<div style="clear:both"></div>';
582 
583  print '<br>';
584 
585  $result = $object->fetchAllPerMvt($piece_num, $mode); // This load $object->linesmvt
586  if ($result < 0) {
587  setEventMessages($object->error, $object->errors, 'errors');
588  } else {
589  print load_fiche_titre($langs->trans("ListeMvts"), '', '');
590 
591  print '<form action="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'" method="post">';
592  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
593  print '<input type="hidden" name="token" value="'.newToken().'">';
594  print '<input type="hidden" name="doc_date" value="'.$object->doc_date.'">'."\n";
595  print '<input type="hidden" name="doc_type" value="'.$object->doc_type.'">'."\n";
596  print '<input type="hidden" name="doc_ref" value="'.$object->doc_ref.'">'."\n";
597  print '<input type="hidden" name="code_journal" value="'.$object->code_journal.'">'."\n";
598  print '<input type="hidden" name="fk_doc" value="'.$object->fk_doc.'">'."\n";
599  print '<input type="hidden" name="fk_docdet" value="'.$object->fk_docdet.'">'."\n";
600  print '<input type="hidden" name="mode" value="'.$mode.'">'."\n";
601 
602  print '<table class="noborder centpercent">';
603 
604  if (count($object->linesmvt) > 0) {
605  $total_debit = 0;
606  $total_credit = 0;
607 
608  print '<tr class="liste_titre">';
609 
610  print_liste_field_titre("AccountAccountingShort");
611  print_liste_field_titre("SubledgerAccount");
612  print_liste_field_titre("LabelOperation");
613  print_liste_field_titre("Debit", "", "", "", "", 'class="right"');
614  print_liste_field_titre("Credit", "", "", "", "", 'class="right"');
615  print_liste_field_titre("Action", "", "", "", "", 'width="60" class="center"');
616 
617  print "</tr>\n";
618 
619  foreach ($object->linesmvt as $line) {
620  print '<tr class="oddeven">';
621  $total_debit += $line->debit;
622  $total_credit += $line->credit;
623 
624  if ($action == 'update' && $line->id == $id) {
625  print '<!-- td columns in edit mode -->';
626  print '<td>';
627  print $formaccounting->select_account((GETPOSTISSET("accountingaccount_number") ? GETPOST("accountingaccount_number", "alpha") : $line->numero_compte), 'accountingaccount_number', 1, array(), 1, 1, '');
628  print '</td>';
629  print '<td>';
630  // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
631  // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
632  // Also, it is not possible to use a value that is not in the list.
633  // Also, the label is not automatically filled when a value is selected.
634  if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
635  print $formaccounting->select_auxaccount((GETPOSTISSET("subledger_account") ? GETPOST("subledger_account", "alpha") : $line->subledger_account), 'subledger_account', 1);
636  } else {
637  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")).'">';
638  }
639  // Add also input for subledger label
640  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")).'">';
641  print '</td>';
642  print '<td><input type="text" class="minwidth200" name="label_operation" value="'.(GETPOSTISSET("label_operation") ? GETPOST("label_operation", "alpha") : $line->label_operation).'"></td>';
643  print '<td class="right"><input type="text" size="6" class="right" name="debit" value="'.(GETPOSTISSET("debit") ? GETPOST("debit", "alpha") : price($line->debit)).'"></td>';
644  print '<td class="right"><input type="text" size="6" class="right" name="credit" value="'.(GETPOSTISSET("credit") ? GETPOST("credit", "alpha") : price($line->credit)).'"></td>';
645  print '<td>';
646  print '<input type="hidden" name="id" value="'.$line->id.'">'."\n";
647  print '<input type="submit" class="button" name="update" value="'.$langs->trans("Update").'">';
648  print '</td>';
649  } else {
650  $accountingaccount->fetch(null, $line->numero_compte, true);
651  print '<td>'.$accountingaccount->getNomUrl(0, 1, 1, '', 0).'</td>';
652  print '<td>'.length_accounta($line->subledger_account);
653  if ($line->subledger_label) {
654  print ' - <span class="opacitymedium">'.$line->subledger_label.'</span>';
655  }
656  print '</td>';
657  print '<td>'.$line->label_operation.'</td>';
658  print '<td class="nowrap right">'.price($line->debit).'</td>';
659  print '<td class="nowrap right">'.price($line->credit).'</td>';
660 
661  print '<td class="center">';
662  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()).'">';
663  print img_edit('', 0, 'class="marginrightonly"');
664  print '</a> &nbsp;';
665 
666  $actiontodelete = 'delete';
667  if ($mode == '_tmp' || $action != 'delmouv') $actiontodelete = 'confirm_delete';
668 
669  print '<a href="'.$_SERVER["PHP_SELF"].'?action='.$actiontodelete.'&id='.$line->id.'&piece_num='.urlencode($line->piece_num).'&mode='.urlencode($mode).'&token='.urlencode(newToken()).'">';
670  print img_delete();
671 
672  print '</a>';
673  print '</td>';
674  }
675  print "</tr>\n";
676  }
677 
678  $total_debit = price2num($total_debit, 'MT');
679  $total_credit = price2num($total_credit, 'MT');
680 
681  if ($total_debit != $total_credit)
682  {
683  setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_debit, $total_credit)), 'warnings');
684  }
685 
686  if ($action == "" || $action == 'add') {
687  print '<tr class="oddeven">';
688  print '<!-- td columns in add mode -->';
689  print '<td>';
690  print $formaccounting->select_account('', 'accountingaccount_number', 1, array(), 1, 1, '');
691  print '</td>';
692  print '<td>';
693  // TODO For the moment we keep a free input text instead of a combo. The select_auxaccount has problem because:
694  // It does not use the setup of "key pressed" to select a thirdparty and this hang browser on large databases.
695  // Also, it is not possible to use a value that is not in the list.
696  // Also, the label is not automatically filled when a value is selected.
697  if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
698  print $formaccounting->select_auxaccount('', 'subledger_account', 1);
699  } else {
700  print '<input type="text" class="maxwidth150" name="subledger_account" value="" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccount")).'">';
701  }
702  print '<br><input type="text" class="maxwidth150" name="subledger_label" value="" placeholder="'.dol_escape_htmltag($langs->trans("SubledgerAccountLabel")).'">';
703  print '</td>';
704  print '<td><input type="text" class="minwidth200" name="label_operation" value="'.$label_operation.'"/></td>';
705  print '<td class="right"><input type="text" size="6" class="right" name="debit" value=""/></td>';
706  print '<td class="right"><input type="text" size="6" class="right" name="credit" value=""/></td>';
707  print '<td><input type="submit" class="button" name="save" value="'.$langs->trans("Add").'"></td>';
708  print '</tr>';
709  }
710  print '</table>';
711 
712 
713  if ($mode == '_tmp' && $action == '')
714  {
715  print '<br>';
716  print '<div class="center">';
717  if ($total_debit == $total_credit)
718  {
719  print '<a class="button" href="'.$_SERVER["PHP_SELF"].'?piece_num='.$object->piece_num.'&action=valid">'.$langs->trans("ValidTransaction").'</a>';
720  } else {
721  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")).'">';
722  }
723 
724  print ' &nbsp; ';
725  print '<a class="button button-cancel" href="'.DOL_URL_ROOT.'/accountancy/bookkeeping/list.php">'.$langs->trans("Cancel").'</a>';
726 
727  print "</div>";
728  }
729  print '</form>';
730  }
731  }
732  } else {
733  print load_fiche_titre($langs->trans("NoRecords"));
734  }
735 }
736 
737 print dol_get_fiche_end();
738 
739 // End of page
740 llxFooter();
741 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
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...
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...
Class to manage Ledger (General Ledger and Subledger)
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
GETPOSTINT($paramname, $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage generation of HTML components for accounting management.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage accounting accounts.
Class to manage accounting accounts.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...