@include('pos.supplier._purchasing_nav')

Purchases

+ Add Purchase
@php $totalGrand = 0.0; $totalDue = 0.0; $totalReturned = 0.0; $statusCounts = ['draft' => 0, 'received' => 0, 'cancelled' => 0, 'other' => 0]; $paymentCounts = ['PAID' => 0, 'PARTIAL' => 0, 'UNPAID' => 0, 'CANCELLED' => 0]; @endphp @forelse($bills as $bill) @php $total = (float) ($bill->supplier_bill_details_total ?? ($bill->total_amount ?? 0)); $paid = (float) ($bill->supplier_bill_details_paid ?? 0); $chequeIssued = (float) ($bill->supplier_bill_details_cheque_issued ?? 0); $returnedTotal = (float) ($bill->supplier_bill_details_returned_total ?? 0); $due = $total - $paid - $chequeIssued - $returnedTotal; $dueDisplay = max(0, $due); $status = $bill->supplier_bill_details_status ?? (($bill->supplier_bill_details_close_status ?? 0) == 1 ? 'closed' : 'open'); // Payment status logic: // - CANCELLED: bill is cancelled // - PAID: fully paid (paid >= total - returns) // - CHEQUE: fully covered by cheques but not yet cleared // - PARTIAL: some payment made but not fully covered // - UNPAID: no payment made $paymentStatus = 'UNPAID'; if ($status === 'cancelled') { $paymentStatus = 'CANCELLED'; } elseif ($due <= 0.00001) { // Fully covered - but by cleared payments or pending cheques? if ($paid >= ($total - $returnedTotal - 0.00001)) { $paymentStatus = 'PAID'; } else { $paymentStatus = 'CHEQUE'; // Covered by pending cheques } } elseif ($paid > 0.00001 || $chequeIssued > 0.00001 || $returnedTotal > 0.00001) { $paymentStatus = 'PARTIAL'; } $totalGrand += $total; $totalDue += $dueDisplay; $totalReturned += $returnedTotal; if (isset($statusCounts[$status])) { $statusCounts[$status] += 1; } else { $statusCounts['other'] += 1; } $paymentCounts[$paymentStatus] = ($paymentCounts[$paymentStatus] ?? 0) + 1; @endphp @empty @endforelse @if($bills->count() > 0) @endif
Action Date Reference No Location Supplier Purchase Status Payment Status Grand Total Payment due Added By
{{ optional($bill->supplier_bill_details_create_date)->format('Y-m-d') }} {{ $bill->supplier_bill_details_billnumber }} {{ $bill->location->name ?? '' }} {{ $bill->supplier->supplier_name ?? '' }} {{ strtoupper($status) }} @php $badgeClass = match($paymentStatus) { 'PAID' => 'bg-green-100 text-green-800', 'CHEQUE' => 'bg-blue-100 text-blue-800', 'PARTIAL' => 'bg-yellow-100 text-yellow-800', 'CANCELLED' => 'bg-red-100 text-red-800', default => 'bg-gray-100 text-gray-800', }; @endphp {{ $paymentStatus }} {{ number_format($total, 2) }} {{ number_format($dueDisplay, 2) }} {{ $bill->createdByUser->name ?? '' }}
No purchases found
Total Draft: {{ $statusCounts['draft'] }} | Received: {{ $statusCounts['received'] }} | Cancelled: {{ $statusCounts['cancelled'] }} Paid: {{ $paymentCounts['PAID'] }} | Partial: {{ $paymentCounts['PARTIAL'] }} | Due: {{ $paymentCounts['UNPAID'] }} | Cancelled: {{ $paymentCounts['CANCELLED'] }} {{ number_format($totalGrand, 2) }}
Purchase Due: {{ number_format($totalDue, 2) }}
Purchase Return: {{ number_format($totalReturned, 2) }}