@extends('dashboard.layouts.app') @section('content') @include('components.alert') @php $statusClass = match ($invoice->status) { 'paid' => 'status-pill--success', 'partial' => 'status-pill--warning', 'cancelled' => 'status-pill--danger', default => 'status-pill--muted', }; $canPay = in_array($invoice->status, ['unpaid', 'partial'], true) && (float) $invoice->remaining_amount > 0; $totalAmount = (float) ($invoice->total ?? 0); $paidAmount = (float) ($invoice->paid_amount ?? 0); $remainingAmount = (float) ($invoice->remaining_amount ?? 0); $paidPercent = $totalAmount > 0 ? min(100, ($paidAmount / $totalAmount) * 100) : 0; $purchasePartyType = $invoice->purchase?->party_type ?? null; // 'student', 'staff', 'company', null $purchaseInvoiceType = $invoice->purchase?->invoice_type ?? null; // 'sale' or 'purchase' // A "sales invoice" that should be redirected to the student flow = sale order for a student only. // Staff/company sale orders are paid through the normal purchase payment flow. $isSalesInvoice = $purchaseInvoiceType === 'sale' && $purchasePartyType === 'student'; $isSaleOrder = $purchaseInvoiceType === 'sale'; // any sale order (staff or student) $invoiceTitle = $isSaleOrder ? 'Sales Invoice' : 'Purchase Invoice'; $orderLabel = $isSaleOrder ? 'Sales Order' : 'Purchase Order'; $partyLabel = match(true) { $purchasePartyType === 'staff' => 'Staff', $purchasePartyType === 'student' => 'Student', default => 'Vendor', }; $partyName = match(true) { $purchasePartyType === 'student' => ($invoice->purchase?->student?->full_name ?? $invoice->purchase?->name ?? $invoice->vendor?->name ?? 'Party'), $purchasePartyType === 'staff' => ($invoice->purchase?->name ?? 'Staff'), default => ($invoice->vendor?->name ?? $invoice->purchase?->vendors?->first()?->name ?? 'Vendor'), }; $canPay = !$isSalesInvoice && $canPay; @endphp
Invoice Details
{{ $isSalesInvoice ? 'Sales invoice posting records receivable and revenue.' : 'Invoice posting creates payable only. Payments move treasury balance.' }}
| # | Item | Qty | Price | Amount | Tax |
|---|---|---|---|---|---|
| {{ $loop->iteration }} | {{ $detail->product_name ?: '--' }} | {{ $detail->quantity }} | {{ number_format((float) $detail->price, 2) }} | {{ number_format((float) $detail->amount, 2) }} | {{ number_format((float) $detail->tax_rate, 2) }}% |
| No items found. | |||||
Payments
{{ $isSalesInvoice ? 'Payments linked to this sales invoice.' : 'Every payment creates a treasury OUT transaction and a payment journal entry.' }}
| # | Date | Treasury | Amount | Journal Entry | Notes |
|---|---|---|---|---|---|
| {{ $loop->iteration }} | {{ optional($payment->payment_date)->format('M d, Y') ?: '--' }} | {{ $payment->treasury?->name ?? '--' }} | {{ number_format((float) $paymentRow['amount'], 2) }} | {{ $payment->journalEntry?->reference_no ?? '--' }} | {{ $payment->notes ?: '--' }} |
| No payments recorded yet. | |||||
Balance
Payment progress for this invoice.
Record Payment
Choose treasury and amount. This is the cash movement step.
{{ $isSalesInvoice ? 'Sales Payment' : 'Payment Complete' }}
{{ $isSalesInvoice ? 'Use the sales payment flow to collect this invoice.' : 'This purchase invoice has no remaining balance.' }}