Fix: on récupère un tarif existant différent si la quantité est insuffisante
This commit is contained in:
parent
c28d872922
commit
1211ab9093
@ -142,6 +142,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->cree
|
|||||||
$tva_tx,
|
$tva_tx,
|
||||||
$prodfournprice->product_id,
|
$prodfournprice->product_id,
|
||||||
$_POST['idprodfournprice'],
|
$_POST['idprodfournprice'],
|
||||||
|
$prodfournprice->fourn_ref,
|
||||||
$_POST['remise_percent'],
|
$_POST['remise_percent'],
|
||||||
'HT'
|
'HT'
|
||||||
);
|
);
|
||||||
|
|||||||
@ -650,7 +650,7 @@ class CommandeFournisseur extends Commande
|
|||||||
* \param price_base_type HT or TTC
|
* \param price_base_type HT or TTC
|
||||||
* \param int <0 si ko, >0 si ok
|
* \param int <0 si ko, >0 si ok
|
||||||
*/
|
*/
|
||||||
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $fk_prod_fourn_price=0, $remise_percent=0, $price_base_type='HT')
|
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0, $price_base_type='HT')
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
|
|
||||||
@ -677,7 +677,7 @@ class CommandeFournisseur extends Commande
|
|||||||
$prod = new Product($this->db, $fk_product);
|
$prod = new Product($this->db, $fk_product);
|
||||||
if ($prod->fetch($fk_product) > 0)
|
if ($prod->fetch($fk_product) > 0)
|
||||||
{
|
{
|
||||||
$result=$prod->get_buyprice($fk_prod_fourn_price,$qty);
|
$result=$prod->get_buyprice($fk_prod_fourn_price,$qty,$fk_product,$fourn_ref);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$label = $prod->libelle;
|
$label = $prod->libelle;
|
||||||
|
|||||||
@ -96,6 +96,8 @@ class Product
|
|||||||
|
|
||||||
//! Id du fournisseur
|
//! Id du fournisseur
|
||||||
var $product_fourn_id;
|
var $product_fourn_id;
|
||||||
|
//! Ref fournisseur
|
||||||
|
var $fourn_ref;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructeur de la classe
|
* \brief Constructeur de la classe
|
||||||
@ -665,7 +667,7 @@ class Product
|
|||||||
* \param qty Quantité du produit
|
* \param qty Quantité du produit
|
||||||
* \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé
|
* \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé
|
||||||
*/
|
*/
|
||||||
function get_buyprice($prodfournprice,$qty)
|
function get_buyprice($prodfournprice,$qty,$product_id,$fourn_ref)
|
||||||
{
|
{
|
||||||
$result = 0;
|
$result = 0;
|
||||||
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pf.ref_fourn";
|
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity, pf.ref_fourn";
|
||||||
@ -689,23 +691,30 @@ class Product
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// On refait le meme select mais sans critere de quantite
|
// On refait le meme select sur la ref et l'id du produit
|
||||||
$sql = "SELECT pfp.price as price, pfp.quantity as quantity, pf.fk_soc";
|
$sql = "SELECT pfp.price as price, pfp.quantity as quantity, pf.fk_soc, pf.ref_fourn";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
||||||
$sql.= " WHERE pf.rowid = pfp.fk_product_fournisseur";
|
$sql.= " WHERE pf.rowid = pfp.fk_product_fournisseur";
|
||||||
$sql.= " AND pfp.rowid = ".$prodfournprice;
|
$sql.= " AND pf.ref_fourn = '".$fourn_ref."'";
|
||||||
|
$sql.= " AND pf.fk_product = ".$product_id;
|
||||||
|
$sql.= " AND quantity <= ".$qty;
|
||||||
|
$sql.= " ORDER BY pfp.quantity DESC";
|
||||||
|
$sql.= " LIMIT 1";
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$num=$this->db->num_rows($result);
|
$obj = $this->db->fetch_object($resql);
|
||||||
if ($num)
|
if ($obj && $obj->quantity > 0)
|
||||||
{
|
{
|
||||||
return -1; // Ce produit existe chez ce fournisseur mais qté insuffisante
|
$this->buyprice = $obj->price; // \deprecated
|
||||||
|
$this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
|
||||||
|
$this->ref_fourn = $obj->ref_fourn;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return 0; // Ce produit n'existe pas chez ce fournisseur
|
return -1; // Ce produit existe chez ce fournisseur mais qté insuffisante
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user