Prevent opening more products than are unopened in stock

This commit is contained in:
Bernd Bestel
2018-11-18 13:35:21 +01:00
parent a489190e81
commit 2ff5faacc0
5 changed files with 31 additions and 6 deletions

View File

@@ -265,11 +265,11 @@ class StockService extends BaseService
throw new \Exception('Product does not exist');
}
$productStockAmount = $this->Database->stock()->where('product_id', $productId)->sum('amount');
$productStockAmountUnopened = $this->Database->stock()->where('product_id = :1 AND open = 0', $productId)->sum('amount');
$potentialStockEntries = $this->GetProductStockEntries($productId, true);
$product = $this->Database->products($productId);
if ($amount > $productStockAmount)
if ($amount > $productStockAmountUnopened)
{
return false;
}