mirror of
https://github.com/grocy/grocy.git
synced 2026-04-08 21:46:16 +02:00
Reuse existing function (GetExpiringProducts) to get expired products
This commit is contained in:
parent
6e342a4a80
commit
586f781348
|
|
@ -59,18 +59,18 @@ class StockService extends BaseService
|
||||||
throw new \Exception('Shopping list does not exist');
|
throw new \Exception('Shopping list does not exist');
|
||||||
}
|
}
|
||||||
|
|
||||||
$expiredProducts = $this->GetExpiredProducts();
|
$expiredProducts = $this->GetExpiringProducts(-1);
|
||||||
|
|
||||||
foreach ($expiredProducts as $expiredProduct)
|
foreach ($expiredProducts as $expiredProduct)
|
||||||
{
|
{
|
||||||
$product = $this->getDatabase()->products()->where('id', $expiredProduct->id)->fetch();
|
$product = $this->getDatabase()->products()->where('id', $expiredProduct->product_id)->fetch();
|
||||||
|
|
||||||
$alreadyExistingEntry = $this->getDatabase()->shopping_list()->where('product_id', $expiredProduct->id)->fetch();
|
$alreadyExistingEntry = $this->getDatabase()->shopping_list()->where('product_id', $expiredProduct->product_id)->fetch();
|
||||||
|
|
||||||
if ( ! $alreadyExistingEntry)
|
if (!$alreadyExistingEntry)
|
||||||
{
|
{
|
||||||
$shoppinglistRow = $this->getDatabase()->shopping_list()->createRow([
|
$shoppinglistRow = $this->getDatabase()->shopping_list()->createRow([
|
||||||
'product_id' => $expiredProduct->id,
|
'product_id' => $expiredProduct->product_id,
|
||||||
'amount' => 1,
|
'amount' => 1,
|
||||||
'shopping_list_id' => $listId
|
'shopping_list_id' => $listId
|
||||||
]);
|
]);
|
||||||
|
|
@ -506,13 +506,6 @@ class StockService extends BaseService
|
||||||
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetExpiredProducts()
|
|
||||||
{
|
|
||||||
$sql = 'SELECT products.* FROM stock JOIN products ON (stock.product_id = products.id) WHERE best_before_date < CURRENT_DATE';
|
|
||||||
|
|
||||||
return $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function GetProductDetails(int $productId)
|
public function GetProductDetails(int $productId)
|
||||||
{
|
{
|
||||||
if (!$this->ProductExists($productId))
|
if (!$this->ProductExists($productId))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user