Don't use a second hidden amount field for shopping list entries which were added by "Add missing products to shopping list" (fixes #149)

This commit is contained in:
Bernd Bestel
2019-01-26 13:09:01 +01:00
parent 276bc94cc6
commit eec3515b6d
4 changed files with 83 additions and 13 deletions

View File

@@ -360,20 +360,23 @@ class StockService extends BaseService
foreach ($missingProducts as $missingProduct)
{
$product = $this->Database->products()->where('id', $missingProduct->id)->fetch();
$amount = ceil($missingProduct->amount_missing / $product->qu_factor_purchase_to_stock);
$amountToAdd = ceil($missingProduct->amount_missing / $product->qu_factor_purchase_to_stock);
$alreadyExistingEntry = $this->Database->shopping_list()->where('product_id', $missingProduct->id)->fetch();
if ($alreadyExistingEntry) // Update
{
$alreadyExistingEntry->update(array(
'amount_autoadded' => $amount
));
if ($alreadyExistingEntry->amount < $amountToAdd)
{
$alreadyExistingEntry->update(array(
'amount' => $amountToAdd
));
}
}
else // Insert
{
$shoppinglistRow = $this->Database->shopping_list()->createRow(array(
'product_id' => $missingProduct->id,
'amount_autoadded' => $amount
'amount' => $amountToAdd
));
$shoppinglistRow->save();
}