From 75bf04ec716b48ad45e958842e961247cc4c6650 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 10 Apr 2011 09:47:12 +0000 Subject: [PATCH] Fix: use FactureLigne class for delete line --- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 87 +++++++++++++------ 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index d6a3109426e..f463b55d622 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1551,7 +1551,7 @@ class Commande extends CommonObject if ($result > 0) { - $result=$this->update_price(); + $result=$this->update_price(1); if ($result > 0) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 5a7c4cc27ed..d649b1c34fb 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1956,33 +1956,34 @@ class Facture extends CommonObject $this->db->rollback(); return -1; } - - // Efface ligne de facture - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facturedet'; - $sql.= ' WHERE rowid = '.$rowid; - - dol_syslog("Facture::Deleteline sql=".$sql); - $result = $this->db->query($sql); - if (! $result) + + $line=new FactureLigne($this->db); + + // For triggers + $line->fetch($rowid); + + if ($line->delete($user) > 0) { - $this->error=$this->db->error(); - dol_syslog("Facture::Deleteline Error ".$this->error, LOG_ERR); - $this->db->rollback(); - return -1; + $result=$this->update_price(1); + + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; + } + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + return -1; } - - $result=$this->update_price(); - - // Appel des triggers - include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); - $interface=new Interfaces($this->db); - $result = $interface->run_triggers('LINEBILL_DELETE',$this,$user,$langs,$conf); - if ($result < 0) { $error++; $this->errors=$interface->errors; } - // Fin appel triggers - - $this->db->commit(); - - return 1; } /** @@ -3186,7 +3187,6 @@ class FactureLigne } } - /** * \brief Insert line in database * \param notrigger 1 no triggers @@ -3335,7 +3335,6 @@ class FactureLigne } } - /** * Update line into database * @return int <0 if KO, >0 if OK @@ -3406,6 +3405,40 @@ class FactureLigne return -2; } } + + /** + * Delete line in database + * @return int <0 si ko, >0 si ok + */ + function delete($rowid) + { + global $conf,$langs,$user; + + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet WHERE rowid = ".$rowid; + dol_syslog("FactureLigne::delete sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql) ) + { + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result = $interface->run_triggers('LINEBILL_DELETE',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers + + $this->db->commit(); + + return 1; + } + else + { + $this->error=$this->db->error()." sql=".$sql; + dol_syslog("FactureLigne::delete Error ".$this->error, LOG_ERR); + $this->db->rollback(); + return -1; + } + } /** * \brief Mise a jour en base des champs total_xxx de ligne de facture