dolibarr  16.0.5
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', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortfield) {
59  $sortfield = 'rowid';
60 }
61 if (!$sortorder) {
62  $sortorder = 'ASC';
63 }
64 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'thirdpartylist';
65 
66 if ($contextpage == 'takepos') {
67  $_GET['optioncss'] = 'print';
68 }
69 
70 $arrayofpaymentmode = array('cash'=>'Cash', 'cheque'=>'Cheque', 'card'=>'CreditCard');
71 
72 $arrayofposavailable = array();
73 if (isModEnabled('cashdesk')) {
74  $arrayofposavailable['cashdesk'] = $langs->trans('CashDesk').' (cashdesk)';
75 }
76 if (isModEnabled('takepos')) {
77  $arrayofposavailable['takepos'] = $langs->trans('TakePOS').' (takepos)';
78 }
79 // TODO Add hook here to allow other POS to add themself
80 
81 $object = new CashControl($db);
82 $extrafields = new ExtraFields($db);
83 
84 // fetch optionals attributes and labels
85 $extrafields->fetch_name_optionals_label($object->table_element);
86 
87 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
88 $hookmanager->initHooks(array('cashcontrolcard', 'globalcard'));
89 
90 // Load object
91 include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
92 
93 // Security check
94 if ($user->socid > 0) { // Protection if external user
95  //$socid = $user->socid;
97 }
98 if (!$user->rights->cashdesk->run && !$user->rights->takepos->run) {
100 }
101 
102 
103 /*
104  * Actions
105  */
106 
107 $permissiontoadd = ($user->rights->cashdesk->run || $user->rights->takepos->run);
108 $permissiontodelete = ($user->rights->cashdesk->run || $user->rights->takepos->run) || ($permissiontoadd && $object->status == 0);
109 if (empty($backtopage)) {
110  $backtopage = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.($id > 0 ? $id : '__ID__');
111 }
112 $backurlforlist = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php';
113 $triggermodname = 'CACHCONTROL_MODIFY'; // Name of trigger action code to execute when we modify record
114 
115 if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) && empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH1)) {
116  setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors');
117 }
118 
119 
120 if (GETPOST('cancel', 'alpha')) {
121  if ($action == 'valid') {
122  $action = 'view';
123  } else {
124  $action = 'create';
125  }
126 }
127 
128 if ($action == "reopen") {
129  $result = $object->setStatut($object::STATUS_DRAFT, null, '', 'CASHFENCE_REOPEN');
130  if ($result < 0) {
131  setEventMessages($object->error, $object->error, 'errors');
132  }
133 
134  $action = 'view';
135 }
136 
137 if ($action == "start") {
138  $error = 0;
139  if (!GETPOST('posmodule', 'alpha') || GETPOST('posmodule', 'alpha') == '-1') {
140  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Module")), null, 'errors');
141  $action = 'create';
142  $error++;
143  }
144  if (GETPOST('posnumber', 'alpha') == '') {
145  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CashDesk")), null, 'errors');
146  $action = 'create';
147  $error++;
148  }
149  if (!GETPOST('closeyear', 'alpha') || GETPOST('closeyear', 'alpha') == '-1') {
150  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Year")), null, 'errors');
151  $action = 'create';
152  $error++;
153  }
154 } elseif ($action == "add") {
155  if (GETPOST('opening', 'alpha') == '') {
156  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InitialBankBalance")), null, 'errors');
157  $action = 'start';
158  $error++;
159  }
160  $error = 0;
161  foreach ($arrayofpaymentmode as $key => $val) {
162  $object->$key = price2num(GETPOST($key.'_amount', 'alpha'));
163  }
164 
165  if (!$error) {
166  $object->day_close = GETPOST('closeday', 'int');
167  $object->month_close = GETPOST('closemonth', 'int');
168  $object->year_close = GETPOST('closeyear', 'int');
169 
170  $object->opening = price2num(GETPOST('opening', 'alpha'));
171  $object->posmodule = GETPOST('posmodule', 'alpha');
172  $object->posnumber = GETPOST('posnumber', 'alpha');
173 
174  $db->begin();
175 
176  $id = $object->create($user);
177 
178  if ($id > 0) {
179  $db->commit();
180  $action = "view";
181  } else {
182  $db->rollback;
183  $action = "view";
184  }
185  }
186  if ($contextpage == 'takepos') {
187  print "
188  <script>
189  parent.location.href='../../takepos/index.php?place='+parent.place;
190  </script>";
191  exit;
192  }
193 }
194 
195 if ($action == "valid") { // validate = close
196  $object->fetch($id);
197 
198  $db->begin();
199 
200  /*
201  $object->day_close = GETPOST('closeday', 'int');
202  $object->month_close = GETPOST('closemonth', 'int');
203  $object->year_close = GETPOST('closeyear', 'int');
204  */
205 
206  $object->cash = price2num(GETPOST('cash_amount', 'alpha'));
207  $object->card = price2num(GETPOST('card_amount', 'alpha'));
208  $object->cheque = price2num(GETPOST('cheque_amount', 'alpha'));
209 
210  $result = $object->update($user);
211 
212  $result = $object->valid($user);
213 
214  if ($result <= 0) {
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  $object->fetch($id);
235 
236  if (!($object->id > 0)) {
237  dol_print_error('', 'Error, object must be fetched before being deleted');
238  exit;
239  }
240 
241  $result = $object->delete($user);
242  //var_dump($result);
243  if ($result > 0) {
244  // Delete OK
245  setEventMessages("RecordDeleted", null, 'mesgs');
246  header("Location: ".$backurlforlist);
247  exit;
248  } else {
249  if (!empty($object->errors)) {
250  setEventMessages(null, $object->errors, 'errors');
251  } else {
252  setEventMessages($object->error, null, 'errors');
253  }
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  if ($action == 'close') {
270  $posmodule = $object->posmodule;
271  $terminalid = $object->posnumber;
272  $terminaltouse = $terminalid;
273 
274  $syear = $object->year_close;
275  $smonth = $object->month_close;
276  $sday = $object->day_close;
277  } elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') {
278  $posmodule = GETPOST('posmodule', 'alpha');
279  $terminalid = GETPOST('posnumber', 'alpha');
280  $terminaltouse = $terminalid;
281 
282  if ($terminaltouse == '1' && $posmodule == 'cashdesk') {
283  $terminaltouse = '';
284  }
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  // Calculate $initialbalanceforterminal for terminal 0
295  foreach ($arrayofpaymentmode as $key => $val) {
296  if ($key != 'cash') {
297  $initialbalanceforterminal[$terminalid][$key] = 0;
298  continue;
299  }
300 
301  // Get the bank account dedicated to this point of sale module/terminal
302  $vartouse = 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse;
303  $bankid = $conf->global->$vartouse;
304 
305  if ($bankid > 0) {
306  $sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
307  $sql .= " WHERE fk_account = ".((int) $bankid);
308  if ($syear && !$smonth) {
309  $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
310  } elseif ($syear && $smonth && !$sday) {
311  $sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
312  } elseif ($syear && $smonth && $sday) {
313  $sql .= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
314  } else {
315  setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
316  }
317 
318  $resql = $db->query($sql);
319  if ($resql) {
320  $obj = $db->fetch_object($resql);
321  if ($obj) {
322  $initialbalanceforterminal[$terminalid][$key] = $obj->total;
323  }
324  } else {
325  dol_print_error($db);
326  }
327  } else {
328  setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminaltouse), null, 'errors');
329  $error++;
330  }
331  }
332 
333  // Calculate $theoricalamountforterminal
334  foreach ($arrayofpaymentmode as $key => $val) {
335  $sql = "SELECT SUM(pf.amount) as total, COUNT(*) as nb";
336  $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";
337  $sql .= " WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement";
338  $sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
339  $sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
340  $sql .= " AND f.paye = 1";
341  $sql .= " AND p.entity IN (".getEntity('facture').")";
342  if ($key == 'cash') {
343  $sql .= " AND cp.code = 'LIQ'";
344  } elseif ($key == 'cheque') {
345  $sql .= " AND cp.code = 'CHQ'";
346  } elseif ($key == 'card') {
347  $sql .= " AND cp.code = 'CB'";
348  } else {
349  dol_print_error('Value for key = '.$key.' not supported');
350  exit;
351  }
352  if ($syear && !$smonth) {
353  $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
354  } elseif ($syear && $smonth && !$sday) {
355  $sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
356  } elseif ($syear && $smonth && $sday) {
357  $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))."'";
358  } else {
359  setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
360  }
361 
362  $resql = $db->query($sql);
363  if ($resql) {
364  $theoricalamountforterminal[$terminalid][$key] = $initialbalanceforterminal[$terminalid][$key];
365 
366  $obj = $db->fetch_object($resql);
367  if ($obj) {
368  $theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total);
369  $theoricalnbofinvoiceforterminal[$terminalid][$key] = $obj->nb;
370  }
371  } else {
372  dol_print_error($db);
373  }
374  }
375  }
376 
377  //var_dump($theoricalamountforterminal); var_dump($theoricalnbofinvoiceforterminal);
378  if ($action != 'close') {
379  llxHeader('', $langs->trans("NewCashFence"));
380 
381  print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register');
382 
383  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
384  print '<input type="hidden" name="token" value="'.newToken().'">';
385  if ($contextpage == 'takepos') {
386  print '<input type="hidden" name="contextpage" value="takepos">';
387  }
388  if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
389  print '<input type="hidden" name="action" value="add">';
390  } elseif ($action == 'close') {
391  print '<input type="hidden" name="action" value="valid">';
392  print '<input type="hidden" name="id" value="'.$id.'">';
393  } else {
394  print '<input type="hidden" name="action" value="start">';
395  }
396 
397  print '<div class="div-table-responsive-no-min">';
398  print '<table class="noborder centpercent">';
399  print '<tr class="liste_titre">';
400  print '<td>'.$langs->trans("Module").'</td>';
401  print '<td>'.$langs->trans("Terminal").'</td>';
402  print '<td>'.$langs->trans("Year").'</td>';
403  print '<td>'.$langs->trans("Month").'</td>';
404  print '<td>'.$langs->trans("Day").'</td>';
405  print '<td></td>';
406  print "</tr>\n";
407 
408  $disabled = 0;
409  $prefix = 'close';
410 
411  print '<tr class="oddeven">';
412  print '<td>'.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable) > 1 ? 1 : 0)).'</td>';
413  print '<td>';
414 
415  $array = array();
416  $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
417  for ($i = 1; $i <= $numterminals; $i++) {
418  $array[$i] = $i;
419  }
420  $selectedposnumber = 0;
421  $showempty = 1;
422  if ($conf->global->TAKEPOS_NUM_TERMINALS == '1') {
423  $selectedposnumber = 1;
424  $showempty = 0;
425  }
426  print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty);
427  //print '<input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'">';
428  print '</td>';
429  // Year
430  print '<td>';
431  $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
432  for ($year = $syear - 10; $year < $syear + 10; $year++) {
433  $retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>';
434  }
435  $retstring .= "</select>\n";
436  print $retstring;
437  print '</td>';
438  // Month
439  print '<td>';
440  $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">';
441  $retstring .= '<option value="0"></option>';
442  for ($month = 1; $month <= 12; $month++) {
443  $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
444  $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
445  $retstring .= "</option>";
446  }
447  $retstring .= "</select>";
448  print $retstring;
449  print '</td>';
450  // Day
451  print '<td>';
452  $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">';
453  $retstring .= '<option value="0" selected>&nbsp;</option>';
454  for ($day = 1; $day <= 31; $day++) {
455  $retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>';
456  }
457  $retstring .= "</select>";
458  print $retstring;
459  print '</td>';
460  // Button Start
461  print '<td>';
462  if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') {
463  print '';
464  } else {
465  print '<input type="submit" name="add" class="button" value="'.$langs->trans("Start").'">';
466  }
467  print '</td>';
468  print '</table>';
469  print '</div>';
470 
471  // Table to see/enter balance
472  if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
473  $posmodule = GETPOST('posmodule', 'alpha');
474  $terminalid = GETPOST('posnumber', 'alpha');
475 
476  print '<br>';
477 
478  print '<div class="div-table-responsive-no-min">';
479  print '<table class="noborder centpercent">';
480 
481  print '<tr class="liste_titre">';
482  print '<td></td>';
483  print '<td class="center">'.$langs->trans("InitialBankBalance");
484  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
485  print '</td>';
486 
487  /*
488  print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
489  print $langs->trans("AmountAtEndOfPeriod");
490  print '</td>';
491  */
492  print '<td></td>';
493  print '</tr>';
494 
495  print '<tr class="liste_titre">';
496  print '<td></td>';
497  print '<td class="center">'.$langs->trans("Cash");
498  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
499  print '</td>';
500  /*
501  $i = 0;
502  foreach ($arrayofpaymentmode as $key => $val)
503  {
504  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
505  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
506  print '</td>';
507  $i++;
508  }*/
509  print '<td></td>';
510  print '</tr>';
511 
512  /*print '<tr>';
513  // Initial amount
514  print '<td>'.$langs->trans("NbOfInvoices").'</td>';
515  print '<td class="center">';
516  print '</td>';
517  // Amount per payment type
518  $i = 0;
519  foreach ($arrayofpaymentmode as $key => $val)
520  {
521  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
522  print $theoricalnbofinvoiceforterminal[$terminalid][$key];
523  print '</td>';
524  $i++;
525  }
526  // Save
527  print '<td align="center"></td>';
528  print '</tr>';
529  */
530 
531  print '<tr>';
532  // Initial amount
533  print '<td>'.$langs->trans("TheoricalAmount").'</td>';
534  print '<td class="center">';
535  print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
536  print '</td>';
537  // Amount per payment type
538  /*$i = 0;
539  foreach ($arrayofpaymentmode as $key => $val)
540  {
541  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
542  print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
543  print '</td>';
544  $i++;
545  }*/
546  // Save
547  print '<td></td>';
548  print '</tr>';
549 
550  print '<tr>';
551  print '<td>'.$langs->trans("RealAmount").'</td>';
552  // Initial amount
553  print '<td class="center">';
554  print '<input ';
555  if ($action == 'close') {
556  print 'disabled '; // To close cash user can't set opening cash
557  }
558  print 'name="opening" type="text" class="maxwidth100 center" value="';
559  if ($action == 'close') {
560  $object->fetch($id);
561  print $object->opening;
562  } else {
563  print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
564  }
565  print '">';
566  print '</td>';
567  // Amount per payment type
568  /*$i = 0;
569  foreach ($arrayofpaymentmode as $key => $val)
570  {
571  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
572  print '<input ';
573  if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
574  print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
575  print '</td>';
576  $i++;
577  }*/
578  // Save
579  print '<td class="center">';
580  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
581  if ($action == 'start') {
582  print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
583  } elseif ($action == 'close') {
584  print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
585  }
586  print '</td>';
587  print '</tr>';
588 
589  print '</table>';
590  print '</div>';
591  }
592 
593  print '</form>';
594  }
595 }
596 
597 if (empty($action) || $action == "view" || $action == "close") {
598  $result = $object->fetch($id);
599 
600  llxHeader('', $langs->trans("CashControl"));
601 
602  if ($result <= 0) {
603  print $langs->trans("ErrorRecordNotFound");
604  } else {
605  $head = array();
606  $head[0][0] = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$object->id;
607  $head[0][1] = $langs->trans("CashControl");
608  $head[0][2] = 'cashcontrol';
609 
610  print dol_get_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'account');
611 
612  $linkback = '<a href="'.DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
613 
614  $morehtmlref = '<div class="refidno">';
615  $morehtmlref .= '</div>';
616 
617 
618  dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
619 
620  print '<div class="fichecenter">';
621  print '<div class="fichehalfleft">';
622  print '<div class="underbanner clearboth"></div>';
623  print '<table class="border tableforfield" width="100%">';
624 
625  print '<tr><td class="titlefield nowrap">';
626  print $langs->trans("Ref");
627  print '</td><td>';
628  print $id;
629  print '</td></tr>';
630 
631  print '<tr><td valign="middle">'.$langs->trans("Module").'</td><td>';
632  print $object->posmodule;
633  print "</td></tr>";
634 
635  print '<tr><td valign="middle">'.$langs->trans("Terminal").'</td><td>';
636  print $object->posnumber;
637  print "</td></tr>";
638 
639  print '<tr><td class="nowrap">';
640  print $langs->trans("Period");
641  print '</td><td>';
642  print $object->year_close;
643  print ($object->month_close ? "-" : "").$object->month_close;
644  print ($object->day_close ? "-" : "").$object->day_close;
645  print '</td></tr>';
646 
647  print '</table>';
648  print '</div>';
649 
650  print '<div class="fichehalfright">';
651  print '<div class="underbanner clearboth"></div>';
652 
653  print '<table class="border tableforfield centpercent">';
654 
655  print '<tr><td class="titlefield nowrap">';
656  print $langs->trans("DateCreationShort");
657  print '</td><td>';
658  print dol_print_date($object->date_creation, 'dayhour');
659  print '</td></tr>';
660 
661  print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").'</td><td>';
662  print '<span class="amount">'.price($object->opening, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
663  print "</td></tr>";
664  foreach ($arrayofpaymentmode as $key => $val) {
665  print '<tr><td valign="middle">'.$langs->trans($val).'</td><td>';
666  print '<span class="amount">'.price($object->$key, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
667  print "</td></tr>";
668  }
669 
670  print "</table>\n";
671 
672  print '</div></div>';
673  print '<div style="clear:both"></div>';
674 
675  print dol_get_fiche_end();
676 
677  if ($action != 'close') {
678  print '<div class="tabsAction">';
679 
680  print '<div class="inline-block divButAction"><a target="_blank" rel="noopener noreferrer" class="butAction" href="report.php?id='.((int) $id).'">'.$langs->trans('PrintTicket').'</a></div>';
681 
682  if ($object->status == CashControl::STATUS_DRAFT) {
683  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).'&action=close&token='.newToken().'&contextpage='.$contextpage.'">'.$langs->trans('Close').'</a></div>';
684 
685  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).'&action=confirm_delete&token='.newToken().'">'.$langs->trans('Delete').'</a></div>';
686  } else {
687  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.((int) $id).'&action=reopen&token='.newToken().'">'.$langs->trans('ReOpen').'</a></div>';
688  }
689 
690  print '</div>';
691 
692  if ($contextpage != 'takepos') {
693  print '<center><iframe src="report.php?id='.$id.'" width="60%" height="800"></iframe></center>';
694  }
695  } else {
696  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formclose">';
697  print '<input type="hidden" name="token" value="'.newToken().'">';
698  if ($contextpage == 'takepos') {
699  print '<input type="hidden" name="contextpage" value="takepos">';
700  }
701  if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
702  print '<input type="hidden" name="action" value="add">';
703  } elseif ($action == 'close') {
704  print '<input type="hidden" name="action" value="valid">';
705  print '<input type="hidden" name="id" value="'.$id.'">';
706  } else {
707  print '<input type="hidden" name="action" value="start">';
708  }
709 
710  /*
711  print '<div class="div-table-responsive-no-min">';
712  print '<table class="noborder centpercent">';
713  print '<tr class="liste_titre">';
714  print '<td>'.$langs->trans("Module").'</td>';
715  print '<td>'.$langs->trans("Terminal").'</td>';
716  print '<td>'.$langs->trans("Year").'</td>';
717  print '<td>'.$langs->trans("Month").'</td>';
718  print '<td>'.$langs->trans("Day").'</td>';
719  print '<td></td>';
720  print "</tr>\n";
721 
722  $disabled = 1;
723  $prefix = 'close';
724 
725  print '<tr class="oddeven">';
726  print '<td>'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).'</td>';
727  print '<input type="hidden" name="posmodule" value="'.$object->posmodule.'">';
728  print '<td>';
729 
730  $array = array();
731  $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
732  for($i = 1; $i <= $numterminals; $i++) {
733  $array[$i] = $i;
734  }
735  $selectedposnumber = $object->posnumber; $showempty = 1;
736  //print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty, 0, 0, '', 0, 0, $disabled);
737  print '<input name="posnumberbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->posnumber.'">';
738  print '<input type="hidden" name="posnumber" value="'.$object->posmodule.'">';
739  print '</td>';
740  // Year
741  print '<td>';
742  print '<input name="yearbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->year_close.'">';
743  print '<input type="hidden" name="year_close" value="'.$object->year_close.'">';
744  print '</td>';
745  // Month
746  print '<td>';
747  print '<input name="monthbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->month_close.'">';
748  print '<input type="hidden" name="month_close" value="'.$object->month_close.'">';
749  print '</td>';
750  // Day
751  print '<td>';
752  print '<input name="daybis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->date_close.'">';
753  print '<input type="hidden" name="day_close" value="'.$object->date_close.'">';
754  print '</td>';
755 
756  print '<td></td>';
757  print '</table>';
758  print '</div>';
759  */
760 
761  // Table to see/enter balance
762  if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
763  $posmodule = $object->posmodule;
764  $terminalid = $object->posnumber;
765 
766  print '<br>';
767 
768  print '<div class="div-table-responsive-no-min">';
769  print '<table class="noborder centpercent">';
770 
771  print '<tr class="liste_titre">';
772  print '<td></td>';
773  print '<td class="center">'.$langs->trans("InitialBankBalance");
774  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
775  print '</td>';
776 
777  print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
778  print $langs->trans("AmountAtEndOfPeriod");
779  print '</td>';
780  print '<td></td>';
781  print '</tr>';
782 
783  print '<tr class="liste_titre">';
784  print '<td></td>';
785  print '<td class="center">'.$langs->trans("Cash");
786  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
787  print '</td>';
788  $i = 0;
789  foreach ($arrayofpaymentmode as $key => $val) {
790  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
791  //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
792  print '</td>';
793  $i++;
794  }
795  print '<td></td>';
796  print '</tr>';
797 
798  print '<tr>';
799  // Initial amount
800  print '<td>'.$langs->trans("NbOfInvoices").'</td>';
801  print '<td class="center">';
802  print '</td>';
803  // Amount per payment type
804  $i = 0;
805  foreach ($arrayofpaymentmode as $key => $val) {
806  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
807  print $theoricalnbofinvoiceforterminal[$terminalid][$key];
808  print '</td>';
809  $i++;
810  }
811  // Save
812  print '<td align="center"></td>';
813  print '</tr>';
814 
815  print '<tr>';
816  // Initial amount
817  print '<td>'.$langs->trans("TheoricalAmount").'</td>';
818  print '<td class="center">';
819  print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
820  print '</td>';
821  // Amount per payment type
822  $i = 0;
823  foreach ($arrayofpaymentmode as $key => $val) {
824  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
825  if ($key == 'cash') {
826  $deltaforcash = ($object->opening - $initialbalanceforterminal[$terminalid]['cash']);
827  print price($theoricalamountforterminal[$terminalid][$key] + $deltaforcash).'<br>';
828  } else {
829  print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
830  }
831  print '</td>';
832  $i++;
833  }
834  // Save
835  print '<td align="center"></td>';
836  print '</tr>';
837 
838  print '<tr>';
839  print '<td>'.$langs->trans("RealAmount").'</td>';
840  // Initial amount
841  print '<td class="center">';
842  print '<input ';
843  if ($action == 'close') {
844  print 'disabled '; // To close cash user can't set opening cash
845  }
846  print 'name="opening" type="text" class="maxwidth100 center" value="';
847  if ($action == 'close') {
848  $object->fetch($id);
849  print $object->opening;
850  } else {
851  print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
852  }
853  print '">';
854  print '</td>';
855  // Amount per payment type
856  $i = 0;
857  foreach ($arrayofpaymentmode as $key => $val) {
858  print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
859  print '<input ';
860  if ($action == 'start') {
861  print 'disabled '; // To start cash user only can set opening cash
862  }
863  print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
864  print '</td>';
865  $i++;
866  }
867  // Save
868  print '<td class="center">';
869  print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
870  if ($action == 'start') {
871  print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
872  } elseif ($action == 'close') {
873  print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Close").'">';
874  }
875  print '</td>';
876  print '</tr>';
877 
878  print '</table>';
879  print '</div>';
880  }
881 
882  print '</form>';
883  }
884  }
885 }
886 
887 // End of page
888 llxFooter();
889 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
CashControl
Class to manage cash fence.
Definition: cashcontrol.class.php:30
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:551
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:570
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10878
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
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 ...
Definition: security.lib.php:933
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2757
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59