diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 6a3d7918ac3..c67b15bc619 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -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) { diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 060d2d51a83..d8f15c5b9b3 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -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++; } } } diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 48a2614deb0..4bc7a22b06b 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -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='
'.$langs->trans($commande->error).'
'; } } @@ -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 ""; print ''; print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; - 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 '
'.nl2br($objp->description); - print ''; - print ''; + print ''."\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 ''."\n"; print "\n"; print ''.$objp->qty.''; @@ -346,7 +354,7 @@ if ($id > 0 || ! empty($ref)) print ''; } - + dol_fiche_end(); // List of already dispatching @@ -369,9 +377,9 @@ if ($id > 0 || ! empty($ref)) if ($num > 0) { print "
\n"; - + print_titre($langs->trans("ReceivingForSameOrder")); - + print ''; print '';