diff --git a/README.md b/README.md index b56458c2..0a4cf0dd 100755 --- a/README.md +++ b/README.md @@ -9,3 +9,5 @@ From command propmt run the following cmds Run speeific method `php vendor/bin/phpunit tests\unit\PremiumCalculationTest.php --filter testPremiumCalculationWithPrimaryRackRateAndAdditionalRackRate` + +Test Comments \ No newline at end of file diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c5eed924..b6d181b3 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -404,6 +404,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) { $routes->group("rfq", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "LeadsController::createRFQ"); + $routes->post("savePolicyInfo", "LeadsController::savePolicyInfo"); $routes->post("createQCR", "LeadsController::createQCR"); $routes->get("list/(:any)", "LeadsController::viewRFQ/$1"); $routes->get("nonEB","LeadsController::rfqNonEB"); diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 4c70308a..b361c5b3 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -28,6 +28,7 @@ use App\Models\InsurerBranchModel; use App\Models\TPABranchModel; use App\Models\RFQModel; use App\Models\InsurerModel; +use App\Models\OccupancyMasterModel; use App\Helpers\MailHelper; use App\Helpers\ExcelMergeHelper; @@ -60,6 +61,7 @@ class LeadsController extends BaseController protected $tpaBranchModel; protected $RFQModel; protected $insurerModel; + protected $occupancyModel; //variables for storing array protected $issuer; @@ -68,6 +70,7 @@ class LeadsController extends BaseController protected $leadsStatus; protected $claim_type_for_gpa; protected $cause_of_death; + protected $buisnessType; public function __construct() @@ -88,10 +91,12 @@ class LeadsController extends BaseController $this->tpaBranchModel = new TPABranchModel(); $this->RFQModel = new RFQModel(); $this->insurerModel = new InsurerModel(); + $this->occupancyModel = new OccupancyMasterModel(); $this->issuer = [1 => 'JIBS', 2 => 'Nhance']; $this->clientType = [1 => 'Group', 2 => 'Individual']; $this->leadType = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over']; + $this->buisnessType = [1 => 'Industrial', 2 => 'Non Industrial']; $this->leadsStatus = [ 'queued' => 'Queued', 'qcr_sent' => 'QCR sent', @@ -113,7 +118,6 @@ class LeadsController extends BaseController 'suicide' => 'Suicide', 'accident' => 'Accident' ]; - } public function viewLeadsList() @@ -133,10 +137,10 @@ class LeadsController extends BaseController // dd($lastFiveYears); if ($this->request->is('get')) { // Fetch leads data - $data ['lead_data_list'] = $this->leadsModel->getLeadDataForLising(); + $data['lead_data_list'] = $this->leadsModel->getLeadDataForLising(); // Load layout and pass data $this->loadLayout('lead_filter', $data); - }else{ + } else { $search_data = $this->request->getPost(); // print_r($search_data); @@ -147,7 +151,7 @@ class LeadsController extends BaseController $where[$search_objects] = $key; } } - + $data['lead_data_list'] = $this->leadsModel->getLeadDataForLising($where); $html = view('leads_list', $data); return $this->respond(['status' => true, 'html' => $html], 200); @@ -190,9 +194,9 @@ class LeadsController extends BaseController $data['client_code'] = generate_client_code('IC'); } - if(isset($data['lead_form_type'])){ + if (isset($data['lead_form_type'])) { $data = $this->prepareSingleLeadData($data); - }else{ + } else { $data = $this->prepareMultipleLeadData($data); } // print_r($data); die; @@ -208,46 +212,45 @@ class LeadsController extends BaseController $files = $this->request->getFileMultiple('file_name'); // print_r($files); die; - - - // Separate the insurer and insurer branch, handle missing or invalid data - if (isset($data['insurer']) && strpos($data['insurer'], '-') !== false) { - list($insurer_branch_id, $insurer_id) = explode('-', $data['insurer']); - - }else{ - $insurer_branch_id = 0; - $insurer_id = 0; - } - - $data['insurer_id'] = $insurer_id; - $data['insurer_branch_id'] = $insurer_branch_id; - - // Separate the insurer and insurer branch, handle missing or invalid data - if (isset($data['tpa']) && strpos($data['tpa'], '-') !== false) { - list($tpa_branch_id, $tpa_id) = explode('-', $data['tpa']); - } else { - $tpa_branch_id = 0; - $tpa_id = 0; - } - - $data['tpa_id'] = $tpa_id; - $data['tpa_branch_id'] = $tpa_branch_id; - if (!empty($data['policy_start_date'])) { - $data['policy_start_date'] = change_date_format($data['policy_start_date']); - } else { - $data['policy_start_date'] = null; - } + // Separate the insurer and insurer branch, handle missing or invalid data + if (isset($data['insurer']) && strpos($data['insurer'], '-') !== false) { + list($insurer_branch_id, $insurer_id) = explode('-', $data['insurer']); + } else { + $insurer_branch_id = 0; + $insurer_id = 0; + } - if (!empty($data['policy_end_date'])) { - $data['policy_end_date'] = change_date_format($data['policy_end_date']); - } else { - $data['policy_end_date'] = null; - } + $data['insurer_id'] = $insurer_id; + $data['insurer_branch_id'] = $insurer_branch_id; - $data['file_name'] = file_Upload($files, $uploadFilePath); - $processcedData[] = $data; + // Separate the insurer and insurer branch, handle missing or invalid data + if (isset($data['tpa']) && strpos($data['tpa'], '-') !== false) { + list($tpa_branch_id, $tpa_id) = explode('-', $data['tpa']); + } else { + $tpa_branch_id = 0; + $tpa_id = 0; + } + + $data['tpa_id'] = $tpa_id; + $data['tpa_branch_id'] = $tpa_branch_id; + + + if (!empty($data['policy_start_date'])) { + $data['policy_start_date'] = change_date_format($data['policy_start_date']); + } else { + $data['policy_start_date'] = null; + } + + if (!empty($data['policy_end_date'])) { + $data['policy_end_date'] = change_date_format($data['policy_end_date']); + } else { + $data['policy_end_date'] = null; + } + + $data['file_name'] = file_Upload($files, $uploadFilePath); + $processcedData[] = $data; // print_r($data);die(); return $processcedData; @@ -263,14 +266,13 @@ class LeadsController extends BaseController $files = $this->request->getFileMultiple('file_name'); // print_r($files); die; - - foreach($data['policy_type_id'] as $index => $value){ + + foreach ($data['policy_type_id'] as $index => $value) { // Separate the insurer and insurer branch, handle missing or invalid data if (isset($data['insurer'][$index]) && strpos($data['insurer'][$index], '-') !== false) { list($insurer_branch_id, $insurer_id) = explode('-', $data['insurer'][$index]); - - }else{ + } else { $insurer_branch_id = 0; $insurer_id = 0; } @@ -310,15 +312,15 @@ class LeadsController extends BaseController $policy_end_date = null; } - if(!empty($data['incurred_claim_date'][$index])){ + if (!empty($data['incurred_claim_date'][$index])) { $incurred_claims_date = change_date_format($data['incurred_claim_date'][$index], 'd/m/Y', 'Y-m-d'); - }else{ + } else { $incurred_claims_date = null; } - if(!empty($data['premium_date'][$index])){ + if (!empty($data['premium_date'][$index])) { $premium_date = change_date_format($data['premium_date'][$index], 'd/m/Y', 'Y-m-d'); - }else{ + } else { $premium_date = null; } @@ -406,7 +408,7 @@ class LeadsController extends BaseController $insertCount[] = $insert; $this->insertLeadStatus($insert, $value['status'], 3); - if($value['lead_form_type'] == 1){ + if ($value['lead_form_type'] == 1) { //for this push the job to the calculateMembersDemography() function $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => [ @@ -441,9 +443,9 @@ class LeadsController extends BaseController ->first(); $data['lead_edit_data'] = $this->leadsModel - ->where('leads.id', $id) - ->where('leads.is_active', 1) - ->first(); + ->where('leads.id', $id) + ->where('leads.is_active', 1) + ->first(); if (!empty($data['policy_start_date'])) { @@ -509,18 +511,18 @@ class LeadsController extends BaseController { $data['rfq_data'] = $this->RFQModel - ->where('lead_id', $id) - // ->where('type', $type) - ->where('is_active', 1) - ->orderBy('id', 'desc') - ->first(); + ->where('lead_id', $id) + // ->where('type', $type) + ->where('is_active', 1) + ->orderBy('id', 'desc') + ->first(); // dd($data); $data['rfq_count'] = $this->RFQModel - ->where('lead_id', $id) - // ->where('type', 1) - ->where('is_active', 1) - ->countAllResults(); + ->where('lead_id', $id) + // ->where('type', 1) + ->where('is_active', 1) + ->countAllResults(); $data['qcr_count'] = $this->RFQModel ->where('lead_id', $id) @@ -532,18 +534,18 @@ class LeadsController extends BaseController $data['lead_id'] = $id; $lead_data = $this->leadsModel - ->select(' + ->select(' leads.*, policy_type.question_json, policy_type.policy_type, policy_type.long_name, user_profiles.email as created_person_email ') - ->join('policy_type', 'leads.policy_type_id = policy_type.id') - ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left') - ->where('leads.id', $id) - ->where('leads.is_active', 1) - ->first(); + ->join('policy_type', 'leads.policy_type_id = policy_type.id') + ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left') + ->where('leads.id', $id) + ->where('leads.is_active', 1) + ->first(); // dd($lead_data); @@ -557,7 +559,7 @@ class LeadsController extends BaseController $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); $data['userList'] = $this->userModel->getUserListForRFQ(); $data['lead_data'] = $lead_data; - + $mail_content = "

Dear Sir,

Greetings From Nhance India!

@@ -566,8 +568,8 @@ class LeadsController extends BaseController

In case of any query, please feel free to contact us.

Thank You!

"; - - + + $subject = "{{CLIENT_NAME}} _ {{POLICY_TYPE}} _ {{RFQ_OR_QCR}} _ {{POLICY_YEAR}}"; $data['mail_content'] = $this->transformMailContent($lead_data, $mail_content, $data['page_name']); @@ -575,27 +577,58 @@ class LeadsController extends BaseController // dd($data); - if ($data['lead_data']['lead_form_type'] == 1){ - - $this->loadLayout('view_rfq.php', $data); + if ($data['lead_data']['lead_form_type'] == 1) { - }else if ($data['lead_data']['lead_form_type'] == 2){ - + $this->loadLayout('view_rfq.php', $data); + } else if ($data['lead_data']['lead_form_type'] == 2) { + + $data['occupancy'] = $this->occupancyModel->findAll(); + // dd($data['occupancy']); $data['policies'] = json_decode($data['question_json'], true)['policies']; $data["child_table_data"] = json_decode($data['question_json'], true)['child_table_data']; // $data['lead_register_data'] = json_decode($data['lead_data']['custom_fields']); // dd($data['lead_register_data']); $data['client_type'] = $this->clientType; + $data['buisness_type'] = $this->buisnessType; $this->loadLayout('view_rfq_non_eb', $data); - } - + } + + public function savePolicyInfo() + { + + $data = $this->request->getPost(); + + $lead_id = $data['lead_id']; + $json_data = $data['registration_json']; + + $existingJson = $this->RFQModel->where('is_active', 1)->where("lead_id", $lead_id)->first()['registration_json'] ?? null; + + if (empty($existingJson)) { + $this->RFQModel + ->where('lead_id', $lead_id) + ->where('type', 1) + ->where('is_active', 1) + ->set('is_active', 0) + ->update(); + + $insertData['lead_id'] = $lead_id; + $insertData['registration_json'] = json_encode($json_data); + + + $this->RFQModel->insert($insertData); + + return $this->respond(['status' => true, "message" => "Policy Inforamtion saved"]); + } else { + + return $this->respond(['status' => true, "message" => "Policy Inforamtion Already saved"]); + } } public function createRFQ() { - + // print_r($this->request->getPost('json')); die(); $data = $this->request->getPost(); @@ -608,12 +641,37 @@ class LeadsController extends BaseController ->set('is_active', 0) ->update(); - $result = $this->RFQModel->insert($data); + $registrationJson = $data['registration_json'] ?? null; // Use null coalescing operator for safety + + if ($registrationJson) { + // If registration_json is provided, insert the data directly + $result = $this->RFQModel->insert($data); + } else { + // If registration_json is not provided, fetch the latest registration_json from the database + $this->RFQModel->select('registration_json') + ->where("lead_id", $lead_id) + ->order_by('id', 'DESC') // Assuming 'id' is an auto-increment field + ->limit(1); + + $query = $this->RFQModel->get(); + $latestRegistrationJson = $query->row()->registration_json ?? null; + + if ($latestRegistrationJson) { + // If a valid registration_json is found, update the data and insert + $data['registration_json'] = $latestRegistrationJson; + $result = $this->RFQModel->insert($data); + } else { + // If no registration_json is found, insert the data as-is + $result = $this->RFQModel->insert($data); + } + } if ($result) { $message = "RFQ submitted successfully"; - if($data['submit_type'] == 'QCR'){ $message = "QCR submitted successfully"; } + if ($data['submit_type'] == 'QCR') { + $message = "QCR submitted successfully"; + } return $this->respond(['status' => true, 'id' => $result, 'message' => $message, 'data' => $data], 200); } @@ -655,10 +713,10 @@ class LeadsController extends BaseController //FOR EXCEL public function exportExcelForQCRandRFQ($lead_id, $type, $lead_form_type = 1) - { - if($lead_form_type == 2){ + { + if ($lead_form_type == 2) { $filepath = $this->constructNonEbExcelToSaveTemp($lead_id, $type); - }else{ + } else { $filepath = $this->constructExcelToSaveTemp($lead_id, $type); } @@ -1189,7 +1247,7 @@ class LeadsController extends BaseController $highestRowAndColumn = $members_sheet->getHighestRowAndColumn(); // dd($highestRowAndColumn); $uncleaned_members = $members_sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); - $members = ExcelSanitizeHelper::sanitizeArrayData($uncleaned_members); + $members = ExcelSanitizeHelper::sanitizeArrayData($uncleaned_members); //get age band data $age_band_sheet = $spreadsheet->getSheet(1); $highestRowAndColumn = $age_band_sheet->getHighestRowAndColumn(); @@ -1224,21 +1282,21 @@ class LeadsController extends BaseController $result = $this->generateClassifierSpreadsheet($classifiers, WRITEPATH . 'uploads/lead_files/'); if ($result['success']) { $this->myLogger->logme('error', "Spreadsheet generated successfully!"); - + echo "Location: " . $result['fullpath'] . "\n"; echo "Filename: " . $result['filename'] . "\n"; $filePaths = [ ['file_path' => WRITEPATH . 'uploads/lead_files/' . $lead_data['file_name'], 'sheets' => [0, 1]], - ['file_path' => WRITEPATH.'/uploads/lead_files/' . $result['filename'], 'sheets' => []], + ['file_path' => WRITEPATH . '/uploads/lead_files/' . $result['filename'], 'sheets' => []], ]; $outputPath = WRITEPATH . 'uploads/lead_files/Member_Data.xlsx'; $result_merge = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath); if ($result_merge) { // Call the delete function after the file is successfully created - $deleteResponse = $this->deleteGeneratedFile($result['fullpath']); - - // Add delete message to response - $response['deleteMessage'] = $deleteResponse['message']; + $deleteResponse = $this->deleteGeneratedFile($result['fullpath']); + + // Add delete message to response + $response['deleteMessage'] = $deleteResponse['message']; return ['status' => 'success', 'message' => 'Member_Data Merged Suceesfully']; } } else { @@ -1370,17 +1428,17 @@ class LeadsController extends BaseController throw new Exception("Failed to create directory: $outputDir"); } } - + // Check if directory is writable if (!is_writable($outputDir)) { throw new Exception("Directory is not writable: $outputDir"); } - + // Generate unique filename $timestamp = date('Y-m-d_His'); $filename = "member_classification_{$timestamp}.xlsx"; $filepath = $outputDir . DIRECTORY_SEPARATOR . $filename; - + // Check if file already exists (shouldn't happen with timestamp, but just in case) if (file_exists($filepath)) { $counter = 1; @@ -1390,31 +1448,31 @@ class LeadsController extends BaseController $filename = "member_classification_{$timestamp}_{$counter}.xlsx"; $filepath = $outputDir . DIRECTORY_SEPARATOR . $filename; } - + $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Demography_Data'); - + // Get all age bands $age_bands = array_keys(reset($classifiers['general'])); array_pop($age_bands); // Remove 'Grand Total' $age_bands[] = 'Grand Total'; // Add it back at the end - + $currentRow = 5; // Start from row 5 to match the example - + // Function to write section data $writeSectionData = function ($data, $sheet, &$currentRow, $si_type) use ($age_bands) { // Add section header for the SI type $sheet->setCellValue('B' . $currentRow, strtoupper($si_type)); - + // Style section header $sheet->getStyle('B' . $currentRow)->applyFromArray([ 'font' => ['bold' => true, 'size' => 14], 'alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER], ]); - + $currentRow++; // Move to the next row after the section header - + // Set headers for the data table $sheet->setCellValue('B' . $currentRow, 'Relationship'); $col = 'C'; @@ -1422,7 +1480,7 @@ class LeadsController extends BaseController $sheet->setCellValue($col . $currentRow, $band); $col++; } - + // Style headers $lastCol = chr(ord('B') + count($age_bands)); $headerRange = 'B' . $currentRow . ':' . $lastCol . $currentRow; @@ -1438,9 +1496,9 @@ class LeadsController extends BaseController 'horizontal' => Alignment::HORIZONTAL_CENTER, ], ]); - + $currentRow++; - + // Write data rows foreach ($data as $relation => $values) { if ($relation !== 'Grand Total') { @@ -1451,7 +1509,7 @@ class LeadsController extends BaseController $sheet->setCellValue($col . $currentRow, $value); $col++; } - + // Style data row $dataRange = 'B' . $currentRow . ':' . $lastCol . $currentRow; $sheet->getStyle($dataRange)->applyFromArray([ @@ -1465,11 +1523,11 @@ class LeadsController extends BaseController 'horizontal' => Alignment::HORIZONTAL_CENTER, ], ]); - + $currentRow++; } } - + // Add Grand Total row $sheet->setCellValue('B' . $currentRow, 'Grand Total'); $col = 'C'; @@ -1477,7 +1535,7 @@ class LeadsController extends BaseController $sheet->setCellValue($col . $currentRow, $data['Grand Total'][$band]); $col++; } - + // Style Grand Total row $totalRange = 'B' . $currentRow . ':' . $lastCol . $currentRow; $sheet->getStyle($totalRange)->applyFromArray([ @@ -1496,31 +1554,31 @@ class LeadsController extends BaseController 'horizontal' => Alignment::HORIZONTAL_CENTER, ], ]); - + $currentRow += 3; // Add gap after each section }; - + // Write each SI section with gaps foreach ($classifiers as $si_type => $data) { $writeSectionData($data, $sheet, $currentRow, $si_type); } - + // Auto-size columns foreach (range('B', chr(ord('B') + count($age_bands))) as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); } - + // Create Excel file try { // Create Excel file $writer = new Xlsx($spreadsheet); $writer->save($filepath); - + // Verify file was created successfully if (!file_exists($filepath)) { throw new Exception("Failed to create file: $filepath"); } - + // Return the file info after creation $response = [ 'success' => true, @@ -1530,7 +1588,6 @@ class LeadsController extends BaseController ]; return $response; - } catch (Exception $e) { return [ 'success' => false, @@ -1538,7 +1595,7 @@ class LeadsController extends BaseController ]; } } - + // Function to delete generated file public function deleteGeneratedFile($filePath) { @@ -1562,7 +1619,7 @@ class LeadsController extends BaseController ]; } } - + public function getAge($available_col, $member, $col_index) { if ($available_col == 'age') { @@ -1643,7 +1700,7 @@ class LeadsController extends BaseController $cc_data = isset($params['cc']) ? $params['cc'] : ""; $param_cc_mail = json_decode($cc_data, true); - + if (isset($param_cc_mail) && is_array($param_cc_mail) && count($param_cc_mail) > 0) { // Fetch user data where ID is in the param_cc_mail array $userData = $this->userModel @@ -1674,7 +1731,7 @@ class LeadsController extends BaseController $bcc_data = isset($params['bcc']) ? $params['bcc'] : ""; $param_bcc_mail = json_decode($bcc_data, true); - + if (isset($param_bcc_mail) && is_array($param_bcc_mail) && count($param_bcc_mail) > 0) { // Fetch user data where ID is in the param_cc_mail array $userData = $this->userModel @@ -1709,14 +1766,14 @@ class LeadsController extends BaseController //get file path to attach - if($lead_data["lead_form_type"] == 2){ + if ($lead_data["lead_form_type"] == 2) { $file_info = $this->constructNonEbExcelToSaveTemp($lead_id, ($file_type == 'rfq' ? 1 : 2), $propsal_and_insurer); - }else{ + } else { $file_info = $this->constructExcelToSaveTemp($lead_id, ($file_type == 'rfq' ? 1 : 2), $propsal_and_insurer); } // $file_info = $this->constructExcelToSaveTemp($lead_id, ($file_type == 'rfq' ? 1 : 2), $propsal_and_insurer); - log_message('error','File Info'.json_encode($file_info)); + log_message('error', 'File Info' . json_encode($file_info)); if ($lead_data['file_name'] != null && $lead_data['file_name'] != '') { $temp_file_path = $file_info['filePath']; $temp_file_name = $file_info['fileName']; @@ -1730,7 +1787,7 @@ class LeadsController extends BaseController $result = ExcelMergeHelper::mergeExcelFiles($filePaths, $outputPath); // print_rr($result); } - }else{ + } else { $result = $file_info['filePath']; // return $this->respond(['status' => 'fail', 'code' => 200, 'messgae' => 'File Not Found'], 200); } @@ -1767,12 +1824,12 @@ class LeadsController extends BaseController $original_message = '

Request for Quotation (RFQ)

Dear {{RECIPIENT_NAME}},

We are reaching out to request a quotation for the following insurance coverage. Please review the details below and provide your quote at your earliest convenience.

RFQ Details

Client name{{CLIENT_NAME}}
Coverage Type{{POLICY_LONG_NAME}}
Policy Start Date{{POLICY_START_DATE}}
Policy Duration{{DURATION}}
Please note: Additional terms and details are included in the attachment for your reference.

Please feel free to reach out if you require any further information to prepare the quote. We look forward to receiving your proposal.

Best regards,

Nhance India Pvt Ltd

© Nhance India Pvt Ltd. All rights reserved.

'; //for mail content - if(!empty($mail_content)){ + if (!empty($mail_content)) { $original_message = $mail_content; } //for mail subject - if(!empty($mail_subject)){ + if (!empty($mail_subject)) { $subject = $mail_subject; } @@ -1963,16 +2020,16 @@ class LeadsController extends BaseController return $data; } - + public function convertJsonForQCR($json, $type) { if ($json) { - + // Deep copy of JSON $first_json = json_decode(json_encode($json), true); // dd($first_json); - - if($type == 2){ + + if ($type == 2) { // Column-wise Check: Remove headers and relevant data if qcr == 0 foreach ($json['proposal_data']['over_all_column_data'] as $proposalKey => $proposalData) { @@ -1995,8 +2052,8 @@ class LeadsController extends BaseController // Remove proposalKey from over_all_column_data unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]); - - if($type == 2){ + + if ($type == 2) { // Remove proposalKey from premium_data unset($first_json['premium_data']['data'][$proposalKey]); } @@ -2004,7 +2061,7 @@ class LeadsController extends BaseController // Insurer Check: Remove subHeaders and relevant data for insurers with qcr == 0 foreach ($proposalData['insurers'] as $insurerIndex => $insurer) { - if (($insurer['qcr'] === 0 || $insurer['qcr'] === false) || ($insurer['stc'] === 0 || $insurer['stc'] === false) ) { + if (($insurer['qcr'] === 0 || $insurer['qcr'] === false) || ($insurer['stc'] === 0 || $insurer['stc'] === false)) { foreach ($first_json['table_data']['headers'] as &$header) { if (isset($header['subHeaders'])) { $header['subHeaders'] = array_values(array_filter($header['subHeaders'], function ($sub) use ($insurer) { @@ -2023,7 +2080,7 @@ class LeadsController extends BaseController // Remove insurer from proposal's insurers array unset($first_json['proposal_data']['over_all_column_data'][$proposalKey]['insurers'][$insurerIndex]); - if($type == 2){ + if ($type == 2) { unset($first_json['premium_data']['data'][$proposalKey][$insurer['display_name']]); } } @@ -2047,8 +2104,7 @@ class LeadsController extends BaseController $proposal['insurers'] = array_values($proposal['insurers']); return $proposal; }, $first_json['proposal_data']['over_all_column_data']); - - }else{ + } else { //remove insurer as Subheaders for RFQ foreach ($first_json['table_data']['headers'] as &$header) { @@ -2082,10 +2138,9 @@ class LeadsController extends BaseController $proposal['insurers'] = []; } } - + // Ensure to reset the reference unset($proposal); - } return $first_json; @@ -2250,7 +2305,7 @@ class LeadsController extends BaseController //Function for convert the RFQ and QCR Json to Policy Terms Json public function convertQCRJsonToPolicyTerms($data, $policy_type, $proposel_name, $insurer_name) - { + { //transform the data into the currernt proposel and insurere ( get single proposel ) $data = $this->transformProposelData($data, $proposel_name, $insurer_name); @@ -2295,7 +2350,7 @@ class LeadsController extends BaseController $si_amt = explode(',', $value); $terms_array[$item] = $si_amt[0] ?? ''; $terms_array['multiple_sum_insured'] = array_slice($si_amt, 1); - + // Add age_ratio after Sum insured if ($policy_type == 1) { $terms_array['age_ratio'] = $age_ratio; @@ -2306,7 +2361,7 @@ class LeadsController extends BaseController // CASE 3: Handle family floaters case $item === 'family_composition': $terms_array['family_floaters'] = isJsonString($input_value) ? json_decode($input_value, true) : $input_value; - + // Add age_ratio after family floaters if ($policy_type == 2) { $terms_array['age_ratio'] = $age_ratio; @@ -2350,13 +2405,13 @@ class LeadsController extends BaseController public function transformMailContent($lead_data, $mail_content, $page_name) - { - $current_year = date('Y'); + { + $current_year = date('Y'); $next_year = $current_year + 1; $policy_year = "$current_year-$next_year"; if ($lead_data) { - + // Replacing placeholders with actual values $message = $mail_content; $message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'] ?? "Valued Client", $message); @@ -2366,30 +2421,29 @@ class LeadsController extends BaseController $message = str_replace("{{POLICY_YEAR}}", $policy_year, $message); return $message; - } else { return ''; // Return empty if no lead data found } } - function getLastFiveFinancialYears() + function getLastFiveFinancialYears() { - $currentYear = date('Y'); + $currentYear = date('Y'); $currentMonth = date('m'); - + // In India, the financial year starts from April (04) if ($currentMonth < 4) { $currentYear--; // Adjust year if it's Jan-Mar } - + $financialYears = []; - + for ($i = 0; $i < 5; $i++) { $startYear = $currentYear - $i - 1; $endYear = $currentYear - $i; $financialYears[] = "$startYear-$endYear"; } - + return $financialYears; } @@ -2426,7 +2480,7 @@ class LeadsController extends BaseController ->where('user_teams.team_id', 5) ->where('user_teams.is_active', 1) ->where('user_profiles.is_active', 1) - ->findAll(); + ->findAll(); if (!empty($id)) { $data['lead_edit_data'] = $this->leadsModel->where('id', $id)->first() ?? []; @@ -2452,15 +2506,14 @@ class LeadsController extends BaseController : []; $data['lead_edit_data']['html'] = $this->generateViewPageHtml( - $data['lead_edit_data']['policy_type_id'] ?? null, + $data['lead_edit_data']['policy_type_id'] ?? null, $data ) ?? ""; - } - if($data['lead_edit_data']['lead_type'] != 1 && $data['lead_edit_data']['lead_form_type'] == 2){ + if ($data['lead_edit_data']['lead_type'] != 1 && $data['lead_edit_data']['lead_form_type'] == 2) { $data['lead_edit_data']['claims_details_html'] = view('rfq/claims_details_non_eb', $data['lead_edit_data']); - }else{ + } else { $data['lead_edit_data']['claims_details_html'] = ""; } } @@ -2471,36 +2524,50 @@ class LeadsController extends BaseController } public function getPolicyTypeFields() - { + { $policy_type_id = $this->request->getGET('policy_type_id'); $html = $this->generateViewPageHtml($policy_type_id) ?? ""; - - if(!empty($html)){ + + if (!empty($html)) { return $this->respond(['status' => true, 'code' => 200, 'message' => 'Policy Type FIELDS are found', 'data' => $html], 200); - }else{ + } else { return $this->respond(['status' => false, 'code' => 400, 'message' => 'Fields not found for this policy type'], 200); } - } public function generateViewPageHtml($policy_type_id, $data = []) { $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); - + $viewMap = [ - 1 => 'rfq/gpa', 6 => 'rfq/gpa', 7 => 'rfq/gpa', - 2 => 'rfq/gmc', 3 => 'rfq/gmc', 4 => 'rfq/gmc', 5 => 'rfq/gmc', - 22 => 'rfq/car', 23 => 'rfq/cpm', 24 => 'rfq/cyber_crime', - 25 => 'rfq/do', 27 => 'rfq/eo', 49 => 'rfq/money', - 19 => 'rfq/cgl', 59 => 'rfq/sfsp', 63 => 'rfq/wc', - 15 => 'rfq/blu', 16 => 'rfq/bsu', - 44 => 'rfq/marine', 45 => 'rfq/marine', 46 => 'rfq/marine', 47 => 'rfq/marine', + 1 => 'rfq/gpa', + 6 => 'rfq/gpa', + 7 => 'rfq/gpa', + 2 => 'rfq/gmc', + 3 => 'rfq/gmc', + 4 => 'rfq/gmc', + 5 => 'rfq/gmc', + 22 => 'rfq/car', + 23 => 'rfq/cpm', + 24 => 'rfq/cyber_crime', + 25 => 'rfq/do', + 27 => 'rfq/eo', + 49 => 'rfq/money', + 19 => 'rfq/cgl', + 59 => 'rfq/sfsp', + 63 => 'rfq/wc', + 15 => 'rfq/blu', + 16 => 'rfq/bsu', + 44 => 'rfq/marine', + 45 => 'rfq/marine', + 46 => 'rfq/marine', + 47 => 'rfq/marine', 50 => 'rfq/office' ]; - + return isset($viewMap[$policy_type_id]) ? view($viewMap[$policy_type_id], $data) : ""; } diff --git a/app/Models/OccupancyMasterModel.php b/app/Models/OccupancyMasterModel.php new file mode 100644 index 00000000..2db89bfa --- /dev/null +++ b/app/Models/OccupancyMasterModel.php @@ -0,0 +1,22 @@ + - + + +