From a87078a70ad742c2b8d3bd1d465513eacdb9e33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 29 Nov 2022 22:21:46 +0100 Subject: [PATCH] Update account.class.php --- htdocs/compta/bank/class/account.class.php | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 464df7d5fb5..ce73d62c0fe 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -1971,6 +1971,10 @@ class AccountLine extends CommonObject */ public function insert() { + $error = 0; + + $this->db->begin(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank ("; $sql .= "datec"; $sql .= ", dateo"; @@ -2006,15 +2010,26 @@ class AccountLine extends CommonObject dol_syslog(get_class($this)."::insert", LOG_DEBUG); $resql = $this->db->query($sql); - - if (!$resql) { + if ($resql) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank'); + // Actions on extra fields (by external module or standard code) + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; + } + } else { + $error++; $this->error = $this->db->lasterror(); - return -1; + dol_print_error($this->db); } - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'bank'); - - return $this->id; + if (!$error) { + $this->db->commit(); + return $this->id; + } else { + $this->db->rollback(); + return -1 * $error; + } } /**