@php $org = auth()->user()->organization ?? \App\Models\System\Organization::find(auth()->user()->organization_id); @endphp @extends('documents.procurement._layout', [ 'documentTitle' => 'Production Cost Analysis', 'reference' => null, 'documentDate' => $reportDate, 'noAutoPrint' => true, ]) @section('header-meta')
Completion Period: {{ $from->format('d M Y') }} โ€” {{ $until->format('d M Y') }}
Currency: {{ $currency }} (base) ยท Completed orders only
@endsection @section('content') @php $types = ['material', 'labour', 'overhead', 'other']; @endphp @if($orders->isEmpty())

No completed production orders found for this period.

@else @php $grandEst = 0; $grandAct = 0; @endphp @foreach($orders as $order) @php $lines = $order->costLines->keyBy('cost_type'); $totalEst = 0; $totalAct = 0; foreach ($types as $t) { $totalEst += (float) ($lines[$t]?->estimated_amount_base ?? 0); $totalAct += (float) ($lines[$t]?->amount_base ?? 0); } $variance = $totalAct - $totalEst; $grandEst += $totalEst; $grandAct += $totalAct; @endphp @foreach($types as $type) @php $line = $lines[$type] ?? null; @endphp @endforeach @endforeach @php $grandVar = $grandAct - $grandEst; @endphp @foreach($types as $type) @php $estSum = $orders->sum(fn($o) => (float)($o->costLines->firstWhere('cost_type', $type)?->estimated_amount_base ?? 0)); $actSum = $orders->sum(fn($o) => (float)($o->costLines->firstWhere('cost_type', $type)?->amount_base ?? 0)); @endphp @endforeach
Reference Product Material Labour Overhead Other Total ({{ $currency }})
Est. Act. Est. Act. Est. Act. Est. Act. Est. Act. Var.
{{ $order->production_reference }} {{ $order->product?->name ?? 'โ€”' }}{{ number_format((float)($line?->estimated_amount_base ?? 0), 0) }} {{ number_format((float)($line?->amount_base ?? 0), 0) }}{{ number_format($totalEst, 0) }} {{ number_format($totalAct, 0) }} {{ $variance >= 0 ? '+' : '' }}{{ number_format($variance, 0) }}
Grand Totals{{ number_format($estSum, 0) }} {{ number_format($actSum, 0) }}{{ number_format($grandEst, 0) }} {{ number_format($grandAct, 0) }} {{ $grandVar >= 0 ? '+' : '' }}{{ number_format($grandVar, 0) }}

Variance = Actual โˆ’ Estimated. Red = over budget. Green = under budget.

@endif @endsection