diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9c09427e..680cba75 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -22,7 +22,7 @@ $routes->get("update-policy-terms-for-corrections", "ClientController::updatePol $routes->get("update_rack_rate_json", "ClientController::updateRackRateJson"); $routes->get("updatajson", "EmpDataServiceController::updatajson"); $routes->get("view", "EmployeeController::viewECard/$1"); -// $routes->get("exportQCRandRFQ", "LeadsController::exportQCRandRFQ"); +$routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); $routes->get("smapletest", "ClientController::smapletest"); $routes->get("testMailAttachments", "ClientController::testMailAttachments"); $routes->get("updatePolicyTermsKey", "ClientController::updatePolicyTermsKey"); @@ -346,6 +346,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('getCDAmount', 'ClientController::getCDAmount'); $routes->get('getTheEmpDataForClaim/(:any)', 'ClientController::getTheEmpDataForClaim/$1'); $routes->get('getTheEmpDataForClaimSearchByMobile/(:any)', 'ClientController::getTheEmpDataForClaimSearchByMobile/$1'); + $routes->get('getLeadNonEB/(:any)', 'LeadsController::getLeadNonEB/$1'); + $routes->get('getPolicyTypeFields', 'LeadsController::getPolicyTypeFields'); }); $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index fffbcbd8..3bae2393 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -3679,8 +3679,11 @@ class ClientController extends AdminController { // ---------for client----------------------------------------------------------------------------- - $clients = $this->clientModel->where('is_active', 1)->findAll(); - + $clients = $this->clientModel + ->select("*, DATE_FORMAT(dob, '%d-%m-%Y') as dob") + ->where('is_active', 1) + ->findAll(); + $clientIds = array_column($clients, 'id'); // Fetch branches in a single query @@ -3814,7 +3817,7 @@ class ClientController extends AdminController // Add additional fields if client type is 2 if ($client_type == 2) { $client_data = array_merge($client_data, [ - 'dob' => $postData['dob'], + 'dob' => change_date_format($postData['dob']), 'aadhar' => $postData['aadhar'], 'phone' => $postData['phone'], 'email' => $postData['email'], diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index f0f1cc7b..dc7f17ea 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -118,14 +118,6 @@ class LeadsController extends BaseController public function viewLeadsList() { - - // $d = $this->constructExcelToSaveTemp(24, 1, $propsal_and_insurer = null); - // $job_details = new Jobs(); - // $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => ['lead_id' => 24]]); - // $d = $this->calculateMembersDemography(['lead_id' => 24]); - //$this->mergeQuoteExcelFileWithMembersListExcelFile(24, 1, $propsal_and_insurer = null); - // dd($d); - $data['page_name'] = 'Leads'; // Set basic data @@ -138,23 +130,6 @@ class LeadsController extends BaseController $data['policy_type'] = $this->policyTypeModel->where('is_active', 1)->findAll(); $data['entity'] = $this->kycEntityTypeModel->where('is_active', 1)->findAll(); - // Fetch insurer and TPA branch data - $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); - $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); - // print_r($data['tpa']);die(); - // Fetch sales team members who are active in team 5 - $data['salse_team'] = $this->userModel - ->select('user_profiles.*') - ->join('user_teams', 'user_profiles.id = user_teams.user_id') - ->where('user_teams.team_id', 5) - ->where('user_teams.is_active', 1) - ->where('user_profiles.is_active', 1) - ->findAll(); - - // dd($data); - $data['lastFiveYears'] = $this->getLastFiveFinancialYears(); - $data['gpaClaimType'] = $this->claim_type_for_gpa; - $data['causeOfDeath'] = $this->cause_of_death; // dd($lastFiveYears); if ($this->request->is('get')) { // Fetch leads data @@ -184,7 +159,7 @@ class LeadsController extends BaseController // print_r($this->request->getPost()); die; $id = $this->request->getPost('id'); $data = $this->prepareLeadData(); - // print_r($this->request->getPost()); die; + // print_r($data); die; if (!$id) { @@ -215,11 +190,69 @@ class LeadsController extends BaseController $data['client_code'] = generate_client_code('IC'); } - $data = $this->prepareMultipleLeadData($data); + if(isset($data['lead_form_type'])){ + $data = $this->prepareSingleLeadData($data); + }else{ + $data = $this->prepareMultipleLeadData($data); + } // print_r($data); die; return $data; } + private function prepareSingleLeadData($data) + { + // print_r($data); die; + $uploadFilePath = WRITEPATH . 'uploads/lead_files/'; + + // Get all uploaded files for 'file_name[]' + $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; + } + + 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; + } + private function prepareMultipleLeadData($data) { // print_r($data); die; @@ -291,22 +324,8 @@ class LeadsController extends BaseController $file_name = file_Upload($files[$index], $uploadFilePath); - $last_3_years_claims = null; - if($value != 2){ - $last_3_years_claims = []; - $finyear = json_decode($data['finyear']); + $last_3_years_claims = $data['finyear']; - foreach ($finyear as $year){ - $received_policy_type = ($year->finyear[0]->policy_type); - if ($value == $received_policy_type){ - array_push($last_3_years_claims,$year); - }else{ - continue; - } - } - $last_3_years_claims = json_encode($last_3_years_claims); - } - $processedData[] = [ 'lead_type' => $data['lead_type'], 'issuer' => $data['issuer'], @@ -328,18 +347,18 @@ class LeadsController extends BaseController 'policy_type_id' => $value, 'salse_person_id' => $data['salse_person_id'] ?? 0, - 'insurer_id' => $insurer_id ?? 0, - 'insurer_branch_id' => $insurer_branch_id ?? 0, - 'tpa_id' => $tpa_id ?? 0, - 'tpa_branch_id' => $tpa_branch_id ?? 0, - 'policy_start_date' => $policy_start_date, - 'policy_end_date' => $policy_end_date, - 'no_of_lives' => $data['no_of_lives'][$index] ?? null, - 'incurred_claims' => $data['incurred_claims'][$index] ?? 0, - 'location' => $data['location'][$index] ?? null, - 'proposed_insurer_id' => $proposed_insurer_id ?? 0, - 'proposed_insurer_branch_id' => $proposed_insurer_branch_id ?? 0, - 'proposed_tpa_id' => $proposed_tpa_id ?? 0, + 'insurer_id' => $insurer_id ?? 0, + 'insurer_branch_id' => $insurer_branch_id ?? 0, + 'tpa_id' => $tpa_id ?? 0, + 'tpa_branch_id' => $tpa_branch_id ?? 0, + 'policy_start_date' => $policy_start_date, + 'policy_end_date' => $policy_end_date, + 'no_of_lives' => $data['no_of_lives'][$index] ?? null, + 'incurred_claims' => $data['incurred_claims'][$index] ?? 0, + 'location' => $data['location'][$index] ?? null, + 'proposed_insurer_id' => $proposed_insurer_id ?? 0, + 'proposed_insurer_branch_id' => $proposed_insurer_branch_id ?? 0, + 'proposed_tpa_id' => $proposed_tpa_id ?? 0, 'proposed_tpa_branch_id' => $proposed_tpa_branch_id ?? 0, 'renewal_emp_count' => $data['renewal_emp_count'][$index] ?? 0, @@ -370,6 +389,9 @@ class LeadsController extends BaseController 'status' => $data['status'] ?? null, 'notes' => $data['notes'] ?? null, + + 'lead_form_type' => $data['lead_form_type'] ?? 1, + 'custom_fields' => $data['custom_fields'] ?? null, ]; } // print_r($processedData);die(); @@ -384,11 +406,13 @@ class LeadsController extends BaseController $insertCount[] = $insert; $this->insertLeadStatus($insert, $value['status'], 3); - //for this push the job to the calculateMembersDemography() function - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'calculateMembersDemography', 'payload' => [ - 'lead_id' => $insert, - ]]); + 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' => [ + 'lead_id' => $insert, + ]]); + } } if (count($insertCount) > 0) { @@ -416,6 +440,12 @@ class LeadsController extends BaseController ->where('leads.is_active', 1) ->first(); + $data['lead_edit_data'] = $this->leadsModel + ->where('leads.id', $id) + ->where('leads.is_active', 1) + ->first(); + + if (!empty($data['policy_start_date'])) { $data['policy_start_date'] = change_date_format($data['policy_start_date'], 'Y-m-d', 'd/m/Y'); } else { @@ -440,6 +470,19 @@ class LeadsController extends BaseController $data['premium_date'] = null; } + $data['lastFiveYears'] = $this->getLastFiveFinancialYears(); + $data['gpaClaimType'] = $this->claim_type_for_gpa; + $data['causeOfDeath'] = $this->cause_of_death; + + if (!empty($data['fin_years_claims'])) { + $decoded = json_decode($data['fin_years_claims'], true); + $data['lead_edit_data']['fin_years_claims_array'] = isset($decoded['finyear']) ? $decoded['finyear'] : []; + } else { + $data['lead_edit_data']['fin_years_claims_array'] = []; + } + + $data['html'] = $this->generateViewPageHtml($data['policy_type_id'], $data) ?? ""; + if ($data) { return $this->respond(['status' => true, 'data' => $data], 200); } else { @@ -590,15 +633,20 @@ class LeadsController extends BaseController //export main route function - public function exportQCRandRFQ($lead_id, $type, $export_type) + public function exportQCRandRFQ($lead_id, $type, $lead_form_type) { - $this->exportExcelForQCRandRFQ($lead_id, $type); + $this->exportExcelForQCRandRFQ($lead_id, $type, $lead_form_type); } //FOR EXCEL - public function exportExcelForQCRandRFQ($lead_id, $type) - { - $filepath = $this->constructExcelToSaveTemp($lead_id, $type); + public function exportExcelForQCRandRFQ($lead_id, $type, $lead_form_type = 1) + { + if($lead_form_type == 2){ + $filepath = $this->constructNonEbExcelToSaveTemp($lead_id, $type); + }else{ + $filepath = $this->constructExcelToSaveTemp($lead_id, $type); + } + $lead_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type); // dd($filepath); @@ -2279,69 +2327,6 @@ class LeadsController extends BaseController //------------------------------------------------------------------------------------------------ - // public function transformMailContent($lead_id, $page_name) - // { - // helper('excel_util_helper'); - // // $params = $this->request->getGet(); - - // // print_r($params); die; - // // $lead_id = $params['lead_id']; - // // $file_type = $params['file_type']; //rfq or qcr - // // $recipient_type = $params['recipient_type']; //insurer or client or internal or placement - // // $recipient_mail = $params['recipient_mail']; // - only primary key of contacts - // // $propsal_and_insurer = isset($params['proposal_insurer']) ? $params['proposal_insurer'] : null; - - // // if ($recipient_type == 'insurer' && empty($recipient_mail)) { - // // return $this->respond(['status' => 'failed', 'code' => 400, 'data' => '', 'messgae' => 'Recipient mail not found ! '], 200); - // // } - - // //gather lead info - // $lead_data = $this->leadsModel - // ->select('leads.*,policy_type.long_name,policy_type.policy_type,user_profiles.email as created_person_email') - // ->join('policy_type', 'leads.policy_type_id = policy_type.id', 'left') - // ->join('user_profiles', 'leads.created_by = user_profiles.id', 'left') - // ->where('leads.id', $lead_id) - // ->first(); - - // // dd($lead_data); - - // if($lead_data){ - - // $recipient_data = ['name' => "Team"]; - // // $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.

'; - // $original_message = `Dear Sir, - - // Greetings From Nhance India! - - // Please find attached the RFQ for {{POLICY_TYPE}} policy pertaining to {{RECIPIENT_NAME}} - // Kindly request you to share the competitive quotes at the earliest - // In case of any query, Please feel free to contact us. - // Thank You !`; - - // $message = $original_message; - // $message = str_replace("{{RECIPIENT_NAME}}", $lead_data['client_name'], $message); - // $message = str_replace("{{POLICY_LONG_NAME}}", $lead_data['long_name'] ?? $lead_data['policy_type'], $message); - // $message = str_replace("{{POLICY_TYPE}}", $lead_data['policy_type'], $message); - // $message = str_replace("{{RFQ_OR_QCR}}", $page_name, $message); - - // $message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'], $message); - // $message = str_replace("{{POLICY_START_DATE}}", change_date_format($lead_data['policy_start_date'], 'Y-m-d', 'd-m-Y'), $message); - // $message = str_replace("{{DURATION}}", calculate_days_bw_dates($lead_data['policy_end_date'] ?? "", $lead_data['policy_start_date'] ?? "")->days, $message) ?? '--'; - - // dd($message); - // // return $this->respond(['status' => true, 'code' => 200, 'data' => $message], 200); - // return $message; - - // }else{ - - // // return $this->respond(['status' => false, 'code' => 404, 'message' => "This lead has not data"], 200); - // return ''; - // } - - - - // } - public function transformMailContent($lead_data, $mail_content, $page_name) { $current_year = date('Y'); @@ -2365,7 +2350,8 @@ class LeadsController extends BaseController } } - function getLastFiveFinancialYears() { + function getLastFiveFinancialYears() + { $currentYear = date('Y'); $currentMonth = date('m'); @@ -2385,11 +2371,610 @@ class LeadsController extends BaseController return $financialYears; } - public function rfqNonEB(){ + // ------------RFQ NON EB----------------------------------------------------------------------------------------- + + public function rfqNonEB() + { $this->loadLayout('view_rfq_non_eb'); } + + // public function getLeadNonEB($type, $id = null) + // { + // // Set basic data + // $data['issuer'] = $this->issuer; + // $data['client_type'] = $this->clientType; + // $data['lead_type'] = $this->leadType; + // $data['lead_status'] = $this->leadsStatus; + + // // Fetch policy types and entity data + // $data['policy_type'] = $this->policyTypeModel->where('is_active', 1)->findAll(); + // $data['entity'] = $this->kycEntityTypeModel->where('is_active', 1)->findAll(); + + // // Fetch insurer and TPA branch data + // $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); + // $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); + // // print_r($data['tpa']);die(); + // // Fetch sales team members who are active in team 5 + // $data['salse_team'] = $this->userModel + // ->select('user_profiles.*') + // ->join('user_teams', 'user_profiles.id = user_teams.user_id') + // ->where('user_teams.team_id', 5) + // ->where('user_teams.is_active', 1) + // ->where('user_profiles.is_active', 1) + // ->findAll(); + + // // dd($data); + // $data['lastFiveYears'] = $this->getLastFiveFinancialYears(); + // $data['gpaClaimType'] = $this->claim_type_for_gpa; + // $data['causeOfDeath'] = $this->cause_of_death; + // $data['selected_lead_type'] = $type; + + // if(!empty($id)){ + + // $data['lead_edit_data'] = $this->leadsModel->where('id', $id)->first(); + + // if (!empty($data['lead_edit_data'])) { + // $data['lead_edit_data']['policy_start_date'] = !empty($data['lead_edit_data']['policy_start_date']) + // ? change_date_format($data['lead_edit_data']['policy_start_date'], 'Y-m-d', 'd/m/Y') + // : null; + + // $data['lead_edit_data']['policy_end_date'] = !empty($data['lead_edit_data']['policy_end_date']) + // ? change_date_format($data['lead_edit_data']['policy_end_date'], 'Y-m-d', 'd/m/Y') + // : null; + + // $data['lead_edit_data']['incurred_claims_date'] = !empty($data['lead_edit_data']['incurred_claims_date']) + // ? change_date_format($data['lead_edit_data']['incurred_claims_date'], 'Y-m-d', 'd/m/Y') + // : null; + + // $data['lead_edit_data']['premium_date'] = !empty($data['lead_edit_data']['premium_date']) + // ? change_date_format($data['lead_edit_data']['premium_date'], 'Y-m-d', 'd/m/Y') + // : null; + // } else { + // $data['lead_edit_data'] = []; + // } + + // if (!empty($data['lead_edit_data']['fin_years_claims'])) { + // $decoded = json_decode($data['lead_edit_data']['fin_years_claims'], true); + // $data['lead_edit_data']['fin_years_claims_array'] = isset($decoded['finyear']) ? $decoded['finyear'] : []; + // } else { + // $data['lead_edit_data']['fin_years_claims_array'] = []; + // } + + // $data['lead_edit_data']['html'] = $this->generateViewPageHtml($data['lead_edit_data']['policy_type_id'], $data) ?? ""; + // } + + // // dd($data); + + // return $this->loadLayout('leads_form_handler', $data); + // } + + public function getLeadNonEB($type, $id = null) + { + // Set basic data + $data = [ + 'issuer' => $this->issuer, + 'client_type' => $this->clientType, + 'lead_type' => $this->leadType, + 'lead_status' => $this->leadsStatus, + 'policy_type' => $this->policyTypeModel->where('is_active', 1)->findAll(), + 'entity' => $this->kycEntityTypeModel->where('is_active', 1)->findAll(), + 'insurer' => $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(), + 'tpa' => $this->tpaBranchModel->getTpaBranchesWithTpaNames(), + 'lastFiveYears' => $this->getLastFiveFinancialYears(), + 'gpaClaimType' => $this->claim_type_for_gpa, + 'causeOfDeath' => $this->cause_of_death, + 'selected_lead_type' => $type, + ]; + + // Fetch sales team members who are active in team 5 + $data['salse_team'] = $this->userModel + ->select('user_profiles.*') + ->join('user_teams', 'user_profiles.id = user_teams.user_id') + ->where('user_teams.team_id', 5) + ->where('user_teams.is_active', 1) + ->where('user_profiles.is_active', 1) + ->findAll(); + + if (!empty($id)) { + $data['lead_edit_data'] = $this->leadsModel->where('id', $id)->first() ?? []; + + // Decode and merge custom fields if present + $custom_fields_data = !empty($data['lead_edit_data']['custom_fields']) + ? json_decode($data['lead_edit_data']['custom_fields'], true) + : []; + + if (!empty($custom_fields_data) && is_array($custom_fields_data)) { + $data['lead_edit_data'] = array_merge($data['lead_edit_data'], $custom_fields_data); + } + + if (!empty($data['lead_edit_data'])) { + foreach (['policy_start_date', 'policy_end_date', 'incurred_claims_date', 'premium_date'] as $dateField) { + $data['lead_edit_data'][$dateField] = !empty($data['lead_edit_data'][$dateField]) + ? change_date_format($data['lead_edit_data'][$dateField], 'Y-m-d', 'd/m/Y') + : null; + } + + $data['lead_edit_data']['fin_years_claims_array'] = !empty($data['lead_edit_data']['fin_years_claims']) + ? json_decode($data['lead_edit_data']['fin_years_claims'], true)['finyear'] ?? [] + : []; + + $data['lead_edit_data']['html'] = $this->generateViewPageHtml( + $data['lead_edit_data']['policy_type_id'] ?? null, + $data + ) ?? ""; + + } + } + + // dd($data); + + return $this->loadLayout('leads_form_handler', $data); + } + - - + public function getPolicyTypeFields() + { + + $policy_type_id = $this->request->getGET('policy_type_id'); + + $html = $this->generateViewPageHtml($policy_type_id) ?? ""; + + if(!empty($html)){ + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Policy Type FIELDS are found', 'data' => $html], 200); + }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', + 50 => 'rfq/office' + ]; + + return isset($viewMap[$policy_type_id]) ? view($viewMap[$policy_type_id], $data) : ""; + } + + // public function generateViewPageHtml($policy_type_id, $data = []) + // { + // $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); + // $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); + + // $html = ""; + // if(in_array($policy_type_id, [1,6,7])){ + // $html = view('rfq/gpa', $data); + // }else if(in_array($policy_type_id, [2,3,4,5])) { + // $html = view('rfq/gmc', $data); + // }else if($policy_type_id == 22) { + // $html = view('rfq/car'); + // }else if($policy_type_id == 23) { + // $html = view('rfq/cpm'); + // }else if($policy_type_id == 24) { + // $html = view('rfq/cyber_crime'); + // }else if($policy_type_id == 25) { + // $html = view('rfq/do'); + // }else if($policy_type_id == 27) { + // $html = view('rfq/eo'); + // }else if($policy_type_id == 49) { + // $html = view('rfq/money'); + // }else if($policy_type_id == 19) { + // $html = view('rfq/cgl'); + // }else if($policy_type_id == 59) { + // $html = view('rfq/sfsp'); + // }else if($policy_type_id == 63) { + // $html = view('rfq/wc'); + // }else if($policy_type_id == 15) { + // $html = view('rfq/blu'); + // }else if($policy_type_id == 16) { + // $html = view('rfq/bsu'); + // }else if(in_array($policy_type_id, [44,45,46,47])) { + // $html = view('rfq/marine'); + // } + + // return $html; + // } + + // ---------------------------------------------------------------------------------------------------------- + + //Construct excel file and save the file to the folder and return file path + public function constructNonEbExcelToSaveTemp($lead_id, $type, $propsal_and_insurer = null) + { + $rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type); + + $lead_data = json_decode($rfq_data['custom_fields'], true); + $lead_data = array_merge(['Insured' => $rfq_data['client_name']], $lead_data); + + // dd($lead_data); + // dd($rfq_data, $lead_id, $type, $propsal_and_insurer); + // print_r($propsal_and_insurer); die; + + // $data = json_decode($rfq_data['json'], true); + // $proposalData = end($data); + // array_pop($data); + + // foreach ($data as $key => $value) { + // Kint::dump($value); + // } + + // dd($data); + + + // if ($type == 2) { + // $data = $this->convertJsonForQCR($data, $type); + // if ($propsal_and_insurer !== null) { + // list($proposal_key, $insurer_key) = explode('-', $propsal_and_insurer, 2); + // $data = $this->transformProposelData($data, $proposal_key, $insurer_key); + // } + // } else if ($type == 1) { + // $data = $this->convertJsonForQCR($data, $type); + // // dd($data); + // } + + // dd($data); + + + $spreadsheet = new Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + + // Start with lead_data at the top + $rowNumber = 1; + + $title = "Nhance India Insurance Broking Pvt Ltd"; + $mergeRange1 = "A{$rowNumber}:B{$rowNumber}"; + $sheet->mergeCells($mergeRange1); + $sheet->setCellValue("A{$rowNumber}", $title); + $sheet->getStyle("A{$rowNumber}")->applyFromArray([ + 'font' => [ + 'bold' => true, + 'size' => 20 + ], + 'alignment' => [ + 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, + ], + ]); + + // Calculate title width + $maxWidthA = mb_strlen($title); + + // Set column width to fit the image properly + $sheet->getColumnDimension('C')->setWidth(20); // Adjust as needed + $sheet->getRowDimension($rowNumber)->setRowHeight(40); // Adjust as needed + + $drawing = new Drawing(); + $path = ROOTPATH . "public/assets/images/Nhance-Logo-Final.png"; // Use FCPATH for server path + $drawing->setPath($path); + $drawing->setCoordinates("C{$rowNumber}"); // Set position in column C + $drawing->setHeight(35); // Adjust image height + + // Center align the image in the cell + $drawing->setOffsetX(30); // Adjust horizontal offset + $drawing->setOffsetY(5); // Adjust vertical offset + $drawing->setWorksheet($sheet); + + // Apply center alignment to the cell + $sheet->getStyle("C{$rowNumber}")->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); + $sheet->getStyle("C{$rowNumber}")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); + + $rowNumber++; + + // Initialize max width tracking variables + $maxWidthB = 0; + + foreach ($lead_data as $key => $value) { + $formattedKey = ucwords(str_replace('_', ' ', $key)); + + // Merge A:B for key + $mergeRangeKey = "A{$rowNumber}:B{$rowNumber}"; + $sheet->mergeCells($mergeRangeKey); + + // Set values in merged cells + $sheet->setCellValue("A{$rowNumber}", $formattedKey); + $sheet->setCellValue("C{$rowNumber}", $value); + + // Apply styles for alignment and bold text in A:B + $sheet->getStyle($mergeRangeKey)->applyFromArray([ + 'font' => ['bold' => true], + 'alignment' => [ + 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, + ], + ]); + + // Apply bold style to C column if the key is "Insured" + if ($key === "Insured") { + $sheet->getStyle("C{$rowNumber}")->applyFromArray([ + 'font' => ['bold' => true], + ]); + } + + // Track max width needed for columns + $maxWidthA = max($maxWidthA, mb_strlen($formattedKey)); // Consider title and keys + $maxWidthB = max($maxWidthB, mb_strlen((string) $value)); + + $rowNumber++; + } + + // Set column width based on max content length (adjusted for padding) + $sheet->getColumnDimension('A')->setWidth($maxWidthA * 1.2); + $sheet->getColumnDimension('B')->setWidth($maxWidthA * 1.2); + $sheet->getColumnDimension('C')->setWidth($maxWidthB * 1.2); + $sheet->getColumnDimension('D')->setWidth($maxWidthB * 1.2); + + + // // $rowNumber += 2; + + // // Add headers and subheaders + // $headers = $data['table_data']['headers']; + + // $sheet->setCellValue("A{$rowNumber}", "Details of Coverage"); + // $sheet->getStyle("A{$rowNumber}")->applyFromArray([ + // 'font' => [ + // 'bold' => true, + // ], + // 'fill' => [ + // 'fillType' => Fill::FILL_SOLID, + // 'startColor' => ['rgb' => 'ADD8E6'], + // ], + // 'borders' => [ + // 'allBorders' => [ + // 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + // 'color' => ['argb' => 'FF000000'], // Black color + // ], + // ], + // ]); + // $subheader_count = array_sum(array_map(fn($header) => count($header['subHeaders']), $data['table_data']['headers'])); + // $subheader_count = $subheader_count - 2; + // $headerCount = count($data['table_data']['headers']); + // $lastColumn = Coordinate::stringFromColumnIndex($subheader_count); + // // dd( $headerCount, $lastColumn); + + // // Merge cells from A to the last column + // $mergeRange = "A{$rowNumber}:{$lastColumn}{$rowNumber}"; + + // $sheet->getStyle($mergeRange)->applyFromArray([ + // 'borders' => [ + // 'allBorders' => [ + // 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + // 'color' => ['argb' => 'FF000000'], // Black color + // ], + // ], + // ]); + + // $sheet->mergeCells($mergeRange); + // $rowNumber = $rowNumber + 1; + + // $subHeaderRow = $rowNumber + 1; + // $columnLetter = 'A'; + + // foreach ($headers as $header) { + + // if (in_array($header['parentHeader'], ['Item Key', 'Action'])) { + // continue; + // } + + // if ($header['parentHeader'] === 'Sno') { + // $header['parentHeader'] = 'S.No.'; + // $sheet->getColumnDimension('A')->setWidth(10); + // } + + // if ($header['parentHeader'] === 'Particulars') { + // $sheet->getColumnDimension('B')->setWidth(40); + // } + + // $startColumn = $columnLetter; // Start of the current header range + // $subHeaderCount = count($header['subHeaders']); // Number of subheaders for this parent header + + // // Set parent header value + // $sheet->setCellValue("{$startColumn}{$rowNumber}", $header['parentHeader']); + // $sheet->getStyle("{$startColumn}{$rowNumber}")->applyFromArray([ + // 'font' => ['bold' => true], + // 'alignment' => [ + // 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + // 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, + // ], + // ]); + + // // Merge header cells if it spans multiple subheaders + // if ($subHeaderCount > 1) { + // $endColumn = chr(ord($startColumn) + $subHeaderCount - 1); // Calculate the end column + // $sheet->mergeCells("{$startColumn}{$rowNumber}:{$endColumn}{$rowNumber}"); + // } else { + // $endColumn = $startColumn; // No merge needed if only one subheader + // } + + // // Add subheaders + // foreach ($header['subHeaders'] as $subHeader) { + // $sheet->setCellValue("{$columnLetter}{$subHeaderRow}", $subHeader); + + // if ($columnLetter != "A" && $columnLetter != "B" && $columnLetter != "C" && $columnLetter != "D") { + // $sheet->getColumnDimension($columnLetter)->setWidth(35); + // } else { + // $sheet->getColumnDimension('A')->setWidth(10); + // } + + // $sheet->getStyle("{$columnLetter}{$subHeaderRow}")->applyFromArray([ + // 'font' => ['bold' => true], + // 'alignment' => [ + // 'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER, + // 'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER, + // ], + // ]); + // $columnLetter++; // Move to the next column for subheaders + // } + // } + + // // Apply border to the header range + // $headerRange = "A{$rowNumber}:" . chr(ord($columnLetter) - 1) . "{$subHeaderRow}"; + // $sheet->getStyle($headerRange)->applyFromArray([ + // 'borders' => [ + // 'allBorders' => [ + // 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + // 'color' => ['argb' => 'FF000000'], // Black color + // ], + // ], + // ]); + + // // Increase row height for headers and subheaders + // $sheet->getRowDimension($rowNumber)->setRowHeight(25); // Header row height + // $sheet->getRowDimension($subHeaderRow)->setRowHeight(20); // Subheader row height + + // $rowNumber = $subHeaderRow + 2; + // $column_data = $data['table_data']['data']; + // $serial_no = 1; + // $maxColumnWidths = []; + + // // Add table data rows + // foreach ($column_data as $dataRow) { + // $columnLetter = 'A'; + // foreach ($dataRow['data'] as $cellData) { + // if (in_array($cellData['parentth'], ['Item Key', 'Action'])) { + // continue; + // } + + // if ($cellData['parentth'] == 'Sno') { + // $sheet->setCellValue("{$columnLetter}{$rowNumber}", $serial_no); + // } else { + // $sheet->setCellValue("{$columnLetter}{$rowNumber}", $cellData['value']); + // } + + // $columnLetter++; + // } + // $rowNumber++; + // $serial_no++; + // } + + // $dataRange = "A" . ($subHeaderRow + 1) . ":" . chr(ord($columnLetter) - 1) . ($rowNumber - 1); + // $sheet->getStyle($dataRange)->applyFromArray([ + // 'borders' => [ + // 'allBorders' => [ + // 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + // 'color' => ['argb' => 'FF000000'], // Black color + // ], + // ], + // ]); + + + // if ($type == 2) { + + // $rowNumber += 2; + + // // Add premium data + // // dd($data); + // $labelArray = ["Premium", "GST (%)", "GST Amount (₹)", "Total"]; + // $premiumData = $data['premium_data']['data']; + // $premium = [$labelArray[0]]; + // $gst = [$labelArray[1]]; + // $gstAmt = [$labelArray[2]]; + // $total = [$labelArray[3]]; + + // foreach ($premiumData as $proposal => $insurers) { + // if ($proposal != 'Particulars') { + // foreach ($insurers as $insurer => $values) { + // $premium[] = $values[$labelArray[0]]; + // $gst[] = $values[$labelArray[1]]; + // $gstAmt[] = $values[$labelArray[2]]; + // $total[] = $values[$labelArray[3]]; + // } + // } + // } + + // foreach ([$premium, $gst, $gstAmt, $total] as $index => $rowData) { + // $columnLetter = 'B'; + // foreach ($rowData as $key => $value) { + // $sheet->setCellValue("{$columnLetter}{$rowNumber}", $value); + // if ($key === 0) { + // $sheet->getStyle("{$columnLetter}{$rowNumber}")->applyFromArray(['font' => ['bold' => true,],]); + // } + // $columnLetter++; + // } + // $rowNumber++; + // } + + // $premiumRange = "B" . ($rowNumber - 4) . ":" . chr(ord($columnLetter) - 2) . ($rowNumber - 1); + // // dd($premiumRange); + // $sheet->getStyle($premiumRange)->applyFromArray([ + // 'borders' => [ + // 'allBorders' => [ + // 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + // 'color' => ['argb' => 'FF000000'], // Black color + // ], + // ], + // ]); + // } + + // // Auto-size columns + // // foreach ($sheet->getColumnIterator() as $column) { + // // $sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true); + // // } + + // $dataRange = $sheet->calculateWorksheetDimension(); + + // $sheet->getStyle($dataRange)->getAlignment() + // ->setHorizontal(Alignment::HORIZONTAL_CENTER) + // ->setVertical(Alignment::VERTICAL_CENTER) + // ->setWrapText(true); + + // $sheet->getStyle('A1')->applyFromArray([ + // 'alignment' => [ + // 'wrapText' => false, // Disables text wrapping for A1 + // ], + // ]); + + // // Apply border to the entire sheet + // preg_match('/([A-Z]+)(\d+):([A-Z]+)(\d+)/', $dataRange, $matches); + + // if ($matches) { + // $startColumn = $matches[1]; // A + // $startRow = $matches[2]; // 1 + // $endColumn = $matches[3]; // G + // $endRow = $matches[4]; // 75 + + // // Convert column letter to index, reduce by 1, and convert back + // $endColumnIndex = Coordinate::columnIndexFromString($endColumn) - 1; + // $newEndColumn = Coordinate::stringFromColumnIndex($endColumnIndex); + + // // Generate the new range (e.g., "A1:F75" instead of "A1:G75") + // $newDataRange = "{$startColumn}{$startRow}:{$newEndColumn}{$endRow}"; + // // $sheet->getStyle($newDataRange)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN); + // } + + // $lastRow = count($lead_data) + 1; + // $leadRange = "A1:D{$lastRow}"; + + // $sheet->getStyle($leadRange)->applyFromArray([ + // 'borders' => [ + // 'allBorders' => [ + // 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, + // 'color' => ['argb' => 'FF000000'], // Black color + // ], + // ], + // ]); + + // Set filename + $string = ($type == 2) ? 'QCR' : 'RFQ'; + $filename = "{$string}_{$rfq_data['client_short_name']}_{$rfq_data['policy_type']}_" . date('YmdHis') . '.xlsx'; + + // Save to temporary location + $uploadFilePath = WRITEPATH . 'tmp/' . $filename; + $writer = new Xlsx($spreadsheet); + $writer->save($uploadFilePath); + + return [ + 'filePath' => $uploadFilePath, + 'fileName' => $filename, + ]; + } } diff --git a/app/Models/LeadsModel.php b/app/Models/LeadsModel.php index bc47a3ff..84e9c9bf 100644 --- a/app/Models/LeadsModel.php +++ b/app/Models/LeadsModel.php @@ -84,6 +84,9 @@ class LeadsModel extends Model 'total_si_at_incept', 'total_si_at_renewal', 'fin_years_claims', + + 'lead_form_type', + 'custom_fields', ]; diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index 4321896f..003e8d96 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -11,9 +11,7 @@ background-color: #f0f0f0; color: #666; } - - -