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