From 59208c9a51a357ccbfd5976fa49d24fab573362a Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 6 Feb 2026 14:07:24 +0530 Subject: [PATCH 1/6] FIX_ISSUE --- app/Controllers/EmployeeRestController.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index bad00c73..6f8f0a81 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -4526,11 +4526,12 @@ class EmployeeRestController extends AdminController $post_data = [ 'client_id' => $this->request->getPost('client_id') ?? null, - 'client_branch_id' => $this->request->getPost('client_branch_id'), - 'policy_id' => $this->request->getPost('policy_id'), - 'file_action' => $this->request->getPost('file_action'), - 'created_by' => $this->request->getPost('created_by'), - 'file_name' => $this->request->getFile('file_name') + 'client_branch_id' => $this->request->getPost('client_branch_id') ?? null, + 'policy_id' => $this->request->getPost('policy_id') ?? null, + 'file_action' => $this->request->getPost('file_action') ?? null, + 'created_by' => $this->request->getPost('created_by') ?? null, + 'file_name' => $this->request->getFile('file_name') ?? null, + 'policy_no' => $this->request->getPost('policy_no') ?? null, ]; // print_r($post_data); die; From 00d115b7450f1b8f0ab019d4be4a4fb563a1a198 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 6 Feb 2026 14:18:40 +0530 Subject: [PATCH 2/6] FIX_ISSUE --- app/Controllers/EmployeeRestController.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 6f8f0a81..1040c97e 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -4803,7 +4803,14 @@ class EmployeeRestController extends AdminController $data = $this->getDataFromHrFileUploadTable($search_data); $table = "hr_file_upload"; }else{ - $client_data = $this->clientModel->where('MD5(id)', $search_data['client_id'])->first(); + + if (is_string($search_data['client_id']) && preg_match('/^[a-f0-9]{32}$/i', $search_data['client_id'])) { + $client_data = $this->clientModel->where('MD5(id)', $search_data['client_id'])->first(); + $search_data['client_id'] = $client_data['id']; + } else { + $client_data = $this->clientModel->where('id', $search_data['client_id'])->first(); + } + if($client_data['hr_file_processed_by'] == 1){ $data = $this->getDataFromHrFilesTable($search_data); $table = "files"; From dc17e48d8b0397a3939ee5b01627779b56c05572 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 6 Feb 2026 15:38:42 +0530 Subject: [PATCH 3/6] FIX_ISSUE --- app/Controllers/EmployeeRestController.php | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 1040c97e..583f33c7 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -606,7 +606,9 @@ class EmployeeRestController extends AdminController public function getEmployeeAndDependenceByClientId() { try { + $empData = $this->employeePolicyModel->getEmployeePolicy(client_id: $this->request->getGet('client_id'), policy_id: $this->request->getGet('client_policy_id'), status: 0, branch_id: $this->request->getGet('client_branch_id')); + $empData = array_slice($empData, 0, 5); if ($empData) { return $this->respond(['status' => 'success', 'code' => 200, 'data' => $empData], 200); @@ -4723,28 +4725,40 @@ class EmployeeRestController extends AdminController try { $file_id = $this->request->getGet('id') ?? $id; + $client_id = $this->request->getGet('client_id') ?? null; + + $client_data = []; + if(!empty($client_id)){ + if (is_string($client_id) && preg_match('/^[a-f0-9]{32}$/i', $client_id)) { + $client_data = $this->clientModel->where('MD5(id)', $client_id)->first(); + } else { + $client_data = $this->clientModel->where('id', $client_id)->first(); + } + } // Find record - $record = $this->hrFileUploadModel->where('id', (int)$file_id)->find(); - - // print_rr( $record);die; + if($client_data && $client_data['hr_file_processed_by'] == 1){ + $record = $this->fileModel->where('id', (int)$file_id)->find(); + $uploadPath = WRITEPATH . 'uploads/excel/'; + }else{ + $record = $this->hrFileUploadModel->where('id', (int)$file_id)->find(); + $uploadPath = WRITEPATH . 'uploads/hr_files/'; + } if (!$record) { return $this->failNotFound("File record not found"); } - $uploadPath = WRITEPATH . 'uploads/hr_files/'; - $filePath = $uploadPath . $record[0]['file_name']; + $filePath = $uploadPath . $record[0]['file_name']; if (!file_exists($filePath)) { - // return $this->failNotFound("File not found on server"); - $data['message'] = 'The Physical File Not Found'; - return view('errors/404', $data); + return $this->failNotFound("File not found on server"); } // Force file download return $this->response->download($filePath, null) ->setFileName($record[0]['file_name']); + } catch (\Exception $e) { return $this->failServerError($e->getMessage()); } From c2d962eb726c5e38a6dc0e55a31453d3528b4335 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 6 Feb 2026 15:50:25 +0530 Subject: [PATCH 4/6] FIX_ISSUE --- app/Controllers/EmployeeRestController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 583f33c7..0d079092 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -608,7 +608,6 @@ class EmployeeRestController extends AdminController try { $empData = $this->employeePolicyModel->getEmployeePolicy(client_id: $this->request->getGet('client_id'), policy_id: $this->request->getGet('client_policy_id'), status: 0, branch_id: $this->request->getGet('client_branch_id')); - $empData = array_slice($empData, 0, 5); if ($empData) { return $this->respond(['status' => 'success', 'code' => 200, 'data' => $empData], 200); From ced337311602d36670a40e5e0b76c201b470ed33 Mon Sep 17 00:00:00 2001 From: velz Date: Fri, 6 Feb 2026 18:00:25 +0530 Subject: [PATCH 5/6] FIX_DASHBOARD_META_ARGS --- app/Controllers/EmployeeRestController.php | 2 +- app/Controllers/TestingController.php | 2 +- app/Models/TicketMasterModel.php | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 9b47b6ef..bc2e1dae 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -5447,7 +5447,7 @@ class EmployeeRestController extends AdminController // 'dashboard' => 1 'dashboard' => 2 ], - 'params' => (object)['client_policy_id' => $received_data['client_policy_id']], // MUST be object for Metabase + 'params' => (object)['client_policy' => $received_data['client_policy_id']], // MUST be object for Metabase 'exp' => time() + (10 * 60) // 10 minutes ]; diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index bc0bfdb0..8d2eaa6f 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -996,7 +996,7 @@ class TestingController extends BaseController // 'dashboard' => 1 'dashboard' => 2 ], - 'params' => (object)['client_policy' => 108], // MUST be object for Metabase + 'params' => (object)['client_policy' => 4687], // MUST be object for Metabase 'exp' => time() + (10 * 60) // 10 minutes ]; // dd($payload); diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index f2feb0d5..98cad654 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -93,6 +93,7 @@ class TicketMasterModel extends Model 'required_docs', 'policy_transaction_id', 'tpa_claim_type', + 'tpa_ailments' ]; From 274be778cccf4a2b2aab8562778405a86fee77e8 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 6 Feb 2026 18:11:32 +0530 Subject: [PATCH 6/6] FIX_ISSUE --- app/Controllers/ClientController.php | 369 ++++++++++++++++++++- app/Controllers/EmployeeRestController.php | 2 +- 2 files changed, 365 insertions(+), 6 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index bd9f4a54..09f34f77 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1611,7 +1611,7 @@ class ClientController extends AdminController } - public function createClientBranch() + public function createClientBranchNew() { $this->myLogger->logme('error', 'Client branch CREATE function called'); @@ -1796,7 +1796,7 @@ class ClientController extends AdminController } } - public function editClientBranch() + public function editClientBranchNew() { $this->myLogger->logme('error', 'Client branch EDIT function called'); @@ -1916,11 +1916,9 @@ class ClientController extends AdminController $level_contact_data = []; if (!empty($level_contact_data_raw)) { - $level_contact_data_decoded = json_decode($level_contact_data_raw, true); + $level_contact_data_decoded = json_decode($level_contact_data_raw ?? '{}', true); - if (json_last_error() === JSON_ERROR_NONE && is_array($level_contact_data_decoded)) { $level_contact_data = sanitizeInputArrayAdvanced($level_contact_data_decoded); - } } if (!empty($level_contact_data)) { @@ -1949,6 +1947,367 @@ class ClientController extends AdminController } } + public function saveLevelContactsNew($level_contact_data, $branch_id) + { + if (!empty($level_contact_data) && is_array($level_contact_data)) { + foreach ($level_contact_data as $value) { + if (!empty($value['id'])) { + $id = $value['id']; + unset($value['id']); + $this->levelContactModel->update($id, $value); + } else { + unset($value['id']); + $value['contact_type'] = "client"; + $value['ref_id'] = $branch_id ?? null; + $this->levelContactModel->insert($value); + } + } + } + } + + public function removeLevelContactsNew() + { + $id = $this->request->getGet('id'); + try { + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'message' => 'Invalid ID provided. ID is empty', + 'data' => $id + ], 400); + } + + $updated = $this->levelContactModel->update($id, ['is_active' => 0]); + + if ($updated === false) { + return $this->respond([ + 'status' => false, + 'message' => 'Failed to remove contact' + ], 500); + } + + return $this->respond([ + 'status' => true, + 'message' => 'Contact removed successfully' + ]); + } catch (\Exception $e) { + return $this->respond([ + 'status' => false, + 'message' => 'An error occurred: ' . $e->getMessage() + ], 500); + } + } + + + + public function createClientBranch() + { + + $this->myLogger->logme('error', 'Client branch CREATE function called'); + + $rules = [ + 'branch_name' => [ + 'rules' => 'required', + 'errors' => [ + 'required' => 'Branch Name is required', + ] + ], + 'branch_code' => [ + 'rules' => 'required', + 'errors' => [ + 'required' => 'Branch Code is required', + ] + ], + 'address1' => [ + 'rules' => 'required', + 'errors' => [ + 'required' => 'Address Line 1 is required', + ] + ], + 'state' => [ + 'rules' => 'required', + 'errors' => [ + 'required' => 'State is required', + ] + ], + 'district' => [ + 'rules' => 'required', + 'errors' => [ + 'required' => 'District is required.', + ] + ], + 'city' => [ + 'rules' => 'required', + 'errors' => [ + 'required' => 'City is required.', + ] + ], + 'pincode' => [ + 'rules' => 'required', + 'errors' => [ + 'required' => 'Pincode is required.', + ] + ], + 'gst' => [ + 'rules' => 'required|regex_match[/^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}Z[A-Z\d]{1}$/]', + 'errors' => [ + 'required' => 'GST number is required', + 'regex_match' => 'Invalid GST Number. Example: 12ABCDE1234F5Z6' + ] + ], + 'name.*' => [ + 'rules' => 'required|alpha_space', + 'errors' => [ + 'required' => 'Contact name is required', + 'alpha_space' => 'Contact name may contain only letters and spaces' + ] + ], + 'designation.*' => [ + 'rules' => 'required|alpha_space', + 'errors' => [ + 'required' => 'Designation is required', + 'alpha_space' => 'Designation may contain only letters and spaces' + ] + ], + 'email.*' => [ + 'rules' => 'required|valid_email', + 'errors' => [ + 'required' => 'Email is required', + 'valid_email' => 'Please enter a valid email address' + ] + ], + 'mobile.*' => [ + 'rules' => 'required|numeric|exact_length[10]', + 'errors' => [ + 'required' => 'Mobile number is required', + 'numeric' => 'Mobile number must contain digits only', + 'exact_length' => 'Mobile number must be exactly 10 digits' + ] + ], + ]; + + if (!$this->validate($rules)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => $this->validator->getErrors() + ]); + } + + $data = $this->request->getPost(); + $data = sanitizeInputArrayAdvanced($data); + + + if (!isset($data['sez'])) { + $data['sez'] = 0; + } elseif ($data['sez']) { + $data['sez'] = 1; + } + + $units = json_decode($data['units'], true) ?? []; + + if (!is_array($units) || empty($units)) { + $client_data = $this->clientModel->where('id', $data['client_id'])->first(); + $default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-'); + $data['units'] = json_encode([$default_unit]); + } + + $data['created_by'] = get_session_userid(); + + + // before updating check if pre_branch_id is already existing in the current db + + if(isset($data['pre_branch_id']) && !empty($data['pre_branch_id'])) + { + $existing_pre_branch = $this->clientBranchModel + ->where('pre_branch_id',$data['pre_branch_id']) + //->where('id !=',$post_branch_id) + ->first(); + + if($existing_pre_branch) + { + return $this->respond([ + 'status' => false, + 'code' => 409, + 'message' => 'The branch is already mapped with another branch. Please check.', + ], 409); + } + } + + + + $insert = $this->clientBranchModel->insert($data); + + $post_branch_id = $insert; + + if ($insert) { + $level_contact_data = $this->request->getPost('level_contect_data'); + $level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null; + $this->saveLevelContacts($level_contact_data, $insert); + } + + if($post_branch_id && isset($data['pre_branch_id']) && !empty($data['pre_branch_id'])) + { + // need to update the client_branch in the pre + $result = $this->updatePreClientBranch($data['pre_branch_id'],$post_branch_id , "create"); + + log_message('error','Pre client_branch update result for pre_branch_id '.$data['pre_branch_id'].' and post_branch_id '.$post_branch_id.' is '.json_encode($result)); + } + + if ($insert) { + $branchData = $this->clientBranchModel->where('client_id', $this->request->getPost('client_id'))->findAll(); + $branchData['role'] = get_role_id(); + return $this->respond([ + 'status' => true, + 'code' => 200, + 'data' => $branchData, + 'message' => 'Client branch created successfully', + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'Failed to create client branch ', + ], 200); + } + } + + public function editClientBranch() + { + + $this->myLogger->logme('error', 'Client branch EDIT function called'); + $id = $this->request->getPost('branch_id_primarykey'); + $client_id = $this->request->getPost('client_id'); + $pre_branch_id = $this->request->getPost('pre_branch_id') ?? ''; + + $data = $this->request->getPost(); + $data = sanitizeInputArrayAdvanced($data); + $data['pre_branch_id'] = $pre_branch_id; + + $units = $this->request->getPost('units'); + + $emp_unit_count = 0; + $rr_unit_count = 0; + $rr_unit_count2 = 0; + $total_count = 0; + + $list_of_branch_units = $this->clientBranchModel->find((int)$id); + $units = json_decode($list_of_branch_units['units']); + + if (!is_array($units) || empty($units)) { + $client_data = $this->clientModel->where('id', $data['client_id'])->first(); + $default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-'); + $data['units'] = json_encode([$default_unit]); + } + + if (!empty($units)) { + foreach ($units as $unit) { + $emp_unit_count += $this->employeeModel->where('unit', $unit)->countAllResults(); + $rr_unit_count += $this->policyPremium2Model->where('unit', $unit)->countAllResults(); + $rr_unit_count2 += $this->policyPremium1Model->where('unit', $unit)->countAllResults(); + } + + $total_count = $emp_unit_count + $rr_unit_count + $rr_unit_count2; + } + + $uncommonValues = []; + + if ($total_count > 0) { + $units = (string) $this->request->getPost('units'); // Assuming 'units' is an array + + $list_of_branch_units = $this->clientBranchModel->find((int)$id); + $branch_units = json_decode($list_of_branch_units['units'], true); + $units = json_decode($units); + + $uncommonValues = array_diff($branch_units, $units); + + if (count($uncommonValues) > 0) { + + $branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll(); + + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => "Deleted unit(s) in use. couldn't complete this operation.", + 'uncommonValues' => $uncommonValues, + 'data' => $branchData, + ], 200); + } + } + + if (!isset($data['sez'])) { + $data['sez'] = 0; + } elseif ($data['sez']) { + $data['sez'] = 1; + } + + $data['updated_by'] = get_session_userid(); + + $post_branch_id = $id; + + // before updating check if pre_branch_id is already existing in the current db + + if(isset($data['pre_branch_id']) && !empty($data['pre_branch_id'])) + { + $existing_pre_branch = $this->clientBranchModel + ->where('pre_branch_id',$data['pre_branch_id']) + ->where('id !=',$post_branch_id) + ->first(); + + if($existing_pre_branch) + { + return $this->respond([ + 'status' => false, + 'code' => 409, + 'message' => 'The branch is already mapped with another branch. Please check.', + ], 409); + } + } + + $insert = $this->clientBranchModel->update($id, $data); + + + + if($post_branch_id && isset($data['pre_branch_id']) && !empty($data['pre_branch_id'])) + { + // need to update the client_branch in the pre + $result = $this->updatePreClientBranch($data['pre_branch_id'],$post_branch_id , "update"); + + log_message('error','Pre client_branch update result for pre_branch_id '.$data['pre_branch_id'].' and post_branch_id '.$post_branch_id.' is '.json_encode($result)); + } + + + $this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]); + + + if ($insert) { + + $level_contact_data = $this->request->getPost('level_contect_data'); + $level_contact_data = !empty($level_contact_data) ? json_decode($level_contact_data, true) : null; + $this->saveLevelContacts($level_contact_data, $id); + } + + if ($insert) { + $branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll(); + return $this->respond([ + 'status' => true, + 'code' => 200, + 'data' => $branchData, + 'emp_unit_count' => $emp_unit_count, + 'rr_unit_count' => $rr_unit_count, + 'list_of_branch_units' => $list_of_branch_units, + 'total_count' => $total_count, + 'uncommonValues' => $uncommonValues, + 'message' => 'Client branch updated successfully', + 'response_data' => $this->request->getPost() + + ], 200); + } else { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update client branch'], 200); + } + } + public function saveLevelContacts($level_contact_data, $branch_id) { if (!empty($level_contact_data) && is_array($level_contact_data)) { diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 0d079092..405ae063 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -4724,7 +4724,7 @@ class EmployeeRestController extends AdminController try { $file_id = $this->request->getGet('id') ?? $id; - $client_id = $this->request->getGet('client_id') ?? null; + $client_id = $this->request->getGet('cliend_id') ?? null; $client_data = []; if(!empty($client_id)){