@php $formatMoney = function ($amount, $symbol = '$') { return $symbol . number_format((float) $amount, 2); }; $pagesToShow = []; if ($totalPages <= 5) { for ($i = 1; $i <= $totalPages; $i++) { $pagesToShow[] = $i; } } elseif ($currentPage <= 3) { $pagesToShow = [1, 2, 3, 4, 5]; } elseif ($currentPage >= $totalPages - 2) { for ($i = $totalPages - 4; $i <= $totalPages; $i++) { $pagesToShow[] = $i; } } else { for ($i = $currentPage - 2; $i <= $currentPage + 2; $i++) { $pagesToShow[] = $i; } } $formGrandTotal = (float) collect($lineItems)->sum(fn ($item) => (float) ($item['line_total'] ?? 0)); @endphp
{{-- Header --}}

{{ __('purchases.purchase_management') }}

{{ __('purchases.manage_your_purchase_orders_suppliers_and_inventory') }}

{{-- Currency summary cards --}}
@forelse ($currencyStats as $curr)

{{ $curr['currency'] }} ({{ $curr['symbol'] }})

{{ $curr['count'] }} purchase{{ $curr['count'] !== 1 ? 's' : '' }}
{{ __('purchases.total_amount') }}
{{ $formatMoney($curr['totalAmount'], $curr['symbol']) }}
{{ __('purchases.total_paid') }}
{{ $formatMoney($curr['totalPaid'], $curr['symbol']) }}
{{ __('purchases.total_due') }}
{{ $formatMoney($curr['totalDue'], $curr['symbol']) }}
@empty
{{ __('common.no_records') }}
@endforelse
@if ($flashMessage)
{{ $flashMessage }}
@endif {{-- Add/Edit form --}} @if ($showForm) @php $itemCatalog = $itemOptions->map(fn ($it) => [ 'id' => (string) $it->id, 'label' => trim(($it->item_code ? $it->item_code.' - ' : '').$it->item_name), ])->values(); @endphp

{{ $editingId ? __('purchases.edit_purchase_order') : __('purchases.create_new_purchase_order') }}

@if ($destination_type === 'warehouse')
@endif @if ($destination_type === 'project')
@endif
{{-- Line items --}}

{{ __('purchases.purchase_items') }}

@forelse ($lineItems as $i => $item) @empty @endforelse @if (count($lineItems) > 0) @endif
{{ __('common.item') }} {{ __('common.unit') }} {{ __('purchases.qty') }} {{ __('common.price') }} {{ __('purchases.discount') }} {{ __('purchases.tax') }} {{ __('purchases.transport') }} {{ __('common.other') }} {{ __('purchases.line_total') }} {{ __('purchases.action') }}
{{ number_format((float) ($item['line_total'] ?? 0), 2) }}
{{ __('common.no_records') }}
{{ __('purchases.grand_total') }} {{ number_format($formGrandTotal, 2) }}
@endif {{-- Search & per page (always above the purchase table) --}}
{{-- Flat combined table --}}
@forelse ($pageRows as $idx => $purchase) @php $items = $lineItemsMap[$purchase->id] ?? collect(); $serial = $startIndex + $idx + 1; $paid = (float) $purchase->paid_amount; $total = (float) $purchase->grand_total; if ($paid >= $total && $total > 0) { $statusLabel = 'Paid'; $statusClass = 'paid'; } elseif ($paid > 0) { $statusLabel = 'Partial'; $statusClass = 'partial'; } else { $statusLabel = 'Unpaid'; $statusClass = 'unpaid'; } $purchaseDate = $purchase->purchase_date ? \Carbon\Carbon::parse($purchase->purchase_date)->format('n/j/Y') : '—'; @endphp @if ($items->isEmpty()) @else @foreach ($items as $itemIdx => $item) @endforeach @endif @empty @endforelse
# {{ __('purchases.po_number') }} {{ __('common.supplier') }} {{ __('common.date') }} {{ __('common.item') }} {{ __('common.unit') }} {{ __('purchases.qty') }} {{ __('common.price') }} {{ __('purchases.discount') }} {{ __('purchases.tax') }} {{ __('purchases.transport') }} {{ __('common.other') }} {{ __('purchases.line_total') }} {{ __('purchases.grand_total') }} {{ __('common.paid') }} {{ __('purchases.due') }} {{ __('common.status') }} {{ __('common.actions') }}
{{ $serial }} {{ $purchase->purchase_no }} {{ $purchase->supplier_name ?: '—' }} {{ $purchaseDate }} {{ __('common.no_records') }} {{ number_format((float) $purchase->grand_total, 2) }} {{ number_format((float) $purchase->due_amount, 2) }} {{ $statusLabel }}
{{ $itemIdx === 0 ? $serial : '' }} {{ $itemIdx === 0 ? $purchase->purchase_no : '' }} {{ $itemIdx === 0 ? ($purchase->supplier_name ?: '—') : '' }} {{ $itemIdx === 0 ? $purchaseDate : '' }} {{ $item->item_name ?: 'Item' }} {{ $item->unit_name ?: '—' }} {{ number_format((float) $item->quantity, 3) }} {{ number_format((float) $item->unit_price, 2) }} {{ number_format((float) $item->discount, 2) }} {{ number_format((float) $item->tax, 2) }} {{ number_format((float) $item->transport_cost, 2) }} {{ number_format((float) $item->other_cost, 2) }} {{ number_format((float) $item->line_total, 2) }} {{ $itemIdx === 0 ? number_format((float) $purchase->grand_total, 2) : '' }} {{ $itemIdx === 0 ? number_format((float) $purchase->due_amount, 2) : '' }} @if ($itemIdx === 0) {{ $statusLabel }} @endif @if ($itemIdx === 0) @endif
{{ __('common.no_records') }}
@if ($filteredCount > 0)
{{ __('common.showing') }} {{ $startIndex + 1 }} {{ __('common.to') }} {{ min($startIndex + $itemsPerPage, $filteredCount) }} {{ __('common.of') }} {{ $filteredCount }} {{ __('purchases.purchases') }}
@foreach ($pagesToShow as $pageNum) @endforeach
@endif