{{-- ── Draft conflict modal ──────────────────────────────────────────────── --}} @if ($showDraftConflictModal) {{-- Backdrop --}}
{{-- Dialog --}}
{{-- Icon + title --}}

Draft PO already exists

{{ $conflictingPoReference }} is an open draft for this supplier and warehouse. Do you want to add these lines to it, or create a separate PO?

{{-- Actions --}}
@endif {{-- ── Add line panel ─────────────────────────────────────────────────── --}} @if ($showAddLinePanel) {{-- Backdrop --}}
{{-- Dialog --}}
{{-- Header --}}

Add product line

{{-- Search input --}}
{{-- Results list --}}
@if (empty($addLineResults))
{{ $addLineSearch ? 'No products match "' . $addLineSearch . '"' : 'Type to search products from this supplier' }}
@else @foreach ($addLineResults as $result) @endforeach @endif
{{-- Footer --}}
@endif {{-- ══════════════════════════════════════════════════════════════════════ --}} {{-- STEP 1 — Supplier Selection --}} {{-- ══════════════════════════════════════════════════════════════════════ --}} @if ($step === 1) {{-- Relative wrapper: absolute overlay anchors here, not the viewport --}}
{{-- Loading overlay: pointer-events:none so it never blocks card clicks --}}
{{-- translate(-50%,-50%) centers without flex — no Tailwind dependency --}}

Loading stock data…

PO Create

{{-- Company split: suppliers' counts and the receiving warehouses follow the chosen company --}} @if (count($companies) > 1)
@foreach (array_merge([['id' => null, 'name' => 'All companies']], $companies) as $company) @php $active = $selectedCompanyId === $company['id']; @endphp @endforeach
@endif
@php $filteredPartners = $this->getFilteredPartners(); @endphp {{-- Grid dims during loading but stays in DOM so overlay has something to sit over --}}
@if (empty($filteredPartners))

{{ $search ? 'No suppliers match your search' : 'No suppliers found' }}

@else
@foreach ($filteredPartners as $partner) @php $hasAlerts = $partner['min_stock_count'] > 0 || $partner['open_order_count'] > 0 || ($partner['draft_po_count'] ?? 0) > 0; $initials = collect(explode(' ', $partner['name']))->take(2)->map(fn ($w) => strtoupper(substr($w, 0, 1)))->implode(''); @endphp @endforeach
@endif
{{-- ══════════════════════════════════════════════════════════════════════ --}} {{-- STEP 2 — Review & Edit Lines --}} {{-- ══════════════════════════════════════════════════════════════════════ --}} @else @php $partner = $this->getSelectedPartnerData(); $counts = $this->getLineCounts(); $subtotal = $this->getSubtotal(); $vatAmount = $this->getVatTotal(); $totalIncVat = round($subtotal + $vatAmount, 2); $units = $this->getTotalUnits(); $selected = $this->getSelectedCount(); $excluded = $this->getExcludedCount(); $overridden = $counts['overridden']; $visible = $this->getVisibleLines(); $initials = collect(explode(' ', $partner['name'] ?? ''))->take(2)->map(fn ($w) => strtoupper(substr($w, 0, 1)))->implode(''); $allVisibleSelected = !empty($visible) && collect($visible)->every(fn ($l) => $l['included']); @endphp {{-- ── Page title row ────────────────────────────────────────────────── --}}

Create Purchase Order

{{-- ── Progress stepper — in a card ──────────────────────────────────── --}}
{{-- Step 1: Complete --}}
Select supplier
{{-- Connector line: green (step 1 complete) --}}
{{-- Step 2: Active --}}
2 Review order lines
{{-- Connector line: grey (step 3 not reached) --}}
{{-- Step 3: Future --}}
3 Confirm & send
Draft auto-saves
{{-- ── Warehouse selector tabs (only shown when multiple warehouses) ──── --}} @if (count($warehouses) > 1)
@foreach ($warehouses as $wh) @php $isActive = $selectedWarehouseId === $wh['id']; @endphp @endforeach
@endif {{-- ── Supplier card ─────────────────────────────────────────────────── --}}
{{-- Left: avatar + name + info row --}}
@if (!empty($partner['avatar_url']))
{{ $partner['name'] }}
@else
{{ $initials }}
@endif
{{ $partner['name'] ?? '' }}
@php $infoItems = []; if (!empty($partner['reference'])) $infoItems[] = $partner['reference']; if (!empty($partner['lead_time'])) $infoItems[] = 'Lead time: ' . $partner['lead_time'] . ' days'; $selectedWarehouse = collect($warehouses)->firstWhere('id', $selectedWarehouseId); if ($selectedWarehouse) $infoItems[] = 'Warehouse: ' . $selectedWarehouse['name']; $infoItems[] = 'Currency: GBP'; @endphp

{{ implode(' · ', $infoItems) }}

{{-- Right: mode toggle + stats --}}
{{-- Mode toggle --}}
{{-- Stats --}}

@if ($mode === 'min_stock') Below Minimum @elseif ($mode === 'open_orders') Outstanding @else All Needs @endif

{{ $counts['all'] }}items

Estimated Value

£{{ number_format($subtotal, 2) }}

{{-- ── Open PO notice ───────────────────────────────────────────────── --}} @php $openPoRefs = collect($lines)->pluck('open_po_ref')->filter()->unique()->values(); @endphp @if ($openPoRefs->isNotEmpty())
Already on order: {{ $openPoRefs->join(', ') }} {{ $openPoRefs->count() === 1 ? 'has' : 'have' }} some quantity of these items outstanding. The suggested quantities below already account for that — they won't double up what's on {{ $openPoRefs->count() === 1 ? 'it' : 'them' }}.
@endif {{-- ── Filter toolbar + Table — single card ─────────────────────────── --}}
{{-- Filter toolbar row --}}
{{-- Inline search --}}
{{-- ── Filter chip: All ── --}} {{-- ── Filter chip: Critical ── --}} {{-- ── Filter chip: Overridden ── --}} {{-- ── Filter chip: Excluded ── --}} {{-- Add line --}}
{{-- Table / empty state --}} @if (empty($visible))

@if ($lineSearch !== '') No results match "{{ $lineSearch }}" @elseif ($lineFilter === 'all' && empty($warehouses)) No order points configured for this supplier — add reorder points in Inventory → Order Points @elseif ($lineFilter === 'all') No items to reorder for this supplier @elseif ($lineFilter === 'critical') No critical items @elseif ($lineFilter === 'overridden') No overridden quantities @else No excluded lines @endif

@if ($lineSearch !== '') @endif
@else
@foreach ($visible as $line) @php $idx = $line['_idx']; $isCritical = (float) $line['on_hand_qty'] === 0.0; $isOverridden = $line['included'] && (float) $line['qty'] !== (float) $line['suggested_qty']; $lineTotal = $line['included'] ? round((float) $line['qty'] * (float) $line['unit_cost'], 2) : 0; $vatAmount = ($line['included'] && ($line['tax_rate'] ?? 0) > 0) ? round((float) $line['qty'] * (float) $line['unit_cost'] * ((float)($line['tax_rate'] ?? 0) / 100), 2) : null; $refQty = $mode === 'min_stock' ? (float)($line['min_qty'] ?? 0) : ($mode === 'open_orders' ? (float)($line['ordered_qty'] ?? 0) : max((float)($line['min_qty'] ?? 0), (float)($line['ordered_qty'] ?? 0))); $stockPct = $refQty > 0 ? min(100, ((float)$line['on_hand_qty'] / $refQty) * 100) : 0; @endphp ! $line['included'], 'bg-red-50/40 hover:bg-red-50/60 dark:bg-red-900/5' => $isCritical && $line['included'], 'hover:bg-gray-50/70 dark:hover:bg-gray-800/30' => ! $isCritical, ])> {{-- Checkbox --}} {{-- SKU: amber monospace, no pill --}} {{-- Product name --}} {{-- Current stock: number + compact bar + badge, all inline --}} {{-- Min level / Ordered qty --}} {{-- Qty stepper --}} {{-- Unit cost --}} {{-- VAT amount --}} {{-- Line total --}} @endforeach
SKU ↕ Product ↕ Current Stock ↕ @if ($mode === 'min_stock') Min Level @elseif ($mode === 'open_orders') Ordered Qty @else Min / Ordered @endif ↕ Suggested Qty ↕ Unit Cost ↕ VAT Line Total ↕
@if ($line['sku']) {{ $line['sku'] }} @else — @endif {{ $line['name'] }} @if (!empty($line['open_po_ref'])) {{ $line['open_po_ref'] }}@if(!empty($line['open_po_qty'])) ({{ (int) $line['open_po_qty'] }} on order)@endif @endif
{{ (int) $line['on_hand_qty'] }} {{-- Bar: explicit @class so Tailwind compiles the colours --}}
$stockPct == 0, 'bg-amber-500' => $stockPct > 0 && $stockPct < 40, 'bg-amber-300' => $stockPct >= 40, ]) style="width: {{ number_format($stockPct, 0) }}%">
@if ($isCritical) CRITICAL @else LOW @endif
@if ($mode === 'combined') @php $minQ = $line['min_qty'] !== null ? (int)$line['min_qty'] : null; $ordQ = $line['ordered_qty'] !== null ? (int)$line['ordered_qty'] : null; @endphp @if ($minQ !== null && $ordQ !== null) {{ $minQ }} / {{ $ordQ }} @else {{ $minQ ?? $ordQ }} @endif @elseif ($mode === 'min_stock') {{ (int)($line['min_qty'] ?? 0) }} @else {{ (int)($line['ordered_qty'] ?? 0) }} @endif
$isOverridden, 'border-gray-300 focus:ring-primary-500/30 dark:border-gray-600' => ! $isOverridden, ])>
@if ($isOverridden) @else suggested {{ (int) $line['suggested_qty'] }} @endif
£{{ number_format((float) $line['unit_cost'], 2) }} @if ($vatAmount !== null) £{{ number_format($vatAmount, 2) }} @else — @endif @if ($line['included'] && (float) $line['qty'] > 0) £{{ number_format($lineTotal, 2) }} @else — @endif
@endif
{{-- end filter+table card --}} {{-- ── Sticky footer ───────────────────────────────────────────────── --}}
{{-- Left: summary stats --}}
LINES {{ $selected }} selected @if ($excluded > 0) ({{ $excluded }} excluded)@endif | UNITS {{ (int) $units }} | SUBTOTAL (EX VAT) £{{ number_format($subtotal, 2) }} | TOTAL (INC VAT) £{{ number_format($totalIncVat, 2) }}
{{-- Right: overridden badge + buttons --}}
@if ($overridden > 0) ⊙ {{ $overridden }} {{ $overridden === 1 ? 'line' : 'lines' }} overridden @endif
@endif