--- /tmp/dsg/dolibarr/htdocs/compta/cashcontrol/github_cashcontrol_card.php +++ /tmp/dsg/dolibarr/htdocs/compta/cashcontrol/client_cashcontrol_card.php @@ -28,7 +28,6 @@ */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php'; @@ -59,7 +58,7 @@ if ($contextpage == 'takepos') { - $_GET['optioncss'] = 'print'; + $_GET['optioncss'] = 'print'; } // Security check @@ -108,7 +107,8 @@ { if ($action == 'valid') { $action = 'view'; - } else { + } + else { $action = 'create'; } } @@ -144,7 +144,8 @@ $action = 'create'; $error++; } -} elseif ($action == "add") +} +elseif ($action == "add") { if (GETPOST('opening', 'alpha') == '') { @@ -164,8 +165,8 @@ $object->month_close = GETPOST('closemonth', 'int'); $object->year_close = GETPOST('closeyear', 'int'); - $object->opening = price2num(GETPOST('opening', 'alpha')); - $object->posmodule = GETPOST('posmodule', 'alpha'); + $object->opening = price2num(GETPOST('opening', 'alpha')); + $object->posmodule = GETPOST('posmodule', 'alpha'); $object->posnumber = GETPOST('posnumber', 'alpha'); $db->begin(); @@ -176,7 +177,9 @@ { $db->commit(); $action = "view"; - } else { + } + else + { $db->rollback; $action = "view"; } @@ -214,7 +217,9 @@ { setEventMessages($object->error, $object->errors, 'errors'); $db->rollback(); - } else { + } + else + { setEventMessages($langs->trans("CashFenceDone"), null); $db->commit(); } @@ -226,32 +231,34 @@ "; exit; } - $action = "view"; + $action = "view"; } // Action to delete if ($action == 'confirm_delete' && !empty($permissiontodelete)) { - $object->fetch($id); - - if (!($object->id > 0)) - { - dol_print_error('', 'Error, object must be fetched before being deleted'); - exit; - } - - $result = $object->delete($user); - //var_dump($result); - if ($result > 0) - { - // Delete OK - setEventMessages("RecordDeleted", null, 'mesgs'); - header("Location: ".$backurlforlist); - exit; - } else { - if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); - else setEventMessages($object->error, null, 'errors'); - } + $object->fetch($id); + + if (!($object->id > 0)) + { + dol_print_error('', 'Error, object must be fetched before being deleted'); + exit; + } + + $result = $object->delete($user); + //var_dump($result); + if ($result > 0) + { + // Delete OK + setEventMessages("RecordDeleted", null, 'mesgs'); + header("Location: ".$backurlforlist); + exit; + } + else + { + if (!empty($object->errors)) setEventMessages(null, $object->errors, 'errors'); + else setEventMessages($object->error, null, 'errors'); + } } @@ -275,7 +282,8 @@ $syear = $object->year_close; $smonth = $object->month_close; $sday = $object->day_close; - } elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') + } + elseif (GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '' && GETPOST('posnumber', 'alpha') != '-1') { $posmodule = GETPOST('posmodule', 'alpha'); $terminalid = GETPOST('posnumber', 'alpha'); @@ -307,22 +315,25 @@ if ($bankid > 0) { - $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); - } else { + $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); + } + else + { setEventMessages($langs->trans("SetupOfTerminalNotComplete", $terminaltouse), null, 'errors'); - $error++; + $error++; } } @@ -339,7 +350,8 @@ 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 { + else + { dol_print_error('Value for key = '.$key.' not supported'); exit; } @@ -359,7 +371,8 @@ $theoricalamountforterminal[$terminalid][$key] = price2num($theoricalamountforterminal[$terminalid][$key] + $obj->total); $theoricalnbofinvoiceforterminal[$terminalid][$key] = $obj->nb; } - } else dol_print_error($db); + } + else dol_print_error($db); } } @@ -370,50 +383,53 @@ print load_fiche_titre($langs->trans("CashControl")." - ".$langs->trans("New"), '', 'cash-register'); print '