diff --git a/htdocs/soc.php b/htdocs/soc.php index 41367e49af2..4a9fa3ba1bf 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -23,7 +23,7 @@ /** \file htdocs/soc.php \ingroup societe - \brief Onglet societe d'une societe + \brief Third party card page \version $Id$ */ @@ -237,20 +237,21 @@ if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"]) if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->societe->supprimer) { - $soc = new Societe($db); - $soc->fetch($socid); - $result = $soc->delete($socid); - - if ($result == 0) - { - Header("Location: ".DOL_URL_ROOT."/societe.php?delsoc=".$soc->nom.""); - exit; - } - else - { - $reload = 0; - $_GET["action"]=''; - } + $soc = new Societe($db); + $soc->fetch($socid); + $result = $soc->delete($socid); + + if ($result >= 0) + { + Header("Location: ".DOL_URL_ROOT."/societe.php?delsoc=".$soc->nom.""); + exit; + } + else + { + $reload = 0; + $mesg=$soc->error; + $_GET["action"]=''; + } } @@ -961,11 +962,10 @@ else print "
\n"; } - - if ($soc->error) + if ($mesg) { print '
'; - print $soc->error; + print $mesg; print '
'; } diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 6282ebf7866..ac8f7236794 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -682,45 +682,48 @@ class Societe extends CommonObject dolibarr_syslog("Societe::Delete"); $sqr = 0; + // \Todo + // Check if third party can be deleted + + + + if ( $this->db->begin()) { - $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople "; - $sql .= " WHERE fk_soc = " . $id .";"; - + $sql = "DELETE from ".MAIN_DB_PREFIX."socpeople"; + $sql.= " WHERE fk_soc = " . $id; if ($this->db->query($sql)) { $sqr++; } else { - $this->error .= "Impossible de supprimer les contacts.\n"; - dolibarr_syslog("Societe::Delete erreur -1"); + $this->error .= $this->db->lasterror(); + dolibarr_syslog("Societe::Delete erreur -1 ".$this->error); } - $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib "; - $sql .= " WHERE fk_soc = " . $id .";"; - + $sql = "DELETE from ".MAIN_DB_PREFIX."societe_rib"; + $sql.= " WHERE fk_soc = " . $id; if ($this->db->query($sql)) { $sqr++; } else { - $this->error .= "Impossible de supprimer le RIB.\n"; - dolibarr_syslog("Societe::Delete erreur -2"); + $this->error = $this->db->lasterror(); + dolibarr_syslog("Societe::Delete erreur -2 ".$this->error); } - $sql = "DELETE from ".MAIN_DB_PREFIX."societe "; - $sql .= " WHERE rowid = " . $id .";"; - + $sql = "DELETE from ".MAIN_DB_PREFIX."societe"; + $sql.= " WHERE rowid = " . $id; if ($this->db->query($sql)) { $sqr++; } else { - $this->error .= "Impossible de supprimer la soci�t�.\n"; - dolibarr_syslog("Societe::Delete erreur -3"); + $this->error = $this->db->lasterror(); + dolibarr_syslog("Societe::Delete erreur -3 ".$this->error); } if ($sqr == 3)