dolibarr/htdocs/compta/cashcontrol/cashcontrol_card.php

890 lines
31 KiB
PHP
Raw Normal View History

2018-12-08 21:33:54 +01:00
<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-12-08 21:33:54 +01:00
*/
/**
2018-12-16 16:47:09 +01:00
* \file htdocs/compta/cashcontrol/cashcontrol_card.php
* \ingroup cashdesk|takepos
* \brief Page to show a cash fence
2018-12-08 21:33:54 +01:00
*/
2018-12-15 19:20:30 +01:00
require '../../main.inc.php';
2020-10-27 10:19:00 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
2018-12-19 15:40:01 +01:00
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
2018-12-15 18:27:38 +01:00
require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
2018-12-08 21:33:54 +01:00
$langs->loadLangs(array("install", "cashdesk", "admin", "banks"));
2018-12-08 21:33:54 +01:00
$id = GETPOST('id', 'int');
2018-12-17 10:37:56 +01:00
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'aZ09');
2018-12-08 21:33:54 +01:00
$categid = GETPOST('categid');
$label = GETPOST("label");
$now = dol_now();
$syear = (GETPOSTISSET('closeyear') ?GETPOST('closeyear', 'int') : dol_print_date($now, "%Y"));
$smonth = (GETPOSTISSET('closemonth') ?GETPOST('closemonth', 'int') : dol_print_date($now, "%m"));
$sday = (GETPOSTISSET('closeday') ?GETPOST('closeday', 'int') : dol_print_date($now, "%d"));
2018-12-08 21:33:54 +01:00
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-02-23 21:09:01 +01:00
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
2018-12-15 19:20:30 +01:00
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
2021-02-23 21:09:01 +01:00
if (!$sortfield) {
$sortfield = 'rowid';
}
if (!$sortorder) {
$sortorder = 'ASC';
}
2020-03-30 20:05:45 +02:00
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'thirdpartylist';
2021-02-23 21:09:01 +01:00
if ($contextpage == 'takepos') {
$_GET['optioncss'] = 'print';
2020-03-30 20:05:45 +02:00
}
2018-12-15 19:20:30 +01:00
$arrayofpaymentmode = array('cash'=>'Cash', 'cheque'=>'Cheque', 'card'=>'CreditCard');
2018-12-16 16:47:09 +01:00
$arrayofposavailable = array();
2022-08-29 11:58:27 +02:00
if (isModEnabled('cashdesk')) {
2021-02-23 21:09:01 +01:00
$arrayofposavailable['cashdesk'] = $langs->trans('CashDesk').' (cashdesk)';
}
2022-08-29 11:58:27 +02:00
if (isModEnabled('takepos')) {
2021-02-23 21:09:01 +01:00
$arrayofposavailable['takepos'] = $langs->trans('TakePOS').' (takepos)';
}
2018-12-16 16:47:09 +01:00
// TODO Add hook here to allow other POS to add themself
$object = new CashControl($db);
2018-12-17 10:37:56 +01:00
$extrafields = new ExtraFields($db);
2018-12-16 16:47:09 +01:00
2018-12-17 10:37:56 +01:00
// fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
2018-12-17 10:37:56 +01:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('cashcontrolcard', 'globalcard'));
2018-12-15 19:20:30 +01:00
2020-03-15 13:57:31 +01:00
// Load object
include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
2021-03-18 14:41:48 +01:00
// Security check
if ($user->socid > 0) { // Protection if external user
//$socid = $user->socid;
accessforbidden();
}
if (!$user->rights->cashdesk->run && !$user->rights->takepos->run) {
accessforbidden();
}
2018-12-15 19:56:08 +01:00
2018-12-08 21:33:54 +01:00
/*
2018-12-15 19:56:08 +01:00
* Actions
2018-12-08 21:33:54 +01:00
*/
2018-12-15 19:56:08 +01:00
2020-01-25 14:23:23 +01:00
$permissiontoadd = ($user->rights->cashdesk->run || $user->rights->takepos->run);
$permissiontodelete = ($user->rights->cashdesk->run || $user->rights->takepos->run) || ($permissiontoadd && $object->status == 0);
2021-02-23 21:09:01 +01:00
if (empty($backtopage)) {
$backtopage = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.($id > 0 ? $id : '__ID__');
2021-02-23 21:09:01 +01:00
}
$backurlforlist = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php';
$triggermodname = 'CACHCONTROL_MODIFY'; // Name of trigger action code to execute when we modify record
2019-01-03 14:18:02 +01:00
2021-02-23 21:09:01 +01:00
if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) && empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH1)) {
2018-12-19 15:40:01 +01:00
setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors');
}
2021-02-23 21:09:01 +01:00
if (GETPOST('cancel', 'alpha')) {
2020-03-15 13:57:31 +01:00
if ($action == 'valid') {
$action = 'view';
2020-05-21 15:05:19 +02:00
} else {
2020-03-15 13:57:31 +01:00
$action = 'create';
}
}
2021-02-23 21:09:01 +01:00
if ($action == "reopen") {
2020-03-15 13:57:31 +01:00
$result = $object->setStatut($object::STATUS_DRAFT, null, '', 'CASHFENCE_REOPEN');
if ($result < 0) {
2021-11-10 12:06:39 +01:00
setEventMessages($object->error, $object->error, 'errors');
2020-03-15 13:57:31 +01:00
}
$action = 'view';
2018-12-19 15:40:01 +01:00
}
2019-01-03 14:18:02 +01:00
2021-02-23 21:09:01 +01:00
if ($action == "start") {
$error = 0;
2021-02-23 21:09:01 +01:00
if (!GETPOST('posmodule', 'alpha') || GETPOST('posmodule', 'alpha') == '-1') {
2018-12-16 15:30:31 +01:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Module")), null, 'errors');
$action = 'create';
2018-12-16 15:30:31 +01:00
$error++;
}
2021-02-23 21:09:01 +01:00
if (GETPOST('posnumber', 'alpha') == '') {
2018-12-16 16:47:09 +01:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CashDesk")), null, 'errors');
$action = 'create';
2018-12-16 16:47:09 +01:00
$error++;
}
2021-02-23 21:09:01 +01:00
if (!GETPOST('closeyear', 'alpha') || GETPOST('closeyear', 'alpha') == '-1') {
2018-12-16 16:47:09 +01:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Year")), null, 'errors');
$action = 'create';
2018-12-16 16:47:09 +01:00
$error++;
}
2021-02-23 21:09:01 +01:00
} elseif ($action == "add") {
if (GETPOST('opening', 'alpha') == '') {
2018-12-16 15:30:31 +01:00
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InitialBankBalance")), null, 'errors');
$action = 'start';
2018-12-16 15:30:31 +01:00
$error++;
}
$error = 0;
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
2019-08-18 09:33:02 +02:00
$object->$key = price2num(GETPOST($key.'_amount', 'alpha'));
2018-12-16 16:47:09 +01:00
}
2021-02-23 21:09:01 +01:00
if (!$error) {
2018-12-17 10:37:56 +01:00
$object->day_close = GETPOST('closeday', 'int');
$object->month_close = GETPOST('closemonth', 'int');
$object->year_close = GETPOST('closeyear', 'int');
2018-12-16 16:47:09 +01:00
$object->opening = price2num(GETPOST('opening', 'alpha'));
$object->posmodule = GETPOST('posmodule', 'alpha');
$object->posnumber = GETPOST('posnumber', 'alpha');
2018-12-16 16:47:09 +01:00
2018-12-19 15:40:01 +01:00
$db->begin();
2018-12-16 16:47:09 +01:00
$id = $object->create($user);
2018-12-19 15:40:01 +01:00
2021-02-23 21:09:01 +01:00
if ($id > 0) {
2018-12-19 15:40:01 +01:00
$db->commit();
$action = "view";
2020-05-21 15:05:19 +02:00
} else {
2018-12-19 15:40:01 +01:00
$db->rollback;
$action = "view";
2018-12-19 15:40:01 +01:00
}
2018-12-16 15:30:31 +01:00
}
if ($contextpage == 'takepos') {
2020-03-30 20:05:45 +02:00
print "
<script>
parent.location.href='../../takepos/index.php?place='+parent.place;
</script>";
exit;
}
2018-12-08 21:33:54 +01:00
}
2021-02-23 21:09:01 +01:00
if ($action == "valid") { // validate = close
$object->fetch($id);
2020-03-15 13:57:31 +01:00
$db->begin();
/*
$object->day_close = GETPOST('closeday', 'int');
$object->month_close = GETPOST('closemonth', 'int');
$object->year_close = GETPOST('closeyear', 'int');
*/
$object->cash = price2num(GETPOST('cash_amount', 'alpha'));
$object->card = price2num(GETPOST('card_amount', 'alpha'));
$object->cheque = price2num(GETPOST('cheque_amount', 'alpha'));
$result = $object->update($user);
$result = $object->valid($user);
2021-02-23 21:09:01 +01:00
if ($result <= 0) {
2018-12-17 10:37:56 +01:00
setEventMessages($object->error, $object->errors, 'errors');
2020-03-15 13:57:31 +01:00
$db->rollback();
2020-05-21 15:05:19 +02:00
} else {
setEventMessages($langs->trans("CashFenceDone"), null);
2020-03-15 13:57:31 +01:00
$db->commit();
}
2018-12-17 10:37:56 +01:00
if ($contextpage == 'takepos') {
2020-03-30 20:05:45 +02:00
print "
<script>
parent.location.href='../../takepos/index.php?place='+parent.place;
</script>";
exit;
}
$action = "view";
2018-12-08 21:33:54 +01:00
}
2019-01-03 14:18:02 +01:00
// Action to delete
2021-02-23 21:09:01 +01:00
if ($action == 'confirm_delete' && !empty($permissiontodelete)) {
$object->fetch($id);
2021-02-23 21:09:01 +01:00
if (!($object->id > 0)) {
dol_print_error('', 'Error, object must be fetched before being deleted');
exit;
}
$result = $object->delete($user);
//var_dump($result);
2021-02-23 21:09:01 +01:00
if ($result > 0) {
// Delete OK
setEventMessages("RecordDeleted", null, 'mesgs');
header("Location: ".$backurlforlist);
exit;
} else {
2021-02-23 21:09:01 +01:00
if (!empty($object->errors)) {
setEventMessages(null, $object->errors, 'errors');
} else {
setEventMessages($object->error, null, 'errors');
}
}
2019-01-03 14:18:02 +01:00
}
2018-12-17 10:37:56 +01:00
/*
* View
*/
$form = new Form($db);
2018-12-17 10:37:56 +01:00
2020-03-15 13:57:31 +01:00
$initialbalanceforterminal = array();
$theoricalamountforterminal = array();
$theoricalnbofinvoiceforterminal = array();
2018-12-15 19:20:30 +01:00
2021-02-23 21:09:01 +01:00
if ($action == "create" || $action == "start" || $action == 'close') {
2020-03-15 13:57:31 +01:00
if ($action == 'close') {
$posmodule = $object->posmodule;
$terminalid = $object->posnumber;
$terminaltouse = $terminalid;
2018-12-16 16:47:09 +01:00
2020-03-15 13:57:31 +01:00
$syear = $object->year_close;
$smonth = $object->month_close;
$sday = $object->day_close;
2021-02-23 21:09:01 +01:00
} elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') {
$posmodule = GETPOST('posmodule', 'alpha');
$terminalid = GETPOST('posnumber', 'alpha');
2019-05-09 14:36:48 +02:00
$terminaltouse = $terminalid;
2021-02-23 21:09:01 +01:00
if ($terminaltouse == '1' && $posmodule == 'cashdesk') {
$terminaltouse = '';
}
2018-12-19 15:40:01 +01:00
if ($posmodule == 'cashdesk' && $terminaltouse != '' && $terminaltouse != '1') {
$terminaltouse = '';
setEventMessages($langs->trans("OnlyTerminal1IsAvailableForCashDeskModule"), null, 'errors');
$error++;
}
2020-03-15 13:57:31 +01:00
}
2021-02-23 21:09:01 +01:00
if ($terminalid != '') {
2018-12-19 15:40:01 +01:00
// Calculate $initialbalanceforterminal for terminal 0
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
if ($key != 'cash') {
2018-12-19 15:40:01 +01:00
$initialbalanceforterminal[$terminalid][$key] = 0;
continue;
}
// Get the bank account dedicated to this point of sale module/terminal
$vartouse = 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse;
2020-03-15 13:57:31 +01:00
$bankid = $conf->global->$vartouse;
2018-12-19 15:40:01 +01:00
2021-02-23 21:09:01 +01:00
if ($bankid > 0) {
$sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank";
$sql .= " WHERE fk_account = ".((int) $bankid);
2021-02-23 21:09:01 +01:00
if ($syear && !$smonth) {
$sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, 1))."'";
} elseif ($syear && $smonth && !$sday) {
$sql .= " AND dateo < '".$db->idate(dol_get_first_day($syear, $smonth))."'";
} elseif ($syear && $smonth && $sday) {
$sql .= " AND dateo < '".$db->idate(dol_mktime(0, 0, 0, $smonth, $sday, $syear))."'";
} else {
2021-11-10 12:24:53 +01:00
setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
2021-02-23 21:09:01 +01:00
}
$resql = $db->query($sql);
2021-02-23 21:09:01 +01:00
if ($resql) {
$obj = $db->fetch_object($resql);
2021-02-23 21:09:01 +01:00
if ($obj) {
$initialbalanceforterminal[$terminalid][$key] = $obj->total;
}
} else {
dol_print_error($db);
}
2020-05-21 15:05:19 +02:00
} else {
setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminaltouse), null, 'errors');
$error++;
2018-12-19 15:40:01 +01:00
}
}
2020-03-15 13:57:31 +01:00
// Calculate $theoricalamountforterminal
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
2019-01-07 19:02:38 +01:00
$sql = "SELECT SUM(pf.amount) as total, COUNT(*) as nb";
$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";
$sql .= " WHERE pf.fk_facture = f.rowid AND p.rowid = pf.fk_paiement AND cp.id = p.fk_paiement";
$sql .= " AND f.module_source = '".$db->escape($posmodule)."'";
$sql .= " AND f.pos_source = '".$db->escape($terminalid)."'";
$sql .= " AND f.paye = 1";
$sql .= " AND p.entity IN (".getEntity('facture').")";
2021-02-23 21:09:01 +01:00
if ($key == 'cash') {
$sql .= " AND cp.code = 'LIQ'";
} elseif ($key == 'cheque') {
$sql .= " AND cp.code = 'CHQ'";
} elseif ($key == 'card') {
$sql .= " AND cp.code = 'CB'";
} else {
2018-12-19 15:40:01 +01:00
dol_print_error('Value for key = '.$key.' not supported');
exit;
}
2021-02-23 21:09:01 +01:00
if ($syear && !$smonth) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, 1))."' AND '".$db->idate(dol_get_last_day($syear, 12))."'";
} elseif ($syear && $smonth && !$sday) {
$sql .= " AND datef BETWEEN '".$db->idate(dol_get_first_day($syear, $smonth))."' AND '".$db->idate(dol_get_last_day($syear, $smonth))."'";
} elseif ($syear && $smonth && $sday) {
$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))."'";
} else {
2021-11-10 12:24:53 +01:00
setEventMessages($langs->trans('YearNotDefined'), null, 'errors');
2021-02-23 21:09:01 +01:00
}
2018-12-19 15:40:01 +01:00
$resql = $db->query($sql);
2021-02-23 21:09:01 +01:00
if ($resql) {
2018-12-19 15:40:01 +01:00
$theoricalamountforterminal[$terminalid][$key] = $initialbalanceforterminal[$terminalid][$key];
$obj = $db->fetch_object($resql);
2021-02-23 21:09:01 +01:00
if ($obj) {
2018-12-19 15:40:01 +01:00
$theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total);
2019-01-07 19:02:38 +01:00
$theoricalnbofinvoiceforterminal[$terminalid][$key] = $obj->nb;
2018-12-19 15:40:01 +01:00
}
2021-02-23 21:09:01 +01:00
} else {
dol_print_error($db);
}
2018-12-19 15:40:01 +01:00
}
2018-12-16 16:47:09 +01:00
}
2018-12-15 19:20:30 +01:00
2020-03-15 13:57:31 +01:00
//var_dump($theoricalamountforterminal); var_dump($theoricalnbofinvoiceforterminal);
if ($action != 'close') {
llxHeader('', $langs->trans("NewCashFence"));
2018-12-16 16:47:09 +01:00
2020-03-15 13:57:31 +01:00
print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register');
2020-02-05 21:08:55 +01:00
2020-03-15 13:57:31 +01:00
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2021-02-23 21:09:01 +01:00
if ($contextpage == 'takepos') {
print '<input type="hidden" name="contextpage" value="takepos">';
}
if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
print '<input type="hidden" name="action" value="add">';
2021-02-23 21:09:01 +01:00
} elseif ($action == 'close') {
print '<input type="hidden" name="action" value="valid">';
2020-03-15 13:57:31 +01:00
print '<input type="hidden" name="id" value="'.$id.'">';
} else {
print '<input type="hidden" name="action" value="start">';
}
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Module").'</td>';
print '<td>'.$langs->trans("Terminal").'</td>';
print '<td>'.$langs->trans("Year").'</td>';
print '<td>'.$langs->trans("Month").'</td>';
print '<td>'.$langs->trans("Day").'</td>';
print '<td></td>';
print "</tr>\n";
2020-03-15 13:57:31 +01:00
$disabled = 0;
$prefix = 'close';
print '<tr class="oddeven">';
print '<td>'.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable) > 1 ? 1 : 0)).'</td>';
print '<td>';
$array = array();
$numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
for ($i = 1; $i <= $numterminals; $i++) {
$array[$i] = $i;
}
2021-03-01 20:37:16 +01:00
$selectedposnumber = 0;
$showempty = 1;
2021-02-23 21:09:01 +01:00
if ($conf->global->TAKEPOS_NUM_TERMINALS == '1') {
2021-03-01 20:37:16 +01:00
$selectedposnumber = 1;
$showempty = 0;
}
print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty);
//print '<input name="posnumber" type="text" class="maxwidth50" value="'.(GETPOSTISSET('posnumber')?GETPOST('posnumber', 'alpha'):'0').'">';
print '</td>';
2020-03-15 13:57:31 +01:00
// Year
print '<td>';
$retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">';
2021-02-23 21:09:01 +01:00
for ($year = $syear - 10; $year < $syear + 10; $year++) {
2020-03-15 13:57:31 +01:00
$retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>';
}
$retstring .= "</select>\n";
print $retstring;
2018-12-19 15:40:01 +01:00
print '</td>';
2020-03-15 13:57:31 +01:00
// Month
print '<td>';
$retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">';
$retstring .= '<option value="0"></option>';
2021-02-23 21:09:01 +01:00
for ($month = 1; $month <= 12; $month++) {
2020-03-15 13:57:31 +01:00
$retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>';
$retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b");
$retstring .= "</option>";
2018-12-16 16:47:09 +01:00
}
2020-03-15 13:57:31 +01:00
$retstring .= "</select>";
print $retstring;
2019-01-07 19:02:38 +01:00
print '</td>';
2020-03-15 13:57:31 +01:00
// Day
print '<td>';
$retstring = '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">';
$retstring .= '<option value="0" selected>&nbsp;</option>';
2021-02-23 21:09:01 +01:00
for ($day = 1; $day <= 31; $day++) {
2020-03-15 13:57:31 +01:00
$retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>';
2019-01-07 19:02:38 +01:00
}
2020-03-15 13:57:31 +01:00
$retstring .= "</select>";
print $retstring;
2018-12-19 15:40:01 +01:00
print '</td>';
2020-03-15 13:57:31 +01:00
// Button Start
print '<td>';
2021-02-23 21:09:01 +01:00
if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') {
2020-03-15 13:57:31 +01:00
print '';
2020-05-21 15:05:19 +02:00
} else {
2020-03-15 13:57:31 +01:00
print '<input type="submit" name="add" class="button" value="'.$langs->trans("Start").'">';
2020-02-05 21:08:55 +01:00
}
2018-12-19 15:40:01 +01:00
print '</td>';
2020-03-15 13:57:31 +01:00
print '</table>';
print '</div>';
// Table to see/enter balance
2021-02-23 21:09:01 +01:00
if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
2020-03-15 13:57:31 +01:00
$posmodule = GETPOST('posmodule', 'alpha');
$terminalid = GETPOST('posnumber', 'alpha');
print '<br>';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td></td>';
print '<td class="center">'.$langs->trans("InitialBankBalance");
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
/*
print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
print $langs->trans("AmountAtEndOfPeriod");
print '</td>';
*/
print '<td></td>';
print '</tr>';
print '<tr class="liste_titre">';
print '<td></td>';
print '<td class="center">'.$langs->trans("Cash");
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
/*
$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
$i++;
}*/
print '<td></td>';
print '</tr>';
/*print '<tr>';
// Initial amount
print '<td>'.$langs->trans("NbOfInvoices").'</td>';
print '<td class="center">';
print '</td>';
// Amount per payment type
$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
2021-02-23 21:09:01 +01:00
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print $theoricalnbofinvoiceforterminal[$terminalid][$key];
print '</td>';
$i++;
2020-03-15 13:57:31 +01:00
}
// Save
print '<td align="center"></td>';
print '</tr>';
*/
print '<tr>';
// Initial amount
print '<td>'.$langs->trans("TheoricalAmount").'</td>';
print '<td class="center">';
print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
print '</td>';
// Amount per payment type
/*$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
print '</td>';
$i++;
}*/
// Save
print '<td></td>';
print '</tr>';
print '<tr>';
print '<td>'.$langs->trans("RealAmount").'</td>';
// Initial amount
print '<td class="center">';
2020-02-05 21:08:55 +01:00
print '<input ';
2021-02-23 21:09:01 +01:00
if ($action == 'close') {
print 'disabled '; // To close cash user can't set opening cash
}
2020-03-15 13:57:31 +01:00
print 'name="opening" type="text" class="maxwidth100 center" value="';
2021-02-23 21:09:01 +01:00
if ($action == 'close') {
2020-03-15 13:57:31 +01:00
$object->fetch($id);
print $object->opening;
2021-02-23 21:09:01 +01:00
} else {
print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
}
2020-03-15 13:57:31 +01:00
print '">';
2018-12-19 15:40:01 +01:00
print '</td>';
2020-03-15 13:57:31 +01:00
// Amount per payment type
/*$i = 0;
foreach ($arrayofpaymentmode as $key => $val)
{
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print '<input ';
if ($action == 'start') print 'disabled '; // To start cash user only can set opening cash
print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
print '</td>';
$i++;
}*/
// Save
print '<td class="center">';
print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
2021-02-23 21:09:01 +01:00
if ($action == 'start') {
print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
} elseif ($action == 'close') {
print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Validate").'">';
}
2020-03-15 13:57:31 +01:00
print '</td>';
print '</tr>';
print '</table>';
print '</div>';
2018-12-19 15:40:01 +01:00
}
print '</form>';
2018-12-16 16:47:09 +01:00
}
2018-12-08 21:33:54 +01:00
}
2021-02-23 21:09:01 +01:00
if (empty($action) || $action == "view" || $action == "close") {
$result = $object->fetch($id);
2018-12-17 10:37:56 +01:00
llxHeader('', $langs->trans("CashControl"));
2018-12-17 10:37:56 +01:00
if ($result <= 0) {
print $langs->trans("ErrorRecordNotFound");
} else {
$head = array();
$head[0][0] = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$object->id;
$head[0][1] = $langs->trans("CashControl");
$head[0][2] = 'cashcontrol';
print dol_get_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'account');
2018-12-17 10:37:56 +01:00
$linkback = '<a href="'.DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
2018-12-17 10:37:56 +01:00
$morehtmlref = '<div class="refidno">';
$morehtmlref .= '</div>';
2018-12-17 10:37:56 +01:00
dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'rowid', $morehtmlref);
2018-12-17 10:37:56 +01:00
print '<div class="fichecenter">';
print '<div class="fichehalfleft">';
2019-12-22 20:02:18 +01:00
print '<div class="underbanner clearboth"></div>';
2020-03-15 13:57:31 +01:00
print '<table class="border tableforfield" width="100%">';
2018-12-15 18:27:38 +01:00
2019-12-22 20:02:18 +01:00
print '<tr><td class="titlefield nowrap">';
print $langs->trans("Ref");
print '</td><td>';
print $id;
print '</td></tr>';
2018-12-15 18:27:38 +01:00
2019-12-22 20:02:18 +01:00
print '<tr><td valign="middle">'.$langs->trans("Module").'</td><td>';
print $object->posmodule;
print "</td></tr>";
2018-12-16 15:30:31 +01:00
2020-01-24 16:14:52 +01:00
print '<tr><td valign="middle">'.$langs->trans("Terminal").'</td><td>';
2019-12-22 20:02:18 +01:00
print $object->posnumber;
print "</td></tr>";
2018-12-15 18:27:38 +01:00
2019-12-22 20:02:18 +01:00
print '<tr><td class="nowrap">';
print $langs->trans("Period");
print '</td><td>';
2020-01-24 15:26:18 +01:00
print $object->year_close;
print ($object->month_close ? "-" : "").$object->month_close;
print ($object->day_close ? "-" : "").$object->day_close;
2019-12-22 20:02:18 +01:00
print '</td></tr>';
2018-12-08 21:33:54 +01:00
2019-12-22 20:02:18 +01:00
print '</table>';
print '</div>';
2018-12-16 15:30:31 +01:00
2022-05-23 19:43:31 +02:00
print '<div class="fichehalfright">';
2019-12-22 20:02:18 +01:00
print '<div class="underbanner clearboth"></div>';
2021-10-23 17:18:35 +02:00
print '<table class="border tableforfield centpercent">';
print '<tr><td class="titlefield nowrap">';
print $langs->trans("DateCreationShort");
print '</td><td>';
print dol_print_date($object->date_creation, 'dayhour');
print '</td></tr>';
print '<tr><td valign="middle">'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").'</td><td>';
2022-05-23 20:05:30 +02:00
print '<span class="amount">'.price($object->opening, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
print "</td></tr>";
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
print '<tr><td valign="middle">'.$langs->trans($val).'</td><td>';
2022-05-23 20:05:30 +02:00
print '<span class="amount">'.price($object->$key, 0, $langs, 1, -1, -1, $conf->currency).'</span>';
print "</td></tr>";
}
2018-12-15 18:27:38 +01:00
2019-12-22 20:02:18 +01:00
print "</table>\n";
2021-10-23 17:18:35 +02:00
print '</div></div>';
print '<div style="clear:both"></div>';
2018-12-08 21:33:54 +01:00
print dol_get_fiche_end();
2018-12-15 18:27:38 +01:00
if ($action != 'close') {
2020-03-15 13:57:31 +01:00
print '<div class="tabsAction">';
2019-01-03 14:18:02 +01:00
2021-11-22 02:35:55 +01:00
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>';
2020-03-15 13:57:31 +01:00
2021-02-23 21:09:01 +01:00
if ($object->status == CashControl::STATUS_DRAFT) {
2021-11-22 02:35:55 +01:00
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>';
2018-12-15 18:27:38 +01:00
2021-11-22 02:35:55 +01:00
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>';
2020-03-15 13:57:31 +01:00
} else {
2021-11-22 02:35:55 +01:00
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>';
2020-03-15 13:57:31 +01:00
}
print '</div>';
2021-02-23 21:09:01 +01:00
if ($contextpage != 'takepos') {
print '<center><iframe src="report.php?id='.$id.'" width="60%" height="800"></iframe></center>';
}
} else {
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'" name="formclose">';
print '<input type="hidden" name="token" value="'.newToken().'">';
2021-02-23 21:09:01 +01:00
if ($contextpage == 'takepos') {
print '<input type="hidden" name="contextpage" value="takepos">';
}
if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') {
print '<input type="hidden" name="action" value="add">';
2021-02-23 21:09:01 +01:00
} elseif ($action == 'close') {
print '<input type="hidden" name="action" value="valid">';
print '<input type="hidden" name="id" value="'.$id.'">';
} else {
print '<input type="hidden" name="action" value="start">';
}
2020-03-15 13:57:31 +01:00
/*
2021-02-23 21:09:01 +01:00
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Module").'</td>';
print '<td>'.$langs->trans("Terminal").'</td>';
print '<td>'.$langs->trans("Year").'</td>';
print '<td>'.$langs->trans("Month").'</td>';
print '<td>'.$langs->trans("Day").'</td>';
print '<td></td>';
print "</tr>\n";
$disabled = 1;
$prefix = 'close';
print '<tr class="oddeven">';
print '<td>'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).'</td>';
print '<input type="hidden" name="posmodule" value="'.$object->posmodule.'">';
print '<td>';
$array = array();
$numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS);
for($i = 1; $i <= $numterminals; $i++) {
$array[$i] = $i;
}
$selectedposnumber = $object->posnumber; $showempty = 1;
//print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty, 0, 0, '', 0, 0, $disabled);
print '<input name="posnumberbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->posnumber.'">';
print '<input type="hidden" name="posnumber" value="'.$object->posmodule.'">';
print '</td>';
// Year
print '<td>';
print '<input name="yearbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->year_close.'">';
print '<input type="hidden" name="year_close" value="'.$object->year_close.'">';
print '</td>';
// Month
print '<td>';
print '<input name="monthbis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->month_close.'">';
print '<input type="hidden" name="month_close" value="'.$object->month_close.'">';
print '</td>';
// Day
print '<td>';
print '<input name="daybis" disabled="disabled" type="text" class="maxwidth50" value="'.$object->date_close.'">';
print '<input type="hidden" name="day_close" value="'.$object->date_close.'">';
print '</td>';
2020-03-15 13:57:31 +01:00
print '<td></td>';
2021-02-23 21:09:01 +01:00
print '</table>';
print '</div>';
*/
2020-03-15 13:57:31 +01:00
// Table to see/enter balance
2021-02-23 21:09:01 +01:00
if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') {
$posmodule = $object->posmodule;
$terminalid = $object->posnumber;
print '<br>';
print '<div class="div-table-responsive-no-min">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print '<td></td>';
print '<td class="center">'.$langs->trans("InitialBankBalance");
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
print '<td align="center" class="hide0" colspan="'.count($arrayofpaymentmode).'">';
print $langs->trans("AmountAtEndOfPeriod");
print '</td>';
print '<td></td>';
print '</tr>';
print '<tr class="liste_titre">';
print '<td></td>';
print '<td class="center">'.$langs->trans("Cash");
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
$i = 0;
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>'.$langs->trans($val);
//print '<br>'.$langs->trans("TheoricalAmount").'<br>'.$langs->trans("RealAmount");
print '</td>';
$i++;
}
print '<td></td>';
print '</tr>';
print '<tr>';
// Initial amount
print '<td>'.$langs->trans("NbOfInvoices").'</td>';
print '<td class="center">';
print '</td>';
// Amount per payment type
$i = 0;
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print $theoricalnbofinvoiceforterminal[$terminalid][$key];
print '</td>';
$i++;
}
// Save
print '<td align="center"></td>';
print '</tr>';
print '<tr>';
// Initial amount
print '<td>'.$langs->trans("TheoricalAmount").'</td>';
print '<td class="center">';
print price($initialbalanceforterminal[$terminalid]['cash']).'<br>';
print '</td>';
// Amount per payment type
$i = 0;
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
if ($key == 'cash') {
$deltaforcash = ($object->opening - $initialbalanceforterminal[$terminalid]['cash']);
print price($theoricalamountforterminal[$terminalid][$key] + $deltaforcash).'<br>';
} else {
print price($theoricalamountforterminal[$terminalid][$key]).'<br>';
}
print '</td>';
$i++;
}
// Save
print '<td align="center"></td>';
print '</tr>';
print '<tr>';
print '<td>'.$langs->trans("RealAmount").'</td>';
// Initial amount
print '<td class="center">';
print '<input ';
2021-02-23 21:09:01 +01:00
if ($action == 'close') {
print 'disabled '; // To close cash user can't set opening cash
}
print 'name="opening" type="text" class="maxwidth100 center" value="';
2021-02-23 21:09:01 +01:00
if ($action == 'close') {
$object->fetch($id);
print $object->opening;
2021-02-23 21:09:01 +01:00
} else {
print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash']));
}
print '">';
print '</td>';
// Amount per payment type
$i = 0;
2021-02-23 21:09:01 +01:00
foreach ($arrayofpaymentmode as $key => $val) {
print '<td align="center"'.($i == 0 ? ' class="hide0"' : '').'>';
print '<input ';
2021-02-23 21:09:01 +01:00
if ($action == 'start') {
print 'disabled '; // To start cash user only can set opening cash
}
print 'name="'.$key.'_amount" type="text"'.($key == 'cash' ? ' autofocus' : '').' class="maxwidth100 center" value="'.GETPOST($key.'_amount', 'alpha').'">';
print '</td>';
$i++;
}
// Save
print '<td class="center">';
print '<input type="submit" name="cancel" class="button button-cancel" value="'.$langs->trans("Cancel").'">';
2021-02-23 21:09:01 +01:00
if ($action == 'start') {
print '<input type="submit" name="add" class="button button-save" value="'.$langs->trans("Save").'">';
} elseif ($action == 'close') {
print '<input type="submit" name="valid" class="button" value="'.$langs->trans("Close").'">';
}
print '</td>';
print '</tr>';
2020-03-15 13:57:31 +01:00
print '</table>';
print '</div>';
}
print '</form>';
}
}
2018-12-08 21:33:54 +01:00
}
2018-12-15 18:27:38 +01:00
// End of page
2018-12-08 21:33:54 +01:00
llxFooter();
2018-12-15 18:27:38 +01:00
$db->close();