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