Adapt shopping list add expired products for #851

This commit is contained in:
Bernd Bestel
2020-11-15 22:38:21 +01:00
parent 1bbd7787d8
commit 7b4edf3147
8 changed files with 110 additions and 9 deletions

View File

@@ -60,7 +60,6 @@ class StockService extends BaseService
}
$overdueProducts = $this->GetDueProducts(-1);
foreach ($overdueProducts as $overdueProduct)
{
$product = $this->getDatabase()->products()->where('id', $overdueProduct->product_id)->fetch();
@@ -78,6 +77,31 @@ class StockService extends BaseService
}
}
public function AddExpiredProductsToShoppingList($listId = 1)
{
if (!$this->ShoppingListExists($listId))
{
throw new \Exception('Shopping list does not exist');
}
$expiredProducts = $this->GetExpiredProducts();
foreach ($expiredProducts as $expiredProduct)
{
$product = $this->getDatabase()->products()->where('id', $expiredProduct->product_id)->fetch();
$alreadyExistingEntry = $this->getDatabase()->shopping_list()->where('product_id', $expiredProduct->product_id)->fetch();
if (!$alreadyExistingEntry)
{
$shoppinglistRow = $this->getDatabase()->shopping_list()->createRow([
'product_id' => $expiredProduct->product_id,
'amount' => 1,
'shopping_list_id' => $listId
]);
$shoppinglistRow->save();
}
}
}
public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null, $shoppingLocationId = null, &$transactionId = null)
{
if (!$this->ProductExists($productId))