@php $statusMeta = [ 'draft' => ['label' => __('Draft'), 'color' => 'slate'], 'awaiting_payment' => ['label' => __('Awaiting Payment'), 'color' => 'amber'], 'partial' => ['label' => __('Partially Paid'), 'color' => 'sky'], 'paid' => ['label' => __('Paid'), 'color' => 'emerald'], 'cancelled' => ['label' => __('Cancelled'), 'color' => 'slate'], ]; $tonePill = [ 'up' => 'bg-emerald-50 text-emerald-700', 'down' => 'bg-rose-50 text-rose-700', 'muted' => 'bg-slate-100 text-slate-500', ]; $currencySymbol = $currencies->firstWhere('code', $currency_code)->symbol ?? $currency_code; @endphp
{{-- Header --}} @if ($tab === 'suppliers') @if ($canManageSuppliers) {{ __('New Supplier') }} @endif @elseif ($canManage) {{ __('Receive Stock') }} {{ __('New Bill') }} @endif {{-- Purchasing navigation: RFQs → POs → Bills → Suppliers. --}} {{-- KPI cards --}}
@foreach ($kpis as $kpi)

{{ $kpi['label'] }}

{{ $kpi['value'] }}

{{ $kpi['sub']['text'] }}
@endforeach
@if ($tab === 'bills') {{-- Bills table --}} {{-- Toolbar --}}
{{-- Table --}}
@forelse ($bills as $bill) @php $stockLines = $bill->lines->whereNotNull('material_variant_id'); $receivable = $stockLines->where('received', false)->count(); $isOpen = ! in_array($bill->status, ['paid', 'cancelled'], true); @endphp @empty @endforelse
{{ __('Bill') }} {{ __('Supplier') }} {{ __('Bill Date') }} {{ __('Due') }} {{ __('Total') }} {{ __('Balance') }} {{ __('Status') }} {{ __('Stock') }} {{ __('Actions') }}

{{ $bill->bill_number ?: __('Bill #:id', ['id' => $bill->id]) }}

@if ($bill->reference)

{{ $bill->reference }}

@endif
{{ $bill->supplier?->name ?? '—' }} {{ optional($bill->bill_date)->format('j M Y') ?? '—' }} @if ($bill->due_date) {{ $bill->due_date->format('j M Y') }} @if ($bill->is_overdue) {{ __('Overdue') }} @endif @else — @endif {{ $bill->currency_code }} {{ number_format((float) $bill->total, 2) }} {{ $bill->balance_due > 0 && $isOpen ? $bill->currency_code . ' ' . number_format((float) $bill->balance_due, 2) : '—' }} {{ $statusMeta[$bill->status]['label'] ?? $bill->status_label }} @if ($stockLines->isEmpty()) — @elseif ($receivable === 0) {{ __('Received') }} @else {{ trans_choice('{1} :count to receive|[2,*] :count to receive', $receivable, ['count' => $receivable]) }} @endif
@if ($canManage && $receivable > 0 && $bill->status !== 'cancelled') @endif @if ($canManage && $isOpen && $bill->balance_due > 0) @endif @if ($canManage && $bill->status !== 'paid') @endif @if ($canDelete) @endif
@if ($canManage && $search === '' && $statusFilter === '' && $flagFilter === '' && $supplierFilter === '') {{ __('New Bill') }} @endif
{{-- Pagination --}}
{{ $bills->links() }}
@endif @if ($tab === 'suppliers') {{-- Suppliers table --}} {{-- Toolbar --}}
{{-- Table --}}
@forelse ($supplierRows as $supplier) @php $typeColor = $supplier->type === 'international' ? 'sky' : 'emerald'; @endphp @empty @endforelse
{{ __('Name') }} {{ __('Type') }} {{ __('Supplies') }} {{ __('Email') }} {{ __('Phone') }} {{ __('Actions') }}
{{ \Illuminate\Support\Str::of($supplier->name)->substr(0, 1)->upper() }}

{{ $supplier->name }}

@if ($supplier->category)

{{ $supplier->category }}

@endif
{{ $supplier->type === 'international' ? __('International') : __('Local') }} @php $supplies = (int) ($supplyCounts[$supplier->id] ?? 0); @endphp {{ $supplier->email ?: '—' }} {{ $supplier->phone ?: '—' }}
@if ($canManageSuppliers) @else — @endif
@if ($canManageSuppliers && $search === '' && $supplierTypeFilter === '' && $supplierStatusFilter === '') {{ __('New Supplier') }} @endif
{{-- Pagination --}}
{{ $supplierRows->links() }}
@endif
{{-- ============================================================= --}} {{-- Create / Edit bill modal --}} {{-- ============================================================= --}} @if ($receive_on_save) {{ __('Receive Stock') }} @else {{ $editingId ? __('Edit Bill') : __('New Supplier Bill') }} @endif
{{-- Header fields --}}
{{-- Lines --}}

{{ __('Lines') }}

@foreach ($lines as $i => $line) @php $qty = (float) ($line['qty'] ?? 0); $cost = (float) ($line['unit_cost'] ?? 0); $factor = (float) ($line['purchase_to_base'] ?? 1) ?: 1; $isStock = ($line['material_variant_id'] ?? '') !== ''; $lineTotal = round($qty * $cost, 2); $qtyBase = $isStock ? round($qty * $factor, 6) : $qty; @endphp

{{ $isStock ? number_format($qtyBase, 4) : '—' }}

{{ number_format($lineTotal, 2) }}

@unless ($line['received'] ?? false) @else {{ __('Received') }} @endunless
@error('lines.' . $i . '.description')

{{ $message }}

@enderror @error('lines.' . $i . '.qty')

{{ $message }}

@enderror @error('lines.' . $i . '.unit_cost')

{{ $message }}

@enderror
@endforeach
{{-- Tax + totals --}}
{{ __('Subtotal') }} {{ $currency_code }} {{ number_format($totals['subtotal'], 2) }}
{{ __('Tax') }} {{ $currency_code }} {{ number_format($totals['tax'], 2) }}
{{ __('Total') }} {{ $currency_code }} {{ number_format($totals['total'], 2) }}
@unless ($editingId) @endunless
{{ __('Cancel') }} {{ $editingId ? __('Save Changes') : __('Create Bill') }} {{ __('Saving...') }}
{{-- ============================================================= --}} {{-- Record payment modal --}} {{-- ============================================================= --}} {{ __('Record Payment') }}

{{ __('Bank/EcoCash fee to send this payment. Booked as a bank charge. Leave blank if none.') }}

{{ __('Cancel') }} {{ __('Record Payment') }} {{ __('Saving...') }}
{{-- ============================================================= --}} {{-- Create / Edit supplier modal --}} {{-- ============================================================= --}} {{ $editingSupplierId ? __('Edit Supplier') : __('New Supplier') }}

{{ __('Buying terms') }}

{{ __('Used to date bills, price currencies and advise on reorder lead time.') }}

{{ __('Typical days from order to delivery.') }}

{{ __('Defaults a bill’s due date.') }}

{{ __('Bank details') }}

{{ __('Where you pay this supplier. Optional.') }}

{{ __('Cancel') }} {{ __('Save') }} {{ __('Saving...') }}
{{-- ============================================================= --}} {{-- Supplier catalogue, what this supplier supplies --}} {{-- ============================================================= --}} {{ __('What :name supplies', ['name' => $suppliesSupplierName]) }}

{{ __('Link the materials you buy from this supplier. Buying from them on a bill adds the link automatically, this is for setting it up ahead of time, or recording their SKU, price and minimum order.') }}

{{-- Existing catalogue --}}
@forelse ($supplyRows as $row) @empty @endforelse
{{ __('Material') }} {{ __('Their SKU') }} {{ __('Last price') }} {{ __('MOQ') }} {{ __('Lead time') }} {{ __('Actions') }}
{{ $row->material?->name }} @if ($row->variant) {{ $row->variant->label }} @endif @if ($row->is_preferred) {{ __('Preferred') }} @endif
@if ($row->purchase_count > 0)

{{ trans_choice('{1} bought once|[2,*] bought :count times', $row->purchase_count, ['count' => $row->purchase_count]) }} @if ($row->last_purchased_at) · {{ $row->last_purchased_at->format('d M Y') }} @endif

@endif
{{ $row->supplier_sku ?: '—' }} {{ $row->last_unit_cost !== null ? ($row->currency_code ?: $baseCode) . ' ' . number_format((float) $row->last_unit_cost, 2) : '—' }} {{ $row->moq !== null ? rtrim(rtrim(number_format((float) $row->moq, 2), '0'), '.') : '—' }} {{ $row->effectiveLeadTimeDays() !== null ? __(':days d', ['days' => $row->effectiveLeadTimeDays()]) : '—' }}
@if (! $row->is_preferred) @endif
{{ __('Nothing linked yet. Add the first material below.') }}
{{-- Add a material --}}

{{ __('Add a material') }}

{{ __('Per stock unit (m, sheet, each), not per roll or box.') }}

{{ __('Add to catalogue') }} {{ __('Adding...') }}
{{ __('Done') }}