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