@extends('layouts.nav') @section('title', 'Age Analysis Report') @section('content')

Age Analysis Report

@if ($errors->any())
@endif
Report Filters
@csrf
Refresh
@if(request()->filled('report_type'))
{{-- Summary Report --}} @if(request()->input('report_type') == 'summary')
@php $totals = ['180_days' => 0, '150_days' => 0, '120_days' => 0, '90_days' => 0, '60_days' => 0, '30_days' => 0, 'current' => 0, 'balance' => 0]; @endphp @foreach($reportData as $row) @foreach($totals as $key => $value) @php $totals[$key] += $row[$key]; @endphp @endforeach @endforeach @foreach (['180_days', '150_days', '120_days', '90_days', '60_days', '30_days', 'current'] as $key) @endforeach
Tenant 180+ Days 150 Days 120 Days 90 Days 60 Days 30 Days Current Balance
{{ $row['tenant'] }} {{ !empty($row['180_days']) ? number_format($row['180_days'], 2) : '' }} {{ !empty($row['150_days']) ? number_format($row['150_days'], 2) : '' }} {{ !empty($row['120_days']) ? number_format($row['120_days'], 2) : '' }} {{ !empty($row['90_days']) ? number_format($row['90_days'], 2) : '' }} {{ !empty($row['60_days']) ? number_format($row['60_days'], 2) : '' }} {{ !empty($row['30_days']) ? number_format($row['30_days'], 2) : '' }} {{ !empty($row['current']) ? number_format($row['current'], 2) : '' }} {{ !empty($row['balance']) ? number_format($row['balance'], 2) : '' }}
Totals: 180+ Days
{{ $totals['180_days'] != 0 ? number_format($totals['180_days'], 2) : '' }}
150 Days
{{ $totals['150_days'] != 0 ? number_format($totals['150_days'], 2) : '' }}
120 Days
{{ $totals['120_days'] != 0 ? number_format($totals['120_days'], 2) : '' }}
90 Days
{{ $totals['90_days'] != 0 ? number_format($totals['90_days'], 2) : '' }}
60 Days
{{ $totals['60_days'] != 0 ? number_format($totals['60_days'], 2) : '' }}
30 Days
{{ $totals['30_days'] != 0 ? number_format($totals['30_days'], 2) : '' }}
Current
{{ $totals['current'] != 0 ? number_format($totals['current'], 2) : '' }}
Balance
{{ $totals['balance'] != 0 ? number_format($totals['balance'], 2) : '' }}
% of Balance: {{ $totals['balance'] > 0 && $totals[$key] > 0 ? round(($totals[$key] / $totals['balance']) * 100, 2) . '%' : '' }}
@endif {{-- Detailed Report --}} @if(request()->input('report_type') == 'detailed') @if($detailedData->isNotEmpty())
@foreach ($detailedData as $tenantName => $transactions) @php $firstTxn = $transactions->first(); $tenantTotal = 0; @endphp

Tenant: {{ $tenantName }}

@foreach ($transactions as $txn) @php $entryDate = \Carbon\Carbon::parse($txn->entrydate); $now = \Carbon\Carbon::parse($to_date); $daysOverdue = $entryDate->diffInDays($now, false); $daysOverdue = max(0, $daysOverdue); $discountAmount = ($txn->discount / 100) * $txn->total; $paidAmount = $txn->dr ?? 0; $balance = ($txn->total ?? 0) - $discountAmount - $paidAmount; $bucket = match(true) { $daysOverdue >= 180 => '180 Days', $daysOverdue >= 150 => '150 Days', $daysOverdue >= 120 => '120 Days', $daysOverdue >= 90 => '90 Days', $daysOverdue >= 60 => '60 Days', $daysOverdue >= 30 => '30 Days', default => 'Current', }; $tenantTotal += $balance; @endphp @endforeach
Date Invoice Discount Rent (USD) Amount Paid (USD) Balance (USD) Overdue(dys) Age(Group)
{{ $entryDate->format('d/m/Y') }} {{ $txn->batch }} {{ $txn->discount }}% {{ number_format(num: $txn->total, decimals: 2) }} {{ number_format(num: $paidAmount, decimals: 2) }} {{ number_format(num: $balance, decimals: 2) }} {{ $daysOverdue }} days {{ $bucket }}
Closing balance for {{ $tenantName }} : USD{{ number_format(num: $tenantTotal, decimals: 2) }}
@endforeach
@else

No detailed age analysis data found for the selected date range.

@endif @endif
@endif
@endsection