diff --git a/changelog/62_UNRELEASED_xxxx-xx-xx.md b/changelog/62_UNRELEASED_xxxx-xx-xx.md index d3a89547..0cf217ee 100644 --- a/changelog/62_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/62_UNRELEASED_xxxx-xx-xx.md @@ -29,6 +29,7 @@ - Product barcodes are now enforced to be unique across products - On the stock overview page it's now also possible to search/filter by product barcodes (via the general search field) - The product picker on the consume page now only shows products which are currently in stock +- Added a filter option to only show in-stock products on the products list page (master data) - Fixed that editing stock entries was not possible - Fixed that consuming with Scan Mode was not possible - Fixed that the current stock total value (header of the stock overview page) didn't include decimal amounts (thanks @Ape) diff --git a/controllers/StockController.php b/controllers/StockController.php index 4f6c38d7..9516a033 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -233,15 +233,19 @@ class StockController extends BaseController public function ProductsList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args) { - if (isset($request->getQueryParams()['include_disabled'])) + $products = $this->getDatabase()->products(); + if (!isset($request->getQueryParams()['include_disabled'])) { - $products = $this->getDatabase()->products()->orderBy('name', 'COLLATE NOCASE'); + $products = $products->where('active = 1'); } - else + + if (isset($request->getQueryParams()['only_in_stock'])) { - $products = $this->getDatabase()->products()->where('active = 1')->orderBy('name', 'COLLATE NOCASE'); + $products = $products->where('id IN (SELECT product_id from stock_current WHERE amount_aggregated > 0)'); } + $products = $products->orderBy('name', 'COLLATE NOCASE'); + return $this->renderPage($response, 'products', [ 'products' => $products, 'locations' => $this->getDatabase()->locations()->orderBy('name', 'COLLATE NOCASE'), diff --git a/localization/strings.pot b/localization/strings.pot index 23e44535..46dfcc81 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2144,3 +2144,6 @@ msgstr "" msgid "Only done items" msgstr "" + +msgid "Show only in-stock products" +msgstr "" diff --git a/public/viewjs/products.js b/public/viewjs/products.js index 7feb7e9c..7aa3b9a2 100644 --- a/public/viewjs/products.js +++ b/public/viewjs/products.js @@ -38,7 +38,14 @@ $("#clear-filter-button").on("click", function() $("#product-group-filter").val("all"); productsTable.column(6).search("").draw(); productsTable.search("").draw(); - $("#show-disabled").prop('checked', false); + if ($("#show-disabled").is(":checked") || $("#show-only-in-stock").is(":checked")) + { + $("#show-disabled").prop("checked", false); + $("#show-only-in-stock").prop("checked", false); + RemoveUriParam("include_disabled"); + RemoveUriParam("only_in_stock"); + window.location.reload(); + } }); if (typeof GetUriParam("product-group") !== "undefined") @@ -90,12 +97,28 @@ $("#show-disabled").change(function() { if (this.checked) { - window.location.href = U('/products?include_disabled'); + UpdateUriParam("include_disabled", "true"); } else { - window.location.href = U('/products'); + RemoveUriParam("include_disabled"); } + + window.location.reload(); +}); + +$("#show-only-in-stock").change(function() +{ + if (this.checked) + { + UpdateUriParam("only_in_stock", "true"); + } + else + { + RemoveUriParam("only_in_stock"); + } + + window.location.reload(); }); if (GetUriParam('include_disabled')) diff --git a/views/products.blade.php b/views/products.blade.php index 310157a1..b23132a7 100644 --- a/views/products.blade.php +++ b/views/products.blade.php @@ -71,7 +71,7 @@ -