@php $counter = 1; $dateTime = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $date = $dateTime->format("d/m/y h:i a"); // Consolidate all policy data $allPolicies = []; foreach ($response['data'] as $pageData) { foreach ($pageData as $value1) { foreach ($value1 as $policy) { $allPolicies[] = $policy; } } } // Group and sort client data $groupedData = []; foreach ($response['client_data'] as $client) { $groupName = $client['group_name']; if (!isset($groupedData[$groupName])) { $groupedData[$groupName] = []; } $groupedData[$groupName][] = $client; } ksort($groupedData); foreach ($groupedData as $groupName => &$clients) { usort($clients, function($a, $b) { return strcmp($a['policy_holder_name'], $b['policy_holder_name']); }); } unset($clients); // Flatten grouped data into unique policy holders with policies $policyHolders = []; foreach ($groupedData as $groupName => $clients) { foreach ($clients as $client) { $hasPolicies = false; foreach ($allPolicies as $policy) { if ($policy['policy_holder_name'] == $client['policy_holder_name']) { $hasPolicies = true; break; } } if ($hasPolicies && !in_array($client['policy_holder_name'], array_column($policyHolders, 'policy_holder_name'))) { $policyHolders[] = $client; } } } $lastPolicyHolderPerGroup = []; foreach ($groupedData as $groupName => $clients) { $policyHoldersWithPolicies = array_filter($clients, function($client) use ($allPolicies) { return in_array($client['policy_holder_name'], array_column($allPolicies, 'policy_holder_name')); }); if (!empty($policyHoldersWithPolicies)) { $lastPolicyHolderPerGroup[$groupName] = end($policyHoldersWithPolicies)['policy_holder_name']; } } // Pre-calculate total pages $totalPages = 0; $maxRowsPerPage = 15; // Adjust based on your 80mm height and 9px font size foreach ($policyHolders as $client) { $policiesForHolder = array_filter($allPolicies, function($policy) use ($client) { return $policy['policy_holder_name'] == $client['policy_holder_name']; }); $totalPolicies = count($policiesForHolder); $totalPages += ceil($totalPolicies / $maxRowsPerPage); } @endphp Reachassuree - Consolidated Renewal Report @if (empty($policyHolders))

No policy holders with policies found.

@else @php $currentPageCounter = 0; // Cumulative page counter @endphp @foreach ($policyHolders as $client) @php $policiesForHolder = array_filter($allPolicies, function($policy) use ($client) { return $policy['policy_holder_name'] == $client['policy_holder_name']; }); if (empty($policiesForHolder)) continue; $counter = 1; $policyArray = array_values($policiesForHolder); $totalPolicies = count($policyArray); $pagesNeeded = ceil($totalPolicies / $maxRowsPerPage); @endphp @for ($page = 0; $page < $pagesNeeded; $page++) @php $startIndex = $page * $maxRowsPerPage; $endIndex = min($startIndex + $maxRowsPerPage, $totalPolicies); $currentPageCounter++; // Increment for each page @endphp
Header Avatar

:: Consolidated Renewal Report (D/L) ::

@if($response['start_date'] != 'not selected') From Date :- {{ $response['start_date'] }} @endif @if($response['end_date'] != 'not selected') To Date :- {{ $response['end_date'] }} @endif

Selected Department: @php $lastDepartmentCount = count($response['department']) - 1; foreach ($response['department'] as $key2 => $value2) { echo $value2 . ($key2 < $lastDepartmentCount ? ", " : ""); } if ($lastDepartmentCount == 0) echo "General Insurance, Life Insurance, Investment, Documents"; @endphp

Page :- {{ $currentPageCounter }} > {{ $totalPages }}
@for ($i = $startIndex; $i < $endIndex; $i++) @php $policy = $policyArray[$i]; @endphp @if($policy['remark'] != '') @else @endif @if($policy['remark'] != '') @endif @php $counter++; @endphp @endfor @if ($page == $pagesNeeded - 1) @foreach ($response['total'] as $key2 => $value2) @foreach ($value2 as $key3 => $value3) @if($client['policy_holder_name'] == $key3 && $key3 != "group_total") @endif @if($key3 == "group_total" && $key2 == $client['group_name'] && $client['policy_holder_name'] == $lastPolicyHolderPerGroup[$client['group_name']]) @endif @endforeach @endforeach @endif
Group Name: {{ $client['group_name'] }} Family Name: {{ $client['family_name'] }}
Policy Holder Name: {{ $client['policy_holder_name'] }} Mob No: {{ $client['mobile_number'] . ' / ' . $client['whatsapp_number'] }} Email: {{ $client['email'] }}
Sr. No. Division Ins. Co. Name Policy / Docs. No. Plan / Segment / Docs Detail Risk Start Sum Assured Risk End Last Prem. Mode Due Type Renewal Date Payable Receivable
{{ $counter }}{{ $counter }}{{ $policy['division'] ?? '-' }} {{ $policy['ins_comp_name'] ?? '-' }} {{ $policy['policy_number'] ?? '-' }} {{ $policy['plan_segment_name'] ?? '-' }} {{ $policy['plan_segment_details'] ?? '-' }} {{ $policy['risk_start_date'] ?? '-' }} {{ $policy['sum_assured'] ?? '-' }} {{ $policy['risk_end_date'] ?? '-' }} {{ $policy['last_prem_date'] ?? '-' }} {{ $policy['mode'] ?? '-' }} {{ $policy['due_type'] ?? '-' }} {{ $policy['renewal_date'] ?? '-' }} {{ $policy['payble_amt'] ?? '-' }} -
Remarks {{ $policy['remark'] ?? '-' }}
Member Total {{ $value3['member_total'] ?? '-' }}
Group Total {{ $value3 ?? '-' }}
@endfor @endforeach @endif