diff --git a/controllers/StockController.php b/controllers/StockController.php index cf2011a3..c5afe868 100644 --- a/controllers/StockController.php +++ b/controllers/StockController.php @@ -95,7 +95,7 @@ class StockController extends BaseController 'locations' => $this->getDatabase()->locations_hierarchy()->orderBy('location_path', 'COLLATE NOCASE'), 'locationsResolved' => $this->getDatabase()->locations_resolved(), 'currentStockLocationContent' => $this->getStockService()->GetCurrentStockLocationContent(isset($request->getQueryParams()['include_out_of_stock'])), - 'showLeafLocationsOnly' => isset($request->getQueryParams()['leaf_locations_only']) + 'showDirectContentOnly' => isset($request->getQueryParams()['direct_content_only']) ]); } diff --git a/localization/strings.pot b/localization/strings.pot index 1d3c6265..dd1e8f56 100644 --- a/localization/strings.pot +++ b/localization/strings.pot @@ -2477,8 +2477,8 @@ msgstr "" msgid "List actions" msgstr "" -msgid "Show only leaf locations" +msgid "Show direct content only" msgstr "" -msgid "When enabled, only locations without sub-locations are shown. When disabled, parent locations show aggregated content from all sub-locations." +msgid "When enabled, each location shows only products stored directly there. When disabled, locations include products from all sub-locations." msgstr "" diff --git a/public/viewjs/locationcontentsheet.js b/public/viewjs/locationcontentsheet.js index 8ba9b542..9def3ad3 100644 --- a/public/viewjs/locationcontentsheet.js +++ b/public/viewjs/locationcontentsheet.js @@ -32,15 +32,15 @@ if (GetUriParam("include_out_of_stock")) $("#include-out-of-stock").prop("checked", false); } -$(document).on("change", "#leaf-locations-only", function() +$(document).on("change", "#direct-content-only", function() { if (this.checked) { - UpdateUriParam("leaf_locations_only", true); + UpdateUriParam("direct_content_only", true); } else { - RemoveUriParam("leaf_locations_only"); + RemoveUriParam("direct_content_only"); } window.location.reload(); diff --git a/views/locationcontentsheet.blade.php b/views/locationcontentsheet.blade.php index e0ee6dd4..958883b4 100644 --- a/views/locationcontentsheet.blade.php +++ b/views/locationcontentsheet.blade.php @@ -53,15 +53,15 @@
+ id="direct-content-only" + @if($showDirectContentOnly) checked @endif>
@@ -88,59 +88,48 @@ $locationsArray = iterator_to_array($locations); $locationsResolvedArray = iterator_to_array($locationsResolved); $stockContentArray = iterator_to_array($currentStockLocationContent); -@endphp + @endphp @foreach($locationsArray as $location) @php - // Determine if this location has children - $hasChildren = count(array_filter($locationsArray, function($loc) use ($location) { - return $loc->parent_location_id == $location->id; - })) > 0; - - // Flag to skip this location - $skipLocation = $showLeafLocationsOnly && $hasChildren; - $currentStockEntriesForLocation = []; - if (!$skipLocation) { - // Get stock entries for this location - if ($showLeafLocationsOnly) { - // Only show products directly at this location - $currentStockEntriesForLocation = array_filter($stockContentArray, function($entry) use ($location) { - return $entry->location_id == $location->id; - }); - } else { - // Aggregate products from this location and all descendant locations - $descendantLocationIds = array_map(function($r) { - return $r->location_id; - }, array_filter($locationsResolvedArray, function($r) use ($location) { - return $r->ancestor_location_id == $location->id; - })); + if ($showDirectContentOnly) { + // Only show products directly at this location + $currentStockEntriesForLocation = array_filter($stockContentArray, function($entry) use ($location) { + return $entry->location_id == $location->id; + }); + } else { + // Aggregate products from this location and all descendant locations + $descendantLocationIds = array_map(function($r) { + return $r->location_id; + }, array_filter($locationsResolvedArray, function($r) use ($location) { + return $r->ancestor_location_id == $location->id; + })); - $currentStockEntriesForLocation = array_filter($stockContentArray, function($entry) use ($descendantLocationIds) { - return in_array($entry->location_id, $descendantLocationIds); - }); + $currentStockEntriesForLocation = array_filter($stockContentArray, function($entry) use ($descendantLocationIds) { + return in_array($entry->location_id, $descendantLocationIds); + }); - // Aggregate amounts by product_id - $aggregatedEntries = []; - foreach ($currentStockEntriesForLocation as $entry) { - $productId = $entry->product_id; - if (!isset($aggregatedEntries[$productId])) { - $aggregatedEntries[$productId] = (object)[ - 'product_id' => $productId, - 'location_id' => $location->id, - 'amount' => 0, - 'amount_opened' => 0 - ]; - } - $aggregatedEntries[$productId]->amount += $entry->amount; - $aggregatedEntries[$productId]->amount_opened += $entry->amount_opened; + // Aggregate amounts by product_id + $aggregatedEntries = []; + foreach ($currentStockEntriesForLocation as $entry) { + $productId = $entry->product_id; + if (!isset($aggregatedEntries[$productId])) { + $aggregatedEntries[$productId] = (object)[ + 'product_id' => $productId, + 'location_id' => $location->id, + 'amount' => 0, + 'amount_opened' => 0 + ]; } - $currentStockEntriesForLocation = array_values($aggregatedEntries); + $aggregatedEntries[$productId]->amount += $entry->amount; + $aggregatedEntries[$productId]->amount_opened += $entry->amount_opened; } + $currentStockEntriesForLocation = array_values($aggregatedEntries); } @endphp -@if($skipLocation || count($currentStockEntriesForLocation) == 0) +@if(count($currentStockEntriesForLocation) == 0) @continue @endif