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