@extends('dashboard.layouts.app') @section('content') @include('components.alert') @php $student = $studentInvoice->student; $isSalesOrderInvoice = str_starts_with((string) $studentInvoice->id, 'sales-'); $studentName = $student ? trim(($student->full_name ?? '') ?: (($student->first_name ?? '') . ' ' . ($student->last_name ?? ''))) : ($studentInvoice->party_name ?? 'Sales Customer'); $courseItems = $studentInvoice->courseStudentInvoices ?? collect(); $transactions = $studentInvoice->transactions ?? collect(); $latestTransactionId = $transactions->max('id'); $paymentAllocations = ($studentInvoice->paymentAllocations ?? collect()) ->filter(fn ($allocation) => $allocation->payment) ->sortByDesc(fn ($allocation) => optional($allocation->payment->payment_date)->timestamp ?? $allocation->payment->id); $paymentStatusClass = match ($studentInvoice->payment_status) { 'paid', 'paid_purchased' => 'status-pill--success', 'paid_deposite', 'deposite', 'partial' => 'status-pill--warning', 'rejected', 'refunded', 'unpaid', 'not_paid' => 'status-pill--danger', default => 'status-pill--muted', }; $completionStatusClass = !$studentInvoice->display_completion_status ? 'status-pill--muted' : ($studentInvoice->display_completion_status === 'complete' ? 'status-pill--success' : 'status-pill--warning'); $displayLastSessionAt = $studentInvoice->display_last_session_at; $totalPrice = (float) ($studentInvoice->total_price ?? 0); $netPrice = (float) ($studentInvoice->display_total_amount ?? ($studentInvoice->net_price ?? $totalPrice)); $paidAmount = (float) ($studentInvoice->display_paid_amount ?? 0); $receivedAmounts = app(\App\Services\InvoiceReceiptPresentationService::class)->groups($studentInvoice); $depositAmount = (float) ($studentInvoice->display_deposit_amount ?? 0); $remainingAmount = (float) ($studentInvoice->display_remaining_amount ?? max($netPrice - $paidAmount, 0)); $discountAmount = max($totalPrice - $netPrice, 0); $vatAmount = (float) ($studentInvoice->vat_amount ?? 0); if ($vatAmount <= 0) { $vatAmount = max($netPrice - $totalPrice + $discountAmount, 0); } $vatRate = (float) ($studentInvoice->vat_rate ?? 0); $paidPercent = $netPrice > 0 ? min(100, ($paidAmount / $netPrice) * 100) : 0; $receiptUrl = function (?string $path): ?string { if (blank($path)) { return null; } if (str_starts_with($path, 'http')) { return $path; } $path = ltrim($path, '/'); return str_starts_with($path, 'storage/') || str_starts_with($path, 'Uploads/') || str_starts_with($path, 'uploads/') ? asset($path) : asset('storage/' . $path); }; @endphp
Created {{ optional($studentInvoice->created_at)->format('M d, Y') ?: '--' }}
Create a full or partial payment from this invoice.
{{ $paymentAllocations->count() }} payment(s) allocated to this invoice.
| # | Payment No | Date | Status | Method | Allocated | Receipt | From | To | Action |
|---|---|---|---|---|---|---|---|---|---|
| {{ $loop->iteration }} | {{ $payment->payment_no ?: ('#' . $payment->id) }} | {{ optional($payment->payment_date)->format('M d, Y') ?: '--' }} | {{ ucfirst($payment->status ?? 'draft') }} | {{ ucwords(str_replace('_', ' ', $payment->payment_method ?? '--')) }} | {{ number_format($allocatedAmount, 2) }} {{ $allocatedCurrency }} | @if (!empty($payment->receipt_image)) View @else -- @endif | {{ $payment->fromAccount ? ($payment->fromAccount->code . ' - ' . $payment->fromAccount->title) : '--' }} | {{ $payment->toAccount ? ($payment->toAccount->code . ' - ' . $payment->toAccount->title) : '--' }} | View |
| No payments allocated to this invoice yet. | |||||||||
{{ $courseItems->count() }} course item(s) linked to this invoice.
| # | Course | Booking ID | Course ID | Start | End | Teacher |
|---|---|---|---|---|---|---|
| {{ $loop->iteration }} | {{ $courseTitle }} | {{ $item->id }} | {{ $item->course_id }} | {{ $course?->start_date ?? '--' }} | {{ $course?->end_date ?? '--' }} | {{ $teacherName ?: '--' }} |
| No courses linked to this invoice. | ||||||
{{ $transactions->count() }} transaction(s).
| # | Amount | Payment Type | Status | Date | Receipt | Actions |
|---|---|---|---|---|---|---|
| {{ $loop->iteration }} | {{ number_format($transaction->treasury_amount ?? $transaction->amount ?? 0, 2) }} {{ $transaction->treasury_currency ?: $transaction->currency }} | {{ ucfirst(str_replace('_', ' ', $transaction->payment_type ?? '--')) }} | {{ ucfirst($transaction->status ?? 'pending') }} | {{ optional($transaction->created_at)->format('M d, Y') ?: '--' }} | @if ($transactionReceiptUrl) @else -- @endif | @if ($transaction->id === $latestTransactionId && $transaction->status === 'pending' && $transaction->payment_type === 'instapay') @else -- @endif |
| No transactions found. | ||||||