From 1a029367dd227ccee4734103b367410a20a0239a Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 28 May 2024 12:13:33 +0530 Subject: [PATCH 01/16] CHANGE_RACK_RATE_ADD_SECONDARY_RACK_RATE : RV --- app/Controllers/ClientController.php | 54 +- app/Models/PolicyPremium2Model.php | 2 + app/Views/layout/footer.php | 68 +-- app/Views/policy_grid.php | 852 ++++++++++++++++++++------- 4 files changed, 715 insertions(+), 261 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 7de442a9..4e22dbbd 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -783,6 +783,9 @@ class ClientController extends AdminController public function createClientPolicyPremium() { + + // echo json_encode(['key' => $this->request->getPost()]); die; + try { $policy_type = $this->request->getPost('policy_type'); $client_id = $this->request->getPost('client_id'); @@ -793,6 +796,25 @@ class ClientController extends AdminController $client_id = $client_policy_data['client_id']; } $policy_grid_id = $this->request->getPost('policy_grid_id'); + $rack_rate_type = $this->request->getPost('rack_rate_type'); + + $self = $this->request->getPost('self') ? 1 : 0; + $spouse = $this->request->getPost('spouse')? 1 : 0; + $childrens = $this->request->getPost('childrens')? 1 : 0; + $parents = $this->request->getPost('parents')? 1 : 0; + $parents_in_law = $this->request->getPost('parents-in-law')? 1 : 0; + $either_parents_pil = $this->request->getPost('either-parents-pil')? 1 : 0; + + $relation_data['self'] = $self; + $relation_data['spouse'] = $spouse; + $relation_data['childrens'] = $childrens; + $relation_data['parents'] = $parents; + $relation_data['parents_in_law'] = $parents_in_law; + $relation_data['either_parents_pil'] = $either_parents_pil; + + + $jsonDataForRelation = json_encode($relation_data); + // if($policy_grid_id == 10 || $policy_grid_id == 11){ // $premium_type = 1; @@ -811,6 +833,11 @@ class ClientController extends AdminController $data['client_policy_id'] = $client_policy_id; $data['policy_grid_id'] = $policy_grid_id; $data['premium_type'] = $premium_type; + $data['rack_rate_type'] = $rack_rate_type; + + if($rack_rate_type == 1){ + $data['additional_relationship'] = $jsonDataForRelation; + } $premium = []; @@ -818,7 +845,7 @@ class ClientController extends AdminController if ($policy_grid_id == '1' || $policy_grid_id == '2') { $this->policyPremium1Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update(); } else { - $this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->set('is_active', 0)->update(); + $this->policyPremium2Model->where('client_id', $client_id)->where('client_policy_id', $client_policy_id)->where('rack_rate_type', $rack_rate_type)->set('is_active', 0)->update(); } @@ -925,6 +952,9 @@ class ClientController extends AdminController $premium = $this->request->getPost('6_premium[]'); + + print_r($premium); + $sum_insure = $this->request->getPost('6_si'); $age_from = $this->request->getPost('6_age_from[]'); $age_to = $this->request->getPost('6_age_to[]'); @@ -1184,6 +1214,11 @@ class ClientController extends AdminController $premiumData = ""; } + + + + + // echo '
';
         // print_r($premiumData); die;
 
@@ -1240,13 +1275,22 @@ class ClientController extends AdminController
                 $premiumDataa = $premiumData;
             }
 
-            // print_r($premiumData);die;
+            // $premium1 = [];
+            // $premium2 = [];
 
-            // print_r($data[0]->policy_type); die;
-            // echo "hello";
-            // return json_encode($premiumData);
+            // foreach ($premiumDataa as $key => $item) {
+            //     if ($item['rack_rate_type'] == 0) {
+            //         $premium1[] = $item;
+            //     } elseif ($item['rack_rate_type'] == 1) {
+            //         $premium2[] = $item;
+            //     }
+            // }
+
+            // print_r($premium1);
+            // print_r($premium2); die;
 
             return $this->respond(['status' => true, 'code' => 200, 'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
+
         } else if ($search_term === 'GPA') {
 
             return $this->respond(['status' => true, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200);
diff --git a/app/Models/PolicyPremium2Model.php b/app/Models/PolicyPremium2Model.php
index a03ca381..b302a53c 100644
--- a/app/Models/PolicyPremium2Model.php
+++ b/app/Models/PolicyPremium2Model.php
@@ -25,6 +25,8 @@ class PolicyPremium2Model extends Model
         'is_active',  
         'premium_type',  
         'relationship',  
+        'additional_relationship',  
+        'rack_rate_type',  
         
     ];
 
diff --git a/app/Views/layout/footer.php b/app/Views/layout/footer.php
index a785c23b..114184f7 100644
--- a/app/Views/layout/footer.php
+++ b/app/Views/layout/footer.php
@@ -164,7 +164,7 @@
                     //  });
 
 
-                    console.log('responce', response)
+                    //console.log('responce', response)
 
                     let messagesList = $('#messages-list');
                     messagesList.empty();
@@ -260,11 +260,11 @@
 
         $('#messages-list').on('click', 'li', function(event) {
 
-            console.log('messages-list click li')
+            //console.log('messages-list click li')
 
             if ($(event.target).closest('.rm_msg').length > 0) {
 
-                console.log('.rm_msg')
+                //console.log('.rm_msg')
 
                 let messageId = $(this).data('id');
                 let url = $(this).data('url');
@@ -276,11 +276,11 @@
 
             } else if ($(event.target).closest('.redirect_page').length > 0) {
 
-                console.log('redirect_page')
+                //console.log('redirect_page')
 
                 let messageId = $(this).data('id');
                 let url = $(this).data('url');
-                console.log('url : ', url)
+                //console.log('url : ', url)
                 acknowledgeMessage(messageId);
 
                 window.location.href = '' + url;
@@ -304,7 +304,7 @@
                 method: 'GET',
                 success: function(response) {
 
-                    console.log(response);
+                    //console.log(response);
 
                     if (response.length == 0) {
 
@@ -332,7 +332,7 @@
                         const queryString = objectToQueryString(queryParams);
 
                         var url = 'employee/upload?' + queryString
-                        //console.log(url)
+                        ////console.log(url)
 
 
                         var toast_body_css = 'background : #bfd7eb !important;';
@@ -342,15 +342,15 @@
 
                         if (!item.branch_name.toLowerCase().includes('branch')) {
 
-                            console.log(item.branch_name)
+                            //console.log(item.branch_name)
                             item.branch_name += ' branch';
                         }
 
-                        //console.log(item.branch_name);
+                        ////console.log(item.branch_name);
 
                         var toast_body_data = item.client_name + '( ' + item.branch_name + ' ) ' + ' - ' + item.policy_name;
 
-                        //console.log(toast_body_data);
+                        ////console.log(toast_body_data);
 
                         var html = ` 
  • @@ -394,7 +394,7 @@ const queryString = objectToQueryString(queryParams); var url = 'employee/upload?' + queryString + '#KYC-DOC-tab' - //console.log(url) + ////console.log(url) var toast_body_css = 'background : #bfd7eb !important;'; @@ -407,12 +407,12 @@ if (!item.branch_name.toLowerCase().includes('branch')) { - console.log(item.branch_name) + //console.log(item.branch_name) item.branch_name += ' branch'; } - //console.log(item.branch_name); + ////console.log(item.branch_name); // if (item.batch_export_count > 0) { @@ -420,7 +420,7 @@ // } var toast_body_data = item.client_name + ' - ' + item.branch_name; - //console.log(toast_body_data); + ////console.log(toast_body_data); var html = `
  • @@ -469,7 +469,7 @@ const queryString = objectToQueryString(queryParams); var url = 'employee/upload?' + queryString + '#KYC-DOC-tab' - //console.log(url) + ////console.log(url) var toast_body_css = 'background : #bfd7eb !important;'; @@ -481,12 +481,12 @@ if (!item.branch_name.toLowerCase().includes('branch')) { - console.log(item.branch_name) + //console.log(item.branch_name) item.branch_name += ' branch'; } - //console.log(item.branch_name); + ////console.log(item.branch_name); // if (item.batch_export_count > 0) { @@ -494,7 +494,7 @@ // } var toast_body_data = item.client_name + '( ' + item.branch_name + ' ) ' + ' - ' + item.policy_name; - //console.log(toast_body_data); + ////console.log(toast_body_data); var html = `
  • @@ -541,7 +541,7 @@ const queryString = objectToQueryString(queryParams); var url = 'employee/upload?' + queryString + '#KYC-DOC-tab' - //console.log(url) + ////console.log(url) var toast_body_css = 'background : #bfd7eb !important;'; @@ -553,12 +553,12 @@ if (!item.branch_name.toLowerCase().includes('branch')) { - console.log(item.branch_name) + //console.log(item.branch_name) item.branch_name += ' branch'; } - //console.log(item.branch_name); + ////console.log(item.branch_name); // if (item.batch_export_count > 0) { @@ -566,7 +566,7 @@ // } var toast_body_data = item.client_name + '( ' + item.branch_name + ' ) ' + ' - ' + item.policy_name; - //console.log(toast_body_data); + ////console.log(toast_body_data); var html = `
  • @@ -613,7 +613,7 @@ const queryString = objectToQueryString(queryParams); var url = 'employee/upload?' + queryString + '#KYC-DOC-tab' - //console.log(url) + ////console.log(url) var toast_body_css = 'background : #bfd7eb !important;'; @@ -624,12 +624,12 @@ if (!item.branch_name.toLowerCase().includes('branch')) { - console.log(item.branch_name) + //console.log(item.branch_name) item.branch_name += ' branch'; } - //console.log(item.branch_name); + ////console.log(item.branch_name); // if (item.batch_export_count > 0) { @@ -637,7 +637,7 @@ // } var toast_body_data = item.client_name + '( ' + item.branch_name + ' ) ' + ' - ' + item.policy_name; - //console.log(toast_body_data); + ////console.log(toast_body_data); var html = `
  • @@ -684,7 +684,7 @@ const queryString = objectToQueryString(queryParams); var url = 'employee/upload?' + queryString + '#KYC-DOC-tab' - //console.log(url) + ////console.log(url) var toast_body_css = 'background : #bfd7eb !important;'; var toast_head_css = 'background-color : rgb(2, 168, 181) !important; color :#000; border-bottom: 0;'; @@ -695,12 +695,12 @@ if (!item.branch_name.toLowerCase().includes('branch')) { - console.log(item.branch_name) + //console.log(item.branch_name) item.branch_name += ' branch'; } - //console.log(item.branch_name); + ////console.log(item.branch_name); // if (item.batch_export_count > 0) { @@ -708,7 +708,7 @@ // } var toast_body_data = item.client_name + '( ' + item.branch_name + ' ) ' + ' - ' + item.policy_name; - //console.log(toast_body_data); + ////console.log(toast_body_data); var html = `
  • @@ -753,11 +753,11 @@ $('#messages-list-2').on('click', 'li', function(event) { - console.log('messages-list-2 click li') + //console.log('messages-list-2 click li') if ($(event.target).closest('.rm_msg').length > 0) { - console.log('.rm_msg') + //console.log('.rm_msg') $(this).delay(300).fadeOut('slow', function() { $(this).remove(); @@ -765,10 +765,10 @@ } else if ($(event.target).closest('.redirect_page').length > 0) { - console.log('redirect_page') + //console.log('redirect_page') let url = $(this).data('url'); - console.log('url : ', url); + //console.log('url : ', url); window.location.href = '' + url; } diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 9482c63b..5abfcd9e 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -4,53 +4,139 @@
    - +
    `; } @@ -1387,12 +1741,12 @@ function appendGridtHtml(ui_type = false, data = false, ) { container.insertAdjacentHTML('beforeend', html); - $('#gmc_add_more').hide(); - $('#gmc_add_more2').hide(); - $('#gmc_remove').show(); - Count-- - $('#gmc_add_more_' + Count).hide() - Count++ + // $('#gmc_add_more').hide(); + // $('#gmc_add_more2').hide(); + // $('#gmc_remove').show(); + // Count-- + // $('#gmc_add_more_' + Count).hide() + // Count++ // Number to word @@ -1437,12 +1791,25 @@ function removebutton(index, type) { } -function checkDuplicate() { +function checkDuplicate(val) { - if ($('#grid')[0].value === '3') { + $('#additional_grid_content_input'); + $('#grid_content_input') + + var id = $('#additional_grid')[0]; + var container = $('#additional_grid_content_input'); + if(val == 0){ + id = $('#grid')[0]; + container = $('#grid_content_input'); + } - var siInputs = $('input[name="3_si[]"]'); - var premiumInputs = $('input[name="3_premium[]"]'); + console.log(id); + console.log(container); + + if (id.value === '3') { + + var siInputs = container.find('input[name="3_si[]"]'); + var premiumInputs = container.find('input[name="3_premium[]"]'); var siValues = []; var premiumValues = []; @@ -1472,10 +1839,10 @@ function checkDuplicate() { } else { return false; } - } else if ($('#grid')[0].value === '4') { + } else if (id.value === '4') { - var ageFrom = $('input[name="4_age_from[]"]'); - var ageTo = $('input[name="4_age_to[]"]'); + var ageFrom = container.find('input[name="4_age_from[]"]'); + var ageTo = container.find('input[name="4_age_to[]"]'); var ageFromValues = []; var ageToValues = []; @@ -1506,10 +1873,10 @@ function checkDuplicate() { return false; } - } else if ($('#grid')[0].value === '5') { - var si = $('input[name="5_si[]"]'); - var ageFrom = $('input[name="5_age_from[]"]'); - var ageTo = $('input[name="5_age_to[]"]'); + } else if (id.value === '5') { + var si = container.find('input[name="5_si[]"]'); + var ageFrom = container.find('input[name="5_age_from[]"]'); + var ageTo = container.find('input[name="5_age_to[]"]'); var si_array = []; var ageFrom_array = []; @@ -1544,9 +1911,9 @@ function checkDuplicate() { } else { return false; } - } else if ($('#grid')[0].value === '6') { - var ageFrom = $('input[name="6_age_from[]"]'); - var ageTo = $('input[name="6_age_to[]"]'); + } else if (id.value === '6') { + var ageFrom = container.find('input[name="6_age_from[]"]'); + var ageTo = container.find('input[name="6_age_to[]"]'); var ageFromValues = []; var ageToValues = []; @@ -1576,10 +1943,10 @@ function checkDuplicate() { } else { return false; } - } else if ($('#grid')[0].value === '7') { - var si = $('input[name="7_si[]"]'); - var ageFrom = $('input[name="7_age_from[]"]'); - var ageTo = $('input[name="7_age_to[]"]'); + } else if (id.value === '7') { + var si = container.find('input[name="7_si[]"]'); + var ageFrom = container.find('input[name="7_age_from[]"]'); + var ageTo = container.find('input[name="7_age_to[]"]'); var si_array = []; var ageFrom_array = []; @@ -1614,10 +1981,10 @@ function checkDuplicate() { } else { return false; } - } else if ($('#grid')[0].value === '10') { - var si = $('input[name="10_si[]"]'); - var ageFrom = $('input[name="10_age_from[]"]'); - var ageTo = $('input[name="10_age_to[]"]'); + } else if (id.value === '10') { + var si = container.find('input[name="10_si[]"]'); + var ageFrom = container.find('input[name="10_age_from[]"]'); + var ageTo = container.find('input[name="10_age_to[]"]'); var si_array = []; var ageFrom_array = []; @@ -1653,9 +2020,9 @@ function checkDuplicate() { } else { return false; } - } else if ($('#grid')[0].value === '8') { - var siInputs = $('input[name="8_si[]"]'); - var gradeInputs = $('input[name="8_grade[]"]'); + } else if (id.value === '8') { + var siInputs = container.find('input[name="8_si[]"]'); + var gradeInputs = container.find('input[name="8_grade[]"]'); var siValues = []; var gradeValues = []; @@ -1685,9 +2052,9 @@ function checkDuplicate() { } else { return false; } - } else if ($('#grid')[0].value === '9') { - var siInputs = $('input[name="9_si[]"]'); - var gradeInputs = $('input[name="9_grade[]"]'); + } else if (id.value === '9') { + var siInputs = container.find('input[name="9_si[]"]'); + var gradeInputs = container.find('input[name="9_grade[]"]'); var siValues = []; var gradeValues = []; @@ -1717,10 +2084,10 @@ function checkDuplicate() { } else { return false; } - } else if ($('#grid')[0].value === '11') { - var siInputs = $('input[name="11_si[]"]'); - var gradeInputs = $('input[name="11_grade[]"]'); - var maxSiInputs = $('input[name="11_max_si[]"]'); + } else if (id.value === '11') { + var siInputs = container.find('input[name="11_si[]"]'); + var gradeInputs = container.find('input[name="11_grade[]"]'); + var maxSiInputs = container.find('input[name="11_max_si[]"]'); var siValues = []; var gradeValues = []; @@ -1758,13 +2125,13 @@ function checkDuplicate() { } else { return false; } - }else if ($('#grid')[0].value === '1') { + } else if (id.value === '1') { var selectedValue = $('#si_or_bp').val(); - if(selectedValue == 1){ + if (selectedValue == 1) { - var siInputs = $('input[name="gpa_sum_si[]"]'); - var premiumInputs = $('input[name="gpa_sum_premium[]"]'); + var siInputs = container.find('input[name="gpa_sum_si[]"]'); + var premiumInputs = container.find('input[name="gpa_sum_premium[]"]'); var siValues = []; var premiumValues = []; @@ -1800,11 +2167,11 @@ function checkDuplicate() { return false; } - }else if(selectedValue == 3){ + } else if (selectedValue == 3) { - var siInputs = $('input[name="gpa_sum_si2[]"]'); - var premiumInputs = $('input[name="gpa_sum_premium2[]"]'); - var bandInputs = $('input[name="gpa_band[]"]'); + var siInputs = container.find('input[name="gpa_sum_si2[]"]'); + var premiumInputs = container.find('input[name="gpa_sum_premium2[]"]'); + var bandInputs = container.find('input[name="gpa_band[]"]'); var siValues = []; var premiumValues = []; @@ -1861,7 +2228,7 @@ function checkDuplicate() { } function basicPayMultiple(input) { - + if (input.id == 'basic_pay') { var multi = $('#basic_multiplier')[0].value.replace(/,/g, '') * input.value.replace(/,/g, ''); @@ -1877,7 +2244,8 @@ function basicPayMultiple(input) { var multi = input.value * $('#basic_pay')[0].value.replace(/,/g, ''); $('#gpa_basic_si').val(multi).trigger('keyup'); - var multi_2 = $('#gpa_basic_si')[0].value.replace(/,/g, '') * $('#premium_multiplier')[0].value.replace(/,/g,''); + var multi_2 = $('#gpa_basic_si')[0].value.replace(/,/g, '') * $('#premium_multiplier')[0].value.replace(/,/g, + ''); $('#gpa_basic_premium').val(multi_2).trigger('keyup'); } else if (input.id == 'premium_multiplier') { @@ -1897,11 +2265,11 @@ function basicPayMultiple(input) { function gpaSumInsureMultiplier(element) { // console.log(element); - - var element = $('#gpa_sum_multiplier')[0]; - var sumInsured = $('input[name="gpa_sum_si[]"]'); - if ($('#si_or_bp').val() == 3) { + var element = $('#gpa_sum_multiplier')[0]; + var sumInsured = $('input[name="gpa_sum_si[]"]'); + + if ($('#si_or_bp').val() == 3) { var element = $('#gpa_sum_multiplier2')[0] var sumInsured = $('input[name="gpa_sum_si2[]"]') @@ -1913,7 +2281,7 @@ function gpaSumInsureMultiplier(element) { var premium = $('input[name="premium[]"]'); } else if ($('#si_or_bp').val() == 3) { var premium = $('input[name="gpa_sum_premium2[]"]'); - }else { + } else { var premium = $('input[name="gpa_sum_premium[]"]'); } @@ -1995,11 +2363,11 @@ function si_orbp_change_function() { $('.gpa_sum_insure_remove').show(); $('.gpa_band_remove').hide(); - var count = $("div.form-row.gpa_sum_insure_remove").length; - - if(count == 0){ + var count = $("div.form-row.gpa_sum_insure_remove").length; + + if (count == 0) { $('#gmc_add_more').show(); - }else{ + } else { $('#gmc_add_more').hide(); } @@ -2050,15 +2418,15 @@ function si_orbp_change_function() { elementsToUnhide.show(); } else if (selectedValue == 3) { - + $('.gpa_sum_insure_remove').hide(); $('.gpa_band_remove').show(); - var count = $("div.form-row.gpa_band_remove").length; - - if(count == 0){ + var count = $("div.form-row.gpa_band_remove").length; + + if (count == 0) { $('#gmc_add_more2').show(); - }else{ + } else { $('#gmc_add_more2').hide(); } @@ -2118,17 +2486,57 @@ function si_orbp_change_function() { } function getCurrentTime() { - var now = new Date(); - var hours = now.getHours(); - var minutes = now.getMinutes(); - var ampm = hours >= 12 ? 'PM' : 'AM'; - hours = hours % 12; - hours = hours ? hours : 12; // 0 should be considered as 12 - minutes = minutes < 10 ? '0' + minutes : minutes; // Add leading zero if minutes < 10 - var timeString = hours + ':' + minutes + ' ' + ampm; - return timeString; + var now = new Date(); + var hours = now.getHours(); + var minutes = now.getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // 0 should be considered as 12 + minutes = minutes < 10 ? '0' + minutes : minutes; // Add leading zero if minutes < 10 + var timeString = hours + ':' + minutes + ' ' + ampm; + return timeString; +} + + +function createCheckboxes(obj, additional_relationship) { + + console.log('createCheckboxes function called'); + + console.log(additional_relationship) + additional_relationship = JSON.parse(additional_relationship); + console.log(additional_relationship) + + $('#relationship').empty(); + const $relationshipElement = $('#relationship'); + let html = `
    + +
    `; + const multiplier = 7; // Adjust this value as needed + + $.each(obj, function(key, value) { + + if (value > 0 && key != 'either-parents-pil') { + + key = formatString(key); + const isChecked = additional_relationship && additional_relationship[key] === 1 ? 'checked' : ''; + html += ` +
    + + +
    `; + } + }); + + $relationshipElement.append(html); + +} + + +function formatString(str) { + return str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); } + \ No newline at end of file From eae1e6c8a8883eb3003f352110b3ba917ca4e852 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Tue, 28 May 2024 17:47:25 +0530 Subject: [PATCH 02/16] CHANGE_NHANCE_TO_TICKET_HEADER : AADHAVAN --- app/Views/layout/header.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 3fedb248..5d65d9be 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -556,7 +556,8 @@ $currentUrl = base_url(); $parsedUrl = parse_url($currentUrl); $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . '/'; - $redirectUrl = $baseUrl . 'Ticketing/staff/login?' . http_build_query(['token' => $sessionData]); + $hashedEmail = hash('sha256', $sessionData->email); + $redirectUrl = $baseUrl . 'helpdesk/staff/login?' . http_build_query(['token' => $hashedEmail]); ?> From add2a3e0fb9f634d125f4e8d2a9939f06f91eab8 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Tue, 28 May 2024 17:57:58 +0530 Subject: [PATCH 03/16] CHANGE_NHANCE_TO_TICKET_ENV_HELPDESK_URL : AADHAVAN --- app/Views/layout/header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 8e8187d3..9cc606ba 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -590,7 +590,7 @@ $parsedUrl = parse_url($currentUrl); $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . '/'; $hashedEmail = hash('sha256', $sessionData->email); - $redirectUrl = $baseUrl . 'helpdesk/staff/login?' . http_build_query(['token' => $hashedEmail]); + $redirectUrl = $baseUrl . getenv('hepldeskURL') .'/staff/login?' . http_build_query(['token' => $hashedEmail]); ?> From 65987607c518df2ab9c59a914912a20513b31f94 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 29 May 2024 11:46:55 +0530 Subject: [PATCH 04/16] FEAT_COPY_PASTE_EXCEL_TO_RACK_RATE_DATA_COMPLETE : RV --- app/Controllers/ClientController.php | 35 +- app/Views/policy_grid.php | 129 ++++-- app/Views/policy_grid_excel.php | 599 +++++++++++++++++---------- 3 files changed, 501 insertions(+), 262 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 4e22dbbd..7a9e9263 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1165,21 +1165,24 @@ class ClientController extends AdminController $self = $policy_terms_data->family_floaters; } - $emp_count = $this->employeeModel->join('client_policy cp', "employees.client_id = cp.client_id") - ->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id") - ->where("employees.client_id", $record['client_id']) - ->where("employees.emp_status", 'active') - ->where("ep.status", 'active') - ->where("employees.is_active", 1) - ->where("ep.is_active", 1) + // $emp_count = $this->employeeModel + // ->join('client_policy cp', "employees.client_id = cp.client_id") + // ->join('employee_polices ep', "cp.id = ep.client_policy_id AND employees.id = ep.employee_id") + // ->where("employees.client_id", $record['client_id']) + // ->where("employees.emp_status", 'active') + // ->where("ep.status", 'active') + // ->where("employees.is_active", 1) + // ->where("ep.is_active", 1) + // ->countAllResults(); + + + $emp_count = $this->employeePolicyModel + ->join('client_policy cp', "cp.id = employee_polices.client_policy_id") + ->where("employee_polices.client_policy_id", $client_policy_id) + ->where("employee_polices.status", 'active') + ->where("employee_polices.is_active", 1) ->countAllResults(); - - // $data = $this->employeePolicyModel->select('employee_polices.id') - // ->where('employee_polices.is_active', 1) - // ->where('employee_polices.client_policy_id', $client_policy_id) - // ->findAll(); - // $emp_count = count($data); // if($emp_count == 0){ @@ -1289,14 +1292,14 @@ class ClientController extends AdminController // print_r($premium1); // print_r($premium2); die; - return $this->respond(['status' => true, 'code' => 200, 'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); + return $this->respond(['status' => true, 'code' => 200, 'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200); } else if ($search_term === 'GPA') { - return $this->respond(['status' => true, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); + return $this->respond(['status' => true, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200); } else { - return $this->respond(['status' => false, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); + return $this->respond(['status' => false, 'code' => 200, 'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self, 'client_policy_id' => $client_policy_id], 200); } } diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index e3c8ff95..c96b1c69 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -1,3 +1,5 @@ + + - -
    -
    +
    + + Copy from excel
    -
    +
    +
    + +
    @@ -158,6 +173,26 @@ $('#btnGridSubmit').hide(); $('.close').click(function() { + $('#grid_content_input').show(); + $('#grid_content_from_excel').hide(); + + if ($('#copyfromexcel').text() == "Manual entry") { + $('#copyfromexcel').text("Copy from excel") + } else { + $('#copyfromexcel').text("Copy from excel"); + } + + + $('#additional_grid_content_input').show(); + $('#additional_grid_content_from_excel').hide(); + + if ($('#copyfromexcelforadditional').text() == "Manual entry") { + $('#copyfromexcelforadditional').text("Copy from excel") + } else { + $('#copyfromexcelforadditional').text("Copy from excel"); + } + + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); $('#add_grid_' + i).remove(); @@ -166,6 +201,7 @@ $('.close').click(function() { }); $('#copyfromexcel').click(function() { + // alert('called'); // $('#copyfromexcel').toggle(); // $("#copied_excel_data").val(result.exampleMessage); @@ -182,6 +218,22 @@ $('#copyfromexcel').click(function() { +}); + +$('#copyfromexcelforadditional').click(function() { + + if ($(this).text() == "Copy from excel") { + $(this).text("Manual entry") + + } else { + $(this).text("Copy from excel"); + } + + $('#additional_grid_content_input').toggle(); + $('#additional_grid_content_from_excel').toggle(); + + + }); function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = false, rr_type = false) { @@ -807,8 +859,7 @@ $("#GridForm").submit(function(event) { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); - var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' : - 'Policy Premium Added Successfully'; + var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :'Policy Premium Added Successfully'; toastr.success(message, 'Success'); // $('.close').click(); @@ -829,7 +880,6 @@ $("#GridForm").submit(function(event) { $("#AdditionalGridForm").submit(function(event) { var check = checkDuplicate(1); - event.preventDefault(); if ($('#grid_emp_count').val() == 'false') { @@ -966,18 +1016,21 @@ $('body').on('click', '.btnPolicyModel', function() { res.premiumData = JSON.parse(res.premiumData); console.log('policy grid responce', res.premiumData); - console.log('policy grid responce', res.policy_name); + console.log('policy name', res.policy_name); - $('#nameOfThePolicy').html(' - ' + res.policy_name); + $('#nameOfThePolicy').text(' - ' + res.policy_name); $('#grid_emp_count').val(res.count); if (res.count > 0) { $("#hide_smbt_btn").hide(); + $("#secondary_rack_rate_btn_grp").hide(); } else { $("#hide_smbt_btn").show(); + $("#secondary_rack_rate_btn_grp").show(); } + if (res.status === false) { toastr.error(res.status); @@ -1037,8 +1090,6 @@ $('body').on('click', '.btnPolicyModel', function() { console.log('policy_grid_id_value', policy_grid_id_value); console.log('secondary_policy_grid_id_value', secondary_policy_grid_id_value); - - $('#grid_content_input').empty(); var policeGridOptionHTML = ''; policeGridOptionHTML += ` `; @@ -1050,7 +1101,7 @@ $('body').on('click', '.btnPolicyModel', function() { }); - + $('#additional_grid_content_input').empty(); var policeGridOptionHTMLforSecondary = ''; policeGridOptionHTMLforSecondary += ` `; @@ -1129,7 +1180,12 @@ $('body').on('click', '.btnPolicyModel', function() { $(this).trigger('keyup'); }); - var id_for_trigger = temp_for_premiumData[0].policy_grid_id; + var id_for_trigger = []; + if (temp_for_premiumData.length > 0 && temp_for_premiumData[0] !== undefined) { + id_for_trigger = temp_for_premiumData[0].policy_grid_id; + } + + $(`input[name="${id_for_trigger}_si[]"]`).each(function() { // console.log($(this)); $(this).trigger('keyup'); @@ -1167,6 +1223,8 @@ $('body').on('click', '.btnPolicyModel', function() { $('#grid').change(function() { + $('.excel_textarea').val(''); + var grid_id = $(this)[0].value; var client_policy_id = $('#client_policy_id')[0].value; @@ -1239,7 +1297,6 @@ $('#grid').change(function() { si_or_bp_value = res.premiumData[0].si_or_bp; $('#si_or_bp').val(si_or_bp_value); - } @@ -1277,6 +1334,8 @@ $('#grid').change(function() { $('#additional_grid').change(function() { + $('.excel_textarea').val(''); + var grid_id = $(this)[0].value; var client_policy_id = $('#client_policy_id')[0].value; @@ -1302,9 +1361,9 @@ $('#additional_grid').change(function() { if (res.count > 0) { // console.log(' hide submit btn count ', res.count); - $("#hide_smbt_btn").hide(); + $("#secondary_rack_rate_btn_grp").hide(); } else { - $("#hide_smbt_btn").show(); + $("#secondary_rack_rate_btn_grp").show(); // console.log('show submit btn count ', res.count); } @@ -1315,9 +1374,9 @@ $('#additional_grid').change(function() { if (res.count > 0) { // console.log(' hide submit btn count ', res.count); - $("#hide_smbt_btn").hide(); + $("#secondary_rack_rate_btn_grp").hide(); } else { - $("#hide_smbt_btn").show(); + $("#secondary_rack_rate_btn_grp").show(); // console.log('show submit btn count ', res.count); } @@ -1332,7 +1391,7 @@ $('#additional_grid').change(function() { policy_grid_id_value = res.premiumData[0].policy_grid_id; } - $('#grid_content_input').empty(); + $('#additional_grid_content_input').empty(); var policeGridOptionHTML = ''; policeGridOptionHTML += ` `; $.each(res.data, function(index, item) { @@ -1341,7 +1400,9 @@ $('#additional_grid').change(function() { 'selected="selected"' : '') + '>' + item.policy_grid_type + ''; }); + // $('#grid').html(policeGridOptionHTML); + var si_or_bp_value = ''; if (res.premiumData && res.premiumData.length > 0) { @@ -2530,12 +2591,16 @@ function getCurrentTime() { function createCheckboxes(obj, additional_relationship) { - console.log('createCheckboxes function called'); - console.log(additional_relationship) - additional_relationship = JSON.parse(additional_relationship); - console.log(additional_relationship) + console.log(additional_relationship); + try { + additional_relationship = JSON.parse(additional_relationship); + console.log(additional_relationship); + } catch (error) { + console.error("Error parsing additional_relationship:", error); + return; + } $('#relationship').empty(); const $relationshipElement = $('#relationship'); @@ -2545,24 +2610,24 @@ function createCheckboxes(obj, additional_relationship) { const multiplier = 7; // Adjust this value as needed $.each(obj, function(key, value) { - if (value > 0 && key != 'either-parents-pil') { - + const isChecked = additional_relationship && typeof additional_relationship === 'object' && additional_relationship[key] == 1 ? 'checked' : ''; key = formatString(key); - const isChecked = additional_relationship && additional_relationship[key] === 1 ? 'checked' : ''; + console.log('isChecked', isChecked); html += `
    - +
    `; + // console.log(html); } }); $relationshipElement.append(html); - } + function formatString(str) { return str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); } diff --git a/app/Views/policy_grid_excel.php b/app/Views/policy_grid_excel.php index 50487a0a..009c6bb6 100644 --- a/app/Views/policy_grid_excel.php +++ b/app/Views/policy_grid_excel.php @@ -1,241 +1,412 @@ +table { + border-collapse: collapse; + width: 100%; +} -
    - - -

    Paste excel data here: Copy Excel Headers

    -
    - - -
    -
    - -
    -
    - -

    -

    JSON output:

    -
    -
    +td, +th { + padding: 0.2rem; +} - -
    + $(`input[name="${formatType}_premium[]"]`).each(function() { + // console.log($(this)); + $(this).trigger('keyup'); + }); + + + + } + + \ No newline at end of file From 127a12d2351d19b88d015ea6ef879979960dd121 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 29 May 2024 12:19:10 +0530 Subject: [PATCH 05/16] CHANGE _ adding branch_id : GWM --- app/Controllers/EmployeeRestController.php | 129 +++++------------- .../RestAuthenticationController.php | 2 +- 2 files changed, 36 insertions(+), 95 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index daf246d7..67306e3c 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -84,10 +84,12 @@ class EmployeeRestController extends AdminController try { $emp_code = $this->request->getGet('emp_code'); $client_id = $this->request->getGet('client_id'); + $client_branch_id = $this->request->getGet('client_branch_id'); if ($emp_code) { $relationship = 'self'; $employee = $this->employeeModel->where('emp_code', $emp_code) ->where('client_id', $client_id) + ->where('client_branch_id', $client_branch_id) ->where('is_active', 1 ) ->where('relationship', $relationship) ->first(); @@ -102,7 +104,7 @@ class EmployeeRestController extends AdminController } } - + //not in use public function editEmployeeProfile() { try { @@ -125,7 +127,7 @@ class EmployeeRestController extends AdminController } - + //not in use public function getEmployeeAndDependence() { try { @@ -152,7 +154,7 @@ class EmployeeRestController extends AdminController } - + //not in use public function editEmployeeAndDependence() { try { @@ -372,6 +374,7 @@ class EmployeeRestController extends AdminController return null; } } + public function deleteDependence() { try { @@ -404,7 +407,7 @@ class EmployeeRestController extends AdminController public function getEmployeeAndDependenceByClientId() { try { - $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0); + $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0,client_branch_id:$this->request->getGet('client_branch_id')); if ($empData) { return $this->respond(['status' => 'success', 'code' => 200, 'data' => $empData], 200); @@ -934,7 +937,8 @@ public function getEmployeePolicy() $id = $this->request->getGet('id'); $emp_code = $this->request->getGet('emp_code'); - $client_id = $this->request->getGet('client_id'); + $client_id = $this->request->getGet('client_id'); + $client_branch_id = $this->request->getGet('client_branch_id'); // This is an array containing keys to be removed from the terms and conditions array $keysToRemove = ["removable_keys"]; @@ -942,8 +946,11 @@ public function getEmployeePolicy() $empPolicy = $this->employeeModel->getEmployeePolicy($id); // Retrieve employee and dependents data by passing the employee code - $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('client_id',$client_id) - ->where('is_active', 1 )->where('is_addon_value',0)->findAll(); + $employeeData = $this->employeeModel->where('emp_code',$emp_code) + ->where('client_id',$client_id) + ->where('client_branch_id',$client_branch_id) + ->where('is_active', 1 ) + ->where('is_addon_value',0)->findAll(); if ($empPolicy) { @@ -1091,12 +1098,13 @@ public function getEmployeePolicy() ->where('client_policy.policy_type_id', 3 ) ->where('client_policy.is_addon', 1 ) ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) ->where('client_policy.is_active', 1 ) ->get() ->getResult(); if($checkGmcParentsPolicyExist) { - $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id); + $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id,$client_branch_id); return $this->respond(['status' => 'success','code' => 200,'data' => [$array,$GmcParrentsData]], 200); } @@ -1122,11 +1130,14 @@ public function getEmployeePolicy() } -public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id) +public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$client_branch_id) { - $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('client_id',$client_id) - ->where('is_active', 1 )->where('is_addon_value',0)->findAll(); + $employeeData = $this->employeeModel->where('emp_code',$emp_code) + ->where('client_id',$client_id) + ->where('client_branch_id',$client_branch_id) + ->where('is_active', 1 ) + ->where('is_addon_value',0)->findAll(); foreach ($GmcParrentsPolicy as $key => $array) { @@ -1163,9 +1174,7 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id) $array->eCardDownload = null; } - // if($array->tpa_id != null){ - // $array->eCardDownload = base_url('download-e-card/') . $array->rand_string; - // }else{ $array->eCardDownload = null; } + $array->eCardDownload = null; // Map family floaters that already exist in the employee table @@ -1320,7 +1329,8 @@ public function getClientDetails() $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first(); if($client) { $client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo']; - $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll(); + $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id'))->findAll(); return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 200); }else{ @@ -1335,17 +1345,22 @@ public function getAddOnPolicy() { try { - $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',1)->findAll(); + $addOnEmployeeData = $this->employeeModel->where('is_active', 1 ) + ->where('emp_code',$this->request->getGet('emp_code')) + ->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) + ->where('is_addon_value',1)->findAll(); $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) ->where('policy_status', 1) ->findAll(); if(count($clientPolicy)) { - $band = $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('family_floater_key','self')->get()->getRow()->band; + $band = $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('client_branch_id',$this->request->getGet('client_branch_id'))->where('family_floater_key','self')->get()->getRow()->band; $PolicyData = []; foreach ($clientPolicy as $key => $array) { $responce = []; @@ -1970,83 +1985,6 @@ public function removeEmpAndEmpPolicyData() } - - -function getEmployeeOldPolicy() -{ - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.* , policies.name as policy_name , policy_type.policy_type as policy_type') - ->join('policies', 'client_policy.policy_id = policies.id', 'left') - ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') - ->where('client_policy.client_id', $this->request->getGet('client_id') ) - ->where('client_policy.is_active', 1 ) - ->where('client_policy.policy_status', 0) - ->orderby('client_policy.id' , 'ASC') - ->findAll(); - - // Retrieve employee and dependents data by passing the employee code - $employeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('client_id',$this->request->getGet('client_id')) - ->where('is_active', 1 )->findAll(); - $whereArrayForId = []; - foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); } - - if(count($ClientPolicyData) > 0 && count($employeeData) > 0) - { - $result = []; - foreach ($ClientPolicyData as $key => $ClientPolicyValue) { - - $terms = json_decode($ClientPolicyValue['policy_terms']); - // dd($terms); - $data['client_id'] = $ClientPolicyValue['client_id']; - $data['client_policy_id'] = $ClientPolicyValue['id']; - $data['policy_name'] = $ClientPolicyValue['policy_name']; - $data['policy_type'] = $ClientPolicyValue['policy_type']; - $data['policy_type'] = $ClientPolicyValue['policy_type']; - $data['policy_start_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_start_date']); - $data['policy_end_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['policy_end_date']); - - if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else - if($ClientPolicyValue['policy_type_id'] == 2){ $data['heading'] = 'Group Medical Coverage'; }else - if($ClientPolicyValue['policy_type_id'] == 3){ $data['heading'] = 'Group Medical Coverage - Parents'; }else - if($ClientPolicyValue['policy_type_id'] == 4){ $data['heading'] = 'Group Medical Coverage - Top Up'; }else - if($ClientPolicyValue['policy_type_id'] == 5){ $data['heading'] = 'Group Medical Coverage - Parents (Top Up)'; } - - if($ClientPolicyValue['policy_type_id'] == 1){ $data['floter_text_heading'] = 'Sum Insured'; } - else - { - if($terms->family_floater == 1){ $data['floter_text_heading'] = 'Floter Sum Insured'; }else{ $data['floter_text_heading'] = 'Sum Insured'; } - } - - $employee_policy = $this->employeePolicyModel->select('employees.*,employee_polices.employee_id , employee_polices.basic_cover_si , employee_polices.premium , employee_polices.gst , employee_polices.tpa_id , employee_polices.rand_string') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->whereIn('employee_polices.employee_id',$whereArrayForId) - ->where('employee_polices.client_policy_id',$ClientPolicyValue['id']) - ->where('employee_polices.is_active', 1 )->findAll(); - $si_value = 0; - $si_premium_value = 0; - $si_gst_value = 0; - foreach ($employee_policy as $key => $value) { - if(isset($value['basic_cover_si'])){ $si_value = $value['basic_cover_si']; } - if(isset($value['premium'])){ $si_premium_value = $si_premium_value + $value['premium'];} - if(isset($value['gst'])){ $si_gst_value = $si_gst_value + $value['gst'];} - } - - $data['si_value'] = $si_value; - $data['si_premium_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_premium_value; - $data['si_gst_value'] = ($ClientPolicyValue['policy_type_id'] == 1 || $ClientPolicyValue['policy_type_id'] == 2) ? 0 : $si_gst_value; - - $data['EmployeePolicy'] = $employee_policy; - array_push($result, $data); - } - - return $this->respond(['status' => 'success','code' => 200,'data' => $result ], 200); - - }else{ - return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200); - } - -} - function getEmployeeActiveOrInactivePolicy() { @@ -2055,6 +1993,7 @@ function getEmployeeActiveOrInactivePolicy() ->join('policies', 'client_policy.policy_id = policies.id', 'left') ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left') ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) ->where('client_policy.is_active', 1 ) ->where('client_policy.policy_status', $policy_status) ->orderby('client_policy.id' , 'ASC') @@ -2063,9 +2002,11 @@ function getEmployeeActiveOrInactivePolicy() // Retrieve employee and dependents data by passing the employee code $employeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) ->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) ->where('is_active', 1 )->findAll(); $employeeName = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) ->where('client_id',$this->request->getGet('client_id')) + ->where('client_branch_id',$this->request->getGet('client_branch_id')) ->where('family_floater_key','self')->where('is_active', 1 ) ->get()->getRow()->name; $whereArrayForId = []; diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 3af70fc4..72e7b8c7 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -101,7 +101,7 @@ class RestAuthenticationController extends AdminController $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $data = [ - 'user_id' => $employeeData['id'], + 'user_id' => $employeeData['id'], 'user_type' => 'employee', 'ip' => $auth['ip'], 'platform' => $auth['platform'], From d16c0799bb76285996491b0d3f09699387e772c5 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 29 May 2024 12:26:10 +0530 Subject: [PATCH 06/16] CHANGE _ adding branch_id : GWM --- app/Controllers/EmployeeRestController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 67306e3c..81529bc7 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -407,7 +407,7 @@ class EmployeeRestController extends AdminController public function getEmployeeAndDependenceByClientId() { try { - $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0,client_branch_id:$this->request->getGet('client_branch_id')); + $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0,branch_id:$this->request->getGet('client_branch_id')); if ($empData) { return $this->respond(['status' => 'success', 'code' => 200, 'data' => $empData], 200); @@ -426,7 +426,8 @@ class EmployeeRestController extends AdminController public function exportDataByClientPolicyId() { try { - $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0); + + $empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0,branch_id:$this->request->getGet('client_branch_id')); if(count($empData)) { @@ -1783,6 +1784,7 @@ public function getCashDepositData() $ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name') ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) ->where('client_policy.is_active', 1 ) ->where('client_policy.policy_status', 1) ->groupBy('client_policy.insurer_id') @@ -1812,7 +1814,7 @@ public function getCashDepositData() { $value['type'] = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow()->policy_type; - $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0); + $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$this->request->getGet('client_branch_id')); $enrolledCount = 0; $draftCount = 0; if(count($employeeDetails)) From 0d17c1692b04f73c8f557fb19d2054e87390a92c Mon Sep 17 00:00:00 2001 From: bitbucket Date: Wed, 29 May 2024 13:27:34 +0530 Subject: [PATCH 07/16] CHANGE_ adding branch_id : GWM --- app/Controllers/EmployeeRestController.php | 142 +++++++++++---------- 1 file changed, 74 insertions(+), 68 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 81529bc7..09dff202 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -403,6 +403,73 @@ class EmployeeRestController extends AdminController } + // Get the RelationShip list + public function createOrUpdateEmployeePolicySiAmount() + { + + try { + $requestData = $this->request->getJSON(); + + foreach ($requestData as $key => $value) { + + + $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id) + ->where('client_policy_id', $value->client_policy_id) + ->where('is_active', 1 ) + ->findAll(); + + + // dd($checkIfExist); + if ($checkIfExist) { + + $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si); + + }else{ + + $data['employee_id']= $value->employee_id; + $data['client_policy_id']= $value->client_policy_id; + $data['basic_cover_si']= $value->basic_cover_si; + $data['status'] = 'draft'; + + $this->employeePolicyModel->insert($data); + } + } + + $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code); + + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + } + + public function findPremiumAmount($slabArray,$siAmount) + { + foreach ($slabArray as $key => $value) { + if($value['si'] == $siAmount){ + return $value['premium']; + break; + } + } + } + + public function relationshipList() + { + try { + + $relation_ships= $this->relationshipModel->findAll(); + + if(count($relation_ships) > 0){ + return $this->respond(['status' => 'success','code' => 200,'data' => $relation_ships], 200); + }else{ + return $this->respond(['status' => 'success','code' => 200,'data' => "No Data..!"], 200); + } + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + } public function getEmployeeAndDependenceByClientId() { @@ -422,7 +489,6 @@ class EmployeeRestController extends AdminController } - public function exportDataByClientPolicyId() { try { @@ -500,6 +566,7 @@ class EmployeeRestController extends AdminController } + //not in use public function getClientPolicy() { try { @@ -538,73 +605,7 @@ class EmployeeRestController extends AdminController - // Get the RelationShip list - public function createOrUpdateEmployeePolicySiAmount() - { - - try { - $requestData = $this->request->getJSON(); - - foreach ($requestData as $key => $value) { - - - $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id) - ->where('client_policy_id', $value->client_policy_id) - ->where('is_active', 1 ) - ->findAll(); - - - // dd($checkIfExist); - if ($checkIfExist) { - - $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si); - - }else{ - - $data['employee_id']= $value->employee_id; - $data['client_policy_id']= $value->client_policy_id; - $data['basic_cover_si']= $value->basic_cover_si; - $data['status'] = 'draft'; - - $this->employeePolicyModel->insert($data); - } - } - - $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code); - - return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); - - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - } - } - - public function findPremiumAmount($slabArray,$siAmount) - { - foreach ($slabArray as $key => $value) { - if($value['si'] == $siAmount){ - return $value['premium']; - break; - } - } - } - public function relationshipList() - { - try { - - $relation_ships= $this->relationshipModel->findAll(); - - if(count($relation_ships) > 0){ - return $this->respond(['status' => 'success','code' => 200,'data' => $relation_ships], 200); - }else{ - return $this->respond(['status' => 'success','code' => 200,'data' => "No Data..!"], 200); - } - - } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - } - } // Upload the Employee Detail in DB by Sheet Data public function employeeUpload() @@ -618,6 +619,7 @@ class EmployeeRestController extends AdminController // die; $file = $this->request->getFile('file'); $client_id = $this->request->getPost('client_id'); + $client_branch_id = $this->request->getPost('client_branch_id'); $policy_id = $this->request->getPost('policy_id'); $client_data = $this->clientModel->where('id', $client_id)->first(); @@ -636,7 +638,7 @@ class EmployeeRestController extends AdminController - $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->first(); + $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->where('client_branch_id', $client_branch_id)->first(); if ($client_policy) { $policy = $this->policesModel->where('id', $client_policy['policy_id'])->first(); $policy_permium_1 = $this->policyPremium1Model->where(['client_id' => $client_id , 'client_policy_id' => $policy_id,'is_active' =>1])-> first(); @@ -670,6 +672,7 @@ class EmployeeRestController extends AdminController $extractData['file_name']= $filename; $extractData['client_id']= $client_id; + $extractData['client_branch_id']= $client_branch_id; $extractData['status']= 'success'; $extractData['policy_id']= $policy_id; $extractData['action']= 'enrollment'; @@ -932,6 +935,7 @@ public function getAgeRange($terms,$familyFloatesValue) } + public function getEmployeePolicy() { try { @@ -1266,6 +1270,7 @@ public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id,$cl } } + public function FloterConvertion($array){ $result = []; @@ -1806,6 +1811,7 @@ public function getCashDepositData() ->join('policies', 'client_policy.policy_id = policies.id', 'left') ->where('client_policy.insurer_id', $value['insurerId'] ) ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) ->where('client_policy.is_active', 1 ) ->where('client_policy.policy_status', 1) ->findAll(); From 499ed67fdd35392c4b57f9d8405126b18300d99d Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Wed, 29 May 2024 18:11:51 +0530 Subject: [PATCH 08/16] CHANGE_HEADER_HELPDESK_URL_SET : AADHAVAN --- app/Views/layout/header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 9cc606ba..9c6a4795 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -590,7 +590,7 @@ $parsedUrl = parse_url($currentUrl); $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . '/'; $hashedEmail = hash('sha256', $sessionData->email); - $redirectUrl = $baseUrl . getenv('hepldeskURL') .'/staff/login?' . http_build_query(['token' => $hashedEmail]); + $redirectUrl = getenv('helpdeskURL') .'/staff/login?' . http_build_query(['token' => $hashedEmail]); ?> From c69d9747113d89e3c0fd3c28c47d3f7be4dcd4d8 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 30 May 2024 10:24:47 +0530 Subject: [PATCH 09/16] CHANHE_ in emplayee upload API : GWM --- app/Controllers/EmployeeRestController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 09dff202..0bbe620c 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -874,6 +874,7 @@ class EmployeeRestController extends AdminController foreach ($employee_policy as $existing_policy) { $emp_policy_data['id']= $existing_policy['id']; $emp_policy_data['updated_at'] = $formatted_date_time; + $emp_policy_data['client_branch_id'] = $client_branch_id; $this->employeePolicyModel->save($emp_policy_data); } } else { From 8326b3c1f02df9a8fcfb40dae422962702d41810 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 30 May 2024 10:39:46 +0530 Subject: [PATCH 10/16] CHANHE_ in emplayee upload API : GWM --- app/Controllers/EmployeeRestController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0bbe620c..3c51bae9 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -779,6 +779,7 @@ class EmployeeRestController extends AdminController 'client_id' => $client_id, 'emp_status'=>'draft', 'band'=> $extra['10'][$index], + 'client_branch_id' => $client_branch_id ]; $basic_cover_si_value = null; @@ -874,7 +875,6 @@ class EmployeeRestController extends AdminController foreach ($employee_policy as $existing_policy) { $emp_policy_data['id']= $existing_policy['id']; $emp_policy_data['updated_at'] = $formatted_date_time; - $emp_policy_data['client_branch_id'] = $client_branch_id; $this->employeePolicyModel->save($emp_policy_data); } } else { From a2ebc9bea7b00f2452959bf858a022e643379746 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 30 May 2024 15:17:05 +0530 Subject: [PATCH 11/16] CHANGE_SI_ENHANCEMENT_HIDE_SHOW_IN_DROP_DOWN_DELETE_ADDITIONAL_RACK_RATE_DATE : RV --- app/Config/Routes.php | 10 +- app/Config/Session.php | 3 +- app/Controllers/ClientController.php | 37 +++++- app/Controllers/DashboardController.php | 18 ++- app/Controllers/EmployeeController.php | 41 +++++- app/Helpers/sendMailNotification.php | 4 +- app/Helpers/session_helper.php | 31 +++++ app/Models/ClientModel.php | 13 +- app/Views/client_branch.php | 2 +- app/Views/client_policy.php | 9 +- app/Views/employee_upload.php | 22 ++-- app/Views/insurer_or_tpa_data.php | 2 +- app/Views/layout/footer.php | 22 ++-- app/Views/notification.php | 3 +- app/Views/policy_grid.php | 159 +++++++++++++++++++++--- 15 files changed, 317 insertions(+), 59 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a32b6788..7e69c587 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -23,12 +23,6 @@ $routes->get('download-e-card/(:any)', 'EmployeeController::generateIDCardForEmp $routes->get('download-kyc-docs/(:segment)', 'ClientController::downloadKYCDocument/$1'); -$routes->get('get-notification', 'DashboardController::getDashboardNotifications'); -$routes->get('acknowledge-notification/(:segment)', 'DashboardController::acknowledgeMessage/$1'); -$routes->get('get-pending-action', 'PendingActionsController::getPendingActions'); - - - $routes->group("/user", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "UserController::create"); $routes->get("create", "UserController::create"); @@ -42,6 +36,9 @@ $routes->group("/user", ["filter" => "authMVC"], function ($routes) { $routes->group("/dashboard", ["filter" => "authMVC"], function ($routes) { $routes->get("view", "DashboardController::dashboard"); + $routes->get('get-notification', 'DashboardController::getDashboardNotifications'); + $routes->get('acknowledge-notification/(:segment)', 'DashboardController::acknowledgeMessage/$1'); + $routes->get('get-pending-action', 'PendingActionsController::getPendingActions'); }); @@ -236,6 +233,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("has_policy_config_completed/(:any)", "EmployeeController::hasPolicyConfigCompleted/$1"); $routes->get("get-client-branch/(:any)", "ClientController::getClientBranch/$1"); $routes->get("get-client-details/(:any)", "ClientController::getClientAllDetailsByUsingClientID/$1"); + $routes->get("delete-additional-rack-rate/(:any)", "ClientController::deleteAdditionalRackRate/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); diff --git a/app/Config/Session.php b/app/Config/Session.php index 591aefdc..e077df64 100644 --- a/app/Config/Session.php +++ b/app/Config/Session.php @@ -40,8 +40,7 @@ class Session extends BaseConfig * The number of SECONDS you want the session to last. * Setting to 0 (zero) means expire when the browser is closed. */ - // public int $expiration = 7200; - public int $expiration = 86400; //24 Hours + public int $expiration = 7200; /** * -------------------------------------------------------------------------- diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 7a9e9263..033300aa 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -169,8 +169,9 @@ class ClientController extends AdminController // echo "
    ";
             // print_r($data); die;
    -        $data['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'client_name'];
    +        $data['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
     
    +        // dd($data['placeHolders']);
     
             echo view('layout/header', $headerData);
             echo view('client_onboarding', $data);
    @@ -283,7 +284,7 @@ class ClientController extends AdminController
             
     
             $editData['notification'] =$this->notificationModel->select('template_name,enabled')->where('client_id',$id)->findAll();
    -        $editData['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'client_name'];
    +        $editData['placeHolders'] = ['member_name','nhance_logo','tpa_id','ecard_download_link', 'client_logo', 'policy_no', 'member_summary', 'app_link', 'post_enrollment_app_link', 'client_name'];
     
     
             echo view('layout/header', $headerData);
    @@ -591,7 +592,7 @@ class ClientController extends AdminController
             $policyCount = $this->clientPolicyModel
             ->where('policy_id', $policy_id) 
             ->where('client_branch_id', $client_branch_id)
    -        ->countAllResult(); 
    +        ->countAllResults(); 
     
             if($policyCount > 0 ){
                 $clientPoliceData =  $this->clientPolicyModel->getClientPolicyByClientId($this->request->getPost('client_id'));
    @@ -809,8 +810,8 @@ class ClientController extends AdminController
                 $relation_data['spouse'] = $spouse;
                 $relation_data['childrens'] = $childrens;
                 $relation_data['parents'] = $parents;
    -            $relation_data['parents_in_law'] = $parents_in_law;
    -            $relation_data['either_parents_pil'] = $either_parents_pil;
    +            $relation_data['parents-in-law'] = $parents_in_law;
    +            $relation_data['either-parents-pil'] = $either_parents_pil;
     
     
                 $jsonDataForRelation = json_encode($relation_data);
    @@ -2094,5 +2095,31 @@ class ClientController extends AdminController
         }
     
     
    +    public function deleteAdditionalRackRate($client_id, $client_policy_id, $rack_rate_type)
    +    {
    +        try {
    +            $result = $this->policyPremium2Model
    +                ->where('client_id', $client_id)
    +                ->where('client_policy_id', $client_policy_id)
    +                ->where('rack_rate_type', $rack_rate_type)
    +                ->set('is_active', 0)
    +                ->update();
    +    
    +            if (!$result) {
    +
    +                return $this->respond(['status' => false,'code' => 200, 'message' => 'Failed to update the record.'], 200);
    +            }
    +        } catch (\Exception $e) {
    +
    +            log_message('error', $e->getMessage());
    +            return $this->respond(['status' => false,'code' => 200, 'message' => 'Failed to update the record.'], 200);
    +
    +        }
    +    
    +        return $this->respond(['status' => true,'code' => 200, 'message' => 'Additionaly Rack Rate Data Remove Successfully'], 200);
    +    }
    +    
    +
    +
     
     }
    \ No newline at end of file
    diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php
    index 1378abbf..8642c0a5 100644
    --- a/app/Controllers/DashboardController.php
    +++ b/app/Controllers/DashboardController.php
    @@ -18,11 +18,14 @@ class DashboardController extends AdminController
         use ResponseTrait;
         protected $messageModel;
         protected $userMessageModel;
    +    protected $myLogger;
         
         public function __construct()
         {
    +        set_session_context('Dashboard');
             $this->messageModel        = new MessageModel();
             $this->userMessageModel    = new UserMessageModel();
    +        $this->myLogger = \Config\Services::mylogger();
         }
     
         public function dashboard()
    @@ -34,15 +37,20 @@ class DashboardController extends AdminController
     
         public function getDashboardNotifications()
         {
    -        //pull notofications to dashboard especially for file upload cases
    +        // Pull notifications for the dashboard, especially for file upload cases.
             $userId = get_session_userid();
             $roleId = 5;
             $teamId = 1;
    -
    -        $messages = $this->messageModel->getMessagesForUser($userId, $roleId, $teamId);
    -
    -        return $this->respond($messages);
    +    
    +        if ($userId != null && $roleId != null && $teamId != null) {
    +            $messages = $this->messageModel->getMessagesForUser($userId, $roleId, $teamId);
    +            return $this->respond(['status' => true, 'code' => 200, 'message' => $messages], 200);
    +        } else {
    +            $this->myLogger->logme('error', 'The session is not set correctly. USER_ID : {user_id},  ROLE_ID : {role_id},  TEAM_ID : {team_id}', ['user_id' => $userId, 'role_id' => $roleId, 'team_id' => $teamId]);
    +            return $this->respond(['status' => false, 'code' => 404, 'message' => 'No data found'], 200);
    +        }
         }
    +    
     
         public function acknowledgeMessage($messageId)
         {
    diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
    index 77a14554..3e73f9a8 100644
    --- a/app/Controllers/EmployeeController.php
    +++ b/app/Controllers/EmployeeController.php
    @@ -1040,6 +1040,34 @@ class EmployeeController extends AdminController
         {
     
             $this->loadLayout('ecard_template/default_ecard');
    +        
    +        // Load the session library if it's not autoloaded
    +        // $session = \Config\Services::session();
    +        
    +        // Access session data
    +        $sessionData = session()->get();
    +        
    +        // Check if session data exists and if expiration time is set
    +        if (!empty($sessionData) && isset($sessionData['isLoggedIn']) && isset($sessionData['session_expiration'])) {
    +            // Get the session expiration timestamp
    +            $expirationTimestamp = $sessionData['session_expiration'];
    +        
    +            // Get the current timestamp
    +            $currentTimestamp = time();
    +        
    +            // Check if the current time is greater than the expiration time
    +            if ($currentTimestamp > $expirationTimestamp) {
    +                // Session has expired
    +                echo "Session has expired";
    +            } else {
    +                // Session is active
    +                echo "Session is active";
    +            }
    +        } else {
    +            // Session data is not set or session is not started
    +            echo "Session is not started or data is not set";
    +        }
    +        
         }
     
     
    @@ -1253,9 +1281,18 @@ class EmployeeController extends AdminController
         {
             $client_policy_id = $this->request->uri->getSegment(3);
             $policy_details = $this->clientPolicyModel->find($client_policy_id);
    -        // print_r($policy_details);die();
             $policy_terms = isset($policy_details['policy_terms']) ? true : false;
     
    +        $si_enhancement_true_or_false = 1;
    +        if($policy_terms){
    +            $policyTermsData = json_decode($policy_details['policy_terms']);
    +
    +            if (isset($policyTermsData->suminsuredenhancement) && $policyTermsData->suminsuredenhancement !== null) {
    +                $si_enhancement_true_or_false = $policyTermsData->suminsuredenhancement;
    +            }        
    +        }
    +        
    +
             $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$policy_details['client_id']);
     
             $message = null;
    @@ -1270,7 +1307,7 @@ class EmployeeController extends AdminController
             }
             $message  = isset($message) ? ($message . ' not defined for choosed policy') : null;
     
    -            return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message], 200);
    +        return $this->respond(['dataStatus' => true, 'code' => 200, 'message' => $message, 'si_enhancement' => $si_enhancement_true_or_false], 200);
             
         }
     
    diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php
    index cfc96b17..0c8c7067 100644
    --- a/app/Helpers/sendMailNotification.php
    +++ b/app/Helpers/sendMailNotification.php
    @@ -105,6 +105,7 @@ class sendMailNotification
                 $name =  $get_emp_email_and_other_details['name'];
                 $mail_content = $notification['mail_content'];
                 $nhance_logo = $_ENV['NHANCE_LOGO'];
    +            $post_enrollment_app_link = $_ENV['POST_ENROLLMENT_APP_LINK'];
                 
                 $client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo'];
                 // $client_logo = $nhance_logo;
    @@ -114,8 +115,9 @@ class sendMailNotification
     
                 $mail_content = str_replace("[[member_name]]", $name, $mail_content);
                 $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content);
    +            $mail_content = str_replace("[[post_enrollment_app_link]]", "Review Details", $mail_content);
                 // $mail_content = str_replace("[[tpa_id]]", $tpa_id, $mail_content);
    -            $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content);
    +            $mail_content = str_replace("[[ecard_download_link]]", "Download Insurance Card", $mail_content);
                 $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
     
                 $wholeData =  ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails']];
    diff --git a/app/Helpers/session_helper.php b/app/Helpers/session_helper.php
    index 6e879e4b..ce6a0f56 100644
    --- a/app/Helpers/session_helper.php
    +++ b/app/Helpers/session_helper.php
    @@ -10,6 +10,37 @@ if (!function_exists('check_session')) {
         }
     }
     
    +if (!function_exists('set_last_visited_time')) {
    +    function set_last_visited_time()
    +    {
    +        $session = \Config\Services::session();
    +        $session->set('last_visited', date("Y-m-d H:i:s"));
    +    }
    +}
    +
    +if (!function_exists('get_last_visited_time')) {
    +    function get_last_visited_time()
    +    {
    +        // Get the session service
    +        $session = \Config\Services::session();
    +
    +        // Get the last visited time from session
    +        $lastVisitTime = $session->get('last_visited');
    +
    +        // Check if the last visited time is set
    +        if ($lastVisitTime) {
    +            // Calculate the time five minutes ago
    +            $fiveMinutesBefore = date("YmdHi", strtotime('-5 minutes'));
    +
    +            // Compare the last visited time with the time five minutes ago
    +            return date("YmdHi", strtotime($lastVisitTime)) > $fiveMinutesBefore ? 1 : 0;
    +        }
    +
    +        // If last visited time is not set, return 0
    +        return 0;
    +    }
    +}
    +
     if (!function_exists('get_session_userid')) {
         function get_session_userid()
         {
    diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php
    index 35beeb4c..fd1e8510 100644
    --- a/app/Models/ClientModel.php
    +++ b/app/Models/ClientModel.php
    @@ -42,7 +42,18 @@ class ClientModel extends Model
     
                 foreach ($clients as &$client) {
                     $clientPolicyModel = new ClientPolicyModel();
    -                $clientPolicies = $clientPolicyModel->select(['client_branch.id as branch_id','client_branch.branch_name','client_branch.branch_code', 'client_branch.client_id', 'client_policy.id as client_policy_id','p.name','pt.policy_type',])
    +                $clientPolicies = $clientPolicyModel
    +                                  ->select(['
    +
    +                                        client_branch.id as branch_id',
    +                                        'client_branch.branch_name',
    +                                        'client_branch.branch_code', 
    +                                        'client_branch.client_id', 
    +                                        'client_policy.id as client_policy_id',
    +                                        'client_policy.policy_terms',
    +                                        'p.name',
    +                                        'pt.policy_type',
    +                                    ])
                                       ->join('client_branch', 'client_branch.id = client_policy.client_branch_id') 
                                       ->join('policies p', 'p.id = client_policy.policy_id') 
                                       ->join('policy_type pt','client_policy.policy_type_id = pt.id')
    diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php
    index c788731c..93ea7137 100644
    --- a/app/Views/client_branch.php
    +++ b/app/Views/client_branch.php
    @@ -234,7 +234,7 @@ $(document).ready(function () {
         $("#branch_form").submit(function(event) {
     
             event.preventDefault(); 
    -        branch_PrimaryKey = $('#client_id_for_client_branch').val();
    +        branch_PrimaryKey = $('#client_id_branch').val();
     
             console.log('branch_PrimaryKey', branch_PrimaryKey)
             
    diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php
    index bb844432..ab4e17f4 100644
    --- a/app/Views/client_policy.php
    +++ b/app/Views/client_policy.php
    @@ -47,7 +47,7 @@
                                 
    @@ -1468,6 +1468,13 @@ $('#client_branch').empty(); + + $('#client_branch').append($('"; + echo ""; } } ?> @@ -351,9 +351,10 @@ function fetchClientPolicies() { }, success: function(response) { - // console.log(response); + console.log(response); // console.log(response.dataStatus); // console.log(response.data); + if (response.code === 200 && response.dataStatus === true && response.data !== "") { try { clientPolicies = (response.data) @@ -910,7 +911,7 @@ function checkPolicyTermsAndRackRatesHasDefiend(event) { // console.log(event.target.id); var policy_id = (event.target.value); - // console.log('checkPolicyTermsAndRackRatesHasDefiend called ' + policy_id); + console.log('checkPolicyTermsAndRackRatesHasDefiend called ' + policy_id); if(policy_id != 0 && policy_id != " " && policy_id != undefined) { var apiURL = '' + 'util/has_policy_config_completed/' + policy_id; @@ -930,11 +931,18 @@ function checkPolicyTermsAndRackRatesHasDefiend(event) success: function(response) { setTimeout(function() { - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - }, 1000); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + }, 1000); + + console.log('check policy responce', response); + + if (response.hasOwnProperty('si_enhancement') && response.si_enhancement == 0) { + $('.si-enhancement-option').hide(); + } else { + $('.si-enhancement-option').show(); + } - // console.log('check policy responce', response); if (response.code === 200 && response.dataStatus === true && response.message !== null) { toastr.error(response.message, 'Error'); diff --git a/app/Views/insurer_or_tpa_data.php b/app/Views/insurer_or_tpa_data.php index 48cc73a1..c068ec39 100644 --- a/app/Views/insurer_or_tpa_data.php +++ b/app/Views/insurer_or_tpa_data.php @@ -76,7 +76,7 @@ $action) { - echo ""; + echo ""; } } ?> diff --git a/app/Views/layout/footer.php b/app/Views/layout/footer.php index 114184f7..35093e66 100644 --- a/app/Views/layout/footer.php +++ b/app/Views/layout/footer.php @@ -155,27 +155,28 @@ function fetchMessages() { $.ajax({ - url: '', + url: '', method: 'GET', success: function(response) { - // $(document).ready(function() { - // $("#playMusic").get(0).play(); - // }); + console.log('responce', response) - - //console.log('responce', response) + if(response.status == false){ + $('#notification_count').html('0') + console.log('The session is not set correctly. ') + return; + } let messagesList = $('#messages-list'); messagesList.empty(); var html = ""; - pullNotificationCount = response.length + pullNotificationCount = response.message.length localStorage.setItem('pullNotificationCount', pullNotificationCount) - response.forEach(message => { + response.message.forEach(message => { // if (!message.is_read) { // unreadCount++; @@ -183,7 +184,6 @@ var jasonDecodeData = JSON.parse(message.message_text) - var toast_body_css = 'background : #bfd7eb !important;'; var toast_head_css = 'background-color : rgb(2, 168, 181) !important; color :#000; border-bottom: 0;'; var toast_icon = 'mdi mdi-checkbox-marked-circle mr-auto'; @@ -247,7 +247,7 @@ function acknowledgeMessage(messageId) { $.ajax({ - url: '' + messageId, + url: '' + messageId, method: 'GET', success: function(response) { fetchMessages(); @@ -300,7 +300,7 @@ $.ajax({ - url: '', + url: '', method: 'GET', success: function(response) { diff --git a/app/Views/notification.php b/app/Views/notification.php index 124094f5..feffdae3 100644 --- a/app/Views/notification.php +++ b/app/Views/notification.php @@ -370,7 +370,8 @@ - - +
    @@ -110,7 +110,7 @@
    @@ -130,9 +130,19 @@
    -

    + - Copy from excel +
    + + + + + +

    @@ -861,7 +871,10 @@ $("#GridForm").submit(function(event) { $('.loader-mask').delay(350).fadeOut('slow'); var message = (policy_PrimaryKey === '') ? 'Policy Premium Added successfully' :'Policy Premium Added Successfully'; toastr.success(message, 'Success'); - // $('.close').click(); + + if($('#grid').val() == 1 || $('#grid').val() == 2){ + $('.close').click(); + } }, error: function(xhr, status, error) { @@ -887,6 +900,10 @@ $("#AdditionalGridForm").submit(function(event) { return; } + if (!checkCheckboxes()) { + event.preventDefault(); + } + var isValid = $('#AdditionalGridForm').parsley().validate(); if (!isValid) { console.log('Form is Empty', 'Warning'); @@ -987,10 +1004,14 @@ $('body').on('click', '.btnPolicyModel', function() { dataType: 'json', success: function(res) { - if (res.self == "") { - $('.close').click(); - toastr.warning('Unable to create rack rate due to the absence of policy terms.', - 'Warning'); + if(policy_type_string == 'GMC'){ + + if (res.self == "") { + $('.close').click(); + toastr.warning('Unable to create rack rate due to the absence of policy terms.', + 'Warning'); + } + } $('#GridForm')[0].reset(); @@ -998,7 +1019,7 @@ $('body').on('click', '.btnPolicyModel', function() { if (policy_type_string == 'GMC') { $('#premium_type').show(); - $('#individual').prop('checked', true) + $('#individual').prop('checked', true) } else { $('#premium_type').hide(); $('#individual').prop('checked', true) @@ -1047,10 +1068,10 @@ $('body').on('click', '.btnPolicyModel', function() { if (res.premiumData && res.premiumData.length > 0) { $.each(res.premiumData, function(index, item) { - if (item.rack_rate_type == 0) { + if (item.rack_rate_type == 0 || policy_type_string == 'GPA') { policy_grid_id_value = item.policy_grid_id; secondary = item.policy_grid_id; - premium_type_for_sec_rr.push(item.premium_type); + premium_type_for_primary_rr.push(item.premium_type); } else if (item.rack_rate_type == 1) { @@ -1063,6 +1084,14 @@ $('body').on('click', '.btnPolicyModel', function() { } + console.log('premium_type_for_sec_rr', premium_type_for_sec_rr) + + if(premium_type_for_sec_rr.length > 0){ + $('#del_btn_col').show(); + }else{ + $('#del_btn_col').hide(); + } + if (premium_type_for_sec_rr.length > 0) { @@ -1081,6 +1110,10 @@ $('body').on('click', '.btnPolicyModel', function() { $('#single_2').prop('checked', false) $('#individual_2').prop('checked', true) } + }else{ + + $('#single_2').prop('checked', false) + $('#individual_2').prop('checked', true) } @@ -1129,6 +1162,9 @@ $('body').on('click', '.btnPolicyModel', function() { $('#single').prop('checked', false); $('#individual').prop('checked', true); } + }else{ + $('#single').prop('checked', false); + $('#individual').prop('checked', true); } @@ -2616,7 +2652,7 @@ function createCheckboxes(obj, additional_relationship) { console.log('isChecked', isChecked); html += `
    - +
    `; // console.log(html); @@ -2627,8 +2663,101 @@ function createCheckboxes(obj, additional_relationship) { } - function formatString(str) { return str.split('-').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' '); } + + +$('#del_btn').click(function() { + console.log('delete btn clicked'); + + Swal.fire({ + title: "Are you sure?", + text: "You need to Delete this!", + icon: "warning", + showCancelButton: true, + confirmButtonColor: "#3085d6", + confirmButtonText: "Yes", + }).then((result) => { + console.log('after then entered'); + + if (result.isConfirmed) { + console.log('isConfirmed entered'); + + var client_policy_id = $('#client_policy_id_2').val(); + console.log('client_policy_id', client_policy_id) + + var rack_rate_type = $('#rack_rate_type_2').val(); + console.log('rack_rate_type', rack_rate_type) + + var client_id = $('#Client_id_2').val(); + console.log('client_id', client_id) + + + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); + + $.ajax({ + url: '' + client_id + '/' + client_policy_id + '/' + rack_rate_type, + type: 'GET', + success: function(res) { + + console.log('ajax success entered'); + console.log(res); + + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + + if (res.status === true) { + + $('#additional_grid_content_input').empty(); + $('#additional_grid').val(''); + $('#individual_2').prop('checked', true) + $('#single_2').prop('checked', false) + $('input[type="checkbox"]').prop('checked', false); + + + toastr.success(res.message, 'Success'); + + } else if (res.status === false) { + toastr.warning(res.message, 'Warning'); + return; + } + }, + error: function(xhr, status, error) { + console.log('ajax error entered'); + console.error(xhr.responseText); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + } + }); + + // Removed the duplicated loader hiding code here + } + + console.log('after then entered end or cancel'); + }); + + console.log('delete btn clicked end'); +}); + + +function checkCheckboxes() { + var checkboxes = $('input.relation_checkbox'); + var checkedCount = checkboxes.filter(':checked').length; + var uncheckedCount = checkboxes.not(':checked').length; + + console.log('Checked count:', checkedCount); // Debugging + console.log('unchecked Count', uncheckedCount); + + if (checkedCount < 1) { + toastr.warning('You must select at least one checkbox.', 'Warning'); + return false; + } else if (checkedCount != uncheckedCount) { + toastr.warning('You can not select all of the checkboxes', 'Waraning'); + return false; + } + return true; +} + \ No newline at end of file From 183cbd7fffbbfb780cd7892ce5fbd92d488376f8 Mon Sep 17 00:00:00 2001 From: bitbucket Date: Fri, 31 May 2024 09:08:40 +0530 Subject: [PATCH 12/16] CHANGE_ AccountManagerDetails attached in getEmployeeProfile API : GWM --- app/Config/Routes.php | 4 ---- app/Controllers/EmployeeRestController.php | 7 ++++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a32b6788..d1a18cb3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -258,12 +258,8 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { -$routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/$1"); -$routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile"); -$routes->post("/calculatePremium", "EmployeeRestController::calculatePremium"); -$routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 3c51bae9..c31cabe7 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -94,7 +94,12 @@ class EmployeeRestController extends AdminController ->where('relationship', $relationship) ->first(); $result = $employee; - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + $AccountManagerDetails = $this->clientRMModel->select('client_rm.* , user_profiles.*') + ->join('user_profiles', 'client_rm.user_id = user_profiles.id', 'left') + ->where('client_rm.client_id', $client_id ) + ->where('client_rm.level', 3 ) + ->findAll(); + return $this->respond(['status' => 'success','code' => 200,'data' => $result, 'AccountManagerDetails'=> isset($AccountManagerDetails[0]) ? $AccountManagerDetails[0] : null ],200); } else { $result = "No Match's"; return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404); From 6d404cfae57910fc2d5f5e1e7e1a119291b5280b Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 31 May 2024 13:22:46 +0530 Subject: [PATCH 13/16] CHANGE_JWT_CHECK : AADHAVAN --- app/Config/Routes.php | 4 +--- app/Helpers/JWTToken.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a32b6788..5e98d503 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -243,6 +243,7 @@ $routes->cli('cli/processjobs', 'JobWorker::processJobs'); $routes->get("processjob", "JobWorker::processJob"); + //Employee login api's $routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); $routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); @@ -255,9 +256,6 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->post("getId", "RestAuthenticationController::getUserIdFromToken"); }); - - - $routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/$1"); $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile"); $routes->post("/calculatePremium", "EmployeeRestController::calculatePremium"); diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 6c6d29cf..3d86be20 100644 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -20,7 +20,7 @@ class JWTToken { $secret_Key="secret"; $iat = time(); - $exp = $iat + 36000; + $exp = $iat + 120; $request_data = [ "iat" => $iat, "exp" => $exp, From a026f7799d972f3230a4440867c1ccb9c94f8f10 Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 31 May 2024 16:36:34 +0530 Subject: [PATCH 14/16] CHANGE_JWT_TIME_SET : AADHAVAN --- app/Filters/AuthJWT.php | 10 +++++++++- app/Helpers/JWTToken.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php index a9b6911f..456b2e6f 100644 --- a/app/Filters/AuthJWT.php +++ b/app/Filters/AuthJWT.php @@ -24,9 +24,17 @@ class AuthJWT implements FilterInterface if (JWTToken::validateJWT($jwt)) { $data = JWTToken::validateJWT($jwt); $data = json_decode($data); + if ($data->status) { // $auth = $request->getHeader("Authorization"); - + // $decodedToken = $data->decoded; + + // $decodedToken->exp += 30; + // $newJwt = JWTToken::encode((array)$decodedToken); + + // Set the new JWT in the response headers + // $response = service('response'); + // $response->setHeader('Authorization', $newJwt); return true; }else{ header('Content-Type: application/json'); diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 3d86be20..3eae594c 100644 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -20,7 +20,7 @@ class JWTToken { $secret_Key="secret"; $iat = time(); - $exp = $iat + 120; + $exp = $iat + 9000; $request_data = [ "iat" => $iat, "exp" => $exp, From 17bc0b9911b8c8fb940e98c70751a3c8c7cf690f Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 31 May 2024 16:37:57 +0530 Subject: [PATCH 15/16] CHANGE_JWT_TIME_SET_THREE_MIN : AADHAVAN --- app/Helpers/JWTToken.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index 3eae594c..dc381fa1 100644 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -20,7 +20,7 @@ class JWTToken { $secret_Key="secret"; $iat = time(); - $exp = $iat + 9000; + $exp = $iat + 180; $request_data = [ "iat" => $iat, "exp" => $exp, From d9c9209286961032e1a382dd481d6c3eab375ce8 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 3 Jun 2024 10:06:15 +0530 Subject: [PATCH 16/16] CHANGE_ALL_IMPORT_EXPORT_FUNCTION_TO_CHECK_VALIDATION_AND_CONVERT_TO_JOB : RV --- app/Controllers/ClientController.php | 5 +- app/Controllers/EmpDataServiceController.php | 2151 ++++++++++++------ app/Controllers/EmployeeController.php | 184 +- app/Controllers/JobWorker.php | 12 + app/Models/EmployeePolicyModel.php | 253 +- app/Views/client_policy.php | 6 +- app/Views/employee_upload.php | 57 +- app/Views/file_list.php | 6 +- app/Views/policy_grid.php | 7 +- app/Views/view_file_upload_emp_list.php | 2 +- 10 files changed, 1886 insertions(+), 797 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 033300aa..52b3dbca 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -586,11 +586,11 @@ class ClientController extends AdminController $this->myLogger->logme('error','Client policy CREATE function called'); - $policy_id = $this->request->getPost('policy_id'); + $policy_type_id = $this->request->getPost('policy_type_id'); $client_branch_id = $this->request->getPost('client_branch_id'); $policyCount = $this->clientPolicyModel - ->where('policy_id', $policy_id) + ->where('policy_type_id', $policy_type_id) ->where('client_branch_id', $client_branch_id) ->countAllResults(); @@ -816,7 +816,6 @@ class ClientController extends AdminController $jsonDataForRelation = json_encode($relation_data); - // if($policy_grid_id == 10 || $policy_grid_id == 11){ // $premium_type = 1; // }else{ diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 9ea04893..6325255f 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -111,7 +111,7 @@ class EmpDataServiceController extends BaseController $batch_list_data['batch_code'] = $params['batch_code']; $batch_list_data['emp_policy_id'] = $value['primaryKey']; - $batch_list_data['created_by'] = get_session_userid(); + $batch_list_data['created_by'] = $params['user_id']; $this->batchListModel->insert($batch_list_data); } @@ -133,30 +133,29 @@ class EmpDataServiceController extends BaseController public function generateExcelForAdditionandInception($export_data) { - $return = $this->removeOldExportInfoFromBatchFile($export_data); - // Fetch employee data for export from the database $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); - $insurer_id = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first(); - $cash_balance = $this->clientDepositModel->where('client_id', $export_data['client_id'])->where('insurer_id', $insurer_id['insurer_id'])->orderBy('id', 'DESC')->first(); - $totals = 0; - foreach ($objects as $key => $value) { + // Calculate the total amount from the objects + $totals = array_reduce($objects, function ($carry, $item) { + return $carry + $item->total; + }, 0); + + $totals = round($totals, 2); + + $this->removeOldExportInfoFromBatchFile($export_data); - $totals += $value->total; - } if (!empty($cash_balance)) { if ((int) $cash_balance['balance'] < (int) $totals) { + $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.'); return 0; } - } else { - // return 0; } @@ -171,6 +170,8 @@ class EmpDataServiceController extends BaseController // If no data is found for export, return false if ($count == 0) { + + $this->myLogger->logme('error', 'No Record found. TPA ID or UHID are Alread Updated. Correction export data count : {data}', ['data' => $count]); return false; } @@ -212,30 +213,35 @@ class EmpDataServiceController extends BaseController // If Excel generation is successful if ($success) { - - // Batch files and list entry - // $return = $this->batchFilesAndBatchListEntry($export_data, $objects); - $random_number_count = 4; $export_data['batch_code'] = generate_random_string($random_number_count); $export_data['created_by'] = get_session_userid(); - + $insert = $this->batchFileModel->insert($export_data); $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); $batch_code = $batch_file_batch_code['batch_code']; // $this->insertBatchList(['batch_code' => $batch_code, 'batch_list_data' => $objects ]); - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'insertBatchList','payload' => ['batch_code' => $batch_code, 'batch_list_data' => $objects ]]); + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'insertBatchList', 'payload' => ['batch_code' => $batch_code, 'user_id' => get_session_userid(), 'batch_list_data' => $objects]]); // If batch operation is successful if (true) { + + // Clear the output buffer to avoid any unwanted output + if (ob_get_level()) { + ob_end_clean(); + } + // Set headers for Excel file download header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); - header('Cache-Control: max-age=0'); + header('Content-Disposition: attachment; filename="' . $export_data['file_name'] . '"'); + header('Content-Transfer-Encoding: binary'); + header('Cache-Control: must-revalidate'); + header('Pragma: public'); + header('Expires: 0'); // Output file contents rewind($tempFile); @@ -247,7 +253,7 @@ class EmpDataServiceController extends BaseController return true; // Excel file successfully generated and exported } else { - + return false; // Batch operation failed } } @@ -266,17 +272,18 @@ class EmpDataServiceController extends BaseController $ids[] = $obj->id; } - // echo '
    ';
    -        // print_r($objects); die;
    -
             $count = count($objects);
             $export_data['count'] = $count;
             $this->myLogger->logme('error', 'Correction export data count : {data}', ['data' => $count]);
     
             if ($count == 0) {
    -            return false;
    +            $this->myLogger->logme('error', 'No Record found. Endorsement ID Alread Updated.  Correction export data count : {data}', ['data' => $count]);
    +            return false;  
             }
     
    +        $this->removeOldExportInfoFromBatchFile($export_data);
    +
    +
             $this->myLogger->logme('error', 'Correction export file name : {data}', ['data' => $export_data['file_name']]);
     
             $correction_data = transform_objects_to_array_for_correction($objects);
    @@ -302,7 +309,11 @@ class EmpDataServiceController extends BaseController
             $value = generate_excel($headers, $correction_data, $tempFile);
     
             if ($value) {
    +
    +
    +
                 $return = $this->batchFilesAndBatchListEntry($export_data, $objects);
    +
                 if ($return) {
     
                     foreach ($ids as $key => $id) {
    @@ -312,7 +323,6 @@ class EmpDataServiceController extends BaseController
                         }
                     }
     
    -
                     // Set the appropriate headers for Excel file download
                     header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                     header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"');
    @@ -329,7 +339,6 @@ class EmpDataServiceController extends BaseController
     
                     return true;
                 } else {
    -
                     return false;
                 }
             }
    @@ -347,6 +356,7 @@ class EmpDataServiceController extends BaseController
                 $ids[] = $obj->endorsement_primarykey;
                 $totals += $obj->total;
             }
    +        
             $rounded_totals = round($totals, 2);
             // echo '
    ';
             // print_r($ids); die;
    @@ -354,13 +364,17 @@ class EmpDataServiceController extends BaseController
             $count = count($objects);
             $export_data['count'] = $count;
             $export_data['amount'] = $rounded_totals;
    +        $export_data['status'] = 'success';
     
             $this->myLogger->logme('error', 'SI_Enhancement export data count : {data}', ['data' => $count]);
     
             if ($count == 0) {
    +
    +            $this->myLogger->logme('error', 'No Record found. Endorsement ID Alread Updated. SI_Enhancement export data count : {data}', ['data' => $count]);
                 return false;
             }
     
    +        $this->removeOldExportInfoFromBatchFile($export_data);
             $this->myLogger->logme('error', 'SI_Enhancement export file name : {data}', ['data' => $export_data['file_name']]);
     
             $si_data = transform_objects_to_array_for_si_enhancement($objects);
    @@ -440,21 +454,21 @@ class EmpDataServiceController extends BaseController
                 $totals += $obj->total;
             }
             $rounded_totals = round($totals, 2);
    -        // echo '
    ';
    -        // print_r($ids); 
    -        // print_r($objects); die;
     
             $count = count($objects);
             $export_data['count'] = $count;
             $export_data['amount'] = $rounded_totals;
    -
    +        $export_data['status'] = 'success';
     
             $this->myLogger->logme('error', 'Deletion export data count : {data}', ['data' => $count]);
     
             if ($count == 0) {
    +
    +            $this->myLogger->logme('error', 'No Record found. Endorsement ID Alread Updated. Deletion export data count : {data}', ['data' => $count]);
                 return false;
             }
     
    +        $this->removeOldExportInfoFromBatchFile($export_data);
             $this->myLogger->logme('error', 'Deletion export file name : {data}', ['data' => $export_data['file_name']]);
     
             $si_data = transform_objects_to_array_for_deletion($objects);
    @@ -539,48 +553,24 @@ class EmpDataServiceController extends BaseController
          *               - 0 if the provided data is incomplete or incorrect.
          */
     
    -    public function importExcelDataForInception($import_data)
    -    {
    -
    -        $file = $import_data['file'];
    -
    -        $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
    -        $filename = $file->getName();
    -        $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
    -
    -
    -        $random_number_count = 4;
    -        $import_data['batch_code'] = generate_random_string($random_number_count);
    -        $import_data['created_by'] = get_session_userid();
    -        $import_data['status'] = 'pending';
    -        $import_data['file_name'] = $filename;
    -
    -        $insert = $this->batchFileModel->insert($import_data);
    -
    -        $file_id['file_id'] = $insert;
    -
    -        $job_details  = new Jobs();                             
    -        $r = Jobs::addJob(['job_name' => 'importInceptionFileValidation','payload' => ['file_id' => $insert]]);
    -
    -        return 1;
    -    }
     
    +    //Endorsement Inception
     
         public function importInceptionFileValidation($params)
         {
     
    -        $this->myLogger->logme('info', 'importInceptionFileValidation called');
    +        $this->myLogger->logme('info', 'Inception File Validation --  Function called');
     
             $file_id = $params['file_id'];
     
    -        $this->myLogger->logme('error', 'importInceptionFileValidation batch file table primary id : {data}', ['data' => $file_id]);
    +        $this->myLogger->logme('error', 'Inception File Validation --   Batch File Table Primary ID : {data}', ['data' => $file_id]);
             
             $file = $this->batchFileModel->where('id', $file_id)->first();
             $client_id = $file['client_id'];
             $client_policy_id = $file['client_policy_id'];
             $client_branch_id = $file['client_branch_id'];
             $batch_code = $file['batch_code'];
    -
    +        $user_id = $file['created_by'];
     
             $insurer_or_tpa = $file['insurer_or_tpa'];
             if ($insurer_or_tpa == 'tpa') {
    @@ -629,10 +619,12 @@ class EmpDataServiceController extends BaseController
                 ->where('employees.client_id', $client_id)
                 ->where('employees.client_branch_id', $client_branch_id)
                 ->where("employee_polices.{$id} IS NULL OR employee_polices.{$id} = ''")
    +            ->where('employee_polices.is_active', 1)
    +            ->where('employee_polices.status', 'active')
    +            ->where('employees.is_active', 1)
    +            ->where('employees.emp_status', 'active')
                 ->findAll();
     
    -        // echo '
    ';
    -        // print_r($employee_data); die;
     
     
             if ($employee_data == null || empty($employee_data)) {
    @@ -644,12 +636,12 @@ class EmpDataServiceController extends BaseController
                     ];
         
                     $this->batchFileModel->where('id', $file_id)->set($data)->update();
    -                $this->myLogger->logme('error', 'importInceptionFileValidation TPAID already updated');
    +                $this->myLogger->logme('error', 'Inception File Validation --   TPAID already updated');
     
                     $file_data = $this->getDataByFileId($file_id, 'failure');
                     $this->setPullNotification($file_data);
     
    -                return 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file';
    +                return ['status' => 'error', 'message' => 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file'];
     
                 } else if ($insurer_or_tpa == 'insurer') {
     
    @@ -658,23 +650,23 @@ class EmpDataServiceController extends BaseController
                     ];
         
                     $this->batchFileModel->where('id', $file_id)->set($data)->update();
    -                $this->myLogger->logme('error', 'importInceptionFileValidation UHID already updated');
    +                $this->myLogger->logme('error', 'Inception File Validation --   UHID already updated');
     
                     $file_data = $this->getDataByFileId($file_id, 'failure');
                     $this->setPullNotification($file_data);
     
    -                return 'The list of employees provided has already been updated with the UHID, or this is not the correct file';
    +                return ['status' => 'error', 'message' =>'The list of employees provided has already been updated with the UHID, or this is not the correct file'];
                 }
     
    -            $this->myLogger->logme('error', 'importInceptionFileValidation UHID or TPAID already updated or the uploadedfile is not correct');
    +            $this->myLogger->logme('error', 'Inception File Validation --   UHID or TPAID already updated or the uploadedfile is not correct');
     
             }
     
             $excel_data_count = count($excel_data);
             $emp_data_count = count($employee_data);
     
    -        $this->myLogger->logme('error', 'importInceptionFileValidation excel file count : {data}', ['data' => $excel_data_count]);
    -        $this->myLogger->logme('error', 'importInceptionFileValidation database count : {data}', ['data' => $emp_data_count]);
    +        $this->myLogger->logme('error', 'Inception File Validation --   Excel File count : {data}', ['data' => $excel_data_count]);
    +        $this->myLogger->logme('error', 'Inception File Validation --   Database count : {data}', ['data' => $emp_data_count]);
     
     
             // dd($excel_data_count, $emp_data_count);
    @@ -685,7 +677,7 @@ class EmpDataServiceController extends BaseController
     
                 $status = 'in-progress-partially';
                 $partially_updated_data = 'Expected : ' . $emp_data_count . ',  ' . 'Updated : ' . $excel_data_count . ',  ' . 'difference : ' . $difference;
    -            $this->myLogger->logme('error', 'importInceptionFileValidation excel file count partially : {data}', ['data' => $partially_updated_data]);
    +            $this->myLogger->logme('error', 'Inception File Validation --   excel file count partially : {data}', ['data' => $partially_updated_data]);
             }
     
     
    @@ -697,12 +689,12 @@ class EmpDataServiceController extends BaseController
                 ];
     
                 $this->batchFileModel->where('id', $file_id)->set($data)->update();
    -            $this->myLogger->logme('error', 'importInceptionFileValidation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $emp_data_count, 'excel' => $excel_data_count]);
    +            $this->myLogger->logme('error', 'Inception File Validation --   Excel File Count ( {excel} ) exceeds db count ( {db} )', ['db' => $emp_data_count, 'excel' => $excel_data_count]);
     
                 $file_data = $this->getDataByFileId($file_id, 'failure');
                 $this->setPullNotification($file_data);
     
    -            return 'The Excel record count exceeds the DB record count. excel file count : ' .  $excel_data_count . 'db count : ' .  $emp_data_count;
    +            return ['status' => 'error', 'message' =>'The Excel record count exceeds the DB record count. excel file count : ' .  $excel_data_count . 'db count : ' .  $emp_data_count];
             }
     
     
    @@ -874,15 +866,11 @@ class EmpDataServiceController extends BaseController
             $error_count = count($errors);
             $json_errors = json_encode($errors);
     
    -        // echo $json_errors; die;
    -
             $missing_id_count = count($missing_id);
             $json_missing_id = json_encode($missing_id);
     
             // dd($error_count, $missing_id_count, $json_errors, $json_missing_id);
     
    -        // dd($batch_list_id);
    -
             if ($missing_id_count > 0) {
     
                 $data = [
    @@ -897,14 +885,14 @@ class EmpDataServiceController extends BaseController
                     $file_data = $this->getDataByFileId($file_id, 'failure');
                     $this->setPullNotification($file_data);
     
    -                return 'The TPA ID column is either partially or entirely empty.';
    +                return ['status' => 'error', 'message' =>'The TPA ID column is either partially or entirely empty.'];
     
                 } else if ($insurer_or_tpa == 'insurer') {
     
                     $file_data = $this->getDataByFileId($file_id, 'failure');
                     $this->setPullNotification($file_data);
     
    -                return 'The UHID column is either partially or entirely empty.';
    +                return ['status' => 'error', 'message' =>'The UHID column is either partially or entirely empty.'];
                 }
             }
     
    @@ -916,8 +904,11 @@ class EmpDataServiceController extends BaseController
                     'status' => 'failed',
                 ];
     
    +            $file_data = $this->getDataByFileId($file_id, 'failure');
    +            $this->setPullNotification($file_data);
    +
                 $this->batchFileModel->where('id', $file_id)->set($data)->update();
    -            return 0;
    +            return ['status' => 'error', 'message' => 'Inception File Validation Failed Excel and Database Data are Mismatching'];
     
             } else {
     
    @@ -935,6 +926,7 @@ class EmpDataServiceController extends BaseController
                     $data = [
                         'emp_policy_id' => $value,
                         'batch_code' => $batch_code,
    +                    'created_by' => $user_id
                     ];
     
                     $insert = $this->batchListModel->insert($data);
    @@ -946,9 +938,10 @@ class EmpDataServiceController extends BaseController
                 $job_details  = new Jobs();                             
                 $r = Jobs::addJob(['job_name' => 'importInceptionUpdateTPAandUHID','payload' => ['file_id' => $file_id]]);
     
    -
                 // $this->importInceptionUpdateTPAandUHID(['file_id' => $file_id]);
     
    +            return ['status' => 'error', 'message' => 'Inception File Validation Successfully Completed'];
    +
             }
             
         }
    @@ -957,7 +950,7 @@ class EmpDataServiceController extends BaseController
         public function importInceptionUpdateTPAandUHID($params)
         {
     
    -        $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID called');
    +        $this->myLogger->logme('error', 'Inception Update TPA and UHID --  Function called');
     
             $file_id = $params['file_id'];
             $file = $this->batchFileModel->find($file_id);
    @@ -968,12 +961,12 @@ class EmpDataServiceController extends BaseController
                 ];
     
                 $this->batchFileModel->where('id', $file_id)->set($data)->update();
    -            $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID the Physical file not found - file id : {data}', ['data' => $file_id]);
    +            $this->myLogger->logme('error', 'Inception Update TPA and UHID --   The Physical file not found --   File id : {data}', ['data' => $file_id]);
     
                 $file_data = $this->getDataByFileId($file_id, 'failure');
                 $this->setPullNotification($file_data);
     
    -            return 'importInceptionUpdateTPAandUHID the Physical file not found'; // Return error code if file not found
    +            return ['status' => 'error', 'message' => 'Inception Update TPA and UHID --   The Physical file not found']; // Return error code if file not found
             }
     
             $client_id = $file['client_id'];
    @@ -986,11 +979,11 @@ class EmpDataServiceController extends BaseController
     
     
             $get_policy_type = $this->clientPolicyModel
    -                                ->select('policy_type.policy_type, policies.policy_type_id as policy_type_id')
    -                                ->join('policies', 'policies.id = client_policy.policy_id')
    -                                ->join('policy_type', 'policy_type.id = policies.policy_type_id')
    -                                ->where('client_policy.id', $client_policy_id)
    -                                ->first();
    +            ->select('policy_type.policy_type, policies.policy_type_id as policy_type_id')
    +            ->join('policies', 'policies.id = client_policy.policy_id')
    +            ->join('policy_type', 'policy_type.id = policies.policy_type_id')
    +            ->where('client_policy.id', $client_policy_id)
    +            ->first();
     
     
             $status_val = 'success';
    @@ -999,7 +992,7 @@ class EmpDataServiceController extends BaseController
                 $status_val = 'partially success';
             }
     
    -        $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID  file name : {data}', ['data'=> $file['file_name']]);
    +        $this->myLogger->logme('error', 'Inception Update TPA and UHID --    file name : {data}', ['data' => $file['file_name']]);
     
     
             $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
    @@ -1025,10 +1018,8 @@ class EmpDataServiceController extends BaseController
                 $uhid[] = $value[16];
                 $amount = $value[20];
     
    -            $totals += $amount;
    +            $totals = $totals + $amount;
     
    -
    -            // Execute the query
                 $query = $db->table('employee_polices');
                 $query->select('employee_polices.id');
                 $query->join('employees', 'employees.id = employee_polices.employee_id');
    @@ -1045,45 +1036,19 @@ class EmpDataServiceController extends BaseController
                     $query->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")');
                 }
                 $query->where('employee_polices.is_active', 1);
    +            $query->where('employee_polices.status', 'active');
    +            $query->where('employees.is_active', 1);
    +            $query->where('employees.emp_status', 'active');
                 $query->limit(1);
     
    -            // Get the result
                 $result = $query->get()->getRowArray();
                 if (isset($result['id']) && $result['id'] !== null) {
    -                $emp_policy_ids[] = $result['id'];
    -                $emp_details[] = array('id' => $result['id'],'tpa_id' => $value[15], 'uhid' => $value[16]);
    +                $emp_policy_ids[] = $result['id']; //for cash deposite
    +                $emp_details[] = array('id' => $result['id'], 'tpa_id' => $value[15], 'uhid' => $value[16]);
                 }
    -
    -
    -
    -            // $sql = "
    -            // UPDATE employee_polices
    -            // JOIN employees ON employees.id = employee_polices.employee_id
    -            // SET tpa_id = ?
    -            // WHERE employees.name = ?
    -            // AND employees.emp_code = ?
    -            // AND employee_polices.client_policy_id = ?
    -            // AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '')";
    -
    -            // $params = [$tpa_id, $name, $emp_code, $client_policy_id];
    -            // $db->query($sql, $params);
    -
    -
    -
    -            // $sql = "
    -            // UPDATE employee_polices 
    -            // JOIN employees ON employees.id = employee_polices.employee_id 
    -            // SET employee_polices.uhid = ? 
    -            // WHERE employees.name = ? 
    -            // AND employees.emp_code = ? 
    -            // AND employee_polices.client_policy_id = ?
    -            // AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '')";
    -
    -            // $params = [$uhid, $name, $emp_code, $client_policy_id];
    -            // $db->query($sql, $params);
             }
     
    -       $return = $this->employeePolicyModel->bulkUpdate($emp_details);
    +        $return = $this->employeePolicyModel->bulkUpdate($emp_details);
     
             // Update batch file status and amount
             $this->batchFileModel->update($file_id, [
    @@ -1093,14 +1058,14 @@ class EmpDataServiceController extends BaseController
             ]);
     
     
    -        $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID  employee count : {data}', ['data'=> $emp_count]);
    -        $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID  batch file status : {data}', ['data'=> $status_val]);
    -        $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID  total amount for cash deposite : {data}', ['data'=> $totals]);
    +        $this->myLogger->logme('error', 'Inception Update TPA and UHID --    employee count : {data}', ['data' => $emp_count]);
    +        $this->myLogger->logme('error', 'Inception Update TPA and UHID --    batch file status : {data}', ['data' => $status_val]);
    +        $this->myLogger->logme('error', 'Inception Update TPA and UHID --    total amount for cash deposite : {data}', ['data' => $totals]);
     
     
             if ($file['insurer_or_tpa'] == 'tpa') {
     
    -            $this->myLogger->logme('error', 'importInceptionUpdateTPAandUHID  set  cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE');
    +            $this->myLogger->logme('error', 'Inception Update TPA and UHID --    set  cashDepositCalculationForInception and sendMailForDownloadingECard in JOB QUEUE');
     
                 $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id);
                 $depositeData = [
    @@ -1116,8 +1081,8 @@ class EmpDataServiceController extends BaseController
     
     
     
    -            $job_details  = new Jobs();                             
    -            $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForInception','payload' => [
    +            $job_details  = new Jobs();
    +            $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForInception', 'payload' => [
                     'employeeIds' => $emp_policy_ids,
                     'client_id' => $client_id,
                     'client_policy_id' => $client_policy_id,
    @@ -1127,12 +1092,11 @@ class EmpDataServiceController extends BaseController
                     'policy_name' => $policy_name['policy_name'],
                     'user_id' => $user_id,
                 ]]);
    -    
    -            if($get_policy_type['policy_type_id'] != 1){
     
    -                $job_details  = new Jobs();                             
    -                $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard','payload' => $emp_policy_ids]);  
    +            if ($get_policy_type['policy_type_id'] != 1) {
     
    +                $job_details  = new Jobs();
    +                $r = Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => $emp_policy_ids]);
                 }
     
                 // $this->cashDepositCalculationForInception($depositeData);
    @@ -1144,602 +1108,1474 @@ class EmpDataServiceController extends BaseController
             $this->setPullNotification($file_data);
     
     
    -        return 'Import Inception Updated '. $status_val . '- Updated Count : ' . $emp_count;
    +        return 'Import Inception Updated ' . $status_val . '- Updated Count : ' . $emp_count;
         }
     
     
     
     
     
    +    //Endorsement Correction
     
    -
    -    public function importExcelDataForCorrection($import_data)
    +    public function importCorrectionValidation($params)
         {
     
    -        $client_id = $import_data['client_id'];
    -        $client_policy_id = $import_data['client_policy_id'];
    -        $client_branch_id = $import_data['client_branch_id'];
    -        $file = $import_data['file'];
    +        $this->myLogger->logme('error', 'Correction File Validation --   Function called');
     
    -        $data = $this->readExcelToArray($file);
    -        unset($data[0]);
    -        $count = count($data);
    +        $file_id = $params['file_id'];
    +        $file = $this->batchFileModel->where('id', $file_id)->first();
     
    -        $missing_id = [];
    -        $empty_emp_tpa_uh_ids = [];
    -        foreach ($data as $key => $value) {
    +        $client_id = $file['client_id'];
    +        $client_policy_id = $file['client_policy_id'];
    +        $client_branch_id = $file['client_branch_id'];
    +        $batch_code = $file['batch_code'];
    +        $user_id = $file['created_by'];
     
    -            try {
    -
    -                if ($value[10] === null) {
    -                    $missing_id[] = $key + 1;
    -                }
    -
    -                $emp_code = $value[0];
    -                $uhid = $value[1];
    -                $endorsement_id = $value[10] != null ? $value[10] : '';
    -
    -                $db = \Config\Database::connect();
    -
    -                // Execute the query
    -                $query = $db->table('emp_endorsement')
    -                    ->select('emp_endorsement.id')
    -                    ->join('employees', 'employees.id = emp_endorsement.pk')
    -                    ->join('employee_polices', 'employee_polices.employee_id = employees.id')
    -                    ->where('employee_polices.client_policy_id', $client_policy_id)
    -                    ->where('employees.client_id', $client_id)
    -                    ->where('employees.client_branch_id', $client_branch_id)
    -                    ->where('employee_polices.uhid', $uhid)
    -                    ->where('employees.emp_code', $emp_code)
    -                    ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")')
    -                    ->groupBy('emp_endorsement.group_key')
    -                    ->limit(1);
    -
    -                // Get the result
    -                $result = $query->get()->getRowArray();
    -                if (isset($result['id']) && $result['id'] !== null) {
    -                    $empty_emp_tpa_uh_ids[] = $result['id'];
    -                }
    -            } catch (\Exception $e) {
    -                // Handle the exception here
    -                return 0;
    -            }
    -        }
    -
    -        $missing_id_count = count($missing_id);
    -        $empty_id_count = count($empty_emp_tpa_uh_ids);
    -
    -        // if($missing_id_count != $count){
    -
    -        //     return 2;
    -        // }
    -
    -        if ($missing_id_count != 0) {
    -
    -            return 2;
    -        }
    -
    -
    -        if ($empty_id_count == 0) {
    -
    -            return 3;
    -        }
    -
    -        // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids);
    -
    -
    -        $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
    -        $filename = $file->getName();
    -
    -        $this->myLogger->logme('error', 'Correction Import file name : {data}', ['data' => $filename]);
    -        $random_number_count = 4;
    -        $batch_code = generate_random_string($random_number_count);
    -        $this->myLogger->logme('error', 'Correction Import BATCH CODE : {data}', ['data' => $batch_code]);
    -
    -
    -        $import_data['batch_code'] = $batch_code;
    -        $import_data['created_by'] = get_session_userid();
    -        $import_data['file_name'] = $filename;
    -        $insert = $this->batchFileModel->insert($import_data);
    -        $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
    -
    -        $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code'];
    -        $batch_code_for_batch_list['created_by'] = get_session_userid();
    -
    -        $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name'];
    +        $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name'];
     
             if (!file_exists($file_name_with_path)) {
    -            return 2;
    +
    +            $this->myLogger->logme('error', 'Correction File Validation --   The Physical file not found');
    +            $this->myLogger->logme('error', 'Correction File Validation --   File Name : {data}', ['data' => $file['file_name']]);
    +            $this->myLogger->logme('error', 'Correction File Validation --   File Path : {data}', ['data' => $file_name_with_path]);
    +
    +            return 'The Physical file not found';
             }
     
    -        $data = read_excel_file_to_array($file_name_with_path);
    -        unset($data[0]);
    -        $count = count($data);
    -        $this->batchFileModel->where('id', $insert)->set('count', $count)->update();
    -        foreach ($data as $key => $value) {
    +        $excel_data = $this->readExcelFileToArray($file_name_with_path);
    +        unset($excel_data[0]);
     
    -            if (!empty($value) && isset($value[10])) {
     
    -                $emp_code = $value[0];
    -                $uhid = $value[1];
    -                $endorsement_id = $value[10] != null ? $value[10] : '';
    +        $endorsement_data = $this->empEndorsementModel
    +            ->select("
    +                                emp_endorsement.id, 
    +                                emp_endorsement.pk, 
    +                                emp_endorsement.emp_code, 
    +                                emp_endorsement.endorsement_id, 
    +                                emp_endorsement.old_value, 
    +                                emp_endorsement.new_value, 
    +                                emp_endorsement.field_name, 
    +                                emp_endorsement.remarks, 
    +                                emp_endorsement.actions, 
    +                                employees.id AS primaryKey, 
    +                                employees.name AS emp_name, 
    +                                employees.dob AS emp_dob, 
    +                                employees.gender AS emp_gender, 
    +                                employees.client_id AS emp_client_id, 
    +                                'Has Define' AS emp_type,
    +                                employee_polices.uhid,
    +                                employees.relationship_code
    +                            ")
    +            ->join("employees", "employees.id = emp_endorsement.pk", "left")
    +            ->join("employee_polices", "employees.id = employee_polices.employee_id", "left")
    +            ->where("employees.client_id", $client_id)
    +            ->where("employee_polices.client_policy_id", $client_policy_id)
    +            ->where("employees.client_branch_id", $client_branch_id)
    +            ->where("employees.is_active", 1)
    +            ->where("employees.emp_status", "active")
    +            ->where("emp_endorsement.actions", "c")
    +            ->where("(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')")
    +            ->findAll();
     
    -                $val = $this->employeePolicyModel
    -                    ->select('employees.id')
    -                    ->join('employees', 'employees.id = employee_polices.employee_id')
    -                    ->where('employee_polices.client_policy_id', $client_policy_id)
    -                    ->where('employees.client_id', $client_id)
    -                    ->where('employees.client_branch_id', $client_branch_id)
    -                    ->where('employee_polices.uhid', $uhid)
    -                    ->where('employees.emp_code', $emp_code)
    -                    ->where('employees.is_active', 1)
    -                    ->first();
     
    -                $batch_code_for_batch_list['emp_policy_id'] = $val['id'];
    -                $this->batchListModel->insert($batch_code_for_batch_list);
     
    -                // $this->employeePolicyModel->updateCorrectionData($emp_code, $uhid, $endorsement_id);
    +        // dd($endorsement_data, $excel_data);
     
    -                $queryData =  $this->empEndorsementModel->select('emp_endorsement.*, employees.id as emp_id')
    -                    ->join('employees', 'employees.id = emp_endorsement.pk')
    -                    ->join('employee_polices', 'employee_polices.employee_id = employees.id')
    -                    ->where('employees.emp_code', $emp_code)
    -                    ->where('employees.client_id', $client_id)
    -                    ->where('employees.client_branch_id', $client_branch_id)
    -                    ->where('employee_polices.client_policy_id', $client_policy_id)
    -                    ->where('employee_polices.uhid', $uhid)
    -                    ->get()
    -                    ->getResultArray();
     
    -                // dd($queryData);
    +        if ($endorsement_data == null || empty($endorsement_data)) {
     
    -                foreach ($queryData as $endorsementData) {
    +            $data = [
    +                'status' => 'failed-1',
    +            ];
     
    -                    $emp_endoresment_id = $endorsementData['id'];
    -                    $emp_id = $endorsementData['emp_id'];
    -                    $field_name = $endorsementData['field_name'];
    -                    $new_value = $endorsementData['new_value'];
    -                    $endoresment_udate_data = [
    -                        'endorsement_id' => $endorsement_id,
    -                        'status' => 'complete',
    -                    ];
    -                    $this->empEndorsementModel->where('id', $emp_endoresment_id)->set($endoresment_udate_data)->update();
    -                    $this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update();
    -                }
    +            $this->batchFileModel->where('id', $file_id)->set($data)->update();
    +            $this->myLogger->logme('error', 'correctionFileValidation ENDORSEMENT ID already updated');
     
    -                // $query = $this->employeePolicyModel->getLastQuery();
    -                // echo $query . "
    "; - } else { + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); - return 0; - } + return 'The list of employees provided has already been updated with the ENDORSEMENT ID, or this is not the correct file'; + + $this->myLogger->logme('error', 'correctionFileValidation ENDORSEMENT ID already updated or the uploadedfile is not correct'); + } + + $excel_data_count = count($excel_data); + $endorsement_data_count = count($endorsement_data); + + $this->myLogger->logme('error', 'correctionFileValidation excel file count : {data}', ['data' => $excel_data_count]); + $this->myLogger->logme('error', 'correctionFileValidation database count : {data}', ['data' => $endorsement_data_count]); + + + $difference = $endorsement_data_count - $excel_data_count; + + $status = 'in-progress'; + if ($excel_data_count < $endorsement_data_count) { + + $status = 'in-progress-partially'; + $partially_updated_data = 'Expected : ' . $endorsement_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference; + $this->myLogger->logme('error', 'correctionFileValidation excel file count partially : {data}', ['data' => $partially_updated_data]); } - return 1; - } - - - public function importExcelDataForSIEnhancement($import_data) - { - - $client_id = $import_data['client_id']; - $client_policy_id = $import_data['client_policy_id']; - $client_branch_id = $import_data['client_branch_id']; - $file = $import_data['file']; - - $data = $this->readExcelToArray($file); - unset($data[0]); - $count = count($data); + + if ($endorsement_data_count < $excel_data_count) { + + $data = [ + 'status' => 'failed-3', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'correctionFileValidation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $endorsement_data_count, 'excel' => $excel_data_count]); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $endorsement_data_count; + } + $errors = []; // Initialize an array to store errors $missing_id = []; - $empty_emp_tpa_uh_ids = []; - $totals = 0; - foreach ($data as $key => $value) { + $batch_list_id = []; - try { - if ($value[19] === null) { - $missing_id[] = $key + 1; - } + foreach ($endorsement_data as $key => $endorsement_value) { - $totals += $value[18]; + $key = $key + 1; - $emp_name = $value[1]; - $emp_code = $value[2]; - $endorsement_id = $value[19] != null ? $value[19] : ''; - - $db = \Config\Database::connect(); - - // Execute the query - $query = $db->table('emp_endorsement') - ->select('emp_endorsement.id') - ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk') - ->join('employees', 'employees.emp_code = emp_endorsement.emp_code') - ->where('employees.emp_code', $emp_code) - ->where('employees.name', $emp_name) - ->where('employees.client_id', $client_id) - ->where('employees.client_branch_id', $client_branch_id) - ->where('emp_endorsement.actions', 'si') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') - ->groupBy('emp_endorsement.group_key'); - - // Get the result - $result = $query->get()->getRowArray(); - if (isset($result['id']) && $result['id'] !== null) { - $empty_emp_tpa_uh_ids[] = $result['id']; - } - } catch (\Exception $e) { - // Handle the exception here - return 0; + if (!isset($excel_data[$key])) { + break; } + + + if ($excel_data[$key][10] === null) { + $missing_id[$key][] = [ + 'row' => $key, + 'column' => 10, + ]; + } + + + if ($endorsement_value['emp_name'] != $excel_data[$key][2]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 2, + 'db_data' => $endorsement_value['emp_name'], + 'excel_data' => $excel_data[$key][2] + ]; + } + + if ($endorsement_value['emp_code'] != $excel_data[$key][0]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 0, + 'db_data' => $endorsement_value['emp_code'], + 'excel_data' => $excel_data[$key][0] + ]; + } + + if ($endorsement_value['emp_dob'] != $excel_data[$key][5]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 5, + 'db_data' => $endorsement_value['emp_dob'], + 'excel_data' => $excel_data[$key][5] + ]; + } + + if ($endorsement_value['emp_gender'] != $excel_data[$key][6]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 6, + 'db_data' => $endorsement_value['emp_gender'], + 'excel_data' => $excel_data[$key][6] + ]; + } + + if ($endorsement_value['old_value'] != $excel_data[$key][7]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 7, + 'db_data' => $endorsement_value['old_value'], + 'excel_data' => $excel_data[$key][7] + ]; + } + + if ($endorsement_value['new_value'] != $excel_data[$key][8]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 8, + 'db_data' => $endorsement_value['new_value'], + 'excel_data' => $excel_data[$key][8] + ]; + } + + + + if ($endorsement_value['uhid'] != $excel_data[$key][1]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 1, + 'db_data' => $endorsement_value['uhid'], + 'excel_data' => $excel_data[$key][1] + ]; + } + + $batch_list_id[] = $endorsement_value['primaryKey']; } - $rounded_totals = round($totals, 2); + + + $error_count = count($errors); + $json_errors = json_encode($errors); + $missing_id_count = count($missing_id); - $empty_id_count = count($empty_emp_tpa_uh_ids); + $json_missing_id = json_encode($missing_id); - // if($missing_id_count != $count){ + // dd($error_count, $missing_id_count, $json_errors, $json_missing_id, $batch_list_id); - // return 2; - // } - if ($missing_id_count != 0) { + if ($missing_id_count > 0) { - return 2; + $data = [ + + 'count' => $endorsement_data_count, + 'error_data' => $json_missing_id, + 'status' => 'failed', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The ENDORSEMENT ID column is either partially or entirely empty.'; + } - // if($empty_emp_tpa_uh_ids != $count){ - // return 3; - // } + if ($error_count > 0) { - if ($empty_id_count == 0) { + $data = [ - return 3; - } + 'count' => $endorsement_data_count, + 'error_data' => $json_errors, + 'status' => 'failed', + ]; - // dd($count, $missing_id, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + return 'Correction Validation Failed'; - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); + } else { - $this->myLogger->logme('error', 'SI_Enhancement Import file name : {data}', ['data' => $filename]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - $this->myLogger->logme('error', 'SI_Enhancement Import BATCH CODE : {data}', ['data' => $batch_code]); + $data = [ + 'count' => $endorsement_data_count, + 'status' => $status, + 'error_data' => $partially_updated_data ?? null, + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); - $import_data['batch_code'] = $batch_code; - $import_data['created_by'] = get_session_userid(); - $import_data['file_name'] = $filename; - $import_data['amount'] = $rounded_totals; - $insert = $this->batchFileModel->insert($import_data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + foreach ($batch_list_id as $key => $value) { - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); - - $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name']; - - if (!file_exists($file_name_with_path)) { - return 2; - } - - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - $count = count($data); - $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); - $employeeIds = []; - foreach ($data as $key => $value) { - - if (!empty($value) && isset($value[19])) { - - $emp_name = $value[1]; - $emp_code = $value[2]; - // echo $emp_name .'-'. $emp_code; die; - $endorsement_id = $value[19] != null ? $value[19] : ''; - - $updateData = [ - 'emp_code' => $emp_code, - 'client_id' => $client_id, - 'client_policy_id' => $client_policy_id, - 'emp_name' => $emp_name, - 'endorsement_id' => $endorsement_id, + $data = [ + 'emp_policy_id' => $value, + 'batch_code' => $batch_code, + 'created_by' => $user_id, ]; - $this->employeePolicyModel->updateEndoresmentIdForSIEnhancement($updateData); - - $queryData = $this->employeePolicyModel - ->select('employee_polices.*') - ->join('employees', 'employee_polices.employee_id = employees.id') - ->where('employees.emp_code', $emp_code) - ->where('employees.name', $emp_name) - ->where('employees.client_id', $client_id) - ->where('employees.client_branch_id', $client_branch_id) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employee_polices.is_active', 1) - ->first(); - - $queryData['is_active'] = 0; - $this->employeePolicyModel->save($queryData); - - unset($queryData['id']); - unset($queryData['created_by']); - unset($queryData['created_at']); - unset($queryData['updated_by']); - unset($queryData['updated_at']); - unset($queryData['is_active']); - - $queryData['basic_cover_si'] = $value[8]; - $queryData['premium'] = $value[14]; - $queryData['si_enhancement_date'] = $value[10]; - $queryData['rata_premimum'] = $value[16]; - $queryData['gst'] = $value[17]; - $queryData['created_by'] = get_session_userid(); - - //new insert - $this->employeePolicyModel->save($queryData); - - $val = $this->employeePolicyModel - ->select('employee_polices.id') - ->join('employees', 'employees.id = employee_polices.employee_id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employees.client_branch_id', $client_branch_id) - ->where('employees.name', $emp_name) - ->where('employees.emp_code', $emp_code) - ->where('employee_polices.is_active', 1) - ->first(); - - if ($val !== null) { - $id = $val['id']; - $batch_code_for_batch_list['emp_policy_id'] = $id; - $this->batchListModel->insert($batch_code_for_batch_list); - array_push($employeeIds, $id); - } - } else { - - return 0; + $insert = $this->batchListModel->insert($data); } + + + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'importCorrectionUpdateEndorsementID','payload' => ['file_id' => $file_id]]); + + // $this->importCorrectionUpdateEndorsementID(['file_id' => $file_id]); + + return 'Correction Validation Success'; } - - $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); - $depositeData = [ - 'employeeIds' => $employeeIds, - 'client_id' => $client_id, - 'client_policy_id' => $client_policy_id, - 'client_branch_id' => $client_branch_id, - 'count' => $count, - 'event' => $import_data['event_type'], - 'policy_name' => $policy_name['policy_name'], - ]; - - // dd($depositeData); - $this->cashDepositCalculationForSIEnhancement($depositeData); - - return 1; } - public function importExcelDataForDeletion($import_data) + public function importCorrectionUpdateEndorsementID($params){ + + $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID called'); + + $file_id = $params['file_id']; + $file = $this->batchFileModel->find($file_id); + if (!$file) { + + $data = [ + 'status' => 'failed-4', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID the Physical file not found - file id : {data}', ['data' => $file_id]); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'importCorrectionUpdateEndorsementID the Physical file not found'; // Return error code if file not found + } + + $client_id = $file['client_id']; + $client_policy_id = $file['client_policy_id']; + $client_branch_id = $file['client_branch_id']; + $insurer_or_tpa = $file['insurer_or_tpa']; + $status = $file['status']; + $batch_code = $file['batch_code']; + $user_id = $file['created_by']; + + + $status_val = 'success'; + if ($status == 'in-progress-partially') { + + $status_val = 'partially success'; + } + + $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID file name : {data}', ['data'=> $file['file_name']]); + + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name']; + $excel_data = $this->readExcelFileToArray($file_name_with_path); + unset($excel_data[0]); + + $emp_ids = []; + $emp_details = []; + $endorsement_id = []; + $endorsement_details = []; + + $emp_count = count($excel_data); + $db = \Config\Database::connect(); + + + foreach ($excel_data as $key => $value) { + + $emp_code = $value[0]; + $old_value = $value[7]; + $endorsement_id[] = $value[10]; + $uhid = $value[1]; + + + $result = $this->empEndorsementModel + ->select('emp_endorsement.*, employees.id as emp_id') + ->join('employees', 'employees.id = emp_endorsement.pk') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code', $emp_code) + ->where('employees.client_id', $client_id) + ->where('employees.client_branch_id', $client_branch_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.uhid', $uhid) + ->where('emp_endorsement.old_value', $old_value) + + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status', 'active') + ->where('employees.is_active', 1) + ->where('employees.emp_status', 'active') + ->first(); + + if (isset($result['id']) && $result['id'] !== null) { + + // return $result; + $emp_details[] = array('id' => $result['emp_id'], 'group_key' => $result['group_key'], $result['field_name'] => $value[8]); + $endorsement_details[] = array('group_key' => $result['group_key'], 'id' => $result['id'], 'endorsement_id' => $value[10], 'status' => 'complete'); + } + + } + + // return [$emp_details, $endorsement_details]; + + $this->empEndorsementModel->updateBatch($endorsement_details, 'group_key'); + $this->employeeModel->updateBatch($emp_details); + + // Update batch file status and amount + $this->batchFileModel->update($file_id, [ + 'count' => $emp_count, + 'status' => $status_val, + ]); + + + $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID employee count : {data}', ['data'=> $emp_count]); + $this->myLogger->logme('error', 'importCorrectionUpdateEndorsementID batch file status : {data}', ['data'=> $status_val]); + + + $file_data = $this->getDataByFileId($file_id, 'success'); + $this->setPullNotification($file_data); + + + return 'Import Correction Updated '. $status_val . '- Updated Count : ' . $emp_count; + + } + + + + + //Endorsement SIEnhancement + + public function importSIEnhancementValidation($params) + { + $file_id = $params['file_id']; + $file = $this->batchFileModel->where('id', $file_id)->first(); + + $client_id = $file['client_id']; + $client_policy_id = $file['client_policy_id']; + $client_branch_id = $file['client_branch_id']; + $batch_code = $file['batch_code']; + $user_id = $file['created_by']; + + + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name']; + + if (!file_exists($file_name_with_path)) { + return 'The Physical file not found'; + } + + $excel_data = $this->readExcelFileToArray($file_name_with_path); + unset($excel_data[0]); + + + $db = \Config\Database::connect(); + + // Raw SQL query + $sql = " + SELECT + a.id as endorsement_primarykey, + a.group_key, + employee_polices.id AS primaryKey, + employees.id AS emp_primary, + employees.name AS emp_name, + employees.emp_code AS emp_code, + employees.dob AS emp_dob, + employees.gender AS emp_gender, + employees.relationship_code AS emp_relationship_code, + 'Has Define' AS emp_type, + employee_polices.uhid AS risk_id, + employee_polices.pre_existing_alignments, + employee_polices.policy_end_date, + employee_polices.basic_cover_si as old_basic_cover_si, + employee_polices.rata_premimum as old_si_premium, + sidata.new_basic_cover_si, + sidata.new_si_premium, + sidata.date_of_coverage, + DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days, + sidata.new_si_premium - employee_polices.rata_premimum AS difference_premium, + ROUND((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum, + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst, + ((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total + FROM + emp_endorsement a + LEFT JOIN + employees ON employees.emp_code = a.emp_code + LEFT JOIN + employee_polices ON employees.id = employee_polices.employee_id + LEFT JOIN ( + SELECT + aa.emp_code, + aa.new_value as new_basic_cover_si, + bb.new_value as new_si_premium, + cc.new_value as date_of_coverage + FROM ( + SELECT + a1.emp_code, + a1.field_name, + a1.new_value + FROM + emp_endorsement as a1 + WHERE + a1.field_name = 'basic_cover_si' + ) aa + LEFT JOIN ( + SELECT + b1.emp_code, + b1.field_name, + b1.new_value + FROM + emp_endorsement as b1 + WHERE + b1.field_name = 'premium' + ) bb ON aa.emp_code = bb.emp_code + LEFT JOIN ( + SELECT + c1.emp_code, + c1.field_name, + c1.new_value + FROM + emp_endorsement as c1 + WHERE + c1.field_name = 'si_enhancement_date' + ) cc ON aa.emp_code = cc.emp_code + ) as sidata ON a.emp_code = sidata.emp_code + WHERE + employee_polices.client_policy_id = '$client_policy_id' + AND employees.client_branch_id = '$client_branch_id' + AND employee_polices.is_active = '1' + AND (a.endorsement_id IS NULL OR a.endorsement_id = '') + AND a.actions = 'si' + GROUP BY group_key + "; + + // Execute the query + $query = $db->query($sql); + + // Fetch the results + $endorsement_data = $query->getResultArray(); + + + + // dd($endorsement_data, $excel_data); + + + if ($endorsement_data == null || empty($endorsement_data)) { + + $data = [ + 'status' => 'failed-1', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'SI Enhancement_File Validation -- ENDORSEMENT ID already updated or the uploadedfile is not correct'); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The list of employees provided has already been updated with the ENDORSEMENT ID, or this is not the correct file'; + } + + $excel_data_count = count($excel_data); + $endorsement_data_count = count($endorsement_data); + + $this->myLogger->logme('error', 'SI Enhancement_File Validation -- Excel file count : {data}', ['data' => $excel_data_count]); + $this->myLogger->logme('error', 'SI Enhancement File Validation -- Database count : {data}', ['data' => $endorsement_data_count]); + + + $difference = $endorsement_data_count - $excel_data_count; + + $status = 'in-progress'; + if ($excel_data_count < $endorsement_data_count) { + + $status = 'in-progress-partially'; + $partially_updated_data = 'Expected : ' . $endorsement_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference; + $this->myLogger->logme('error', 'SI Enhancement File Validation -- excel file count partially : {data}', ['data' => $partially_updated_data]); + } + + + + if ($endorsement_data_count < $excel_data_count) { + + $data = [ + 'status' => 'failed-3', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'SI_Enhancement_FileValidation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $endorsement_data_count, 'excel' => $excel_data_count]); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . 'db count : ' . $endorsement_data_count; + } + + + $errors = []; // Initialize an array to store errors + $missing_id = []; + $batch_list_id = []; + + foreach ($endorsement_data as $key => $endorsement_value) { + + $key = $key + 1; + + if (!isset($excel_data[$key])) { + break; + } + + + if ($excel_data[$key][19] === null) { + $missing_id[$key][] = [ + 'row' => $key, + 'column' => 19, + ]; + } + + + if ($endorsement_value['emp_name'] != $excel_data[$key][1]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 1, + 'db_data' => $endorsement_value['emp_name'], + 'excel_data' => $excel_data[$key][1] + ]; + } + + if ($endorsement_value['emp_code'] != $excel_data[$key][2]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 2, + 'db_data' => $endorsement_value['emp_code'], + 'excel_data' => $excel_data[$key][2] + ]; + } + + if ($endorsement_value['emp_relationship_code'] != $excel_data[$key][4]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 4, + 'db_data' => $endorsement_value['emp_relationship_code'], + 'excel_data' => $excel_data[$key][4] + ]; + } + + if ($endorsement_value['emp_dob'] != $excel_data[$key][5]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 5, + 'db_data' => $endorsement_value['emp_dob'], + 'excel_data' => $excel_data[$key][5] + ]; + } + + if ($endorsement_value['emp_gender'] != $excel_data[$key][6]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 6, + 'db_data' => $endorsement_value['emp_gender'], + 'excel_data' => $excel_data[$key][6] + ]; + } + + + if ($endorsement_value['pre_existing_alignments'] != $excel_data[$key][7]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 7, + 'db_data' => $endorsement_value['pre_existing_alignments'], + 'excel_data' => $excel_data[$key][7] + ]; + } + + if ($endorsement_value['new_basic_cover_si'] != $excel_data[$key][8]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 8, + 'db_data' => $endorsement_value['new_basic_cover_si'], + 'excel_data' => $excel_data[$key][8] + ]; + } + + if ($endorsement_value['old_basic_cover_si'] != $excel_data[$key][9]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 9, + 'db_data' => $endorsement_value['old_basic_cover_si'], + 'excel_data' => $excel_data[$key][9] + ]; + } + + + + if ($endorsement_value['date_of_coverage'] != $excel_data[$key][10]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 10, + 'db_data' => $endorsement_value['date_of_coverage'], + 'excel_data' => $excel_data[$key][10] + ]; + } + + if ($endorsement_value['policy_end_date'] != $excel_data[$key][11]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 11, + 'db_data' => $endorsement_value['policy_end_date'], + 'excel_data' => $excel_data[$key][11] + ]; + } + + if ($endorsement_value['no_of_days'] != $excel_data[$key][12]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 12, + 'db_data' => $endorsement_value['no_of_days'], + 'excel_data' => $excel_data[$key][12] + ]; + } + + if ($endorsement_value['old_si_premium'] != $excel_data[$key][13]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 13, + 'db_data' => $endorsement_value['old_si_premium'], + 'excel_data' => $excel_data[$key][13] + ]; + } + + if ($endorsement_value['new_si_premium'] != $excel_data[$key][14]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 14, + 'db_data' => $endorsement_value['new_si_premium'], + 'excel_data' => $excel_data[$key][14] + ]; + } + + if ($endorsement_value['difference_premium'] != $excel_data[$key][15]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 15, + 'db_data' => $endorsement_value['difference_premium'], + 'excel_data' => $excel_data[$key][15] + ]; + } + + if ($endorsement_value['pro_rata_premimum'] != $excel_data[$key][16]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 16, + 'db_data' => $endorsement_value['pro_rata_premimum'], + 'excel_data' => $excel_data[$key][16] + ]; + } + + if ($endorsement_value['gst'] != $excel_data[$key][17]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 17, + 'db_data' => $endorsement_value['gst'], + 'excel_data' => $excel_data[$key][17] + ]; + } + + $batch_list_id[] = $endorsement_value['primaryKey']; + } + + + $error_count = count($errors); + $json_errors = json_encode($errors); + + + $missing_id_count = count($missing_id); + $json_missing_id = json_encode($missing_id); + + // dd($error_count, $missing_id_count, $json_errors, $json_missing_id, $batch_list_id); + + + if ($missing_id_count > 0) { + + $data = [ + + 'count' => $endorsement_data_count, + 'error_data' => $json_missing_id, + 'status' => 'failed', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The ENDORSEMENT ID column is either partially or entirely empty.'; + } + + + if ($error_count > 0) { + + $data = [ + + 'count' => $endorsement_data_count, + 'error_data' => $json_errors, + 'status' => 'failed', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + return 'SI ENHANCEMENT File Validation Failed'; + } else { + + $data = [ + 'count' => $endorsement_data_count, + 'status' => $status, + 'error_data' => $partially_updated_data ?? null, + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + + + foreach ($batch_list_id as $key => $value) { + + $data = [ + 'emp_policy_id' => $value, + 'batch_code' => $batch_code, + 'created_by' => $user_id, + ]; + + $insert = $this->batchListModel->insert($data); + } + + + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'importSIEnhancementUpdateEndorsementID', 'payload' => ['file_id' => $file_id]]); + + // $this->importSIEnhancementUpdateEndorsementID(['file_id' => $file_id]); + return 'SI Enhancement_File Validation -- Success'; + } + } + + + public function importSIEnhancementUpdateEndorsementID($params) { - $client_id = $import_data['client_id']; - $client_policy_id = $import_data['client_policy_id']; - $client_branch_id = $import_data['client_branch_id']; - $file = $import_data['file']; + $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- Function called'); + + $file_id = $params['file_id']; + $file = $this->batchFileModel->find($file_id); + if (!$file) { + + $data = [ + 'status' => 'failed-4', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- The Physical file not found -- File id : {data}', ['data' => $file_id]); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'SI Enhancement Update Endorsement ID -- The Physical file not found'; // Return error code if file not found + } + + $client_id = $file['client_id']; + $client_policy_id = $file['client_policy_id']; + $client_branch_id = $file['client_branch_id']; + $status = $file['status']; + $batch_code = $file['batch_code']; + $user_id = $file['created_by']; - $data = $this->readExcelToArray($file); - unset($data[0]); - array_pop($data); - $count = count($data); + $status_val = 'success'; + if ($status == 'in-progress-partially') { + $status_val = 'partially success'; + } - $missing_id = []; - $empty_emp_tpa_uh_ids = []; + $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- file name : {data}', ['data' => $file['file_name']]); + + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name']; + $excel_data = $this->readExcelFileToArray($file_name_with_path); + unset($excel_data[0]); + + $emp_count = count($excel_data); //excel file count + + $emp_policy_ids = []; + $employeeIds = []; + $emp_details = []; + $endorsement_id = []; + $endorsement_details = []; $totals = 0; - foreach ($data as $key => $value) { - try { + foreach ($excel_data as $key => $value) { - if ($value[15] === null) { - $missing_id[] = $key + 1; - } + $emp_name = $value[1]; + $emp_code = $value[2]; + $endorsement_id[] = $value[19]; + $totals += $value[18]; - $totals += $value[13]; - $emp_name = $value[2]; //employee name - $emp_code = $value[1]; //employee code - $date_of_exit = $value[7]; // date of releving - $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id + $result = $this->empEndorsementModel - $db = \Config\Database::connect(); + ->select('emp_endorsement.*, employees.id as emp_id, employee_polices.id as emp_policy_id') + ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk') + ->join('employees', 'employees.emp_code = emp_endorsement.emp_code') + ->where('employees.emp_code', $emp_code) + ->where('employees.name', $emp_name) + ->where('employees.client_id', $client_id) + ->where('employees.client_branch_id', $client_branch_id) + ->where('emp_endorsement.actions', 'si') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status', 'active') + ->where('employees.is_active', 1) + ->where('employees.emp_status', 'active') + ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') + ->groupBy('emp_endorsement.group_key') + ->first(); - // Execute the query - $query = $db->table('emp_endorsement') - ->select('emp_endorsement.id') - ->join('employee_polices', 'employee_polices.id = emp_endorsement.pk') - ->join('employees', 'employees.emp_code = emp_endorsement.emp_code') - ->where('employees.emp_code', $emp_code) - ->where('employees.name', $emp_name) - ->where('employees.client_id', $client_id) - ->where('employees.client_branch_id', $client_branch_id) - ->where('emp_endorsement.actions', 'd') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('(emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = "")') - ->groupBy('emp_endorsement.group_key'); - - $result = $query->get()->getRowArray(); - if (isset($result['id']) && $result['id'] !== null) { - $empty_emp_tpa_uh_ids[] = $result['id']; - } - } catch (\Exception $e) { - // Handle the exception here - return 0; + if (isset($result['id']) && $result['id'] !== null) { + $emp_policy_ids[] = array('id' => $result['emp_policy_id'], 'is_active' => 0); + $employeeIds[] = $result['emp_policy_id']; + $endorsement_details[] = array('id' => $result['id'], 'group_key' => $result['group_key'], 'endorsement_id' => $value[19], 'status' => 'complete'); } + + $empData = $this->employeePolicyModel + ->select('employee_polices.*') + ->join('employees', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code', $emp_code) + ->where('employees.name', $emp_name) + ->where('employees.client_id', $client_id) + ->where('employees.client_branch_id', $client_branch_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status', 'active') + ->where('employees.is_active', 1) + ->where('employees.emp_status', 'active') + ->first(); + + unset($empData['id'], $empData['created_by'], $empData['created_at'], $empData['updated_by'], $empData['updated_at'], $empData['is_active']); + + $empData['basic_cover_si'] = $value[8]; + $empData['premium'] = $value[14]; + $empData['si_enhancement_date'] = $value[10]; + $empData['rata_premimum'] = $value[16]; + $empData['gst'] = $value[17]; + $empData['created_by'] = $user_id; + + $emp_details[] = $empData; } $rounded_totals = round($totals, 2); - $missing_id_count = count($missing_id); - $empty_id_count = count($empty_emp_tpa_uh_ids); - // if($missing_id_count != $count){ + // dd($emp_policy_ids, $emp_details, $endorsement_details); - // return 2; + $this->employeePolicyModel->updateBatch($emp_policy_ids, 'id'); + + $db = \Config\Database::connect(); + $db->transStart(); + + $this->employeePolicyModel->insertBatch($emp_details); + + $insertedIds = []; + $startId = $db->insertID(); // Get the first inserted ID + + for ($i = 0; $i < count($emp_details); $i++) { + $insertedIds[] = $startId + $i; + } + + $db->transComplete(); + + // if ($db->transStatus() === FALSE) { + // // Handle the error, rollback, etc. + // } else { + // // Transaction successful + // print_r($insertedIds); // This will print the array of inserted IDs // } + + $this->employeePolicyModel->bulkUpdateForEndorsement($endorsement_details); - if ($missing_id_count != 0) { - - return 2; - } - - // if($empty_emp_tpa_uh_ids != $count){ - - // return 3; - // } - - if ($empty_id_count == 0) { - - return 3; - } - - // dd($count, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); - - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); - - $this->myLogger->logme('error', 'Deletion Import file name : {data}', ['data' => $filename]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - $this->myLogger->logme('error', 'Deletion Import BATCH CODE : {data}', ['data' => $batch_code]); + // Update batch file status and amount + $this->batchFileModel->update($file_id, [ + 'count' => $emp_count, + 'status' => $status_val, + 'amount' => $rounded_totals, + ]); - $import_data['batch_code'] = $batch_code; - $import_data['created_by'] = get_session_userid(); - $import_data['file_name'] = $filename; - $import_data['amount'] = $rounded_totals; - $insert = $this->batchFileModel->insert($import_data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); - - $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $batch_file_batch_code['file_name']; - - if (!file_exists($file_name_with_path)) { - return 2; - } - - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - array_pop($data); - - $count = count($data); - $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); - - $employeeIds = []; - foreach ($data as $key => $value) { - - if (!empty($value) && isset($value[15])) { - - $emp_name = $value[2]; //employee name - $emp_code = $value[1]; //employee code - $date_of_exit = $value[7]; // date of releving - - // echo $emp_name .'-'. $emp_code .'-'. $date_of_exit; die; - $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id - - $val = $this->employeePolicyModel - ->select('employee_polices.id') - ->join('employees', 'employees.id = employee_polices.employee_id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employees.client_branch_id', $client_branch_id) - ->where('employees.name', $emp_name) - ->where('employees.emp_code', $emp_code) - ->where('employee_polices.is_active', 1) - ->first(); + $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- Employee count : {data}', ['data' => $emp_count]); + $this->myLogger->logme('error', 'SI Enhancement Update Endorsement ID -- Batch File status : {data}', ['data' => $status_val]); - if ($val !== null) { + $file_data = $this->getDataByFileId($file_id, 'success'); + $this->setPullNotification($file_data); - $id = $val['id']; - $batch_code_for_batch_list['emp_policy_id'] = $id; - $this->batchListModel->insert($batch_code_for_batch_list); - array_push($employeeIds, $id); - } - - // $updateData = [ - // 'emp_code' =>$emp_code, - // 'client_id' =>$client_id, - // 'client_policy_id' =>$client_policy_id, - // 'emp_name' =>$emp_name, - // 'endorsement_id' =>$endorsement_id, - // ]; - - // $this->employeePolicyModel->updateEndoresmentIdForDeletion($updateData); - - $deletionDataForEmployee = $this->empEndorsementModel - ->select('emp_endorsement.new_value, emp_endorsement.id as ee_id, employees.id') - ->join('employees', 'emp_endorsement.emp_code = employees.emp_code') - ->join('employee_polices', 'employee_polices.employee_id = employees.id') - ->where('emp_endorsement.emp_code', $emp_code) - ->where('employees.client_id', $client_id) - ->where('employees.client_branch_id', $client_branch_id) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('emp_endorsement.name', $emp_name) - ->where('emp_endorsement.field_name', 'emp_status') - ->first(); - - $deletionDataForEmployee['updated_by'] = get_session_userid(); - $this->employeeModel->save($deletionDataForEmployee); - - $e_Data = [ - 'endorsement_id' => $endorsement_id, - 'status' => 'complete', - ]; - $group_key = $this->empEndorsementModel->select('group_key')->where('id', $deletionDataForEmployee['ee_id'])->first(); - $this->empEndorsementModel->where('group_key', $group_key)->set($e_Data)->update(); - - $fetchData = [ - 'emp_code' => $emp_code, - 'client_policy_id' => $client_policy_id, - 'emp_name' => $emp_name, - ]; - - $deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($fetchData); - $deletionDataForEmployeePolicy['updated_by'] = get_session_userid(); - $this->employeePolicyModel->save($deletionDataForEmployeePolicy); - - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
    "; - - } else { - - return 0; - } - } + //call the cash deposite function $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); - $depositeData = [ - 'employeeIds' => $employeeIds, + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForSIEnhancement','payload' => [ + 'employeeIds' => $insertedIds, 'client_id' => $client_id, - 'client_branch_id' => $client_branch_id, 'client_policy_id' => $client_policy_id, - 'count' => $count, - 'event' => $import_data['event_type'], + 'client_branch_id' => $client_branch_id, + 'count' => $emp_count, + 'event' => $file['event_type'], 'policy_name' => $policy_name['policy_name'], - ]; + 'user_id' => $user_id, + ]]); - $this->cashDepositCalculationForDeletion($depositeData); - return 1; + return 'SI Enhancement Update Endorsement ID -- ' . $status_val . '-- Updated Count : ' . $emp_count; } + //Endorsement Deletion + + public function importDeletionValidation($params) + { + $file_id = $params['file_id']; + $file = $this->batchFileModel->where('id', $file_id)->first(); + + $client_id = $file['client_id']; + $client_policy_id = $file['client_policy_id']; + $client_branch_id = $file['client_branch_id']; + $batch_code = $file['batch_code']; + $user_id = $file['created_by']; + + + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name']; + + if (!file_exists($file_name_with_path)) { + return 'The Physical file not found'; + } + + $excel_data = $this->readExcelFileToArray($file_name_with_path); + unset($excel_data[0]); + array_pop($excel_data); + + + $db = \Config\Database::connect(); + + $sql = " + SELECT DISTINCT + a.id as endorsement_primarykey, + a.group_key, + employee_polices.id as primaryKey, + employees.name AS emp_name, + employees.emp_code AS emp_code, + employees.dob AS emp_dob, + employees.gender AS emp_gender, + employees.relationship AS emp_relationship, + 'Has Define' as emp_type, + + employee_polices.basic_cover_si, + employee_polices.uhid as risk_id, + employee_polices.policy_end_date, + employee_polices.rata_premimum as premium, + + + deletiondata.empstatus, + deletiondata.changeevent, + deletiondata.dateofexit, + deletiondata.reasonforexit, + deletiondata.status, + + DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) AS no_of_days, + ROUND((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365, 2) AS pro_rata_premium, + ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18, 2) AS gst, + ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) + (((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18), 2) AS total + FROM + emp_endorsement a + LEFT JOIN + employees ON a.emp_code = employees.emp_code and a.pk = employees.id + LEFT JOIN + employee_polices ON employees.id = employee_polices.employee_id + + LEFT JOIN( + + select aa.emp_code, aa.new_value as 'empstatus', bb.new_value as 'changeevent', cc.new_value as 'dateofexit', dd.new_value as 'reasonforexit', ee.new_value as 'status' from + + ( SELECT a1.emp_code, a1.field_name, a1.new_value from emp_endorsement as a1 where a1.field_name = 'emp_status') aa + left join + ( SELECT b1.emp_code, b1.field_name, b1.new_value from emp_endorsement as b1 where b1.field_name = 'change_event') bb on aa.emp_code = bb.emp_code + left join + ( SELECT c1.emp_code, c1.field_name, c1.new_value from emp_endorsement as c1 where c1.field_name = 'date_of_exit') cc on aa.emp_code = cc.emp_code + left join + ( SELECT d1.emp_code, d1.field_name, d1.new_value from emp_endorsement as d1 where d1.field_name = 'reason_for_exit') dd on aa.emp_code = dd.emp_code + left JOIN + ( SELECT e1.emp_code, e1.field_name, e1.new_value from emp_endorsement as e1 where e1.field_name = 'status') ee on aa.emp_code = ee.emp_code + + ) as deletiondata on a.emp_code = deletiondata.emp_code + + WHERE employee_polices.client_policy_id = '$client_policy_id' + AND employees.client_branch_id = '$client_branch_id' + AND a.actions = 'd' + AND employee_polices.is_active = 1 + AND employee_polices.status = 'active' + AND employees.is_active = 1 + AND employees.emp_status = 'active' + AND (a.endorsement_id IS NULL OR a.endorsement_id = '') + group by group_key + "; + + $query = $db->query($sql); + $endorsement_data = $query->getResultArray(); + + + if ($endorsement_data == null || empty($endorsement_data)) { + + $data = [ + 'status' => 'failed-1', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'Deletion File Validation ENDORSEMENT ID already updated'); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The list of employees provided has already been updated with the ENDORSEMENT ID, or this is not the correct file'; + $this->myLogger->logme('error', 'Deletion File Validation ENDORSEMENT ID already updated or the uploadedfile is not correct'); + } + + $excel_data_count = count($excel_data); + $endorsement_data_count = count($endorsement_data); + + $this->myLogger->logme('error', 'Deletion File Validation excel file count : {data}', ['data' => $excel_data_count]); + $this->myLogger->logme('error', 'Deletion File Validation database count : {data}', ['data' => $endorsement_data_count]); + + + $difference = $endorsement_data_count - $excel_data_count; + + $status = 'in-progress'; + if ($excel_data_count < $endorsement_data_count) { + + $status = 'in-progress-partially'; + $partially_updated_data = 'Expected : ' . $endorsement_data_count . ', ' . 'Updated : ' . $excel_data_count . ', ' . 'difference : ' . $difference; + $this->myLogger->logme('error', 'Deletion File Validation excel file count partially : {data}', ['data' => $partially_updated_data]); + } + + + + if ($endorsement_data_count < $excel_data_count) { + + $data = [ + 'status' => 'failed-3', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'Deletion File Validation excel file count ( {excel} ) exceeds db count ( {db} )', ['db' => $endorsement_data_count, 'excel' => $excel_data_count]); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The Excel record count exceeds the DB record count. excel file count : ' . $excel_data_count . ' db count : ' . $endorsement_data_count; + } + + + $errors = []; // Initialize an array to store errors + $missing_id = []; + $batch_list_id = []; + + foreach ($endorsement_data as $key => $endorsement_value) { + + $key = $key + 1; + + if (!isset($excel_data[$key])) { + break; + } + + + if ($excel_data[$key][15] === null) { + $missing_id[$key][] = [ + 'row' => $key, + 'column' => 15, + ]; + } + + + if ($endorsement_value['emp_name'] != $excel_data[$key][2]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 2, + 'db_data' => $endorsement_value['emp_name'], + 'excel_data' => $excel_data[$key][2] + ]; + } + + if ($endorsement_value['emp_code'] != $excel_data[$key][1]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 1, + 'db_data' => $endorsement_value['emp_code'], + 'excel_data' => $excel_data[$key][1] + ]; + } + + if ($endorsement_value['emp_dob'] != $excel_data[$key][3]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 3, + 'db_data' => $endorsement_value['emp_dob'], + 'excel_data' => $excel_data[$key][3] + ]; + } + + if ($endorsement_value['emp_gender'] != $excel_data[$key][4]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 4, + 'db_data' => $endorsement_value['emp_gender'], + 'excel_data' => $excel_data[$key][4] + ]; + } + + + if ($endorsement_value['emp_relationship'] != $excel_data[$key][5]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 5, + 'db_data' => $endorsement_value['emp_relationship'], + 'excel_data' => $excel_data[$key][5] + ]; + } + + if ($endorsement_value['basic_cover_si'] != $excel_data[$key][6]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 6, + 'db_data' => $endorsement_value['basic_cover_si'], + 'excel_data' => $excel_data[$key][6] + ]; + } + + if ($endorsement_value['dateofexit'] != $excel_data[$key][7]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 7, + 'db_data' => $endorsement_value['dateofexit'], + 'excel_data' => $excel_data[$key][7] + ]; + } + + if ($endorsement_value['policy_end_date'] != $excel_data[$key][8]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 8, + 'db_data' => $endorsement_value['policy_end_date'], + 'excel_data' => $excel_data[$key][8] + ]; + } + + if ($endorsement_value['no_of_days'] != $excel_data[$key][9]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 9, + 'db_data' => $endorsement_value['no_of_days'], + 'excel_data' => $excel_data[$key][9] + ]; + } + + + + if ($endorsement_value['premium'] != $excel_data[$key][10]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 10, + 'db_data' => $endorsement_value['premium'], + 'excel_data' => $excel_data[$key][10] + ]; + } + + if ($endorsement_value['pro_rata_premium'] != $excel_data[$key][11]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 11, + 'db_data' => $endorsement_value['pro_rata_premium'], + 'excel_data' => $excel_data[$key][11] + ]; + } + + if ($endorsement_value['gst'] != $excel_data[$key][12]) { + $errors[$key][] = [ + 'row' => $key, + 'column' => 12, + 'db_data' => $endorsement_value['gst'], + 'excel_data' => $excel_data[$key][12] + ]; + } + + $batch_list_id[] = array('emp_policy_id' =>$endorsement_value['primaryKey'], 'batch_code' => $batch_code, 'created_by' => $user_id); + } + + + $error_count = count($errors); + $json_errors = json_encode($errors); + + + $missing_id_count = count($missing_id); + $json_missing_id = json_encode($missing_id); + + // dd($error_count, $missing_id_count, $json_errors, $json_missing_id, $batch_list_id); + + if ($missing_id_count > 0) { + + $data = [ + + 'count' => $endorsement_data_count, + 'error_data' => $json_missing_id, + 'status' => 'failed', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'The ENDORSEMENT ID column is either partially or entirely empty.'; + } + + + if ($error_count > 0) { + + $data = [ + 'count' => $endorsement_data_count, + 'error_data' => $json_errors, + 'status' => 'failed', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'Deletion File Validation Failed'; + + } else { + + $data = [ + 'count' => $endorsement_data_count, + 'status' => $status, + 'error_data' => $partially_updated_data ?? null, + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $insert = $this->batchListModel->insertBatch($batch_list_id); + + + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'importDeletionUpdateEndorsementID', 'payload' => ['file_id' => $file_id]]); + + // $this->importDeletionUpdateEndorsementID(['file_id' => $file_id]); + + return 'Deletion File Validation ENDORSEMENT ID validated the file Successfully'; + } + + } + + + public function importDeletionUpdateEndorsementID($params) + { + + $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- Function called'); + + $file_id = $params['file_id']; + $file = $this->batchFileModel->find($file_id); + if (!$file) { + + $data = [ + 'status' => 'failed-4', + ]; + + $this->batchFileModel->where('id', $file_id)->set($data)->update(); + $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- The Physical file not found -- File id : {data}', ['data' => $file_id]); + + $file_data = $this->getDataByFileId($file_id, 'failure'); + $this->setPullNotification($file_data); + + return 'Deletion Update Endorsement ID -- The Physical file not found'; // Return error code if file not found + } + + $client_id = $file['client_id']; + $client_policy_id = $file['client_policy_id']; + $client_branch_id = $file['client_branch_id']; + $status = $file['status']; + $batch_code = $file['batch_code']; + $user_id = $file['created_by']; + + + $status_val = 'success'; + if ($status == 'in-progress-partially') { + + $status_val = 'partially success'; + } + + $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- file name : {data}', ['data' => $file['file_name']]); + + $file_name_with_path = WRITEPATH . "/uploads/import_excel/" . $file['file_name']; + $excel_data = $this->readExcelFileToArray($file_name_with_path); + unset($excel_data[0]); + array_pop($excel_data); + + $emp_count = count($excel_data); //excel file count + + $employees_table_data = []; + $emp_endorsement_table_data = []; + $employee_policy_table_data = []; + $employee_policy_table_primaryKey = []; + + $totals = 0; + + + foreach ($excel_data as $key => $value) { + + $emp_name = $value[2]; //employee name + $emp_code = $value[1]; //employee code + $totals = $totals + $value[13]; + + + $fetch_data = [ + 'client_policy_id' => $client_policy_id, + 'client_branch_id' => $client_branch_id, + 'emp_name' => $emp_name, + 'emp_code' => $emp_code + ]; + $result = $this->employeePolicyModel->fetchEmpEndorsementData($fetch_data); + + // dd($result['emp_endorsement_primarykey']); + + if (isset($result['emp_endorsement_primarykey']) && $result['emp_endorsement_primarykey'] !== null) { + + $employee_policy_table_primaryKey[] = $result['emp_policy_primarykey']; //for cash deposite + $employee_policy_table_data[] = array('id' => $result['emp_policy_primarykey'], 'date_of_exit' => $result['date_of_exit'], 'reason_for_exit' => $result['reason_for_exit'], 'status' => $result['status'], 'is_active' => 0); + $employees_table_data[] = array('id' => $result['employees_primarykey'], 'emp_status' => $result['status'], 'is_active' => 0); + $emp_endorsement_table_data[] = array('id' => $result['emp_endorsement_primarykey'], 'group_key' => $result['group_key'], 'endorsement_id' => $value[15], 'status' => 'complete'); + } + + } + + $rounded_totals = round($totals, 2); + + // dd($employees_table_data, $emp_endorsement_table_data, $employee_policy_table_data, $employee_policy_table_primaryKey, $totals, $emp_count); + + + // Check if $employees_table_data is null or empty + if (empty($employees_table_data)) { + return ['error' => true, 'message' => 'Employees table data is empty or null.']; + } + + // Check if $employee_policy_table_data is null or empty + if (empty($employee_policy_table_data)) { + return ['error' => true, 'message' => 'Employee policy table data is empty or null.']; + } + + // Check if $emp_endorsement_table_data is null or empty + if (empty($emp_endorsement_table_data)) { + return ['error' => true, 'message' => 'Employee endorsement table data is empty or null.']; + } + + $this->employeeModel->updateBatch($employees_table_data, 'id'); + $this->employeePolicyModel->updateBatch($employee_policy_table_data, 'id'); + $this->employeePolicyModel->bulkUpdateForEndorsement($emp_endorsement_table_data); + + // Update batch file status and amount + $this->batchFileModel->update($file_id, [ + 'count' => $emp_count, + 'status' => $status_val, + 'amount' => $rounded_totals, + ]); + + + $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- Employee count : {data}', ['data' => $emp_count]); + $this->myLogger->logme('error', 'Deletion Update Endorsement ID -- Batch File status : {data}', ['data' => $status_val]); + + + $file_data = $this->getDataByFileId($file_id, 'success'); + $this->setPullNotification($file_data); + + //call the cash deposite function + + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'cashDepositCalculationForDeletion', 'payload' => [ + 'employeeIds' => $employee_policy_table_primaryKey, + 'client_id' => $client_id, + 'client_policy_id' => $client_policy_id, + 'client_branch_id' => $client_branch_id, + 'count' => $emp_count, + 'event' => $file['event_type'], + 'policy_name' => $policy_name['policy_name'], + 'user_id' => $user_id, + ]]); + + return 'Deletion Update Endorsement ID -- ' . $status_val . '-- Updated Count : ' . $emp_count; + } + + /** * The below functions are Calculates and records cash deposits for employee policies at inception. * @@ -1795,16 +2631,17 @@ class EmpDataServiceController extends BaseController public function cashDepositCalculationForSIEnhancement($arrayData) - { + { + // return $arrayData; + if (!empty($arrayData)) { $amount = $this->employeePolicyModel->query(" - SELECT - SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365, 2) + - ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365) * 0.18, 2)) AS total_sum + SELECT SUM(rata_premimum + gst) AS total_sum FROM employee_polices WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ") - ")->getRow(); + ")->getRow(); + $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first(); $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.'; @@ -1816,11 +2653,12 @@ class EmpDataServiceController extends BaseController 'insurer_id' => $insurer_id['insurer_id'], 'description' => $description, 'transaction_type' => 'Debit', - 'updated_by' => get_session_userid(), + 'updated_by' => $arrayData['user_id'], 'is_active' => 1, ]; - $response = DepositHelper::saveDeposit($data, get_session_userid()); - return true; + $response = DepositHelper::saveDeposit($data, $arrayData['user_id']); + $msg = "SI Enhancement Cash Deposite Updated Successfully -- " . $description; + return [$msg, $response]; // print_r($response); // $query = $this->employeePolicyModel->getLastQuery(); // echo $query . "
    "; @@ -1839,11 +2677,9 @@ class EmpDataServiceController extends BaseController // echo '
    ';
                 // print_r($arrayData); die;
                 $amount = $this->employeePolicyModel->query("
    -                SELECT
    -                    SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365, 2) +
    -                        ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365) * 0.18, 2)) AS total_sum
    -                FROM employee_polices
    -                WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
    +                SELECT SUM(rata_premimum + gst) AS total_sum
    +                    FROM employee_polices
    +                    WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
                     ")->getRow();
     
                 $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();
    @@ -1857,10 +2693,13 @@ class EmpDataServiceController extends BaseController
                     'insurer_id' => $insurer_id['insurer_id'],
                     'description' => $description,
                     'transaction_type' => 'Credit',
    -                'updated_by' => get_session_userid(),
    +                'updated_by' => $arrayData['user_id'],
                     'is_active' => 1,
                 ];
    -            $response = DepositHelper::saveDeposit($data, get_session_userid());
    +            $response = DepositHelper::saveDeposit($data, $arrayData['user_id']);
    +            $msg = "Deletion Cash Deposite Updated Successfully -- " . $description;
    +            return [$msg, $response];
    +
                 return true;
                 // print_r($response);
                 // $query = $this->employeePolicyModel->getLastQuery();
    @@ -2210,15 +3049,26 @@ class EmpDataServiceController extends BaseController
     
         public function readExcelFileToArray($path)
         {
    -
             $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($path);
             $sheet = $spreadsheet->getActiveSheet();
    -
    +    
             $highestRowAndColumn = $sheet->getHighestRowAndColumn();
             $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
    -
    -        return $excel_data;
    +    
    +        // Filter out empty or null rows
    +        $filtered_data = array_filter($excel_data, function($row) {
    +            // Check if all cells in the row are empty or null
    +            foreach ($row as $cell) {
    +                if (!is_null($cell) && $cell !== '') {
    +                    return true;
    +                }
    +            }
    +            return false;
    +        });
    +    
    +        return $filtered_data;
         }
    +    
     
     
         public function removeOldExportInfoFromBatchFile($params){
    @@ -2242,7 +3092,6 @@ class EmpDataServiceController extends BaseController
     
                     $id = $batch_data['id'];
                     $batch_code = $batch_data['batch_code'];
    -
                     $this->batchFileModel->where('id', $id)->delete();
                     $this->batchListModel->where('batch_code', $batch_code)->delete();
     
    diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php
    index 3e73f9a8..feba609b 100644
    --- a/app/Controllers/EmployeeController.php
    +++ b/app/Controllers/EmployeeController.php
    @@ -358,7 +358,7 @@ class EmployeeController extends AdminController
         public function importExport()
         {
     
    -        $this->myLogger->logme('error', 'importExport function called');
    +        $this->myLogger->logme('error', 'Import Export --  Function called');
             $empDataServiceController = new EmpDataServiceController();
     
             $client_id = $this->request->getPost('client_id');
    @@ -370,10 +370,10 @@ class EmployeeController extends AdminController
     
             $client_data = $this->clientModel->where('id', $client_id)->first();
             $policy_name_and_branch_name = $this->clientPolicyModel->select('policies.name, client_branch.branch_code')
    -                            ->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
    -                            ->join('policies', 'policies.id = client_policy.policy_id')
    -                            ->where('client_policy.id', $client_policy_id)
    -                            ->first();
    +        ->join('client_branch', 'client_branch.id = client_policy.client_branch_id')
    +        ->join('policies', 'policies.id = client_policy.policy_id')
    +        ->where('client_policy.id', $client_policy_id)
    +            ->first();
             $file_name = generate_filename($client_data['short_name'], $event_type, $actions, $insurer_or_tpa, $policy_name_and_branch_name['name'], $policy_name_and_branch_name['branch_code']);
     
             $batch_data = [
    @@ -386,20 +386,19 @@ class EmployeeController extends AdminController
                 'file_name' => $file_name,
             ];
     
    -        //  $event_type = 'si_enhancement';
     
             if ($actions == 'export') {
     
                 if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition') {
     
                     $return = $empDataServiceController->generateExcelForAdditionandInception($batch_data);
    -               
    -                if($return == 0){
    +
    +                if ($return == 0) {
     
                         session()->setFlashdata('error', "Insufficient deposit amount.");
                         return redirect()->to(base_url('employee/upload'));
    -                } 
    -                
    +                }
    +
                     if (!$return) {
     
                         if ($insurer_or_tpa == 'tpa') {
    @@ -409,7 +408,6 @@ class EmployeeController extends AdminController
                             session()->setFlashdata('error', "No data was found for this action. The UHID has already been updated.");
                             return redirect()->to(base_url('employee/upload'));
                         }
    -
                     } else {
                         $this->myLogger->logme('error', 'Successfully exported Excel file in {data}.', ['data' => $event_type]);
                     }
    @@ -425,6 +423,13 @@ class EmployeeController extends AdminController
                 } else if ($event_type == 'si_enhancement') {
     
                     $return = $empDataServiceController->generateExcelForSIEnhancement($batch_data);
    +
    +                if ($return == 0) {
    +
    +                    session()->setFlashdata('error', "Insufficient deposit amount.");
    +                    return redirect()->to(base_url('employee/upload'));
    +                }
    +
                     if (!$return) {
                         session()->setFlashdata('error', 'No data found about this action');
                         return redirect()->to(base_url('employee/upload'));
    @@ -444,29 +449,25 @@ class EmployeeController extends AdminController
             } else if ($actions == 'import') {
     
                 $batch_data['file'] = $this->request->getFile('import_file_data');
    -            
    +            $file = $this->request->getFile('import_file_data');
    +
    +            $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
    +            $filename = $file->getName();
    +            $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
    +
    +            $random_number_count = 4;
    +            $batch_data['batch_code'] = generate_random_string($random_number_count);
    +            $batch_data['created_by'] = get_session_userid();
    +            $batch_data['status'] = 'pending';
    +            $batch_data['file_name'] = $filename;
     
                 if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition') {
     
    -
    -                $file = $this->request->getFile('import_file_data');
    -
    -                $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
    -                $filename = $file->getName();
    -                $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
    -        
    -        
    -                $random_number_count = 4;
    -                $batch_data['batch_code'] = generate_random_string($random_number_count);
    -                $batch_data['created_by'] = get_session_userid();
    -                $batch_data['status'] = 'pending';
    -                $batch_data['file_name'] = $filename;
    -        
                     $file_id = $this->batchFileModel->insert($batch_data);
     
    -                $job_details  = new Jobs();                             
    -                $r = Jobs::addJob(['job_name' => 'importInceptionFileValidation','payload' => ['file_id' => $file_id]]);
    -        
    +                $job_details  = new Jobs();
    +                $r = Jobs::addJob(['job_name' => 'importInceptionFileValidation', 'payload' => ['file_id' => $file_id]]);
    +
                     $return = 1;
     
                     // $return = $empDataServiceController->importInceptionFileValidation(['file_id' => $file_id]);
    @@ -474,71 +475,64 @@ class EmployeeController extends AdminController
                     if ($return == 1) {
                         session()->setFlashdata('success', 'Data updated successfully. File is being validated.');
                         return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 2) {
    -                    session()->setFlashdata('error', 'The TPA ID column is either partially or entirely empty.');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 0) {
    -                    session()->setFlashdata('error', 'Please upload the correct file.');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 3) {
    -                    session()->setFlashdata('error', 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 4) {
    -                    session()->setFlashdata('error', 'The UHID column is either partially or entirely empty.');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 5) {
    -                    session()->setFlashdata('error', 'The list of employees provided has already been updated with the UHID, or this is not the correct file');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 6) {
    -                    session()->setFlashdata('error', 'The Excel record count exceeds the DB record count.');
    +                } else {
    +                    session()->setFlashdata($return['status'], $return['message']);
                         return redirect()->to(base_url('employee/upload'));
                     }
                 } else if ($event_type == 'correction') {
     
    -                $return = $empDataServiceController->importExcelDataForCorrection($batch_data);
    +                $file_id = $this->batchFileModel->insert($batch_data);
    +
    +                $job_details  = new Jobs();
    +                $r = Jobs::addJob(['job_name' => 'importCorrectionValidation', 'payload' => ['file_id' => $file_id]]);
    +
    +                $return = 1;
    +
    +                // $return = $empDataServiceController->importCorrectionValidation(['file_id' => $file_id]);
    +
                     if ($return == 1) {
    -                    session()->setFlashdata('success', 'Data updated successfully');
    +                    session()->setFlashdata('success', 'Data updated successfully. File is being validated.');
                         return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 2) {
    -                    session()->setFlashdata('error', 'The Endorsement ID columns are empty.');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 0) {
    -                    session()->setFlashdata('error', 'Please upload the correct file');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 3) {
    -                    session()->setFlashdata('error', 'File already uploaded');
    +                } else {
    +                    session()->setFlashdata('error', $return);
                         return redirect()->to(base_url('employee/upload'));
                     }
                 } else if ($event_type == 'si_enhancement') {
     
    -                $return = $empDataServiceController->importExcelDataForSIEnhancement($batch_data);
    +
    +                $file_id = $this->batchFileModel->insert($batch_data);
    +
    +                $job_details  = new Jobs();
    +                $r = Jobs::addJob(['job_name' => 'importSIEnhancementValidation', 'payload' => ['file_id' => $file_id]]);
    +
    +                $return = 1;
    +
    +                // $return = $empDataServiceController->importSIEnhancementValidation(['file_id' => $file_id]);
    +
                     if ($return == 1) {
    -                    session()->setFlashdata('success', 'Data updated successfully');
    +                    session()->setFlashdata('success', 'Data updated successfully. File is being validated.');
                         return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 2) {
    -                    session()->setFlashdata('error', 'The Endorsement ID columns are empty.');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 0) {
    -                    session()->setFlashdata('error', 'Please upload the correct file');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 3) {
    -                    session()->setFlashdata('error', 'File already uploaded');
    +                } else {
    +                    session()->setFlashdata('error', $return);
                         return redirect()->to(base_url('employee/upload'));
                     }
                 } else if ($event_type == 'deletion') {
     
    -                $return = $empDataServiceController->importExcelDataForDeletion($batch_data);
    +                $file_id = $this->batchFileModel->insert($batch_data);
    +
    +                $job_details  = new Jobs();
    +                $r = Jobs::addJob(['job_name' => 'importDeletionValidation', 'payload' => ['file_id' => $file_id]]);
    +
    +                $return = 1;
    +
    +                // $return = $empDataServiceController->importDeletionValidation(['file_id' => $file_id]);
    +
    +
                     if ($return == 1) {
    -                    session()->setFlashdata('success', 'Data updated successfully');
    +                    session()->setFlashdata('success', 'Data updated successfully. File is being validated.');
                         return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 2) {
    -                    session()->setFlashdata('error', 'The Endorsement ID columns are empty.');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 0) {
    -                    session()->setFlashdata('error', 'Please upload the correct file');
    -                    return redirect()->to(base_url('employee/upload'));
    -                } else if ($return == 3) {
    -                    session()->setFlashdata('error', 'File already uploaded');
    +                } else {
    +                    session()->setFlashdata('error', $return);
                         return redirect()->to(base_url('employee/upload'));
                     }
                 }
    @@ -707,6 +701,9 @@ class EmployeeController extends AdminController
     
         public function viewUploadedEmployeeList()
         {
    +
    +        $empDataServiceController = new EmpDataServiceController();
    +
             $file_id = $this->request->getGet('file_id');
             // $emp_data['employees'] = $this->employeePolicyModel->getViewEmpSuccessList($file_id);
             // $html = view('view_file_upload_emp_list', $emp_data);
    @@ -718,20 +715,21 @@ class EmployeeController extends AdminController
                 ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left')
                 ->where('files.id', $file_id)->first();
     
    +            // dd($file_name);
    +
             try {
     
                 $filePath = WRITEPATH . '/uploads/excel/' . $file_name['file_name'];
     
                 if (file_exists($filePath)) {
    -                $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath);
    -                $sheet = $spreadsheet->getActiveSheet();
    -
    -                $highestRowAndColumn = $sheet->getHighestRowAndColumn();
    -                $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
    -                // dd($excel_data);
    +                
    +                $excel_data = $empDataServiceController->readExcelFileToArray($filePath);
                     $emp_data['thead'] = $excel_data[0];
                     unset($excel_data[0]);
                     $emp_data['tbody'] = $excel_data;
    +                $emp_data['count'] = count($excel_data);
    +
    +                // dd($emp_data);
     
                     $html = view('view_file_upload_emp_list', $emp_data);
                 } else {
    @@ -1210,6 +1208,7 @@ class EmployeeController extends AdminController
             $client_id = $file['client_id'];
             $client_policy_id = $file['client_policy_id'];
             $insurer_or_tpa = $file['insurer_or_tpa'];
    +        $event_type = $file['event_type'];
     
             $error_data = json_decode($file['error_data']);
     
    @@ -1225,8 +1224,10 @@ class EmployeeController extends AdminController
             $excel_data = $empDataServiceController->readExcelFileToArray($file_name_with_path);
             $excelErrorData['excel_header'] = $excel_data[0];
             unset($excel_data[0]);
    -        array_pop($excel_data);
     
    +        if($event_type == 'inception' || $event_type == 'deletion'){
    +            array_pop($excel_data);
    +        }
     
             $finalArray = [];
             foreach ($error_data as $key => $values) {
    @@ -1242,15 +1243,22 @@ class EmployeeController extends AdminController
     
                     }else{
     
    -                    if ($insurer_or_tpa == 'tpa') {
    +                    if($event_type == 'inception'){
     
    -                        $error = 'Expected value : TPA ID';
    +                        if ($insurer_or_tpa == 'tpa') {
     
    -                    } else if ($insurer_or_tpa == 'insurer') {
    -        
    -                        $error = 'Expected value : UHID';
    +                            $error = 'Expected value : TPA ID';
    +    
    +                        } else if ($insurer_or_tpa == 'insurer') {
    +            
    +                            $error = 'Expected value : UHID';
    +                        }
    +
    +                    }else{
    +                        $error = 'Expected value : ENDORSEMENT ID';
                         }
     
    +
                     }
                     $data = ['value' => $excel_data[$row][$column], 'error' => $error,];
                     $excel_data[$row][$column] = $data;
    diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php
    index 793ddb76..38fd648a 100644
    --- a/app/Controllers/JobWorker.php
    +++ b/app/Controllers/JobWorker.php
    @@ -16,10 +16,22 @@ class JobWorker extends AdminController
     
         private  static $event_class_mapping = [
             'add' => ['type' => 'HC', 'handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' =>  ['type' => 'CC', 'handler' => 'App\\Controllers\\Jobs\SubJob'], 'fancy_date_time_format' => ['type' => 'HF', 'handler' => 'fancy_date_time_format'], 'addNumber' => ['type' => 'HC', 'handler' => 'App\\Model\\HttpRequestHelper'], 'excelFileFormatValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'excelFileDataValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesOnboardPreprocess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeeDisembark' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesSIEnhanceProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesCorrectionProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'send_email' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'bulk_mail' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'insertBatchList' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +       
             'importInceptionFileValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
             'importInceptionUpdateTPAandUHID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
             'cashDepositCalculationForInception' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
             'sendMailForDownloadingECard' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        
    +        'importCorrectionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        'importCorrectionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        
    +        'cashDepositCalculationForSIEnhancement' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        'importSIEnhancementValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        'importSIEnhancementUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        
    +        'cashDepositCalculationForDeletion' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        'importDeletionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
    +        'importDeletionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
         ];
         public function __construct()
         {
    diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php
    index 2e7bcf23..4f9652d9 100644
    --- a/app/Models/EmployeePolicyModel.php
    +++ b/app/Models/EmployeePolicyModel.php
    @@ -143,7 +143,7 @@ class EmployeePolicyModel extends Model
                     employees.relationship AS emp_relationship,
                     employees.relationship_code AS emp_relationship_code,
                     TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
    -                'Has Define' as emp_type,
    +                employees.emp_type as emp_type,
     
                     employee_polices.id as primaryKey, 
                     employee_polices.tpa_id, 
    @@ -175,8 +175,13 @@ class EmployeePolicyModel extends Model
                 ) as batch_data ON employee_polices.id = batch_data.emp_policy_id
                 WHERE employee_polices.client_policy_id = '{$client_policy_id}'
                     AND (employee_polices.{$id} IS NULL OR employee_polices.{$id} = '')
    +                AND employees.client_branch_id = '{$client_branch_id}'
                     AND employee_polices.is_active = 1
    -                AND employees.client_branch_id = '{$client_branch_id}'";
    +                AND employee_polices.status = 'active'
    +                AND employees.is_active = 1
    +                AND employees.emp_status = 'active'
    +                
    +        ";
     
                 // Get the result set
                 $query = $this->db->query($sql);
    @@ -209,7 +214,7 @@ class EmployeePolicyModel extends Model
                             employees.dob AS emp_dob, 
                             employees.gender AS emp_gender, 
                             employees.client_id AS emp_client_id, 
    -                        'Has Define' AS emp_type,
    +                        employees.emp_type as emp_type,
                             employee_polices.uhid,
                             employees.relationship_code,
                             batch_data.emp_policy_id, 
    @@ -235,12 +240,16 @@ class EmployeePolicyModel extends Model
                             AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
                         ) AS batch_data ON emp_endorsement.pk = batch_data.emp_policy_id
     
    -                    WHERE batch_data.bf IS NULL
    -                    AND batch_data.bl IS NULL
    -                    AND employees.client_id = '{$client_id}'
    +                    WHERE employees.client_id = '{$client_id}'
                         AND employee_polices.client_policy_id = '{$client_policy_id}'
                         AND employees.client_branch_id = '{$client_branch_id}'
                         AND emp_endorsement.actions = 'c'
    +                    AND employee_polices.is_active = 1
    +                    AND employee_polices.status = 'active'
    +                    AND employees.is_active = 1
    +                    AND employees.emp_status = 'active'
    +                    AND (employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '')
    +                    AND (employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '')                    
                         AND (emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')";
     
                     // Execute the raw query
    @@ -265,13 +274,14 @@ class EmployeePolicyModel extends Model
                 $query = $this->db->query("
                         SELECT 
                             a.id as endorsement_primarykey,
    +                        a.group_key,
                             employee_polices.id AS primaryKey,
                             employees.name AS emp_name,
                             employees.emp_code AS emp_code,
                             employees.dob AS emp_dob,
                             employees.gender AS emp_gender,
                             employees.relationship_code AS emp_relationship_code,
    -                        'Has Define' AS emp_type,
    +                        employees.emp_type as emp_type,
                             employee_polices.uhid AS risk_id,
                             employee_polices.pre_existing_alignments,
                             employee_polices.policy_end_date,
    @@ -283,10 +293,15 @@ class EmployeePolicyModel extends Model
                             sidata.new_basic_cover_si, 
                             sidata.new_si_premium,
                             sidata.date_of_coverage,
    +                        
                             DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days,
    +
                             sidata.new_si_premium - employee_polices.rata_premimum AS difference_premium,
    +
                             ROUND((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum,
    +
                             ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst,
    +
                             ((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total
     
                         FROM 
    @@ -346,14 +361,16 @@ class EmployeePolicyModel extends Model
                                 AND batch_files.actions = 'export' 
                                 AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
                         ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
    -                    WHERE 
    -                        batch_data.bf IS NULL 
    -                        AND batch_data.bl IS NULL 
    -                        AND employee_polices.client_policy_id = '{$client_policy_id}'
    -                        AND employees.client_branch_id = '{$client_policy_id}'
    -                        AND employee_polices.is_active = '1'
    +
    +                    WHERE employee_polices.client_policy_id = '{$client_policy_id}'
    +                        AND employees.client_branch_id = '{$client_branch_id}'
                             AND (a.endorsement_id IS NULL OR a.endorsement_id = '') 
    -                        AND a.field_name = 'si_enhancement_date'
    +                        AND a.actions = 'si'
    +                        AND employee_polices.is_active = 1
    +                        AND employee_polices.status = 'active'
    +                        AND employees.is_active = 1
    +                        AND employees.emp_status = 'active'
    +                        group by group_key
                     ");
     
                     // Get the result set
    @@ -374,13 +391,14 @@ class EmployeePolicyModel extends Model
                 $query = $this->db->query("
                 SELECT DISTINCT
                     a.id as endorsement_primarykey,
    +                a.group_key,
                     employee_polices.id as primaryKey, 
                     employees.name AS emp_name,
                     employees.emp_code AS emp_code,
                     employees.dob AS emp_dob,
                     employees.gender AS emp_gender,
                     employees.relationship AS emp_relationship,
    -                'Has Define' as emp_type,
    +                employees.emp_type as emp_type,
                     
                     employee_polices.basic_cover_si, 
                     employee_polices.uhid as risk_id, 
    @@ -404,7 +422,7 @@ class EmployeePolicyModel extends Model
                 FROM 
                     emp_endorsement a
                 LEFT JOIN 
    -                employees ON a.emp_code = employees.emp_code 
    +                employees ON a.emp_code = employees.emp_code and a.pk = employees.id 
                 LEFT JOIN 
                     employee_polices ON employees.id = employee_polices.employee_id 
                 
    @@ -439,16 +457,20 @@ class EmployeePolicyModel extends Model
                         AND batch_files.actions = 'export'
                         AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
                     ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id 
    -            WHERE 
    -                batch_data.bf IS NULL
    -                AND batch_data.bl IS NULL
    -                AND employee_polices.client_policy_id = {$client_policy_id}
    +
    +            WHERE employee_polices.client_policy_id = {$client_policy_id}
                     AND employees.client_branch_id = {$client_branch_id}
    +                AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
    +                AND a.actions = 'd'
                     AND employee_polices.is_active = 1
    -                AND (a.endorsement_id IS NULL OR a.endorsement_id = '') AND a.field_name = 'status'
    +                AND employee_polices.status = 'active'
    +                AND employees.is_active = 1
    +                AND employees.emp_status = 'active'
    +                group by group_key
             ");
         
             $result = $query->getResult();
    +
             return $result;
             
         }
    @@ -547,34 +569,62 @@ class EmployeePolicyModel extends Model
     
         public function fetchEmpEndorsementData($fetch_data)
         {
    +        // dd($fetch_data);
    +
             $client_policy_id = $fetch_data['client_policy_id'];
    +        $client_branch_id = $fetch_data['client_branch_id'];
             $emp_name = $fetch_data['emp_name'];
             $emp_code = $fetch_data['emp_code'];
     
             // Your raw SQL query
             $sql = "
    -            SELECT 
    -                ep.id,
    -                MAX(CASE WHEN ee.field_name = 'date_of_exit' THEN ee.new_value END) AS date_of_exit,
    -                MAX(CASE WHEN ee.field_name = 'reason_for_exit' THEN ee.new_value END) AS reason_for_exit,
    -                MAX(CASE WHEN ee.field_name = 'status' THEN ee.new_value END) AS status
    -            FROM 
    -                emp_endorsement AS ee
    -            JOIN 
    -                employee_polices AS ep ON ep.id = ee.pk
    -            WHERE 
    -                ee.emp_code = '$emp_code'
    -                AND ep.client_policy_id = $client_policy_id
    -                AND ee.name = '$emp_name'
    -                AND ee.field_name IN ('date_of_exit', 'reason_for_exit', 'status')
    -            GROUP BY 
    -                ee.emp_code, ee.name, ep.id";
    +                SELECT
    +                    ee.id as emp_endorsement_primarykey,
    +                    ep.id as emp_policy_primarykey,
    +                    e.id as employees_primarykey,
    +                    ee.group_key,
    +                    MAX(
    +                    CASE
    +                        WHEN ee.field_name = 'date_of_exit' THEN ee.new_value
    +                    END
    +                    ) AS date_of_exit,
    +                    MAX(
    +                    CASE
    +                        WHEN ee.field_name = 'reason_for_exit' THEN ee.new_value
    +                    END
    +                    ) AS reason_for_exit,
    +                    MAX(
    +                    CASE
    +                        WHEN ee.field_name = 'status' THEN ee.new_value
    +                    END
    +                    ) AS status
    +                FROM
    +                    emp_endorsement AS ee
    +                    JOIN employee_polices AS ep ON ep.id = ee.pk
    +                    JOIN employees AS e ON e.emp_code = ee.emp_code
    +                WHERE
    +                    ee.emp_code = '$emp_code'
    +                    AND ep.client_policy_id = '$client_policy_id'
    +                    AND e.client_branch_id = '$client_branch_id'
    +                    AND ee.name = '$emp_name'
    +                    AND ee.field_name IN ('date_of_exit', 'reason_for_exit', 'status')
    +                    AND ep.is_active = 1
    +                    AND ep.status = 'active'
    +                    AND e.is_active = 1
    +                    AND e.emp_status = 'active'
    +                GROUP BY
    +                    ee.group_key
    +        ";
    +
    +        // dd($sql);
     
             // Execute the raw SQL query
             $query = $this->db->query($sql);
     
             // Fetch and return results
    -        return  $row = $query->getRowArray();
    +         $row = $query->getRowArray();
    +
    +         return $row;
         }
         
     
    @@ -659,7 +709,7 @@ class EmployeePolicyModel extends Model
                     $query2->join('insurers', 'insurers.id = policies.insurer_id');
                     $query2->whereIn('e.actions', ['si', 'd']);
                     $query2->where('ep.client_policy_id', $policy_id);
    -                $query2->where('employees.client_id', $policy_id);
    +                $query2->where('employees.client_id', $client_id);
                     $query1->where('employees.client_branch_id', $branch_id);
                     if($status != 0 && !empty($status)){
     
    @@ -931,7 +981,132 @@ class EmployeePolicyModel extends Model
                 throw $e;
             }
         }
    +
    +
    +    public function bulkUpdateForEndorsement($endorsement_details)
    +    {
    +
    +        // Extract IDs, endorsement_ids, and statuses
    +        $ids = array_column($endorsement_details, 'group_key');
    +        $endorsement_ids = array_column($endorsement_details, 'endorsement_id');
    +        $statuses = array_column($endorsement_details, 'status');
    +
    +        // Escape values for SQL
    +        $escapedIds = array_map([$this->db, 'escape'], $ids);
    +        $escapedEndorsementIds = array_map([$this->db, 'escape'], $endorsement_ids);
    +        $escapedStatuses = array_map([$this->db, 'escape'], $statuses);
    +
    +        // Construct the CASE statements
    +        $caseEndorsementId = array_map(function ($id, $endorsement_id) {
    +            return "WHEN group_key = $id THEN $endorsement_id";
    +        }, $escapedIds, $escapedEndorsementIds);
    +
    +        $caseStatus = array_map(function ($id, $status) {
    +            return "WHEN status = $id THEN $status";
    +        }, $escapedIds, $escapedStatuses);
    +
    +        // Convert cases to a string
    +        $caseEndorsementIdString = implode(' ', $caseEndorsementId);
    +        $caseStatusString = implode(' ', $caseStatus);
    +
    +        // Convert ids to a string
    +        $idsString = implode(', ', $escapedIds);
    +
    +        // Construct the SQL query
    +        $sql = "
    +            UPDATE emp_endorsement
    +            SET 
    +                endorsement_id = CASE {$caseEndorsementIdString} END,
    +                status = CASE {$caseStatusString} END
    +            WHERE group_key IN ({$idsString})
    +        ";
    +
    +        // Begin a transaction
    +        $this->db->transBegin();
    +
    +        try {
    +            // Execute the query
    +            $this->db->query($sql);
    +
    +            // Commit the transaction
    +            if ($this->db->transStatus() === FALSE) {
    +                // If something went wrong, rollback
    +                $this->db->transRollback();
    +                throw new \Exception('Bulk update failed.');
    +            } else {
    +                // Otherwise, commit
    +                $this->db->transCommit();
    +            }
    +
    +            return $this->db->getLastQuery();
    +        } catch (\Exception $e) {
    +            // Rollback the transaction on error
    +            $this->db->transRollback();
    +            throw $e;
    +        }
    +    }
         
     
    +    public function bulkUpdateForCorrection($emp_details){
    +
    +        foreach ($emp_details as $employee) {
    +            $id = $this->db->escape($employee['id']);
    +            $ids[] = $id;
    +        
    +            foreach ($employee as $field => $value) {
    +                if ($field === 'id') continue;
    +                $escapedValue = $this->db->escape($value);
    +        
    +                if (!isset($caseStatements[$field])) {
    +                    $caseStatements[$field] = [];
    +                }
    +        
    +                $caseStatements[$field][] = "WHEN id = $id THEN $escapedValue";
    +            }
    +        }
    +        
    +        // Construct the CASE strings
    +        $caseStrings = [];
    +        foreach ($caseStatements as $field => $cases) {
    +            $caseStrings[] = "$field = CASE " . implode(' ', $cases) . " END";
    +        }
    +        
    +        // Convert ids to a string
    +        $idsString = implode(', ', $ids);
    +        
    +        // Construct the SQL query
    +        $sql = "
    +            UPDATE employees
    +            SET " . implode(', ', $caseStrings) . "
    +            WHERE id IN ($idsString)
    +        ";
    +        
    +        // Begin a transaction
    +        $this->db->transBegin();
    +        
    +        try {
    +            // Execute the query
    +            $this->db->query($sql);
    +        
    +            // Commit the transaction
    +            if ($this->db->transStatus() === FALSE) {
    +                // If something went wrong, rollback
    +                $this->db->transRollback();
    +                throw new \Exception('Bulk update failed.');
    +            } else {
    +                // Otherwise, commit
    +                $this->db->transCommit();
    +            }
    +        
    +            return $this->db->getLastQuery();
    +            
    +        } catch (\Exception $e) {
    +            // Rollback the transaction on error
    +            $this->db->transRollback();
    +            throw $e;
    +        }
    +
    +    }
    +
     
     }
    \ No newline at end of file
    diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php
    index ab4e17f4..18d6ee36 100644
    --- a/app/Views/client_policy.php
    +++ b/app/Views/client_policy.php
    @@ -14,7 +14,7 @@
                         Policy
                         TPA
                         Date
    -                    Enrollment Status
    +                    Enrollment 
    Status Status Action @@ -252,7 +252,7 @@ ${item.insurer_short} - ${item.insurer_branch_name} ${item.policy_name} (${item.policy_type_name}) ${tpaValue} - ${(item.policy_start_date)} / ${(item.policy_end_date)} + ${(item.policy_start_date)} /
    ${(item.policy_end_date)} ${(enrollmentStatus)} ${checkDateStatus(item.policy_end_date, 1)} @@ -474,7 +474,7 @@ ${item.insurer_short} - ${item.insurer_branch_name} ${item.policy_name} (${item.policy_type_name}) ${tpaValue} - ${rearrangeDateFormat(item.policy_start_date)} - ${rearrangeDateFormat(item.policy_end_date)} + ${rearrangeDateFormat(item.policy_start_date)} /
    ${rearrangeDateFormat(item.policy_end_date)} ${(enrollmentStatus)} ${checkDateStatus(item.policy_end_date, 1)} diff --git a/app/Views/employee_upload.php b/app/Views/employee_upload.php index 052b1bab..82d763cb 100644 --- a/app/Views/employee_upload.php +++ b/app/Views/employee_upload.php @@ -20,8 +20,8 @@ option:disabled {
    -
    + + @@ -38,14 +38,14 @@ option:disabled {

    -

    -
    @@ -214,7 +214,21 @@ $(document).ready(function() { // console.log('submit called'); + if(!checkValues()){ + + toastr.warning('Form is Empty', 'warning') + return false; + } + + + $('#client_id').val() + $('#policy_id').val() + $('#branch_id').val() + $('#upload-action-type').val() + var isValid = $('#emp-upload-form').parsley().validate(); + + console.log('isValid', isValid) if (!isValid) { console.log('Form is Empty', 'Warning'); return; @@ -933,7 +947,7 @@ function checkPolicyTermsAndRackRatesHasDefiend(event) setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); - }, 1000); + }, 300); console.log('check policy responce', response); @@ -965,7 +979,7 @@ function checkPolicyTermsAndRackRatesHasDefiend(event) setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); - }, 1000); + }, 300); // toastr.error('Something went wrong! Try Later', 'Error'); console.error('Error fetching data from checkPolicyTermsAndRackRatesHasDefiend API:', error); return false; @@ -976,5 +990,36 @@ function checkPolicyTermsAndRackRatesHasDefiend(event) } +function checkValues() { + + var clientId = $('#client_id').val(); + var policyId = $('#policy_id').val(); + var branchId = $('#branch_id').val(); + var uploadActionType = $('#upload-action-type').val(); + + if (!clientId || clientId == '0') { + // alert('Client ID is empty or zero'); + return false; + } + + if (!policyId || policyId == '0') { + // alert('Policy ID is empty or zero'); + return false; + } + + if (!branchId || branchId == '0') { + // alert('Branch ID is empty or zero'); + return false; + } + + if (!uploadActionType || uploadActionType == '0') { + // alert('Upload action type is empty or zero'); + return false; + } + + // If all values are valid, return true + return true; +} + //--------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/app/Views/file_list.php b/app/Views/file_list.php index 5c3504af..3f8320ad 100644 --- a/app/Views/file_list.php +++ b/app/Views/file_list.php @@ -81,7 +81,7 @@ class="mdi mdi-dots-horizontal">