@php $org = auth()->user()->organization ?? \App\Models\System\Organization::find(auth()->user()->organization_id); @endphp @extends('documents.procurement._layout', [ 'documentTitle' => 'Material Consumption', 'reference' => null, 'documentDate' => $reportDate, 'noAutoPrint' => true, ]) @section('header-meta')
Period: {{ $from->format('d M Y') }}{{ $until->format('d M Y') }}
Currency: {{ $currency }} (base) · Confirmed consumptions only
@endsection @section('content') @php $byProduct = $consumptions->groupBy('product_id'); $totalQty = $consumptions->sum('quantity_consumed'); $totalCost = $consumptions->sum('total_cost_base'); @endphp {{-- KPI strip --}}
Records
{{ $consumptions->count() }}
Raw Materials
{{ $byProduct->count() }}
Total Cost ({{ $currency }})
{{ number_format($totalCost, 0) }}
@if($consumptions->isEmpty())

No confirmed material consumptions found for this period.

@else @foreach($byProduct as $productId => $productRows) @php $product = $productRows->first()->product; $totalPQty = $productRows->sum('quantity_consumed'); $totalPCost = $productRows->sum('total_cost_base'); @endphp

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

Total consumed: {{ number_format($totalPQty, 4) }} {{ $product?->uom ?? '' }} · Total cost: {{ $currency }} {{ number_format($totalPCost, 2) }}

@foreach($productRows as $c) @endforeach
Production Order Finished Product Lot Qty Consumed UoM Unit Cost ({{ $currency }}) Total Cost ({{ $currency }}) Confirmed
{{ $c->productionOrder?->production_reference ?? '—' }} {{ $c->productionOrder?->product?->name ?? '—' }} {{ $c->lot?->lot_number ?? '—' }} {{ number_format((float) ($c->quantity_consumed ?? 0), 4) }} {{ $c->quantity_uom ?? $product?->uom ?? '—' }} {{ number_format((float) $c->unit_cost_snapshot_base, 4) }} {{ number_format((float) $c->total_cost_base, 2) }} {{ $c->consumed_at ? \Carbon\Carbon::parse($c->consumed_at)->format('d M Y') : '—' }}
@endforeach {{-- Grand total --}}
Grand Total Cost ({{ $currency }}) {{ number_format($totalCost, 2) }}
@endif @endsection