Fixed volatil stock logic (fixes #69)

This commit is contained in:
Bernd Bestel 2018-10-02 17:06:21 +02:00
parent 9dd57decdf
commit bb9caf9cc9
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 17 additions and 5 deletions

View File

@ -126,7 +126,7 @@ class StockApiController extends BaseApiController
$nextXDays = $request->getQueryParams()['expiring_days'];
}
$expiringProducts = $this->StockService->GetExpiringProducts($nextXDays);
$expiringProducts = $this->StockService->GetExpiringProducts($nextXDays, true);
$expiredProducts = $this->StockService->GetExpiringProducts(-1);
$missingProducts = $this->StockService->GetMissingProducts();
return $this->ApiResponse(array(

View File

@ -8,9 +8,14 @@ class StockService extends BaseService
const TRANSACTION_TYPE_CONSUME = 'consume';
const TRANSACTION_TYPE_INVENTORY_CORRECTION = 'inventory-correction';
public function GetCurrentStock()
public function GetCurrentStock($includeNotInStockButMissingProducts = false)
{
$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);
}
@ -20,10 +25,17 @@ class StockService extends BaseService
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();
return FindAllObjectsInArrayByPropertyValue($currentStock, 'best_before_date', date('Y-m-d', strtotime("+$days days")), '<');
$currentStock = $this->GetCurrentStock(true);
$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)