Fix: better check duplicates with reference supplier
This commit is contained in:
parent
bcc62447af
commit
d7f538d78f
@ -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
|
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.
|
ErrorSupplierCountryIsNotDefined=Country for this supplier is not defined. Correct this first.
|
||||||
ProductHasAlreadyReferenceInThisSupplier=This product has already a reference in this supplier
|
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
|
NoRecordedSuppliers=No suppliers recorded
|
||||||
SupplierPayment=Supplier payment
|
SupplierPayment=Supplier payment
|
||||||
SuppliersArea=Suppliers area
|
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
|
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.
|
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
|
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
|
NoRecordedSuppliers=Pas de fournisseurs enregistrés
|
||||||
SupplierPayment=Paiement fournisseur
|
SupplierPayment=Paiement fournisseur
|
||||||
SuppliersArea=Espace fournisseurs
|
SuppliersArea=Espace fournisseurs
|
||||||
|
|||||||
@ -112,6 +112,9 @@ class Product extends CommonObject
|
|||||||
//! Id du fournisseur
|
//! Id du fournisseur
|
||||||
var $product_fourn_id;
|
var $product_fourn_id;
|
||||||
|
|
||||||
|
//! Product ID already linked to a reference supplier
|
||||||
|
var $product_id_already_linked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructeur de la classe
|
* \brief Constructeur de la classe
|
||||||
* \param DB Handler acces base de donnees
|
* \param DB Handler acces base de donnees
|
||||||
@ -1679,10 +1682,9 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql = "SELECT count(*) as nb";
|
$sql = "SELECT rowid, fk_product";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||||
$sql.= " WHERE fk_product = ".$this->id;
|
$sql.= " WHERE fk_soc = ".$id_fourn;
|
||||||
$sql.= " AND fk_soc = ".$id_fourn;
|
|
||||||
$sql.= " AND ref_fourn = '".$ref_fourn."'";
|
$sql.= " AND ref_fourn = '".$ref_fourn."'";
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
|
|
||||||
@ -1691,7 +1693,10 @@ class Product extends CommonObject
|
|||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($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 = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur (";
|
||||||
$sql.= "datec";
|
$sql.= "datec";
|
||||||
@ -1722,24 +1727,20 @@ class Product extends CommonObject
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
// If the reference supplier is already linked to this product
|
||||||
|
else if ($obj->fk_product == $this->id)
|
||||||
{
|
{
|
||||||
$sql = "SELECT rowid";
|
$this->product_fourn_id = $obj->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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// If the reference provider is not linked to this product
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->product_id_already_linked = $obj->fk_product;
|
||||||
|
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -115,10 +115,14 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
|
|||||||
$error++;
|
$error++;
|
||||||
$mesg='<div class="error">'.$product->error.'</div>';
|
$mesg='<div class="error">'.$product->error.'</div>';
|
||||||
}
|
}
|
||||||
if ($ret == 0)
|
if ($ret == 2)
|
||||||
{
|
{
|
||||||
$error++;
|
$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++;
|
$error++;
|
||||||
$mesg='<div class="error">'.$product->error.'</div>';
|
$mesg='<div class="error">'.$product->error.'</div>';
|
||||||
if ($ret == -2)
|
|
||||||
{
|
|
||||||
$mesg='<div class="error">'.$langs->trans("ProductHasAlreadyReferenceInThisSupplier").'</div>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user