Fix: Regression, l'ajout d'un produit prdfini de fournisseur sur une facture fournisseur plantait
This commit is contained in:
parent
33ee08034e
commit
76109b21c4
@ -248,60 +248,60 @@ if ($_REQUEST['action'] == 'update_line')
|
||||
|
||||
if ($_GET['action'] == 'add_ligne')
|
||||
{
|
||||
$facfou = new FactureFournisseur($db, '', $_GET['facid']);
|
||||
$facfou = new FactureFournisseur($db, '', $_GET['facid']);
|
||||
|
||||
if ($_POST['idprod'])
|
||||
{
|
||||
$nv_prod = new Product($db);
|
||||
$nv_prod->fetch($_POST['idprod']);
|
||||
|
||||
// cas spécial pour lequel on a les meme référence que le fournisseur
|
||||
// $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
|
||||
$label = $nv_prod->libelle;
|
||||
|
||||
$result=$nv_prod->get_buyprice($_POST['socid'], $_POST['qty']);
|
||||
if ($result > 0)
|
||||
{
|
||||
$societe='';
|
||||
if ($_POST['socid'])
|
||||
{
|
||||
$societe=new Societe($db);
|
||||
$societe->fetch($_POST['socid']);
|
||||
}
|
||||
if ($_POST['prodfournpriceid'])
|
||||
{
|
||||
$nv_prod = new Product($db);
|
||||
$idprod=$nv_prod->get_buyprice($_POST['prodfournpriceid'], $_POST['qty']);
|
||||
if ($idprod > 0)
|
||||
{
|
||||
$result=$nv_prod->fetch($idprod);
|
||||
|
||||
// cas spécial pour lequel on a les meme référence que le fournisseur
|
||||
// $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
|
||||
$label = $nv_prod->libelle;
|
||||
|
||||
$tvatx=get_default_tva($societe,$mysoc,$nv_prod->tva_tx);
|
||||
$societe='';
|
||||
if ($_POST['socid'])
|
||||
{
|
||||
$societe=new Societe($db);
|
||||
$societe->fetch($_POST['socid']);
|
||||
}
|
||||
|
||||
$facfou->addline($label, $nv_prod->fourn_pu, $tvatx, $_POST['qty'], $_POST['idprod']);
|
||||
}
|
||||
if ($result == -1)
|
||||
{
|
||||
// Quantité insuffisante
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$tauxtva = price2num($_POST['tauxtva']);
|
||||
if (! $_POST['label'])
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!empty($_POST['amount']))
|
||||
{
|
||||
$ht = price2num($_POST['amount']);
|
||||
$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ttc = price2num($_POST['amountttc']);
|
||||
$ht = $ttc / (1 + ($tauxtva / 100));
|
||||
$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']);
|
||||
}
|
||||
$tvatx=get_default_tva($societe,$mysoc,$nv_prod->tva_tx);
|
||||
|
||||
$result=$facfou->addline($label, $nv_prod->fourn_pu, $tvatx, $_POST['qty'], $idprod);
|
||||
}
|
||||
}
|
||||
$_GET['action'] = '';
|
||||
if ($idprod == -1)
|
||||
{
|
||||
// Quantité insuffisante
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$tauxtva = price2num($_POST['tauxtva']);
|
||||
if (! $_POST['label'])
|
||||
{
|
||||
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!empty($_POST['amount']))
|
||||
{
|
||||
$ht = price2num($_POST['amount']);
|
||||
$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$ttc = price2num($_POST['amountttc']);
|
||||
$ht = $ttc / (1 + ($tauxtva / 100));
|
||||
$facfou->addline($_POST['label'], $ht, $tauxtva, $_POST['qty']);
|
||||
}
|
||||
}
|
||||
}
|
||||
$_GET['action'] = '';
|
||||
}
|
||||
|
||||
|
||||
@ -817,7 +817,7 @@ else
|
||||
$var=! $var;
|
||||
print '<tr '.$bc[$var].'>';
|
||||
print '<td colspan="4">';
|
||||
$html->select_produits_fournisseurs($fac->socid,'','idprod',$filtre);
|
||||
$html->select_produits_fournisseurs($fac->socid,'','prodfournpriceid',$filtre);
|
||||
print '</td>';
|
||||
print '<td align="right"><input type="text" name="qty" value="1" size="1"></td>';
|
||||
print '<td> </td>';
|
||||
|
||||
@ -1149,7 +1149,7 @@ class Form
|
||||
|
||||
/**
|
||||
\brief Retourne la liste des produits de fournisseurs
|
||||
\param socid Id société (0 pour aucun filtre)
|
||||
\param socid Id société fournisseur (0 pour aucun filtre)
|
||||
\param selected Produit présélectionné
|
||||
\param htmlname Nom de la zone select
|
||||
\param filtretype Pour filtre sur type de produit
|
||||
@ -1174,7 +1174,7 @@ class Form
|
||||
if ($ajaxkeysearch && $ajaxkeysearch != '') $sql.=" AND (pf.ref_fourn like '%".$ajaxkeysearch."%' OR p.label like '%".$ajaxkeysearch."%')";
|
||||
$sql.= " ORDER BY pf.ref_fourn DESC";
|
||||
|
||||
dolibarr_syslog("Form::select_produits_fournisseurs sql=$sql",LOG_DEBUG);
|
||||
dolibarr_syslog("Form::select_produits_fournisseurs sql=".$sql,LOG_DEBUG);
|
||||
|
||||
$result=$this->db->query($sql);
|
||||
if ($result)
|
||||
|
||||
@ -96,8 +96,6 @@ class Product
|
||||
|
||||
//! Id du fournisseur
|
||||
var $product_fourn_id;
|
||||
//! Ref fournisseur
|
||||
var $fourn_ref;
|
||||
|
||||
/**
|
||||
* \brief Constructeur de la classe
|
||||
@ -660,21 +658,23 @@ class Product
|
||||
|
||||
|
||||
/**
|
||||
* \brief Lit le prix pratiqué par un fournisseur
|
||||
* \param prodfournprice Id du tarif
|
||||
* \param qty Quantité du produit
|
||||
* \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé
|
||||
* \brief Lit le prix pratiqué par un fournisseur
|
||||
* On renseigne le couple prodfournprice/qty ou le triplet qty/product_id/fourn_ref)
|
||||
* \param prodfournprice Id du tarif = rowid table product_fournisseur_price
|
||||
* \param qty Quantité du produit
|
||||
* \return int <0 si ko, 0 si ok mais rien trouvé, id_product si ok et trouvé
|
||||
*/
|
||||
function get_buyprice($prodfournprice,$qty,$product_id,$fourn_ref)
|
||||
function get_buyprice($prodfournprice,$qty,$product_id=0,$fourn_ref=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,";
|
||||
$sql.= " pf.fk_product, pf.ref_fourn";
|
||||
$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.= " AND pfp.rowid = ".$prodfournprice;
|
||||
$sql.= " AND pfp.quantity <= ".$qty;
|
||||
|
||||
dolibarr_syslog("Product::get_buyprice $prodfournprice,$qty sql=$sql");
|
||||
dolibarr_syslog("Product::get_buyprice $prodfournprice,$qty sql=".$sql);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -685,19 +685,21 @@ class Product
|
||||
$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;
|
||||
$result=$obj->fk_product;
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 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, pf.ref_fourn";
|
||||
$sql = "SELECT pfp.price as price, pfp.quantity as quantity, pf.fk_soc";
|
||||
$sql.= " pf.fk_product, pf.ref_fourn";
|
||||
$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.= " 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";
|
||||
$sql.= " ORDER BY pfp.quantity DESC";
|
||||
$sql.= " LIMIT 1";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
@ -708,7 +710,8 @@ class Product
|
||||
$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;
|
||||
$result=$obj->fk_product;
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user