{{-- ICTHospital - invoice, payments and the balance. Copyright (c) DEVtrust Part of ICTHospital Licensed under the GNU General Public License v3.0. --}} @extends('layouts.master') @section('style') @stop @section('content') @if (Session::get('success'))
{{ Session::get('success') }}
@endif @if (Session::get('error'))
{{ Session::get('error') }}
@endif

Invoice #{{ $invoice->id }} {{ $invoice->date }}

@if (count($errors) > 0)
    @foreach ($errors->all() as $error)
  • {{ $error }}
  • @endforeach
@endif

Patient: @if ($patient) {{ $patient->name }} ({{ $patient->patient_id }}) @else {{ $invoice->patient_name ?: 'Unknown' }} @endif

Doctor: {{ $doctor ? $doctor->name : ($invoice->doctor_name ?: '-') }}

Status: {{ ucfirst($invoice->settlement()) }}

@foreach ($invoice->items as $item) @php($pkg = $item->payment_category_id ? \App\Models\ServicePackageItem::where('package_id', $item->payment_category_id)->get() : collect()) @if ($pkg->isNotEmpty()) @php($pkgNames = \App\Models\PaymentCategory::whereIn('id', $pkg->pluck('component_id'))->pluck('category', 'id')) @endif @endforeach
Charge Quantity Unit Total
{{ $item->name }} {{ $item->quantity }} {{ number_format((float) $item->unit_price, 2) }} {{ number_format((float) $item->line_total, 2) }}
Includes: {{ $pkg->map(fn ($c) => ($pkgNames[$c->component_id] ?? '') . ($c->quantity > 1 ? ' x' . $c->quantity : ''))->implode(', ') }}
Subtotal {{ number_format((float) $invoice->amount, 2) }}
Discount {{ number_format((float) $invoice->discount, 2) }}
Tax {{ number_format((float) $invoice->vat, 2) }}
Total {{ number_format((float) $invoice->gross_total, 2) }}
Paid {{ number_format($invoice->paid(), 2) }}
Balance {{ number_format($invoice->balance(), 2) }}
@php($shares = \App\Models\DoctorShare::where('payment_id', $invoice->id)->get()) @if ($shares->isNotEmpty())

Doctor shares

@php($dn = \App\Models\Doctor::whereIn('id', $shares->pluck('doctor_id'))->pluck('name', 'id')) @foreach ($shares as $sh) @endforeach
DoctorTypeBase%ShareStatus
{{ $dn[$sh->doctor_id] ?? $sh->doctor_id }}{{ ucfirst($sh->role) }}{{ number_format((float) $sh->base_amount, 2) }}{{ rtrim(rtrim($sh->percent, '0'), '.') }}{{ number_format((float) $sh->amount, 2) }}{{ ucfirst($sh->status) }}
@endif @if ($invoice->payments->isNotEmpty())

Payments

@foreach ($invoice->payments as $payment) @endforeach
WhenMethodReferenceAmount
{{ $payment->paid_at }} {{ $payment->method ?: '-' }} {{ $payment->reference ?: '-' }} {{ number_format((float) $payment->amount, 2) }}
@endif @if ($invoice->balance() > 0.004)

Take a payment

{{ csrf_field() }}

More than the outstanding balance is refused, rather than accepted and left as a negative for somebody to puzzle over later.

@endif
@stop @section('script') @stop