From 393270f2a66f9896afe283b5867a5fffe32648bc Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 2 Aug 2025 13:03:11 +0530 Subject: [PATCH] CHANGE_CLIENT_INCEPTION_CRS_AND_LIVE_ISSUE_AND_OTHERS : RV --- app/Config/Routes.php | 2 + app/Controllers/ClientController.php | 688 +++++++++++++++- app/Controllers/EmployeeController.php | 5 +- app/Controllers/EmployeeServiceController.php | 16 +- app/Helpers/excel_import_export_helper.php | 8 +- app/Models/ClientModel.php | 1 + app/Models/EmployeePolicyModel.php | 4 +- app/Views/UserList.php | 748 +++++++++++++++--- app/Views/client_basic_info.php | 18 +- app/Views/client_list.php | 88 ++- app/Views/insurer_export_templete.php | 37 +- app/Views/leads_list.php | 8 +- 12 files changed, 1451 insertions(+), 172 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6e3e0e30..9b859b7d 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -87,6 +87,8 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->get('deposit/(:num)', 'ClientController::deposit/$1'); $routes->get('remove/(:num)', 'ClientController::removeClient/$1'); $routes->get("list/(:any)", "ClientController::editClientOnboarding/$1"); + $routes->post('wipe', 'ClientController::wipeDemoClient'); + // application/config/routes.php // Add a route for the view_Deposit method diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e639c97c..39a0285e 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -809,7 +809,12 @@ class ClientController extends AdminController $data['is_download_btn'] = 1; } + if(empty($data['parent_client_id'])){ + $data['parent_client_id'] = null; + } + $insert = $this->clientModel->insert($data); + if ($insert) { $client_data = $this->clientModel->where(['id' => $insert, 'is_active' => 1])->first(); return $this->respond(['status' => true, 'code' => 200, 'data' => $client_data], 200); @@ -838,6 +843,9 @@ class ClientController extends AdminController $data['is_download_btn'] = 1; } + if(empty($data['parent_client_id'])){ + $data['parent_client_id'] = null; + } // print_r($data);die; $update = $this->clientModel->update($id, $data); @@ -3557,21 +3565,54 @@ class ClientController extends AdminController public function get_cd_ac($client_id, $insurer_id, $insurer_branch_id) { + // Get client data + $client_data = $this->clientModel + ->where('is_active', 1) + ->where('id', $client_id) + ->first(); - $cd_data = $this->CDMasterModel + $cd_data = []; + + // If client has a parent, fetch parent client CD data + if (!empty($client_data['parent_client_id'])) { + $parent_cd_data = $this->CDMasterModel + ->where('client_id', $client_data['parent_client_id']) + ->where('insurer_id', $insurer_id) + ->where('insurer_branch_id', $insurer_branch_id) + ->where('is_active', 1) + ->findAll(); + + $cd_data = array_merge($cd_data, $parent_cd_data); + } + + // Fetch current client CD data + $client_cd_data = $this->CDMasterModel ->where('client_id', $client_id) ->where('insurer_id', $insurer_id) ->where('insurer_branch_id', $insurer_branch_id) ->where('is_active', 1) ->findAll(); - if ($cd_data) { - return $this->respond(['status' => true, 'code' => 200, 'data' => $cd_data], 200); + $cd_data = array_merge($cd_data, $client_cd_data); + + if (!empty($cd_data)) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'data' => $cd_data + ], 200); } else { - return $this->respond(['status' => false, 'code' => 404, 'insurer_id' => $insurer_id, 'client_id' => $client_id], 200); + return $this->respond([ + 'status' => false, + 'code' => 404, + 'client_id' => $client_id, + 'insurer_id' => $insurer_id, + 'insurer_branch_id' => $insurer_branch_id + ], 200); } } + public function otherPolicyTermsFormSubmit() { @@ -4100,22 +4141,60 @@ class ClientController extends AdminController } - - public function getCDAccNoByClientAndInsurer($client, $insurer, $insurer_branch_id) + public function getCDAccNoByClientAndInsurer($client_id, $insurer_id, $insurer_branch_id) { - $cdmData = $this->CDMasterModel - ->where('client_id', $client) - ->where('insurer_id', $insurer) - ->where('insurer_branch_id', $insurer_branch_id) - ->where('is_active', 1) - ->findAll(); + // Get client data + $client_data = $this->clientModel + ->where('is_active', 1) + ->where('id', $client_id) + ->first(); - if ($cdmData) { - return $this->respond(['status' => true, 'data' => $cdmData], 200); + $cd_data = []; + + // If client has a parent, fetch parent client CD data + if (!empty($client_data['parent_client_id'])) { + $parent_cd_data = $this->CDMasterModel + ->where('client_id', $client_data['parent_client_id']) + ->where('insurer_id', $insurer_id) + ->where('insurer_branch_id', $insurer_branch_id) + ->where('is_active', 1) + ->findAll(); + + $cd_data = array_merge($cd_data, $parent_cd_data); + } + + // Fetch current client CD data + $client_cd_data = $this->CDMasterModel + ->where('client_id', $client_id) + ->where('insurer_id', $insurer_id) + ->where('insurer_branch_id', $insurer_branch_id) + ->where('is_active', 1) + ->findAll(); + + $cd_data = array_merge($cd_data, $client_cd_data); + + if (!empty($cd_data)) { + return $this->respond([ 'status' => true,'code' => 200, 'data' => $cd_data], 200); } else { - return $this->respond(['status' => false], 200); + return $this->respond(['status' => false,'code' => 404,'client_id' => $client_id,'insurer_id' => $insurer_id,'insurer_branch_id' => $insurer_branch_id ], 200); } } + + // public function getCDAccNoByClientAndInsurer($client, $insurer, $insurer_branch_id) + // { + // $cdmData = $this->CDMasterModel + // ->where('client_id', $client) + // ->where('insurer_id', $insurer) + // ->where('insurer_branch_id', $insurer_branch_id) + // ->where('is_active', 1) + // ->findAll(); + + // if ($cdmData) { + // return $this->respond(['status' => true, 'data' => $cdmData], 200); + // } else { + // return $this->respond(['status' => false], 200); + // } + // } public function createClientWithMinimalData() { @@ -6147,7 +6226,7 @@ class ClientController extends AdminController } } - // --------------------------------------------------------------------------------------------------- + // ---------------- HR ACCESS CONTROL ----------------------------------------------------------------------------------- public function viewHrAccessData() { @@ -6493,8 +6572,585 @@ class ClientController extends AdminController } } + // ------------------- DEMO CLIENT FUNCTION -------------------------------------------------------------------------------- + // public function wipeDemoClient() + // { + // // $this->myLogger->logme('error', "Wipe Demo Client function called"); + // $this->myLogger->logme('error', "Wipe Demo Client function called"); // Red text + // $this->myLogger->logme('error', "Wipe Demo client Payload : " . json_encode($this->request->getPost() ?? [])); + // $client_id = $this->request->getPost('client_id'); + + // if (empty($client_id)) { + // return $this->respond(['status' => false, 'message' => 'Client id required'], 404); + // } + + // // 1. Client Model + // $client_data = $this->clientModel->where('id', $client_id)->where('is_active', 1)->first(); + // $this->myLogger->logme('error', "Client data : " . json_encode($client_data ?? [])); + + // if (!empty($client_data)) { + // $is_deleted = $this->clientModel->where('id', $client_id)->delete(); + + // if ($is_deleted) { + // $this->myLogger->logme('error', "Client data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Client record does not exist."); + // } + // } else { + // return $this->respond(['status' => false, 'message' => 'Client not found'], 404); + // } + + // // 2. Client RM Model + // $client_rm_data = $this->clientRMModel->where('client_id', $client_id)->first(); + // $this->myLogger->logme('error', "Client Relationship Manager data : " . json_encode($client_rm_data ?? [])); + + // if (!empty($client_rm_data)) { + // $is_deleted = $this->clientRMModel->where('client_id', $client_id)->delete(); + + // if ($is_deleted) { + // $this->myLogger->logme('error', "Client Relationship Manager data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Client Relationship Manager record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Client Relationship Manager data not found."); + // } + + // // 3. Client KYC Docs Model + // $client_kyc_data = $this->clientKYCDocsModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Client KYC Docs data : " . json_encode($client_kyc_data ?? [])); + + // if (!empty($client_kyc_data)) { + // $is_deleted = $this->clientKYCDocsModel->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Client KYC Docs data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Client KYC Docs record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Client KYC Docs data not found."); + // } + + // // 4. Client Branch Model + // $client_branch_data = $this->clientBranchModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Client Branch data : " . json_encode($client_branch_data ?? [])); + + // $branch_ids = array_column($client_branch_data, 'id') ?? []; + // $this->myLogger->logme('error', "Client Branch id count : " . count($branch_ids ?? [])); + + // if (!empty($client_branch_data)) { + + // $is_deleted = $this->clientBranchModel->where('client_id', $client_id)->delete(); + + // if ($is_deleted) { + // $this->myLogger->logme('error', "Client Branch data removed successfully."); + + // if(!empty($branch_ids)){ + + // $level_contact_data = $this->levelContactModel->where('contact_type', 'client')->whereIn('ref_id', $branch_ids)->findAll(); + // $this->myLogger->logme('error', "Level Contact data : " . json_encode($level_contact_data ?? [])); + + // $is_deleted = $this->levelContactModel->where('contact_type', 'client')->whereIn('ref_id', $branch_ids)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Level Contact data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Level Contact record does not exist. To delete"); + // } + + // }else{ + // $this->myLogger->logme('error', "Level Contact data not found."); + // } + + // } else { + // $this->myLogger->logme('error', "Client Branch record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Client Branch data not found."); + // } + + // // 5. Client Policy Model + // $client_policy_data = $this->clientPolicyModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Client Policy data : " . json_encode($client_policy_data ?? [])); + + // $policy_ids = array_column($client_policy_data, 'id') ?? []; + // $this->myLogger->logme('error', "Client Policy id count : " . count($policy_ids ?? [])); + + // if (!empty($client_policy_data)) { + // $is_deleted = $this->clientPolicyModel->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + + // $this->myLogger->logme('error', "Client Policy data removed successfully."); + + // if(!empty($policy_ids)){ + + // $employee_policy_data = $this->employeePolicyModel->whereIn('client_policy_id', $policy_ids)->findAll(); + // $this->myLogger->logme('error', "Employee Policy data count : " . count($employee_policy_data ?? [])); + + // $is_deleted = $this->employeePolicyModel->whereIn('client_policy_id', $policy_ids)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Employee policy data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Employee policy record does not exist. To delete"); + // } + + // }else{ + // $this->myLogger->logme('error', "Employee policy data not found."); + // } + + // } else { + // $this->myLogger->logme('error', "Client Policy record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Client Policy data not found."); + // } + + // // 6. Employee Model + // $employee_data = $this->employeeModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Employee data count : " . count($employee_data ?? [])); + + // if (!empty($employee_data)) { + + // $is_deleted = $this->employeeModel->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Employee data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Employee record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Employee data not found."); + // } + + // // 7. Client Deposit Model + // $client_deposit_data = $this->clientDepositModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Client Deposit data : " . json_encode($client_deposit_data ?? [])); + + // if (!empty($client_deposit_data)) { + // $is_deleted = $this->clientDepositModel->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Client Deposit data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Client Deposit record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Client Deposit data not found."); + // } + + // // 8. Policy Premium 1 Model + // $policy_premium1_data = $this->policyPremium1Model->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Policy Premium 1 data count : " . count($policy_premium1_data ?? [])); + + // if (!empty($policy_premium1_data)) { + // $is_deleted = $this->policyPremium1Model->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Policy Premium 1 data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Policy Premium 1 record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Policy Premium 1 data not found."); + // } + + // // 9. Policy Premium 2 Model + // $policy_premium2_data = $this->policyPremium2Model->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Policy Premium 2 data count: " . count($policy_premium2_data ?? [])); + + // if (!empty($policy_premium2_data)) { + // $is_deleted = $this->policyPremium2Model->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Policy Premium 2 data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Policy Premium 2 record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Policy Premium 2 data not found."); + // } + + // // 10. Notification Model + // $notification_data = $this->notificationModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Notification data : " . json_encode($notification_data ?? [])); + + // if (!empty($notification_data)) { + // $is_deleted = $this->notificationModel->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Notification data removed successfully."); + // } else { + // $this->myLogger->logme('error', "Notification record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Notification data not found."); + // } + + // // 11. CD Master Model + // $cd_master_data = $this->CDMasterModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "CD Master data : " . json_encode($cd_master_data ?? [])); + + // if (!empty($cd_master_data)) { + // $is_deleted = $this->CDMasterModel->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "CD Master data removed successfully."); + // } else { + // $this->myLogger->logme('error', "CD Master record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "CD Master data not found."); + // } + + // // 12. Policy Transaction Model + // $policy_transaction_data = $this->policyTransactionModel->where('client_id', $client_id)->findAll(); + // $this->myLogger->logme('error', "Policy Transaction data : " . json_encode($policy_transaction_data ?? [])); + + // $pt_ids = array_column($policy_transaction_data, 'id') ?? []; + // $this->myLogger->logme('error', "Policy Transaction id count : " . count($pt_ids ?? [])); + + // if (!empty($policy_transaction_data)) { + // $is_deleted = $this->policyTransactionModel->where('client_id', $client_id)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "Policy Transaction data removed successfully."); + + // if(!empty($pt_ids)){ + + // $pt_co_share_data = $this->PTCOShareDetailsModel->whereIn('pt_id', $pt_ids)->findAll(); + // $this->myLogger->logme('error', "PT CO Share data : " . json_encode($pt_co_share_data ?? [])); + + // $is_deleted = $this->PTCOShareDetailsModel->whereIn('pt_id', $pt_ids)->delete(); + // if ($is_deleted) { + // $this->myLogger->logme('error', "PT CO Share data removed successfully."); + // } else { + // $this->myLogger->logme('error', "PT CO Share record does not exist. To delete"); + // } + + // }else{ + // $this->myLogger->logme('error', "PT CO Share data not found."); + // } + + // } else { + // $this->myLogger->logme('error', "Policy Transaction record does not exist. To delete"); + // } + // } else { + // $this->myLogger->logme('error', "Policy Transaction data not found."); + // } + + // $this->myLogger->logme('error', "Wipe Demo Client function closed"); + // return $this->respond(['status' => true, 'message' => 'Demo client data wiped successfully'], 200); + // } + + public function wipeDemoClient() + { + $this->myLogger->logme('error', "========================================"); + $this->myLogger->logme('error', "WIPE DEMO CLIENT FUNCTION STARTED"); + $this->myLogger->logme('error', "========================================"); + + $this->myLogger->logme('error', "Request Payload: " . json_encode($this->request->getPost() ?? [])); + $client_id = $this->request->getPost('client_id'); + + if (empty($client_id)) { + $this->myLogger->logme('error', "ERROR: Client ID is required"); + return $this->respond(['status' => false, 'message' => 'Client id required'], 404); + } + + $this->myLogger->logme('error', "Client ID to wipe: " . $client_id); + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 1. CLIENT MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "1. PROCESSING CLIENT MODEL"); + $client_data = $this->clientModel->where('id', $client_id)->where('is_active', 1)->first(); + $this->myLogger->logme('error', " Found Client Data: " . json_encode($client_data ?? [])); + + if (!empty($client_data)) { + $is_deleted = $this->clientModel->where('id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Client data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete client record"); + } + } else { + $this->myLogger->logme('error', " ✗ Client not found or inactive"); + return $this->respond(['status' => false, 'message' => 'Client not found'], 404); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 2. CLIENT RM MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "2. PROCESSING CLIENT RM MODEL"); + $client_rm_data = $this->clientRMModel->where('client_id', $client_id)->first(); + $this->myLogger->logme('error', " Found Client RM Data: " . json_encode($client_rm_data ?? [])); + + if (!empty($client_rm_data)) { + $is_deleted = $this->clientRMModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Client RM data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Client RM record"); + } + } else { + $this->myLogger->logme('error', " ℹ No Client RM data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 3. CLIENT KYC DOCS MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "3. PROCESSING CLIENT KYC DOCS MODEL"); + $client_kyc_data = $this->clientKYCDocsModel->where('client_id', $client_id)->findAll(); + $this->myLogger->logme('error', " Found Client KYC Records: " . count($client_kyc_data ?? [])); + $this->myLogger->logme('error', " Client KYC Data: " . json_encode($client_kyc_data ?? [])); + + if (!empty($client_kyc_data)) { + $is_deleted = $this->clientKYCDocsModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Client KYC Docs data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Client KYC Docs records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Client KYC Docs data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 4. CLIENT BRANCH MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "4. PROCESSING CLIENT BRANCH MODEL"); + $client_branch_data = $this->clientBranchModel->where('client_id', $client_id)->findAll(); + $branch_ids = array_column($client_branch_data, 'id') ?? []; + $this->myLogger->logme('error', " Found Client Branch Records: " . count($client_branch_data ?? [])); + $this->myLogger->logme('error', " Branch IDs: " . json_encode($branch_ids)); + $this->myLogger->logme('error', " Client Branch Data: " . json_encode($client_branch_data ?? [])); + + if (!empty($client_branch_data)) { + $is_deleted = $this->clientBranchModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Client Branch data removed successfully"); + + // Delete related Level Contact data + if (!empty($branch_ids)) { + $this->myLogger->logme('error', " 4a. PROCESSING RELATED LEVEL CONTACT DATA"); + $level_contact_data = $this->levelContactModel->where('contact_type', 'client')->whereIn('ref_id', $branch_ids)->findAll(); + $this->myLogger->logme('error', " Found Level Contact Records: " . count($level_contact_data ?? [])); + $this->myLogger->logme('error', " Level Contact Data: " . json_encode($level_contact_data ?? [])); + + $is_deleted = $this->levelContactModel->where('contact_type', 'client')->whereIn('ref_id', $branch_ids)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Level Contact data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Level Contact records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Branch IDs available for Level Contact deletion"); + } + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Client Branch records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Client Branch data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 5. CLIENT POLICY MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "5. PROCESSING CLIENT POLICY MODEL"); + $client_policy_data = $this->clientPolicyModel->where('client_id', $client_id)->findAll(); + $policy_ids = array_column($client_policy_data, 'id') ?? []; + $this->myLogger->logme('error', " Found Client Policy Records: " . count($client_policy_data ?? [])); + $this->myLogger->logme('error', " Policy IDs: " . json_encode($policy_ids)); + $this->myLogger->logme('error', " Client Policy Data: " . json_encode($client_policy_data ?? [])); + + if (!empty($client_policy_data)) { + $is_deleted = $this->clientPolicyModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Client Policy data removed successfully"); + + // Delete related Employee Policy data + if (!empty($policy_ids)) { + $this->myLogger->logme('error', " 5a. PROCESSING RELATED EMPLOYEE POLICY DATA"); + $employee_policy_data = $this->employeePolicyModel->whereIn('client_policy_id', $policy_ids)->findAll(); + $this->myLogger->logme('error', " Found Employee Policy Records: " . count($employee_policy_data ?? [])); + + $is_deleted = $this->employeePolicyModel->whereIn('client_policy_id', $policy_ids)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Employee Policy data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Employee Policy records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Policy IDs available for Employee Policy deletion"); + } + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Client Policy records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Client Policy data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 6. EMPLOYEE MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "6. PROCESSING EMPLOYEE MODEL"); + $employee_data = $this->employeeModel->where('client_id', $client_id)->findAll(); + $this->myLogger->logme('error', " Found Employee Records: " . count($employee_data ?? [])); + + if (!empty($employee_data)) { + $is_deleted = $this->employeeModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Employee data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Employee records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Employee data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 7. CLIENT DEPOSIT MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "7. PROCESSING CLIENT DEPOSIT MODEL"); + $client_deposit_data = $this->clientDepositModel->where('client_id', $client_id)->findAll(); + $this->myLogger->logme('error', " Found Client Deposit Records: " . count($client_deposit_data ?? [])); + $this->myLogger->logme('error', " Client Deposit Data: " . json_encode($client_deposit_data ?? [])); + + if (!empty($client_deposit_data)) { + $is_deleted = $this->clientDepositModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Client Deposit data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Client Deposit records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Client Deposit data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 8. POLICY PREMIUM 1 MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "8. PROCESSING POLICY PREMIUM 1 MODEL"); + $policy_premium1_data = $this->policyPremium1Model->where('client_id', $client_id)->findAll(); + $this->myLogger->logme('error', " Found Policy Premium 1 Records: " . count($policy_premium1_data ?? [])); + + if (!empty($policy_premium1_data)) { + $is_deleted = $this->policyPremium1Model->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Policy Premium 1 data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Policy Premium 1 records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Policy Premium 1 data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 9. POLICY PREMIUM 2 MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "9. PROCESSING POLICY PREMIUM 2 MODEL"); + $policy_premium2_data = $this->policyPremium2Model->where('client_id', $client_id)->findAll(); + $this->myLogger->logme('error', " Found Policy Premium 2 Records: " . count($policy_premium2_data ?? [])); + + if (!empty($policy_premium2_data)) { + $is_deleted = $this->policyPremium2Model->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Policy Premium 2 data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Policy Premium 2 records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Policy Premium 2 data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 10. NOTIFICATION MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "10. PROCESSING NOTIFICATION MODEL"); + $notification_data = $this->notificationModel->where('client_id', $client_id)->findAll(); + $this->myLogger->logme('error', " Found Notification Records: " . count($notification_data ?? [])); + $this->myLogger->logme('error', " Notification Data: " . json_encode($notification_data ?? [])); + + if (!empty($notification_data)) { + $is_deleted = $this->notificationModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Notification data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Notification records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Notification data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 11. CD MASTER MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "11. PROCESSING CD MASTER MODEL"); + $cd_master_data = $this->CDMasterModel->where('client_id', $client_id)->findAll(); + $this->myLogger->logme('error', " Found CD Master Records: " . count($cd_master_data ?? [])); + $this->myLogger->logme('error', " CD Master Data: " . json_encode($cd_master_data ?? [])); + + if (!empty($cd_master_data)) { + $is_deleted = $this->CDMasterModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ CD Master data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete CD Master records"); + } + } else { + $this->myLogger->logme('error', " ℹ No CD Master data found"); + } + $this->myLogger->logme('error', "----------------------------------------"); + + // ======================================== + // 12. POLICY TRANSACTION MODEL DELETION + // ======================================== + $this->myLogger->logme('error', "12. PROCESSING POLICY TRANSACTION MODEL"); + $policy_transaction_data = $this->policyTransactionModel->where('client_id', $client_id)->findAll(); + $pt_ids = array_column($policy_transaction_data, 'id') ?? []; + $this->myLogger->logme('error', " Found Policy Transaction Records: " . count($policy_transaction_data ?? [])); + $this->myLogger->logme('error', " Policy Transaction IDs: " . json_encode($pt_ids)); + $this->myLogger->logme('error', " Policy Transaction Data: " . json_encode($policy_transaction_data ?? [])); + + if (!empty($policy_transaction_data)) { + $is_deleted = $this->policyTransactionModel->where('client_id', $client_id)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ Policy Transaction data removed successfully"); + + // Delete related PT CO Share data + if (!empty($pt_ids)) { + $this->myLogger->logme('error', " 12a. PROCESSING RELATED PT CO SHARE DATA"); + $pt_co_share_data = $this->PTCOShareDetailsModel->whereIn('pt_id', $pt_ids)->findAll(); + $this->myLogger->logme('error', " Found PT CO Share Records: " . count($pt_co_share_data ?? [])); + $this->myLogger->logme('error', " PT CO Share Data: " . json_encode($pt_co_share_data ?? [])); + + $is_deleted = $this->PTCOShareDetailsModel->whereIn('pt_id', $pt_ids)->delete(); + if ($is_deleted) { + $this->myLogger->logme('error', " ✓ PT CO Share data removed successfully"); + } else { + $this->myLogger->logme('error', " ✗ Failed to delete PT CO Share records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Policy Transaction IDs available for PT CO Share deletion"); + } + } else { + $this->myLogger->logme('error', " ✗ Failed to delete Policy Transaction records"); + } + } else { + $this->myLogger->logme('error', " ℹ No Policy Transaction data found"); + } + + $this->myLogger->logme('error', "========================================"); + $this->myLogger->logme('error', "WIPE DEMO CLIENT FUNCTION COMPLETED"); + $this->myLogger->logme('error', "Client ID: " . $client_id . " - Successfully processed"); + $this->myLogger->logme('error', "========================================"); + + return $this->respond(['status' => true, 'message' => 'Demo client data wiped successfully'], 200); + } } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 512122c6..97a71e4c 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -302,8 +302,9 @@ class EmployeeController extends AdminController //for TPA/insurer upload $data['events'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; //for inception upload - $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrolment']; - + $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; + // $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrolment']; + $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export']; $data['insurer_or_tpa'] = ['insurer' => 'Insurer', 'tpa' => 'TPA']; diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 938c9099..2cc47520 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1319,6 +1319,7 @@ class EmployeeServiceController extends AdminController //get file name $file_id = $params['file_id']; $file = $this->fileModel->find($file_id); + // dd($file); $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; @@ -1330,6 +1331,7 @@ class EmployeeServiceController extends AdminController $excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']); // $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + // dd($excel_data); unset($excel_data[0]); // kint::dump($excel_data); $endorsement_data = []; @@ -1379,10 +1381,14 @@ class EmployeeServiceController extends AdminController ->where('employee_polices.client_policy_id',$file['policy_id']) ->where('employees.emp_status !=','truncated') ->where('employees.is_active', 1) + ->where('employee_polices.status !=','truncated') + ->where('employee_polices.is_active', 1) ->first(); // $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first(); // dd($employee); + // kint::dump($employee); + if(is_array($employee) && count($employee)) { // dd($employee); @@ -1406,7 +1412,13 @@ class EmployeeServiceController extends AdminController if(!in_array($employee['id'],$endorsement_data))//make entry in endorsement firsttime only with checking that PK of emp exisintg in variable $endorsement_data { - $employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first(); + $employee_policy = $this->employeePolicyModel + ->where('employee_id',$employee['id']) + ->where('client_policy_id',$file['policy_id']) + ->where('status !=','truncated') + ->where('is_active', 1) + ->first(); + $data = ['emp_id' => $employee['id'],'name' => $employee['name'],'emp_status' => $employee['emp_status'],'emp_policy_id' => $employee_policy['id'],'emp_code' => $employee['emp_code'],'change_event' => $employee['change_event'],'date_of_exit' => $employee_policy['date_of_exit'],'reason_for_exit' => $employee_policy['reason_for_exit'],'status' => $employee_policy['status'],'claim_status' => $employee_policy['claim_status']]; $endorsement($data,$file,$row); $endorsement_data[] = $employee['id']; @@ -1447,7 +1459,7 @@ class EmployeeServiceController extends AdminController //set success msg to pull notifications $this->setPullNotification($this->getFileMetaDataByFileId($file_id,'success')); - return $endorsement_data; + return $endorsement_data; } diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index ad484ffe..9c72c973 100755 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -664,12 +664,18 @@ if(!function_exists('generate_insurer_based_excel')){ $rowData = []; foreach ($excel_header_array as $header) { + $fieldName = $header['db_column_name']; + $defaultValue = isset($header['default_value']) ? $header['default_value'] : null; if ($fieldName === 'index') { $value = $serialNumber; } else { - $value = $row->$fieldName ?? ''; + if(empty($fieldName) && !empty($defaultValue)){ + $value = $defaultValue; + }else{ + $value = $row->$fieldName ?? ''; + } } $rowData[] = $value; diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index a09f75f1..e1407c2c 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -40,6 +40,7 @@ class ClientModel extends Model "reply_to", "mail_domain", "addon_subheading", + "parent_client_id", ]; diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index ec4b9222..e6b02543 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -1085,10 +1085,10 @@ class EmployeePolicyModel extends Model } $status_condition = "{$insurer_or_tpa}" === 'tpa' - ? "employee_polices.status = 'inactive' AND employees.emp_status = 'active'" + ? "employee_polices.status = 'active' AND employees.emp_status = 'active'" : "employee_polices.status = 'active' AND employees.emp_status = 'active'"; - $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NOT NULL OR a.endorsement_id != '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')"; + $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')"; $query = $this->db->query(" SELECT DISTINCT diff --git a/app/Views/UserList.php b/app/Views/UserList.php index be654b8d..b7de1d73 100755 --- a/app/Views/UserList.php +++ b/app/Views/UserList.php @@ -1,4 +1,4 @@ - --> + + +
@@ -96,7 +286,7 @@ table.dataTable tbody td { -