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