Skip to content
Snippets Groups Projects
Commit d7f538d7 authored by Regis Houssin's avatar Regis Houssin
Browse files

Fix: better check duplicates with reference supplier

parent bcc62447
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ ChangeSupplierPrice=Change supplier price
ErrorQtyTooLowForThisSupplier=Quantity too low for this supplier or no price defined on this product for this supplier
ErrorSupplierCountryIsNotDefined=Country for this supplier is not defined. Correct this first.
ProductHasAlreadyReferenceInThisSupplier=This product has already a reference in this supplier
ReferenceSupplierIsAlreadyAssociatedWithAProduct=This reference provider is already associated with a product
ReferenceSupplierIsAlreadyAssociatedWithAProduct=This reference supplier is already associated with a reference: %s
NoRecordedSuppliers=No suppliers recorded
SupplierPayment=Supplier payment
SuppliersArea=Suppliers area
......
......@@ -17,7 +17,7 @@ ChangeSupplierPrice=Modifier prix fournisseur
ErrorQtyTooLowForThisSupplier=Quantité insuffisante pour ce fournisseur ou aucun tarif défini sur ce produit pour ce fournisseur
ErrorSupplierCountryIsNotDefined=Le pays de ce fournisseur n'est pas défini. Corriger sur sa fiche.
ProductHasAlreadyReferenceInThisSupplier=Ce produit a déjà une référence chez ce fournisseur
ReferenceSupplierIsAlreadyAssociatedWithAProduct=Cette référence fournisseur est déjà associée à un produit
ReferenceSupplierIsAlreadyAssociatedWithAProduct=Cette référence fournisseur est déjà associée à la référence : %s
NoRecordedSuppliers=Pas de fournisseurs enregistrés
SupplierPayment=Paiement fournisseur
SuppliersArea=Espace fournisseurs
......
......@@ -111,6 +111,9 @@ class Product extends CommonObject
//! Id du fournisseur
var $product_fourn_id;
//! Product ID already linked to a reference supplier
var $product_id_already_linked;
/**
* \brief Constructeur de la classe
......@@ -1679,10 +1682,9 @@ class Product extends CommonObject
{
global $conf;
$sql = "SELECT count(*) as nb";
$sql = "SELECT rowid, fk_product";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
$sql.= " WHERE fk_product = ".$this->id;
$sql.= " AND fk_soc = ".$id_fourn;
$sql.= " WHERE fk_soc = ".$id_fourn;
$sql.= " AND ref_fourn = '".$ref_fourn."'";
$sql.= " AND entity = ".$conf->entity;
......@@ -1691,7 +1693,10 @@ class Product extends CommonObject
if ($resql)
{
$obj = $this->db->fetch_object($resql);
if ($obj->nb == 0)
$nb = count($obj);
// The reference supplier does not exist, it creates for this product.
if (!$nb)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur (";
$sql.= "datec";
......@@ -1722,24 +1727,20 @@ class Product extends CommonObject
return -1;
}
}
else
// If the reference supplier is already linked to this product
else if ($obj->fk_product == $this->id)
{
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
$sql.= " WHERE fk_product = ".$this->id;
$sql.= " AND fk_soc = ".$id_fourn;
$sql.= " AND ref_fourn = '".$ref_fourn."'";
$sql.= " AND entity = ".$conf->entity;
$resql=$this->db->query($sql);
if ($resql)
{
$obj = $this->db->fetch_object($resql);
$this->product_fourn_id = $obj->rowid;
}
$this->product_fourn_id = $obj->rowid;
return 0;
}
// If the reference provider is not linked to this product
else
{
$this->product_id_already_linked = $obj->fk_product;
return 2;
}
}
else
{
......
......@@ -115,10 +115,14 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
$error++;
$mesg='<div class="error">'.$product->error.'</div>';
}
if ($ret == 0)
if ($ret == 2)
{
$error++;
$mesg='<div class="error">'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct").'</div>';
$product->fetch($product->product_id_already_linked);
$productLink = $product->getNomUrl(1,'supplier');
$mesg='<div class="error">'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink).'</div>';
}
}
......@@ -136,10 +140,6 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
{
$error++;
$mesg='<div class="error">'.$product->error.'</div>';
if ($ret == -2)
{
$mesg='<div class="error">'.$langs->trans("ProductHasAlreadyReferenceInThisSupplier").'</div>';
}
}
}
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment