@extends('documents.procurement._layout', [ 'documentTitle' => 'Item Sourcing Report', 'reference' => $sourcingTrip->trip_reference, 'documentDate' => now()->format('d M Y'), ]) @section('header-meta')
Status: {{ ucwords(str_replace('_', ' ', $sourcingTrip->status)) }}
@if($sourcingTrip->return_date)
Returned: {{ \Carbon\Carbon::parse($sourcingTrip->return_date)->format('d M Y') }}
@endif @endsection @section('content') @php $currency = $sourcingTrip->source_currency_code ?? ''; $items = $sourcingTrip->items; $totalEstQty = $items->sum('planned_quantity'); $totalSrcQty = $items->sum('sourced_quantity'); $totalEstCost = $items->sum(fn($i) => (float)($i->estimated_total_source_cost ?? 0)); $totalActCost = $items->sum(fn($i) => isset($i->unit_source_price, $i->sourced_quantity) ? $i->unit_source_price * $i->sourced_quantity : 0); $unavailableItems = $items->where('status', 'unavailable'); $sourcedItems = $items->where('status', '!=', 'unavailable'); @endphp {{-- Summary block --}} @if($sourcingTrip->actual_departure) @endif @if($sourcingTrip->return_date) @endif
Destination Countries {{ implode(', ', $sourcingTrip->destination_countries ?? []) ?: '—' }}
Departed {{ \Carbon\Carbon::parse($sourcingTrip->actual_departure)->format('d M Y') }}
Returned {{ \Carbon\Carbon::parse($sourcingTrip->return_date)->format('d M Y') }}
Source Currency {{ $currency }} @ {{ number_format($sourcingTrip->exchange_rate ?? 0, 4) }} to base
{{-- Cost summary cards --}}
Items Planned Items Sourced / Partial Items Unavailable Total Est. Cost ({{ $currency }}) Total Actual Cost ({{ $currency }}) Variance ({{ $currency }})
{{ $items->count() }} {{ $sourcedItems->count() }} {{ $unavailableItems->count() }} {{ $totalEstCost > 0 ? number_format($totalEstCost, 2) : '—' }} {{ $totalActCost > 0 ? number_format($totalActCost, 2) : '—' }} @if($totalEstCost > 0 && $totalActCost > 0) {{ ($totalActCost <= $totalEstCost ? '−' : '+') . number_format(abs($totalActCost - $totalEstCost), 2) }} @else — @endif
{{-- Detailed items --}}

Item-by-Item Comparison

{{-- status --}} @foreach($items as $i => $item) @php $dQty = ($item->sourced_quantity ?? 0) - $item->planned_quantity; $dPrice = isset($item->unit_source_price, $item->estimated_unit_source_price) ? $item->unit_source_price - $item->estimated_unit_source_price : null; $actTotal = isset($item->unit_source_price, $item->sourced_quantity) ? $item->unit_source_price * $item->sourced_quantity : null; @endphp status === 'unavailable') style="background:#fef2f2;" @endif> @endforeach
# Product Supplier Planned Qty Sourced Qty Δ Qty Est. Unit Price Act. Unit Price Δ Price Act. Total Status
{{ $i + 1 }} {{ $item->product?->name ?? '—' }} {{ $item->supplier?->name ?? '—' }} {{ number_format($item->planned_quantity, 0) }} {{ $item->sourced_quantity !== null ? number_format($item->sourced_quantity, 0) : '—' }} @if($item->sourced_quantity !== null) {{ ($dQty >= 0 ? '+' : '') . number_format($dQty, 0) }} @else — @endif {{ $item->estimated_unit_source_price ? number_format($item->estimated_unit_source_price, 2) : '—' }} {{ $item->unit_source_price ? number_format($item->unit_source_price, 2) : '—' }} {{ $dPrice !== null ? (($dPrice >= 0 ? '+' : '') . number_format($dPrice, 2)) : '—' }} {{ $actTotal !== null ? number_format($actTotal, 2) : '—' }} {{ ucwords(str_replace('_', ' ', $item->status)) }}
{{-- Unavailable items --}} @if($unavailableItems->count())

Unavailable Items

@foreach($unavailableItems as $item) @endforeach
Product Planned Qty Reason
{{ $item->product?->name ?? '—' }} {{ number_format($item->planned_quantity, 0) }} {{ $item->unavailability_reason ?? '—' }}
@endif @endsection