From 00f7a241f6331f8d658383d72f0ba977b94efbaa Mon Sep 17 00:00:00 2001 From: Kurt Riddlesperger Date: Mon, 14 Oct 2019 22:31:28 -0500 Subject: [PATCH] services StockService#GetProductStockEntriesByLocation: add method --- services/StockService.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/StockService.php b/services/StockService.php index 48276380..e0ef6683 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -176,6 +176,21 @@ class StockService extends BaseService } } + public function GetProductStockEntriesByLocation($productId, $locationId, $excludeOpened = false) + { + // In order of next use: + // First expiring first, then first in first out + + if ($excludeOpened) + { + return $this->Database->stock()->where('product_id = :1 AND location_id = :2 AND open = 0', $productId, $locationId)->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC')->fetchAll(); + } + else + { + return $this->Database->stock()->where('product_id = :1 AND location_id = :2', $productId, $locationId)->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC')->fetchAll(); + } + } + public function AddProduct(int $productId, float $amount, $bestBeforeDate, $transactionType, $purchasedDate, $price, $locationId = null) { if (!$this->ProductExists($productId))