diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 22dac7fa2a9..dd80c0de89a 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -3151,6 +3151,19 @@ class Propal extends CommonObject // End call triggers } + // Remove linked categories. + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_propal"; + $sql .= " WHERE fk_propal = ".((int) $this->id); + + $result = $this->db->query($sql); + if (!$result) { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + } + } + // Delete extrafields of lines and lines if (!$error && !empty($this->table_element_line)) { $tabletodelete = $this->table_element_line; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index f83b0bfaa26..8979af9ce35 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1483,28 +1483,41 @@ class FactureFournisseur extends CommonInvoice // Fin appel triggers } - // If invoice was converted into a discount not yet consumed, we remove discount - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'societe_remise_except'; - $sql .= ' WHERE fk_invoice_supplier_source = '.((int) $rowid); - $sql .= ' AND fk_invoice_supplier_line IS NULL'; - $resql = $this->db->query($sql); + // Remove linked categories. + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_supplier_invoice"; + $sql .= " WHERE fk_supplier_invoice = ".((int) $this->id); - // If invoice has consumned discounts - $this->fetch_lines(); - $list_rowid_det = array(); - foreach ($this->lines as $key => $invoiceline) { - $list_rowid_det[] = $invoiceline->id; + $result = $this->db->query($sql); + if (!$result) { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; } - // Consumned discounts are freed - if (count($list_rowid_det)) { - $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; - $sql .= ' SET fk_invoice_supplier = NULL, fk_invoice_supplier_line = NULL'; - $sql .= ' WHERE fk_invoice_supplier_line IN ('.$this->db->sanitize(implode(',', $list_rowid_det)).')'; + if (!$error) { + // If invoice was converted into a discount not yet consumed, we remove discount + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'societe_remise_except'; + $sql .= ' WHERE fk_invoice_supplier_source = '.((int) $rowid); + $sql .= ' AND fk_invoice_supplier_line IS NULL'; + $resql = $this->db->query($sql); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - if (!$this->db->query($sql)) { - $error++; + // If invoice has consumned discounts + $this->fetch_lines(); + $list_rowid_det = array(); + foreach ($this->lines as $key => $invoiceline) { + $list_rowid_det[] = $invoiceline->id; + } + + // Consumned discounts are freed + if (count($list_rowid_det)) { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'societe_remise_except'; + $sql .= ' SET fk_invoice_supplier = NULL, fk_invoice_supplier_line = NULL'; + $sql .= ' WHERE fk_invoice_supplier_line IN ('.$this->db->sanitize(implode(',', $list_rowid_det)).')'; + + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + if (!$this->db->query($sql)) { + $error++; + } } } @@ -1565,18 +1578,6 @@ class FactureFournisseur extends CommonInvoice } } - // Remove linked categories. - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_invoice"; - $sql .= " WHERE fk_invoice = ".((int) $this->id); - - $result = $this->db->query($sql); - if (!$result) { - $error++; - $this->errors[] = $this->db->lasterror(); - } - } - // Remove extrafields if (!$error) { $result = $this->deleteExtraFields(); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index aadef3cf7a1..de3b49694e7 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -2136,6 +2136,19 @@ class SupplierProposal extends CommonObject // End call triggers } + // Remove linked categories. + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_supplier_proposal"; + $sql .= " WHERE fk_supplier_proposal = ".((int) $this->id); + + $result = $this->db->query($sql); + if (!$result) { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + } + } + if (!$error) { $main = MAIN_DB_PREFIX.'supplier_proposaldet'; $ef = $main."_extrafields";