diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d1195ea6..f7426af0 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -360,6 +360,7 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) { $routes->get("sendMail", "LeadsController::sendMailWithAttachement"); $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); $routes->get("featchLeadDataAndInsertClient/(:any)", "LeadsController::featchLeadDataAndInsertClient/$1"); + $routes->get("featchClientPolicyFromLead/(:any)", "LeadsController::featchClientPolicyFromLead/$1"); }); $routes->group("rfq", ["filter" => "authMVC"], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e90f1e1b..1e169b88 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -287,7 +287,7 @@ class ClientController extends AdminController $headerData['page_name'] = 'Client List'; $data['clientList'] = $this->clientModel->getCreatedByUserName(); $data['client_rm'] = $this->clientRMModel->getAllClientRM(); - // $data['lead_data'] = $this->leadsModel->getLeadForInsertClientList(); + $data['lead_data'] = $this->leadsModel->getLeadForInsertClientList(); // dd($data); @@ -553,6 +553,7 @@ class ClientController extends AdminController $editData['client_branch'] = $this->clientBranchModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); $editData['client_relation'] = $this->clientRMModel->where(['client_id' => $id, 'is_active' => 1])->findAll(); $editData['client_branch']['role'] = get_role_id(); + $editData['lead_data'] = $this->leadsModel->getLeadForInsertClientList(2, $id); $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($id); foreach ($clientPoliceData as $key => $value) { diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index b79bde7d..af508898 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -1900,6 +1900,8 @@ class EmployeeController extends AdminController if (is_dir($logPath)) { $files = array_diff(scandir($logPath), ['.', '..']); // Exclude '.' and '..' + $files = array_reverse($files); + foreach ($files as $file) { if (is_file($logPath . $file)) { $logs[] = $file; // Add log files to the list @@ -1907,8 +1909,11 @@ class EmployeeController extends AdminController } } + $data['logs'] = $logs; + $data['server_details'] = get_server_details(); + // Pass log files to the view - return view('log_view', ['logs' => $logs]); + return $this->loadLayout('log_view', $data); } public function downloadLog($fileName) @@ -1931,7 +1936,11 @@ class EmployeeController extends AdminController if (file_exists($logPath)) { $content = file_get_contents($logPath); - return view('log_content_view', ['fileName' => $fileName, 'content' => $content]); + $data['fileName'] = $fileName; + $data['content'] = $content; + $data['server_details'] = get_server_details(); + + return $this->loadLayout('log_content_view', $data); } return redirect()->back()->with('error', 'Log file not found.'); diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 91c08094..d25b93a9 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -390,7 +390,7 @@ class LeadsController extends BaseController $result = $this->RFQModel->insert($data); if ($result) { - return $this->respond(['status' => true, 'id' => $result, 'message' => 'New RFQ created successfully', 'data' =>$data], 200); + return $this->respond(['status' => true, 'id' => $result, 'message' => 'RFQ created successfully', 'data' =>$data], 200); } return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create RFQ", 'data' =>$data], 200); @@ -413,7 +413,7 @@ class LeadsController extends BaseController $result = $this->RFQModel->insert($data); if ($result) { - return $this->respond(['status' => true, 'id' => $result, 'message' => 'New QCR created successfully', 'data' =>$data], 200); + return $this->respond(['status' => true, 'id' => $result, 'message' => 'QCR created successfully', 'data' =>$data], 200); } return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create QCR", 'data' =>$data], 200); @@ -456,9 +456,11 @@ class LeadsController extends BaseController //Construct excel file and save the file to the folder and return file path public function constructExcelToSaveTemp($lead_id, $type, $propsal_and_insurer = null) - { + { $rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type); + // dd($rfq_data, $lead_id, $type); + $lead_data = [ 'Insured' => $rfq_data['client_name'], 'Insurer' => $rfq_data['insurer_name'] . ' - ' . $rfq_data['insurer_branch_name'], @@ -769,9 +771,9 @@ class LeadsController extends BaseController $message = str_replace("{{CLIENT_NAME}}", $lead_data['client_name'], $message); $message = str_replace("{{POLICY_LONG_NAME}}", $lead_data['long_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); + $message = str_replace("{{DURATION}}", calculate_days_bw_dates($lead_data['policy_end_date'] ?? "", $lead_data['policy_start_date'] ?? "")->days, $message) ?? '--'; - // print_rr($message); + // print_rr($message);calculate_days_bw_dates $res = MailHelper::send_email(['mail' => $recipient['email'], 'cc'=> $cc_mails, 'subject' => $subject, 'message' => $message, 'attachments' => $attachments, 'reply_to' => $reply_to]); // !dd($res); @@ -789,8 +791,12 @@ class LeadsController extends BaseController 'insurer' => $params['insurer_and_branch'], ] ; - $lead_update_data = json_encode($lead_update_data); - $this->leadsModel->where('id', $lead_id)->set('proposel_data', $lead_update_data)->update(); + $data = [ + 'proposel_data' => json_encode($lead_update_data), + 'status' => 'won' + ]; + + $this->leadsModel->where('id', $lead_id)->set($data)->update(); } //delete attachment file @@ -1035,7 +1041,9 @@ class LeadsController extends BaseController $result = $this->createClientWithLeadData($data); if ($result) { - return $this->respond(['status' => true, 'message' => 'New Client created successfully', 'client_id' => $result, 'data' => $data], 200); + + $policy_data = $this->clientPolicyModel->where('client_id', $result)->where('is_active', 1)->first(); + return $this->respond(['status' => true, 'message' => 'New Client created successfully', 'client_id' => $result, 'data' => $data, 'client_policy_id' => $policy_data['id']], 200); } return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200); @@ -1081,7 +1089,6 @@ class LeadsController extends BaseController return $branch_id; } - private function prepareClientBranchData($data, $client_id) { $default_unit = trim(($data['client_short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-'); @@ -1113,20 +1120,26 @@ class LeadsController extends BaseController } private function prepareClientPolicyData($data, $client_id, $branch_id) - { + { + $proposel_data = json_decode($data['proposel_data'], true); + // print_r($proposel_data); die; + list($insurer_branch_id, $insurer_id) = explode('-', $proposel_data['insurer'], 2); + $client_policy_data = [ 'client_id' => $client_id, 'client_branch_id' => $branch_id, 'policy_type_id' => $data['policy_type_id'], - 'insurer_id' => $data['insurer_id'], - 'insurer_branch_id' => $data['insurer_branch_id'], + 'insurer_id' => $insurer_id, + 'insurer_branch_id' => $insurer_branch_id, 'tpa_id' => $data['tpa_id'], 'tpa_branch_id' => $data['tpa_branch_id'], 'policy_start_date' => $data['policy_start_date'], 'policy_end_date' => $data['policy_end_date'], 'policy_status' => 1, ]; - + + $terms = $this->preparePolicyTermsFromRFQ($data); + $policy_type_id = $data['policy_type_id']; if (in_array($policy_type_id, [1, 2, 6, 7])) { $client_policy_data['is_addon'] = 1; // Base Policy @@ -1139,15 +1152,146 @@ class LeadsController extends BaseController $data['is_addon'] = 1; // } } + + $client_policy_data['policy_terms'] = $this->preparePolicyTermsFromRFQ($data); + + // print_r($client_policy_data); die; return $client_policy_data; } private function preparePolicyTermsFromRFQ($data) - { + { + $proposel_data = json_decode($data['proposel_data'], true); + $QCRData = $this->RFQModel->where('is_active', 1)->where('type', 2)->where('lead_id', $data['id'])->first(); + + $JSON = json_decode($QCRData['json'], true); + + $converted_json = $this->transformProposelData($JSON, $proposel_data['proposel_name'], $proposel_data['insurer_name']); + + return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']); } + private function convertQCRJsonToPolicyTerms($data, $policy_type, $proposel_name, $insurer_name) + { + $GMC_Keys = [ + "sum_insured", "family_floater", "family_floaters", "age_ratio", "waiverofpreexistingdiseases", + "maternitycoverage", "twindelivery", "preandpostnatal", "babyday1cover", "9monthwaitingperiodwaived", + "coverfromthedateofjoining", "waiverof1,2,3&4thyearexclusions", "waiverof30dayswaitingperiod", + "prehospitalizationcover", "congenitaldiseasesinternal", "copayzonewisecopay", + "bioabsorbablestenttoriclensmultifocallens", "roomrentlimit", "proportionatedeductionclause", + "ailmentcapping", "ambulancecharges", "airambulance", "familytransportationbenefit", + "reasonableandcustomarycharges", "ayudhtreatmentcover", "congenitaldiseasesexternal", + "optionalparentalcopay", "posthospitalizationcover", "corporatebuffer", "sublimitofcorporatebuffer", + "ayushTreatmentCoverData", "armdcovered", "suminsuredenhancement", "automaticsuminsuredreinstatement", + "additionalsicknessbenefit", "lasiksurgery", "midterminclusion", "capd", "organdonorexpenses", + "moderntreatmentsasperirdai", "Wellness", "days_of_discharge", "days_from_dod", + "special_condition_label", "special_condition_input", "multiple_sum_insured", + "cataract", "cataractData" + ]; + + $GPA_Keys = [ + "sumInsured2", "totalSumInsured", "age_ratio", "accidentalDeathBenefit", "permanentTotalDisablement", + "permanentPartialDisablement", "temporaryTotalDisablementBenefit", "accidentalHospitalizationExpenses", + "childrenEducationWelfareFund", "compassionateVisitExpenses", "compassionateVisitExpensesData", + "brokenBoneExpenses", "brokenBoneExpensesData", "ambulanceCharges", "ambulanceChargesData", + "burnExpenses", "burnExpensesData", "carriageOfDeadBody", "carriageOfDeadBodyData", + "animalSnakeInsectBite", "terrorism", "worldwideCover", "gpa_special_condition_label", + "gpa_special_condition_input", "multiple_sum_insured" + ]; + + // Select keys based on policy type + $termsKey = $policy_type == 1 ? $GPA_Keys : $GMC_Keys; + + // Initialize terms_array with default empty values + $terms_array = array_fill_keys($termsKey, ""); + $specialKeys = ['special_condition_label', 'special_condition_input', 'gpa_special_condition_label', 'gpa_special_condition_input', 'multiple_sum_insured']; + foreach ($specialKeys as $key) { + $terms_array[$key] = []; + } + // Initialize age_ratio based on policy type + $terms_array['age_ratio'] = $policy_type == 2 ? [ + "self" => ["min" => "18", "max" => "60"], + "spouse" => ["min" => 0, "max" => 0], + "child" => ["min" => 0, "max" => "25"], + "elders" => ["min" => 0, "max" => 0], + ] : ["self" => ["min" => "18", "max" => "60"]]; + + foreach ($data['table_data']['data'] as $dataRow) { -} + $item = $dataRow['items'] ?? ''; + + foreach ($dataRow['data'] as $cellData) { + $parentth = $cellData['parentth'] ?? ''; + $subth = $cellData['subth'] ?? ''; + $input_value = $cellData['input_value'] ?? ''; + $value = $cellData['value'] ?? ''; + + // Skip unwanted keys + if (in_array($parentth, ['Sno', 'Item Key', 'Particulars', 'Action']) || + in_array($subth, ['Quote Asked'])) { + continue; + } + + // Handle special conditions + if (str_starts_with($item, "special_condition") && $parentth === $proposel_name && $subth === $insurer_name) { + + $parts = explode("-", $input_value); + $question = $parts[0] ?? ''; + $answer = $parts[1] ?? ''; + $labelKey = $policy_type == 1 ? 'gpa_special_condition_label' : 'special_condition_label'; + $inputKey = $policy_type == 1 ? 'gpa_special_condition_input' : 'special_condition_input'; + + $terms_array[$labelKey][] = $question; + $terms_array[$inputKey][] = $answer; + continue; + } + + // Handle sum insured + if (in_array($item, ['sum_insured', 'sumInsured2'])) { + $si_amt = explode(",", $value); + $terms_array[$item] = $si_amt[0] ?? ""; + $terms_array['multiple_sum_insured'] = array_slice($si_amt, 1); + continue; + } + + // Handle family floaters + if ($item === 'family_composition') { + $terms_array['family_floaters'] = isJsonString($input_value) ? json_decode($input_value, true) : $input_value; + continue; + } + + // Decode JSON if valid + $terms_array[$item] = isJsonString($input_value) ? + (json_decode($input_value, true)['key'] ?? '') : + $input_value; + } + } + + return json_encode($terms_array); + } + + public function featchClientPolicyFromLead($client_id, $branch_id, $lead_id) + { + $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); + + if (!$data) { + return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200); + } + + $result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); + // print_r($result); die; + + if ($result) { + + $policy_data = $this->clientPolicyModel->where('id', $result)->where('is_active', 1)->first(); + return $this->respond(['status' => true, 'message' => 'New Policy created successfully', 'client_policy_id' => $result, 'data' => $data, 'client_id' => $policy_data['client_id']], 200); + } + + return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200); + + } + +} \ No newline at end of file diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index f42e3c32..fe345717 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -474,4 +474,30 @@ if (!function_exists('print_rr')) { print_r($data); echo ""; } -} \ No newline at end of file +} + +if (!function_exists('get_server_details')) { + /** + * Get the hostname and server name. + * + * @return array + */ + function get_server_details(): array + { + $hostname = gethostname(); // Get the hostname of the server + $serverName = $_SERVER['SERVER_NAME'] ?? 'Unknown'; // Get the server name + + return [ + 'hostname' => $hostname, + 'server_name' => $serverName, + ]; + } +} +if (!function_exists('isJsonString')) { + + function isJsonString($input) + { + json_decode($input); // Decode the string + return (json_last_error() === JSON_ERROR_NONE); // Check if the last JSON error is "no error" + } +} diff --git a/app/Models/LeadsModel.php b/app/Models/LeadsModel.php index 7b7cc54a..594a4c65 100644 --- a/app/Models/LeadsModel.php +++ b/app/Models/LeadsModel.php @@ -120,12 +120,25 @@ class LeadsModel extends Model } - public function getLeadForInsertClientList() + public function getLeadForInsertClientList($type = null, $client_id = null) { - return $this + $query = $this->db->table('leads') + ->select('leads.*, user_profiles.first_name as user_name') + ->join('user_profiles', 'leads.created_by = user_profiles.id') ->where('leads.is_active', 1) ->where('leads.status', 'won') - ->findAll(); + ->where("leads.proposel_data IS NOT NULL AND leads.proposel_data <> ''"); + + if ($type) { + $query->where('leads.lead_type', $type); + } + if ($client_id) { + $query->where('leads.client_id', $client_id); + } + + $result = $query->get()->getResultArray(); + return $result; + } diff --git a/app/Models/RFQModel.php b/app/Models/RFQModel.php index fa00c3a9..d616e517 100644 --- a/app/Models/RFQModel.php +++ b/app/Models/RFQModel.php @@ -71,10 +71,10 @@ class RFQModel extends Model ') ->join('leads', 'rfq.lead_id = leads.id') ->join('policy_type', 'leads.policy_type_id = policy_type.id') - ->join('insurers', 'leads.insurer_id = insurers.id') - ->join('insurer_branch', 'leads.insurer_branch_id = insurer_branch.id') - ->join('tpa', 'leads.tpa_id = tpa.id') - ->join('tpa_branch', 'leads.tpa_branch_id = tpa_branch.id') + ->join('insurers', 'leads.insurer_id = insurers.id', 'left') + ->join('insurer_branch', 'leads.insurer_branch_id = insurer_branch.id', 'left') + ->join('tpa', 'leads.tpa_id = tpa.id', 'left') + ->join('tpa_branch', 'leads.tpa_branch_id = tpa_branch.id', 'left') ->where('rfq.lead_id', $lead_id) ->where('rfq.type', $type) ->where('rfq.is_active', 1) diff --git a/app/Views/client_list.php b/app/Views/client_list.php index e9499095..f5c2a547 100755 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -100,7 +100,7 @@ table.dataTable thead th { - + @@ -275,7 +275,7 @@ function featchClient(){ $('.loader-mask').delay(350).fadeOut('slow'); if(res.status == true){ - let client_url = ''+res.client_id; + let client_url = '' + res.client_id + '?client_policy_id=' + res.client_policy_id+'#police-tab'; toastr.success(res.message, 'SUCCESS') window.location.href = client_url }else{ @@ -294,4 +294,5 @@ function featchClient(){ } }); } + \ No newline at end of file diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index 6ced70eb..e1c807b0 100755 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -2,7 +2,8 @@
- + +
@@ -193,6 +194,36 @@ + + + \ No newline at end of file diff --git a/app/Views/leads_list.php b/app/Views/leads_list.php index edc17e10..6da050d1 100644 --- a/app/Views/leads_list.php +++ b/app/Views/leads_list.php @@ -74,7 +74,7 @@ table.dataTable tbody td { - 0) { ?> + $row){ ?> diff --git a/app/Views/log_content_view.php b/app/Views/log_content_view.php index 5a34b2cf..8ca04171 100644 --- a/app/Views/log_content_view.php +++ b/app/Views/log_content_view.php @@ -6,11 +6,26 @@ View Log: <?= esc($fileName) ?> -

Log File:

+
+
+

Log File:

+
+ +
-
-        
-    
+
+
+
+
+
     
+                        
+                    
+
+
+
+
Back to Logs diff --git a/app/Views/log_view.php b/app/Views/log_view.php index 00da3691..d7791d34 100644 --- a/app/Views/log_view.php +++ b/app/Views/log_view.php @@ -1,41 +1,49 @@ - - - - - - Log Files - - -

Log Files

- getFlashdata('error')): ?> -

getFlashdata('error') ?>

- +Log Files + + + +

Log Files

+ +getFlashdata('error')): ?> +

getFlashdata('error') ?>

+ + + + + + + + + + + + + $log): ?> - + + + - - -
S.No.Log FileActions
No log files found. + View | + Download +
- - + + + + No log files found. + + + + diff --git a/app/Views/policy_gmc_terms.php b/app/Views/policy_gmc_terms.php index 3872cccc..70a10fdd 100755 --- a/app/Views/policy_gmc_terms.php +++ b/app/Views/policy_gmc_terms.php @@ -1293,7 +1293,7 @@ var index = $('.modifyclassinput').length; var appendElement = `
diff --git a/app/Views/policy_gpa_terms.php b/app/Views/policy_gpa_terms.php index 469d99dc..7e81a9b0 100755 --- a/app/Views/policy_gpa_terms.php +++ b/app/Views/policy_gpa_terms.php @@ -705,7 +705,7 @@ var appendElement = `
diff --git a/app/Views/view_rfq.php b/app/Views/view_rfq.php index 122484c9..b173c674 100644 --- a/app/Views/view_rfq.php +++ b/app/Views/view_rfq.php @@ -496,6 +496,7 @@ var insurer_count = 0 var proposalDataForDropDown = {}; var policy_terms = {}; + var premium_data_check = false; $(document).ready(function() { @@ -545,8 +546,13 @@ if(data){ proposalDataForDropDown = data.proposal_data; + + if(!data.premium_data){ + premium_data_check = true; + } } + console.log('policy_terms', policy_terms); console.log('JSON DATA', data); console.log('suggestions data', suggestions); @@ -3220,6 +3226,8 @@ function constructInsurerNameWithVersion(proposal_name, insurerName) { function checkTheTableDataChanged(redirect_type, url){ + console.log('isFormDataModified', isFormDataModified); + if(isFormDataModified){ SweertAlert() }else{ @@ -3709,7 +3717,9 @@ function jsonToTable(json) { hideQCR() isFormDataModified = false; - populateTable(json) + if(RFQ_or_QCR == 2){ + populateTable(json) + } } function populateTable(json) { @@ -3803,6 +3813,10 @@ function populateTable(json) { // Append tbody to table table.appendChild(tbody); + + if(premium_data_check){ + isFormDataModified = true; + } } // function generateJSONFromTable() { @@ -4281,6 +4295,7 @@ function removeProposalForPremiumTable(secondRowIndex) { async function submitQCRData() { + console.log(over_all_column_data); let qcr_count = $('#qcr_count').val(); @@ -4294,6 +4309,7 @@ function removeProposalForPremiumTable(secondRowIndex) { console.log('QCR not found'); try { + $('.loader').fadeIn(); $('.loader-mask').fadeIn();