From b0652494b50c2b271971c0f0ca69f52e03129f3d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 19 Dec 2018 15:40:01 +0100 Subject: [PATCH] Debug cash fence --- htdocs/cashdesk/admin/cashdesk.php | 7 +- .../compta/cashcontrol/cashcontrol_card.php | 189 ++++++++++++++++-- .../cashcontrol/class/cashcontrol.class.php | 4 +- htdocs/langs/en_US/cashdesk.lang | 1 + htdocs/takepos/admin/setup.php | 7 +- 5 files changed, 179 insertions(+), 29 deletions(-) diff --git a/htdocs/cashdesk/admin/cashdesk.php b/htdocs/cashdesk/admin/cashdesk.php index 399a59b4687..7bc587bd67b 100644 --- a/htdocs/cashdesk/admin/cashdesk.php +++ b/htdocs/cashdesk/admin/cashdesk.php @@ -121,7 +121,7 @@ print "\n"; print ''.$langs->trans("CashDeskThirdPartyForSell").''; print ''; -print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY,'socid','s.client in (1,3) AND s.status = 1',1,0,1,array(),0); +print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY,'socid','s.client in (1,3) AND s.status = 1', 1, 0, 0, array(), 0); print ''; if (! empty($conf->banque->enabled)) { @@ -157,7 +157,8 @@ if (! empty($conf->stock->enabled)) if (!$conf->global->CASHDESK_NO_DECREASE_STOCK) { $res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",1,'chaine',0,'',$conf->entity); } - print $langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch'); + print $langs->trans("Yes").'
'; + print ''.$langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch').''; } print ''; @@ -173,7 +174,7 @@ if (! empty($conf->stock->enabled)) } else { - print $langs->trans("StockDecreaseForPointOfSaleDisabled"); + print ''.$langs->trans("StockDecreaseForPointOfSaleDisabled").''; } print ''; } diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index 11c86e53af3..6d446580353 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -1,4 +1,6 @@ * Copyright (C) 2004-2013 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin @@ -28,6 +30,7 @@ */ require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php'; $langs->loadLangs(array("cashcontrol","install","cashdesk","admin","banks")); @@ -38,7 +41,10 @@ $action=GETPOST('action','aZ09'); $categid = GETPOST('categid'); $label = GETPOST("label"); -if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) or empty($conf->global->CASHDESK_ID_BANKACCOUNT_CB)) setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors'); +$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")); $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); @@ -78,6 +84,16 @@ $hookmanager->initHooks(array('cashcontrolcard','globalcard')); * Actions */ +if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH)) +{ + setEventMessages($langs->trans("CashDesk")." - ".$langs->trans("NotConfigured"), null, 'errors'); +} + + +if (GETPOST('cancel')) +{ + $action = 'create'; +} if ($action=="start") { $error=0; @@ -102,13 +118,13 @@ if ($action=="start") } elseif ($action=="add") { - $error=0; if (GETPOST('opening','alpha') == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("InitialBankBalance")), null, 'errors'); $action='start'; $error++; } + $error=0; foreach($arrayofpaymentmode as $key=>$val) { if (GETPOST($key,'alpha') == '') @@ -133,9 +149,20 @@ elseif ($action=="add") $object->posmodule=GETPOST('posmodule','alpha'); $object->posnumber=GETPOST('posnumber','alpha'); - $id=$object->create($user); + $db->begin(); - $action="view"; + $id=$object->create($user); + + if ($id > 0) + { + $db->commit(); + $action="view"; + } + else + { + $db->rollback; + $action="view"; + } } } @@ -171,16 +198,86 @@ if ($action=="create" || $action=="start") $initialbalanceforterminal=array(); $theoricalamountforterminal=array(); - if (GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') + if (GETPOST('posnumber','alpha') != '' && GETPOST('posnumber','alpha') != '' && GETPOST('posnumber','alpha') != '-1') { - // Calculate $initialbalanceforterminal and $theoricalamountforterminal for terminal 0 - // TODO + $posmodule = GETPOST('posmodule','alpha'); + $terminalid = GETPOST('posnumber','alpha'); + + // Calculate $initialbalanceforterminal for terminal 0 + foreach($arrayofpaymentmode as $key => $val) + { + if ($key != 'cash') + { + $initialbalanceforterminal[$terminalid][$key] = 0; + continue; + } + + // Get the bank account dedicated to this point of sale module/terminal + $bankid = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; // This value is ok for 'Terminal 0' for module 'CashDesk' and 'TakePos' (they manage only 1 terminal) + // Hook to get the good bank id according to posmodule and posnumber. + // @TODO add hook here + + $sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank"; + $sql.= " WHERE fk_account = ".$bankid; + 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 dol_print_error('', 'Year not defined'); + + $resql = $db->query($sql); + if ($resql) + { + $obj = $db->fetch_object($resql); + if ($obj) $initialbalanceforterminal[$terminalid][$key] = $obj->total; + } + else dol_print_error($db); + } + + // Calculate $theoricalamountforterminal for terminal 0 + foreach($arrayofpaymentmode as $key => $val) + { + /*$sql = "SELECT SUM(amount) as total FROM ".MAIN_DB_PREFIX."bank"; + $sql.= " WHERE fk_account = ".$bankid;*/ + + $sql = "SELECT SUM(pf.amount) as total"; + $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').")"; + 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 + { + dol_print_error('Value for key = '.$key.' not supported'); + exit; + } + 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 dol_print_error('', 'Year not defined'); + + $resql = $db->query($sql); + if ($resql) + { + $theoricalamountforterminal[$terminalid][$key] = $initialbalanceforterminal[$terminalid][$key]; + + $obj = $db->fetch_object($resql); + if ($obj) + { + $theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total); + } + } + else dol_print_error($db); + } } print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'title_bank.png'); print '
'; - if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') + if ($action == 'start' && GETPOST('posnumber','int') != '' && GETPOST('posnumber','int') != '' && GETPOST('posnumber','int') != '-1') { print ''; } @@ -198,10 +295,6 @@ if ($action=="create" || $action=="start") print ''; print "\n"; - $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")); $disabled=0; $prefix='close'; @@ -242,6 +335,7 @@ if ($action=="create" || $action=="start") $retstring.=""; print $retstring; print ''; + // Button Start print ''; if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') { @@ -256,28 +350,81 @@ if ($action=="create" || $action=="start") if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') { + $posmodule = GETPOST('posmodule','alpha'); + $terminalid = GETPOST('posnumber','alpha'); + + print '
'; + print ''; + print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + $i=0; foreach($arrayofpaymentmode as $key => $val) { - print ''; + print ''; + $i++; } print ''; print ''; + print ''; // Initial amount - print ''; + print ''; + print ''; + // Amount per payment type + $i=0; foreach($arrayofpaymentmode as $key => $val) { - print ''; + $i++; } - - print ''; + // Save + print ''; print ''; + + print ''; + print ''; + // Initial amount + print ''; + // Amount per payment type + $i=0; + foreach($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + } + // Save + print ''; + print ''; + print ''; } print ''; @@ -342,7 +489,7 @@ if (empty($action) || $action=="view") print dol_print_date($object->date_creation, 'dayhour'); print ''; - print '"; diff --git a/htdocs/compta/cashcontrol/class/cashcontrol.class.php b/htdocs/compta/cashcontrol/class/cashcontrol.class.php index 0acb9c0dd82..fdf77b17961 100644 --- a/htdocs/compta/cashcontrol/class/cashcontrol.class.php +++ b/htdocs/compta/cashcontrol/class/cashcontrol.class.php @@ -52,7 +52,7 @@ class CashControl extends CommonObject /** * @var string String with name of icon for pos_cash_fence. Must be the part after the 'object_' into object_pos_cash_fence.png */ - public $picto = 'bank'; + public $picto = 'account'; public $fields=array( 'rowid' =>array('type'=>'integer', 'label'=>'ID', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'position'=>10), @@ -141,7 +141,7 @@ class CashControl extends CommonObject $sql .= ") VALUES ("; //$sql .= "'(PROV)', "; $sql .= $conf->entity; - $sql .= ", ".($this->opening > 0 ? $this->opening : 0); + $sql .= ", ".(is_numeric($this->opening) ? $this->opening : 0); $sql .= ", 0"; // Draft by default $sql .= ", '".$this->db->idate(dol_now())."'"; $sql .= ", '".$this->db->escape($this->posmodule)."'"; diff --git a/htdocs/langs/en_US/cashdesk.lang b/htdocs/langs/en_US/cashdesk.lang index 353c4ee93ab..73b2b4f6b37 100644 --- a/htdocs/langs/en_US/cashdesk.lang +++ b/htdocs/langs/en_US/cashdesk.lang @@ -42,3 +42,4 @@ Place=Place TakeposConnectorNecesary='TakePOS Connector' required OrderPrinters=Order printers SearchProduct=Search product +AmountAtEndOfPeriod=Amount at end of period (day, month or year) \ No newline at end of file diff --git a/htdocs/takepos/admin/setup.php b/htdocs/takepos/admin/setup.php index e2f944d6641..aaec165baa5 100644 --- a/htdocs/takepos/admin/setup.php +++ b/htdocs/takepos/admin/setup.php @@ -152,7 +152,7 @@ print "\n"; print ''; print ''; if (! empty($conf->banque->enabled)) { @@ -188,7 +188,8 @@ if (! empty($conf->stock->enabled)) if (!$conf->global->CASHDESK_NO_DECREASE_STOCK) { $res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",1,'chaine',0,'',$conf->entity); } - print $langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch'); + print $langs->trans("Yes").'
'; + print ''.$langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch').''; } print ''; @@ -204,7 +205,7 @@ if (! empty($conf->stock->enabled)) } else { - print $langs->trans("StockDecreaseForPointOfSaleDisabled"); + print ''.$langs->trans("StockDecreaseForPointOfSaleDisabled").''; } print ''; }
'.$langs->trans("InitialBankBalance").''.$langs->trans("InitialBankBalance"); + //print '
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount"); + print '
'; + print $langs->trans("AmountAtEndOfPeriod"); + print '
'.$langs->trans("Cash"); + //print '
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount"); + print '
'.$langs->trans($val).'
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount").'
'.$langs->trans($val); + //print '
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount"); + print '
'.$langs->trans("TheoricalAmount").''; + print price($initialbalanceforterminal[$terminalid]['cash']).'
'; + print '
'; - print price($theoricalamountforterminal[0][$key]).'
'; - print ''; + print '
'; + print price($theoricalamountforterminal[$terminalid][$key]).'
'; print '
'.$langs->trans("RealAmount").''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'.$langs->trans("InitialBankBalance").''; + print '
'.$langs->trans("InitialBankBalance").' - '.$langs->trans("Cash").''; print price($object->opening, 0, $langs, 1, -1, -1, $conf->currency); print "
'.$langs->trans("CashDeskThirdPartyForSell").''; -print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY,'socid','s.client in (1,3) AND s.status = 1',1,0,1,array(),0); +print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY, 'socid', 's.client in (1,3) AND s.status = 1', 1, 0, 0, array(), 0); print '