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