From 3006e2bf75fce7c65e5f086487b7b75f6e1c8a43 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Mar 2019 12:05:42 +0100 Subject: [PATCH 1/5] memorize line before delete (for triggers) --- htdocs/commande/class/commande.class.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 07b7a907150..6eff20da863 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1367,7 +1367,7 @@ class Commande extends CommonOrder // Check parameters if ($type < 0) return -1; - + if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error=$langs->trans('ErrorStartDateGreaterEnd'); @@ -2194,6 +2194,12 @@ class Commande extends CommonOrder // For triggers $line->fetch($lineid); + // Memorize previous line for triggers + $staticline=new OrderLine($this->db); + $staticline->fetch($lineid); + $staticline->fetch_optionals($lineid); + $line->oldline = $staticline; + if ($line->delete($user) > 0) { $result=$this->update_price(1); @@ -2947,7 +2953,7 @@ class Commande extends CommonOrder if (empty($txlocaltax2)) $txlocaltax2=0; if (empty($remise_percent)) $remise_percent=0; if (empty($special_code) || $special_code == 3) $special_code=0; - + if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error=$langs->trans('ErrorStartDateGreaterEnd'); @@ -2962,7 +2968,7 @@ class Commande extends CommonOrder $txtva=price2num($txtva); $txlocaltax1=price2num($txlocaltax1); $txlocaltax2=price2num($txlocaltax2); - + $this->db->begin(); // Calcul du total TTC et de la TVA pour la ligne a partir de From 631be04d5de1c7489af970338d94163dc174d61e Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Mar 2019 12:15:50 +0100 Subject: [PATCH 2/5] better clone oldline and avoid emptylabel on update --- htdocs/commande/class/commande.class.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6eff20da863..18495a68f50 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2195,9 +2195,7 @@ class Commande extends CommonOrder $line->fetch($lineid); // Memorize previous line for triggers - $staticline=new OrderLine($this->db); - $staticline->fetch($lineid); - $staticline->fetch_optionals($lineid); + $staticline = clone $line; $line->oldline = $staticline; if ($line->delete($user) > 0) @@ -3054,7 +3052,7 @@ class Commande extends CommonOrder } $this->line->rowid=$rowid; - $this->line->label=$label; + $this->line->label=!empty($label)?$label:$this->line->oldline->label; $this->line->desc=$desc; $this->line->qty=$qty; From dfa5c419b324233668520f4b8f2f8ca6e2b10311 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 19 Jun 2021 14:52:06 +0200 Subject: [PATCH 3/5] Update commande.class.php --- htdocs/commande/class/commande.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 728fe45d7bd..608e1aa5199 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3087,10 +3087,10 @@ class Commande extends CommonOrder $this->line->rang = $rangmax + 1; } - $this->line->rowid=$rowid; - $this->line->label=!empty($label)?$label:$this->line->oldline->label; - $this->line->desc=$desc; - $this->line->qty=$qty; + $this->line->rowid = $rowid; + $this->line->label = $label; + $this->line->desc = $desc; + $this->line->qty = $qty; $this->line->vat_src_code = $vat_src_code; $this->line->tva_tx = $txtva; From 3669600242108201fffc17874089aad0ae7f17b7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 19 Jun 2021 14:55:41 +0200 Subject: [PATCH 4/5] Update commande.class.php --- htdocs/commande/class/commande.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 20b80bdef2f..dec941049a1 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3181,7 +3181,6 @@ class Commande extends CommonOrder } $this->line->id = $rowid; - $this->line->rowid = $rowid; // For backward compatibility $this->line->label = $label; $this->line->desc = $desc; $this->line->qty = $qty; From 26f72b7fff281fefd9c2277a8ee5b9ee02df1457 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 19 Jun 2021 12:58:08 +0000 Subject: [PATCH 5/5] Fixing style errors. --- htdocs/commande/class/commande.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index dec941049a1..2805f4556d3 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2351,10 +2351,10 @@ class Commande extends CommonOrder $staticline = clone $line; $line->oldline = $staticline; - if ($line->delete($user) > 0) { + if ($line->delete($user) > 0) { $result = $this->update_price(1); - if ($result > 0) { + if ($result > 0) { $this->db->commit(); return 1; } else {