@extends('admin_navbar') @section('content')
CUSTOMER #{{ $customer->id }}

{{ $customer->user->name }} — Test History

Email: {{ $customer->user->email }} • Phone: {{ $customer->phone ?? '-' }}
Back Download All Orders PDF
@if(session('success'))
{{ session('success') }}
@endif
{{-- Create new order --}}

Create New Visit / Order

@csrf
{{-- Orders --}} @forelse($orders as $order) @php $inv = $order->invoice; $status = $inv?->status ?? 'unpaid'; $badge = $status === 'paid' ? 'b-paid' : ($status === 'partial' ? 'b-partial' : 'b-unpaid'); $testNames = $order->items->pluck('test_name_snapshot')->filter()->take(6)->implode(', '); $moreCount = max(0, $order->items->count() - 6); if ($moreCount > 0) $testNames .= " +{$moreCount} more"; $detailsId = 'order-details-'.$order->id; @endphp
{{-- Collapsed Row --}}
Order #{{ $order->id }} {{ strtoupper($status) }}
Tests: {{ $testNames ?: 'No tests assigned yet' }}
Status: {{ $order->status }} • Branch: {{ $order->branch?->branch_name ?? 'Main/Admin' }} • Created: {{ $order->created_at->format('Y-m-d H:i') }}
Total: {{ number_format($inv?->total_amount ?? 0, 2) }}
Paid: {{ number_format($inv?->paid_amount ?? 0, 2) }}
{{-- Stop click bubbling so row doesn't toggle when clicking button --}}
{{-- Expanded Content --}}
{{-- Assign tests --}}

Assign Tests

@csrf
{{-- Assigned tests + Results --}}

Assigned Tests

@forelse($order->items as $it) @empty @endforelse
Test Code Price Result Status Result Actions
{{ $it->test_name_snapshot }} {{ $it->test_code_snapshot }} {{ number_format($it->price_snapshot, 2) }} {{ $it->result_status }} @if($it->result_posted_at)
Posted: {{ optional($it->result_posted_at)->format('Y-m-d H:i') }} @if($it->resultPostedByUser) • By: {{ $it->resultPostedByUser->name }} @endif
@endif
@if($it->result_text)
{{ \Illuminate\Support\Str::limit($it->result_text, 180) }}
@else No result yet. @endif
@if(auth()->user()->category === 'admin') @if(!empty($it) && !empty($it->id))
@csrf
@else Item not loaded properly (missing ID). @endif @else View only @endif
No tests assigned yet.
{{-- Discount --}}

Discount

@csrf
Percent: 10 = 10%. Flat: 500 = PKR 500.
{{-- Payments --}}

Payments

@csrf
@forelse($inv?->payments ?? [] as $p) @empty @endforelse
Amount Method Date Received By
{{ number_format($p->amount, 2) }} {{ $p->method }} {{ optional($p->paid_at)->format('Y-m-d H:i') }} {{ $p->receivedByUser?->name ?? '-' }}
No payments yet.
@empty

No orders yet

Create the first visit/order above, then assign tests and manage invoices.
@endforelse
@endsection