mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 20:26:42 +00:00
Optimized CurrentVolatileStock
handling (fixes #2341)
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
### Stock
|
### Stock
|
||||||
|
|
||||||
- Fixed that the location dropdown on the consume page contained the same location multiple times if there are currently stock entries at multiple locations of the corresponding product
|
- Fixed that the location dropdown on the consume page contained the same location multiple times if there are currently stock entries at multiple locations of the corresponding product
|
||||||
|
- Fixed that the status filter "n products are overdue" on the stock overview page also counted/included stock entries due today or tomorrow
|
||||||
|
|
||||||
### Shopping list
|
### Shopping list
|
||||||
|
|
||||||
|
@@ -619,12 +619,9 @@ class StockService extends BaseService
|
|||||||
return $pluginOutput;
|
return $pluginOutput;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static $CurrentStockCache = null;
|
public function GetCurrentStock($customWhere = '')
|
||||||
public function GetCurrentStock(bool $useCache = false)
|
|
||||||
{
|
{
|
||||||
if (!$useCache || self::$CurrentStockCache == null)
|
$sql = 'SELECT * FROM stock_current ' . $customWhere;
|
||||||
{
|
|
||||||
$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);
|
||||||
$relevantProducts = $this->getDatabase()->products()->where('id IN (SELECT product_id FROM (' . $sql . ') x)');
|
$relevantProducts = $this->getDatabase()->products()->where('id IN (SELECT product_id FROM (' . $sql . ') x)');
|
||||||
|
|
||||||
@@ -634,10 +631,7 @@ class StockService extends BaseService
|
|||||||
$currentStockMapped[$product->id][0]->product = $product;
|
$currentStockMapped[$product->id][0]->product = $product;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$CurrentStockCache = array_column($currentStockMapped, 0);
|
return array_column($currentStockMapped, 0);
|
||||||
}
|
|
||||||
|
|
||||||
return self::$CurrentStockCache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetCurrentStockLocationContent($includeOutOfStockProductsAtTheDefaultLocation = false)
|
public function GetCurrentStockLocationContent($includeOutOfStockProductsAtTheDefaultLocation = false)
|
||||||
@@ -665,24 +659,19 @@ 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(true);
|
|
||||||
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime("+$days days")), '<');
|
|
||||||
|
|
||||||
if ($excludeOverdue)
|
if ($excludeOverdue)
|
||||||
{
|
{
|
||||||
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime('-1 days')), '>');
|
return $this->GetCurrentStock("WHERE best_before_date <= date('now', '$days days') AND best_before_date >= date()");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return $this->GetCurrentStock("WHERE best_before_date <= date('now', '$days days')");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $currentStock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetExpiredProducts()
|
public function GetExpiredProducts()
|
||||||
{
|
{
|
||||||
$currentStock = $this->GetCurrentStock(true);
|
return $this->GetCurrentStock('WHERE best_before_date < date() AND due_type = 2');
|
||||||
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d 23:59:59', strtotime('-1 days')), '<');
|
|
||||||
$currentStock = FindAllObjectsInArrayByPropertyValue($currentStock, 'due_type', 2);
|
|
||||||
|
|
||||||
return $currentStock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetMissingProducts()
|
public function GetMissingProducts()
|
||||||
@@ -705,7 +694,7 @@ class StockService extends BaseService
|
|||||||
throw new \Exception('Product does not exist or is inactive');
|
throw new \Exception('Product does not exist or is inactive');
|
||||||
}
|
}
|
||||||
|
|
||||||
$stockCurrentRow = FindObjectinArrayByPropertyValue($this->GetCurrentStock(), 'product_id', $productId);
|
$stockCurrentRow = FindObjectInArrayByPropertyValue($this->GetCurrentStock(), 'product_id', $productId);
|
||||||
if ($stockCurrentRow == null)
|
if ($stockCurrentRow == null)
|
||||||
{
|
{
|
||||||
$stockCurrentRow = new \stdClass();
|
$stockCurrentRow = new \stdClass();
|
||||||
|
Reference in New Issue
Block a user