From 3f0003224f16d94b064577dfce1dfd3ae85174e3 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 16 May 2025 10:47:15 +0530 Subject: [PATCH 1/8] CHANGE_CLIENT_FROM_LEADS : RV --- app/Controllers/LeadsController.php | 199 ++++++++++-------- .../PolicyTransactionController.php | 34 +-- app/Views/client_list.php | 53 ++++- 3 files changed, 170 insertions(+), 116 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 617add8f..fdeca47e 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -602,8 +602,8 @@ class LeadsController extends BaseController return $this->respond(['status' => false, 'message' => 'File could not be removed.'], 200); } } - //--------RFQ----------------------------------------------------------------------------------------------- + //--------RFQ----------------------------------------------------------------------------------------------- public function viewRFQ($id, $type = 1) { @@ -2538,64 +2538,103 @@ class LeadsController extends BaseController public function featchLeadDataAndInsertClient($lead_id) { - $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); + try { + $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); - if (!$data) { - return $this->respond(['status' => false, 'message' => 'Failed to create Client', 'data' => null], 200); + if (!$data) { + $this->myLogger->logme('featchLeadDataAndInsertClient', "Lead not found or inactive", ['lead_id' => $lead_id]); + return $this->respond(['status' => false, 'message' => 'Failed to create Client', 'data' => null], 200); + } + + $result = $this->createClientWithLeadData($data); + + if ($result) { + $policy_data = $this->clientPolicyModel->where('client_id', $result)->where('is_active', 1)->first(); + return $this->respond([ + 'status' => true, + 'message' => 'New Client created successfully', + 'client_id' => $result, + 'data' => $data, + 'client_policy_id' => $policy_data['id'] ?? null, + ], 200); + } + + $this->myLogger->logme('featchLeadDataAndInsertClient', "Client creation failed after processing", ['lead_id' => $lead_id]); + return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200); + } catch (\Throwable $e) { + $this->myLogger->logme('featchLeadDataAndInsertClient', $e->getMessage(), ['lead_id' => $lead_id, 'trace' => $e->getTraceAsString()]); + return $this->respond(['status' => false, 'message' => 'Internal server error', 'error' => $e->getMessage()], 500); } - - $result = $this->createClientWithLeadData($data); - - if ($result) { - - $policy_data = $this->clientPolicyModel->where('client_id', $result)->where('is_active', 1)->first(); - return $this->respond(['status' => true, 'message' => 'New Client created successfully', 'client_id' => $result, 'data' => $data, 'client_policy_id' => $policy_data['id']], 200); - } - - return $this->respond(['status' => false, 'message' => 'Failed to create client', 'data' => $data], 200); } public function createClientWithLeadData($data) { - $client_data = $this->prepareClientData($data); - $client_id = $this->clientModel->insert($client_data); + try { + $client_data = $this->prepareClientData($data); + $client_id = $this->clientModel->insert($client_data); - if ($client_id) { - $this->createClientBranchAndContactWithLeadData($data, $client_id); - $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + if ($client_id) { + $this->createClientBranchAndContactWithLeadData($data, $client_id); + $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + } + + return $client_id; + } catch (\Throwable $e) { + $this->myLogger->logme('createClientWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + return false; } + } - return $client_id; + public function createClientBranchAndContactWithLeadData($data, $client_id) + { + try { + $branch_data = $this->prepareClientBranchData($data, $client_id); + $branch_id = $this->clientBranchModel->insert($branch_data); + + if ($branch_id) { + $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + $contact_data = $this->prepareContactData($data, $branch_id); + $this->levelContactModel->insert($contact_data); + $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); + } + + return $branch_id; + } catch (\Throwable $e) { + $this->myLogger->logme('createClientBranchAndContactWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + return false; + } + } + + public function createClientPolicyWithLeadData($data, $client_id, $branch_id) + { + try { + $client_policy_data = $this->prepareClientPolicyData($data, $client_id, $branch_id); + $client_policy_id = $this->clientPolicyModel->insert($client_policy_data); + + if ($client_policy_id) { + $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); + $this->leadsModel->where('id', $data['id'])->set('is_policy_created', $client_id)->update(); + } + + return $client_policy_id; + } catch (\Throwable $e) { + $this->myLogger->logme('createClientPolicyWithLeadData', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + return false; + } } private function prepareClientData($data) { return [ - 'client_type' => $data['client_type'], - 'entity_type_id' => $data['entity_type_id'], - 'client_code' => $data['client_code'], - 'client_name' => $data['client_name'], - 'short_name' => $data['client_short_name'], - 'pan' => $data['pan'], + 'client_type' => $data['client_type'] ?? null, + 'entity_type_id' => $data['entity_type_id'] ?? null, + 'client_code' => $data['client_code'] ?? null, + 'client_name' => $data['client_name'] ?? null, + 'short_name' => $data['client_short_name'] ?? null, + 'pan' => $data['pan'] ?? null, ]; } - public function createClientBranchAndContactWithLeadData($data, $client_id) - { - $branch_data = $this->prepareClientBranchData($data, $client_id); - $branch_id = $this->clientBranchModel->insert($branch_data); - - if ($branch_id) { - $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); - $contact_data = $this->prepareContactData($data, $branch_id); - $this->levelContactModel->insert($contact_data); - - $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); - } - - return $branch_id; - } - private function prepareClientBranchData($data, $client_id) { $default_unit = trim(($data['client_short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-'); @@ -2620,19 +2659,6 @@ class LeadsController extends BaseController ]; } - public function createClientPolicyWithLeadData($data, $client_id, $branch_id) - { - $client_policy_data = $this->prepareClientPolicyData($data, $client_id, $branch_id); - $client_policy_id = $this->clientPolicyModel->insert($client_policy_data); - - - if ($client_policy_id) { - $this->leadsModel->where('id', $data['id'])->set('is_client_created', $client_id)->update(); - } - - return $client_policy_id; - } - private function prepareClientPolicyData($data, $client_id, $branch_id) { $proposel_data = json_decode($data['proposel_data'], true); @@ -2682,17 +2708,46 @@ class LeadsController extends BaseController private function preparePolicyTermsFromRFQ($data) { - $proposel_data = json_decode($data['proposel_data'], true); + try { + $proposel_data = json_decode($data['proposel_data'], true); + $QCRData = $this->RFQModel->where('is_active', 1)->where('lead_id', $data['id'])->first(); - $QCRData = $this->RFQModel->where('is_active', 1)->where('lead_id', $data['id'])->first(); + if (!$QCRData) { + throw new \Exception('RFQ Data not found'); + } - $JSON = json_decode($QCRData['json'], true); + $JSON = json_decode($QCRData['json'], true); + $converted_json = $this->transformProposelData($JSON, $proposel_data['proposel_name'], $proposel_data['insurer_name']); - $converted_json = $this->transformProposelData($JSON, $proposel_data['proposel_name'], $proposel_data['insurer_name']); - - return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']); + return $this->convertQCRJsonToPolicyTerms($converted_json, $data['policy_type_id'], $proposel_data['proposel_name'], $proposel_data['insurer_name']); + } catch (\Throwable $e) { + $this->myLogger->logme('preparePolicyTermsFromRFQ', $e->getMessage(), ['lead_id' => $data['id'], 'trace' => $e->getTraceAsString()]); + return null; + } } + public function featchClientPolicyFromLead($client_id, $branch_id, $lead_id) + { + $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); + + if (!$data) { + return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200); + } + + $result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); + // print_r($result); die; + + if ($result) { + + $policy_data = $this->clientPolicyModel->where('id', $result)->where('is_active', 1)->first(); + return $this->respond(['status' => true, 'message' => 'New Policy created successfully', 'client_policy_id' => $result, 'data' => $data, 'client_id' => $policy_data['client_id']], 200); + } + + return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200); + } + + // --------------------------------------------------------------------------------------------------------------- + //Function for convert the RFQ and QCR Json to Policy Terms Json public function convertQCRJsonToPolicyTerms($data, $policy_type, $proposel_name, $insurer_name) { @@ -2817,26 +2872,6 @@ class LeadsController extends BaseController } } - public function featchClientPolicyFromLead($client_id, $branch_id, $lead_id) - { - $data = $this->leadsModel->where('leads.id', $lead_id)->where('leads.is_active', 1)->first(); - - if (!$data) { - return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => null], 200); - } - - $result = $this->createClientPolicyWithLeadData($data, $client_id, $branch_id); - // print_r($result); die; - - if ($result) { - - $policy_data = $this->clientPolicyModel->where('id', $result)->where('is_active', 1)->first(); - return $this->respond(['status' => true, 'message' => 'New Policy created successfully', 'client_policy_id' => $result, 'data' => $data, 'client_id' => $policy_data['client_id']], 200); - } - - return $this->respond(['status' => false, 'message' => 'Failed to create policy', 'data' => $data], 200); - } - public function getPlacementJson(array $data): ?string { $proposel_data = json_decode($data['proposel_data'], true); @@ -2929,7 +2964,7 @@ class LeadsController extends BaseController } - function getLastFiveFinancialYears() + public function getLastFiveFinancialYears() { $currentYear = date('Y'); $currentMonth = date('m'); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index a4721770..7b35bc86 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -327,42 +327,37 @@ class PolicyTransactionController extends BaseController return $data; } - + private function insertInceptionPolicy($data) - { + { // print_r($data); die; $insert = $this->policyTransactionModel->insert($data); + if ($insert) { + $this->insertTransactionStatus($insert, $data, 1); $emp_data = $this->processInsertIndividualMemberInEmpTable($data); - if(isset($data['follow_insurer_id']) && !empty($data['follow_insurer_id'][0])){ + if (isset($data['follow_insurer_id']) && !empty($data['follow_insurer_id'][0])) { $pt_co_share_details = $this->insertOrUpdateCoShareDetails($data, $insert); if ($data['ct_type'] == 2) { - $client_policy_insert_data = $this->prepareClientPolicyInsertData($data); $client_policy_id = $this->clientPolicyModel->insert($client_policy_insert_data); $this->policyTransactionModel->update($insert, ['client_policy_id' => $client_policy_id]); $emp_policy_insert = $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id); - - if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) { - $this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']); - } } - - $data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $insert)->where('is_active', 1)->findAll(); + if ($data['client_type'] == 1 && $data['status'] == 'completed' && $data['is_cd_reduce_from_bds'] == 1) { + $this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']); + } } - - $client_data = $this->clientModel->where('id', $data['client_id'])->first(); - $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); - $data['entity_type_id'] = $client_data['entity_type_id']; return $this->respondSuccess($insert, "Policy transaction created successfully", $data); } + return $this->respondError("Failed to create policy transaction"); } @@ -397,19 +392,12 @@ class PolicyTransactionController extends BaseController } } - if ($data['status'] == 'completed' && $data['ct_type'] == 2) { - if($data['client_type'] == 1 && $data['is_cd_reduce_from_bds'] == 1){ - $this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']); - } + if($data['status'] == 'completed' && $data['client_type'] == 1 && $data['is_cd_reduce_from_bds'] == 1){ + $this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']); } - $data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $id)->where('is_active', 1)->findAll(); } - $client_data = $this->clientModel->where('id', $data['client_id'])->first(); - $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll(); - $data['entity_type_id'] = $client_data['entity_type_id']; - return $this->respondSuccess($id, "Policy transaction updated successfully", $data); } diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 592031dc..673c5eaf 100755 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -17,6 +17,10 @@ table.dataTable thead th { max-width: 98% !important; } +.btn-filter{ + margin-left: 20px !important; +} + .custom-dropdown-menu { display: none; position: absolute; @@ -53,12 +57,12 @@ table.dataTable thead th {

Client List

-
+
@@ -269,18 +273,40 @@ table.dataTable thead th { $(document).ready(function() { $('#tickets-table').DataTable({ - dom: "<'row'<'col-sm-0'f><'col-sm-7 text-right'B>>" + + dom: "<'row'<'col-sm-2'f><'col-sm-10 text-right'B>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-5'i><'col-sm-7'p>>", - buttons: [{ - extend: 'csv', - text: 'CSV', - title: 'ClientList', - className: 'my_class', - exportOptions: { - columns: ':not(:last-child)' + buttons: [ + { + extend: 'csv', + text: 'CSV', + title: 'ClientList', + className: 'my_class', + exportOptions: { + columns: ':not(:last-child)' + }, + }, + { + text: 'Add From Lead', + className: 'btn-filter', // custom class + action: function(e, dt, node, config) { + showModal(); + } }, - }], + { + text: 'Add', + className: 'btn-filter', // custom class + action: function(e, dt, node, config) { + addClient(); + } + } + ], + + initComplete: function() { + $('.btn-filter') + .removeClass('btn-secondary') + .addClass('btn btn-primary'); + }, language: { search: "_INPUT_", searchPlaceholder: "Search..." @@ -440,4 +466,9 @@ function featchClient(){ }); } +function addClient(){ + let url = ""; + window.location.href = url; +} + \ No newline at end of file From 9b63c61b0a1edea2a5e8e5be4bb1116ed3fa1bfc Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Fri, 16 May 2025 14:06:55 +0530 Subject: [PATCH 2/8] FEAT_ADD_CLIENT_ROLLOVER --- app/Controllers/ClientController.php | 7 +- app/Views/leads_form.php | 111 +++++++- app/Views/leads_form_handler.php | 90 ++++++ app/Views/leads_non_eb.php | 85 +++++- app/Views/newClientModal.php | 218 +++++++++++++++ .../policy_transaction_inception_form.php | 256 +++++------------- 6 files changed, 569 insertions(+), 198 deletions(-) create mode 100644 app/Views/newClientModal.php diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 9bf373ce..9d96e72b 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -3839,13 +3839,13 @@ class ClientController extends AdminController 'dob' => change_date_format($postData['dob'],'d/m/Y','Y-m-d'), 'aadhar' => $postData['aadhar'], 'phone' => $postData['phone'], - 'email' => $postData['email'], 'entity_type_id' => 7 ]); } else { $client_data['entity_type_id'] = $postData['entity_type_id']; } + // print_rr($client_data);die(); // Insert client data $client_insert = $this->clientModel->insert($client_data); @@ -3871,6 +3871,8 @@ class ClientController extends AdminController 'contact_type' => 'client', 'name' => $postData['name'], 'mobile' => $postData['mobile'], + 'email' => $postData['email'], + ]; $this->levelContactModel->insert($contact_data); } @@ -4050,7 +4052,8 @@ class ClientController extends AdminController ->join('clients', 'client_branch.client_id = clients.id') ->where(['client_branch.id' => $id, 'client_branch.is_active' => 1]) ->first(); - $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type' => 'client', 'is_active' => 1])->orderBy('id','asc')->first(); + $branch_contact_data = $this->levelContactModel->where(['ref_id' => $id, 'contact_type' => 'client', 'is_active' => 1])->findAll(); + // print_rr($branch_contact_data);die(); return $this->respond(['status' => true, 'code' => 200, 'data' => $branch_data, 'contact' => $branch_contact_data], 200); } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200); diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index 25044797..23209757 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -149,7 +149,7 @@ @@ -207,6 +207,14 @@ placeholder="Enter Branch Code" required> +
+ + + +
+
+ + \ No newline at end of file diff --git a/app/Views/policy_transaction_inception_form.php b/app/Views/policy_transaction_inception_form.php index a8d31703..3621bd08 100644 --- a/app/Views/policy_transaction_inception_form.php +++ b/app/Views/policy_transaction_inception_form.php @@ -795,115 +795,7 @@ - - + + + + From 65b405d3e4f5d939749140baafe94facf44b665b Mon Sep 17 00:00:00 2001 From: Srinivas-Saravanan Date: Sat, 17 May 2025 12:33:20 +0530 Subject: [PATCH 8/8] FIX_ADD_CLIENT --- app/Controllers/LeadsController.php | 9 ++++- app/Views/leads_form_handler.php | 28 +++++++------- app/Views/newClientModal.php | 58 ++++++++++++++++++++++++++--- 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 944ab17e..77a6ba81 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -681,7 +681,9 @@ class LeadsController extends BaseController if ($lead_data['lead_type'] != 1) { $client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first(); - $data['policy_terms'] = $client_policy_data['policy_terms']; + if (isset($client_policy_data)) { + $data['policy_terms'] = $client_policy_data['policy_terms']; + } } $data['question_json'] = $lead_data['question_json']; @@ -740,7 +742,10 @@ class LeadsController extends BaseController if ($lead_data['lead_type'] != 1 && $data['rfq_count'] == 0) { $client_policy_data = $this->clientPolicyModel->where('is_active', 1)->where('id', $lead_data['source_policy_id'])->first(); - $data['rfq_data']['json'] = $client_policy_data['placement_json']; + if (isset($client_policy_data)) { + + $data['rfq_data']['json'] = $client_policy_data['placement_json']; + } } if (!empty($data['question_json'])) { diff --git a/app/Views/leads_form_handler.php b/app/Views/leads_form_handler.php index 023dc0d3..7d9a6006 100644 --- a/app/Views/leads_form_handler.php +++ b/app/Views/leads_form_handler.php @@ -338,24 +338,24 @@ if (isset($selected_lead_type)) { $('#salse_person_id').trigger('change'); } - function validateInput(input, table, field){ + // function validateInput(input, table, field){ - let value = $(input).val(); - let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim(); + // let value = $(input).val(); + // let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim(); - let message = "Value is duplicate!"; - if(label){ - message = label + " already exists!"; - } + // let message = "Value is duplicate!"; + // if(label){ + // message = label + " already exists!"; + // } - checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) { - if (isDuplicate) { - toastr.warning(message, 'WARNING'); - $(input).val('') - } - }); + // checkDuplicateTableFieldValue(table, field, value, function(isDuplicate) { + // if (isDuplicate) { + // toastr.warning(message, 'WARNING'); + // $(input).val('') + // } + // }); - } + // } // -------------------------------------------------------------------------------------------------------- diff --git a/app/Views/newClientModal.php b/app/Views/newClientModal.php index 9f75a734..c4285aac 100644 --- a/app/Views/newClientModal.php +++ b/app/Views/newClientModal.php @@ -22,7 +22,7 @@
- +
@@ -39,7 +39,7 @@
+ onkeypress="return onlyNumbers(event)" onchange="validateInputForClient(this, 'clients', 'phone')">
@@ -48,7 +48,7 @@
- +
@@ -96,7 +96,7 @@
-
@@ -113,8 +113,52 @@