@extends('reports::layouts.master_pdf') @php $subdomain = request()->route()->parameter('subdomain'); $is_student = app(\Hyn\Tenancy\Repositories\HostnameRepository::class)->findByHostname($subdomain)->website->company->is_student; $isAr = app()->getLocale() === 'ar'; $showCostCenter = empty($data['filters']['cost_center_ids']) || count($data['filters']['cost_center_ids']) > 1; $mainCenterLabel = __('products::cost_center.main center'); // Translate a period/aging label: keep numbers in Western digits, translate words to Arabic $translateLabel = function(string $label) use ($isAr): string { if (! $isAr) return $label; if ($label === 'Current') return 'الحالي'; if ($label === 'Credit') return 'دائن'; return str_replace(' Days', ' يوم', $label); }; // Fiscal year date range $fyRange = null; if (! empty($data['fiscalYear'])) { $fy = $data['fiscalYear']; $startFormatted = \Carbon\Carbon::createFromDate($fy->year, $fy->month, $fy->day)->format('d-m-Y'); $endFormatted = \Carbon\Carbon::parse($fy->closing_date)->format('d-m-Y'); $fyRange = $startFormatted . ' — ' . $endFormatted; } // Cost center display names $ccNames = []; if (! empty($data['costCenters'])) { foreach ($data['costCenters'] as $cc) { $ccNames[] = $isAr ? ($cc['name_ar'] ?? $cc['name_en']) : ($cc['name_en'] ?? $cc['name_ar']); } } @endphp @section('extra_styles') @if(app()->getLocale() == 'en') @else @endif @endsection @section('koolreport')
@if($is_student) @include('draft_report') @endif

@lang('reports::reports.customer_aging.title')

{{ $data['companyName'] }}

@if($fyRange)

@lang('reports::reports.customer_aging.fiscal_year'): {{ $fyRange }}

@endif @if(! empty($ccNames))

@lang('reports::reports.cost_center'): {{ implode(' | ', $ccNames) }}

@endif

@lang('reports::reports.customer_aging.customer'): {{ $data['customerName'] }}

@lang('reports::reports.customer_aging.as_of') {{ \Carbon\Carbon::parse($data['filters']['as_of_date'])->format('d-m-Y') }}

{{-- Report Metadata --}}
@lang('reports::reports.customer_aging.aging_method'): @if($data['filters']['aging_method'] === 'due_date') @lang('reports::reports.customer_aging.by_due_date') @else @lang('reports::reports.customer_aging.by_transaction_date') @endif     @lang('reports::reports.customer_aging.generated_at'): {{ $data['generatedAt'] }}
{{-- Transaction Detail Table --}} @if(count($data['transactions']) > 0) @if($showCostCenter) @endif @foreach($data['transactions'] as $transaction) @php $typeClass = $transaction['transaction_type'] === 'invoice' ? 'invoice' : ($transaction['transaction_type'] === 'debit_note' ? 'debit-note' : 'credit-note'); $typeLabel = $transaction['transaction_type'] === 'invoice' ? __('reports::reports.customer_aging.invoice') : ($transaction['transaction_type'] === 'debit_note' ? __('reports::reports.customer_aging.debit_note') : __('reports::reports.customer_aging.credit_note')); $balance = (float)($transaction['balance'] ?? 0); $agingBucketKey = $transaction['aging_bucket'] ?? 'current'; $agingBadgeClass = $agingBucketKey === 'current' ? 'current' : (preg_match('/^period_(\d+)$/', $agingBucketKey, $m) ? 'period-' . min($m[1], 4) : 'current'); if ($balance < 0) { $agingBadgeClass = 'credit'; $agingLabel = __('reports::reports.customer_aging.credit'); } else { // aging_bucket_label from service is already locale-aware via __() // Fall back to periodLabels lookup (also locale-aware) then the raw key $agingLabel = $transaction['aging_bucket_label'] ?? ($data['periodLabels'][$agingBucketKey] ?? $agingBucketKey); } $daysOverdue = (int)($transaction['days_overdue'] ?? 0); @endphp @if($showCostCenter) @endif @endforeach
@lang('reports::reports.customer_aging.type') @lang('reports::reports.customer_aging.reference') @lang('reports::reports.customer_aging.date') @lang('reports::reports.customer_aging.due_date') @lang('reports::reports.customer_aging.amount') @lang('reports::reports.customer_aging.paid') @lang('reports::reports.customer_aging.balance') @lang('reports::reports.customer_aging.days_overdue') @lang('reports::reports.customer_aging.aging')@lang('reports::reports.cost_center')
{{ $typeLabel }} {{ $transaction['reference'] }} {{ $transaction['transaction_date'] ? substr($transaction['transaction_date'], 0, 10) : '' }} {{ $transaction['transaction_due_date'] ? substr($transaction['transaction_due_date'], 0, 10) : '' }} {{ number_format((float)($transaction['amount'] ?? 0), 2) }} {{ number_format((float)($transaction['paid_amount'] ?? 0), 2) }} {{ number_format($balance, 2) }} @if($daysOverdue > 0) {{ $daysOverdue }} @elseif($daysOverdue < 0) {{ abs($daysOverdue) }} @else - @endif {{ $agingLabel }} {{ $transaction['cost_center_name'] ?? $mainCenterLabel }}
@lang('reports::reports.customer_aging.customer_net_balance'): {{ number_format((float)($data['customerBalance']['total_amount'] ?? 0), 2) }} {{ number_format((float)($data['customerBalance']['total_paid'] ?? 0), 2) }} {{ number_format((float)($data['customerBalance']['net_balance'] ?? 0), 2) }}
@else

@lang('reports::reports.customer_aging.no_transactions')

@endif
@endsection