mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Fixed volatil stock logic (fixes #69)
This commit is contained in:
parent
9dd57decdf
commit
bb9caf9cc9
@ -126,7 +126,7 @@ class StockApiController extends BaseApiController
|
|||||||
$nextXDays = $request->getQueryParams()['expiring_days'];
|
$nextXDays = $request->getQueryParams()['expiring_days'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$expiringProducts = $this->StockService->GetExpiringProducts($nextXDays);
|
$expiringProducts = $this->StockService->GetExpiringProducts($nextXDays, true);
|
||||||
$expiredProducts = $this->StockService->GetExpiringProducts(-1);
|
$expiredProducts = $this->StockService->GetExpiringProducts(-1);
|
||||||
$missingProducts = $this->StockService->GetMissingProducts();
|
$missingProducts = $this->StockService->GetMissingProducts();
|
||||||
return $this->ApiResponse(array(
|
return $this->ApiResponse(array(
|
||||||
|
@ -8,9 +8,14 @@ class StockService extends BaseService
|
|||||||
const TRANSACTION_TYPE_CONSUME = 'consume';
|
const TRANSACTION_TYPE_CONSUME = 'consume';
|
||||||
const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction';
|
const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction';
|
||||||
|
|
||||||
public function GetCurrentStock()
|
public function GetCurrentStock($includeNotInStockButMissingProducts = false)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT * from stock_current';
|
$sql = 'SELECT * from stock_current';
|
||||||
|
if ($includeNotInStockButMissingProducts)
|
||||||
|
{
|
||||||
|
$sql = 'SELECT * from stock_current WHERE best_before_date IS NOT NULL';
|
||||||
|
}
|
||||||
|
|
||||||
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,10 +25,17 @@ class StockService extends BaseService
|
|||||||
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetExpiringProducts(int $days = 5)
|
public function GetExpiringProducts(int $days = 5, bool $excludeExpired = false)
|
||||||
{
|
{
|
||||||
$currentStock = $this->GetCurrentStock();
|
$currentStock = $this->GetCurrentStock(true);
|
||||||
return FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d', strtotime("+$days days")), '<');
|
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d', strtotime("+$days days")), '<');
|
||||||
|
|
||||||
|
if ($excludeExpired)
|
||||||
|
{
|
||||||
|
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d', strtotime('now')), '>');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $currentStock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetProductDetails(int $productId)
|
public function GetProductDetails(int $productId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user