{{-- Smart Report v2 - CBC analysis card grid. --}} {{-- Mirrors SmartReportService::GetCbcPDF (lines 3116-3347). 6 cells per page --}} {{-- in a 3-row x 2-column grid. Rows are skipped for MXD/MXD# and non-numeric --}} {{-- RESULT values, but v1 paginates on the RAW row index ($key % 6, v1:3110) --}} {{-- where skipped rows still consume an index, and uses the "big cell" name --}} {{-- variant for RAW keys 4 and 5 (v1:3154). --}} @php /** @var array $group Group view-model from WebController v2 dispatch */ /** @var \App\Services\SmartReportV2Service $service */ $service = $service ?? app(\App\Services\SmartReportV2Service::class); $Package = $group['package'] ?? ($group['firstPackage'] ?? null); $rows = $Package ? $service->buildCbcRows($Package) : []; // buildCbcRows() only emits the surviving rows (indexed by the filtered // counter), so re-derive each surviving row's RAW key here with the same // query and skip rules the service uses. $rawKeys = []; if ($Package) { $rawResults = \App\Models\ENDUSERLABORDERPACKAGERESULT::where('END_USER_PACKAGE_ID', $Package->ID) ->with('Result') ->get(); foreach ($rawResults as $rawKey => $rawRow) { $rawCode = $rawRow->Result->CODE ?? ''; if ($rawCode === 'MXD' || $rawCode === 'MXD#') continue; if (empty($rawRow->RESULT) || !is_numeric($rawRow->RESULT)) continue; $rawKeys[] = $rawKey; } } // v1 starts a new page when a RENDERED row's own raw key is a non-zero // multiple of 6 (a skipped row never triggers a break). $pages = [[]]; $pageNo = 0; foreach ($rows as $i => $row) { $rawKey = $rawKeys[$i] ?? $row['index']; if ($rawKey !== 0 && $rawKey % 6 === 0) { $pageNo++; $pages[$pageNo] = []; } // Big-cell variant follows the raw key (v1:3154), not the filtered counter. $row['is_big_cell'] = in_array($rawKey, [4, 5], true); $pages[$pageNo][] = $row; } if (empty($rows)) $pages = [[]]; // still emit a header-only page @endphp @foreach ($pages as $pageIdx => $pageRows)