Fixed GetCurrentStock caching

This commit is contained in:
Bernd Bestel
2023-09-02 09:12:37 +02:00
parent 60adda2b42
commit 1f7580af3f

View File

@@ -620,9 +620,9 @@ class StockService extends BaseService
} }
private static $CurrentStockCache = null; private static $CurrentStockCache = null;
public function GetCurrentStock() public function GetCurrentStock(bool $useCache = false)
{ {
if (self::$CurrentStockCache == null) if (!$useCache || self::$CurrentStockCache == null)
{ {
$sql = 'SELECT * FROM stock_current'; $sql = 'SELECT * FROM stock_current';
$currentStockMapped = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_OBJ); $currentStockMapped = $this->getDatabaseService()->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_OBJ);
@@ -665,7 +665,7 @@ class StockService extends BaseService
public function GetDueProducts(int $days = 5, bool $excludeOverdue = false) public function GetDueProducts(int $days = 5, bool $excludeOverdue = false)
{ {
$currentStock = $this->GetCurrentStock(); $currentStock = $this->GetCurrentStock(true);
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime("+$days days")), '<'); $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime("+$days days")), '<');
if ($excludeOverdue) if ($excludeOverdue)
@@ -678,7 +678,7 @@ class StockService extends BaseService
public function GetExpiredProducts() public function GetExpiredProducts()
{ {
$currentStock = $this->GetCurrentStock(); $currentStock = $this->GetCurrentStock(true);
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime('-1 days')), '<'); $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime('-1 days')), '<');
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'due_type', 2); $currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'due_type', 2);