ajout d'un bouton supprimer sur la fiche produit uniquement accessible si le produit
n'a jamais t utilis.
This commit is contained in:
parent
e365e36fa9
commit
d76c66a568
@ -249,8 +249,55 @@ class Product
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Vérification de l'utilisation du produit en base
|
||||
* \param id id du produit
|
||||
*/
|
||||
function verif_prod_use($id)
|
||||
{
|
||||
$sql = "SELECT COUNT(*)";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as p, ".MAIN_DB_PREFIX."commandedet as c";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."facturedet as f, ".MAIN_DB_PREFIX."contratdet as ct";
|
||||
$sql.= " WHERE p.fk_product = ".$id." AND c.fk_product = ".$id." AND f.fk_product = ".$id." AND ct.fkproduct = ".$id;
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql == 0)
|
||||
{
|
||||
return 0
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Suppression du produit en base si pas utilisé
|
||||
* \param id id du produit
|
||||
*/
|
||||
function delete($id)
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ($user->rights->produit->supprimer)
|
||||
{
|
||||
$prod_use = $this->verif_prod_use($id);
|
||||
if ($prod_use == 0)
|
||||
{
|
||||
$sqld = "DELETE from ".MAIN_DB_PREFIX."product ";
|
||||
$sqld.= " WHERE rowid = ".$id;
|
||||
$this->db->query($sqld);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error .= "Impossible de supprimer le produit.\n";
|
||||
return -1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief : update ou crée les traductions des infos produits
|
||||
* \brief update ou crée les traductions des infos produits
|
||||
*/
|
||||
function setMultiLangs()
|
||||
{
|
||||
|
||||
@ -203,6 +203,30 @@ if ($_GET["action"] == 'clone' && $user->rights->produit->creer)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Suppression d'un produit/service pas encore affecté
|
||||
*/
|
||||
if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes' && $user->rights->produit->supprimer)
|
||||
{
|
||||
$product = new Product($db);
|
||||
$product->fetch($id);
|
||||
$result = $product->delete($id);
|
||||
|
||||
if ($result == 0)
|
||||
{
|
||||
llxHeader();
|
||||
print '<div class="ok">'.$langs->trans("ProductDeleted",$product->ref).'</div>';
|
||||
llxFooter();
|
||||
exit ;
|
||||
}
|
||||
else
|
||||
{
|
||||
$reload = 0;
|
||||
$_GET["action"]='';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Ajout du produit dans une propal
|
||||
*/
|
||||
@ -495,6 +519,14 @@ if ($_GET["id"] || $_GET["ref"])
|
||||
|
||||
$titre=$langs->trans("CardProduct".$product->type);
|
||||
dolibarr_fiche_head($head, $hselected, $titre);
|
||||
|
||||
// Confirmation de la suppression de la facture
|
||||
if ($_GET["action"] == 'delete')
|
||||
{
|
||||
$html = new Form($db);
|
||||
$html->form_confirm("fiche.php?id=".$product->id,$langs->trans("DeleteProduct"),$langs->trans("ConfirmDeleteProduct"),"confirm_delete");
|
||||
print "<br />\n";
|
||||
}
|
||||
|
||||
|
||||
print($mesg);
|
||||
@ -712,6 +744,15 @@ if ($_GET["action"] == '')
|
||||
|
||||
print '<a class="tabAction" href="fiche.php?action=clone&id='.$product->id.'">'.$langs->trans("CreateCopy").'</a>';
|
||||
}
|
||||
if ($product->verif_prod_use($id))
|
||||
{
|
||||
$prod_use = $product->verif_prod_use($id)
|
||||
}
|
||||
|
||||
if ($user->rights->produit->supprimer && $prod_use == 0)
|
||||
{
|
||||
print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$product->id.'">'.$langs->trans("Delete").'</a>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user