mirror of
https://github.com/grocy/grocy.git
synced 2026-04-11 15:06:15 +02:00
Consume products if less than .001 stock remains
This commit is contained in:
parent
4d79a94817
commit
0475b8c093
|
|
@ -377,6 +377,31 @@ class StockService extends BaseService
|
||||||
{
|
{
|
||||||
$restStockAmount = $stockEntry->amount - $amount;
|
$restStockAmount = $stockEntry->amount - $amount;
|
||||||
|
|
||||||
|
if ($restStockAmount < 0.001) {
|
||||||
|
//Take the full amount if stock is less than .01
|
||||||
|
|
||||||
|
$logRow = $this->Database->stock_log()->createRow(array(
|
||||||
|
'product_id' => $stockEntry->product_id,
|
||||||
|
'amount' => $stockEntry->amount * -1,
|
||||||
|
'best_before_date' => $stockEntry->best_before_date,
|
||||||
|
'purchased_date' => $stockEntry->purchased_date,
|
||||||
|
'used_date' => date('Y-m-d'),
|
||||||
|
'spoiled' => $spoiled,
|
||||||
|
'stock_id' => $stockEntry->stock_id,
|
||||||
|
'transaction_type' => $transactionType,
|
||||||
|
'price' => $stockEntry->price,
|
||||||
|
'opened_date' => $stockEntry->opened_date,
|
||||||
|
'recipe_id' => $recipeId,
|
||||||
|
'transaction_id' => $transactionId
|
||||||
|
));
|
||||||
|
$logRow->save();
|
||||||
|
|
||||||
|
$stockEntry->delete();
|
||||||
|
|
||||||
|
$amount = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$logRow = $this->Database->stock_log()->createRow(array(
|
$logRow = $this->Database->stock_log()->createRow(array(
|
||||||
'product_id' => $stockEntry->product_id,
|
'product_id' => $stockEntry->product_id,
|
||||||
'amount' => $amount * -1,
|
'amount' => $amount * -1,
|
||||||
|
|
@ -400,6 +425,7 @@ class StockService extends BaseService
|
||||||
$amount = 0;
|
$amount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->Database->lastInsertId();
|
return $this->Database->lastInsertId();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user