From 5ca59ab1a7af045fd6987949bedd2a653690e1f2 Mon Sep 17 00:00:00 2001 From: velz Date: Mon, 15 Dec 2025 15:18:52 +0530 Subject: [PATCH 1/9] 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 2/9] 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 3/9] 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 4/9] 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 5/9] 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 6/9] 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 7/9] 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 8/9] 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 9/9] 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
    +
    +
    +
    +
    + + + + + +