Skip to content

Commit

Permalink
Merge pull request #9904 from atm-maxime/fix_replenish_qtymin
Browse files Browse the repository at this point in the history
FIX replenish wasn't caring about supplier price min quantity #9561
  • Loading branch information
eldy committed Oct 30, 2018
2 parents 8ce035f + 46d3bec commit a231932
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions htdocs/langs/en_US/errors.lang
Expand Up @@ -88,6 +88,7 @@ ErrorFileIsInfectedWithAVirus=The antivirus program was not able to validate the
ErrorSpecialCharNotAllowedForField=Special characters are not allowed for field "%s"
ErrorNumRefModel=A reference exists into database (%s) and is not compatible with this numbering rule. Remove record or renamed reference to activate this module.
ErrorQtyTooLowForThisSupplier=Quantity too low for this vendor or no price defined on this product for this supplier
ErrorOrdersNotCreatedQtyTooLow=Some orders haven't been created beacuse of too low quantity
ErrorModuleSetupNotComplete=Setup of module looks to be uncomplete. Go on Home - Setup - Modules to complete.
ErrorBadMask=Error on mask
ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number
Expand Down
45 changes: 25 additions & 20 deletions htdocs/product/stock/replenish.php
Expand Up @@ -106,12 +106,15 @@
{
$linecount = GETPOST('linecount', 'int');
$box = 0;
$errorQty = 0;
unset($_POST['linecount']);
if ($linecount > 0)
{
$db->begin();

$suppliers = array();
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
$productsupplier = new ProductFournisseur($db);
for ($i = 0; $i < $linecount; $i++)
{
if (GETPOST('choose' . $i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0)
Expand All @@ -121,47 +124,47 @@
$supplierpriceid = GETPOST('fourn'.$i, 'int');
//get all the parameters needed to create a line
$qty = GETPOST('tobuy'.$i, 'int');
//$desc = GETPOST('desc'.$i, 'alpha');
$sql = 'SELECT fk_product, fk_soc, ref_fourn';
$sql .= ', tva_tx, unitprice, remise_percent FROM ';
$sql .= MAIN_DB_PREFIX . 'product_fournisseur_price';
$sql .= ' WHERE rowid = ' . $supplierpriceid;
$resql = $db->query($sql);
if ($resql && $db->num_rows($resql) > 0)
$idprod=$productsupplier->get_buyprice($supplierpriceid, $qty);
$res=$productsupplier->fetch($idprod);
if ($res && $idprod > 0)
{
if ($qty)
{
//might need some value checks
$obj = $db->fetch_object($resql);
$line = new CommandeFournisseurLigne($db);
$line->qty = $qty;
$line->fk_product = $obj->fk_product;
$line->fk_product = $idprod;

$product = new Product($db);
$product->fetch($obj->fk_product);
//$product = new Product($db);
//$product->fetch($obj->fk_product);
if (! empty($conf->global->MAIN_MULTILANGS))
{
$product->getMultiLangs();
$productsupplier->getMultiLangs();
}
$line->desc = $product->description;
$line->desc = $productsupplier->description;
if (! empty($conf->global->MAIN_MULTILANGS))
{
// TODO Get desc in language of thirdparty
}

$line->tva_tx = $obj->tva_tx;
$line->subprice = $obj->unitprice;
$line->total_ht = $obj->unitprice * $qty;
$line->tva_tx = $productsupplier->vatrate_supplier;
$line->subprice = $productsupplier->fourn_pu;
$line->total_ht = $productsupplier->fourn_pu * $qty;
$tva = $line->tva_tx / 100;
$line->total_tva = $line->total_ht * $tva;
$line->total_ttc = $line->total_ht + $line->total_tva;
$line->remise_percent = $obj->remise_percent;
$line->ref_fourn = $obj->ref_fourn;
$line->type = $product->type;
$line->fk_unit = $product->fk_unit;
$suppliers[$obj->fk_soc]['lines'][] = $line;
$line->remise_percent = $productsupplier->remise_percent;
$line->ref_fourn = $productsupplier->ref_supplier;
$line->type = $productsupplier->type;
$line->fk_unit = $productsupplier->fk_unit;
$suppliers[$productsupplier->fourn_socid]['lines'][] = $line;
}
}
elseif ($idprod == -1)
{
$errorQty++;
}
else
{
$error=$db->lasterror();
Expand Down Expand Up @@ -242,6 +245,8 @@
}
}

if($errorQty) setEventMessages($langs->trans('ErrorOrdersNotCreatedQtyTooLow'), null, 'warnings');

if (! $fail && $id)
{
$db->commit();
Expand Down

0 comments on commit a231932

Please sign in to comment.