diff --git a/htdocs/langs/en_US/suppliers.lang b/htdocs/langs/en_US/suppliers.lang index 933cbc1a84c..7999235d318 100644 --- a/htdocs/langs/en_US/suppliers.lang +++ b/htdocs/langs/en_US/suppliers.lang @@ -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 diff --git a/htdocs/langs/fr_FR/suppliers.lang b/htdocs/langs/fr_FR/suppliers.lang index 5975e7fe893..c758a8c8851 100644 --- a/htdocs/langs/fr_FR/suppliers.lang +++ b/htdocs/langs/fr_FR/suppliers.lang @@ -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 diff --git a/htdocs/product.class.php b/htdocs/product.class.php index e2568a7a3ae..7211eabedf8 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -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 { diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index b31772ffd23..818f0e27400 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -115,10 +115,14 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc $error++; $mesg='
'.$product->error.'
'; } - if ($ret == 0) + if ($ret == 2) { $error++; - $mesg='
'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct").'
'; + + $product->fetch($product->product_id_already_linked); + $productLink = $product->getNomUrl(1,'supplier'); + + $mesg='
'.$langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink).'
'; } } @@ -136,10 +140,6 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc { $error++; $mesg='
'.$product->error.'
'; - if ($ret == -2) - { - $mesg='
'.$langs->trans("ProductHasAlreadyReferenceInThisSupplier").'
'; - } } } else