dolibarr 20.0.0
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 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
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
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);
111if (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
117if (!getDolGlobalString('CASHDESK_ID_BANKACCOUNT_CASH') && !getDolGlobalString('CASHDESK_ID_BANKACCOUNT_CASH1')) {
118 setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors');
119}
120
121
122if (GETPOST('cancel', 'alpha')) {
123 if ($action == 'valid') {
124 $action = 'view';
125 } else {
126 $action = 'create';
127 }
128}
129
130if ($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
139if ($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
197if ($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
235if ($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
271llxHeader('', $langs->trans("CashControl"));
272
273
274if ($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 $arrayofpos = array();
420 $numterminals = max(1, getDolGlobalString('TAKEPOS_NUM_TERMINALS'));
421 for ($i = 1; $i <= $numterminals; $i++) {
422 $nameofterminal = getDolGlobalString("TAKEPOS_TERMINAL_NAME_".$i);
423 $arrayofpos[$i] = array('id' => $i, 'label' => (($nameofterminal != "TAKEPOS_TERMINAL_NAME_".$i) ? '#'.$i.' '.$nameofterminal : $i), 'data-html' => (($nameofterminal != "TAKEPOS_TERMINAL_NAME_".$i) ? '#'.$i.' - '.$nameofterminal : $i));
424 }
425 $selectedposnumber = 0;
426 $showempty = 1;
427 if (getDolGlobalString('TAKEPOS_NUM_TERMINALS') == '1') {
428 $selectedposnumber = 1;
429 $showempty = 0;
430 }
431 print $form->selectarray('posnumber', $arrayofpos, GETPOSTISSET('posnumber') ? GETPOSTINT('posnumber') : $selectedposnumber, $showempty);
432 //print '<input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'">';
433 print '</td>';
434 // Year
435 print '<td>';
436 $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
437 for ($year = $syear - 10; $year < $syear + 10; $year++) {
438 $retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>';
439 }
440 $retstring .= "</select>\n";
441 print $retstring;
442 print '</td>';
443 // Month
444 print '<td>';
445 $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">';
446 $retstring .= '<option value="0"></option>';
447 for ($month = 1; $month <= 12; $month++) {
448 $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
449 $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
450 $retstring .= "</option>";
451 }
452 $retstring .= "</select>";
453 print $retstring;
454 print '</td>';
455 // Day
456 print '<td>';
457 $retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">';
458 $retstring .= '<option value="0" selected>&nbsp;</option>';
459 for ($day = 1; $day <= 31; $day++) {
460 $retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>';
461 }
462 $retstring .= "</select>";
463 print $retstring;
464 print '</td>';
465 // Button Start
466 print '<td>';
467 if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') {
468 print '';
469 } else {
470 print '<input type="submit" name="add" class="button" value="'.$langs->trans("Start").'">';
471 }
472 print '</td>';
473 print '</table>';
474 print '</div>';
475
476 // Table to see/enter balance
477 if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
478 $posmodule = GETPOST('posmodule', 'alpha');
479 $terminalid = GETPOST('posnumber', 'alpha');
480
481 print '<br>';
482
483 print '<div class="div-table-responsive-no-min">';
484 print '<table class="noborder centpercent">';
485
486 print '<tr class="liste_titre">';
487 print '<td></td>';
488 print '<td class="center">'.$langs->trans("InitialBankBalance");
489 //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
490 print '</td>';
491
492 /*
493 print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
494 print $langs->trans("AmountAtEndOfPeriod");
495 print '</td>';
496 */
497 print '<td></td>';
498 print '</tr>';
499
500 print '<tr class="liste_titre">';
501 print '<td></td>';
502 print '<td class="center">'.$langs->trans("Cash");
503 //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
504 print '</td>';
505 /*
506 $i = 0;
507 foreach ($arrayofpaymentmode as $key => $val)
508 {
509 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
510 //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
511 print '</td>';
512 $i++;
513 }*/
514 print '<td></td>';
515 print '</tr>';
516
517 /*print '<tr>';
518 // Initial amount
519 print '<td>'.$langs->trans("NbOfInvoices").'</td>';
520 print '<td class="center">';
521 print '</td>';
522 // Amount per payment type
523 $i = 0;
524 foreach ($arrayofpaymentmode as $key => $val)
525 {
526 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
527 print $theoricalnbofinvoiceforterminal[$terminalid][$key];
528 print '</td>';
529 $i++;
530 }
531 // Save
532 print '<td align="center"></td>';
533 print '</tr>';
534 */
535
536 print '<tr>';
537 // Initial amount
538 print '<td>'.$langs->trans("TheoricalAmount").'</td>';
539 print '<td class="center">';
540 print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
541 print '</td>';
542 // Amount per payment type
543 /*$i = 0;
544 foreach ($arrayofpaymentmode as $key => $val)
545 {
546 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
547 print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
548 print '</td>';
549 $i++;
550 }*/
551 // Save
552 print '<td></td>';
553 print '</tr>';
554
555 print '<tr>';
556 print '<td>'.$langs->trans("RealAmount").'</td>';
557 // Initial amount
558 print '<td class="center">';
559 print '<input ';
560 if ($action == 'close') {
561 print 'disabled '; // To close cash user can't set opening cash
562 }
563 print 'name="opening" type="text" class="maxwidth100 center" value="';
564 if ($action == 'close') {
565 $object->fetch($id);
566 print $object->opening;
567 } else {
568 print(GETPOSTISSET('opening') ? price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
569 }
570 print '">';
571 print '</td>';
572 // Amount per payment type
573 /*$i = 0;
574 foreach ($arrayofpaymentmode as $key => $val)
575 {
576 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
577 print '<input ';
578 if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
579 print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
580 print '</td>';
581 $i++;
582 }*/
583 // Save
584 print '<td class="center">';
585 print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
586 if ($action == 'start') {
587 print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
588 } elseif ($action == 'close') {
589 print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
590 }
591 print '</td>';
592 print '</tr>';
593
594 print '</table>';
595 print '</div>';
596 }
597
598 print '</form>';
599 }
600}
601
602if (empty($action) || $action == "view" || $action == "close") {
603 $result = $object->fetch($id);
604
605 if ($result <= 0) {
606 print $langs->trans("ErrorRecordNotFound");
607 } else {
608 $head = array();
609 $head[0][0] = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$object->id;
610 $head[0][1] = $langs->trans("CashControl");
611 $head[0][2] = 'cashcontrol';
612
613 print dol_get_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'account');
614
615 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
616
617 $morehtmlref = '<div class="refidno">';
618 $morehtmlref .= '</div>';
619
620
621 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
622
623 print '<div class="fichecenter">';
624 print '<div class="fichehalfleft">';
625 print '<div class="underbanner clearboth"></div>';
626 print '<table class="border tableforfield" width="100%">';
627
628 print '<tr><td class="titlefield nowrap">';
629 print $langs->trans("Ref");
630 print '</td><td>';
631 print $id;
632 print '</td></tr>';
633
634 print '<tr><td valign="middle">'.$langs->trans("Module").'</td><td>';
635 print $object->posmodule;
636 print "</td></tr>";
637
638 print '<tr><td valign="middle">'.$langs->trans("Terminal").'</td><td>';
639 print $object->posnumber;
640 print "</td></tr>";
641
642 print '<tr><td class="nowrap">';
643 print $langs->trans("Period");
644 print '</td><td>';
645 print $object->year_close;
646 print($object->month_close ? "-" : "").$object->month_close;
647 print($object->day_close ? "-" : "").$object->day_close;
648 print '</td></tr>';
649
650 print '</table>';
651 print '</div>';
652
653 print '<div class="fichehalfright">';
654 print '<div class="underbanner clearboth"></div>';
655
656 print '<table class="border tableforfield centpercent">';
657
658 print '<tr><td class="titlefield nowrap">';
659 print $langs->trans("DateCreationShort");
660 print '</td><td>';
661 print dol_print_date($object->date_creation, 'dayhour');
662 print '</td></tr>';
663
664 print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").'</td><td>';
665 print '<span class="amount">'.price($object->opening, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
666 print "</td></tr>";
667 foreach ($arrayofpaymentmode as $key => $val) {
668 print '<tr><td valign="middle">'.$langs->trans($val).'</td><td>';
669 print '<span class="amount">'.price($object->$key, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
670 print "</td></tr>";
671 }
672
673 print "</table>\n";
674
675 print '</div></div>';
676 print '<div class="clearboth"></div>';
677
678 print dol_get_fiche_end();
679
680 if ($action != 'close') {
681 print '<div class="tabsAction">';
682
683 // Print ticket
684 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>';
685
686 // Print ticket (no detail)
687 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>';
688
689 if ($object->status == CashControl::STATUS_DRAFT) {
690 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>';
691
692 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>';
693 } else {
694 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>';
695 }
696
697 print '</div>';
698
699 if ($contextpage != 'takepos') {
700 print '<center><iframe src="report.php?id='.$id.'" width="60%" height="800"></iframe></center>';
701 }
702 } else {
703 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formclose">';
704 print '<input type="hidden" name="token" value="'.newToken().'">';
705 if ($contextpage == 'takepos') {
706 print '<input type="hidden" name="contextpage" value="takepos">';
707 }
708 if ($action == 'start' && GETPOSTINT('posnumber') != '' && GETPOSTINT('posnumber') != '' && GETPOSTINT('posnumber') != '-1') {
709 print '<input type="hidden" name="action" value="add">';
710 } elseif ($action == 'close') {
711 print '<input type="hidden" name="action" value="valid">';
712 print '<input type="hidden" name="id" value="'.$id.'">';
713 } else {
714 print '<input type="hidden" name="action" value="start">';
715 }
716
717 /*
718 print '<div class="div-table-responsive-no-min">';
719 print '<table class="noborder centpercent">';
720 print '<tr class="liste_titre">';
721 print '<td>'.$langs->trans("Module").'</td>';
722 print '<td>'.$langs->trans("Terminal").'</td>';
723 print '<td>'.$langs->trans("Year").'</td>';
724 print '<td>'.$langs->trans("Month").'</td>';
725 print '<td>'.$langs->trans("Day").'</td>';
726 print '<td></td>';
727 print "</tr>\n";
728
729 $disabled = 1;
730 $prefix = 'close';
731
732 print '<tr class="oddeven">';
733 print '<td>'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).'</td>';
734 print '<input type="hidden" name="posmodule" value="'.$object->posmodule.'">';
735 print '<td>';
736
737 $array = array();
738 $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
739 for($i = 1; $i <= $numterminals; $i++) {
740 $array[$i] = $i;
741 }
742 $selectedposnumber = $object->posnumber; $showempty = 1;
743 //print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty, 0, 0, '', 0, 0, $disabled);
744 print '<input name="posnumberbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->posnumber.'">';
745 print '<input type="hidden" name="posnumber" value="'.$object->posmodule.'">';
746 print '</td>';
747 // Year
748 print '<td>';
749 print '<input name="yearbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->year_close.'">';
750 print '<input type="hidden" name="year_close" value="'.$object->year_close.'">';
751 print '</td>';
752 // Month
753 print '<td>';
754 print '<input name="monthbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->month_close.'">';
755 print '<input type="hidden" name="month_close" value="'.$object->month_close.'">';
756 print '</td>';
757 // Day
758 print '<td>';
759 print '<input name="daybis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->date_close.'">';
760 print '<input type="hidden" name="day_close" value="'.$object->date_close.'">';
761 print '</td>';
762
763 print '<td></td>';
764 print '</table>';
765 print '</div>';
766 */
767
768 // Table to see/enter balance
769 if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
770 $posmodule = $object->posmodule;
771 $terminalid = $object->posnumber;
772
773 print '<br>';
774
775 print '<div class="div-table-responsive-no-min">';
776 print '<table class="noborder centpercent">';
777
778 print '<tr class="liste_titre">';
779 print '<td></td>';
780 print '<td class="center">'.$langs->trans("InitialBankBalance");
781 //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
782 print '</td>';
783
784 print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
785 print $langs->trans("AmountAtEndOfPeriod");
786 print '</td>';
787 print '<td></td>';
788 print '</tr>';
789
790 print '<tr class="liste_titre">';
791 print '<td></td>';
792 print '<td class="center">'.$langs->trans("Cash");
793 //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
794 print '</td>';
795 $i = 0;
796 foreach ($arrayofpaymentmode as $key => $val) {
797 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
798 //print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
799 print '</td>';
800 $i++;
801 }
802 print '<td></td>';
803 print '</tr>';
804
805 print '<tr>';
806 // Initial amount
807 print '<td>'.$langs->trans("NbOfInvoices").'</td>';
808 print '<td class="center">';
809 print '</td>';
810 // Amount per payment type
811 $i = 0;
812 foreach ($arrayofpaymentmode as $key => $val) {
813 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
814 print $theoricalnbofinvoiceforterminal[$terminalid][$key];
815 print '</td>';
816 $i++;
817 }
818 // Save
819 print '<td align="center"></td>';
820 print '</tr>';
821
822 print '<tr>';
823 // Initial amount
824 print '<td>'.$langs->trans("TheoricalAmount").'</td>';
825 print '<td class="center">';
826 print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
827 print '</td>';
828 // Amount per payment type
829 $i = 0;
830 foreach ($arrayofpaymentmode as $key => $val) {
831 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
832 if ($key == 'cash') {
833 $deltaforcash = ($object->opening - $initialbalanceforterminal[$terminalid]['cash']);
834 print price($theoricalamountforterminal[$terminalid][$key] + $deltaforcash).'<br>';
835 } else {
836 print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
837 }
838 print '</td>';
839 $i++;
840 }
841 // Save
842 print '<td align="center"></td>';
843 print '</tr>';
844
845 print '<tr>';
846 print '<td>'.$langs->trans("RealAmount").'</td>';
847 // Initial amount
848 print '<td class="center">';
849 print '<input ';
850 if ($action == 'close') {
851 print 'disabled '; // To close cash user can't set opening cash
852 }
853 print 'name="opening" type="text" class="maxwidth100 center" value="';
854 if ($action == 'close') {
855 $object->fetch($id);
856 print $object->opening;
857 } else {
858 print(GETPOSTISSET('opening') ? price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
859 }
860 print '">';
861 print '</td>';
862 // Amount per payment type
863 $i = 0;
864 foreach ($arrayofpaymentmode as $key => $val) {
865 print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
866 print '<input ';
867 if ($action == 'start') {
868 print 'disabled '; // To start cash user only can set opening cash
869 }
870 print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
871 print '</td>';
872 $i++;
873 }
874 // Save
875 print '<td class="center">';
876 print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
877 if ($action == 'start') {
878 print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
879 } elseif ($action == 'close') {
880 print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Close").'">';
881 }
882 print '</td>';
883 print '</tr>';
884
885 print '</table>';
886 print '</div>';
887 }
888
889 print '</form>';
890 }
891 }
892}
893
894// End of page
895llxFooter();
896$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.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:594
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:613
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...
getDolGlobalString($key, $default='')
Return 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.