diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 9d7a4b2f..2daa6305 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -773,7 +773,7 @@ class LeadsController extends BaseController // dd($data); if ($data['lead_data']['lead_form_type'] == 1) { - + $data['demogrphy_html_data'] = $this->generateDemographyDataTable(['lead_id' => $id]); $this->loadLayout('view_rfq.php', $data); } else if ($data['lead_data']['lead_form_type'] == 2) { @@ -1271,7 +1271,6 @@ class LeadsController extends BaseController return $newRowData; } - private function renumberProposalKeys(array $input): array { $result = []; @@ -2062,7 +2061,7 @@ class LeadsController extends BaseController return true; } - public function calculateMembersDemography($params) + public function calculateMembersDemography($params, $returnType = null) { $lead_id = $params['lead_id']; $lead_data = $this->leadsModel->find($lead_id); @@ -2115,12 +2114,20 @@ class LeadsController extends BaseController $this->myLogger->logme('error', ($message . $file_name_with_path)); return ['status' => 'failed', 'message' => $message]; } + try { $classifiers = $this->getDemographyData($members, $age_band_data, $members_heading, $available_col, $col_index); } catch (Exception $e) { return ['status' => 'fail', 'message' => $e->getMessage()]; } + //for this to view the demography in the RFQ and QCR page to using internal + if($returnType == "internal"){ + return ['data' => $classifiers]; + // print_rr($classifiers); die; + } + + try { $result = $this->generateClassifierSpreadsheet($classifiers, WRITEPATH . 'uploads/lead_files/'); if ($result['success']) { @@ -4818,4 +4825,55 @@ class LeadsController extends BaseController return []; } + + + public function generateDemographyDataTable($param) + { + $returnData = $this->calculateMembersDemography($param, "internal"); + + $html = ""; + + if (isset($returnData['data'])) { + + $data = $returnData['data']; + foreach ($data as $category => $records) { + // Extract all column headers (age groups) dynamically + $allColumns = []; + foreach ($records as $person => $ages) { + $allColumns = array_merge($allColumns, array_keys($ages)); + } + $allColumns = array_unique($allColumns); + $allColumns = array_values($allColumns); // reset index + + $category = ucfirst($category); + + // Start table with clean styling + $html .= "
| Relation | "; + foreach ($allColumns as $col) { + $html .= "{$col} | "; + } + $html .= "
|---|---|
| {$relation} | "; + foreach ($allColumns as $col) { + $value = isset($ages[$col]) ? $ages[$col] : "-"; + $html .= "{$value} | "; + } + $html .= "