From b9320f22daaab0b42a87405c2aae7a7fb4182c4d Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 21 Jun 2024 15:38:49 +0530 Subject: [PATCH] FIX_RACK_RATE_ISSUES_AND_OTHER : RV --- app/Controllers/ClientController.php | 54 ++++-- app/Views/client_info.php | 5 +- app/Views/other_policy_terms.php | 189 +++++++++++++------ app/Views/policy_gmc_terms.php | 20 +- app/Views/policy_gpa_terms.php | 12 +- app/Views/policy_grid.php | 262 +++++++++++++++------------ 6 files changed, 335 insertions(+), 207 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 86556e52..0503143e 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1907,7 +1907,7 @@ class ClientController extends AdminController "sum_insured" => "Sum Insured", "family_floater" => "Family Floater", "family_floaters" => "Family Floaters", - "member_count" => "Elders Count:", + "elders_count" => "Elders Count:", "other_member_min_age" => "Min Age:", "other_member_max_age" => "Min Age:", "waiverofpreexistingdiseases" => "Waiver of Pre-existing Diseases", @@ -2067,19 +2067,27 @@ class ClientController extends AdminController } else if (array_key_exists($key, $mapping)) { $transformedData[$mapping[$key]] = $value; } else if ($key == 'special_condition_label') { - - foreach ($value as $key => $value) { - $transformedData[$value] = $data['special_condition_input'][$key]; + + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['special_condition_input'][$key]; + } } - } else if ($key == 'gpa_special_condition_label') { - foreach ($value as $key => $value) { - $transformedData[$value] = $data['gpa_special_condition_input'][$key]; + } else if ($key == 'gpa_special_condition_label') { + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['gpa_special_condition_input'][$key]; + } + } + } else if ($key == 'other_special_condition_label') { + if (is_array($value)) { + foreach ($value as $key => $value) { + $transformedData[$value] = $data['other_special_condition_label'][$key]; + } } } else if ($key == 'age_ratio') { - if (isset($data['sumInsured2'])) { - $transformedData['Self'] = "(Min: " . $data['age_ratio']['self']['min'] . ", Max: " . $data['age_ratio']['self']['max'] . ")"; } } else { @@ -2217,21 +2225,33 @@ class ClientController extends AdminController } - public function getPolicyTerms($client_policy_id){ + public function getPolicyTerms($client_policy_id) + { $policy_terms = $this->clientPolicyModel->where('id', $client_policy_id)->first(); - if(isset($policy_terms['policy_terms']) && $policy_terms['policy_terms'] != null){ + if (isset($policy_terms['policy_terms']) && $policy_terms['policy_terms'] != null) { $JSON = json_decode($policy_terms['policy_terms']); - $si = $JSON->sum_insured ?? $JSON->sumInsured2; - $multi_si = $JSON->multiple_sum_insured; - $multi_si[] = $si; - }else{ - $$multi_si = []; + + $si = null; + if (isset($JSON->sum_insured) && !empty($JSON->sum_insured)) { + $si = $JSON->sum_insured; + } elseif (isset($JSON->sumInsured2) && !empty($JSON->sumInsured2)) { + $si = $JSON->sumInsured2; + } + + if ($si !== null) { + $multi_si = $JSON->multiple_sum_insured ?? []; + $multi_si[] = $si; + } else { + $multi_si = []; + } + } else { + $multi_si = []; } - return $this->respond(['status' => true, 'data'=>$multi_si], 200); + return $this->respond(['status' => true, 'data' => $multi_si], 200); } diff --git a/app/Views/client_info.php b/app/Views/client_info.php index f029a2b0..bcad4293 100644 --- a/app/Views/client_info.php +++ b/app/Views/client_info.php @@ -270,18 +270,20 @@ $(document).ready(function() { $(document).on('click', '.policy_terms', function() { var terms = $(this).data('id'); console.log(terms); + console.log(JSON.stringify(terms)); // terms = JSON.parse(terms); $('#modal_body').empty(); function createListItems(obj) { + const fragment = document.createDocumentFragment(); for (const key in obj) { if (obj.hasOwnProperty(key) && obj[key] !== null && obj[key] !== '' && key != 'family_floater' && key != 'gpa_special_condition_input' && key != 'gpa_special_condition_label' && key != 'special_condition_label' && key != - 'special_condition_input' && key != 'age_ratio') { + 'special_condition_input' && key != 'age_ratio' && key != "multiple_sum_insured" && key != "other_special_condition_label" && key != "other_special_condition_input") { const listItem = document.createElement('li'); @@ -326,6 +328,7 @@ $(document).on('click', '.policy_terms', function() { } $('#modal_body').append(createListItems(terms)); + }); \ No newline at end of file diff --git a/app/Views/other_policy_terms.php b/app/Views/other_policy_terms.php index 6e1160c2..d21d40c4 100644 --- a/app/Views/other_policy_terms.php +++ b/app/Views/other_policy_terms.php @@ -78,7 +78,8 @@ label { x -
+
@@ -87,7 +88,7 @@ label { -
+

@@ -108,12 +109,10 @@ label { @@ -395,13 +422,14 @@ $(document).on('click', '#otherPolicyTermsClose', function() { }); -$("#sumInsured2").on("keyup", function() { +$("#sum_insured_others").on("keyup", function() { var inputNumber = $(this).val(); + console.log('sum_insured_others keyup', inputNumber) if (inputNumber) { var result = convertCommaNumberToWords(inputNumber); - $("#numberToWordSumInsured").text(result); + $("#numberToWordOthers").text(result); } else { - $("#numberToWordSumInsured").text(""); + $("#numberToWordOthers").text(""); } }); @@ -417,6 +445,20 @@ $("#totalSumInsured").on("keyup", function() { }); +function si_keup_num_to_word2(input) { + + console.log('keyup sum insured'); + var inputNumber = $(input).val(); + console.log(inputNumber) + if (inputNumber) { + var result = convertCommaNumberToWords(inputNumber); + + $("#numberToWordOthers").text(result); + } else { + $("#numberToWordOthers").text(""); + } +}; + function appendPolicyTermsHTML(policy_type) { @@ -429,6 +471,25 @@ function appendPolicyTermsHTML(policy_type) {
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+ +
+
@@ -523,11 +584,30 @@ function appendPolicyTermsHTML(policy_type) { ` } else if (policy_type == 6) { - + termsHTML = `
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+ +
+
@@ -592,28 +672,31 @@ function appendPolicyTermsHTML(policy_type) { } -function appendOtherTermsSIAddMore(data = null){ +function appendOtherSIAddMore(data = null) { - console.log('function called') + const addMoreContainer = document.getElementById('sum_insured_add_more'); - var html = ` -
-
- -
-
- -
-
- - -
-
-
-
-
`; + console.log(addMoreContainer) - $('#other_si_add_more').append(html); + const html = ` +
+
+ +
+
+ +
+
+ + +
+
+
+
+
+
+
`; + + addMoreContainer.insertAdjacentHTML('beforeend', html); } - \ No newline at end of file diff --git a/app/Views/policy_gmc_terms.php b/app/Views/policy_gmc_terms.php index f64b7f4b..a28f44df 100644 --- a/app/Views/policy_gmc_terms.php +++ b/app/Views/policy_gmc_terms.php @@ -111,9 +111,9 @@
- +
-
+
@@ -141,14 +141,14 @@ Self: -
Min Age:
-
Max Age:
+
Min Age:
+
Max Age:
Spouse: -
Min Age:
-
Max Age:
+
Min Age:
+
Max Age:
Children: @@ -190,8 +190,8 @@
Elders Count:
-
Min Age:
-
Max Age:
+
Min Age:
+
Max Age:
@@ -1418,9 +1418,9 @@
- +
-
+
diff --git a/app/Views/policy_gpa_terms.php b/app/Views/policy_gpa_terms.php index b19fd8a6..8754b519 100644 --- a/app/Views/policy_gpa_terms.php +++ b/app/Views/policy_gpa_terms.php @@ -91,9 +91,9 @@
- +
-
+
@@ -137,13 +137,13 @@
Min Age: - +
Max Age: - +
@@ -792,9 +792,9 @@
- +
-
+
diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 927895d0..b1fa3667 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -827,12 +827,16 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa }; -$("#GridForm").submit(async function(event) { +$("#GridForm").submit(function(event) { + + event.preventDefault(); var check = checkDuplicate(0); console.log(check) + if(check){ + return; + } - event.preventDefault(); if ($('#grid_emp_count').val() == 'false') { toastr.warning('Client has active employees', 'Warning'); @@ -854,9 +858,16 @@ $("#GridForm").submit(async function(event) { checkPolicyTermsSI(function(result) { + + console.log('checkPolicyTermsSI callback') + console.log(result); + if (!result) { - if (check) { + console.log('after result'); + + + if (check = false) { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); } else { @@ -901,15 +912,14 @@ $("#GridForm").submit(async function(event) { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); - toastr.warning(`Value does not exist in the Policy Terms.`); - + toastr.warning(`Sum Insured Amount does not exist in the Policy Terms.`); } -}).catch(function(error) { - console.error('Error checking policy terms:', error); - // Handle error if necessary - toastr.error(`Error checking policy terms: ${error}`); - }); + }).catch(function(error) { + console.error('Error checking policy terms:', error); + // Handle error if necessary + console.log(`Error checking policy terms: ${error}`); + }); }); @@ -941,46 +951,61 @@ $("#AdditionalGridForm").submit(function(event) { var formData = new FormData($('#AdditionalGridForm')[0]); var policy_form_action = ''; + checkPolicyTermsSI(function(result) { - if (check) { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - } else { - $.ajax({ - data: formData, - url: policy_form_action, - type: "POST", - dataType: 'json', - processData: false, - contentType: false, - success: function(res) { - - //console.log("Response", res); - - if (res.status === false) { - toastr.error('Policy Dose Not Create', 'Error'); - return; - } + if (!result) { + if (check) { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); + } else { + $.ajax({ + data: formData, + url: policy_form_action, + type: "POST", + dataType: 'json', + processData: false, + contentType: false, + success: function(res) { - var message = (policy_PrimaryKey === '') ? - 'Policy Additional Rack Rate Added successfully' : - 'Policy Additional Rack Rate Added Successfully'; - toastr.success(message, 'Success'); - $('.close').click(); + //console.log("Response", res); - }, - error: function(xhr, status, error) { + if (res.status === false) { + toastr.error('Policy Dose Not Create', 'Error'); + return; + } - console.error(xhr.responseText); - console.error(status, error); - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + + var message = (policy_PrimaryKey === '') ? + 'Policy Additional Rack Rate Added successfully' : + 'Policy Additional Rack Rate Added Successfully'; + toastr.success(message, 'Success'); + $('.close').click(); + + }, + error: function(xhr, status, error) { + + console.error(xhr.responseText); + console.error(status, error); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + } + }); } - }); - } + + }else{ + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + toastr.warning(`Sum Insured Amount does not exist in the Policy Terms.`); + } + + }).catch(function(error) { + console.error('Error checking policy terms:', error); + // Handle error if necessary + console.log(`Error checking policy terms: ${error}`); + }); }); @@ -2936,126 +2961,123 @@ function checkTermsSISameAsRackRateSI(input) { } - function checkPolicyTermsSI(callback) { +function checkPolicyTermsSI(callback) { + console.log('checkPolicyTermsSI function called'); - console.log('r function called'); - - var id = $('#additional_grid')[0]; + var id = $('#additional_grid')[0]; var container = $('#additional_grid_content_input'); - var val = 0; + var val = 0; if (val == 0) { id = $('#grid')[0]; container = $('#grid_content_input'); } - console.log(id); console.log(container); - var siInputs = 0; + var siInputs = null; - if (id.value === '2') { - siInputs = container.find('input[name="gpa_si"]'); - } else if (id.value === '3') { - siInputs = container.find('input[name="3_si[]"]'); - } else if (id.value === '4') { - siInputs = container.find('input[name="4_si[]"]'); - } else if (id.value === '5') { - siInputs = container.find('input[name="5_si[]"]'); - } else if (id.value === '6') { - siInputs = container.find('input[name="6_si[]"]'); - } else if (id.value === '7') { - siInputs = container.find('input[name="7_si[]"]'); - } else if (id.value === '8') { - siInputs = container.find('input[name="8_si[]"]'); - } else if (id.value === '9') { - siInputs = container.find('input[name="9_si[]"]'); - } else if (id.value === '10') { - siInputs = container.find('input[name="10_si[]"]'); - } else if (id.value === '11') { - siInputs = container.find('input[name="11_si[]"]'); - } else if (id.value === '1') { - var selectedValue = $('#si_or_bp').val(); - - if (selectedValue == 1) { - siInputs = container.find('input[name="gpa_sum_si[]"]'); - } else if (selectedValue == 3) { - siInputs = container.find('input[name="gpa_sum_si2[]"]'); - } + switch (id.value) { + case '1': + var selectedValue = $('#si_or_bp').val(); + if (selectedValue == 1) { + siInputs = container.find('input[name="gpa_sum_si[]"]'); + } else if (selectedValue == 3) { + siInputs = container.find('input[name="gpa_sum_si2[]"]'); + } + break; + case '2': + siInputs = container.find('input[name="gpa_si"]'); + break; + case '3': + siInputs = container.find('input[name="3_si[]"]'); + break; + case '4': + siInputs = container.find('input[name="4_si[]"]'); + break; + case '5': + siInputs = container.find('input[name="5_si[]"]'); + break; + case '6': + siInputs = container.find('input[name="6_si[]"]'); + break; + case '7': + siInputs = container.find('input[name="7_si[]"]'); + break; + case '8': + siInputs = container.find('input[name="8_si[]"]'); + break; + case '9': + siInputs = container.find('input[name="9_si[]"]'); + break; + case '10': + siInputs = container.find('input[name="10_si[]"]'); + break; + case '11': + siInputs = container.find('input[name="11_si[]"]'); + break; + default: + siInputs = []; } + console.log('siInputs', siInputs); + var client_policy_id = $('#client_policy_id').val(); - console.log('client_policy_id', client_policy_id) + console.log('client_policy_id', client_policy_id); var url = '' + client_policy_id; - var arrayLength = 0; + console.log('url', url); $.ajax({ url: url, type: 'GET', dataType: 'json', success: function(response) { + console.log(response); console.log(response.data); - var array1 = response.data; - var array2 = []; + var policy_terms_si = response.data; + var rack_rate_si = []; siInputs.each(function() { var input = $(this).val(); - array2.push(input.replace(/,/g, '')); + rack_rate_si.push(input.replace(/,/g, '')); }); - console.log('array1', array1) - console.log('array2', array2) + console.log('policy_terms_si', policy_terms_si); + console.log('rack_rate_si', rack_rate_si); + let new_array = []; - function intersection(arr1, arr2) { - return arr1.filter(value => arr2.includes(value)); + rack_rate_si.forEach(element => { + if (!policy_terms_si.includes(element)) { + new_array.push(element); + } + }); + + console.log('filtered array', new_array); + + var arrayLength = new_array.length; + console.log('arrayLength', arrayLength); + + if (arrayLength > 0) { + callback(true); + } else { + callback(false); } - - var commonElements = intersection(array1, array2); - - function removeCommonElements(arr, common) { - return arr.filter(value => !common.includes(value)); - } - - array1 = removeCommonElements(array1, commonElements); - array2 = removeCommonElements(array2, commonElements); - - console.log('array1', array1) - console.log('array2', array2) - - - // var result = array1.concat(array2); - var result = array1; - - console.log('result', result) - - arrayLength = result.length; - - console.log('arrayLength', arrayLength) - - if (arrayLength > 0) { - callback(true); - } else { - callback(false); - } - }, error: function(xhr, status, error) { - console.error(xhr.responseText); - console.error(status, error); - toastr.error(`Failed to retrieve Policy Terms. Error: ${error}`); + console.log(xhr.responseText); + console.log(status, error); + console.log(`Failed to retrieve Policy Terms. Error: ${error}`); callback(false); } }); - - } \ No newline at end of file