From 22e8fdb46b1affe14c1c08957f544defbc56156e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 15 Mar 2020 13:57:31 +0100 Subject: [PATCH] Enhance #13033 --- .../compta/cashcontrol/cashcontrol_card.php | 688 ++++++++++++------ .../cashcontrol/class/cashcontrol.class.php | 13 + htdocs/compta/cashcontrol/report.php | 9 +- htdocs/core/class/html.form.class.php | 2 +- 4 files changed, 490 insertions(+), 222 deletions(-) diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index 800a7be8084..b66e1a5cb0f 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -77,6 +77,9 @@ $extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('cashcontrolcard', 'globalcard')); +// Load object +include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once. + /* * Actions @@ -96,7 +99,22 @@ if (empty($conf->global->CASHDESK_ID_BANKACCOUNT_CASH) && empty($conf->global->C if (GETPOST('cancel', 'alpha')) { - $action = 'create'; + if ($action == 'valid') { + $action = 'view'; + } + else { + $action = 'create'; + } +} + +if ($action == "reopen") +{ + $result = $object->setStatut($object::STATUS_DRAFT, null, '', 'CASHFENCE_REOPEN'); + if ($result < 0) { + dol_print_error($db, $object->error, $object->error); + } + + $action = 'view'; } if ($action == "start") @@ -162,18 +180,35 @@ elseif ($action == "add") } } -if ($action == "valid") +if ($action == "valid") // validate = close { $object->fetch($id); - $result = $object->valid($user); + $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); + if ($result <= 0) { setEventMessages($object->error, $object->errors, 'errors'); + $db->rollback(); } else { setEventMessages($langs->trans("CashFenceDone"), null); + $db->commit(); } $action = "view"; @@ -213,15 +248,22 @@ if ($action == 'confirm_delete' && !empty($permissiontodelete)) $form = new Form($db); -if ($action == "create" || $action == "start" || $action == "close") +$initialbalanceforterminal = array(); +$theoricalamountforterminal = array(); +$theoricalnbofinvoiceforterminal = array(); + +if ($action == "create" || $action == "start" || $action == 'close') { - llxHeader(); + if ($action == 'close') { + $posmodule = $object->posmodule; + $terminalid = $object->posnumber; + $terminaltouse = $terminalid; - $initialbalanceforterminal = array(); - $theoricalamountforterminal = array(); - $theoricalnbofinvoiceforterminal = array(); - - if (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') + $syear = $object->year_close; + $smonth = $object->month_close; + $sday = $object->day_close; + } + elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') { $posmodule = GETPOST('posmodule', 'alpha'); $terminalid = GETPOST('posnumber', 'alpha'); @@ -234,7 +276,10 @@ if ($action == "create" || $action == "start" || $action == "close") setEventMessages($langs->trans("OnlyTerminal1IsAvailableForCashDeskModule"), null, 'errors'); $error++; } + } + if ($terminalid != '') + { // Calculate $initialbalanceforterminal for terminal 0 foreach ($arrayofpaymentmode as $key => $val) { @@ -246,9 +291,7 @@ if ($action == "create" || $action == "start" || $action == "close") // Get the bank account dedicated to this point of sale module/terminal $vartouse = 'CASHDESK_ID_BANKACCOUNT_CASH'.$terminaltouse; - $bankid = $conf->global->$vartouse; // 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 + $bankid = $conf->global->$vartouse; if ($bankid > 0) { @@ -274,11 +317,9 @@ if ($action == "create" || $action == "start" || $action == "close") } } - // Calculate $theoricalamountforterminal for terminal 0 + // Calculate $theoricalamountforterminal 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, 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"; @@ -315,215 +356,230 @@ if ($action == "create" || $action == "start" || $action == "close") } } - print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register'); + //var_dump($theoricalamountforterminal); var_dump($theoricalnbofinvoiceforterminal); + if ($action != 'close') { + llxHeader(); - print '
'; - print ''; - if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') - { - print ''; - } - elseif ($action == 'close') - { - print ''; - print ''; - } - else - { - print ''; - } + print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register'); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; + print ''; + print ''; + if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') + { + print ''; + } + elseif ($action == 'close') + { + print ''; + print ''; + } + else + { + print ''; + } - $disabled = 0; - $prefix = 'close'; + print '
'; + print '
'.$langs->trans("Module").''.$langs->trans("Terminal").''.$langs->trans("Year").''.$langs->trans("Month").''.$langs->trans("Day").'
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; - print ''; - print ''; - print ''; - // Year - print ''; - // Month - print ''; - // Day - print ''; - // Button Start - print ''; - print '
'.$langs->trans("Module").''.$langs->trans("Terminal").''.$langs->trans("Year").''.$langs->trans("Month").''.$langs->trans("Day").'
'.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable) > 1 ? 1 : 0)).''; + $disabled = 0; + $prefix = 'close'; - $array = array(); - $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS); - for($i = 1; $i <= $numterminals; $i++) { - $array[$i] = $i; - } - $selectedposnumber = 0; $showempty = 1; - if ($conf->global->TAKEPOS_NUM_TERMINALS == '1') - { - $selectedposnumber = 1; $showempty = 0; - } - print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty); - //print ''; - print ''; - $retstring = ''; - for ($year = $syear - 10; $year < $syear + 10; $year++) - { - $retstring .= ''; - } - $retstring .= "\n"; - print $retstring; - print ''; - $retstring = ''; - $retstring .= ''; - for ($month = 1; $month <= 12; $month++) - { - $retstring .= '"; - } - $retstring .= ""; - print $retstring; - print ''; - $retstring = ''; - $retstring .= ''; - for ($day = 1; $day <= 31; $day++) - { - $retstring .= ''; - } - $retstring .= ""; - print $retstring; - print ''; - if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') - { - print ''; - } - else - { - print ''; - } - print '
'; + print ''; + print ''.$form->selectarray('posmodule', $arrayofposavailable, GETPOST('posmodule', 'alpha'), (count($arrayofposavailable) > 1 ? 1 : 0)).''; + print ''; - // Table to see/enter balance - if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') - { - $posmodule = GETPOST('posmodule', 'alpha'); - $terminalid = GETPOST('posnumber', 'alpha'); - - print '
'; - - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - $i = 0; - foreach ($arrayofpaymentmode as $key => $val) + $array = array(); + $numterminals = max(1, $conf->global->TAKEPOS_NUM_TERMINALS); + for($i = 1; $i <= $numterminals; $i++) { + $array[$i] = $i; + } + $selectedposnumber = 0; $showempty = 1; + if ($conf->global->TAKEPOS_NUM_TERMINALS == '1') + { + $selectedposnumber = 1; $showempty = 0; + } + print $form->selectarray('posnumber', $array, GETPOSTISSET('posnumber') ?GETPOST('posnumber', 'int') : $selectedposnumber, $showempty); + //print ''; + print ''; + // Year + print ''; + // Month + print ''; + // Day + print ''; + // Button Start + print ''; + print '
'.$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 '
'; + $retstring = ''; + for ($year = $syear - 10; $year < $syear + 10; $year++) { - print ''.$langs->trans($val); + $retstring .= ''; + } + $retstring .= "\n"; + print $retstring; + print ''; + $retstring = ''; + $retstring .= ''; + for ($month = 1; $month <= 12; $month++) + { + $retstring .= '"; + } + $retstring .= ""; + print $retstring; + print ''; + $retstring = ''; + $retstring .= ''; + for ($day = 1; $day <= 31; $day++) + { + $retstring .= ''; + } + $retstring .= ""; + print $retstring; + print ''; + if ($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') + { + print ''; + } + else + { + print ''; + } + print '
'; + print ''; + + // Table to see/enter balance + if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') + { + $posmodule = GETPOST('posmodule', 'alpha'); + $terminalid = GETPOST('posnumber', 'alpha'); + + print '
'; + + print '
'; + print ''; + + print ''; + print ''; + print ''; - $i++; - } - print ''; - print ''; - print ''; - // Initial amount - print ''; - print ''; - // Amount per payment type - $i = 0; - foreach ($arrayofpaymentmode as $key => $val) - { - print ''; - $i++; - } - // Save - print ''; - print ''; - - print ''; - // Initial amount - print ''; - print ''; - // Amount per payment type - $i = 0; - foreach ($arrayofpaymentmode as $key => $val) - { - print ''; - $i++; - } - // Save - print ''; - print ''; + */ + print ''; + print ''; - print ''; - print ''; - // Initial amount - print ''; - // Amount per payment type - $i = 0; - foreach ($arrayofpaymentmode as $key => $val) - { - print ''; + print ''; + print ''; + /* + $i = 0; + foreach ($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + }*/ + print ''; + print ''; + + /*print ''; + // Initial amount + print ''; + print ''; + // Amount per payment type + $i = 0; + foreach ($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + } + // Save + print ''; + print ''; + */ + + print ''; + // Initial amount + print ''; + print ''; + // Amount per payment type + /*$i = 0; + foreach ($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + }*/ + // Save + print ''; + print ''; + + print ''; + print ''; + // Initial amount + print ''; - $i++; - } - // Save - print ''; - print ''; + // Amount per payment type + /*$i = 0; + foreach ($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + }*/ + // Save + print ''; + print ''; - print ''; + print '
'.$langs->trans("InitialBankBalance"); //print '
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount"); print '
'.$langs->trans("NbOfInvoices").''; - print ''; - print $theoricalnbofinvoiceforterminal[$terminalid][$key]; - print '
'.$langs->trans("TheoricalAmount").''; - print price($initialbalanceforterminal[$terminalid]['cash']).'
'; - print '
'; - print price($theoricalamountforterminal[$terminalid][$key]).'
'; + /* + print '
'; + print $langs->trans("AmountAtEndOfPeriod"); print '
'.$langs->trans("RealAmount").''; - print ''; - print ''; + print '
'.$langs->trans("Cash"); + //print '
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount"); + print '
'.$langs->trans($val); + //print '
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount"); + print '
'.$langs->trans("NbOfInvoices").''; + print ''; + print $theoricalnbofinvoiceforterminal[$terminalid][$key]; + print '
'.$langs->trans("TheoricalAmount").''; + print price($initialbalanceforterminal[$terminalid]['cash']).'
'; + print '
'; + print price($theoricalamountforterminal[$terminalid][$key]).'
'; + print '
'.$langs->trans("RealAmount").''; print ''; + if ($action == 'close') print 'disabled '; // To close cash user can't set opening cash + print 'name="opening" type="text" class="maxwidth100 center" value="'; + if ($action == 'close') + { + $object->fetch($id); + print $object->opening; + } + else print (GETPOSTISSET('opening') ?price2num(GETPOST('opening', 'alpha')) : price($initialbalanceforterminal[$terminalid]['cash'])); + print '">'; print ''; - print ''; - if ($action == 'start') print ''; - elseif ($action == 'close') print ''; - print '
'; + print ''; + print ''; + print ''; + if ($action == 'start') print ''; + elseif ($action == 'close') print ''; + print '
'; + print '
'; + } + + print ''; } - print ''; } -if (empty($action) || $action == "view") +if (empty($action) || $action == "view" || $action == "close") { $result = $object->fetch($id); @@ -538,7 +594,7 @@ if (empty($action) || $action == "view") $head[0][1] = $langs->trans("Card"); $head[0][2] = 'cashcontrol'; - dol_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'cashcontrol'); + dol_fiche_head($head, 'cashcontrol', $langs->trans("CashControl"), -1, 'account'); $linkback = ''.$langs->trans("BackToList").''; @@ -551,7 +607,7 @@ if (empty($action) || $action == "view") print '
'; print '
'; print '
'; - print ''; + print '
'; print '
'; print $langs->trans("Ref"); @@ -605,17 +661,213 @@ if (empty($action) || $action == "view") dol_fiche_end(); - print '
'; - print ''; - if ($object->status == CashControl::STATUS_DRAFT) - { - print ''; + if ($action != 'close') { + print '
'; - print ''; - } - print '
'; + print ''; - print '
'; + if ($object->status == CashControl::STATUS_DRAFT) + { + print ''; + + print ''; + } else { + print ''; + } + + print '
'; + + print '
'; + } else { + + print '
'; + print ''; + if ($action == 'start' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '' && GETPOST('posnumber', 'int') != '-1') + { + print ''; + } + elseif ($action == 'close') + { + print ''; + print ''; + } + else + { + print ''; + } + + /* + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + $disabled = 1; + $prefix = 'close'; + + print ''; + print ''; + print ''; + print ''; + // Year + print ''; + // Month + print ''; + // Day + print ''; + + print ''; + print '
'.$langs->trans("Module").''.$langs->trans("Terminal").''.$langs->trans("Year").''.$langs->trans("Month").''.$langs->trans("Day").'
'.$form->selectarray('posmodulebis', $arrayofposavailable, $object->posmodule, (count($arrayofposavailable) > 1 ? 1 : 0), 0, 0, '', 0, 0, $disabled).''; + + $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 ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print '
'; + */ + + // Table to see/enter balance + if (($action == 'start' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '' && GETPOST('posnumber') != '-1') || $action == 'close') + { + $posmodule = $object->posmodule; + $terminalid = $object->posnumber; + + print '
'; + + print '
'; + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + $i = 0; + foreach ($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + } + print ''; + print ''; + + print ''; + // Initial amount + print ''; + print ''; + // Amount per payment type + $i = 0; + foreach ($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + } + // Save + print ''; + print ''; + + print ''; + // Initial amount + print ''; + print ''; + // Amount per payment type + $i = 0; + foreach ($arrayofpaymentmode as $key => $val) + { + print ''; + $i++; + } + // 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 '
'.$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); + //print '
'.$langs->trans("TheoricalAmount").'
'.$langs->trans("RealAmount"); + print '
'.$langs->trans("NbOfInvoices").''; + print ''; + print $theoricalnbofinvoiceforterminal[$terminalid][$key]; + print '
'.$langs->trans("TheoricalAmount").''; + print price($initialbalanceforterminal[$terminalid]['cash']).'
'; + print '
'; + if ($key == 'cash') { + $deltaforcash = ($object->opening - $initialbalanceforterminal[$terminalid]['cash']); + print price($theoricalamountforterminal[$terminalid][$key] + $deltaforcash).'
'; + } else { + print price($theoricalamountforterminal[$terminalid][$key]).'
'; + } + print '
'.$langs->trans("RealAmount").''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($action == 'start') print ''; + elseif ($action == 'close') print ''; + print '
'; + print '
'; + } + + print '
'; + } } } diff --git a/htdocs/compta/cashcontrol/class/cashcontrol.class.php b/htdocs/compta/cashcontrol/class/cashcontrol.class.php index 32f7533b6c3..f30410d187f 100644 --- a/htdocs/compta/cashcontrol/class/cashcontrol.class.php +++ b/htdocs/compta/cashcontrol/class/cashcontrol.class.php @@ -104,6 +104,7 @@ class CashControl extends CommonObject const STATUS_DRAFT = 0; const STATUS_VALIDATED = 1; + const STATUS_CLOSED = 1; // For the moment CLOSED = VALIDATED /** @@ -288,6 +289,18 @@ class CashControl extends CommonObject return $result; } + /** + * Update object into database + * + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = false) + { + return $this->updateCommon($user, $notrigger); + } + /** * Delete object in database * diff --git a/htdocs/compta/cashcontrol/report.php b/htdocs/compta/cashcontrol/report.php index 8cd74f1cccf..1ea06eba9e9 100644 --- a/htdocs/compta/cashcontrol/report.php +++ b/htdocs/compta/cashcontrol/report.php @@ -40,6 +40,7 @@ $langs->load("bills"); $id = GETPOST('id', 'int'); $_GET['optioncss'] = "print"; + $cashcontrol = new CashControl($db); $cashcontrol->fetch($id); @@ -69,6 +70,8 @@ $terminalid = $cashcontrol->posnumber; * View */ +$param = ''; + llxHeader('', $langs->trans("CashControl"), '', '', 0, 0, array(), array(), $param); /*$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro as conciliated, b.num_releve, b.num_chq,"; @@ -268,21 +271,21 @@ if ($resql) print "

"; print $langs->trans("Cash").": ".price($cash); - if ($cash != $cashcontrol->cash) { + if ($cashcontrol->status == $cashcontrol::STATUS_VALIDATED && $cash != $cashcontrol->cash) { print ' <> '.$langs->trans("Declared").': '.price($cashcontrol->cash).''; } print "

"; //print '
'; print $langs->trans("PaymentTypeCHQ").": ".price($cheque); - if ($cheque != $cashcontrol->cheque) { + if ($cashcontrol->status == $cashcontrol::STATUS_VALIDATED && $cheque != $cashcontrol->cheque) { print ' <> '.$langs->trans("Declared").': '.price($cashcontrol->cheque).''; } print "

"; //print '
'; print $langs->trans("PaymentTypeCB").": ".price($bank); - if ($bank != $cashcontrol->card) { + if ($cashcontrol->status == $cashcontrol::STATUS_VALIDATED && $bank != $cashcontrol->card) { print ' <> '.$langs->trans("Declared").': '.price($cashcontrol->card).''; } print "

"; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0f9136bfbe2..02b8529257d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6203,7 +6203,7 @@ class Form $out .= ajax_combobox($htmlname); } - $out .= '