@php $org = auth()->user()->organization ?? \App\Models\System\Organization::find(auth()->user()->organization_id); @endphp @extends('documents.procurement._layout', [ 'documentTitle' => 'Purchase History by Product', 'reference' => null, 'documentDate' => $reportDate, 'noAutoPrint' => true, ]) @section('header-meta')
Period: {{ $from->format('d M Y') }}{{ $until->format('d M Y') }}
Currency: {{ $currency }} (base)
@endsection @section('content')
Products
{{ $byProduct->count() }}
Total Lines
{{ $items->count() }}
Total Qty Ordered
{{ number_format($items->sum('quantity')) }}
@if($byProduct->isEmpty())

No purchase history found for this period.

@else @foreach($byProduct as $productId => $productItems) @php $product = $productItems->first()->product; $totalQty = $productItems->sum('quantity'); $totalCost = $productItems->sum('total_cost_source'); $avgUnit = $totalQty > 0 ? $totalCost / $totalQty : 0; @endphp

{{ $product?->name ?? '—' }} @if($product?->sku) {{ $product->sku }} @endif

Total ordered: {{ number_format($totalQty) }} {{ $product?->uom ?? '' }} · Total cost: {{ number_format($totalCost, 2) }} · Avg unit cost: {{ number_format($avgUnit, 4) }}

@foreach($productItems as $item) @endforeach
LPO Ref Supplier Date Status Qty UoM Unit Cost (src) Total Cost (src)
{{ $item->lpo?->lpo_reference ?? '—' }} {{ $item->lpo?->supplier?->name ?? '—' }} {{ $item->lpo?->purchase_date ? \Carbon\Carbon::parse($item->lpo->purchase_date)->format('d M Y') : '—' }} {{ $item->lpo?->status ? ucwords(str_replace('_',' ',$item->lpo->status)) : '—' }} {{ number_format((float)$item->quantity, 0) }} {{ $item->quantity_uom ?? $product?->uom ?? '—' }} {{ number_format((float)$item->unit_cost_source, 4) }} {{ number_format((float)$item->total_cost_source, 2) }}
@endforeach @endif @endsection