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