Use FilteredApiResponse for ProductStockEntries & ProductStockLocations

This commit is contained in:
fipwmaqzufheoxq92ebc 2020-09-01 15:45:09 +02:00
parent c99c7c3859
commit 076e8df7d3
No known key found for this signature in database
GPG Key ID: F4DF989490C2ADB7
2 changed files with 8 additions and 6 deletions

View File

@ -552,12 +552,12 @@ class StockApiController extends BaseApiController
$allowSubproductSubstitution = true; $allowSubproductSubstitution = true;
} }
return $this->ApiResponse($response, $this->getStockService()->GetProductStockEntries($args['productId'], false, $allowSubproductSubstitution)); return $this->FilteredApiResponse($response, $this->getStockService()->GetProductStockEntries($args['productId'], false, $allowSubproductSubstitution, false), $request->getQueryParams());
} }
public function ProductStockLocations(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) public function ProductStockLocations(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
{ {
return $this->ApiResponse($response, $this->getStockService()->GetProductStockLocations($args['productId'])); return $this->FilteredApiResponse($response, $this->getStockService()->GetProductStockLocations($args['productId']), $request->getQueryParams());
} }
public function RemoveProductFromShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) public function RemoveProductFromShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)

View File

@ -603,7 +603,7 @@ class StockService extends BaseService
return $returnData; return $returnData;
} }
public function GetProductStockEntries($productId, $excludeOpened = false, $allowSubproductSubstitution = false) public function GetProductStockEntries($productId, $excludeOpened = false, $allowSubproductSubstitution = false, $ordered = true)
{ {
// In order of next use: // In order of next use:
// First expiring first, then first in first out // First expiring first, then first in first out
@ -621,8 +621,10 @@ class StockService extends BaseService
{ {
$sqlWhereAndOpen = 'AND open = 0'; $sqlWhereAndOpen = 'AND open = 0';
} }
$result = $this->getDatabase()->stock()->where($sqlWhereProductId . ' ' . $sqlWhereAndOpen, $productId);
return $this->getDatabase()->stock()->where($sqlWhereProductId . ' ' . $sqlWhereAndOpen, $productId)->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC')->fetchAll(); if ($ordered)
return $result->orderBy('best_before_date', 'ASC')->orderBy('purchased_date', 'ASC');
return $result;
} }
public function GetProductStockEntriesForLocation($productId, $locationId, $excludeOpened = false, $allowSubproductSubstitution = false) public function GetProductStockEntriesForLocation($productId, $locationId, $excludeOpened = false, $allowSubproductSubstitution = false)
@ -633,7 +635,7 @@ class StockService extends BaseService
public function GetProductStockLocations($productId) public function GetProductStockLocations($productId)
{ {
return $this->getDatabase()->stock_current_locations()->where('product_id', $productId)->fetchAll(); return $this->getDatabase()->stock_current_locations()->where('product_id', $productId);
} }
public function GetStockEntry($entryId) public function GetStockEntry($entryId)