From 5ca59ab1a7af045fd6987949bedd2a653690e1f2 Mon Sep 17 00:00:00 2001 From: velz Date: Mon, 15 Dec 2025 15:18:52 +0530 Subject: [PATCH 01/27] FIX_INTERNAL_API_CALL_HEADERS --- app/Controllers/EmployeeRestController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 2dad01de..d9e639e2 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -4408,7 +4408,8 @@ class EmployeeRestController extends AdminController { $client = \Config\Services::curlrequest(); $url = env('PRE_ENROLLMENT_BASEURL') . $endPoint; - $response = $client->post($url, ['json' => $postData, 'http_errors' => false]); + $headers = [ 'App-Signature' => getenv('APP_SIGNATURE') ]; + $response = $client->post($url, ['json' => $postData,'headers' => $headers,'http_errors' => false]); // return json_decode($response->getBody(), true); return $response->getBody(); } From 919d15ed549b920140267e1d4bca32db3890ccec Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Mon, 15 Dec 2025 17:53:06 +0530 Subject: [PATCH 02/27] FIX_Raised issues KYC document list not fetched properly and Excepted required validation in Inception form --- .../PolicyTransactionController.php | 1 + .../policy_transaction_inception_form_2.php | 566 ++++++++++++------ 2 files changed, 396 insertions(+), 171 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 66798ee5..7cc91aca 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -1917,6 +1917,7 @@ $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); + $data['client_kyc_dd_data'] = $clientController->fetch_dropdown($data['client_id']); $data['vehicle_docs'] = $this->clientKYCDocsModel ->where('client_id', $data['client_id']) diff --git a/app/Views/policy_transaction_inception_form_2.php b/app/Views/policy_transaction_inception_form_2.php index 365c1594..13c7b309 100644 --- a/app/Views/policy_transaction_inception_form_2.php +++ b/app/Views/policy_transaction_inception_form_2.php @@ -1702,7 +1702,7 @@ $('#follower_policy_no_' + uniqueid).prop('readonly', false); $('#calc_policy_issue_date_1').val(policy_issue_date).addClass('readonly-select'); } - + }); $(document).on('change', 'select[name="relationship[]"]', function() { @@ -2612,141 +2612,203 @@ console.log('variance', variance); } - function co_share_percentage_calculation(input, extra = null){ + // function co_share_percentage_calculation(input, extra = null){ - console.log('input', input) - var inputs = $('input[name="co_share_per[]"]'); // Specifically select input elements - console.log('Number of inputs:', inputs.length); + // console.log('input', input) + // var inputs = $('input[name="co_share_per[]"]'); // Specifically select input elements + // console.log('Number of inputs:', inputs.length); - let insurer_count = insurer_count_array.length; - console.log('insurer_count', insurer_count); - console.log('insurer_count_array', insurer_count_array); + // let insurer_count = insurer_count_array.length; + // console.log('insurer_count', insurer_count); + // console.log('insurer_count_array', insurer_count_array); - if(input){ - if(insurer_count == 2){ + // if ($('#cop_yes').is(':checked')) { + // console.log('cop_yes checked', $('#cop_yes').is(':checked')); + // if(input){ + // if(insurer_count == 2){ - // Find the index of the value - let index = insurer_count_array.indexOf(Number(input)); - let second_value_index = ""; + // // Find the index of the value + // let index = insurer_count_array.indexOf(Number(input)); + // let second_value_index = ""; - if (index !== -1) { + // if (index !== -1) { - console.log(`Value ${input} exists at index ${index}.`); + // console.log(`Value ${input} exists at index ${index}.`); - let beforeValue = index > 0 ? insurer_count_array[index - 1] : null; - let afterValue = index < insurer_count_array.length - 1 ? insurer_count_array[index + 1] : null; + // let beforeValue = index > 0 ? insurer_count_array[index - 1] : null; + // let afterValue = index < insurer_count_array.length - 1 ? insurer_count_array[index + 1] : null; - if (beforeValue != null) { - second_value_index = beforeValue; - } else if (afterValue != null) { - second_value_index = afterValue; - } + // if (beforeValue != null) { + // second_value_index = beforeValue; + // } else if (afterValue != null) { + // second_value_index = afterValue; + // } - } + // } - let value1 = $('#co_share_per_' + input).val(); - let value2 = $('#co_share_per_' + second_value_index).val(); + // let value1 = $('#co_share_per_' + input).val(); + // let value2 = $('#co_share_per_' + second_value_index).val(); - value1 = Number(value1); - value2 = Number(value2); + // value1 = Number(value1); + // value2 = Number(value2); - console.log('value1', value1); - console.log('value2', value2); + // console.log('value1', value1); + // console.log('value2', value2); - if(extra == "add"){ + // if(extra == "add"){ - if(value2 == 0){ - value1 = 50; - value2 = 50; - }else{ - if(value2 == 100){ - value1 = 50; - value2 = 50; - }else{ - value1 = 100 - value2; - } - } + // if(value2 == 0){ + // value1 = 50; + // value2 = 50; + // }else{ + // if(value2 == 100){ + // value1 = 50; + // value2 = 50; + // }else{ + // value1 = 100 - value2; + // } + // } - }else{ + // }else{ - if(value1 == 100){ - value2 = 0; - }else{ - value2 = 100 - value1; - } - } + // if(value1 == 100){ + // value2 = 0; + // }else{ + // value2 = 100 - value1; + // } + // } - console.log('value1', value1); - console.log('value2', value2); + // console.log('value1', value1); + // console.log('value2', value2); - $('#co_share_per_' + input).val(value1); - $('#co_share_per_' + second_value_index).val(value2); + // $('#co_share_per_' + input).val(value1); + // $('#co_share_per_' + second_value_index).val(value2); - }else if(insurer_count > 2){ + // }else if(insurer_count > 2){ - let total_val = 0; + // let total_val = 0; - // Calculate the total sum of input values - inputs.each(function () { - let val = Number($(this).val()) || 0; - if(val == 0){ - $(this).val(0) - } - total_val += val; - }); + // // Calculate the total sum of input values + // inputs.each(function () { + // let val = Number($(this).val()) || 0; + // if(val == 0){ + // $(this).val(0) + // } + // total_val += val; + // }); - // if (total_val < 100) { - // let remaining_val = 100 - total_val; // Calculate the remaining value + // // if (total_val < 100) { + // // let remaining_val = 100 - total_val; // Calculate the remaining value - // // Assign the remaining value to the first empty input - // let assigned = false; - // inputs.each(function () { - // let current_val = Number($(this).val()) || 0; - // if (current_val === 0 && !assigned) { // Assign only once - // $(this).val(remaining_val); - // assigned = true; - // } else if (current_val === 0) { - // $(this).val(0); // Set other empty inputs to 0 - // } - // }); - // } else if (total_val > 100) { - // toastr.warning('Sum of the co-share is greater than 100'); - // } + // // // Assign the remaining value to the first empty input + // // let assigned = false; + // // inputs.each(function () { + // // let current_val = Number($(this).val()) || 0; + // // if (current_val === 0 && !assigned) { // Assign only once + // // $(this).val(remaining_val); + // // assigned = true; + // // } else if (current_val === 0) { + // // $(this).val(0); // Set other empty inputs to 0 + // // } + // // }); + // // } else if (total_val > 100) { + // // toastr.warning('Sum of the co-share is greater than 100'); + // // } - } - }else{ - inputs.each(function (index) { - if (inputs.length === 1) { - $(this).val(100); - } else if(inputs.length === 2) { - let first = $('#co_share_per_1').val(); - first = Number(first) - let second_val = 100 - first; + // } + // }else{ + // inputs.each(function (index) { + // if (inputs.length === 1) { + // $(this).val(100); + // } else if(inputs.length === 2) { + // let first = $('#co_share_per_1').val(); + // first = Number(first) + // let second_val = 100 - first; - if (index === 1) { - $(this).val(second_val); - } - } - }); + // if (index === 1) { + // $(this).val(second_val); + // } + // } + // }); - } + // } + // } - let val_sum = 0; + // let val_sum = 0; - inputs.each(function () { - let val = Number($(this).val()) || 0; - val_sum += val; - }); + // inputs.each(function () { + // let val = Number($(this).val()) || 0; + // val_sum += val; + // }); - if (val_sum > 100) { - toastr.warning('Sum of the co-share is greater than 100', 'WARNING'); - } + // if ($('#cop_yes').is(':checked')) { + // if (val_sum > 100) { + // toastr.warning('Sum of the co-share is greater than 100', 'WARNING'); + // } + // } + // } + + function co_share_percentage_calculation(changedEl = null) { + + let inputs = $('input[name="co_share_per[]"]'); + let count = inputs.length; + let copChecked = $('#cop_yes').is(':checked'); + + /* ========================= + COP UNCHECKED + ========================= */ + if (!copChecked) { + inputs.val(''); + return; } + /* ========================= + AUTO MODE (default / fetch / add / remove) + ========================= */ + if (changedEl === null) { + + // Single card → empty (means 100) + if (count === 1) { + inputs.val(''); + return; + } + + // Multiple cards → auto split + let split = (100 / count).toFixed(2); + inputs.val(split); + return; + } + + /* ========================= + USER MODE (manual edit) + ========================= */ + let sum = 0; + let userTouched = false; + + inputs.each(function () { + let v = $(this).val(); + + if (v !== '') { + userTouched = true; + sum += Number(v) || 0; + } + }); + + // Show warning ONLY if user changed something + if (userTouched && sum > 100) { + toastr.warning( + 'Sum of the co-share is greater than 100', + 'WARNING' + ); + } +} + + + $(document).on('change', '[name="base_premium"], [name="co_share_per[]"]', function() { - console.log('Triggered change event.'); + console.log('Triggered change event. base_premium'); // Get the first non-empty base premium value // let basePremium = $('input[name="base_premium[]"]').toArray() @@ -3276,7 +3338,7 @@ }); } - function addCDAccountNumber(input) + function addCDAccountNumber_old(input) { var val = $(input).val(); var uniqueid = $(input).data('count'); @@ -3328,6 +3390,93 @@ } } + function addCDAccountNumber(input) + { + + var $input = $(input); + var val = $input.val(); + var uniqueid = $input.data('count'); + + var client_id = $('#client_id').val(); + var insurer_id = $('#follow_insurer_id_' + uniqueid).val(); + + var isCurrentLeader = $('#co_share_type_' + uniqueid).is(':checked'); + var isAnyLeaderSelected = $('input[name="co_share_type[]"]:checked').length > 0; + var cop_yes = $('#cop_yes').is(':checked'); + + + + // Missing base data + if (!client_id || !insurer_id) { + toastr.warning('Client or Insurer does not exist.', 'WARNING!'); + return; + } + + // COP enabled but no leader selected + if (cop_yes && !isAnyLeaderSelected) { + toastr.warning('Please select a Leader.', 'WARNING!'); + $input.val(''); + return; + } + + // CD allowed only for leader + if (cop_yes && !isCurrentLeader) { + + toastr.warning( + 'CD account number allowed only for Leader.', + 'WARNING!' + ); + + // Clear current select + $input.val(''); + + // Disable CD for NON-leaders, enable only leader, clear balance div + $('select.follow_insurer_cd').each(function () { + + var count = $(this).data('count'); + var isLeaderRow = $('#co_share_type_' + count).is(':checked'); + + // Get the corresponding balance div + var balanceDiv = document.getElementById('cd_current_balance_info_' + count); + + if (!isLeaderRow) { + $(this) + .prop('disabled', true) + .removeAttr('required') + .val(''); + + // Clear balance div if it exists + if (balanceDiv) { + balanceDiv.innerHTML = ""; + } + + } else { + $(this) + .prop('disabled', false) + .attr('required', true); + } + }); + + return; + } + + + // ➕ Add CD + if (val === 'add_cd') { + $('#premium_details_unique_id').val(uniqueid); + new bootstrap.Modal( + document.getElementById('cd_form_modal') + ).show(); + $input.val(''); + return; + } + + // ✅ Valid selection (leader only) + $('#cd_ac_pk_for_leader').val(val); + getCdAmount(val, uniqueid); + } + + function restrictCDACNO(currentSelect){ const selectedValue = $(currentSelect).val(); @@ -3780,85 +3929,160 @@ //----------------------------------------------------------------------------------------------------------- - $('#cop_yes').change(function() { + // $('#cop_yes').change(function() { - if ($(this).is(':checked')) { - $('.add-insurer-button').removeClass('d-none'); - $('.payby').removeClass('d-none'); - $('.card_group_2').show() - $('.card_group_3').show() - $('.card_group_7').show() - $('.card_group_35').removeClass('d-none'); + // if ($(this).is(':checked')) { + // $('.add-insurer-button').removeClass('d-none'); + // $('.payby').removeClass('d-none'); + // $('.card_group_2').show() + // $('.card_group_3').show() + // $('.card_group_7').show() + // $('.card_group_35').removeClass('d-none'); - var selectedOption = $('#policy_type_id').find('option:selected'); - var bap = selectedOption.data('bap'); - var allocg = selectedOption.data('allocg'); - // console.log('allocg:', allocg); + // var selectedOption = $('#policy_type_id').find('option:selected'); + // var bap = selectedOption.data('bap'); + // var allocg = selectedOption.data('allocg'); + // // console.log('allocg:', allocg); - // do not remove this commented items - // if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ - // $('.hidecoter').show() - // $('.hidecotp').hide() - // }else{ + // // do not remove this commented items + // // if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ + // // $('.hidecoter').show() + // // $('.hidecotp').hide() + // // }else{ - // if(bap == 'Motor'){ - // $('.hidecotp').show() - // $('.hidecoter').hide() - // }else{ - // $('.hidecoter').hide() - // $('.hidecotp').hide() - // } - // } + // // if(bap == 'Motor'){ + // // $('.hidecotp').show() + // // $('.hidecoter').hide() + // // }else{ + // // $('.hidecoter').hide() + // // $('.hidecotp').hide() + // // } + // // } - if(allocg == "EB"){ - $('.hideter').hide(); - $('.hidetp').hide(); - $('.hidecoter').hide() - $('.hidecotp').hide() - }else{ + // if(allocg == "EB"){ + // $('.hideter').hide(); + // $('.hidetp').hide(); + // $('.hidecoter').hide() + // $('.hidecotp').hide() + // }else{ - $('.hidetp').show(); - if($(this).is(':checked')){ - $('.hidecotp').show(); - }else{ - $('.hidecotp').hide(); - } + // $('.hidetp').show(); + // if($(this).is(':checked')){ + // $('.hidecotp').show(); + // }else{ + // $('.hidecotp').hide(); + // } - if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ - $('.hideter').show(); - if($(this).is(':checked')){ - $('.hidecoter').show(); - }else{ - $('.hidecoter').hide(); - } - }else{ - $('.hideter').hide(); - } - } + // if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ + // $('.hideter').show(); + // if($(this).is(':checked')){ + // $('.hidecoter').show(); + // }else{ + // $('.hidecoter').hide(); + // } + // }else{ + // $('.hideter').hide(); + // } + // } - // $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () { - // $(this).val(''); // Clear value - // console.log('Input cleared:', $(this).attr('name')); // Log cleared input - // }); + // // $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () { + // // $(this).val(''); // Clear value + // // console.log('Input cleared:', $(this).attr('name')); // Log cleared input + // // }); - } else { - $('.add-insurer-button').addClass('d-none'); - $('.payby').addClass('d-none'); - // $('#bro_payable_by').prop('checked', false); - $('.card_group_2').hide() - $('.card_group_3').hide() - $('.card_group_7').hide() - $('.card_group_35').addClass('d-none'); - $('.hidecoter').hide() - $('.hidecotp').hide() + // } else { + // $('.add-insurer-button').addClass('d-none'); + // $('.payby').addClass('d-none'); + // // $('#bro_payable_by').prop('checked', false); + // $('.card_group_2').hide() + // $('.card_group_3').hide() + // $('.card_group_7').hide() + // $('.card_group_35').addClass('d-none'); + // $('.hidecoter').hide() + // $('.hidecotp').hide() - // $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () { - // $(this).val(''); // Clear value - // console.log('Input cleared:', $(this).attr('name')); // Log cleared input - // }); + // // $('input[name="co_share_per[]"], input[name="co_premium[]"]').each(function () { + // // $(this).val(''); // Clear value + // // console.log('Input cleared:', $(this).attr('name')); // Log cleared input + // // }); + // } + // }); + + $('#cop_yes').change(function () { + + const isCoPayYes = $(this).is(':checked'); + + const selectedOption = $('#policy_type_id option:selected'); + const bap = selectedOption.data('bap'); + const allocg = selectedOption.data('allocg'); + + const $allPremiumCols = $('.csslabel, .cssbp, .csstp, .csstep'); + + /* ========================= + VISIBILITY LOGIC + ========================= */ + if (isCoPayYes) { + + $('.add-insurer-button, .payby').removeClass('d-none'); + $('.card_group_2, .card_group_3, .card_group_7').show(); + $('.card_group_35').removeClass('d-none'); + + if (allocg === "EB") { + $('.hideter, .hidetp, .hidecoter, .hidecotp').hide(); + } else { + + $('.hidetp').show(); + $('.hidecotp').show(); + + if (['Fire','Marine Cargo','Marine Hull'].includes(bap)) { + $('.hideter, .hidecoter').show(); + } else { + $('.hideter, .hidecoter').hide(); + } } - }); + + } else { + + $('.add-insurer-button, .payby').addClass('d-none'); + $('.card_group_2, .card_group_3, .card_group_7').hide(); + $('.card_group_35').addClass('d-none'); + + $('.hideter, .hidetp, .hidecoter, .hidecotp').hide(); + } + + /* ========================= + COLUMN LAYOUT LOGIC + ========================= */ + $allPremiumCols + .filter(':visible') + .removeClass('col-3 col-4 col-6'); + + if (allocg === "EB") { + + $allPremiumCols + .filter(':visible') + .addClass('col-6'); + + } else if (['Fire','Marine Cargo','Marine Hull'].includes(bap)) { + + $allPremiumCols + .filter(':visible') + .addClass('col-3'); + + } else { + + $allPremiumCols + .filter(':visible') + .addClass('col-4'); + } + + /* ========================= + CO-SHARE RECALC + ========================= */ + co_share_percentage_calculation(); +}); + $('#client_type').change(function() { @@ -4348,7 +4572,7 @@ style="font-size: x-small;"> - From 8b418099232a35923913385b06f6287e2dc0143a Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Mon, 15 Dec 2025 18:47:55 +0530 Subject: [PATCH 03/27] FIX_KYC Deleted Issues Fixed --- app/Controllers/ClientController.php | 4 +++- app/Views/client_kyc_2.php | 26 +++++++++++++++++++++++++- app/Views/client_kyc_single_table.php | 3 ++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d5370b02..9a29156a 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1099,6 +1099,8 @@ class ClientController extends AdminController $kyc_id = $this->request->getPost('id'); $client_id = $this->request->getPost('client_id'); + // echo "KID".$kyc_id; + // echo "CID".$client_id; if (empty($kyc_id)) { return $this->respond(['status' => false, 'code' => 400, 'message' => 'Missing document ID.'], 200); @@ -1107,7 +1109,7 @@ class ClientController extends AdminController $updateData['is_active'] = $this->request->getPost('is_active'); $delete = $this->clientKYCDocsModel->update($kyc_id, $updateData); - + // $delete = 1; if ($delete) { $html = $this->generateKycSingleTable($client_id); $dropdown = $this->fetch_dropdown($client_id); diff --git a/app/Views/client_kyc_2.php b/app/Views/client_kyc_2.php index 8a2ce5ed..b0240572 100755 --- a/app/Views/client_kyc_2.php +++ b/app/Views/client_kyc_2.php @@ -35,7 +35,7 @@
-
@@ -318,5 +318,29 @@ }); } + // Centralized Validation Function + function validateFile(fileInput) { + var file = fileInput.files[0]; + if (!file) { + return true; // No file selected, considered valid or neutral + } + + var type = file.type; + + // Check if the type is PDF or starts with 'image/' + if (type === 'application/pdf' || type.startsWith('image/')) { + return true; // Valid + } + + // Invalid format + toastr.warning('Invalid file format. Only PDF or Image files are allowed.', 'WARNING!'); + $(fileInput).val(''); // clear file + return false; // Invalid + } + + // Attach the centralized handler to BOTH classes + $(document).on('change', '.file-input, .edit_file-input', function () { + validateFile(this); + }); \ No newline at end of file diff --git a/app/Views/client_kyc_single_table.php b/app/Views/client_kyc_single_table.php index 4982bcdf..cae36927 100644 --- a/app/Views/client_kyc_single_table.php +++ b/app/Views/client_kyc_single_table.php @@ -24,6 +24,7 @@ @@ -45,7 +46,7 @@ From 65a8039f6b6b8e06b9aa3a2ae26c322229956f53 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 16 Dec 2025 12:00:25 +0530 Subject: [PATCH 04/27] FIX_CD_TRANSACTION_ISSUE_TICKET_549 --- app/Controllers/ClientController.php | 18 ++++++++++-------- app/Views/view_deposit.php | 11 +++++++++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d5370b02..90647414 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -726,7 +726,7 @@ class ClientController extends AdminController if ($requestFrom == 'rest') { return $data; } - + // print_rr($data);die(); // Load the view for the new list page; echo view('layout/header', $headerData); echo view('view_deposit', $data); @@ -741,12 +741,14 @@ class ClientController extends AdminController $client_id = $this->request->getPost('client_id'); $insurer_id = $this->request->getPost('insurer_id'); $record_date = $this->request->getPost('record_date'); + $cd_ac_pk = $this->request->getPost('cd_ac_pk'); + $cd_ac_no = $this->request->getPost('cd_ac_no'); - $CD_Account_Number = $this->CDMasterModel - ->where('client_id', $client_id) - ->where('insurer_id', $insurer_id) - ->where('is_active', 1) - ->first(); + // $CD_Account_Number = $this->CDMasterModel + // ->where('client_id', $client_id) + // ->where('insurer_id', $insurer_id) + // ->where('is_active', 1) + // ->first(); if (!empty($record_date)) { @@ -762,8 +764,8 @@ class ClientController extends AdminController 'sub_type_id' => $this->request->getPost('sub_type_id'), 'client_id' => $this->request->getPost('client_id'), 'client_policy_id' => null, - 'cd_ac_no' => $CD_Account_Number['cd_ac_no'] ?? null, - 'cd_ac_pk' => $CD_Account_Number['id'] ?? null, + 'cd_ac_no' => $cd_ac_no ?? null, + 'cd_ac_pk' => $cd_ac_pk ?? null, 'endorsement_no' => null, 'insurer_id' => $this->request->getPost('insurer_id'), 'description' => $this->request->getPost('description'), diff --git a/app/Views/view_deposit.php b/app/Views/view_deposit.php index 6e52aa53..c0b9272e 100755 --- a/app/Views/view_deposit.php +++ b/app/Views/view_deposit.php @@ -212,6 +212,8 @@ + + @@ -392,6 +394,8 @@ var transactionTypeValue = $('input[name="transactionMode"]:checked').val(); var subType = ""; var record_date = $('#record_date').val(); + var cd_ac_no = $('#cd_ac_no').val(); + var cd_ac_pk = $('#cd_ac_pk').val(); if (amount == "") { toastr.warning('Amount field is required') @@ -432,7 +436,8 @@ console.log('clientId ', clientId) console.log('insurerId ', insurerId) console.log('subType ', subType) - + console.log('cd_ac_pk ', cd_ac_pk) + console.log('cd_ac_no ', cd_ac_no) // Send data to the server using Ajax $.ajax({ @@ -445,7 +450,9 @@ sub_type_id: subType, // Include sub_type_id client_id: clientId, insurer_id: insurerId, - record_date: record_date + record_date: record_date, + cd_ac_pk: cd_ac_pk, + cd_ac_no: cd_ac_no }, success: function(response) { // Handle success response From 0eea675a9f4807114cac116d159ac008dd650b9f Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 16 Dec 2025 15:23:06 +0530 Subject: [PATCH 05/27] FIX_PAYOUT_ISSUES_STATUS&BROKER_ID --- app/Controllers/PayoutController.php | 4 ++-- app/Models/InvoiceModel.php | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index 01cd7251..29e8b555 100644 --- a/app/Controllers/PayoutController.php +++ b/app/Controllers/PayoutController.php @@ -439,7 +439,7 @@ class PayoutController extends BaseController $agentCode = $agent["agent_code"]; $today = date("Ymd"); - $likePattern = "INV/$agentCode/$today/%"; + $likePattern = "NIIB/$agentCode/$today/%"; $count = $this->invoiceModel ->like("invoice_no", $likePattern) @@ -447,7 +447,7 @@ class PayoutController extends BaseController $nextNumber = $count + 1; - return "INV/$agentCode/$today/$nextNumber"; + return "NIIB/$agentCode/$today/$nextNumber"; } // private function generateInvoiceNumber() diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index ba3388bd..bebd0022 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -23,6 +23,7 @@ class InvoiceModel extends Model 'created_by', 'updated_at', 'payout_status', + 'broker_id' ]; // Timestamps @@ -219,7 +220,8 @@ class InvoiceModel extends Model if ($flag == 1) { // Add mode // EXCLUDE all policies that exist in partner_invoice_items - $builder->where("pt.id NOT IN (SELECT policy_id FROM partner_invoice_items)", null, false); + $builder->where("pp.id NOT IN (SELECT policy_id FROM partner_invoice_items)", null, false); + $builder->where("pt.policy_no NOT IN (SELECT policy_no FROM partner_invoice_items)", null, false); } if ($flag == 2) { // Edit mode From 794a63bd6cdb90f25b7ba6367ee34856834052ac Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Tue, 16 Dec 2025 17:38:24 +0530 Subject: [PATCH 06/27] Sales tracker Database and basic files created : GWM --- app/Config/Routes.php | 88 +++- app/Controllers/SalesController.php | 695 +++++++++++++++++++++++++ app/Models/SalesActivityModel.php | 166 ++++++ app/Models/SalesActualLeadModel.php | 145 ++++++ app/Models/SalesContactPersonModel.php | 95 ++++ app/Models/SalesLeadNoteModel.php | 75 +++ 6 files changed, 1263 insertions(+), 1 deletion(-) create mode 100644 app/Controllers/SalesController.php create mode 100644 app/Models/SalesActivityModel.php create mode 100644 app/Models/SalesActualLeadModel.php create mode 100644 app/Models/SalesContactPersonModel.php create mode 100644 app/Models/SalesLeadNoteModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b0aded13..c3800032 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -776,7 +776,7 @@ $routes->get('testTracelog','TestBusinessController::a'); $routes->get("claimView", "EmployeeRestController::claimView"); // General Tickets -$routes->post("ticketSave", "ThzController::ticketSave"); +$routes->post("ticketSave", "ThzController::ticketSave"); // $routes->get("ticketList", "ThzController::ticketList"); $routes->post("ticketConversationSave", "ThzController::ticketConversationSave"); $routes->get("ticketConversationList", "ThzController::ticketConversationList"); @@ -852,3 +852,89 @@ $routes->group('logs', function($routes) { $routes->get('delete/(:segment)', 'LogController::delete/$1'); $routes->get('clearAll', 'LogController::clearAll'); }); + +// ----------------------------------------------------------------------------------------------------------------- +$routes->group('sales', function($routes) { + + // ==================== LEAD ROUTES ==================== + + // Get all leads with filters + $routes->get('leads', 'SalesController::getLeads'); + + // Get lead statistics + $routes->get('leads/stats', 'SalesController::getLeadStats'); + + // Get single lead with complete details + $routes->get('leads/(:num)', 'SalesController::getLead/$1'); + + // Create new lead + $routes->post('leads', 'SalesController::createLead'); + + // Update lead + $routes->put('leads/(:num)', 'SalesController::updateLead/$1'); + + // Delete lead + $routes->delete('leads/(:num)', 'SalesController::deleteLead/$1'); + + // Get contacts for a lead + $routes->get('leads/(:num)/contacts', 'SalesController::getContacts/$1'); + + // Get activities for a lead + $routes->get('leads/(:num)/activities', 'SalesController::getLeadActivities/$1'); + + // Get activity timeline for a lead + $routes->get('leads/(:num)/timeline', 'SalesController::getActivityTimeline/$1'); + + // Get notes for a lead + $routes->get('leads/(:num)/notes', 'SalesController::getLeadNotes/$1'); + + // ==================== CONTACT PERSON ROUTES ==================== + + // Create contact person + $routes->post('contacts', 'SalesController::createContact'); + + // Update contact person + $routes->put('contacts/(:num)', 'SalesController::updateContact/$1'); + + // Delete contact person + $routes->delete('contacts/(:num)', 'SalesController::deleteContact/$1'); + + // Set primary contact + $routes->put('contacts/(:num)/set-primary', 'SalesController::setPrimaryContact/$1'); + + // ==================== ACTIVITY ROUTES ==================== + + // Get all activities with filters + $routes->get('activities', 'SalesController::getActivities'); + + // Get upcoming activities + $routes->get('activities/upcoming', 'SalesController::getUpcomingActivities'); + + // Get pending activities count + $routes->get('activities/pending-count', 'SalesController::getPendingCount'); + + // Create activity + $routes->post('activities', 'SalesController::createActivity'); + + // Update activity + $routes->put('activities/(:num)', 'SalesController::updateActivity/$1'); + + // Complete activity + $routes->post('activities/(:num)/complete', 'SalesController::completeActivity/$1'); + + // Delete activity + $routes->delete('activities/(:num)', 'SalesController::deleteActivity/$1'); + + // ==================== NOTE ROUTES ==================== + + // Create note + $routes->post('notes', 'SalesController::createNote'); + + // Update note + $routes->put('notes/(:num)', 'SalesController::updateNote/$1'); + + // Delete note + $routes->delete('notes/(:num)', 'SalesController::deleteNote/$1'); +}); + + diff --git a/app/Controllers/SalesController.php b/app/Controllers/SalesController.php new file mode 100644 index 00000000..17a60b0e --- /dev/null +++ b/app/Controllers/SalesController.php @@ -0,0 +1,695 @@ +leadModel = new SalesActualLeadModel(); + $this->contactModel = new SalesContactPersonModel(); + $this->activityModel = new SalesActivityModel(); + $this->noteModel = new SalesLeadNoteModel(); + } + + // ==================== LEAD APIs ==================== + + /** + * Get all leads with pagination and filters + * GET /api/sales/leads + */ + public function getLeads() + { + try { + $limit = $this->request->getGet('limit') ?? 10; + $offset = $this->request->getGet('offset') ?? 0; + + $filters = [ + 'status' => $this->request->getGet('status'), + 'assigned_to' => $this->request->getGet('assigned_to'), + 'search' => $this->request->getGet('search'), + ]; + + $result = $this->leadModel->getLeadsWithFilters($filters, $limit, $offset); + + return $this->respond([ + 'status' => 'success', + 'data' => $result['data'], + 'total' => $result['total'], + 'limit' => $limit, + 'offset' => $offset + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Get single lead with complete details + * GET /api/sales/leads/{id} + */ + public function getLead($id) + { + try { + $lead = $this->leadModel->getLeadComplete($id); + + if (!$lead) { + return $this->failNotFound('Lead not found'); + } + + return $this->respond([ + 'status' => 'success', + 'data' => $lead + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Create new lead + * POST /api/sales/leads + */ + public function createLead() + { + try { + $data = $this->request->getJSON(true); + + // Set created_by and updated_by from authenticated user + $data['created_by'] = $this->getUserId(); + $data['updated_by'] = $this->getUserId(); + + if (!$this->leadModel->insert($data)) { + return $this->fail($this->leadModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $leadId = $this->leadModel->getInsertID(); + + // Insert contact persons if provided + if (!empty($data['contact_persons'])) { + foreach ($data['contact_persons'] as $contact) { + $contact['lead_id'] = $leadId; + $contact['created_by'] = $this->getUserId(); + $this->contactModel->insert($contact); + } + } + + $lead = $this->leadModel->getLeadComplete($leadId); + + return $this->respondCreated([ + 'status' => 'success', + 'message' => 'Lead created successfully', + 'data' => $lead + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Update lead + * PUT /api/sales/leads/{id} + */ + public function updateLead($id) + { + try { + if (!$this->leadModel->find($id)) { + return $this->failNotFound('Lead not found'); + } + + $data = $this->request->getJSON(true); + $data['updated_by'] = $this->getUserId(); + + if (!$this->leadModel->update($id, $data)) { + return $this->fail($this->leadModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $lead = $this->leadModel->getLeadComplete($id); + + return $this->respond([ + 'status' => 'success', + 'message' => 'Lead updated successfully', + 'data' => $lead + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Delete lead + * DELETE /api/sales/leads/{id} + */ + public function deleteLead($id) + { + try { + if (!$this->leadModel->find($id)) { + return $this->failNotFound('Lead not found'); + } + + $this->leadModel->delete($id); + + return $this->respondDeleted([ + 'status' => 'success', + 'message' => 'Lead deleted successfully' + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Get lead statistics + * GET /api/sales/leads/stats + */ + public function getLeadStats() + { + try { + $userId = $this->request->getGet('user_id'); + $stats = $this->leadModel->getLeadStats($userId); + + return $this->respond([ + 'status' => 'success', + 'data' => $stats + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + // ==================== CONTACT PERSON APIs ==================== + + /** + * Get contacts for a lead + * GET /api/sales/leads/{leadId}/contacts + */ + public function getContacts($leadId) + { + try { + $contacts = $this->contactModel->getContactsByLead($leadId); + + return $this->respond([ + 'status' => 'success', + 'data' => $contacts + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Create contact person + * POST /api/sales/contacts + */ + public function createContact() + { + try { + $data = $this->request->getJSON(true); + $data['created_by'] = $this->getUserId(); + $data['updated_by'] = $this->getUserId(); + + if (!$this->contactModel->insert($data)) { + return $this->fail($this->contactModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $contactId = $this->contactModel->getInsertID(); + $contact = $this->contactModel->find($contactId); + + return $this->respondCreated([ + 'status' => 'success', + 'message' => 'Contact created successfully', + 'data' => $contact + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Update contact person + * PUT /api/sales/contacts/{id} + */ + public function updateContact($id) + { + try { + if (!$this->contactModel->find($id)) { + return $this->failNotFound('Contact not found'); + } + + $data = $this->request->getJSON(true); + $data['updated_by'] = $this->getUserId(); + + if (!$this->contactModel->update($id, $data)) { + return $this->fail($this->contactModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $contact = $this->contactModel->find($id); + + return $this->respond([ + 'status' => 'success', + 'message' => 'Contact updated successfully', + 'data' => $contact + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Delete contact person + * DELETE /api/sales/contacts/{id} + */ + public function deleteContact($id) + { + try { + if (!$this->contactModel->find($id)) { + return $this->failNotFound('Contact not found'); + } + + $this->contactModel->delete($id); + + return $this->respondDeleted([ + 'status' => 'success', + 'message' => 'Contact deleted successfully' + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Set primary contact + * PUT /api/sales/contacts/{id}/set-primary + */ + public function setPrimaryContact($id) + { + try { + $contact = $this->contactModel->find($id); + + if (!$contact) { + return $this->failNotFound('Contact not found'); + } + + $this->contactModel->setPrimaryContact($id, $contact['lead_id']); + + return $this->respond([ + 'status' => 'success', + 'message' => 'Primary contact updated successfully' + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + // ==================== ACTIVITY APIs ==================== + + /** + * Get all activities with filters + * GET /api/sales/activities + */ + public function getActivities() + { + try { + $limit = $this->request->getGet('limit') ?? 10; + $offset = $this->request->getGet('offset') ?? 0; + + $filters = [ + 'status' => $this->request->getGet('status'), + 'activity_type' => $this->request->getGet('activity_type'), + 'assigned_to' => $this->request->getGet('assigned_to'), + 'date_from' => $this->request->getGet('date_from'), + 'date_to' => $this->request->getGet('date_to'), + ]; + + $result = $this->activityModel->getActivitiesWithFilters($filters, $limit, $offset); + + return $this->respond([ + 'status' => 'success', + 'data' => $result['data'], + 'total' => $result['total'], + 'limit' => $limit, + 'offset' => $offset + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Get activities for a specific lead + * GET /api/sales/leads/{leadId}/activities + */ + public function getLeadActivities($leadId) + { + try { + $status = $this->request->getGet('status'); + $activities = $this->activityModel->getActivitiesByLead($leadId, $status); + + return $this->respond([ + 'status' => 'success', + 'data' => $activities + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Get activity timeline for a lead + * GET /api/sales/leads/{leadId}/timeline + */ + public function getActivityTimeline($leadId) + { + try { + $timeline = $this->activityModel->getActivityTimeline($leadId); + + return $this->respond([ + 'status' => 'success', + 'data' => $timeline + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Get upcoming activities for user + * GET /api/sales/activities/upcoming + */ + public function getUpcomingActivities() + { + try { + $userId = $this->getUserId(); + $days = $this->request->getGet('days') ?? 7; + $limit = $this->request->getGet('limit') ?? 10; + + $activities = $this->activityModel->getUpcomingActivities($userId, $days, $limit); + + return $this->respond([ + 'status' => 'success', + 'data' => $activities + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Create activity + * POST /api/sales/activities + */ + public function createActivity() + { + try { + $data = $this->request->getJSON(true); + $data['created_by'] = $this->getUserId(); + $data['updated_by'] = $this->getUserId(); + + if (!$this->activityModel->insert($data)) { + return $this->fail($this->activityModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $activityId = $this->activityModel->getInsertID(); + $activity = $this->activityModel->find($activityId); + + return $this->respondCreated([ + 'status' => 'success', + 'message' => 'Activity created successfully', + 'data' => $activity + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Update activity + * PUT /api/sales/activities/{id} + */ + public function updateActivity($id) + { + try { + if (!$this->activityModel->find($id)) { + return $this->failNotFound('Activity not found'); + } + + $data = $this->request->getJSON(true); + $data['updated_by'] = $this->getUserId(); + + if (!$this->activityModel->update($id, $data)) { + return $this->fail($this->activityModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $activity = $this->activityModel->find($id); + + return $this->respond([ + 'status' => 'success', + 'message' => 'Activity updated successfully', + 'data' => $activity + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Complete activity + * POST /api/sales/activities/{id}/complete + */ + public function completeActivity($id) + { + try { + $activity = $this->activityModel->find($id); + + if (!$activity) { + return $this->failNotFound('Activity not found'); + } + + if ($activity['status'] === 'completed') { + return $this->fail('Activity is already completed', ResponseInterface::HTTP_BAD_REQUEST); + } + + $data = $this->request->getJSON(true); + $data['updated_by'] = $this->getUserId(); + + $this->activityModel->completeActivity($id, $data); + + // Create follow-up activity if requested + if (!empty($data['create_followup']) && $data['create_followup'] === true) { + $followupData = [ + 'lead_id' => $activity['lead_id'], + 'activity_type' => $data['followup_type'] ?? 'Call', + 'notes' => $data['followup_notes'] ?? '', + 'scheduled_date' => $data['followup_date'] ?? null, + 'assigned_to' => $activity['assigned_to'], + 'parent_activity_id' => $id, + 'created_by' => $this->getUserId(), + 'updated_by' => $this->getUserId(), + ]; + + $this->activityModel->insert($followupData); + } + + $updatedActivity = $this->activityModel->find($id); + + return $this->respond([ + 'status' => 'success', + 'message' => 'Activity completed successfully', + 'data' => $updatedActivity + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Delete activity + * DELETE /api/sales/activities/{id} + */ + public function deleteActivity($id) + { + try { + if (!$this->activityModel->find($id)) { + return $this->failNotFound('Activity not found'); + } + + $this->activityModel->delete($id); + + return $this->respondDeleted([ + 'status' => 'success', + 'message' => 'Activity deleted successfully' + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Get pending activities count + * GET /api/sales/activities/pending-count + */ + public function getPendingCount() + { + try { + $userId = $this->getUserId(); + $count = $this->activityModel->getPendingActivitiesCount($userId); + + return $this->respond([ + 'status' => 'success', + 'data' => ['count' => $count] + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + // ==================== LEAD NOTES APIs ==================== + + /** + * Get notes for a lead + * GET /api/sales/leads/{leadId}/notes + */ + public function getLeadNotes($leadId) + { + try { + $notes = $this->noteModel->getNotesByLead($leadId); + + return $this->respond([ + 'status' => 'success', + 'data' => $notes + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Create note + * POST /api/sales/notes + */ + public function createNote() + { + try { + $data = $this->request->getJSON(true); + $data['user_id'] = $this->getUserId(); + $data['created_by'] = $this->getUserId(); + $data['updated_by'] = $this->getUserId(); + + if (!$this->noteModel->insert($data)) { + return $this->fail($this->noteModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $noteId = $this->noteModel->getInsertID(); + $note = $this->noteModel->find($noteId); + + return $this->respondCreated([ + 'status' => 'success', + 'message' => 'Note created successfully', + 'data' => $note + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Update note + * PUT /api/sales/notes/{id} + */ + public function updateNote($id) + { + try { + $note = $this->noteModel->find($id); + + if (!$note) { + return $this->failNotFound('Note not found'); + } + + // Check if user owns the note + if ($note['user_id'] != $this->getUserId()) { + return $this->failUnauthorized('You are not authorized to update this note'); + } + + $data = $this->request->getJSON(true); + $data['updated_by'] = $this->getUserId(); + + if (!$this->noteModel->update($id, $data)) { + return $this->fail($this->noteModel->errors(), ResponseInterface::HTTP_BAD_REQUEST); + } + + $updatedNote = $this->noteModel->find($id); + + return $this->respond([ + 'status' => 'success', + 'message' => 'Note updated successfully', + 'data' => $updatedNote + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + /** + * Delete note + * DELETE /api/sales/notes/{id} + */ + public function deleteNote($id) + { + try { + $note = $this->noteModel->find($id); + + if (!$note) { + return $this->failNotFound('Note not found'); + } + + // Check if user owns the note + if ($note['user_id'] != $this->getUserId()) { + return $this->failUnauthorized('You are not authorized to delete this note'); + } + + $this->noteModel->delete($id); + + return $this->respondDeleted([ + 'status' => 'success', + 'message' => 'Note deleted successfully' + ]); + } catch (\Exception $e) { + return $this->fail($e->getMessage(), ResponseInterface::HTTP_INTERNAL_SERVER_ERROR); + } + } + + // ==================== HELPER METHODS ==================== + + /** + * Get current user ID from session or JWT token + * You'll need to implement this based on your authentication system + */ + private function getUserId() + { + // If using session + if (session()->has('user_id')) { + return session()->get('user_id'); + } + + // If using JWT, decode token and get user_id + // Example: return $this->decodeJWT()['user_id']; + + // For development/testing, you can return a default value + return 1; + } +} \ No newline at end of file diff --git a/app/Models/SalesActivityModel.php b/app/Models/SalesActivityModel.php new file mode 100644 index 00000000..dc70086c --- /dev/null +++ b/app/Models/SalesActivityModel.php @@ -0,0 +1,166 @@ + 'required|integer', + 'activity_type' => 'required|in_list[Call,Email,Meeting,Demo,Share,Todo]', + 'notes' => 'required', + 'scheduled_date' => 'required|valid_date', + 'assigned_to' => 'required|integer', + 'status' => 'in_list[pending,completed]', + ]; + + protected $validationMessages = [ + 'lead_id' => [ + 'required' => 'Lead ID is required', + ], + 'activity_type' => [ + 'required' => 'Activity type is required', + ], + 'notes' => [ + 'required' => 'Activity notes are required', + ], + ]; + + protected $skipValidation = false; + + /** + * Get activities by lead with user details + */ + public function getActivitiesByLead($leadId, $status = null) + { + $builder = $this->select('activities.*, user_profiles.username as assigned_to_name') + ->join('user_profiles', 'user_profiles.id = activities.assigned_to', 'left') + ->where('activities.lead_id', $leadId); + + if ($status) { + $builder->where('activities.status', $status); + } + + return $builder->orderBy('activities.scheduled_date', 'DESC')->findAll(); + } + + /** + * Get all activities with filters + */ + public function getActivitiesWithFilters($filters = [], $limit = 10, $offset = 0) + { + $builder = $this->select('activities.*, actual_leads.company_name, user_profiles.username as assigned_to_name') + ->join('actual_leads', 'actual_leads.lead_id = activities.lead_id', 'left') + ->join('user_profiles', 'user_profiles.id = activities.assigned_to', 'left'); + + if (!empty($filters['status'])) { + $builder->where('activities.status', $filters['status']); + } + + if (!empty($filters['activity_type'])) { + $builder->where('activities.activity_type', $filters['activity_type']); + } + + if (!empty($filters['assigned_to'])) { + $builder->where('activities.assigned_to', $filters['assigned_to']); + } + + if (!empty($filters['date_from'])) { + $builder->where('activities.scheduled_date >=', $filters['date_from']); + } + + if (!empty($filters['date_to'])) { + $builder->where('activities.scheduled_date <=', $filters['date_to']); + } + + return [ + 'data' => $builder->orderBy('activities.scheduled_date', 'DESC') + ->limit($limit, $offset)->findAll(), + 'total' => $builder->countAllResults(false) + ]; + } + + /** + * Complete an activity + */ + public function completeActivity($activityId, $completionData) + { + return $this->update($activityId, [ + 'status' => 'completed', + 'completion_notes' => $completionData['completion_notes'], + 'completed_date' => date('Y-m-d H:i:s'), + 'updated_by' => $completionData['updated_by'] ?? null + ]); + } + + /** + * Get pending activities count by user + */ + public function getPendingActivitiesCount($userId) + { + return $this->where('assigned_to', $userId) + ->where('status', 'pending') + ->where('scheduled_date <=', date('Y-m-d H:i:s')) + ->countAllResults(); + } + + /** + * Get upcoming activities for a user + */ + public function getUpcomingActivities($userId, $days = 7, $limit = 10) + { + $endDate = date('Y-m-d H:i:s', strtotime("+{$days} days")); + + return $this->select('activities.*, actual_leads.company_name') + ->join('actual_leads', 'actual_leads.lead_id = activities.lead_id', 'left') + ->where('activities.assigned_to', $userId) + ->where('activities.status', 'pending') + ->where('activities.scheduled_date <=', $endDate) + ->orderBy('activities.scheduled_date', 'ASC') + ->limit($limit) + ->findAll(); + } + + /** + * Get activity timeline for a lead + */ + public function getActivityTimeline($leadId) + { + return $this->select('activities.*, user_profiles.username as assigned_to_name') + ->join('user_profiles', 'user_profiles.id = activities.assigned_to', 'left') + ->where('activities.lead_id', $leadId) + ->orderBy('activities.scheduled_date', 'DESC') + ->findAll(); + } +} \ No newline at end of file diff --git a/app/Models/SalesActualLeadModel.php b/app/Models/SalesActualLeadModel.php new file mode 100644 index 00000000..6b8aee8f --- /dev/null +++ b/app/Models/SalesActualLeadModel.php @@ -0,0 +1,145 @@ + 'required|min_length[2]|max_length[255]', + 'email' => 'required|valid_email|max_length[255]', + 'phone' => 'required|min_length[10]|max_length[20]', + 'status' => 'in_list[New,Potential,Prospects,Non prospects]', + ]; + + protected $validationMessages = [ + 'company_name' => [ + 'required' => 'Company name is required', + ], + 'email' => [ + 'required' => 'Email is required', + 'valid_email' => 'Please provide a valid email address', + ], + 'phone' => [ + 'required' => 'Phone number is required', + ], + ]; + + protected $skipValidation = false; + + /** + * Get lead with assigned user details + */ + public function getLeadWithUser($leadId) + { + return $this->select('actual_leads.*, user_profiles.username as assigned_to_name, user_profiles.email as assigned_to_email') + ->join('user_profiles', 'user_profiles.id = actual_leads.assigned_to', 'left') + ->where('actual_leads.lead_id', $leadId) + ->first(); + } + + /** + * Get all leads with pagination and filters + */ + public function getLeadsWithFilters($filters = [], $limit = 10, $offset = 0) + { + $builder = $this->select('actual_leads.*, user_profiles.username as assigned_to_name') + ->join('user_profiles', 'user_profiles.id = actual_leads.assigned_to', 'left'); + + if (!empty($filters['status'])) { + $builder->where('actual_leads.status', $filters['status']); + } + + if (!empty($filters['assigned_to'])) { + $builder->where('actual_leads.assigned_to', $filters['assigned_to']); + } + + if (!empty($filters['search'])) { + $builder->groupStart() + ->like('actual_leads.company_name', $filters['search']) + ->orLike('actual_leads.email', $filters['search']) + ->orLike('actual_leads.phone', $filters['search']) + ->groupEnd(); + } + + return [ + 'data' => $builder->limit($limit, $offset)->findAll(), + 'total' => $builder->countAllResults(false) + ]; + } + + /** + * Get lead with all related data (contacts, activities, notes) + */ + public function getLeadComplete($leadId) + { + $lead = $this->getLeadWithUser($leadId); + + if (!$lead) { + return null; + } + + $contactModel = new SalesContactPersonModel(); + $activityModel = new SalesActivityModel(); + $noteModel = new SalesLeadNoteModel(); + + $lead['contact_persons'] = $contactModel->where('lead_id', $leadId)->findAll(); + $lead['activities'] = $activityModel->getActivitiesByLead($leadId); + $lead['notes'] = $noteModel->getNotesByLead($leadId); + + return $lead; + } + + /** + * Get leads statistics + */ + public function getLeadStats($userId = null) + { + $builder = $this->builder(); + + if ($userId) { + $builder->where('assigned_to', $userId); + } + + $stats = [ + 'total' => $builder->countAllResults(false), + 'new' => $builder->where('status', 'New')->countAllResults(false), + 'potential' => $builder->where('status', 'Potential')->countAllResults(false), + 'prospects' => $builder->where('status', 'Prospects')->countAllResults(false), + 'non_prospects' => $builder->where('status', 'Non prospects')->countAllResults(false), + ]; + + return $stats; + } +} \ No newline at end of file diff --git a/app/Models/SalesContactPersonModel.php b/app/Models/SalesContactPersonModel.php new file mode 100644 index 00000000..3a7073bb --- /dev/null +++ b/app/Models/SalesContactPersonModel.php @@ -0,0 +1,95 @@ + 'required|integer', + 'name' => 'required|min_length[2]|max_length[100]', + 'mobile' => 'required|min_length[10]|max_length[20]', + ]; + + protected $validationMessages = [ + 'lead_id' => [ + 'required' => 'Lead ID is required', + ], + 'name' => [ + 'required' => 'Contact person name is required', + ], + 'mobile' => [ + 'required' => 'Mobile number is required', + ], + ]; + + protected $skipValidation = false; + + /** + * Get all contacts for a lead + */ + public function getContactsByLead($leadId) + { + return $this->where('lead_id', $leadId) + ->orderBy('is_primary', 'DESC') + ->findAll(); + } + + /** + * Get primary contact for a lead + */ + public function getPrimaryContact($leadId) + { + return $this->where('lead_id', $leadId) + ->where('is_primary', 1) + ->first(); + } + + /** + * Set a contact as primary (unset others) + */ + public function setPrimaryContact($contactId, $leadId) + { + $this->db->transStart(); + + // Unset all primary contacts for this lead + $this->where('lead_id', $leadId) + ->set(['is_primary' => 0]) + ->update(); + + // Set the specified contact as primary + $this->update($contactId, ['is_primary' => 1]); + + $this->db->transComplete(); + + return $this->db->transStatus(); + } +} \ No newline at end of file diff --git a/app/Models/SalesLeadNoteModel.php b/app/Models/SalesLeadNoteModel.php new file mode 100644 index 00000000..c8d9654f --- /dev/null +++ b/app/Models/SalesLeadNoteModel.php @@ -0,0 +1,75 @@ + 'required|integer', + 'user_id' => 'required|integer', + 'note_text' => 'required|min_length[3]', + ]; + + protected $validationMessages = [ + 'lead_id' => [ + 'required' => 'Lead ID is required', + ], + 'note_text' => [ + 'required' => 'Note text is required', + ], + ]; + + protected $skipValidation = false; + + /** + * Get notes by lead with user details + */ + public function getNotesByLead($leadId) + { + return $this->select('lead_notes.*, user_profiles.username') + ->join('user_profiles', 'user_profiles.id = lead_notes.user_id', 'left') + ->where('lead_notes.lead_id', $leadId) + ->orderBy('lead_notes.created_at', 'DESC') + ->findAll(); + } + + /** + * Get notes by user + */ + public function getNotesByUser($userId, $limit = 20, $offset = 0) + { + return $this->select('lead_notes.*, actual_leads.company_name') + ->join('actual_leads', 'actual_leads.lead_id = lead_notes.lead_id', 'left') + ->where('lead_notes.user_id', $userId) + ->orderBy('lead_notes.created_at', 'DESC') + ->limit($limit, $offset) + ->findAll(); + } +} \ No newline at end of file From 529537734851cf9b005196037e6255f856d6a6ff Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 17 Dec 2025 11:28:16 +0530 Subject: [PATCH 07/27] GWM : nhance website contact api --- app/Config/Routes.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index c3800032..9dc08888 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -647,6 +647,11 @@ $routes->group("employeeRest", ["filter" => ['appSignature' , 'authJWT']], funct $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); $routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType'); + //this route for nhance website contact form (sales/service) + $routes->group("employeeRest", ["filter" => ['appSignature']], function ($routes) { + $routes->post("ticketSave", "ThzController::ticketSave"); + }); + //claims From 66ed0a898c545fa0733aef885ef45af2f026ddb0 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Wed, 17 Dec 2025 11:35:36 +0530 Subject: [PATCH 08/27] GWM : nhance website contact api --- app/Config/Routes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9dc08888..857f4c69 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -648,7 +648,7 @@ $routes->group("employeeRest", ["filter" => ['appSignature' , 'authJWT']], funct $routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType'); //this route for nhance website contact form (sales/service) - $routes->group("employeeRest", ["filter" => ['appSignature']], function ($routes) { + $routes->group("employeeRest", ['filter' => ['appSignature'] ], function ($routes) { $routes->post("ticketSave", "ThzController::ticketSave"); }); From e1aa1c9dc2c2b293e5aaa6f46873bc508deb7947 Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Wed, 17 Dec 2025 14:45:16 +0530 Subject: [PATCH 09/27] FIX_POS implementations --- app/Config/Routes.php | 1 + app/Controllers/MasterController.php | 140 ++++++++- app/Models/PartnerPosModel.php | 132 ++++++++ app/Views/layout/header.php | 3 + app/Views/nhance_branch_list.php | 2 +- app/Views/pos_list.php | 455 +++++++++++++++++++++++++++ 6 files changed, 731 insertions(+), 2 deletions(-) create mode 100644 app/Models/PartnerPosModel.php create mode 100644 app/Views/pos_list.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 857f4c69..0a174d34 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -421,6 +421,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->match(['get', 'post', 'delete'], 'nhanceBranchMaster', 'MasterController::nhanceBranchMaster'); $routes->match(['get', 'post', 'delete'], 'vehicleTypeMaster', 'MasterController::vehicleTypeMaster'); $routes->match(['get', 'post', 'delete'], 'rtoMaster', 'MasterController::rtoMaster'); + $routes->match(['get', 'post', 'delete'], 'partnerPOS', 'MasterController::partnerPOS'); $routes->get('checkDuplicateCdAccount', 'MasterController::checkDuplicateCdAccount'); $routes->get('proceedExcelFileDataValidation', 'EmployeeController::proceedExcelFileDataValidation'); $routes->get('checkTpaApiEnable', 'EmployeeRestController::checkTpaApiEnable'); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index fec5dc4e..8d8a161d 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -38,6 +38,7 @@ use App\Models\SettingsModel; use App\Models\VehicleModel; use App\Models\VehicleTypeModel; use App\Models\RTOModel; +use App\Models\PartnerPosModel; use CodeIgniter\CLI\CLI; @@ -2320,4 +2321,141 @@ class MasterController extends AdminController } } -} \ No newline at end of file + public function partnerPOS() + { + $posModel = new PartnerPosModel(); + $method = $this->request->getMethod(); + + if ($this->request->getMethod() === 'post') { + + $id = $this->request->getPost('pk'); + $data = $this->request->getPost(); + + unset($data['pk']); + + try { + // Certificate + $certificate = $this->uploadPOSFile('certificate_file_name', 'pos_certificate_files'); + if ($certificate !== null) { $data['certificate_file_name'] = $certificate; } else { unset($data['certificate_file_name']); } + + // PAN file + $panFile = $this->uploadPOSFile('pan_file_name', 'pos_certificate_files'); + if ($panFile !== null) { $data['pan_file_name'] = $panFile; } else { unset($data['pan_file_name']);} + + // Aadhaar file + $aadharFile = $this->uploadPOSFile('aadhar_file_name', 'pos_certificate_files'); + if ($aadharFile !== null) { $data['aadhar_file_name'] = $aadharFile; } else { unset($data['aadhar_file_name']);} + + } catch (\RuntimeException $e) { + return $this->respond([ 'status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $data ], 400); + } + + // INSERT / UPDATE + if (empty($id)) { + $status = $posModel->insert($data); + } else { + $status = $posModel->update($id, $data); + } + + if ($status) { + return $this->respond([ 'status' => true, 'code' => 200, 'message' => 'POS updated successfully', 'data' => $data ], 200); + } + + return $this->respond([ 'status' => false, 'code' => 400, 'message' => 'Failed to update', 'data' => $data ], 400); + } + elseif ($method === 'get') { + + $id = $this->request->getGet('pk') ?? null; + + $db = db_connect(); + + $builder = $db->table('partner_staff'); + + $data['manager_list'] = $builder->select('partner_staff.id, partner_staff.name') + ->where('partner_staff.is_active', 1) + ->where('partner_staff.role_id', 1) + ->get() + ->getResultArray(); + + + if (!empty($id)) { + + $data['pos_list'] = $posModel + ->select('partner_pos.*, partner_staff.name AS manager_name') + ->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left') + ->where('partner_pos.id', $id) + ->orderBy('partner_pos.id', 'DESC') + ->findAll(); + + if (!empty($data)) { + return $this->respond(['status' => true, 'code' => 200, 'data' => $data], 200); + } else { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'No data found'], 200); + } + } + + $data['pos_list'] = $posModel + ->select('partner_pos.*, ps.name AS manager_name') + ->join('partner_staff ps', 'ps.id = partner_pos.manager_id', 'left') + ->orderBy('partner_pos.id', 'DESC') + ->findAll(); + + + return $this->loadLayout('pos_list', ['data' => $data,'tab_name' => 'POS details','page_name' => 'POS details']); + + } elseif ($method === 'delete') { + + // $input = $this->request->getRawInput(); + $id = $this->request->getGet('pk'); // ✅ THIS + $id = $id ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $posModel->where('id', $id)->set(['is_active' => 0])->update(); + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Data removed successfully', + 'pk' => $id + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to remove data', + 'pk' => $id + ], 200); + } + } + } + + private function uploadPOSFile(string $fieldName, string $uploadDir) + { + $file = $this->request->getFile($fieldName); + + if (!$file || !$file->isValid()) { return null; } + + $allowedMime = [ 'image/jpg', 'image/jpeg', 'image/png', 'image/webp', 'application/pdf']; + + if (!in_array($file->getMimeType(), $allowedMime)) { throw new \RuntimeException('Invalid file format'); } + + $path = ROOTPATH . 'public/uploads/' . $uploadDir . '/'; + + if (!is_dir($path)) { mkdir($path, 0755, true); } + + $newName = $file->getRandomName(); + $file->move($path, $newName); + + return $newName; + } + + + } \ No newline at end of file diff --git a/app/Models/PartnerPosModel.php b/app/Models/PartnerPosModel.php new file mode 100644 index 00000000..6e897e35 --- /dev/null +++ b/app/Models/PartnerPosModel.php @@ -0,0 +1,132 @@ + 'required|min_length[3]', + // 'email' => 'permit_empty|valid_email|is_unique[partner_pos.email,id,{id}]', + // 'mobile' => 'permit_empty|numeric|max_length[20]|is_unique[partner_pos.mobile,id,{id}]', + // 'manager_id' => 'required|integer', + // ]; + + // protected $validationMessages = [ + // 'email' => [ + // 'is_unique' => 'Sorry, that email address is already registered.', + // ], + // ]; + + /** + * @var bool Whether to skip validation during inserts and updates. + */ + protected $skipValidation = false; + + /** + * @var bool Whether to clean data for SQL Injection. + */ + protected $cleanValidationRules = true; + + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } + +} \ No newline at end of file diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index eb8bfea0..96061707 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -1808,6 +1808,9 @@
  • RTO
  • +
  • + POS +
  • diff --git a/app/Views/nhance_branch_list.php b/app/Views/nhance_branch_list.php index ba1536bf..4c435257 100644 --- a/app/Views/nhance_branch_list.php +++ b/app/Views/nhance_branch_list.php @@ -118,7 +118,7 @@ { extend: 'csv', text: ' CSV ', - title: 'Policy-Tranction-Inception-List', + title: 'NHance-Branch-List', className: 'app-btn-primary ', exportOptions: { columns: ':not(:last-child)' diff --git a/app/Views/pos_list.php b/app/Views/pos_list.php new file mode 100644 index 00000000..c9ee1001 --- /dev/null +++ b/app/Views/pos_list.php @@ -0,0 +1,455 @@ + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + $row) { ?> + + + + + + + + + + + + + + + + + + +
    S.No.POS NamePOS CodeEmailMobileManagerStatusAction
    + + + + + +
    No data available
    +
    +
    +
    +
    + + + + + + From ce98d8067e6575ca0a4d09adf2388c056bfb377b Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 17 Dec 2025 15:26:43 +0530 Subject: [PATCH 10/27] FIX_TPA_REF_NO --- app/Controllers/EmployeeRestController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 2dad01de..82514ff2 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2844,7 +2844,7 @@ class EmployeeRestController extends AdminController $emp_reatail_policy_data = $this->getEmpRetailPolicy($retailUserData); $wellness_data = ['status' => 'failed','message' => 'Coming soon........!']; - return $this->respond(['status' => 'success', 'code' => 200, 'data' => [], 'emp_name' => $emp_reatail_policy_data[0]['insurerd_name'] ?? "", 'pre_policy_count' => 0, 'retail_policy_data' => $emp_reatail_policy_data, 'wellness_data' => $wellness_data], 200); + return $this->respond(['status' => 'success', 'code' => 200, 'data' => [], 'emp_name' => $emp_reatail_policy_data[0]['insurerd_name'] ?? "", 'pre_policy_count' => 0, 'emp_not_enrolled_count' => 0, 'retail_policy_data' => $emp_reatail_policy_data, 'wellness_data' => $wellness_data], 200); } } @@ -3828,14 +3828,19 @@ class EmployeeRestController extends AdminController } } - if ($pdf_exist_in_the_file && $tpa_claim_push == true) { + $count = $this->ticketMaster->where('id', $ticket_id)->where('is_active', 1)->where('tpa_claim_push_reference_no IS NULL')->countAllResults(); + log_message('error', 'Ticket validation | Ticket ID: ' . $ticket_id . ' | Matching active tickets with NULL TPA reference: ' . $count); + + if ($count > 0 && $pdf_exist_in_the_file && $tpa_claim_push == true) { // this call for TPA integration $apiServiceController = new ApiServiceController(); $apiServiceController->pushClaims($ticket_id); log_message('error', "pushClaims function called with Ticket ID: {$ticket_id}, In Employee Rest Controller"); } else { if($tpa_claim_push == false){ - log_message('error', 'Skip the TPA claim push'); + log_message('error', 'Skip the TPA claim push for IR DOCUMENTS'); + } else if($count == 0){ + log_message('error', 'TPA claim push skipped as the claim reference number is already generated.'); }else{ log_message('error', "Failed to call the pushClaims function in EmployeeRestController for Ticket ID: {$ticket_id}, because the .pdf file does not exist."); } From af61f687c81dfd6ac21687c92eb8824c8cbd69d0 Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Wed, 17 Dec 2025 18:59:13 +0530 Subject: [PATCH 11/27] FIX_retention rate, kyc download issues and kyc dropdown rechecked and fixed --- app/Config/Routes.php | 1 + app/Controllers/ClientController.php | 153 ++++++++++++++++++-------- app/Controllers/MasterController.php | 7 ++ app/Controllers/UserController.php | 71 +++++++++--- app/Models/PartnerPosModel.php | 6 +- app/Models/PartnerStaffModel.php | 2 +- app/Views/UserList.php | 39 ++++++- app/Views/client_kyc_2.php | 14 ++- app/Views/client_kyc_single_table.php | 5 +- app/Views/pos_list.php | 57 +++++++--- 10 files changed, 273 insertions(+), 82 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0a174d34..166dccc2 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -169,6 +169,7 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->post("create_2", "ClientController::createClientKYCInfo_2"); $routes->post("edit_2", "ClientController::editClientKYCInfo_2"); $routes->post("delete_2", "ClientController::deleteClientKycDocs_2/$1"); + $routes->get("download_2/(:any)", "ClientController::downloadClientKycDocs_2/$1"); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 69b977b4..d7902e54 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1121,37 +1121,43 @@ class ClientController extends AdminController } } - public function fetch_dropdown($client_id){ - - $db = db_connect(); + public function fetch_dropdown($client_id) + { + $db = db_connect(); - - $submitted_ids_subquery = $db->table('client_kyc_documents ckd') - ->select('ckd.kyc_doc_type_id') - ->where('ckd.client_id', $client_id) - ->where('ckd.is_active', 1) - ->getCompiledSelect(); - - - $result = $db->table('kyc_docs kd') - ->select('kd.*') - ->join('clients c', 'kd.kyc_type_id = c.entity_type_id') - ->where('c.id', $client_id) - ->where("kd.kyc_type_id NOT IN ({$submitted_ids_subquery})") - ->groupBy('kd.id') - ->get() - ->getResultArray(); + // Already uploaded docs + $uploadedData = $db->table('client_kyc_documents') + ->select('kyc_doc_type_id') + ->where('client_id', $client_id) + ->where('is_active', 1) + ->get() + ->getResultArray(); - - $dropdown = ''; - $dropdown .= ''; + $excludedIds = array_column($uploadedData, 'kyc_doc_type_id'); + + // Available docs + $builder = $db->table('kyc_docs kd'); + $builder->select('kd.id, kd.file_name'); + $builder->join('clients c', 'kd.kyc_type_id = c.entity_type_id'); + $builder->where('c.id', $client_id); + $builder->where('kd.is_active', 1); + + if (!empty($excludedIds)) { + $builder->whereNotIn('kd.id', $excludedIds); + } + + $result = $builder->get()->getResultArray(); // ✅ ARRAY + + // Build dropdown + $dropdown = ''; + $dropdown .= ''; + + foreach ($result as $row) { + $dropdown .= ''; + } - foreach ($result as $row) { - $dropdown .= ''; - } - return $dropdown; } @@ -2517,22 +2523,57 @@ class ClientController extends AdminController { - $result['ckdlist'] = db_connect()->table('client_kyc_documents ckd') - ->select("ckd.id,ckd.client_id,ckd.kyc_doc_type_id,ckd.file_name,kd.file_name AS kd_docs_name,ckd.other_docs_name,ckd.vehicle_id,ckd.is_active, - CASE - WHEN ckd.kyc_doc_type_id IS NULL - OR ckd.kyc_doc_type_id = 0 - OR ckd.kyc_doc_type_id = '' - THEN ckd.other_docs_name - ELSE kd.file_name - END AS ui_docs_name") - ->join('kyc_docs kd','ckd.kyc_doc_type_id = kd.kyc_type_id','left') - ->where('ckd.client_id',$client_id) - ->where('ckd.is_active',1) - ->groupBy('ckd.id') - ->get() - ->getResultArray(); + // $result['ckdlist'] = db_connect()->table('client_kyc_documents ckd') + // ->select("ckd.id,ckd.client_id,ckd.kyc_doc_type_id,ckd.file_name,kd.file_name AS kd_docs_name,ckd.other_docs_name,ckd.vehicle_id,ckd.is_active, + // CASE + // WHEN ckd.kyc_doc_type_id IS NULL + // OR ckd.kyc_doc_type_id = 0 + // OR ckd.kyc_doc_type_id = '' + // THEN ckd.other_docs_name + // ELSE kd.file_name + // END AS ui_docs_name") + // ->join('kyc_docs kd','ckd.kyc_doc_type_id = kd.id','left') + // ->where('ckd.client_id',$client_id) + // ->where('ckd.is_active',1) + // ->groupBy('ckd.id') + // ->get() + // ->getResultArray(); + + $builder = db_connect()->table('client_kyc_documents AS ckd'); + + // Select the standard fields + $builder->select(' + ckd.id, + ckd.client_id, + ckd.kyc_doc_type_id, + ckd.file_name, + ckd.other_docs_name, + ckd.vehicle_id, + ckd.is_active + '); + + // Add the CASE statement for ui_docs_name + // Using false as the second parameter tells CI4 not to escape the string + $builder->select(" + CASE + WHEN ckd.kyc_doc_type_id IS NULL OR ckd.kyc_doc_type_id = 0 OR ckd.kyc_doc_type_id = '' + THEN ckd.other_docs_name + ELSE kd.file_name + END AS ui_docs_name + ", false); + + // Join with kyc_docs + $builder->join('kyc_docs AS kd', 'ckd.kyc_doc_type_id = kd.id', 'left'); + + // Where clauses + $builder->where('ckd.client_id', $client_id); + $builder->where('ckd.is_active', 1); + + // Group By + $builder->groupBy('ckd.id'); + + $result['ckdlist'] = $builder->get()->getResultArray(); $result['client_id'] = $client_id; $table = view('client_kyc_single_table', $result); @@ -8338,6 +8379,32 @@ class ClientController extends AdminController return $default_templates_inserted ? true : false; } + // public function downloadClientKycDocs_2() + // { + + // $file = WRITEPATH . 'uploads/client_kyc_documents/' . $file_name; // Example file path + // if (file_exists($file)) { + // return $this->response->download($file, null)->setFileName($file_name); + // } else { + // return "File not found."; + // } + // } + public function downloadClientKycDocs_2($file_name = null) + { + if (!$file_name) { + return "No file specified."; + } + + // Use absolute path to your upload folder + $file = WRITEPATH . 'uploads/client_kyc_documents/' . $file_name; + + if (file_exists($file)) { + // download() takes the path as first param and null (or data) as second + return $this->response->download($file, null); + } else { + return "File not found at: " . $file; + } + } } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 8d8a161d..2c243fee 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -2350,6 +2350,13 @@ class MasterController extends AdminController return $this->respond([ 'status' => false, 'code' => 400, 'message' => $e->getMessage(), 'data' => $data ], 400); } + foreach ($data as $k => $v) { + if ($v === '' || $v === null) { + unset($data[$k]); + } + } + + // INSERT / UPDATE if (empty($id)) { $status = $posModel->insert($data); diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 3879b49d..48f3c7a3 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -594,35 +594,70 @@ class UserController extends AdminController // add/update if ($method === 'post') { - $data = $this->request->getPost(); - if (!empty($data['id'])) { - $text = "update"; - $data['updated_by'] = get_session_userid(); - $result = $this->partnerStaffModel->update($data['id'], $data); - $updateID = $data['id']; - } else { - $text = "create"; - $data['role_id'] = 1; - $data['created_by'] = get_session_userid(); - $insertID = $this->partnerStaffModel->insert($data); - if($insertID){ - $details['manager_id'] = $insertID; - $details['updated_by'] = get_session_userid(); - $this->partnerStaffModel->update($insertID, $details); + $id = !empty($data['PrimaryKey']) ? $data['PrimaryKey'] : null; + + // don't forgot same means just unset the key because partner_staff some UNIQUE KEY sets in table thats why + if ($id) { + $existing = $this->partnerStaffModel->find($id); + if ($existing) { + if ($data['email'] === $existing['email']) { unset($data['email']); } + if ($data['mobile'] === $existing['mobile']) { unset($data['mobile']); } } - $result = true; } - $id = isset($insertID) && !empty($insertID) ? $insertID : ($updateID ?? null); + $errors = []; + + // Check Email Duplicate (if it wasn't unset) + if (isset($data['email'])) { + $count = $this->partnerStaffModel->where('email', $data['email'])->countAllResults(); + if ($count > 0) $errors['email'] = "This email is already taken by another user."; + } + + // Check Mobile Duplicate (if it wasn't unset) + if (isset($data['mobile'])) { + $count = $this->partnerStaffModel->where('mobile', $data['mobile'])->countAllResults(); + if ($count > 0) $errors['mobile'] = "This mobile is already taken by another user."; + } + + // If there are duplicates, stop and return error + if (!empty($errors)) { + return $this->response->setJSON([ + 'status' => 'error', + 'message' => 'Duplicate detected', + 'errors' => $errors + ])->setStatusCode(400); + } + + // --- Save/Update --- + if ($id) { + $text = "update"; + $data['updated_by'] = get_session_userid(); + + $result = $this->partnerStaffModel->update($updateID, $data); + } else { + $text = "create"; + $data['role_id'] = 1; + $data['created_by'] = get_session_userid(); + $id = $this->partnerStaffModel->insert($data); + if($id){ + $details['manager_id'] = $id; + $details['updated_by'] = get_session_userid(); + $this->partnerStaffModel->update($id, $details); + } + $result = true; + + } + + return $this->response->setJSON([ 'status' => $id ? 'success' : 'error', 'message' => $id ? "Staff {$text}d successfully" : "Unable to {$text} staff. Please try again.", 'id' => $id ])->setStatusCode($id ? 200 : 400); - } + } // delete if ($method === 'put') { $data = $this->request->getRawInput(); diff --git a/app/Models/PartnerPosModel.php b/app/Models/PartnerPosModel.php index 6e897e35..b1b99328 100644 --- a/app/Models/PartnerPosModel.php +++ b/app/Models/PartnerPosModel.php @@ -61,7 +61,7 @@ class PartnerPosModel extends Model 'mobile', 'pos_code', 'certificate_file_name', - 'pan', + 'gst','pan', 'pan_file_name', 'aadhar', 'aadhar_file_name', @@ -73,6 +73,10 @@ class PartnerPosModel extends Model 'account_holder_name', 'account_number', 'ifsc_code', + 'address', + 'state', + 'city', + 'pincode', // 'created_on' and 'updated_on' are handled by the Model, // but need to be in $allowedFields if $useTimestamps is false. diff --git a/app/Models/PartnerStaffModel.php b/app/Models/PartnerStaffModel.php index 340a0ec5..f79f06ad 100755 --- a/app/Models/PartnerStaffModel.php +++ b/app/Models/PartnerStaffModel.php @@ -16,7 +16,7 @@ class PartnerStaffModel extends Model protected $useSoftDeletes = false; // allowed fields for insert/update - protected $allowedFields = ['name','email','mobile','emp_id','role_id','email_otp','is_active','created_by','updated_by','manager_id']; + protected $allowedFields = ['name','email','mobile','emp_id','role_id','email_otp','is_active','created_by','updated_by','manager_id','retention_rate']; // automatic timestamps protected $useTimestamps = true; diff --git a/app/Views/UserList.php b/app/Views/UserList.php index 1382369b..1e3e2766 100755 --- a/app/Views/UserList.php +++ b/app/Views/UserList.php @@ -623,6 +623,14 @@ table.dataTable tbody td {
    + + + +
    + + +
    +
    @@ -1145,6 +1153,7 @@ table.dataTable tbody td { $('#email_addr').val(user.email); $('#mobile_no').val(user.mobile); $('#locn').val(user.address); + $('#retention_rate').val(user.retention_rate); // $('#btnPartnerSubmit').html('Update'); $('.modal-title').html('Update Nhance Partner'); let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal')); @@ -1395,11 +1404,18 @@ table.dataTable tbody td {
    ` ]; } else { // partner + let roleName = ""; + switch(parseInt(row.role_id)) { + case 1: roleName = "Manager"; break; + case 2: roleName = "Handler"; break; + case 3: roleName = "Staff"; break; + default: roleName = "Others"; + } rowData = [ row.name, row.email, row.mobile, - row.role_id == 1 ? "Manager" : "Staff", + roleName, `${statusText}`, `
    - +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    -
    +
    + + + +
    +
    + + +
    +
    +
    +
    -
    - - - -
    -
    +
    -
    -
    -
    +
    -
    +
    @@ -352,6 +374,13 @@ $('#account_holder_name').val(data.account_holder_name); $('#account_number').val(data.account_number); $('#ifsc_code').val(data.ifsc_code); + + $('#gst').val(data.gst); + + $('#state').val(data.state); + $('#city').val(data.city); + $('#pincode').val(data.pincode); + $('#address').val(data.address); openModal(); $('#con-close-modal').one('shown.bs.modal', function () { From 247d072e9727027da248bee646bbf4265b64b4ff Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 18 Dec 2025 10:29:34 +0530 Subject: [PATCH 12/27] CHANGE_BDS_NEW_CHANGES --- .../PolicyTransactionController.php | 49 ++++- app/Models/PolicyTransactionModel.php | 202 +++++++++++++++--- .../policy_transaction_inception_form.php | 144 ++++++++++++- app/Views/report_bds.php | 110 ++++++++-- 4 files changed, 452 insertions(+), 53 deletions(-) diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 7cc91aca..64425b2e 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -669,14 +669,43 @@ ->where('is_active', 1) ->findAll(); + // // Fetch Sales Team + // $data['salse_team'] = $this->userModel + // ->select('user_profiles.*,nhance_branch.id as nhance_branch_id, nhance_branch.branch_name as nhance_branch_name') + // ->join('user_teams', 'user_profiles.id = user_teams.user_id') + // ->join('nhance_branch', 'user_profiles.nhance_branch_id = nhance_branch.id','left') + // ->where('user_teams.team_id', 5) + // ->where('user_teams.is_active', 1) + // ->where('user_profiles.is_active', 1) + // ->findAll(); + + // // Fetch Partner Agent + // $data['partner_agent'] = db_connect()->table('partner_agent') + // ->where('is_active', 1) + // ->get() + // ->getResultArray(); + + // // Fetch ACM + // $data['ACM'] = $this->userModel + // ->where('role', 3) // Assuming `role` is in `user_profiles` + // ->where('is_active', 1) + // ->findAll(); + // Fetch Sales Team $data['salse_team'] = $this->userModel - ->select('user_profiles.*,nhance_branch.id as nhance_branch_id, nhance_branch.branch_name as nhance_branch_name') + ->select(' + user_profiles.*, + nhance_branch.id as nhance_branch_id, + nhance_branch.branch_name as nhance_branch_name, + rm.first_name AS rm_name + ') ->join('user_teams', 'user_profiles.id = user_teams.user_id') ->join('nhance_branch', 'user_profiles.nhance_branch_id = nhance_branch.id','left') + ->join('user_profiles AS rm', 'user_profiles.rm_id = rm.id', 'left') ->where('user_teams.team_id', 5) ->where('user_teams.is_active', 1) ->where('user_profiles.is_active', 1) + ->groupBy('user_profiles.id', 'asc') ->findAll(); // Fetch Partner Agent @@ -687,12 +716,20 @@ // Fetch ACM $data['ACM'] = $this->userModel - ->where('role', 3) // Assuming `role` is in `user_profiles` - ->where('is_active', 1) - ->findAll(); - // echo '
    ';
    +                    ->select('
    +                        user_profiles.*, 
    +                        nhance_branch.id AS nhance_branch_id, 
    +                        nhance_branch.branch_name AS nhance_branch_name, 
    +                        rm.first_name AS rm_name
    +                    ')
    +                    ->join('user_teams', 'user_profiles.id = user_teams.user_id')
    +                    ->join('nhance_branch', 'user_profiles.nhance_branch_id = nhance_branch.id', 'left')
    +                    ->join('user_profiles AS rm', 'user_profiles.rm_id = rm.id', 'left')
    +                    ->where('user_profiles.role', 3)  
    +                    ->where('user_profiles.is_active', 1)
    +                    ->groupBy('user_profiles.id', 'asc')
    +                    ->findAll();
                 
    -            // print_r($data['ppTeamsData']); die;
     
                 // dd($data);
     
    diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php
    index 1ac58a29..97798b57 100644
    --- a/app/Models/PolicyTransactionModel.php
    +++ b/app/Models/PolicyTransactionModel.php
    @@ -2572,6 +2572,7 @@
                             cb.address1 AS client_address,
                             ptype.policy_type,
                             ptype.bap,
    +                        ins.id AS insurer_id,
                             ins.name AS insurer_name,
                             ins.short_name AS insurer_short_name,
                             ib.branch_name AS insurer_branch_name,
    @@ -2596,7 +2597,6 @@
                             ROUND(pcsd.cotp_amt + pcsd.cotep_amt, 2) AS tp_or_ter,
                             DATEDIFF(pt.policy_end_date, CURDATE()) AS days,
                             (pcsd.agreed_tp_per + pcsd.agreed_tep_per) AS agreed_tp_or_ter_per,
    -                        pcsd.agreed_bp_per,
     
                             ROUND(pcsd.exp_amt, 2) AS total_irda_amt,
                             0.00 AS reward,
    @@ -2607,7 +2607,55 @@
                                 WHEN pcsd.co_share_type > 1 THEN 
                                     IFNULL(NULLIF(pcsd.follower_policy_no,''), pt.policy_no)
                                 ELSE pt.policy_no
    -                        END AS policy_no
    +                        END AS policy_no,
    +
    +                        CASE 
    +                            WHEN pt.co_share = 1 THEN 'Yes'
    +                            ELSE 'No'
    +                        END AS co_share,
    +
    +                        CASE 
    +                            WHEN pt.bro_payable_by = 1 THEN 'Yes'
    +                            ELSE 'No'
    +                        END AS bro_payable_by,
    +
    +                        pcsd.non_comm_per_amt,
    +
    +                        pcsd.bp_igst,
    +                        pcsd.bp_sgst,
    +                        pcsd.bp_cgst, 
    +
    +                        pcsd.agreed_bp_per,    
    +                        ROUND(pcsd.agreed_tp_per + pcsd.agreed_tep_per,2) AS agreed_tp_per, 
    +
    +                        pcsd.standerd_bp_per,
    +                        ROUND(pcsd.standerd_tp_per + pcsd.standerd_tep_per,2) AS standerd_tp_per, 
    +
    +                        0 AS actual_bp_amt,
    +                        ROUND(0, 2) AS actual_tp_amt,
    +
    +                        0 AS actual_bp_per,
    +                        ROUND(0, 2) AS actual_tp_per,
    +
    +                        0 AS actual_tep_brokerage_amt,
    +                        ROUND(0, 2) AS actual_tp_brokerage_amt,
    +         
    +                        service_branch.branch_name as service_branch,
    +
    +                        salse_manager.first_name as salse_manager_name,
    +                        service_manager.first_name as service_manager_name,
    +                        cd_master.cd_ac_no,
    +                        pt.rollover_date,
    +                        pt.policy_holder_name,
    +
    +                        CASE 
    +                            WHEN pt.same_as_proposer = 1 THEN 'Yes'
    +                            ELSE 'No'
    +                        END AS same_as_proposer,
    +
    +                        pcsd.follower_policy_no,
    +                        pcsd.co_share_per,
    +                        pcsd.stamp_duty
     
                         FROM policy_transaction pt
                         LEFT JOIN pt_co_share_details pcsd ON pt.id = pcsd.pt_id
    @@ -2626,6 +2674,11 @@
                         LEFT JOIN user_profiles created_user ON pt.created_by = created_user.id
                         LEFT JOIN nhance_branch ON pt.issuer_branch = nhance_branch.id
     
    +                    LEFT JOIN nhance_branch service_branch ON pt.service_person_branch_id = service_branch.id
    +                    LEFT JOIN user_profiles salse_manager ON pt.salse_person_manager_id = salse_manager.id
    +                    LEFT JOIN user_profiles service_manager ON pt.service_person_manager_id = service_manager.id
    +                    LEFT JOIN cd_master ON pt.cd_ac_pk = cd_master.id
    +
                         WHERE pt.is_active = 1
                         AND pcsd.is_active = 1
                         $default_date_filter
    @@ -2663,10 +2716,20 @@
                             END AS revenue_type,
     
                             CASE 
    -                            WHEN pt.action_type = 'inception' THEN 'Policy'
    +                            WHEN 
    +                                IFNULL(cssd.actual_tep_brokerage_amt, 0) = 0
    +                                AND IFNULL(cssd.actual_tp_brokerage_amt, 0) = 0
    +                                AND IFNULL(cssd.actual_bp_brokerage_amt, 0) = 0
    +                                AND IFNULL(cssd.reward, 0) != 0
    +                            THEN 'Rewards'
    +
    +                            WHEN pt.action_type = 'inception' 
    +                            THEN 'Policy'
    +
                                 ELSE 'Endorsement'
                             END AS action_type,
     
    +
                             pt.action_type as action_type_string,
     
                             c.client_name,
    @@ -2675,20 +2738,13 @@
                             cb.address1 AS client_address,
                             ptype.policy_type,
                             ptype.bap,
    +                        ins.id AS insurer_id,
                             ins.name AS insurer_name,
                             ins.short_name AS insurer_short_name,
                             ib.branch_name AS insurer_branch_name,
                             ib.branch_code AS insurer_branch_code,
     
    -                        CASE 
    -                            WHEN 
    -                                IFNULL(cssd.actual_tep_brokerage_amt,0) = 0 AND
    -                                IFNULL(cssd.actual_tp_brokerage_amt,0) = 0 AND
    -                                IFNULL(cssd.actual_bp_brokerage_amt,0) = 0 AND
    -                                IFNULL(cssd.reward,0) != 0
    -                            THEN 'Rewards'
    -                            ELSE created_user.first_name
    -                        END AS user_name,
    +                        created_user.first_name as user_name,
                             
                             v.vehicle_no,
                             tpa.name AS tpa_name,
    @@ -2708,7 +2764,6 @@
                             ROUND(pcsd.cotp_amt + pcsd.cotep_amt,2) AS tp_or_ter,
                             DATEDIFF(pt.policy_end_date, CURDATE()) AS days,
                             (pcsd.agreed_tp_per + pcsd.agreed_tep_per) AS agreed_tp_or_ter_per,
    -                        pcsd.agreed_bp_per,
     
                             CASE 
                                 WHEN insq.month = pt.month THEN pcsd.exp_amt
    @@ -2747,7 +2802,55 @@
                                 WHEN pcsd.co_share_type > 1 
                                     THEN IFNULL(NULLIF(pcsd.follower_policy_no,''), pt.policy_no)
                                 ELSE pt.policy_no
    -                        END AS policy_no
    +                        END AS policy_no,
    +
    +                        CASE 
    +                            WHEN pt.co_share = 1 THEN 'Yes'
    +                            ELSE 'No'
    +                        END AS co_share,
    +
    +                        CASE 
    +                            WHEN pt.bro_payable_by = 1 THEN 'Yes'
    +                            ELSE 'No'
    +                        END AS bro_payable_by,
    +
    +                        pcsd.non_comm_per_amt,
    +
    +                        pcsd.bp_igst,
    +                        pcsd.bp_sgst,
    +                        pcsd.bp_cgst, 
    +
    +                        pcsd.agreed_bp_per,    
    +                        ROUND(pcsd.agreed_tp_per + pcsd.agreed_tep_per,2) AS agreed_tp_per, 
    +
    +                        pcsd.standerd_bp_per,
    +                        ROUND(pcsd.standerd_tp_per + pcsd.standerd_tep_per,2) AS standerd_tp_per, 
    +
    +                        cssd.actual_bp_amt,
    +                        ROUND(cssd.actual_tp_amt + cssd.actual_tep_amt,2) AS actual_tp_amt,    
    +
    +                        cssd.actual_bp_per,
    +                        ROUND(cssd.actual_tp_per + cssd.actual_tep_per,2) AS actual_tp_per,    
    +
    +                        cssd.actual_tep_brokerage_amt,
    +                        ROUND(cssd.actual_tp_brokerage_amt + cssd.actual_bp_brokerage_amt,2) AS actual_tp_brokerage_amt,
    +                        
    +                        service_branch.branch_name as service_branch,
    +
    +                        salse_manager.first_name as salse_manager_name,
    +                        service_manager.first_name as service_manager_name,
    +                        cd_master.cd_ac_no,
    +                        pt.rollover_date,
    +                        pt.policy_holder_name,
    +
    +                        CASE 
    +                            WHEN pt.same_as_proposer = 1 THEN 'Yes'
    +                            ELSE 'No'
    +                        END AS same_as_proposer,
    +
    +                        pcsd.follower_policy_no,
    +                        pcsd.co_share_per,
    +                        pcsd.stamp_duty
     
                         FROM policy_transaction pt
                         LEFT JOIN pt_co_share_details pcsd ON pt.id = pcsd.pt_id
    @@ -2768,6 +2871,12 @@
                         LEFT JOIN user_profiles created_user ON pt.created_by = created_user.id
                         LEFT JOIN nhance_branch ON pt.issuer_branch = nhance_branch.id
     
    +                    LEFT JOIN nhance_branch service_branch ON pt.service_person_branch_id = service_branch.id
    +                    LEFT JOIN user_profiles salse_manager ON pt.salse_person_manager_id = salse_manager.id
    +                    LEFT JOIN user_profiles service_manager ON pt.service_person_manager_id = service_manager.id
    +                    LEFT JOIN cd_master ON pt.cd_ac_pk = cd_master.id
    +
    +
                         WHERE pt.is_active = 1
                         AND pcsd.is_active = 1
                         AND cssd.is_active = 1
    @@ -2823,29 +2932,64 @@
                 $result = array_values($filtered);
                 // dd($result);
     
    -            $runningBilled = [];
    +            // $runningBilled = [];
    +            // $totalIrdaMap = [];
    +            // $final = [];
    +
    +            // foreach ($result as $row) {
    +            //     $ptId = $row['pt_id'];
    +
    +            //     // Store total_irda_amt only once (first non-zero value)
    +            //     if (!isset($totalIrdaMap[$ptId]) && $row['total_irda_amt'] > 0) {
    +            //         $totalIrdaMap[$ptId] = $row['total_irda_amt'];
    +            //     }
    +
    +            //     // Initialize running sum
    +            //     if (!isset($runningBilled[$ptId])) {
    +            //         $runningBilled[$ptId] = 0;
    +            //     }
    +
    +            //     // Add billed amount to running total
    +            //     $runningBilled[$ptId] += (float)$row['billed_amt'];
    +
    +            //     // Calculate unbilled amount
    +            //     $row['unbilled_amount'] = ($totalIrdaMap[$ptId] ?? 0) - $runningBilled[$ptId];
    +
    +            //     $final[] = $row;
    +            // }
    +
    +            $totalBilled  = [];
                 $totalIrdaMap = [];
    -            $final = [];
     
                 foreach ($result as $row) {
    -                $ptId = $row['pt_id'];
    +                $key = $row['pt_id'].'-'.$row['insurer_id'];
     
    -                // Store total_irda_amt only once (first non-zero value)
    -                if (!isset($totalIrdaMap[$ptId]) && $row['total_irda_amt'] > 0) {
    -                    $totalIrdaMap[$ptId] = $row['total_irda_amt'];
    +                // Sum billed amount
    +                $totalBilled[$key] = ($totalBilled[$key] ?? 0)
    +                    + (float) ($row['billed_amt'] ?? 0);
    +
    +                // Store total_irda_amt once
    +                if (!isset($totalIrdaMap[$key]) && ($row['total_irda_amt'] ?? 0) > 0) {
    +                    $totalIrdaMap[$key] = (float) $row['total_irda_amt'];
                     }
    +            }
     
    -                // Initialize running sum
    -                if (!isset($runningBilled[$ptId])) {
    -                    $runningBilled[$ptId] = 0;
    +
    +            $ptSeen = [];
    +            $final  = [];
    +
    +            foreach ($result as $row) {
    +                $ptId = $row['pt_id'].'-'.$row['insurer_id'];
    +                if (!isset($ptSeen[$ptId])) {
    +                    // First entry → set unbilled amount
    +                    $row['unbilled_amount'] = ($totalIrdaMap[$ptId] ?? 0) - ($totalBilled[$ptId] ?? 0);
    +
    +                    $ptSeen[$ptId] = true;
    +                } else {
    +                    // Other entries → zero
    +                    $row['unbilled_amount'] = 0;
                     }
     
    -                // Add billed amount to running total
    -                $runningBilled[$ptId] += (float)$row['billed_amt'];
    -
    -                // Calculate unbilled amount
    -                $row['unbilled_amount'] = ($totalIrdaMap[$ptId] ?? 0) - $runningBilled[$ptId] ;
    -
                     $final[] = $row;
                 }
     
    diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php
    index 80ae3e0b..25e18758 100644
    --- a/app/Views/policy_transaction_inception_form.php
    +++ b/app/Views/policy_transaction_inception_form.php
    @@ -325,6 +325,10 @@
                             
                             
                             
    +                        
    +                        
    +                        
    +                        
     
                             
                             
    @@ -420,7 +424,7 @@
                                                         
                                                     
    --> -
    + +
    @@ -779,7 +784,7 @@ name="renewal_date" placeholder="DD/MM/YYYY"> -
    + + +
    + + + +
    + +
    + +
    @@ -6422,8 +6486,6 @@ } - - function generateShortName() { let clientInput = $("#client_name"); let shortInput = $("#short_name"); @@ -6593,4 +6655,76 @@ } } + function setNhanceBranch(select, show_id) { + + if (!select || !select.options || select.selectedIndex < 0) { + console.warn('No option selected yet'); + return; + } + + let selectedOption = select.options[select.selectedIndex]; + + let nbID = selectedOption.getAttribute('data-nbid'); + let nbName = selectedOption.getAttribute('data-nbname'); + + console.log('NB ID:', nbID); + console.log('NB Name:', nbName); + + if(show_id == "nhance_branch_info"){ + $('#issuer_branch').val(nbID ? nbID : ''); + }else{ + $('#service_person_branch_id').val(nbID ? nbID : ''); + } + + let nbDiv = document.getElementById(show_id); + + if (!nbID || !nbName) { + nbDiv.innerHTML = ''; + nbDiv.classList.remove('show'); + return; + } + + nbDiv.innerHTML = + '' + nbName + '' + + ' ✓ Nhance Branch'; + + nbDiv.classList.add('show'); + } + + function setRM(select, show_id) { + + if (!select || !select.options || select.selectedIndex < 0) { + console.warn('No option selected yet'); + return; + } + + let selectedOption = select.options[select.selectedIndex]; + + let rmid = selectedOption.getAttribute('data-rmid'); + let rmname = selectedOption.getAttribute('data-rmname'); + + console.log('RM ID:', rmid); + console.log('RM Name:', rmname); + + if(show_id == "salse_rm_info"){ + $('#salse_person_manager_id').val(rmid ? rmid : ''); + }else{ + $('#service_person_manager_id').val(rmid ? rmid : ''); + } + + let rmDiv = document.getElementById(show_id); + + if (!rmid || !rmname) { + rmDiv.innerHTML = ''; + rmDiv.classList.remove('show'); + return; + } + + rmDiv.innerHTML = + '' + rmname + '' + + ' ✓ RM'; + + rmDiv.classList.add('show'); + } + diff --git a/app/Views/report_bds.php b/app/Views/report_bds.php index db84e64e..1d459049 100644 --- a/app/Views/report_bds.php +++ b/app/Views/report_bds.php @@ -54,11 +54,15 @@ table.dataTable tbody td {
    - Total Rewards: 0.00 + IRDA Amount : 0.00
    - Total IRDA Revenue INR: 0.00 + Rewards: 0.00 +
    + +
    + Revenue: 0.00
    @@ -84,7 +88,7 @@ table.dataTable tbody td { Business Type Client Type Insured Name - Policy /
    Endorsement + Transaction Type Policy Type BAP Group Vehicle Number @@ -99,23 +103,60 @@ table.dataTable tbody td { Reference Remarks BP Premium - TP/Ter Premium + TP Premium Premium
    (without GST) Total Premium - BP% - TP/Ter% + Agreed BP % + Agreed TP % Rewards Agreed Amount Invoiced Amount Outstanding Amount + Salse Person Service Person - Nhance Branch + Salse Person Branch Installment Data Received Date Renewal Date - + + Co-Premium + Remuneration Pay By Leader + + Salse Person Manager + Service Person Manager + Service Person Branch + + Rollover Date + + Policyholder Name + Insured (Same as Proposer) + + Follower Policy No + + Co-Share % + Non Commissional
    Premium Amount + + CGST + SGST + IGST + + Stamp Duty + + Standard BP % + Standard TP % + + Actual BP Amount + Actual TP Amount + + Actual BP % + Actual TP % + + Actual BP Remuneration Amount + Actual TP Remuneration Amount + + CD Account No @@ -148,13 +189,14 @@ table.dataTable tbody td { + - + - - % - % + + % + % @@ -198,6 +242,44 @@ table.dataTable tbody td { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -602,12 +684,14 @@ $(document).ready(function() { var totalRewards = getTotal(24); var totalIrda = getTotal(25); var totalBilled = getTotal(26); + var totalRevenue = parseFloat(totalIrda) + parseFloat(totalRewards); // var totalUnbilled = getTotal(27); // Update the totals section above the table $('#total_premium').text(totalPremium.toFixed(2)); $('#total_rewards').text(totalRewards.toFixed(2)); $('#total_irda').text(totalIrda.toFixed(2)); + $('#total_revenue').text(totalRevenue.toFixed(2)); $('#total_billed').text(totalBilled.toFixed(2)); // $('#total_unbilled').text(totalUnbilled.toFixed(2)); var totalUnbilled = getUniqueUnbilled(27); From 70f8ed7fd89fe19ab1ca697075087ae4c2781cbc Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Thu, 18 Dec 2025 11:56:15 +0530 Subject: [PATCH 13/27] FIX_Invoice Module Agent Replaced by POS - Changes --- app/Controllers/PayoutController.php | 66 ++++++++++++--- app/Models/InvoiceModel.php | 59 ++++++++++---- app/Views/invoice_policy_mapping.php | 118 ++++++++++++++++++++------- app/Views/invoice_template_2.php | 45 +++++++++- app/Views/payout_list.php | 11 ++- app/Views/payout_list_handler.php | 29 +++++-- 6 files changed, 262 insertions(+), 66 deletions(-) diff --git a/app/Controllers/PayoutController.php b/app/Controllers/PayoutController.php index 29e8b555..90d501dc 100644 --- a/app/Controllers/PayoutController.php +++ b/app/Controllers/PayoutController.php @@ -51,12 +51,14 @@ class PayoutController extends BaseController $data = $this->request->getPost(); // print_r($data); die; - $agent_id = $data['agent_id'] ?? null; + // $agent_id = $data['agent_id'] ?? null; because dropdown hided + $pos_id = $data['pos_id'] ?? null; $status_id = $data['status_id'] ?? null; $start_date = $data['start_date'] ?? null; $end_date = $data['end_date'] ?? null; - $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); + // $payout_data = $this->invoiceModel->invoiceList($agent_id, $status_id, $start_date, $end_date); // because dropdown hided + $payout_data = $this->invoiceModel->invoiceList($pos_id, $status_id, $start_date, $end_date); $payout_data['payout_list_data'] = $payout_data; $payout_data = view('payout_list', $payout_data); @@ -86,7 +88,8 @@ class PayoutController extends BaseController // for list $data['payout_status'] = $this->payout_status; - $data['agent_list'] = $this->invoiceModel->agentList(); + // $data['agent_list'] = $this->invoiceModel->agentList(); // because dropdown hided + $data['pos_list'] = $this->invoiceModel->posList(); $data['page_name'] = "Invoices"; $payout_data['payout_list_data'] = $this->invoiceModel->invoiceList(); $data['payout_list'] = view('payout_list', $payout_data); @@ -204,8 +207,9 @@ class PayoutController extends BaseController $title = $type === 'add' ? 'Add Payouts' : ($type === 'edit' ? 'Edit Payouts' + : ($type === 'view' ? 'View Payouts' : ($type === 'adjustment' ? 'Payouts Adjustment' - : 'Payouts')); + : 'Payouts'))); $data['tab_name'] = $title; $data['page_name'] = $title; @@ -215,10 +219,12 @@ class PayoutController extends BaseController if($type == 'add') { $data['agents'] = $this->invoiceModel->agentList(['is_active' => 1]); // common both add and edit + $data['pos_list'] = $this->invoiceModel->posList(['is_active' => 1]); // common both add and edit } else { $data['agents'] = $this->invoiceModel->agentList(); // common both add and edit + $data['pos_list'] = $this->invoiceModel->posList(); // common both add and edit } // $data['checked_policy_numbers'] = []; // $data['invoice'] = []; @@ -236,16 +242,21 @@ class PayoutController extends BaseController return $this->loadLayout('invoice_policy_mapping_add', $data); } - if (($type === 'edit' || $type === 'adjustment') && !empty($id)) { + if (($type === 'edit' || $type === 'view' || $type === 'adjustment') && !empty($id)) { $invoice = $this->invoiceModel->where('id', $id)->first(); + // print_r($invoice);die; $data['freeze_edit'] = $this->auditHistory->where('table_name', 'partner_invoice')->where('pk', $id)->countAllResults(); - + if($type === 'view'){ $data['freeze_edit'] = 1; } - $agentId = $invoice['agent_id'] ?? null; + // $agentId = $invoice['agent_id'] ?? null; + $posId = $invoice['pos_id'] ?? null; - $data['payouts'] = $this->invoiceModel->payoutList(2 ,$agentId,$id); - $data['extra_payouts'] = $agentId ? $this->invoiceModel->payoutList(3, $agentId) : []; + // $data['payouts'] = $this->invoiceModel->payoutList(2 ,$agentId,$id); + // $data['extra_payouts'] = $agentId ? $this->invoiceModel->payoutList(3, $agentId) : []; + $data['payouts'] = $this->invoiceModel->payoutList(2 ,$posId,$id); + // print_r($data['payouts']);die; + $data['extra_payouts'] = $posId ? $this->invoiceModel->payoutList(3, $posId) : []; $invoice_items = $this->invoiceItemModel->where('invoice_id', $id)->findAll(); @@ -518,6 +529,7 @@ class PayoutController extends BaseController // Get invoice data from database $invoiceData = $this->getInvoiceData($invoiceId); + // print_r($invoiceData);die; if (empty($invoiceData)) { return $this->respond([ @@ -591,6 +603,27 @@ class PayoutController extends BaseController } + // private function getInvoiceData($invoiceId) + // { + // $invoice_data = $this->invoiceModel + // ->select(' + // partner_invoice.*, + // pa.name as agent_name, + // pa.email as agent_email, + // pa.mobile as agent_mobile, + // pa.address as agent_address, + // pa.agent_code, + // pa.certificate_file_name, + // pa.commission_retain + // ') + // ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id') + // ->where('partner_invoice.is_active', 1) + // ->where('partner_invoice.id', $invoiceId) + // ->first(); + + // return $invoice_data; + // } + private function getInvoiceData($invoiceId) { $invoice_data = $this->invoiceModel @@ -604,9 +637,20 @@ class PayoutController extends BaseController pa.address as agent_address, pa.agent_code, pa.certificate_file_name, - pa.commission_retain + pa.commission_retain, + pos.name as pos_name, + pos.email as pos_email, + pos.mobile as pos_mobile, + pos.address as pos_address, + pos.city as pos_city, + pos.pincode as pos_pincode, + pos.state as pos_state, + pos.pos_code, + pos.certificate_file_name as pos_certificate_file_name, + pos.bank_name,pos.account_holder_name,pos.account_number,pos.ifsc_code, ') - ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id') + ->join('partner_agent pa', 'partner_invoice.agent_id = pa.id','left') + ->join('partner_pos pos', 'partner_invoice.pos_id = pos.id') ->where('partner_invoice.is_active', 1) ->where('partner_invoice.id', $invoiceId) ->first(); diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index bebd0022..a2e241dc 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -75,8 +75,8 @@ class InvoiceModel extends Model return $data; } - - public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null) + // public function invoiceList($agent_id = null, $status_id = null, $start_date = null, $end_date = null) because dropdown hided + public function invoiceList($pos_id = null, $status_id = null, $start_date = null, $end_date = null) { $data = $this->select(" partner_invoice.*, @@ -105,14 +105,21 @@ class InvoiceModel extends Model WHEN payout_status = 2 THEN 'Completed' END AS status_text, - partner_agent.name as agent_name + partner_agent.name as agent_name, + partner_pos.name as pos_name + ") - ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id') + ->join('partner_agent', 'partner_invoice.agent_id = partner_agent.id','left') + ->join('partner_pos', 'partner_invoice.pos_id = partner_pos.id') ->where('partner_invoice.is_active', 1) ->where('partner_invoice.broker_id', 1); - if(!empty($agent_id)){ - $data->where('partner_invoice.agent_id', $agent_id); + // if(!empty($agent_id)){ + // $data->where('partner_invoice.agent_id', $agent_id); + // } // because dropdown hided + + if(!empty($pos_id)){ + $data->where('partner_invoice.pos_id', $pos_id); } if(!empty($status_id)){ @@ -128,7 +135,8 @@ class InvoiceModel extends Model ->where('partner_invoice.invoice_date <=', $endDate); } - if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + // if(!empty($agent_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ + if(!empty($pos_id) && !empty($status_id) && !empty($start_date) && !empty($end_date)){ $fromDate = date('Y-m-d', strtotime('-60 days')); $toDate = date('Y-m-d 23:59:59'); @@ -153,6 +161,21 @@ class InvoiceModel extends Model return $this->db->table('partner_agent')->get()->getResultArray(); } + public function posList(array $params = []) + { + $builder = $this->db->table('partner_pos') + ->select('partner_pos.*, partner_staff.name AS manager_name') + ->join('partner_staff', 'partner_staff.id = partner_pos.manager_id', 'left') + ->orderBy('partner_pos.id', 'DESC'); + + if (isset($params['is_active'])) { + $builder->where('partner_pos.is_active', $params['is_active']); + } + + return $builder->get()->getResultArray(); + } + + public function utrSummary($invoice_id) { $data = $this->select(" @@ -194,7 +217,7 @@ class InvoiceModel extends Model } - public function payoutList($flag, $agentId = null, $invoiceId = null) + public function payoutList($flag, $posId = null, $invoiceId = null) { $builder = $this->db->table('policy_transaction pt') ->select(' @@ -210,13 +233,15 @@ class InvoiceModel extends Model pii.commission_amount as paid_amount, pi.payout_status, pp.id as partner_policy_id, - pp.policy_transaction_id + pp.policy_transaction_id, + pt.pos_id as posId ') ->join('partner_invoice_items pii','pii.policy_no = pt.policy_no','left') ->join('partner_invoice pi','pi.id = pii.invoice_id','left') ->join('partner_policy pp','pt.policy_no = pp.policy_number AND pt.agent_id = pp.agent_id AND pt.id = pp.policy_transaction_id') ->where('pt.is_active',1) - ->where('pt.agent_id IS NOT NULL'); + ->where('pt.pos_id IS NOT NULL'); + // ->where('pt.agent_id IS NOT NULL'); if ($flag == 1) { // Add mode // EXCLUDE all policies that exist in partner_invoice_items @@ -230,16 +255,22 @@ class InvoiceModel extends Model if ($invoiceId) { $builder->where('pi.id', $invoiceId); // only policies of this invoice } - if ($agentId) { - $builder->where('pt.agent_id', $agentId); + // if ($agentId) { + // $builder->where('pt.agent_id', $agentId); + // } + if ($posId) { + $builder->where('pt.pos_id', $posId); } } if ($flag == 3) { // Extra policies // Policies not assigned to any invoice $builder->where('pii.id IS NULL', null, false); - if ($agentId) { - $builder->where('pt.agent_id', $agentId); + // if ($agentId) { + // $builder->where('pt.agent_id', $agentId); + // } + if ($posId) { + $builder->where('pt.pos_id', $posId); } } diff --git a/app/Views/invoice_policy_mapping.php b/app/Views/invoice_policy_mapping.php index 3491db49..c103ec1d 100644 --- a/app/Views/invoice_policy_mapping.php +++ b/app/Views/invoice_policy_mapping.php @@ -98,7 +98,7 @@ table.dataTable tbody td { padding: 4px 4px !important; }
    -
    + +
    + + +
    @@ -481,17 +498,20 @@ table.dataTable tbody td { padding: 4px 4px !important; } } - // ---- Filter policies by agent/date ---- + // ---- Filter policies by agent/POS/date ---- function filterPolicies() { const fromDate = getEl('fromDate')?.value || ''; const toDate = getEl('toDate')?.value || ''; - const agentId = getEl('agentSelect')?.value || ''; + // const agentId = getEl('agentSelect')?.value || ''; + const posId = getEl('posSelect')?.value || ''; const policyTillDate = getEl('policyTillDate')?.value || ''; - if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + // if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + if (!posId || posId === '0') return toastr.warning('Please select an POS', 'Required'); filteredPolicies = window.allPolicies.filter(p => { - if (String(p.agentId) !== String(agentId)) return false; + // if (String(p.agentId) !== String(agentId)) return false; + // if (String(p.posId) !== String(posId)) return false; if (policyTillDate && p.date_db > policyTillDate) return false; if (fromDate && p.date_db < fromDate) return false; if (toDate && p.date_db > toDate) return false; @@ -503,7 +523,9 @@ table.dataTable tbody td { padding: 4px 4px !important; } // ---- Load policies for selected agent ---- function loadPolicies() { - const agentId = getEl('agentSelect')?.value || ''; + // const agentId = getEl('agentSelect')?.value || ''; + const posId = getEl('posSelect')?.value || ''; + console.log('-->',posId); const policyTillDate = getEl('policyTillDate')?.value || ''; const list = getEl('policyListBody'); if (!list) return; @@ -518,16 +540,30 @@ table.dataTable tbody td { padding: 4px 4px !important; } list.innerHTML = ''; - if (!agentId || agentId === '0') { - list.innerHTML = `Please select an agent`; + // if (!agentId || agentId === '0') { + // list.innerHTML = `Please select an agent`; + // updateSummary(); + // reloadDataTable(); + // return; + // } + + // Filter policies for the selected agent + // filteredPolicies = window.allPolicies.filter(p => { + // if (String(p.agentId) !== String(agentId)) return false; + // if (policyTillDate && p.date_db > policyTillDate) return false; + // return true; + // }); + + if (!posId || posId === '0') { + list.innerHTML = `Please select a POS`; updateSummary(); reloadDataTable(); return; } - // Filter policies for the selected agent + // Filter policies for the selected POS filteredPolicies = window.allPolicies.filter(p => { - if (String(p.agentId) !== String(agentId)) return false; + if (String(p.posId) !== String(posId)) return false; if (policyTillDate && p.date_db > policyTillDate) return false; return true; }); @@ -652,8 +688,11 @@ table.dataTable tbody td { padding: 4px 4px !important; } // ---- Show More Policies ---- function showMorePolicies() { - const agentId = getEl('agentSelect')?.value || ''; - if (!agentId) return toastr.warning('Please select an agent', 'Required'); + // const agentId = getEl('agentSelect')?.value || ''; + // if (!agentId) return toastr.warning('Please select an agent', 'Required'); + + const posId = getEl('posSelect')?.value || ''; + if (!posId) return toastr.warning('Please select an POS', 'Required'); if (!window.extraPolicies || window.extraPolicies.length === 0) { return toastr.info('No more policies available.', 'Information'); @@ -664,11 +703,13 @@ table.dataTable tbody td { padding: 4px 4px !important; } // Filter extraPolicies: same agent + not already in filteredPolicies const newPolicies = window.extraPolicies.filter(p => { - return String(p.agentId) === String(agentId) && !existingPolicyIds.has(p.id); + // return String(p.agentId) === String(agentId) && !existingPolicyIds.has(p.id); + return String(p.posId) === String(posId) && !existingPolicyIds.has(p.id); }); if (newPolicies.length === 0) { - toastr.info('No more policies available for this agent.', 'Information'); + // toastr.info('No more policies available for this agent.', 'Information'); + toastr.info('No more policies available for this POS.', 'Information'); return; } @@ -690,13 +731,15 @@ table.dataTable tbody td { padding: 4px 4px !important; } // ---- Save invoice ---- function saveInvoice() { - const agentId = getEl('agentSelect')?.value || ''; + // const agentId = getEl('agentSelect')?.value || ''; + const posId = getEl('posSelect')?.value || ''; const invoiceNo = getEl('invoiceNo')?.value || ''; const invoiceDate = getEl('invoiceDate')?.value || ''; const policyTillDate = getEl('policyTillDate')?.value || ''; const invoiceID = getEl('invoiceID')?.value || ''; - if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + // if (!agentId || agentId === '0') return toastr.warning('Please select an agent', 'Required'); + if (!posId || posId === '0') return toastr.warning('Please select an pos', 'Required'); if (!invoiceDate) return toastr.warning('Please select invoice date', 'Required'); if (selectedPolicies.size === 0) return toastr.warning('Please select at least one policy', 'Required'); @@ -728,10 +771,11 @@ table.dataTable tbody td { padding: 4px 4px !important; } const invoiceData = { invoice_id: invoiceID, invoice_no: invoiceNo, - agent_id: agentId, + // agent_id: agentId, invoice_date: invoiceDate, invoice_amount: totalAmount, - policies: policies + policies: policies, + pos_id: posId }; // console.log(invoiceData);return true; @@ -774,7 +818,8 @@ table.dataTable tbody td { padding: 4px 4px !important; } const invoiceDateEl = getEl('invoiceDate'); const policyTillDateEl = getEl('policyTillDate'); - const agentSelectEl = getEl('agentSelect'); + // const agentSelectEl = getEl('agentSelect'); + const posSelectEl = getEl('posSelect'); // Set max date (today) if (invoiceDateEl) invoiceDateEl.max = today; @@ -783,20 +828,25 @@ table.dataTable tbody td { padding: 4px 4px !important; } if (invoiceType == 'add') { // -------- ADD MODE -------- - if (agentSelectEl) agentSelectEl.value = ''; + // if (agentSelectEl) agentSelectEl.value = ''; + if (posSelectEl) posSelectEl.value = ''; if (invoiceDateEl) invoiceDateEl.required = true; if (policyTillDateEl) policyTillDateEl.required = true; - if (agentSelectEl) agentSelectEl.required = true; + // if (agentSelectEl) agentSelectEl.required = true; + if (posSelectEl) posSelectEl.required = true; // Enable Select2 - $('#agentSelect').prop('disabled', false).select2(); + // $('#agentSelect').prop('disabled', false).select2(); + $('#posSelect').prop('disabled', false).select2(); } else { // -------- EDIT,ADJUSTMENT MODE -------- - if (agentSelectEl) agentSelectEl.readOnly = true; + // if (agentSelectEl) agentSelectEl.readOnly = true; + if (posSelectEl) posSelectEl.readOnly = true; // Disable Select2 (readonly) - $('#agentSelect').prop('disabled', true); + // $('#agentSelect').prop('disabled', true); + $('#posSelect').prop('disabled', true); // Remove red star (*) from label const agentLabel = document.querySelector('label[for="agents"] .text-danger'); @@ -810,9 +860,16 @@ table.dataTable tbody td { padding: 4px 4px !important; } if (getEl('policyTillDate')) getEl('policyTillDate').valueAsDate = new Date(); } - const agentEl = getEl('agentSelect'); - if (agentEl) { - agentEl.addEventListener('change', () => { + // const agentEl = getEl('agentSelect'); + // if (agentEl) { + // agentEl.addEventListener('change', () => { + // selectedPolicies.clear(); + // loadPolicies(); + // }); + // } + const posEl = getEl('posSelect'); + if (posEl) { + posEl.addEventListener('change', () => { selectedPolicies.clear(); loadPolicies(); }); @@ -826,10 +883,12 @@ table.dataTable tbody td { padding: 4px 4px !important; } if (policyTillDateEl) policyTillDateEl.addEventListener('change', loadPolicies); - if (agentEl && agentEl.value && agentEl.value !== '0') loadPolicies(); + // if (agentEl && agentEl.value && agentEl.value !== '0') loadPolicies(); + if (posEl && posEl.value && posEl.value !== '0') loadPolicies(); else { const body = getEl('policyListBody'); - if (body) body.innerHTML = `Please select an agent`; + // if (body) body.innerHTML = `Please select an agent`; + if (body) body.innerHTML = `Please select a POS`; reloadDataTable(); } }); @@ -843,6 +902,7 @@ document.addEventListener('DOMContentLoaded', function () { // Determine if we should freeze edits const shouldFreeze = + (freeze > 0 && type === 'view') || (freeze > 0 && type === 'edit') || (payout_status === 2 && (type === 'adjustment' || type === 'edit')); diff --git a/app/Views/invoice_template_2.php b/app/Views/invoice_template_2.php index 93946a38..8713f2ef 100644 --- a/app/Views/invoice_template_2.php +++ b/app/Views/invoice_template_2.php @@ -95,6 +95,7 @@
    + + + + + + + + $pos_c, $pos_s - $pos_p."; + } elseif ($pos_a && $pos_c && $pos_s) { $address = "$pos_a,
    $pos_c, $pos_s."; + } elseif ($pos_a && $pos_c && $pos_p) { $address = "$pos_a,
    $pos_c - $pos_p."; + } elseif ($pos_a && $pos_s && $pos_p) { $address = "$pos_a,
    $pos_s - $pos_p."; + } elseif ($pos_a && $pos_c) { $address = "$pos_a,
    $pos_c."; + } elseif ($pos_a && $pos_s) { $address = "$pos_a,
    $pos_s."; + } elseif ($pos_a && $pos_p) { $address = "$pos_a - $pos_p."; + } elseif ($pos_c && $pos_s && $pos_p) { $address = "$pos_c, $pos_s - $pos_p."; + } elseif ($pos_c && $pos_s) { $address = "$pos_c, $pos_s."; + } elseif ($pos_c && $pos_p) { $address = "$pos_c - $pos_p."; + } elseif ($pos_s && $pos_p) { $address = "$pos_s - $pos_p."; + } elseif ($pos_a) { $address = "$pos_a
    "; + } elseif ($pos_c) { $address = "$pos_c."; + } elseif ($pos_s) { $address = "$pos_s."; + } elseif ($pos_p) { $address = "$pos_p."; + } else { $address = '-';} + ?> + + + + @@ -144,11 +180,18 @@ Amount Payable in words : -
    + +
    + BANK ACCOUNT DETAILS
    + ACCOUNT HOLDER NAME :
    + ACCOUNT NUMBER :
    + IFSC CODE :
    + Bank NAME :
    diff --git a/app/Views/payout_list.php b/app/Views/payout_list.php index e81a2897..ab2bca29 100644 --- a/app/Views/payout_list.php +++ b/app/Views/payout_list.php @@ -209,7 +209,8 @@
    - + + @@ -224,15 +225,17 @@ - + + diff --git a/app/Views/payout_list_handler.php b/app/Views/payout_list_handler.php index 329645bd..270ced48 100644 --- a/app/Views/payout_list_handler.php +++ b/app/Views/payout_list_handler.php @@ -14,7 +14,7 @@
    -
    + +
    + +
    @@ -72,7 +83,8 @@ let utrHasBeenChanged = false; $(document).ready(function(){ - $('#agent_id').select2(); + // $('#agent_id').select2(); because dropdown hided + $('#pos_id').select2(); $('#startDate').val(''); $('#endDate').val(''); $('#reportrange').val(''); @@ -121,7 +133,8 @@ $('#clear-filters').on('click', function() { // Reset all select dropdowns to the first option - $('#agent_id').val('').change(); + // $('#agent_id').val('').change(); because dropdown hided + $('#pos_id').val('').change(); $('#status_id').val('').change(); // Clear the date range inputs @@ -135,14 +148,15 @@ function fetchPayoutList(internalCall = false) { - let agent_id = $('#agent_id').val(); + // let agent_id = $('#agent_id').val(); because dropdown hided + let pos_id = $('#pos_id').val(); let status_id = $('#status_id').val(); let start_date = $('#startDate').val(); let end_date = $('#endDate').val(); - console.log({agent_id, status_id, start_date, end_date, internalCall, utrHasBeenChanged}); + console.log({pos_id, status_id, start_date, end_date, internalCall, utrHasBeenChanged}); if(!internalCall){ - if (!agent_id && !status_id && !start_date && !end_date) { + if (!pos_id && !status_id && !start_date && !end_date) { toastr.warning("Please select any one filter!", "WARNING"); return false; } @@ -152,7 +166,8 @@ // Data to send in the AJAX request let requestData = { - agent_id: agent_id, + // agent_id: agent_id, because dropdown hided + pos_id: pos_id, status_id: status_id, start_date: start_date, end_date: end_date, From 454428733f83cbc188040c59da6c27b01d4b00b8 Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Thu, 18 Dec 2025 12:51:47 +0530 Subject: [PATCH 14/27] FIX_IN CRM APP While Partner creating new "Nhance Branch" fields implemented (Odoo 2540) --- app/Models/PartnerStaffModel.php | 2 +- app/Views/UserList.php | 69 +++++++++++++++++++++++--------- app/Views/nhance_branch_list.php | 1 + 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/app/Models/PartnerStaffModel.php b/app/Models/PartnerStaffModel.php index f79f06ad..8c5ca862 100755 --- a/app/Models/PartnerStaffModel.php +++ b/app/Models/PartnerStaffModel.php @@ -16,7 +16,7 @@ class PartnerStaffModel extends Model protected $useSoftDeletes = false; // allowed fields for insert/update - protected $allowedFields = ['name','email','mobile','emp_id','role_id','email_otp','is_active','created_by','updated_by','manager_id','retention_rate']; + protected $allowedFields = ['name','email','mobile','emp_id','role_id','email_otp','is_active','created_by','updated_by','manager_id','retention_rate','nhance_branch_id']; // automatic timestamps protected $useTimestamps = true; diff --git a/app/Views/UserList.php b/app/Views/UserList.php index 1e3e2766..64b7cc3b 100755 --- a/app/Views/UserList.php +++ b/app/Views/UserList.php @@ -609,7 +609,7 @@ table.dataTable tbody td {
    - +
    @@ -630,10 +630,20 @@ table.dataTable tbody td {
    -
    + +
    + + +
    +
    @@ -880,12 +890,18 @@ table.dataTable tbody td { $(document).ready(function () { $('#nhance_branch_id').select2(); + $('#partner_nhance_branch_id').select2(); + $('#rm_id').select2(); $('#nhance_branch_id') .val(null) // ✅ MUST be null .trigger('change.select2'); // ✅ correct trigger + $('#partner_nhance_branch_id') + .val(null) // ✅ MUST be null + .trigger('change.select2'); // ✅ correct trigger + var incentiveMonthPicker = flatpickr("#incentive_month", { dateFormat: "Y-m-d", // real value stored (hidden) @@ -1152,8 +1168,19 @@ table.dataTable tbody td { $('#partner_name').val(user.name); $('#email_addr').val(user.email); $('#mobile_no').val(user.mobile); - $('#locn').val(user.address); + // $('#locn').val(user.address); $('#retention_rate').val(user.retention_rate); + if (user.nhance_branch_id !== null && + user.nhance_branch_id !== "" && + user.nhance_branch_id !== 0) { + $('#partner_nhance_branch_id') + .val(user.nhance_branch_id) + .trigger('change.select2'); + } else { + $('#partner_nhance_branch_id') + .val(null) // ✅ MUST be null + .trigger('change.select2'); // ✅ correct trigger + } // $('#btnPartnerSubmit').html('Update'); $('.modal-title').html('Update Nhance Partner'); let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal')); @@ -1163,10 +1190,12 @@ table.dataTable tbody td { $('body').on('click', '.btnPartnerDelete', function () { var partner_role = $(this).attr('data-role'); var alertText = "You need to remove this user"; - if (partner_role == 2) { + if (partner_role == 3) { alertText = "You need to remove this Staff"; + } else if (partner_role == 2) { + alertText = "You need to remove this Handler"; } else if (partner_role == 1) { - alertText = "You need to remove this Manager and related agent and staff are also delete"; + alertText = "You need to remove this Manager and related Handler and Staff are also delete"; } Swal.fire({ @@ -1246,23 +1275,25 @@ table.dataTable tbody td { var name = document.getElementById('partner_name').value.trim(); var mobile = document.getElementById('mobile_no').value.trim(); var email = document.getElementById('email_addr').value.trim(); - var address = document.getElementById('locn').value.trim(); - + // var address = document.getElementById('locn').value.trim(); + var rate = document.getElementById('retention_rate').value.trim(); + var nb = document.getElementById('partner_nhance_branch_id').value.trim(); + // Validation checks - if (name === "" || mobile === "" || email === "") { - console.log(name); - console.log(mobile); - console.log(email); + if (name === "" || mobile === "" || email === "" || rate === "" || nb === "") { + // console.log(name); + // console.log(mobile); + // console.log(email); toastr.warning('Please fill all required fields.', 'Warning'); form.classList.add('was-validated'); return; } - if (address.length > 1500) { - toastr.error('Address cannot exceed 1500 characters', 'Warning'); - form.classList.add('was-validated'); - return; - } + // if (address.length > 1500) { + // toastr.error('Address cannot exceed 1500 characters', 'Warning'); + // form.classList.add('was-validated'); + // return; + // } var mobilePattern = /^[6-9]\d{9}$/; // must start with 6–9 and be 10 digits if (!mobilePattern.test(mobile)) { @@ -1857,7 +1888,9 @@ table.dataTable tbody td { $('#email_addr').val(''); $('#partner_id').val(''); $('#mobile_no').val(''); - $('#locn').val(''); + // $('#locn').val(''); + $('#retention_rate').val(''); + $('#partner_nhance_branch_id').val('0'); $('.modal-title').html('Add Nhance Partner'); $('#PartnerForm').attr('action', ''); let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal')); diff --git a/app/Views/nhance_branch_list.php b/app/Views/nhance_branch_list.php index 4c435257..d85b83ce 100644 --- a/app/Views/nhance_branch_list.php +++ b/app/Views/nhance_branch_list.php @@ -150,6 +150,7 @@ }) function openModal(){ + resetValues(); var myModal = new bootstrap.Modal(document.getElementById('con-close-modal')); myModal.show(); } From 206d6d28d388c3ac58f21a588b2421ccc99a632c Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Thu, 18 Dec 2025 13:08:59 +0530 Subject: [PATCH 15/27] FIX_user module nhance partner manager data only (filter) --- app/Controllers/UserController.php | 8 ++++---- app/Views/UserList.php | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/Controllers/UserController.php b/app/Controllers/UserController.php index 48f3c7a3..22451e89 100755 --- a/app/Controllers/UserController.php +++ b/app/Controllers/UserController.php @@ -585,11 +585,11 @@ class UserController extends AdminController try{ // Listing if ($method === 'get') { - $types = $this->partnerStaffModel->findAll(); - if (empty($types)) { - return $this->response->setJSON(['status' => 'error','message' => 'No Staff found'])->setStatusCode(404); + $manager = $this->partnerStaffModel->where('role_id',1)->findAll(); + if (empty($manager)) { + return $this->response->setJSON(['status' => 'error','message' => 'No Manager found'])->setStatusCode(404); } - return $this->response->setJSON(['status' => 'success','data' => $types])->setStatusCode(200); + return $this->response->setJSON(['status' => 'success','data' => $manager])->setStatusCode(200); } // add/update diff --git a/app/Views/UserList.php b/app/Views/UserList.php index 64b7cc3b..e1f0f127 100755 --- a/app/Views/UserList.php +++ b/app/Views/UserList.php @@ -489,9 +489,9 @@ table.dataTable tbody td {
    - + - + @@ -1182,7 +1182,7 @@ table.dataTable tbody td { .trigger('change.select2'); // ✅ correct trigger } // $('#btnPartnerSubmit').html('Update'); - $('.modal-title').html('Update Nhance Partner'); + $('.modal-title').html('Update Nhance Partner Manager'); let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal')); myModal.show(); // open modal }); @@ -1891,7 +1891,7 @@ table.dataTable tbody td { // $('#locn').val(''); $('#retention_rate').val(''); $('#partner_nhance_branch_id').val('0'); - $('.modal-title').html('Add Nhance Partner'); + $('.modal-title').html('Add Nhance Partner Manager'); $('#PartnerForm').attr('action', ''); let myModal = new bootstrap.Modal(document.getElementById('nhance-partner-modal')); myModal.show(); // open modal From 464b394231d31fbeafe051879e7e9667d96f67bf Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Thu, 18 Dec 2025 17:47:55 +0530 Subject: [PATCH 16/27] FIX_FAQ Module API AND WEB --- app/Config/Routes.php | 6 +- .../AppContentManagementController.php | 138 +++++++ app/Models/FAQModel.php | 56 +++ app/Views/faq_list.php | 355 ++++++++++++++++++ app/Views/layout/header.php | 3 + app/Views/nhance_branch_list.php | 3 +- app/Views/pos_list.php | 2 +- 7 files changed, 559 insertions(+), 4 deletions(-) create mode 100644 app/Models/FAQModel.php create mode 100644 app/Views/faq_list.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 166dccc2..22cb5f00 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -654,7 +654,8 @@ $routes->group("employeeRest", ["filter" => ['appSignature' , 'authJWT']], funct $routes->post("ticketSave", "ThzController::ticketSave"); }); - + //API FAQ + $routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ'); //claims $routes->post('initiateClaim',"EmployeeRestController::initiateClaim"); @@ -791,6 +792,9 @@ $routes->post('ticketAutoFetchDetails',"ThzController::ticketAutoFetchDetails"); $routes->match(['get','post','put'], 'ticketType', 'ThzController::ticketType'); $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); +// General FAQ +$routes->match(['get','post','delete'], 'FAQ', 'AppContentManagementController::FAQ'); + //for testing $routes->group('test', function($routes) { diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index da65a7b1..a85d1bd6 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -11,6 +11,7 @@ use CodeIgniter\API\ResponseTrait; use App\Models\AddImgModel; use App\Models\FEContentModel; use App\Models\ClientModel; +use App\Models\FAQModel; class AppContentManagementController extends AdminController { @@ -19,6 +20,7 @@ class AppContentManagementController extends AdminController protected $addImgModel; protected $feContentModel; protected $clientModel; + protected $faqModel; public function __construct() @@ -27,6 +29,7 @@ class AppContentManagementController extends AdminController $this->addImgModel = new AddImgModel(); $this->feContentModel = new FEContentModel(); $this->clientModel = new ClientModel(); + $this->faqModel = new FAQModel(); } //listing public function add_image_index() @@ -156,4 +159,139 @@ class AppContentManagementController extends AdminController echo view('layout/footer'); } + + // + // public function FAQ() + // { + + // $data['tab_name'] = "FAQ's"; + // $data['page_name'] = "FAQ's"; + // return $this->loadLayout('faq_list', $data); + + // $returnType = strtolower($this->request->getGet('return_type') ?? 'api'); + + // $data = $this->request->getGet(); + + // $faq_list = $this->faqModel->select('*')->where('is_active', 1)->orderBy('id', 'desc')->findAll(); + + // if ($returnType === 'api') { + // if (empty($faq_list)) { + // $this->myLogger->logme('error', 'empty tickets in ticket list: ' . json_encode($faq)); + // return $this->response->setJSON([ 'status' => 'error','message' => 'No Details found'])->setStatusCode(404); + // } + // } else { + // $data['tab_name'] = "FAQ's"; + // $data['page_name'] = "FAQ's"; + // return $this->loadLayout('faq_list', $data); + // } + + // return $this->response->setJSON([ + // 'status' => 'success', + // 'data' => [], + // ])->setStatusCode(200); + // } + + + + public function FAQ() + { + $method = strtolower($this->request->getMethod()); + $returnType = strtolower($this->request->getGet('return_type') ?? 'api'); + $ref = ['timestamp' => date('Y-m-d H:i:s')]; + + try { + // --- 1. POST: CREATE OR UPDATE --- + if ($method === 'post') { + $id = $this->request->getPost('faq_id'); + $data = array_filter($this->request->getPost(), fn($v) => $v !== '' && $v !== null); + + if (empty($id)) { + $status = $this->faqModel->insert($data); + $msg = "Created"; + } else { + $status = $this->faqModel->update($id, $data); + $msg = "Updated"; + } + + // if ($returnType === 'web') { + // return redirect()->back()->with($status ? 'success' : 'error', "FAQ $msg " . ($status ? 'successfully' : 'failed')); + // } + + // return $this->response->setJSON([ + // ])->setStatusCode($result ? 200 : 400); + return $this->response->setJSON([ + 'status' => $status ? 'success' : 'error', + 'message' => "FAQ $msg " . ($status ? 'successfully' : 'failed'), + 'code' => $status ? 200 : 400, + 'data' => $data, + 'ref' => $ref + ])->setStatusCode($status ? 200 : 400); + } + + // --- 2. GET: FETCH LIST OR SINGLE --- + elseif ($method === 'get') { + + $id = $this->request->getGet('faq_id'); + + if (!empty($id)) { + // $row = $this->faqModel->where('is_active', 1)->find($id); + $row = $this->faqModel->find($id); + $data['faq_list'] = $row ? [$row] : []; + } else { + // $data['faq_list'] = $this->faqModel->where('is_active', 1)->orderBy('id', 'desc')->findAll(); + $data['faq_list'] = $this->faqModel->orderBy('id', 'desc')->findAll(); + } + + if ($returnType === 'web') { + $data['tab_name'] = "FAQ's"; + $data['page_name'] = "FAQ's"; + // print_r($data);die; + return $this->loadLayout('faq_list', $data); + } + + // API Response Logic + if (empty($data['faq_list'])) { + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? false : 'error', + 'message' => 'No data found', + 'code' => 404, + 'data' => [], + 'ref' => $ref + ])->setStatusCode(200); // Using 200 with error status is common for mobile apps to prevent crashes + } + + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? true : 'success', + 'message' => 'Data retrieved', + 'code' => 200, + 'data' => $data, + 'ref' => $ref + ])->setStatusCode(200); + } + + // --- 3. DELETE: SOFT DELETE --- + elseif ($method === 'delete') { + $id = $this->request->getGet('faq_id'); + $status = (!empty($id)) ? $this->faqModel->update($id, ['is_active' => 0]) : false; + + return $this->response->setJSON([ + 'status' => $status ? ($returnType === 'web' ? true : 'success') : ($returnType === 'web' ? false : 'error'), + 'message' => $status ? 'Data removed successfully' : 'Failed to remove or ID missing', + 'code' => $status ? 200 : 400, + 'data' => [], + 'ref' => $ref + ])->setStatusCode( 200 ); + } + + } catch (\Throwable $e) { + $msg = $e->getMessage(); + return $this->response->setJSON([ + 'status' => $returnType === 'web' ? false : 'error', + 'code' => 500, + 'message' => $msg, + 'ref' => ['file' => $e->getFile(), 'line' => $e->getLine()] + ])->setStatusCode(500); + } + } + } \ No newline at end of file diff --git a/app/Models/FAQModel.php b/app/Models/FAQModel.php new file mode 100644 index 00000000..d7c75131 --- /dev/null +++ b/app/Models/FAQModel.php @@ -0,0 +1,56 @@ + +.dataTables_filter { + position: absolute; +} +.dataTables_length label {height: 21px !important;} + + + +
    +
    +
    +
    +
    Bill To: Invoice No UTR Total Amount Balance StatusAgentPOS Action
    + + + + + + + + + + + + + $row) { ?> + + + + + + + + + + + + + + +
    S.No.CategoryQuestionAnswerStatusAction
    50) + ? htmlspecialchars(substr($category, 0, 50)) . "..." + : htmlspecialchars($category); + ?> 50) + ? htmlspecialchars(substr($question, 0, 50)) . "..." + : htmlspecialchars($question); + ?> 50) + ? htmlspecialchars(substr($answer, 0, 50)) . "..." + : htmlspecialchars($answer); + ?> + + + + + +
    +
    +
    +
    + + + + + + + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 96061707..62a6f880 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -2098,6 +2098,9 @@
  • Front-end Content
  • +
  • + FAQ's +
  • diff --git a/app/Views/nhance_branch_list.php b/app/Views/nhance_branch_list.php index d85b83ce..29700edd 100644 --- a/app/Views/nhance_branch_list.php +++ b/app/Views/nhance_branch_list.php @@ -107,7 +107,7 @@ text: 'Add', className: 'btn app-btn-primary mr-2', action: function(e, dt, node, config) { - openModal() + resetValues();openModal(); } }, { @@ -150,7 +150,6 @@ }) function openModal(){ - resetValues(); var myModal = new bootstrap.Modal(document.getElementById('con-close-modal')); myModal.show(); } diff --git a/app/Views/pos_list.php b/app/Views/pos_list.php index f2de943b..3ca34dff 100644 --- a/app/Views/pos_list.php +++ b/app/Views/pos_list.php @@ -226,7 +226,7 @@ text: 'Add', className: 'btn app-btn-primary mr-2', action: function(e, dt, node, config) { - openModal() + resetValues();openModal(); } }, { From f3af0acc5ef657c8fd37dd29af055718c34a6446 Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Thu, 18 Dec 2025 17:53:41 +0530 Subject: [PATCH 17/27] FIX_Mistake --- app/Models/FAQModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/FAQModel.php b/app/Models/FAQModel.php index d7c75131..aa7ca44f 100644 --- a/app/Models/FAQModel.php +++ b/app/Models/FAQModel.php @@ -7,7 +7,7 @@ use CodeIgniter\Model; class FAQModel extends Model { - protected $table = 'partner_faq'; + protected $table = 'faq'; protected $primaryKey = 'id'; protected $allowedFields = [ 'id', From b0441597b10eef50002ab15421e29905fd277794 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 18 Dec 2025 18:03:43 +0530 Subject: [PATCH 18/27] CHANGE_BDS_CHANGE_2 --- app/Controllers/ClientController.php | 42 +- .../PolicyTransactionController.php | 51 ++- app/Views/drive_file_upload.php | 6 +- .../policy_transaction_endorsement_form.php | 59 ++- .../policy_transaction_inception_form.php | 281 +++++++++--- .../policy_transaction_inception_list.php | 68 ++- app/Views/pt_form_file_upload_tab.php | 2 +- app/Views/variance_report_list.php | 430 +++++++++--------- app/Views/vehicle_docs.php | 6 +- 9 files changed, 622 insertions(+), 323 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d7902e54..dea5763b 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -2398,13 +2398,27 @@ class ClientController extends AdminController - public function uploadVehicleFile() + public function uploadVehicleFile($params = null) { $this->myLogger->logme('error', 'uploadVehicleFile function called'); - $data = $this->request->getPost(); - $files = $this->request->getFiles(); - // $data['client_id'] = 12; - // $data['vehicle_id'] = 1; + + $client_id = null; + $vehicle_id = null; + $files = null; + $docs_name = null; + + if(empty($params) && $this->request){ + $data = $this->request->getPost(); + $files = $this->request->getFiles(); + $client_id = $data['client_id'] ?? null; + $vehicle_id = $data['vehicle_id'] ?? null; + $docs_name = $data['other_docs_name'] ?? null; + }else { + $client_id = $params['client_id'] ?? null; + $vehicle_id = $params['vehicle_id'] ?? null; + $docs_name = $params['other_docs_name'] ?? null; + $files = $params['file_data'] ?? null; + } // upload path $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; @@ -2412,20 +2426,21 @@ class ClientController extends AdminController $insertedDocs = []; // Check document names and files - if (isset($data['other_docs_name']) && isset($files['file_name'])) { - foreach ($data['other_docs_name'] as $key => $docName) { + if (!empty($docs_name) && !empty($files) && !empty($client_id) && !empty($vehicle_id)) { + + foreach ($docs_name as $key => $docName) { // Get the corresponding file for this document name $file = $files['file_name'][$key]; if (!empty($docName) && $file->isValid() && !$file->hasMoved()) { // Upload the file - $uploadedFileName = file_Upload($file, $uploadFilePath); + $uploadedFileName = file_Upload_for_lead($file, $uploadFilePath); if ($uploadedFileName) { // Prepare data for each document upload $docData = [ - 'client_id' => $data['client_id'], - 'vehicle_id' => $data['vehicle_id'], + 'client_id' => $client_id, + 'vehicle_id' => $vehicle_id, 'other_docs_name' => $docName, 'file_name' => $uploadedFileName, 'created_by' => get_session_userid(), @@ -2441,16 +2456,21 @@ class ClientController extends AdminController } } + if(!empty($params) && !$this->request){ + return true; + } + if (!empty($insertedDocs)) { // Fetch all documents for the client $vehicleDocs = $this->clientKYCDocsModel ->where('client_id', $data['client_id']) ->where('vehicle_id', $data['vehicle_id']) ->findAll(); - return $this->respond(['status' => true, 'code' => 200, 'vehicle_docs' => $vehicleDocs, 'inserted_docs' => $insertedDocs], 200); + return $this->respond(['status' => true, 'code' => 200, 'vehicle_docs' => $vehicleDocs, 'inserted_docs' => $insertedDocs, 'message' => 'File uploaded successfully'], 200); } else { return $this->respond(['status' => false, 'code' => 400, 'message' => 'No documents uploaded or inserted'], 200); } + } else { return $this->respond(['status' => false, 'code' => 400, 'message' => 'Invalid data submission'], 200); } diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 64425b2e..a6e465d3 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -934,6 +934,12 @@ { $data = $this->request->getPost(); + $file_data = $this->request->getFiles() ?? null; + $data['file_data'] = $file_data ?? null; + + $vehicle_file_data = $this->request->getFiles() ?? null; + $data['vehicle_file_data'] = $vehicle_file_data ?? null; + // print_r($data); die; if (empty($data['policy_issue_date'])) { @@ -1043,6 +1049,28 @@ } } + // policy file upload + if(isset($data['doc_name']) && isset($data['file_data']) && !empty($data['doc_name']) && !empty($data['file_data'])){ + $this->uploadFile($data['doc_name'], $data['file_data'], $insert); + } + + // policy file upload + if( + isset($data['other_docs_name']) && isset($data['vehicle_file_data']) && isset($data['client_id']) && isset($data['vehicle_id']) && + !empty($data['other_docs_name']) && !empty($data['vehicle_file_data']) && !empty($data['client_id']) && !empty($data['vehicle_id']) + ) + { + $vdd = [ + 'other_docs_name' => $data['other_docs_name'], + 'file_data' => $data['vehicle_file_data'], + 'client_id' => $data['client_id'], + 'vehicle_id' => $data['vehicle_id'], + ]; + $clientController = new ClientController(); + $clientController->uploadVehicleFile($vdd); + } + + $client_data = $this->clientModel->where('id', $data['client_id'])->first(); $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); @@ -2871,20 +2899,23 @@ //------------------------------------------------------------------------------------------------ //file upload function - public function uploadFile() + public function uploadFile($docs_name = null, $files = null, $pt_id = null) { $GoogleDriveController = new GoogleDriveController(); - $files = $this->request->getFiles(); - $doc_name = $this->request->getPost('doc_name[]'); - $pt_id = $this->request->getPost('pt_id'); - $client_policy_id = $this->request->getPost('client_policy_id'); - $data = $this->request->getPost(); + + + if(empty($docs_name) && empty($files) && empty($pt_id) && $this->request){ + $files = $this->request->getFiles(); + $docs_name = $this->request->getPost('doc_name'); + $pt_id = $this->request->getPost('pt_id'); + $client_policy_id = $this->request->getPost('client_policy_id'); + } $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; $uploadData = []; - foreach ($data['doc_name'] as $key => $docName) { + foreach ($docs_name as $key => $docName) { // Get the corresponding file for this document name $file = $files['file'][$key]; @@ -2892,7 +2923,7 @@ if (!empty($docName) && $file->isValid() && !$file->hasMoved()) { // Upload the file - $uploadedFileName = file_Upload($file, $uploadFilePath); + $uploadedFileName = file_Upload_for_lead($file, $uploadFilePath); if ($uploadedFileName) { // Prepare data for each document upload @@ -2917,6 +2948,10 @@ } } + if(!empty($docs_name) && !empty($files) && !empty($pt_id) && !$this->request){ + return true; + } + // print_r($uploadData); die; // $uploadData = uploadFilesToGoogleDrive($files['file'], $doc_name, $pt_id); diff --git a/app/Views/drive_file_upload.php b/app/Views/drive_file_upload.php index 96a4fc79..f557fdd9 100644 --- a/app/Views/drive_file_upload.php +++ b/app/Views/drive_file_upload.php @@ -99,12 +99,14 @@ $("#drive_file_upload_form").submit(function(event) { $('.loader-mask').delay(350).fadeOut('slow'); if(res.status == true){ - toastr.success(res.message, 'Success'); + toastr.success(res.message, 'SUCCESS'); appendFileTableBody(res.data.pt_files); }else{ - toastr.error(res.message, 'Error'); + toastr.warning(res.message, 'WARNING'); } + $('#drive_file_upload_form')[0].reset(); + }, error: function (xhr, status, error) { console.error(xhr.responseText); diff --git a/app/Views/policy_transaction_endorsement_form.php b/app/Views/policy_transaction_endorsement_form.php index 0f2d65b6..98f20c0b 100644 --- a/app/Views/policy_transaction_endorsement_form.php +++ b/app/Views/policy_transaction_endorsement_form.php @@ -2446,26 +2446,71 @@ // } // } + // if(allocg == "EB"){ + // $('.hideter').hide(); + // $('.hidetp').hide(); + // $('.hidecoter').hide() + // $('.hidecotp').hide() + // }else{ + + // $('.hidetp').show(); + // if(is_co_pay_yes == 1){ + // $('.hidecotp').show(); + // $('#table_tr_7').show(); + // $('#table_tr_35').show(); + // $('#table_tr_3').show(); + // }else{ + // $('.hidecotp').hide(); + // $('#table_tr_7').hide(); + // $('#table_tr_35').hide(); + // $('#table_tr_3').hide(); + // } + + // if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ + // $('.hideter').show(); + // if(is_co_pay_yes == 1){ + // $('.hidecoter').show(); + // }else{ + // $('.hidecoter').hide(); + // } + // }else{ + // $('.hideter').hide(); + // } + // } + if(allocg == "EB"){ + $('.hideter').hide(); $('.hidetp').hide(); $('.hidecoter').hide() $('.hidecotp').hide() - }else{ + + } else if(allocg == "Non-EB"){ + + $('.hidetp').hide(); + $('.hidecotp').hide(); + + $('.hideter').show(); + if(is_co_pay_yes == 1){ + $('.hidecoter').show(); + }else{ + $('.hidecoter').hide(); + } + + } else if(allocg == "Motor"){ + + $('.hideter').hide(); + $('.hidecoter').hide(); $('.hidetp').show(); if(is_co_pay_yes == 1){ $('.hidecotp').show(); - $('#table_tr_7').show(); - $('#table_tr_35').show(); - $('#table_tr_3').show(); }else{ $('.hidecotp').hide(); - $('#table_tr_7').hide(); - $('#table_tr_35').hide(); - $('#table_tr_3').hide(); } + } else{ + if(bap == 'Fire' || bap == 'Marine Cargo' || bap == 'Marine Hull'){ $('.hideter').show(); if(is_co_pay_yes == 1){ diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index 25e18758..10294b98 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -349,7 +349,7 @@
    -
    +
    @@ -457,15 +457,15 @@
    -
    +
    -
    @@ -659,6 +658,48 @@
    + + + + + +