@extends('documents.procurement._layout', [ 'documentTitle' => 'Production Completion Certificate', 'reference' => $order->production_reference, 'documentDate' => $order->completion_date ? \Carbon\Carbon::parse($order->completion_date)->format('d M Y') : now()->format('d M Y'), ]) @section('header-meta')
COMPLETED
@if($order->outputLot)
Output Lot: {{ $order->outputLot->lot_number }}
@endif @endsection @section('content') @php $src = $order->source_currency_code; $base = auth()->user()->organization?->currency_code ?? 'UGX'; $isForeign = $src !== $base; $netProduced = ($order->produced_quantity ?? 0) - ($order->rejected_quantity ?? 0); $costLines = $order->costLines->keyBy('cost_type'); $types = ['material', 'labour', 'overhead', 'other']; @endphp {{-- Production Summary block --}}
Production Details:
Product: {{ $order->product?->name ?? '—' }}
@if($order->product?->sku) SKU: {{ $order->product->sku }}
@endif Production Location: {{ $order->location?->name ?? '—' }}
Output Location: {{ $order->outputLocation?->name ?? $order->location?->name ?? '—' }}
Output Inventory Lot:
@if($order->outputLot) Lot Number: {{ $order->outputLot->lot_number }}
Qty Received: {{ number_format((float) $order->outputLot->quantity_received, 0) }} {{ $order->quantity_uom ?? $order->product?->uom ?? '' }}
@else — No output lot recorded —
@endif @if($order->bom) BOM: {{ $order->bom->bom_reference }} (v{{ $order->bom->version }})
@endif
{{-- Quantities table --}}

Production Quantities

@if(($order->rejected_quantity ?? 0) > 0) @endif
Planned Quantity {{ number_format($order->planned_quantity) }} {{ $order->quantity_uom ?? $order->product?->uom ?? '' }}
Produced Quantity {{ number_format($order->produced_quantity ?? 0) }} {{ $order->quantity_uom ?? $order->product?->uom ?? '' }}
Rejected (QC Fail) {{ number_format($order->rejected_quantity ?? 0) }} {{ $order->quantity_uom ?? $order->product?->uom ?? '' }}
Net Quantity to Inventory {{ number_format($netProduced) }} {{ $order->quantity_uom ?? $order->product?->uom ?? '' }}
{{-- Rejection notes --}} @if($order->rejection_notes)

QC Rejection Notes: {{ $order->rejection_notes }}

@endif {{-- Cost Breakdown (Estimated vs Actual) --}}

Production Cost Breakdown

@if($isForeign) @endif @php $totalEstSrc = 0; $totalActSrc = 0; $totalActBase = 0; @endphp @foreach($types as $type) @if(isset($costLines[$type])) @php $line = $costLines[$type]; $est = (float) $line->estimated_amount_source; $act = (float) $line->amount_source; $var = $act - $est; $totalEstSrc += $est; $totalActSrc += $act; $totalActBase += (float) $line->amount_base; @endphp @if($isForeign) @endif @endif @endforeach @php $totalVar = $totalActSrc - $totalEstSrc; @endphp @if($isForeign) @endif @if($netProduced > 0) @php $costPerUnit = $netProduced > 0 ? $totalActSrc / $netProduced : 0; @endphp @endif
Cost Type Estimated ({{ $src }}) Actual ({{ $src }}) Variance ({{ $src }})Actual ({{ $base }})
{{ ucfirst($type) }} {{ number_format($est, 2) }} {{ number_format($act, 2) }} {{ $var >= 0 ? '+' : '' }}{{ number_format($var, 2) }} {{ number_format((float) $line->amount_base, 2) }}
Total Production Cost {{ $src }} {{ number_format($totalEstSrc, 2) }} {{ $src }} {{ number_format($totalActSrc, 2) }} {{ $totalVar >= 0 ? '+' : '' }}{{ $src }} {{ number_format($totalVar, 2) }} {{ $base }} {{ number_format($totalActBase, 2) }}
Cost per net unit: {{ $src }} {{ number_format($costPerUnit, 4) }}
{{-- Material Consumptions --}} @php $confirmed = $order->materialConsumptions->filter(fn ($c) => $c->consumed_at !== null); @endphp @if($confirmed->isNotEmpty())

Confirmed Material Consumptions

@foreach($confirmed->values() as $i => $c) @endforeach
# Raw Material Lot Qty UoM Unit Cost ({{ $src }}) Total Cost ({{ $src }})
{{ $i + 1 }} {{ $c->product?->name ?? '—' }} {{ $c->lot?->lot_number ?? '—' }} {{ number_format((float) ($c->quantity_consumed ?? 0), 4) }} {{ $c->quantity_uom ?? $c->product?->uom ?? '—' }} {{ number_format((float) $c->unit_cost_snapshot_source, 4) }} {{ number_format((float) $c->total_cost_source, 2) }}
@endif {{-- Notes --}} @if($order->notes)

Production Notes

{{ $order->notes }}

@endif {{-- Approval trail --}}

Approval Trail

Prepared by {{ $order->submittedBy?->name ?? '—' }} {{ $order->submitted_at ? \Carbon\Carbon::parse($order->submitted_at)->format('d M Y') : '—' }}
Approved by {{ $order->approvedBy?->name ?? '—' }} {{ $order->approved_at ? \Carbon\Carbon::parse($order->approved_at)->format('d M Y') : '—' }}
{{-- Signatures --}}
Production Supervisor
Signature & Date
Quality Control
Signature & Date
Finance / Costing
Signature & Date
@endsection