@extends('layouts.app') @section('title', 'Credit Note | ' . $creditNote->credit_note_number) @section('content') @php $statusColors = [ 'pending' => 'bg-amber-100 text-amber-800 border-amber-300', 'approved' => 'bg-blue-100 text-blue-800 border-blue-300', 'applied' => 'bg-green-100 text-green-800 border-green-300', 'rejected' => 'bg-red-100 text-red-800 border-red-300', ]; $sc = $statusColors[$creditNote->status] ?? 'bg-gray-100 text-gray-800 border-gray-300'; $canApprove = auth()->user()->hasAnyRole('Finance User', 'Hospital Admin', 'Super Admin') && $creditNote->isPending() && $creditNote->requested_by !== auth()->id(); $canReject = auth()->user()->hasAnyRole('Finance User', 'Hospital Admin', 'Super Admin') && $creditNote->isPending(); $canApply = auth()->user()->hasAnyRole('Finance User', 'Hospital Admin', 'Super Admin') && $creditNote->isApproved(); @endphp
{{-- Header --}}
← Back

{{ $creditNote->credit_note_number }}

Raised {{ $creditNote->created_at->format('d M Y H:i') }} by {{ $creditNote->requester->name ?? '|' }}

{{ ucfirst($creditNote->status) }}
@if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif
{{-- LEFT: Credit note detail --}}
{{-- Summary card --}}

Credit Note Detail

Patient
{{ $creditNote->patient->full_name ?? '|' }}
MRN
{{ $creditNote->patient->mrn ?? '|' }}
Invoice
{{ $creditNote->invoice?->invoice_number ?? '|' }}
Credit Amount
KES {{ number_format($creditNote->amount) }}
Reason
{{ $creditNote->reason }}
@if($creditNote->invoiceItem)
Line Item
{{ $creditNote->invoiceItem->description }} (KES {{ number_format($creditNote->invoiceItem->total) }})
@endif @if($creditNote->description)
Description
{{ $creditNote->description }}
@endif
{{-- Workflow timeline --}}

Workflow Timeline

  1. Raised

    {{ $creditNote->created_at->format('d M Y H:i') }} · {{ $creditNote->requester->name ?? '|' }}

  2. @if($creditNote->approved_at)
  3. Approved

    {{ $creditNote->approved_at->format('d M Y H:i') }} · {{ $creditNote->approver->name ?? '|' }}

    @if($creditNote->approval_notes)

    "{{ $creditNote->approval_notes }}"

    @endif
  4. @endif @if($creditNote->applied_at)
  5. Applied to Invoice

    {{ $creditNote->applied_at->format('d M Y H:i') }}

  6. @endif @if($creditNote->rejected_at)
  7. Rejected

    {{ $creditNote->rejected_at->format('d M Y H:i') }} · {{ $creditNote->rejector->name ?? '|' }}

    @if($creditNote->rejection_reason)

    "{{ $creditNote->rejection_reason }}"

    @endif
  8. @endif
{{-- Invoice items (for context) --}}

Invoice Line Items

@foreach($creditNote->invoice?->items ?? [] as $item) @endforeach
Description Category Total (KES)
{{ $item->description }} @if($item->source_type === 'credit_note')CN@endif {{ $item->category }} {{ number_format($item->total) }}
Invoice Total KES {{ number_format($creditNote->invoice?->total_amount ?? 0) }}
Paid KES {{ number_format($creditNote->invoice?->amount_paid ?? 0) }}
Balance KES {{ number_format($creditNote->invoice?->balance ?? 0) }}
{{-- RIGHT: Action panel --}}
{{-- Approve --}} @if($canApprove)

Approve Credit Note

@csrf
@endif {{-- Apply --}} @if($canApply)

Apply to Invoice

This will write a negative line item of KES {{ number_format($creditNote->amount) }} to invoice {{ $creditNote->invoice?->invoice_number ?? '' }} and recalculate the balance.

@csrf
@endif {{-- Reject --}} @if($canReject)

Reject

@csrf
@endif {{-- Self-approval warning --}} @if($creditNote->isPending() && $creditNote->requested_by === auth()->id() && auth()->user()->hasAnyRole('Finance User','Hospital Admin','Super Admin'))

⚠ Four-eyes rule

You raised this credit note and cannot approve it yourself. Another authorised user must review it.

@endif {{-- Status info for non-pending --}} @if($creditNote->isApplied())

✓ Applied

This credit note has been applied to invoice {{ $creditNote->invoice?->invoice_number ?? '' }}. The balance has been updated.

@endif @if($creditNote->isRejected())

✗ Rejected

{{ $creditNote->rejection_reason }}

@endif
@endsection