@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'] }} {{ $row['180_days'] ?: '' }} {{ $row['150_days'] ?: '' }} {{ $row['120_days'] ?: '' }} {{ $row['90_days'] ?: '' }} {{ $row['60_days'] ?: '' }} {{ $row['30_days'] ?: '' }} {{ $row['current'] ?: '' }} {{ $row['balance'] }}
Totals: 180 Days
{{ $totals['180_days'] }}
150 Days
{{ $totals['150_days'] }}
120 Days
{{ $totals['120_days'] }}
90 Days
{{ $totals['90_days'] }}
60 Days
{{ $totals['60_days'] }}
30 Days
{{ $totals['30_days'] }}
Current
{{ $totals['current'] }}
Balance
{{ $totals['balance'] }}
% of Balance: {{ $totals['balance'] > 0 ? round(($totals[$key] / $totals['balance']) * 100) . '%' : '0%' }}
@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($txn->total, 2) }} {{ number_format($paidAmount, 2) }} {{ number_format($balance, 2) }} {{ $daysOverdue }} days {{ $bucket }}
Closing balance for {{ $tenantName }} : USD{{ number_format($tenantTotal, 2) }}
@endforeach
@else

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

@endif @endif
@endif
@endsection