@php require_frontend_packages(['datatables']); @endphp @extends('layout.default') @section('title', $__t('Location Content Sheet')) @push('pageStyles') @endpush @section('content')
@php // Convert iterators to arrays once for reuse $locationsArray = iterator_to_array($locations); $locationsResolvedArray = iterator_to_array($locationsResolved); $stockContentArray = iterator_to_array($currentStockLocationContent); @endphp @foreach($locationsArray as $location) @php $currentStockEntriesForLocation = []; 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); }); // 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; } $currentStockEntriesForLocation = array_values($aggregatedEntries); } @endphp @if(count($currentStockEntriesForLocation) == 0) @continue @endif

{{ $location->location_path }} {{ $__t('Print') . ' (' . $__t('this location') . ')' }}

{{ $__t('Time of printing') }}:
@foreach($currentStockEntriesForLocation as $currentStockEntry) @endforeach
{{ $__t('Product') }} {{ $__t('Amount') }} {{ $__t('Consumed amount') . ' / ' . $__t('Notes') }}
{{ FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->name }} {{ $currentStockEntry->amount }} {{ $__n($currentStockEntry->amount, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name, FindObjectInArrayByPropertyValue($quantityunits, 'id', FindObjectInArrayByPropertyValue($products, 'id', $currentStockEntry->product_id)->qu_id_stock)->name_plural, true) }} @if($currentStockEntry->amount_opened > 0){{ $__t('%s opened', $currentStockEntry->amount_opened) }}@endif
@endforeach @stop