From bf9ee18bed424dbc3f44af4f278235832e0c16c1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 17 Dec 2018 03:25:45 +0100 Subject: [PATCH] Standardize code. --- .../compta/cashcontrol/cashcontrol_card.php | 2 +- .../cashcontrol/class/cashcontrol.class.php | 34 ++++++++++++++++--- .../install/mysql/migration/8.0.0-9.0.0.sql | 1 + .../mysql/tables/llx_pos_cash_fence.sql | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index 4311a3348bc..e212f8ff75b 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -135,7 +135,7 @@ if ($action=="close") { $cashcontrol= new CashControl($db); $cashcontrol->id=$id; - $cashcontrol->close($user); + $cashcontrol->valid($user); $action="view"; } diff --git a/htdocs/compta/cashcontrol/class/cashcontrol.class.php b/htdocs/compta/cashcontrol/class/cashcontrol.class.php index a49cb68e57a..37f73f6712f 100644 --- a/htdocs/compta/cashcontrol/class/cashcontrol.class.php +++ b/htdocs/compta/cashcontrol/class/cashcontrol.class.php @@ -182,19 +182,43 @@ class CashControl extends CommonObject } /** - * close + * Validate cash fence * * @param User $user User * @param number $notrigger No trigger * @return int <0 if KO, >0 if OK */ - public function close(User $user, $notrigger = 0) + public function valid(User $user, $notrigger = 0) { + global $conf,$langs; + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $error = 0; + // Protection + if ($this->status == self::STATUS_VALIDATED) + { + dol_syslog(get_class($this)."::valid action abandonned: already validated", LOG_WARNING); + return 0; + } + + /* + $posmodule = $this->posmodule; + if (! empty($user->rights->$posmodule->use)) + { + $this->error='NotEnoughPermissions'; + dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); + return -1; + } + */ + + $now=dol_now(); + // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence"; - $sql.= " SET status = ".self::STATUS_VALIDATED; + $sql.= " SET status = ".self::STATUS_VALIDATED.","; + $sql.= " date_valid='".$this->db->idate($now)."',"; + $sql.= " fk_user_valid = ".$user->id; $sql.= " WHERE rowid=".$this->id; $this->db->begin(); @@ -212,10 +236,10 @@ class CashControl extends CommonObject if (! $error && ! $notrigger) { - $this->context=array('operation'=>'close'); + $this->context=array('date_valid'=>$now); // Call trigger - $result=$this->call_trigger('CASHCONTROL_MODIFY', $user); + $result=$this->call_trigger('CASHCONTROL_VALIDATE', $user); if ($result < 0) $error++; // End call triggers } diff --git a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql index 7f50d9fe0d5..28d080584d1 100644 --- a/htdocs/install/mysql/migration/8.0.0-9.0.0.sql +++ b/htdocs/install/mysql/migration/8.0.0-9.0.0.sql @@ -242,6 +242,7 @@ CREATE TABLE llx_pos_cash_fence( cheque double(24,8) default 0, status INTEGER, date_creation DATETIME NOT NULL, + date_valid DATETIME, day_close INTEGER, month_close INTEGER, year_close INTEGER, diff --git a/htdocs/install/mysql/tables/llx_pos_cash_fence.sql b/htdocs/install/mysql/tables/llx_pos_cash_fence.sql index 26a78d69f00..607060adab6 100644 --- a/htdocs/install/mysql/tables/llx_pos_cash_fence.sql +++ b/htdocs/install/mysql/tables/llx_pos_cash_fence.sql @@ -25,6 +25,7 @@ CREATE TABLE llx_pos_cash_fence( cheque double(24,8) default 0, status INTEGER, date_creation DATETIME NOT NULL, + date_valid DATETIME, day_close INTEGER, month_close INTEGER, year_close INTEGER,