mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-05 17:18:13 +01:00
Fix: [ bug #1206 ] PMP price is bad calculated
This commit is contained in:
@@ -224,7 +224,8 @@ class CommandeFournisseur extends CommonOrder
|
||||
$line->tva_tx = $objp->tva_tx;
|
||||
$line->localtax1_tx = $objp->localtax1_tx;
|
||||
$line->localtax2_tx = $objp->localtax2_tx;
|
||||
$line->subprice = $objp->subprice;
|
||||
$line->subprice = $objp->subprice; // deprecated
|
||||
$line->pu_ht = $objp->subprice; // Unit price HT
|
||||
$line->remise_percent = $objp->remise_percent;
|
||||
$line->total_ht = $objp->total_ht;
|
||||
$line->total_tva = $objp->total_tva;
|
||||
@@ -462,7 +463,9 @@ class CommandeFournisseur extends CommonOrder
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increment stock of product (and sub-products)
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderBackToDraftInDolibarr",$this->ref));
|
||||
$up_ht_disc=$this->lines[$i]->subprice;
|
||||
if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU');
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("OrderBackToDraftInDolibarr",$this->ref));
|
||||
if ($result < 0) { $error++; }
|
||||
}
|
||||
}
|
||||
@@ -715,7 +718,9 @@ class CommandeFournisseur extends CommonOrder
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We decrement stock of product (and sub-products)
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderApprovedInDolibarr",$this->ref));
|
||||
$up_ht_disc=$this->lines[$i]->subprice;
|
||||
if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU');
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("OrderApprovedInDolibarr",$this->ref));
|
||||
if ($result < 0) { $error++; }
|
||||
}
|
||||
}
|
||||
@@ -1308,7 +1313,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
* @param int $product Id of product to dispatch
|
||||
* @param double $qty Qty to dispatch
|
||||
* @param int $entrepot Id of warehouse to add product
|
||||
* @param double $price Price for PMP value calculation
|
||||
* @param double $price Unit Price for PMP value calculation (Unit price without Tax and taking into account discount)
|
||||
* @param string $comment Comment for stock movement
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
@@ -1364,6 +1369,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
$mouv = new MouvementStock($this->db);
|
||||
if ($product > 0)
|
||||
{
|
||||
// $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on)
|
||||
$result=$mouv->reception($user, $product, $entrepot, $qty, $price, $comment);
|
||||
if ($result < 0)
|
||||
{
|
||||
|
||||
@@ -883,7 +883,9 @@ class FactureFournisseur extends CommonInvoice
|
||||
{
|
||||
$mouvP = new MouvementStock($this->db);
|
||||
// We increase stock for product
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->pu_ht, $langs->trans("InvoiceValidatedInDolibarr",$num));
|
||||
$up_ht_disc=$this->lines[$i]->pu_ht;
|
||||
if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU');
|
||||
$result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr",$num));
|
||||
if ($result < 0) { $error++; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ $langs->load('products');
|
||||
$langs->load('stocks');
|
||||
|
||||
// Security check
|
||||
$id = isset($_GET["id"])?$_GET["id"]:'';
|
||||
$id = GETPOST("id",'int');
|
||||
if ($user->societe_id) $socid=$user->societe_id;
|
||||
$result = restrictedArea($user, 'fournisseur', $id, '', 'commande');
|
||||
|
||||
@@ -64,7 +64,9 @@ $mesg='';
|
||||
if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
|
||||
{
|
||||
$commande = new CommandeFournisseur($db);
|
||||
$commande->fetch($_GET["id"]);
|
||||
$commande->fetch($id);
|
||||
|
||||
$db->begin();
|
||||
|
||||
foreach($_POST as $key => $value)
|
||||
{
|
||||
@@ -73,7 +75,7 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece
|
||||
$prod = "product_".$reg[1];
|
||||
$qty = "qty_".$reg[1];
|
||||
$ent = "entrepot_".$reg[1];
|
||||
$pu = "pu_".$reg[1];
|
||||
$pu = "pu_".$reg[1]; // This is unit price including discount
|
||||
if ($_POST[$ent] > 0)
|
||||
{
|
||||
$result = $commande->DispatchProduct($user, $_POST[$prod], $_POST[$qty], $_POST[$ent], $_POST[$pu], $_POST["comment"]);
|
||||
@@ -96,17 +98,19 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece
|
||||
$result_trigger=$interface->run_triggers('ORDER_SUPPLIER_DISPATCH',$commande,$user,$langs,$conf);
|
||||
if ($result_trigger < 0) { $error++; $commande->errors=$interface->errors; }
|
||||
// Fin appel triggers
|
||||
|
||||
$db->commit();
|
||||
}
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$db->commit();
|
||||
|
||||
header("Location: dispatch.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->rollback();
|
||||
|
||||
$mesg='<div class="error">'.$langs->trans($commande->error).'</div>';
|
||||
}
|
||||
}
|
||||
@@ -232,12 +236,12 @@ if ($id > 0 || ! empty($ref))
|
||||
$db->free($resql);
|
||||
}
|
||||
|
||||
$sql = "SELECT l.fk_product, l.subprice, SUM(l.qty) as qty,";
|
||||
$sql = "SELECT l.fk_product, l.subprice, l.remise_percent, SUM(l.qty) as qty,";
|
||||
$sql.= " p.ref, p.label";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid";
|
||||
$sql.= " WHERE l.fk_commande = ".$commande->id;
|
||||
$sql.= " GROUP BY p.ref, p.label, l.fk_product, l.subprice"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
|
||||
$sql.= " GROUP BY p.ref, p.label, l.fk_product, l.subprice, l.remise_percent"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product
|
||||
$sql.= " ORDER BY p.ref, p.label";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
@@ -283,12 +287,16 @@ if ($id > 0 || ! empty($ref))
|
||||
print "<tr ".$bc[$var].">";
|
||||
print '<td>';
|
||||
print '<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</a>';
|
||||
print ' - '.$objp->label;
|
||||
print ' - '.$objp->label."\n";
|
||||
// To show detail cref and description value, we must make calculation by cref
|
||||
//print ($objp->cref?' ('.$objp->cref.')':'');
|
||||
//if ($objp->description) print '<br>'.nl2br($objp->description);
|
||||
print '<input name="product_'.$i.'" type="hidden" value="'.$objp->fk_product.'">';
|
||||
print '<input name="pu_'.$i.'" type="hidden" value="'.$objp->subprice.'">';
|
||||
print '<input name="product_'.$i.'" type="hidden" value="'.$objp->fk_product.'">'."\n";
|
||||
|
||||
$up_ht_disc=$objp->subprice;
|
||||
if (! empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');
|
||||
|
||||
print '<input name="pu_'.$i.'" type="hidden" value="'.$up_ht_disc.'">'."<!-- This is a up including discount -->\n";
|
||||
print "</td>\n";
|
||||
|
||||
print '<td align="right">'.$objp->qty.'</td>';
|
||||
|
||||
Reference in New Issue
Block a user