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