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 '