mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-12 10:52:37 +01:00
Fix: [ bug #1206 ] PMP price is bad calculated
This commit is contained in:
@@ -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);
|
||||
@@ -278,17 +282,21 @@ if ($id > 0 || ! empty($ref))
|
||||
if ($remaintodispatch)
|
||||
{
|
||||
$nbproduct++;
|
||||
|
||||
|
||||
$var=!$var;
|
||||
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>';
|
||||
@@ -346,7 +354,7 @@ if ($id > 0 || ! empty($ref))
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
// List of already dispatching
|
||||
@@ -369,9 +377,9 @@ if ($id > 0 || ! empty($ref))
|
||||
if ($num > 0)
|
||||
{
|
||||
print "<br/>\n";
|
||||
|
||||
|
||||
print_titre($langs->trans("ReceivingForSameOrder"));
|
||||
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
|
||||
Reference in New Issue
Block a user