@extends('backend.template.layouts.template-base') @section('title', isset($bill) ? 'Modify bill' : 'New bill') @section('styles') @endsection @section('content') @php $isEdit = isset($bill); $p = $prefillPatient ?? ($bill->patient ?? null); $showPatientCard = $isEdit || $p; $ageYears = $p?->age ?? ($p?->dob ? \Carbon\Carbon::parse($p->dob)->age : null); $honorific = $p?->honorificPrefix() ?: ''; $resolvedSex = $p?->resolvedSex(); $sexLetter = $resolvedSex ? strtoupper(substr($resolvedSex, 0, 1)) : ''; $ageSex = ($ageYears !== null && $sexLetter) ? $ageYears . ' YRS/' . $sexLetter : ($ageYears !== null ? $ageYears . ' YRS' : '—'); $patientDisplay = $p ? trim(($honorific !== '' ? $honorific . ' ' : '') . ($p->name ?: trim(($p->first_name ?? '') . ' ' . ($p->last_name ?? '')))) : '—'; $lastReg = $lastRegNo ?? ($isEdit ? $bill->id : null); $defReferred = old('referred_by', session('selected_referrer', $isEdit ? $bill->referred_by : '')); $defCentre = old('collection_centre', $isEdit ? $bill->collection_centre : 'Main'); $defAgent = old('sample_collection_agent', $isEdit ? $bill->sample_collection_agent : ''); $defSampleCollectedAt = old('sample_collected_at', $isEdit ? ($bill->sample_collected_at ?? '') : ''); $showSampleCollectedBlock = filled($defSampleCollectedAt); $defLab = old('lab_investigations', $isEdit ? $bill->lab_investigations : ($prefillLabInvestigations ?? '')); $prefillTotals = $prefillPaymentTotals ?? null; $defPaid = old('lab_paid', $isEdit ? $bill->paid_amount : (float) ($prefillTotals['total_amount'] ?? 0)); $defDiscount = old('lab_discount', $isEdit ? $bill->discount : 0); $defPayPaid = old('payment_paid', $isEdit ? 0 : (float) ($prefillTotals['total_amount'] ?? 0)); $defPayDiscount = old('payment_discount', $isEdit ? $bill->discount : 0); $defAmountReceived = old('amount_received', 0); $advancePaid = $isEdit ? (float) $bill->paid_amount : 0; $defMode = old('payment_mode', $isEdit ? $bill->payment_mode : 'cash'); $defRemarks = old('remarks', $isEdit ? $bill->remarks : ''); $defTotal = $isEdit ? (float) $bill->total_amount : (float) ($prefillTotals['total_amount'] ?? 0); $defBalance = $isEdit ? (float) $bill->balance : (float) ($prefillTotals['balance'] ?? ($prefillTotals['total_amount'] ?? 0)); $labOpen = $isEdit || filled($defLab) || request()->filled('patient_id') || request()->filled('booking_id'); $labLines = array_values(array_filter(array_map('trim', preg_split('/\r\n|\n|\r/', (string) $defLab)))); @endphp

{{ $isEdit ? 'Modify bill' : 'New bill' }}

@if ($lastReg)
Last Reg. no. {{ $lastReg }}
@endif
Courtesy limit: 200 patients/day
@if (session('success'))
{{ session('success') }}
@endif @if ($errors->any())
@endif
@csrf @if ($isEdit) @method('PUT') @endif @if (!empty($prefillBooking)) @endif @if (!empty($prefillBooking)) @php $bookedPackageNames = $prefillBooking->packages->pluck('title')->filter()->join(', '); @endphp
Home collection booking #{{ $prefillBooking->id }} @if($prefillBooking->date) — scheduled {{ $prefillBooking->collectionScheduleLabel() }} @endif @if ($bookedPackageNames !== '') . Patient booked: {{ $bookedPackageNames }}. @endif Patient details are linked to this booking. Enter lab investigations, amounts, and lab report results manually — nothing is saved until you click Create.
@endif {{-- 1 Patient details --}}
1 Patient details @if ($p) View profile @endif
@if ($showPatientCard && $p && ! $isEdit) @endif @if ($showPatientCard)

{{ $patientDisplay }} ({{ $ageSex }})

Mobile No: {{ $p?->mobile ?: '—' }}

Email: {{ $p?->email ?: '—' }}

Address: {{ $p?->address ?: '—' }}

UHID: {{ $p?->uhid ?: '—' }}

Aadhaar number: —

Patient history: —

Registered on: {{ ($isEdit ? $bill->created_at : $p?->registred_on)?->format('d/m/Y, h:i A') ?? '—' }}

@if ($p?->dob)

Estimated DOB: {{ \Carbon\Carbon::parse($p->dob)->format('d/m/Y') }}

Age precision: Years

@endif
@if ($p) Edit @endif
@else
@error('mobile')
{{ $message }}
@enderror
@error('first_name')
{{ $message }}
@enderror
@endif
{{-- 2 Case details --}}
2 Case details
Manage referrers
Edit
@if ($isEdit)
@endif
{{ $lineCode ?? 'L1' }}
@foreach ($labLines as $line) {{ $line }} @endforeach Add tests from ratelist or type below
+ Add New | @php $ratelistPageUrl = route('backend.template.diagnostic.cases.ratelist', array_filter([ 'return' => 'newbill', 'patient_id' => request('patient_id'), 'booking_id' => request('booking_id'), ])); @endphp Ratelist Total: Rs. {{ number_format($defTotal, 0) }}, Due: Rs. {{ number_format($defBalance, 0) }}
@if ($isEdit)
is_cancelled))>
@endif
× Remove
{{-- Payment --}}
Payment Details:
Total: Rs. {{ number_format($defTotal, 0) }}
{{-- On edit the discount field is prefilled with the stored rupee amount ($bill->discount), so default to Rs mode ('0') to avoid re-interpreting rupees as a percentage. --}}
@if ($isEdit)

Rs. {{ number_format($advancePaid, 0) }}

@else
@endif
@if ($isEdit) View bill @endif
@include('backend.template.diagnostic.cases.bill.partials.case_bill_modals') @include('backend.template.diagnostic.cases.bill.partials.add_lab_investigation_modal') @include('backend.template.diagnostic.cases.bill.partials.ratelist_picker_modal')
@endsection @section('scripts') @endsection