@extends('dashboard.layouts.app') @section('content') @include('components.alert') @php $isStudentSale = ($purchase->invoice_type ?? null) === 'sale' && ($purchase->party_type ?? null) === 'student'; $isSaleOrder = ($purchase->invoice_type ?? null) === 'sale'; $isInternalPurchase = !$isSaleOrder; $studentName = $purchase->student ? trim((string) ($purchase->student->full_name ?: (($purchase->student->first_name ?? '') . ' ' . ($purchase->student->last_name ?? '')))) : null; $pageTitle = $isStudentSale ? 'Student Course Request' : ($isSaleOrder ? 'Sales Order' : 'Department Purchase Request'); $partyTypeLabel = match ($purchase->party_type ?? null) { 'student' => 'Students', 'staff', 'employee' => 'Employee', 'company' => 'Company', default => ucwords(str_replace('_', ' ', $purchase->party_type ?? '--')), }; $purchaseInvoice = $purchase->purchaseInvoice; $hasInvoice = $purchase->purchase_invoice_id || $purchase->student_invoice_id || $purchase->details->contains(fn ($detail) => !empty($detail->student_invoice_id)); $statusClass = $hasInvoice ? 'po-pill--success' : 'po-pill--warn'; $statusLabel = $hasInvoice ? 'Invoiced' : 'Pending'; @endphp
Back Edit Order @if($purchase->status !== 'completed') @endif @if($isInternalPurchase && $purchaseInvoice) Open Purchase Invoice @elseif($isInternalPurchase && in_array($purchase->status, ['approved', 'purchased'], true)) Create Purchase Invoice @endif
{{ $purchase->purchase_number }}

Created {{ optional($purchase->created_at)->format('M d, Y') ?: '--' }} @if($isStudentSale && $studentName) ยท {{ $studentName }} @endif

{{ $statusLabel }}
@if($isStudentSale) This is a sales order for a student. Create the linked sales invoice from the booking/course row, then record payments from the sales invoice page. @elseif($isSaleOrder) This is a sales order for the selected party. Review the party details, item rows, totals, and status from this page. @else This internal purchase must have a purchase invoice first. The invoice posts accounts payable, and treasury moves only when a payment is recorded on that invoice. @endif
Subtotal {{ number_format((float) $purchase->sub_total, 2) }}
VAT / Shipping {{ number_format((float) (($purchase->vat_amount ?? 0) + ($purchase->shipping_cost ?? 0)), 2) }}
Total Order Value {{ number_format((float) $purchase->total, 2) }}
{{ ucfirst($purchase->invoice_type ?? 'purchase') }}
{{ $partyTypeLabel }}
{{ $statusLabel }}
{{ ucwords(str_replace('_', ' ', $purchase->status ?? 'pending')) }}
{{ $isStudentSale ? ($studentName ?: 'Student #' . $purchase->student_id) : ($purchase->name ?: '--') }}
@if ($purchase->student_id)
{{ $purchase->student_id ?? '--' }}
@endif
{{ $purchase->due_date ? \Carbon\Carbon::parse($purchase->due_date)->format('M d, Y') : ($purchase->required_by ? \Carbon\Carbon::parse($purchase->required_by)->format('M d, Y') : '--') }}
{{ $purchase->costCenter?->title ?? '--' }}
{{ ($purchase->apply_vat ?? false) ? 'Applied' : 'Not Applied' }}
@forelse($purchase->requestedStaffs as $staff) {{ trim(($staff->first_name ?? '') . ' ' . ($staff->last_name ?? '')) }}{{ !$loop->last ? ', ' : '' }} @empty -- @endforelse
@if($isInternalPurchase)
Purchase Invoice

Vendor bill and payment progress for this purchase request.

@if($purchaseInvoice) Open Invoice @elseif(in_array($purchase->status, ['approved', 'purchased'], true)) Create Invoice @endif
@if($purchaseInvoice)
{{ $purchaseInvoice->invoice_number }}
{{ ucwords(str_replace('_', ' ', $purchaseInvoice->status)) }}
{{ number_format((float) $purchaseInvoice->total, 2) }}
{{ number_format((float) $purchaseInvoice->paid_amount, 2) }}
{{ number_format((float) $purchaseInvoice->remaining_amount, 2) }}
{{ $purchaseInvoice->invoiceJournalEntry?->reference_no ?? '--' }}
@else
No purchase invoice has been created yet.
@endif
@endif @if($isInternalPurchase)
Vendor Information

Vendors linked to this purchase request.

@forelse($purchase->vendors as $vendor) @empty @endforelse
# Vendor Phone Location Tax Shipping
{{ $loop->iteration }} {{ $vendor->name }} {{ $vendor->phone ?? '--' }} {{ $vendor->location ?? '--' }} {{ $vendor->tax ?? '--' }} {{ number_format((float) ($vendor->shipping_cost ?? 0), 2) }}
No vendor details available.
@endif
Order Items

{{ $isStudentSale ? 'For student requests, each row can create one linked sales invoice.' : ($isSaleOrder ? 'Sales order line items and totals for the selected party.' : 'These items are copied into the purchase invoice total before payments are recorded.') }}

{{ $purchase->details->count() }} Item(s)
@if($isStudentSale) @endif @if($isStudentSale) @endif @forelse($purchase->details as $detail) @php $course = $detail->course; $courseTitle = $course?->course_name_en ?: ($course?->track?->name_en ?? null) ?: ($course?->academyProduct?->name_en ?? null) ?: $detail->product_name; @endphp @if($isStudentSale) @endif @if($isStudentSale) @endif @empty @endforelse
# Item / CourseBooking ID Course IDQty Price Amount TaxLinked Invoice Action
{{ $loop->iteration }} {{ $courseTitle ?: '--' }}{{ $detail->booking_id ?? '--' }} {{ $detail->course_id ?? '--' }}{{ $detail->quantity }} {{ number_format((float) $detail->price, 2) }} {{ number_format((float) $detail->amount, 2) }} {{ number_format((float) $detail->tax_rate, 2) }}% @if($detail->studentInvoice) {{ $detail->studentInvoice->invoice_number }} @else -- @endif @if($detail->booking_id && $detail->course_id) @if($detail->studentInvoice) Open Invoice @else
@csrf
@endif @else -- @endif
No order items found.
Subtotal {{ number_format((float) $purchase->sub_total, 2) }}
VAT {{ number_format((float) ($purchase->vat_amount ?? 0), 2) }}
Shipping {{ number_format((float) ($purchase->shipping_cost ?? 0), 2) }}
Total {{ number_format((float) $purchase->total, 2) }}
Attachments

Files attached to this order request.

@forelse($purchase->attachments as $attachment) @php $path = $attachment->file_path; $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION)); $isImage = in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'jfif'], true); @endphp
@if($isImage) Attachment @else @endif
{{ basename($path) }}
View / Download
@empty
No attachments available.
@endforelse
@endsection