@extends('layouts.app') @section('content') {{-- 1. FIXED BACKGROUND --}}
{{-- 2. CONTENT WRAPPER --}}
@if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif {{-- HEADER --}}

Payments Center

Manage refunds and outstanding rental balances.

{{-- ========================= --}} {{-- COLUMN 1: CLAIMABLE REFUNDS --}} {{-- ========================= --}}

Claimable Refunds

{{ $claims->count() ?? 0 }} Items
@forelse($claims ?? [] as $claim)
Booking ID

#{{ $claim->bookingID }}

{{ \Carbon\Carbon::parse($claim->bookingDate)->format('d/m/Y') }}
{{ $claim->vehicle->model ?? 'Unknown Vehicle' }}
Refund: {{-- [FIXED] CALCULATE ACTUAL PAID AMOUNT INSTEAD OF TOTAL COST --}} MYR {{ number_format($claim->payments->sum('amount'), 2) }}
Status: {{ $claim->bookingStatus }}
@if($claim->remarks)

Notes / Deduction Details

{{ $claim->remarks }}

@endif
@if($claim->payment && $claim->payment->depoStatus === 'Requested') Processing @elseif($claim->payment && $claim->payment->depoStatus === 'Refunded') Refunded @else
@csrf
@endif
@empty

No claimable refunds available.

@endforelse
{{-- ========================= --}} {{-- COLUMN 2: OUTSTANDING PAYMENTS --}} {{-- ========================= --}}

Outstanding Payments

{{ ($balanceBookings->count() ?? 0) + ($fines->count() ?? 0) }} Due
{{-- PENALTIES SECTION --}} @forelse($fines ?? [] as $penalty) @php $penaltyAmount = $penalty->amount ?? ($penalty->penaltyFees + $penalty->fuelSurcharge + $penalty->mileageSurcharge); @endphp
{{-- HEADER --}}
Penalty

MYR {{ number_format($penaltyAmount, 2) }}

{{ $penalty->penaltyStatus ?? 'Unpaid' }}

ID: #{{ $penalty->penaltyID }}

{{-- PENALTY INFO --}}
{{ $penalty->reason ?? 'Penalty Charge' }}
@if($penalty->bookingID)
@if($penalty->booking && $penalty->booking->vehicle) {{ $penalty->booking->vehicle->model }} ({{ $penalty->booking->vehicle->plateNo }}) @else Booking #{{ $penalty->bookingID }} @endif
@endif {{-- FINANCIAL BREAKDOWN --}}
Penalty Amount: MYR {{ number_format($penaltyAmount, 2) }}
@if($penalty->date_imposed)
Date Imposed: {{ \Carbon\Carbon::parse($penalty->date_imposed)->format('d M Y') }}
@endif
{{-- ACTION BUTTONS --}}
@empty @endforelse {{-- BOOKING BALANCES SECTION --}} @forelse($balanceBookings ?? [] as $booking) @php // 1. DATA CALCULATION $totalCost = $booking->totalCost; // Sum of payments effectively received and verified by Admin $verifiedPaid = $booking->payments->where('paymentStatus', 'Verified')->sum('amount'); // Sum of payments currently processing (e.g., the deposit you just submitted) $pendingPaid = $booking->payments->where('paymentStatus', 'Pending Verification')->sum('amount'); // Gross Balance: Total Cost - Verified Paid (The absolute remaining debt) $grossBalance = $totalCost - $verifiedPaid; // Net Balance: Gross Balance - Pending Paid (What is left to pay if current pending payments are Confirmed) // If you just paid a deposit, this will still be > 0 $netBalance = $grossBalance - $pendingPaid; // This ensures floating point precision errors don't cause issues if($netBalance < 0) $netBalance = 0; @endphp {{-- Show card if there is debt OR if we are waiting for a payment to clear --}} @if($grossBalance > 0)
{{-- HEADER --}}
Outstanding {{-- Show the Net Balance here so user knows what is actually LEFT to pay --}}

MYR {{ number_format($netBalance, 2) }}

{{ $booking->bookingStatus }}

ID: #{{ $booking->bookingID }}

{{-- VEHICLE INFO --}}
{{ $booking->vehicle->model }} ({{ $booking->vehicle->plateNo }})
{{-- FINANCIAL BREAKDOWN --}}
Total Cost: MYR {{ number_format($totalCost, 2) }}
@if($verifiedPaid > 0)
Paid (Verified): - MYR {{ number_format($verifiedPaid, 2) }}
@endif @if($pendingPaid > 0)
Processing: - MYR {{ number_format($pendingPaid, 2) }}
@endif
Balance to Pay: MYR {{ number_format($netBalance, 2) }}
{{-- ACTION BUTTONS --}}
@if($netBalance > 0.50) {{-- Using 0.50 buffer for float safety --}} {{-- User still owes money --}} Pay Balance @elseif($pendingPaid > 0) {{-- User has paid everything, just waiting for admin --}} Waiting for Verification @else {{-- Paid in full --}} Fully Paid @endif
@endif @empty

All payments settled

No outstanding balances.

@endforelse
{{-- SCROLLBAR --}} @endsection