diff --git a/ChangeLog b/ChangeLog index 1083ec06979..f7275cebf57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ For users: - New: Can use {tttt} in numbering mask setup. It will be replaced with third party type. - New: VAT number is stored in one field. This is more "international". +- New: task #9782 : Add possibility to delete a warehouse - Fix: bug #28055 : Unable to modify the date of a cloned command - Fix: bug #27891 - Fix: Change of numbering module was not effective diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index fab7d627ecb..7bf805a9409 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -151,3 +151,4 @@ CloneProduct=Clone product or service ConfirmCloneProduct=Are you sure you want to clone product or service %s ? CloneContentProduct=Clone all main informations of product/service ClonePricesProduct=Clone main informations and prices +ProductIsUsed=This product is used \ No newline at end of file diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index bd5787beef3..a9d61ac4687 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -66,4 +66,6 @@ WarehousesAndProducts=Warehouses and products AverageUnitPricePMPShort=Average input price AverageUnitPricePMP=Average input price EstimatedStockValueShort=Estimated value of stock -EstimatedStockValue=Estimated value of stock \ No newline at end of file +EstimatedStockValue=Estimated value of stock +DeleteAWarehouse=Delete a warehouse +ConfirmDeleteWarehouse=Are you sure you want to delete the warehouse %s ? \ No newline at end of file diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index f06f50e3076..947450bcaf5 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -151,3 +151,4 @@ CloneProduct=Cloner produit/service ConfirmCloneProduct=Etes-vous sur de vouloir cloner le produit ou service %s ? CloneContentProduct=Cloner les informations générales du produit/service uniquement ClonePricesProduct=Cloner les informations générales et les prix +ProductIsUsed=Ce produit est utilisé \ No newline at end of file diff --git a/htdocs/langs/fr_FR/stocks.lang b/htdocs/langs/fr_FR/stocks.lang index 92c8bd1008e..286fd17d08f 100644 --- a/htdocs/langs/fr_FR/stocks.lang +++ b/htdocs/langs/fr_FR/stocks.lang @@ -66,4 +66,6 @@ WarehousesAndProducts=Entrepôts et produits AverageUnitPricePMPShort=Prix moyen pondéré (PMP) AverageUnitPricePMP=Prix moyen pondéré (PMP) d'aquisition EstimatedStockValueShort=Valorisation (PMP) -EstimatedStockValue=Valorisation aquisition stock (PMP) \ No newline at end of file +EstimatedStockValue=Valorisation aquisition stock (PMP) +DeleteAWarehouse=Supprimer un entrepôt +ConfirmDeleteWarehouse=Etes-vous sur de vouloir supprimer l'entrepôt %s ? \ No newline at end of file diff --git a/htdocs/product/stock/entrepot.class.php b/htdocs/product/stock/entrepot.class.php index fab43edc636..c2a68cb82c5 100644 --- a/htdocs/product/stock/entrepot.class.php +++ b/htdocs/product/stock/entrepot.class.php @@ -120,9 +120,9 @@ class Entrepot extends CommonObject } - /* - * \brief Mise a jour des information d'un entrepot - * \param id id de l'entrepot � modifier + /** + * \brief Update properties of a warehouse + * \param id id of warehouse to modify * \param user */ function update($id, $user) @@ -147,68 +147,125 @@ class Entrepot extends CommonObject $sql .= ",fk_pays = " . $this->pays_id; $sql .= " WHERE rowid = " . $id; - if ( $this->db->query($sql) ) + $this->db->begin(); + + dol_syslog("Entrepot::update sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) { - return 1; + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error()." sql=$sql";; - dol_syslog("Entrepot::Update return -1"); - dol_syslog("Entrepot::Update ".$this->error, LOG_ERR); - return -1; + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("Entrepot::update ".$this->error, LOG_ERR); + return -1; } } /** - * \brief Recup�eration de la base d'un entrepot - * \param id id de l'entrepot a r�cup�rer + * \brief Delete a warehouse + * \param user + * \return int <0 if KO, >0 if OK */ - function fetch ($id) + function delete($user) { - $sql = "SELECT rowid, label, description, statut, lieu, address, cp, ville, fk_pays"; - $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; - $sql .= " WHERE rowid = $id"; - $result = $this->db->query($sql); - if ($result) + $this->db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."stock_mouvement"; + $sql.= " WHERE fk_entrepot = " . $this->id; + dol_syslog("Entrepot::delete sql=".$sql); + $resql1=$this->db->query($sql); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_stock"; + $sql.= " WHERE fk_entrepot = " . $this->id; + dol_syslog("Entrepot::delete sql=".$sql); + $resql2=$this->db->query($sql); + + if ($resql1 && $resql2) { - $obj=$this->db->fetch_object($result); - - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->libelle = $obj->label; - $this->description = $obj->description; - $this->statut = $obj->statut; - $this->lieu = $obj->lieu; - $this->address = $obj->address; - $this->cp = $obj->cp; - $this->ville = $obj->ville; - $this->pays_id = $obj->fk_pays; - - if ($this->pays_id) - { - $sqlp = "SELECT libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$this->pays_id; - $resql=$this->db->query($sqlp); - if ($resql) - { - $objp = $this->db->fetch_object($resql); - } - else - { - dol_print_error($db); - } - $this->pays=$objp->libelle; - } - - $this->db->free($result); - return 1; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."entrepot"; + $sql.= " WHERE rowid = " . $this->id; + + dol_syslog("Entrepot::delete sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("Entrepot::delete ".$this->error, LOG_ERR); + return -1; + } } else { - $this->error=$this->db->error(); - return -1; + $this->db->rollback(); + $this->error=$this->db->lasterror(); + dol_syslog("Entrepot::delete ".$this->error, LOG_ERR); + return -1; + } + + } + + + /** + * \brief Recuperation de la base d'un entrepot + * \param id id de l'entrepot a recuperer + */ + function fetch($id) + { + $sql = "SELECT rowid, label, description, statut, lieu, address, cp, ville, fk_pays"; + $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; + $sql .= " WHERE rowid = ".$id; + + dol_syslog("Entrepot::fetch sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $obj=$this->db->fetch_object($result); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->libelle = $obj->label; + $this->description = $obj->description; + $this->statut = $obj->statut; + $this->lieu = $obj->lieu; + $this->address = $obj->address; + $this->cp = $obj->cp; + $this->ville = $obj->ville; + $this->pays_id = $obj->fk_pays; + + if ($this->pays_id) + { + $sqlp = "SELECT libelle from ".MAIN_DB_PREFIX."c_pays where rowid = ".$this->pays_id; + $resql=$this->db->query($sqlp); + if ($resql) + { + $objp = $this->db->fetch_object($resql); + } + else + { + dol_print_error($db); + } + $this->pays=$objp->libelle; + } + + $this->db->free($result); + return 1; + } + else + { + $this->error=$this->db->error(); + return -1; } } diff --git a/htdocs/product/stock/fiche.php b/htdocs/product/stock/fiche.php index d038b2be978..04ba04d4518 100644 --- a/htdocs/product/stock/fiche.php +++ b/htdocs/product/stock/fiche.php @@ -49,7 +49,7 @@ $mesg = ''; */ // Ajout entrepot -if ($_POST["action"] == 'add') +if ($_POST["action"] == 'add' && $user->rights->stock->creer) { $entrepot = new Entrepot($db); @@ -65,8 +65,10 @@ if ($_POST["action"] == 'add') if ($entrepot->libelle) { $id = $entrepot->create($user); - if ($id > 0) { - Header("Location: fiche.php?id=$id"); + if ($id > 0) + { + header("Location: fiche.php?id=".$id); + exit; } $_GET["action"] = 'create'; @@ -78,6 +80,24 @@ if ($_POST["action"] == 'add') } } +// Delete warehouse +if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' && $user->rights->stock->supprimer) +{ + $entrepot = new Entrepot($db); + $entrepot->fetch($_REQUEST["id"]); + $result=$entrepot->delete($user); + if ($result > 0) + { + header("Location: ".DOL_URL_ROOT.'/product/stock/liste.php'); + exit; + } + else + { + $mesg='
'.$entrepot->error.'
'; + $_REQUEST['action']=''; + } +} + // Modification entrepot if ($_POST["action"] == 'update' && $_POST["cancel"] <> $langs->trans("Cancel")) { @@ -214,7 +234,14 @@ else dol_fiche_head($head, 'card', $langs->trans("Warehouse"), 0, 'stock'); - + // Confirm delete third party + if ($_GET["action"] == 'delete') + { + $html = new Form($db); + $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$entrepot->id,$langs->trans("DeleteAWarehouse"),$langs->trans("ConfirmDeleteWarehouse",$entrepot->libelle),"confirm_delete",'',0,2); + if ($ret == 'html') print '
'; + } + print ''; // Ref diff --git a/htdocs/soc.php b/htdocs/soc.php index e00e2f6445a..c0ba8d5c581 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -962,7 +962,7 @@ else if ($_GET["action"] == 'delete') { $html = new Form($db); - $ret=$html->form_confirm("soc.php?socid=".$soc->id,$langs->trans("DeleteACompany"),$langs->trans("ConfirmDeleteCompany"),"confirm_delete",'',0,2); + $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?socid=".$soc->id,$langs->trans("DeleteACompany"),$langs->trans("ConfirmDeleteCompany"),"confirm_delete",'',0,2); if ($ret == 'html') print '
'; }