From 72c5943c5583590d9c84b5f3a83cc6a7407c3f6c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 16 Dec 2018 17:53:23 +0100 Subject: [PATCH] Execute trigger so we can record line into unalterable log table --- .../cashcontrol/class/cashcontrol.class.php | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/cashcontrol/class/cashcontrol.class.php b/htdocs/compta/cashcontrol/class/cashcontrol.class.php index 8f788d29e15..a49cb68e57a 100644 --- a/htdocs/compta/cashcontrol/class/cashcontrol.class.php +++ b/htdocs/compta/cashcontrol/class/cashcontrol.class.php @@ -87,6 +87,9 @@ class CashControl extends CommonObject public $cheque; public $card; + const STATUS_DRAFT = 0; + const STATUS_VALIDATE = 1; + /** * Constructor @@ -187,21 +190,16 @@ class CashControl extends CommonObject */ public function close(User $user, $notrigger = 0) { - global $conf; - $error = 0; // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence "; - $sql.= "SET"; - $sql.= " day_close=DAYOFMONTH(NOW())"; - $sql.= ", month_close=MONTH(NOW())"; - $sql.= ", year_close=YEAR(NOW())"; - $sql.= ", status=2"; - $sql.= " where rowid=".$this->id; + $sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence"; + $sql.= " SET status = ".self::STATUS_VALIDATED; + $sql.= " WHERE rowid=".$this->id; + $this->db->begin(); - dol_syslog(get_class($this)."::create", LOG_DEBUG); + dol_syslog(get_class($this)."::close", LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error++; @@ -212,6 +210,16 @@ class CashControl extends CommonObject $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."pos_cash_fence"); } + if (! $error && ! $notrigger) + { + $this->context=array('operation'=>'close'); + + // Call trigger + $result=$this->call_trigger('CASHCONTROL_MODIFY', $user); + if ($result < 0) $error++; + // End call triggers + } + // Commit or rollback if ($error) { foreach ($this->errors as $errmsg) {