dolibarr  13.0.2
cashcontrol_card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
6  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7  * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
8  * Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 require '../../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
34 
35 $langs->loadLangs(array("install", "cashdesk", "admin", "banks"));
36 
37 $id = GETPOST('id', 'int');
38 $ref = GETPOST('ref', 'alpha');
39 $action = GETPOST('action', 'aZ09');
40 $categid = GETPOST('categid');
41 $label = GETPOST("label");
42 
43 $now = dol_now();
44 $syear = (GETPOSTISSET('closeyear') ?GETPOST('closeyear', 'int') : dol_print_date($now, "%Y"));
45 $smonth = (GETPOSTISSET('closemonth') ?GETPOST('closemonth', 'int') : dol_print_date($now, "%m"));
46 $sday = (GETPOSTISSET('closeday') ?GETPOST('closeday', 'int') : dol_print_date($now, "%d"));
47 
48 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST("sortfield", 'alpha');
50 $sortorder = GETPOST("sortorder", 'alpha');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
53 $offset = $limit * $page;
54 $pageprev = $page - 1;
55 $pagenext = $page + 1;
56 if (!$sortfield) $sortfield = 'rowid';
57 if (!$sortorder) $sortorder = 'ASC';
58 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'thirdpartylist';
59 
60 if ($contextpage == 'takepos')
61 {
62  $_GET['optioncss'] = 'print';
63 }
64 
65 // Security check
66 if (!$user->rights->cashdesk->run && !$user->rights->takepos->run)
67 {
69 }
70 
71 $arrayofpaymentmode = array('cash'=>'Cash', 'cheque'=>'Cheque', 'card'=>'CreditCard');
72 
73 $arrayofposavailable = array();
74 if (!empty($conf->cashdesk->enabled)) $arrayofposavailable['cashdesk'] = $langs->trans('CashDesk').' (cashdesk)';
75 if (!empty($conf->takepos->enabled)) $arrayofposavailable['takepos'] = $langs->trans('TakePOS').' (takepos)';
76 // TODO Add hook here to allow other POS to add themself
77 
78 $object = new CashControl($db);
79 $extrafields = new ExtraFields($db);
80 
81 // fetch optionals attributes and labels
82 $extrafields->fetch_name_optionals_label($object->table_element);
83 
84 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
85 $hookmanager->initHooks(array('cashcontrolcard', 'globalcard'));
86 
87 // Load object
88 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
89 
90 
91 /*
92  * Actions
93  */
94 
95 $permissiontoadd = ($user->rights->cashdesk->run || $user->rights->takepos->run);
96 $permissiontodelete = ($user->rights->cashdesk->run || $user->rights->takepos->run) || ($permissiontoadd && $object->status == 0);
97 if (empty($backtopage)) $backtopage = dol_buildpath('/compta/cashcontrol/cashcontrol_card.php', 1).'?id='.($id > 0 ? $id : '__ID__');
98 $backurlforlist = dol_buildpath('/compta/cashcontrol/cashcontrol_list.php', 1);
99 $triggermodname = 'CACHCONTROL_MODIFY'; // Name of trigger action code to execute when we modify record
100 
101 if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) && empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH1))
102 {
103  setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors');
104 }
105 
106 
107 if (GETPOST('cancel', 'alpha'))
108 {
109  if ($action == 'valid') {
110  $action = 'view';
111  } else {
112  $action = 'create';
113  }
114 }
115 
116 if ($action == "reopen")
117 {
118  $result = $object->setStatut($object::STATUS_DRAFT, null, '', 'CASHFENCE_REOPEN');
119  if ($result < 0) {
120  dol_print_error($db, $object->error, $object->error);
121  }
122 
123  $action = 'view';
124 }
125 
126 if ($action == "start")
127 {
128  $error = 0;
129  if (!GETPOST('posmodule', 'alpha') || GETPOST('posmodule', 'alpha') == '-1')
130  {
131  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Module")), null, 'errors');
132  $action = 'create';
133  $error++;
134  }
135  if (GETPOST('posnumber', 'alpha') == '')
136  {
137  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CashDesk")), null, 'errors');
138  $action = 'create';
139  $error++;
140  }
141  if (!GETPOST('closeyear', 'alpha') || GETPOST('closeyear', 'alpha') == '-1')
142  {
143  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Year")), null, 'errors');
144  $action = 'create';
145  $error++;
146  }
147 } elseif ($action == "add")
148 {
149  if (GETPOST('opening', 'alpha') == '')
150  {
151  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InitialBankBalance")), null, 'errors');
152  $action = 'start';
153  $error++;
154  }
155  $error = 0;
156  foreach ($arrayofpaymentmode as $key=>$val)
157  {
158  $object->$key = price2num(GETPOST($key.'_amount', 'alpha'));
159  }
160 
161  if (!$error)
162  {
163  $object->day_close = GETPOST('closeday', 'int');
164  $object->month_close = GETPOST('closemonth', 'int');
165  $object->year_close = GETPOST('closeyear', 'int');
166 
167  $object->opening = price2num(GETPOST('opening', 'alpha'));
168  $object->posmodule = GETPOST('posmodule', 'alpha');
169  $object->posnumber = GETPOST('posnumber', 'alpha');
170 
171  $db->begin();
172 
173  $id = $object->create($user);
174 
175  if ($id > 0)
176  {
177  $db->commit();
178  $action = "view";
179  } else {
180  $db->rollback;
181  $action = "view";
182  }
183  }
184  if ($contextpage == 'takepos') {
185  print "
186  <script>
187  parent.location.href='../../takepos/index.php?place='+parent.place;
188  </script>";
189  exit;
190  }
191 }
192 
193 if ($action == "valid") // validate = close
194 {
195  $object->fetch($id);
196 
197  $db->begin();
198 
199  /*
200  $object->day_close = GETPOST('closeday', 'int');
201  $object->month_close = GETPOST('closemonth', 'int');
202  $object->year_close = GETPOST('closeyear', 'int');
203  */
204 
205  $object->cash = price2num(GETPOST('cash_amount', 'alpha'));
206  $object->card = price2num(GETPOST('card_amount', 'alpha'));
207  $object->cheque = price2num(GETPOST('cheque_amount', 'alpha'));
208 
209  $result = $object->update($user);
210 
211  $result = $object->valid($user);
212 
213  if ($result <= 0)
214  {
215  setEventMessages($object->error, $object->errors, 'errors');
216  $db->rollback();
217  } else {
218  setEventMessages($langs->trans("CashFenceDone"), null);
219  $db->commit();
220  }
221 
222  if ($contextpage == 'takepos') {
223  print "
224  <script>
225  parent.location.href='../../takepos/index.php?place='+parent.place;
226  </script>";
227  exit;
228  }
229  $action = "view";
230 }
231 
232 // Action to delete
233 if ($action == 'confirm_delete' && !empty($permissiontodelete))
234 {
235  $object->fetch($id);
236 
237  if (!($object->id > 0))
238  {
239  dol_print_error('', 'Error, object must be fetched before being deleted');
240  exit;
241  }
242 
243  $result = $object->delete($user);
244  //var_dump($result);
245  if ($result > 0)
246  {
247  // Delete OK
248  setEventMessages("RecordDeleted", null, 'mesgs');
249  header("Location: ".$backurlforlist);
250  exit;
251  } else {
252  if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors');
253  else setEventMessages($object->error, null, 'errors');
254  }
255 }
256 
257 
258 /*
259  * View
260  */
261 
262 $form = new Form($db);
263 
264 $initialbalanceforterminal = array();
265 $theoricalamountforterminal = array();
266 $theoricalnbofinvoiceforterminal = array();
267 
268 if ($action == "create" || $action == "start" || $action == 'close')
269 {
270  if ($action == 'close') {
271  $posmodule = $object->posmodule;
272  $terminalid = $object->posnumber;
273  $terminaltouse = $terminalid;
274 
275  $syear = $object->year_close;
276  $smonth = $object->month_close;
277  $sday = $object->day_close;
278  } elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1')
279  {
280  $posmodule = GETPOST('posmodule', 'alpha');
281  $terminalid = GETPOST('posnumber', 'alpha');
282  $terminaltouse = $terminalid;
283 
284  if ($terminaltouse == '1' && $posmodule == 'cashdesk') $terminaltouse = '';
285 
286  if ($posmodule == 'cashdesk' && $terminaltouse != '' && $terminaltouse != '1') {
287  $terminaltouse = '';
288  setEventMessages($langs->trans("OnlyTerminal1IsAvailableForCashDeskModule"), null, 'errors');
289  $error++;
290  }
291  }
292 
293  if ($terminalid != '')
294  {
295  // Calculate $initialbalanceforterminal for terminal 0
296  foreach ($arrayofpaymentmode as $key => $val)
297  {
298  if ($key != 'cash')
299  {
300  $initialbalanceforterminal[$terminalid][$key] = 0;
301  continue;
302  }
303 
304  // Get the bank account dedicated to this point of sale module/terminal
305  $vartouse = 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse;
306  $bankid = $conf->global->$vartouse;
307 
308  if ($bankid > 0)
309  {
310  $sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
311  $sql .= " WHERE fk_account = ".$bankid;
312  if ($syear && !$smonth) $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
313  elseif ($syear && $smonth && !$sday) $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
314  elseif ($syear && $smonth && $sday) $sql .= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
315  else dol_print_error('', 'Year not defined');
316 
317  $resql = $db->query($sql);
318  if ($resql)
319  {
320  $obj = $db->fetch_object($resql);
321  if ($obj) $initialbalanceforterminal[$terminalid][$key] = $obj->total;
322  } else dol_print_error($db);
323  } else {
324  setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminaltouse), null, 'errors');
325  $error++;
326  }
327  }
328 
329  // Calculate $theoricalamountforterminal
330  foreach ($arrayofpaymentmode as $key => $val)
331  {
332  $sql = "SELECT SUM(pf.amount) as total, COUNT(*) as nb";
333  $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as cp";
334  $sql .= " WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement";
335  $sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
336  $sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
337  $sql .= " AND f.paye = 1";
338  $sql .= " AND p.entity IN (".getEntity('facture').")";
339  if ($key == 'cash') $sql .= " AND cp.code = 'LIQ'";
340  elseif ($key == 'cheque') $sql .= " AND cp.code = 'CHQ'";
341  elseif ($key == 'card') $sql .= " AND cp.code = 'CB'";
342  else {
343  dol_print_error('Value for key = '.$key.' not supported');
344  exit;
345  }
346  if ($syear && !$smonth) $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
347  elseif ($syear && $smonth && !$sday) $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
348  elseif ($syear && $smonth && $sday) $sql .= " AND datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $smonth, $sday, $syear))."'";
349  else dol_print_error('', 'Year not defined');
350 
351  $resql = $db->query($sql);
352  if ($resql)
353  {
354  $theoricalamountforterminal[$terminalid][$key] = $initialbalanceforterminal[$terminalid][$key];
355 
356  $obj = $db->fetch_object($resql);
357  if ($obj)
358  {
359  $theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total);
360  $theoricalnbofinvoiceforterminal[$terminalid][$key] = $obj->nb;
361  }
362  } else dol_print_error($db);
363  }
364  }
365 
366  //var_dump($theoricalamountforterminal); var_dump($theoricalnbofinvoiceforterminal);
367  if ($action != 'close') {
368  llxHeader();
369 
370  print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register');
371 
372  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
373  print '<input type="hidden" name="token" value="'.newToken().'">';
374  if ($contextpage == 'takepos') print '<input type="hidden" name="contextpage" value="takepos">';
375  if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1')
376  {
377  print '<input type="hidden" name="action" value="add">';
378  } elseif ($action == 'close')
379  {
380  print '<input type="hidden" name="action" value="valid">';
381  print '<input type="hidden" name="id" value="'.$id.'">';
382  } else {
383  print '<input type="hidden" name="action" value="start">';
384  }
385 
386  print '<div class="div-table-responsive-no-min">';
387  print '<table class="noborder centpercent">';
388  print '<tr class="liste_titre">';
389  print '<td>'.$langs->trans("Module").'</td>';
390  print '<td>'.$langs->trans("Terminal").'</td>';
391  print '<td>'.$langs->trans("Year").'</td>';
392  print '<td>'.$langs->trans("Month").'</td>';
393  print '<td>'.$langs->trans("Day").'</td>';
394  print '<td></td>';
395  print "</tr>\n";
396 
397  $disabled = 0;
398  $prefix = 'close';
399 
400  print '<tr class="oddeven">';
401  print '<td>'.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable) > 1 ? 1 : 0)).'</td>';
402  print '<td>';
403 
404  $array = array();
405  $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
406  for ($i = 1; $i <= $numterminals; $i++) {
407  $array[$i] = $i;
408  }
409  $selectedposnumber = 0; $showempty = 1;
410  if ($conf->global->TAKEPOS_NUM_TERMINALS == '1')
411  {
412  $selectedposnumber = 1; $showempty = 0;
413  }
414  print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty);
415  //print '<input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'">';
416  print '</td>';
417  // Year
418  print '<td>';
419  $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
420  for ($year = $syear - 10; $year < $syear + 10; $year++)
421  {
422  $retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>';
423  }
424  $retstring .= "</select>\n";
425  print $retstring;
426  print '</td>';
427  // Month
428  print '<td>';
429  $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">';
430  $retstring .= '<option value="0"></option>';
431  for ($month = 1; $month <= 12; $month++)
432  {
433  $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
434  $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
435  $retstring .= "</option>";
436  }
437  $retstring .= "</select>";
438  print $retstring;
439  print '</td>';
440  // Day
441  print '<td>';
442  $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">';
443  $retstring .= '<option value="0" selected>&nbsp;</option>';
444  for ($day = 1; $day <= 31; $day++)
445  {
446  $retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>';
447  }
448  $retstring .= "</select>";
449  print $retstring;
450  print '</td>';
451  // Button Start
452  print '<td>';
453  if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1')
454  {
455  print '';
456  } else {
457  print '<input type="submit" name="add" class="button" value="'.$langs->trans("Start").'">';
458  }
459  print '</td>';
460  print '</table>';
461  print '</div>';
462 
463  // Table to see/enter balance
464  if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close')
465  {
466  $posmodule = GETPOST('posmodule', 'alpha');
467  $terminalid = GETPOST('posnumber', 'alpha');
468 
469  print '<br>';
470 
471  print '<div class="div-table-responsive-no-min">';
472  print '<table class="noborder centpercent">';
473 
474  print '<tr class="liste_titre">';
475  print '<td></td>';
476  print '<td class="center">'.$langs->trans("InitialBankBalance");
477  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
478  print '</td>';
479 
480  /*
481  print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
482  print $langs->trans("AmountAtEndOfPeriod");
483  print '</td>';
484  */
485  print '<td></td>';
486  print '</tr>';
487 
488  print '<tr class="liste_titre">';
489  print '<td></td>';
490  print '<td class="center">'.$langs->trans("Cash");
491  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
492  print '</td>';
493  /*
494  $i = 0;
495  foreach ($arrayofpaymentmode as $key => $val)
496  {
497  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
498  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
499  print '</td>';
500  $i++;
501  }*/
502  print '<td></td>';
503  print '</tr>';
504 
505  /*print '<tr>';
506  // Initial amount
507  print '<td>'.$langs->trans("NbOfInvoices").'</td>';
508  print '<td class="center">';
509  print '</td>';
510  // Amount per payment type
511  $i = 0;
512  foreach ($arrayofpaymentmode as $key => $val)
513  {
514  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
515  print $theoricalnbofinvoiceforterminal[$terminalid][$key];
516  print '</td>';
517  $i++;
518  }
519  // Save
520  print '<td align="center"></td>';
521  print '</tr>';
522  */
523 
524  print '<tr>';
525  // Initial amount
526  print '<td>'.$langs->trans("TheoricalAmount").'</td>';
527  print '<td class="center">';
528  print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
529  print '</td>';
530  // Amount per payment type
531  /*$i = 0;
532  foreach ($arrayofpaymentmode as $key => $val)
533  {
534  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
535  print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
536  print '</td>';
537  $i++;
538  }*/
539  // Save
540  print '<td></td>';
541  print '</tr>';
542 
543  print '<tr>';
544  print '<td>'.$langs->trans("RealAmount").'</td>';
545  // Initial amount
546  print '<td class="center">';
547  print '<input ';
548  if ($action == 'close') print 'disabled '; // To close cash user can't set opening cash
549  print 'name="opening" type="text" class="maxwidth100 center" value="';
550  if ($action == 'close')
551  {
552  $object->fetch($id);
553  print $object->opening;
554  } else print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
555  print '">';
556  print '</td>';
557  // Amount per payment type
558  /*$i = 0;
559  foreach ($arrayofpaymentmode as $key => $val)
560  {
561  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
562  print '<input ';
563  if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
564  print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
565  print '</td>';
566  $i++;
567  }*/
568  // Save
569  print '<td class="center">';
570  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
571  if ($action == 'start') print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
572  elseif ($action == 'close') print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
573  print '</td>';
574  print '</tr>';
575 
576  print '</table>';
577  print '</div>';
578  }
579 
580  print '</form>';
581  }
582 }
583 
584 if (empty($action) || $action == "view" || $action == "close")
585 {
586  $result = $object->fetch($id);
587 
588  llxHeader('', $langs->trans("CashControl"));
589 
590  if ($result <= 0) {
591  print $langs->trans("ErrorRecordNotFound");
592  } else {
593  $head = array();
594  $head[0][0] = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$object->id;
595  $head[0][1] = $langs->trans("CashControl");
596  $head[0][2] = 'cashcontrol';
597 
598  print dol_get_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'account');
599 
600  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
601 
602  $morehtmlref = '<div class="refidno">';
603  $morehtmlref .= '</div>';
604 
605 
606  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
607 
608  print '<div class="fichecenter">';
609  print '<div class="fichehalfleft">';
610  print '<div class="underbanner clearboth"></div>';
611  print '<table class="border tableforfield" width="100%">';
612 
613  print '<tr><td class="titlefield nowrap">';
614  print $langs->trans("Ref");
615  print '</td><td>';
616  print $id;
617  print '</td></tr>';
618 
619  print '<tr><td valign="middle">'.$langs->trans("Module").'</td><td>';
620  print $object->posmodule;
621  print "</td></tr>";
622 
623  print '<tr><td valign="middle">'.$langs->trans("Terminal").'</td><td>';
624  print $object->posnumber;
625  print "</td></tr>";
626 
627  print '<tr><td class="nowrap">';
628  print $langs->trans("Period");
629  print '</td><td>';
630  print $object->year_close;
631  print ($object->month_close ? "-" : "").$object->month_close;
632  print ($object->day_close ? "-" : "").$object->day_close;
633  print '</td></tr>';
634 
635  print '</table>';
636  print '</div>';
637 
638  print '<div class="fichehalfright"><div class="ficheaddleft">';
639  print '<div class="underbanner clearboth"></div>';
640  print '<table class="border tableforfield" width="100%">';
641 
642  print '<tr><td class="titlefield nowrap">';
643  print $langs->trans("DateCreationShort");
644  print '</td><td>';
645  print dol_print_date($object->date_creation, 'dayhour');
646  print '</td></tr>';
647 
648  print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").'</td><td>';
649  print price($object->opening, 0, $langs, 1, -1, -1, $conf->currency);
650  print "</td></tr>";
651  foreach ($arrayofpaymentmode as $key => $val)
652  {
653  print '<tr><td valign="middle">'.$langs->trans($val).'</td><td>';
654  print price($object->$key, 0, $langs, 1, -1, -1, $conf->currency);
655  print "</td></tr>";
656  }
657 
658  print "</table>\n";
659  print '</div>';
660  print '</div></div>';
661  print '<div style="clear:both"></div>';
662 
664 
665  if ($action != 'close') {
666  print '<div class="tabsAction">';
667 
668  print '<div class="inline-block divButAction"><a target="_blank" class="butAction" href="report.php?id='.$id.'">'.$langs->trans('PrintTicket').'</a></div>';
669 
670  if ($object->status == CashControl::STATUS_DRAFT)
671  {
672  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=close&amp;contextpage='.$contextpage.'">'.$langs->trans('Close').'</a></div>';
673 
674  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=confirm_delete">'.$langs->trans('Delete').'</a></div>';
675  } else {
676  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&amp;action=reopen">'.$langs->trans('ReOpen').'</a></div>';
677  }
678 
679  print '</div>';
680 
681  if ($contextpage != 'takepos') print '<center><iframe src="report.php?id='.$id.'" width="60%" height="800"></iframe></center>';
682  } else {
683  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formclose">';
684  print '<input type="hidden" name="token" value="'.newToken().'">';
685  if ($contextpage == 'takepos') print '<input type="hidden" name="contextpage" value="takepos">';
686  if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1')
687  {
688  print '<input type="hidden" name="action" value="add">';
689  } elseif ($action == 'close')
690  {
691  print '<input type="hidden" name="action" value="valid">';
692  print '<input type="hidden" name="id" value="'.$id.'">';
693  } else {
694  print '<input type="hidden" name="action" value="start">';
695  }
696 
697  /*
698  print '<div class="div-table-responsive-no-min">';
699  print '<table class="noborder centpercent">';
700  print '<tr class="liste_titre">';
701  print '<td>'.$langs->trans("Module").'</td>';
702  print '<td>'.$langs->trans("Terminal").'</td>';
703  print '<td>'.$langs->trans("Year").'</td>';
704  print '<td>'.$langs->trans("Month").'</td>';
705  print '<td>'.$langs->trans("Day").'</td>';
706  print '<td></td>';
707  print "</tr>\n";
708 
709  $disabled = 1;
710  $prefix = 'close';
711 
712  print '<tr class="oddeven">';
713  print '<td>'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).'</td>';
714  print '<input type="hidden" name="posmodule" value="'.$object->posmodule.'">';
715  print '<td>';
716 
717  $array = array();
718  $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
719  for($i = 1; $i <= $numterminals; $i++) {
720  $array[$i] = $i;
721  }
722  $selectedposnumber = $object->posnumber; $showempty = 1;
723  //print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty, 0, 0, '', 0, 0, $disabled);
724  print '<input name="posnumberbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->posnumber.'">';
725  print '<input type="hidden" name="posnumber" value="'.$object->posmodule.'">';
726  print '</td>';
727  // Year
728  print '<td>';
729  print '<input name="yearbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->year_close.'">';
730  print '<input type="hidden" name="year_close" value="'.$object->year_close.'">';
731  print '</td>';
732  // Month
733  print '<td>';
734  print '<input name="monthbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->month_close.'">';
735  print '<input type="hidden" name="month_close" value="'.$object->month_close.'">';
736  print '</td>';
737  // Day
738  print '<td>';
739  print '<input name="daybis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->date_close.'">';
740  print '<input type="hidden" name="day_close" value="'.$object->date_close.'">';
741  print '</td>';
742 
743  print '<td></td>';
744  print '</table>';
745  print '</div>';
746  */
747 
748  // Table to see/enter balance
749  if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close')
750  {
751  $posmodule = $object->posmodule;
752  $terminalid = $object->posnumber;
753 
754  print '<br>';
755 
756  print '<div class="div-table-responsive-no-min">';
757  print '<table class="noborder centpercent">';
758 
759  print '<tr class="liste_titre">';
760  print '<td></td>';
761  print '<td class="center">'.$langs->trans("InitialBankBalance");
762  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
763  print '</td>';
764 
765  print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
766  print $langs->trans("AmountAtEndOfPeriod");
767  print '</td>';
768  print '<td></td>';
769  print '</tr>';
770 
771  print '<tr class="liste_titre">';
772  print '<td></td>';
773  print '<td class="center">'.$langs->trans("Cash");
774  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
775  print '</td>';
776  $i = 0;
777  foreach ($arrayofpaymentmode as $key => $val)
778  {
779  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
780  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
781  print '</td>';
782  $i++;
783  }
784  print '<td></td>';
785  print '</tr>';
786 
787  print '<tr>';
788  // Initial amount
789  print '<td>'.$langs->trans("NbOfInvoices").'</td>';
790  print '<td class="center">';
791  print '</td>';
792  // Amount per payment type
793  $i = 0;
794  foreach ($arrayofpaymentmode as $key => $val)
795  {
796  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
797  print $theoricalnbofinvoiceforterminal[$terminalid][$key];
798  print '</td>';
799  $i++;
800  }
801  // Save
802  print '<td align="center"></td>';
803  print '</tr>';
804 
805  print '<tr>';
806  // Initial amount
807  print '<td>'.$langs->trans("TheoricalAmount").'</td>';
808  print '<td class="center">';
809  print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
810  print '</td>';
811  // Amount per payment type
812  $i = 0;
813  foreach ($arrayofpaymentmode as $key => $val)
814  {
815  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
816  if ($key == 'cash') {
817  $deltaforcash = ($object->opening - $initialbalanceforterminal[$terminalid]['cash']);
818  print price($theoricalamountforterminal[$terminalid][$key] + $deltaforcash).'<br>';
819  } else {
820  print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
821  }
822  print '</td>';
823  $i++;
824  }
825  // Save
826  print '<td align="center"></td>';
827  print '</tr>';
828 
829  print '<tr>';
830  print '<td>'.$langs->trans("RealAmount").'</td>';
831  // Initial amount
832  print '<td class="center">';
833  print '<input ';
834  if ($action == 'close') print 'disabled '; // To close cash user can't set opening cash
835  print 'name="opening" type="text" class="maxwidth100 center" value="';
836  if ($action == 'close')
837  {
838  $object->fetch($id);
839  print $object->opening;
840  } else print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
841  print '">';
842  print '</td>';
843  // Amount per payment type
844  $i = 0;
845  foreach ($arrayofpaymentmode as $key => $val)
846  {
847  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
848  print '<input ';
849  if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
850  print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
851  print '</td>';
852  $i++;
853  }
854  // Save
855  print '<td class="center">';
856  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
857  if ($action == 'start') print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
858  elseif ($action == 'close') print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Close").'">';
859  print '</td>';
860  print '</tr>';
861 
862  print '</table>';
863  print '</div>';
864  }
865 
866  print '</form>';
867  }
868  }
869 }
870 
871 // End of page
872 llxFooter();
873 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Definition: list.php:566
dol_now($mode= 'auto')
Return date for now.
Class to manage cash fence.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105