From b68e85703ff2530021e870675794ed33c11c30c4 Mon Sep 17 00:00:00 2001 From: simicar29 Date: Thu, 23 Apr 2020 16:29:22 +0200 Subject: [PATCH 1/4] Clean line extrafields when deleting invoice Delete extrafields invoice lines when deleting parent object (sql syntax ok for mariadb & pgsql) Delete extrafields when deleting an invoice line --- htdocs/compta/facture/class/facture.class.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f9285eb2d9c..66cb1aed37d 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2166,13 +2166,16 @@ class Facture extends CommonInvoice } } - + // Invoice line extrafileds + $main = MAIN_DB_PREFIX . 'facturedet'; + $ef = $main . "_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture = $rowid)"; // Delete invoice line $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet WHERE fk_facture = '.$rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); - if ($this->db->query($sql) && $this->delete_linked_contact()) + if ($this->db->query($sqlef) && $this->db->query($sql) && $this->delete_linked_contact()) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture WHERE rowid = '.$rowid; @@ -5312,7 +5315,14 @@ class FactureLigne extends CommonInvoiceLine } // End call triggers - + // extrafields + $result = $this->deleteExtraFields(); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); if ($this->db->query($sql)) From aebc04d30a15eb8e2a46bdd44a1875aacc1db3d7 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 23 Apr 2020 14:33:11 +0000 Subject: [PATCH 2/4] Fixing style errors. --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 66cb1aed37d..9b327aadb45 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5322,7 +5322,7 @@ class FactureLigne extends CommonInvoiceLine $this->db->rollback(); return -1; } - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); if ($this->db->query($sql)) From ce94788dd906cce4f925fc260180359175c88d5a Mon Sep 17 00:00:00 2001 From: simicar29 Date: Thu, 23 Apr 2020 17:01:40 +0200 Subject: [PATCH 3/4] Clean line extrafields when deleting recurring invoice Delete extrafields recurring invoice lines when deleting parent object Delete extrafields when deleting a recurring invoice line --- .../compta/facture/class/facture-rec.class.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 110f5a9cbb8..f3437308f39 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -664,9 +664,13 @@ class FactureRec extends CommonInvoice $error = 0; $this->db->begin(); + $main = MAIN_DB_PREFIX . 'facturedet_rec'; + $ef = $main . "_extrafields"; + $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture = $rowid)"; + dol_syslog($sqlef); $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE fk_facture = ".$rowid; dol_syslog($sql); - if ($this->db->query($sql)) + if ($this->db->query($sqlef) && $this->db->query($sql)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."facture_rec WHERE rowid = ".$rowid; dol_syslog($sql); @@ -675,6 +679,9 @@ class FactureRec extends CommonInvoice // Delete linked object $res = $this->deleteObjectLinked(); if ($res < 0) $error = -3; + // Delete extrafields + $res = $this->deleteExtraFields(); + if ($res < 0) $error = -4; } else { @@ -1881,6 +1888,14 @@ class FactureLigneRec extends CommonInvoiceLine // End call triggers } } + + if (!$error) + { + $result = $this->deleteExtraFields(); + if ($result < 0) { + $error++; + } + } if (!$error) { From 2633e908902d3e20e2cfe35f28447f9842c98582 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 23 Apr 2020 15:03:14 +0000 Subject: [PATCH 4/4] Fixing style errors. --- htdocs/compta/facture/class/facture-rec.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index f3437308f39..5b72b6d465d 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -1888,7 +1888,7 @@ class FactureLigneRec extends CommonInvoiceLine // End call triggers } } - + if (!$error) { $result = $this->deleteExtraFields();