From 33dac25ce4a7ecb9176c7f3e436739eb8a7555d5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 10 Feb 2009 22:40:09 +0000 Subject: [PATCH] Fix: No way to delete a supplier invoice if not a draft --- htdocs/fourn/facture/fiche.php | 13 ++++++++++--- htdocs/fourn/fournisseur.facture.class.php | 17 ++++++++++------- htdocs/propal.class.php | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index bdbd0b49b59..709ff7aff70 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -96,9 +96,16 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') { $facturefourn = new FactureFournisseur($db); $factfournid = $_GET['facid']; - $facturefourn->delete($factfournid); - Header('Location: index.php'); - exit; + $result=$facturefourn->delete($factfournid); + if ($result > 0) + { + Header('Location: index.php'); + exit; + } + else + { + $mesg='
'.$facturefourn->error.'
'; + } } } diff --git a/htdocs/fourn/fournisseur.facture.class.php b/htdocs/fourn/fournisseur.facture.class.php index 9051c50efd3..dc1e1c97ad3 100644 --- a/htdocs/fourn/fournisseur.facture.class.php +++ b/htdocs/fourn/fournisseur.facture.class.php @@ -333,20 +333,21 @@ class FactureFournisseur extends Facture } /** - * \brief Supprime la facture - * \param rowid id de la facture � supprimer + * \brief Delete invoice in database + * \param rowid Id of invoice to delete + * \return int <0 if KO, >0 if OK */ function delete($rowid) { $this->db->begin(); $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';'; - dolibarr_syslog("FactureFournisseur sql=".$sql); + dolibarr_syslog("FactureFournisseur sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE rowid = '.$rowid.' AND fk_statut = 0'; - dolibarr_syslog("FactureFournisseur sql=".$sql); + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE rowid = '.$rowid; + dolibarr_syslog("FactureFournisseur sql=".$sql, LOG_DEBUG); $resql2 = $this->db->query($sql); if ($resql2) { @@ -357,14 +358,16 @@ class FactureFournisseur extends Facture { $this->db->rollback(); $this->error=$this->db->lasterror(); - dolibarr_syslog("FactureFournisseur::delete ".$this->error); + dolibarr_syslog("FactureFournisseur::delete ".$this->error, LOG_ERR); + return -1; } } else { $this->db->rollback(); $this->error=$this->db->lasterror(); - dolibarr_syslog("FactureFournisseur::delete ".$this->error); + dolibarr_syslog("FactureFournisseur::delete ".$this->error, LOG_ERR); + return -1; } } diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index f92b7a561dd..6d7fc2802b1 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -844,7 +844,7 @@ class Propal extends CommonObject else { $this->error=$this->db->error(); - dolibarr_syslog("Propal::Fetch Error ".$this->error, LOG_ERROR); + dolibarr_syslog("Propal::Fetch Error ".$this->error, LOG_ERR); return -1; } }