diff --git a/app/Config/Routes.php b/app/Config/Routes.php index fde6c9ec..877ba46e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -172,6 +172,7 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->group("others", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "ClientController::createOtherTabContent"); + $routes->post('check-duplicate', 'ClientController::validateDuplicateByClientBranch'); }); }); @@ -394,6 +395,11 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('getMemberDataExcelFileErrors', 'LeadsController::getMemberDataExcelFileErrors'); $routes->post('savePlacementDataAndValidateMemberDataFile', 'LeadsController::savePlacementDataAndValidateMemberDataFile'); $routes->get('checkMemberDataFileValidationStatus', 'LeadsController::checkMemberDataFileValidationStatus'); + $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->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail"); @@ -526,6 +532,7 @@ $routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMp $routes->post("employeeRest/getPostEmployeeDataForAuth", "RestAuthenticationController::getPostEmployeeDataForAuth"); // $routes->post("logHrActivity", "RestAuthenticationController::logHrActivity"); +$routes->get("employeeRest/getClientDetails", "EmployeeRestController::getClientDetails"); $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { @@ -550,7 +557,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("deleteDependence", "EmployeeRestController::deleteDependence"); $routes->get("getEmployeeAndDependenceByClientId", "EmployeeRestController::getEmployeeAndDependenceByClientId"); $routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy"); - $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); + $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); @@ -706,8 +713,10 @@ $routes->group('test', function($routes) { $routes->get('viewrfq', 'TestingController::viewRFQNonEb'); $routes->get('exportexcel', 'TestingController::exportExcel'); $routes->post('saverfq', 'TestingController::saverfq'); + $routes->get('mapping_client_id_and_branch_id','TestingController::mapping_client_id_and_branch_id'); $routes->get('membervalidation', 'TestingController::membervalidation'); $routes->get('generateExcel', 'TestingController::generateExcel'); + $routes->get('logo_renaming','TestingController::logo_renaming'); }); $routes->cli('cli/testcli', 'TestingController::testcli'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 3a149d37..bcadb66d 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -132,6 +132,15 @@ class ClientController extends AdminController //-------------------------------------------------------------------------------------------------------- + public function validateDuplicateByClientBranch() + { + $value = $this->request->getPost('value'); + $clientId = $this->request->getPost('client_id'); + $branchId = $this->request->getPost('branch_id'); + $field = $this->request->getPost('field'); + $isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $field, $clientId, $branchId); + return $this->response->setJSON(['isDuplicate' => $isDuplicate]); + } public function checkDuplicateTableFieldValue() { $table = $this->request->getPost('table'); @@ -1121,14 +1130,47 @@ class ClientController extends AdminController } $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(); @@ -1153,7 +1195,11 @@ class ClientController extends AdminController $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['pre_branch_id'] = $pre_branch_id; + $units = $this->request->getPost('units'); $emp_unit_count = 0; @@ -1212,7 +1258,41 @@ class ClientController extends AdminController } $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()]); @@ -4589,7 +4669,7 @@ class ClientController extends AdminController // Additional logic for non-individual clients (client_type != 2) $branch_insert = null; if ($client_type != 2) { - $unit[] = $postData['short_name'] . '-' . $postData['branch_code'] ?? 001; + $unit[] = $postData['short_name'] . '-' . ($postData['branch_code'] ?? 001); $branch_data = [ 'client_id' => $client_insert, 'branch_name' => $postData['branch_name'], @@ -6939,7 +7019,9 @@ class ClientController extends AdminController foreach ($postHrs as $post) { $found = false; foreach ($preHrs as $index => $pre) { - if ($post['hr_mobile'] === $pre['hr_mobile'] && $post['hr_mail'] === $pre['hr_mail']) { + + if ( trim($post['hr_mobile']) == trim($pre['hr_mobile']) && trim($post['hr_mail']) == trim($pre['hr_mail']) ) { + $merged[] = [ 'pre_hr_id' => $pre['pre_hr_id'], 'post_hr_id' => $post['post_hr_id'], @@ -6972,6 +7054,13 @@ class ClientController extends AdminController // Remaining preHrs (not matched) foreach ($preHrs as $pre) { + + foreach ($merged as $value) { + if ( trim($pre['hr_mobile']) == trim($value['hr_mobile']) && trim($pre['hr_mail']) == trim($value['hr_mail']) ) { + continue 2; // Skip adding this pre_hr as it's already matched + } + } + $merged[] = [ 'pre_hr_id' => $pre['pre_hr_id'], 'post_hr_id' => null, @@ -7130,9 +7219,15 @@ class ClientController extends AdminController $post_branch_id = $value['post_branch_id']; $post_hr_id = $value['post_hr_id']; - $value['pre_client_id'] = $this->getPreClientId($post_branch_id); - $value['pre_branch_id'] = $this->getPreBranchId($post_branch_id); - $value["pre_hr_id"] = $this->getPreHrId($post_branch_id); + $preBranchId = $this->getPreBranchIdByPostBranchId($post_branch_id); + + if (!empty($preBranchId)) { + $value['pre_branch_id'] = $preBranchId; + $value['pre_client_id'] = $this->getPreClientIdByPreBranchId($preBranchId); + $value["pre_hr_id"] = $this->getPreHrIdByPreBranchId($preBranchId); + } + + // INSERT or UPDATE if (empty($value['pk']) || (int)$value['pk'] === 0) { @@ -7199,26 +7294,30 @@ class ClientController extends AdminController } } - private function getPreClientId($post_branch_id){ + private function getPreClientIdByPreBranchId($pre_branch_id){ $db2 = \Config\Database::connect('preDB'); - $pre_client_id = $db2->table('client_branch')->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['client_id']??[]; + $pre_client_id = $db2->table('client_branch')->where('id',$pre_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['client_id']??""; return $pre_client_id; } - private function getPreBranchId($post_branch_id){ - $db2 = \Config\Database::connect('preDB'); - $pre_branch_id = $db2->table('client_branch')->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['id']??[]; - return $pre_branch_id; - } - private function getPreHrId($post_branch_id){ + private function getPreHrIdByPreBranchId($pre_branch_id){ $db2 = \Config\Database::connect('preDB'); $pre_hr_id = $db2->table('client_branch cb') ->select('lc.id') ->join('level_contacts lc','lc.ref_id = cb.id') - ->where('post_branch_id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['id']??[]; + ->where('lc.contact_type', 'client') + ->where('cb.id',$pre_branch_id)->where('cb.is_Active',1) + ->where('lc.is_Active',1)->get()->getResultArray()[0]['id']??""; return $pre_hr_id; } + private function getPreBranchIdByPostBranchId($post_branch_id){ + $db = \Config\Database::connect(); + $pre_branch_id = $db->table('client_branch')->where('id',$post_branch_id)->where('is_Active',1)->get()->getResultArray()[0]['pre_branch_id']??""; + return $pre_branch_id; + } + + // ------------------- DEMO CLIENT FUNCTION -------------------------------------------------------------------------------- public function wipeDemoClient() @@ -7607,6 +7706,26 @@ class ClientController extends AdminController } + private function updatePreClientBranch($pre_branch_id,$post_branch_id ,$operation) + { + + + + $preDB = \Config\Database::connect('preDB'); + + if($operation != 'create'){ + + $builder = $preDB->table('client_branch'); + $builder->where('post_branch_id', $post_branch_id); + $builder->update(['post_branch_id' => null]); + } + + $builder = $preDB->table('client_branch'); + $builder->where('id', $pre_branch_id); + $builder->update(['post_branch_id' => $post_branch_id]); + + return true; + } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 341bfcf2..1b7310b6 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2868,14 +2868,14 @@ class EmployeeRestController extends AdminController }else if($ClientPolicyValue['policy_type_id'] == 6) { - $policyGroup = 'gpa'; + $policyGroup = 'other'; $data['ticket_type_id'] = 3; $data['claim_subject'] = "Claim EDLI"; $data['sum_insured_label'] = "Sum Assured"; }else if($ClientPolicyValue['policy_type_id'] == 7) { - $policyGroup = 'gpa'; + $policyGroup = 'other'; $data['ticket_type_id'] = 4; $data['claim_subject'] = "Claim GTLI"; $data['sum_insured_label'] = "Sum Assured"; @@ -2969,9 +2969,6 @@ class EmployeeRestController extends AdminController function policyTermsFiter($terms , $type) { - - - $gpa = [ "sumInsured2" => "Sum Insured", "totalSumInsured" => "Total Sum Assured", @@ -3021,8 +3018,6 @@ class EmployeeRestController extends AdminController "moderntreatmentsasperirdai" => "Modern Treatment " ]; - - $finalarray = []; if($type == 'gpa'){ foreach ($gpa as $key => $value) { @@ -3046,6 +3041,18 @@ class EmployeeRestController extends AdminController $finalarray[$terms->gpa_special_condition_label[$i]] = $terms->gpa_special_condition_input[$i]; } } + }else if($type == 'other'){ + foreach ($terms as $key => $value) { + if($key != "multiple_sum_insured" && $value != ""){ + $result = ucwords(str_replace('_', ' ', $key)); + $finalarray[$result] = $value; + } + } + if(isset(($terms->gpa_special_condition_label)) && is_array($terms->gpa_special_condition_label) && is_array($terms->gpa_special_condition_input)){ + for ($i=0; $i < count($terms->gpa_special_condition_label); $i++) { + $finalarray[$terms->gpa_special_condition_label[$i]] = $terms->gpa_special_condition_input[$i]; + } + } }else{ foreach ($gmc as $key => $value) { if(isset($terms->$key)) @@ -3070,9 +3077,7 @@ class EmployeeRestController extends AdminController } } - return $finalarray; - } diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 40afde50..59608e7e 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -138,7 +138,10 @@ class LeadsController extends BaseController $this->cause_of_death = [ 'natural_death' => 'Natural Death', 'suicide' => 'Suicide', - 'accident' => 'Accident' + 'accident' => 'Accident', + 'cardiac_arrest' => 'Cardiac Arrest', + 'septic_shock' => 'Septic shock', + 'heart_attack' => 'Heart Attack', ]; $this->member_data_excel_columns = [ @@ -2408,8 +2411,11 @@ class LeadsController extends BaseController $row = 2; foreach ($claim_details['finyear'] as $record) { $col = 'A'; - foreach ($record as $value) { + foreach ($record as $array_key => $value) { $label = ucwords(str_replace('_', ' ', ($value ?? ""))); + if(in_array($array_key, ['sum_insured', 'claim_amount', 'settled'])){ + $label = formatIndianCurrency(intval($label)); + } $sheet->setCellValue($col . $row, $label); $col++; } @@ -2427,19 +2433,27 @@ class LeadsController extends BaseController } // Enable wrap text for all cells - $maxColLetter = chr(64 + count($headers)); // Last column letter - $sheet->getStyle("A2:{$maxColLetter}{$row}")->getAlignment()->setWrapText(true); + // $maxColLetter = chr(64 + count($headers)); // Last column letter + // $sheet->getStyle("A2:{$maxColLetter}{$row}")->getAlignment()->setWrapText(true); - // Optional: center vertically for neatness - $sheet->getStyle("A2:{$maxColLetter}{$row}")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); + // // Optional: center vertically for neatness + // $sheet->getStyle("A2:{$maxColLetter}{$row}")->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); - // Optional: Make row height auto (helps when wrap text is on) - for ($i = 2; $i < $row; $i++) { - $sheet->getRowDimension($i)->setRowHeight(-1); - } + $maxColLetter = chr(64 + count($headers)); + $dataRange = "A1:{$maxColLetter}" . ($row - 1); - } - } + $sheet->getStyle($dataRange)->getAlignment() + ->setWrapText(true) + ->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER) + ->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER); + + // Optional: Make row height auto (helps when wrap text is on) + for ($i = 2; $i < $row; $i++) { + $sheet->getRowDimension($i)->setRowHeight(-1); + } + + } + } // Save to temporary location $uploadFilePath = WRITEPATH . 'tmp/' . $filename; diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 013a9324..19cde67b 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -33,8 +33,11 @@ use App\Models\ClientDepositModel; use App\Models\EmployeePolicyModel; use App\Models\FileModel; use App\Models\InsurerExcelExportTemplateModel; +use App\Models\NhanceBranchModel; use App\Models\SettingsModel; use App\Models\VehicleModel; +use App\Models\VehicleTypeModel; +use App\Models\RTOModel; use CodeIgniter\CLI\CLI; @@ -1618,7 +1621,8 @@ class MasterController extends AdminController //Vehicle Master data Function public function VehicleMasterList() - { $data['tab_name'] = 'Vehicle Master'; + { + $data['tab_name'] = 'Vehicle Master'; $data['page_name'] = 'Vehicles'; $data['vehicle_type'] = [ 'two_wheeler' => 'Two Wheeler', @@ -2020,4 +2024,255 @@ class MasterController extends AdminController dd($result); } + //---------------------------------------------------------------------------------------------------------- + + public function nhanceBranchMaster() + { + $nhanceBranchModel = new NhanceBranchModel(); + $method = $this->request->getMethod(); + $data['tab_name'] = 'Nhance Branch'; + $data['page_name'] = 'Nhance Branchs'; + + if ($method === 'post') { + + $id = $this->request->getPost('pk') ?? null; + $data = $this->request->getPost(); + + if (empty($id)) { + $update_status = $nhanceBranchModel->insert($data); + } else { + $update_status = $nhanceBranchModel->where('id', $id)->set($data)->update(); + } + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Nhance Branch Master updated successfully', + 'data' => $data + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to update', + 'data' => $data + ], 200); + } + + } elseif ($method === 'get') { + + $id = $this->request->getGet('pk') ?? null; + + if (!empty($id)) { + $data = $nhanceBranchModel->where('is_active', 1)->where('id', $id)->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 = $nhanceBranchModel->where('is_active', 1)->findAll(); + return $this->loadLayout('nhance_branch_list', ['data' => $data]); + + } elseif ($method === 'delete') { + + $input = $this->request->getRawInput(); + $id = $input['pk'] ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $nhanceBranchModel->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); + } + } + } + + + public function vehicleTypeMaster() + { + $vehicleTypeModel = new VehicleTypeModel(); + $method = $this->request->getMethod(); + $data['tab_name'] = 'Vehicle Type'; + $data['page_name'] = 'Vehicle Types'; + if ($method === 'post') { + + $id = $this->request->getPost('pk') ?? null; + $data = $this->request->getPost(); + + if (empty($id)) { + $update_status = $vehicleTypeModel->insert($data); + } else { + $update_status = $vehicleTypeModel->where('id', $id)->set($data)->update(); + } + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'Vehicle Type Master updated successfully', + 'data' => $data + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to update', + 'data' => $data + ], 200); + } + + } elseif ($method === 'get') { + + $id = $this->request->getGet('pk') ?? null; + + if (!empty($id)) { + $data = $vehicleTypeModel->where('is_active', 1)->where('id', $id)->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 = $vehicleTypeModel->where('is_active', 1)->findAll(); + return $this->loadLayout('vehicle_type_master_list', ['data' => $data]); + + } elseif ($method === 'delete') { + + $input = $this->request->getRawInput(); + $id = $input['pk'] ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $vehicleTypeModel->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); + } + } + } + + public function rtoMaster() + { + $rtoModel = new RTOModel(); + $method = $this->request->getMethod(); + $data['tab_name'] = 'RTO'; + $data['page_name'] = 'RTO'; + + if ($method === 'post') { + + $id = $this->request->getPost('pk') ?? null; + $data = $this->request->getPost(); + + if (empty($id)) { + $update_status = $rtoModel->insert($data); + } else { + $update_status = $rtoModel->where('id', $id)->set($data)->update(); + } + + if ($update_status) { + return $this->respond([ + 'status' => true, + 'code' => 200, + 'message' => 'RTO Master updated successfully', + 'data' => $data + ], 200); + } else { + return $this->respond([ + 'status' => false, + 'code' => 400, + 'message' => 'Failed to update', + 'data' => $data + ], 200); + } + + } elseif ($method === 'get') { + + $id = $this->request->getGet('pk') ?? null; + + if (!empty($id)) { + $data = $rtoModel->where('is_active', 1)->where('id', $id)->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 = $rtoModel->where('is_active', 1)->findAll(); + return $this->loadLayout('rto_master_list', ['data' => $data]); + + } elseif ($method === 'delete') { + + $input = $this->request->getRawInput(); + $id = $input['pk'] ?? null; + + if (empty($id)) { + return $this->respond([ + 'status' => false, + 'code' => 404, + 'message' => 'No ID provided for deletion' + ], 200); + } + + $update_status = $rtoModel->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); + } + } + } + } \ No newline at end of file diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 39b4bdea..1778d0de 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -594,6 +594,7 @@ class PolicyTransactionController extends BaseController 'client_branch_id' => $data['client_branch_id'] ?? 0, 'cd_ac_pk' => $data['cd_ac_no'] ?? null, 'gst' => 18, + 'policy_entry_from' => 2, ]; } @@ -1397,6 +1398,12 @@ class PolicyTransactionController extends BaseController ->orderBy('id', 'asc') ->first(); + $pt_id = null; + if(!empty($data)){ + $inception_data = $this->policyTransactionModel->where('policy_no', $data['policy_no'])->where('client_id', $data['client_id'])->first(); + $pt_id = $inception_data['id']; + } + if (!empty($data['policy_start_date'])) { $data['policy_start_date'] = change_date_format($data['policy_start_date'], 'Y-m-d', 'd/m/Y'); @@ -1559,7 +1566,7 @@ class PolicyTransactionController extends BaseController // print_r($data['endorse_eff_date']); die; if ($data) { - return $this->respond(['status' => true, 'data' => $data], 200); + return $this->respond(['status' => true, 'data' => $data, 'pt_id' => $pt_id], 200); } else { return $this->respond(['status' => false], 200); } @@ -1709,14 +1716,16 @@ class PolicyTransactionController extends BaseController ") ->join('policy_transaction', 'policy_transaction.id = pt_co_share_details.pt_id') ->where('policy_transaction.client_id', $client_id) - ->where('policy_transaction.client_policy_id', $client_policy_id) + // ->where('policy_transaction.client_policy_id', $client_policy_id) + ->where('policy_transaction.id', $client_policy_id) ->where('policy_transaction.action_type', 'inception') ->where('policy_transaction.is_active', 1) ->findAll(); $is_copay_yes = $this->policyTransactionModel ->where('client_id', $client_id) - ->where('client_policy_id', $client_policy_id) + // ->where('client_policy_id', $client_policy_id) + ->where('id', $client_policy_id) ->where('action_type', 'inception') ->where('is_active', 1) ->first(); diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index d9756a7b..a7cdddd1 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -26,7 +26,7 @@ class TestingController extends BaseController { $this->myLogger = \Config\Services::mylogger(); } - + public function saveForm() { // Get JSON input @@ -41,7 +41,7 @@ class TestingController extends BaseController } public function testcli() - { + { echo "hi"; $this->myLogger->logme('error', "test log"); echo "hi 2"; @@ -85,19 +85,19 @@ class TestingController extends BaseController $options->set('debugLayoutBlocks', false); $options->set('debugLayoutInline', false); $options->set('debugLayoutPaddingBox', false); - + // Initialize DomPDF $dompdf = new Dompdf($options); - + // Load HTML content $dompdf->loadHtml($html); - + // Set paper size and orientation $dompdf->setPaper('A4', 'landscape'); // or 'portrait' - + // Render PDF $dompdf->render(); - + // Output PDF to browser $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf'; $dompdf->stream($filename, ['Attachment' => true]); // Set to false for inline view @@ -117,7 +117,7 @@ class TestingController extends BaseController 'POLICY_DATE' => '31/12/2024', 'INSURER_NAME' => 'ZURICH KOTAK GTNERAL INSURANCE COIIPANY lNDlA LIMITED', 'TPA_NAME' => 'HealthIndia Insurance TPA Services Pvt. Ltd.', - 'FRONT_CARD' => base_url() .('public/uploads/template_bg/Nhance_Ecard_working_1_front_3.png'), + 'FRONT_CARD' => base_url() . ('public/uploads/template_bg/Nhance_Ecard_working_1_front_3.png'), 'BACK_CARD' => base_url() . ('public/uploads/template_bg/Nhance_Ecard_working_1_Back_3.png'), 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' ]; @@ -133,7 +133,7 @@ class TestingController extends BaseController 'POLICY_DATE' => '31/12/2024', 'INSURER_NAME' => 'ABC Insurance Co.', 'TPA_NAME' => 'XYZ TPA Ltd.', - 'FRONT_CARD' => base_url() .('public/uploads/template_bg/Nhance_Ecard_working_1_front_3.png'), + 'FRONT_CARD' => base_url() . ('public/uploads/template_bg/Nhance_Ecard_working_1_front_3.png'), 'BACK_CARD' => base_url() . ('public/uploads/template_bg/Nhance_Ecard_working_1_Back_3.png'), 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' ]; @@ -163,12 +163,12 @@ class TestingController extends BaseController { // Load your HTML template $template = file_get_contents(WRITEPATH . 'e_card_template/common.html'); - + // Replace placeholders with actual data foreach ($data as $key => $value) { $template = str_replace('{' . $key . '}', $value, $template); } - + return $template; } @@ -231,21 +231,21 @@ class TestingController extends BaseController $employeePolicy = new EmployeePolicyModel(); $data = $employeePolicy - ->select('client_policy.policy_type_id') - ->join('employees', 'employee_polices.employee_id = employees.id') - ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id') - ->where('employees.is_active', 1) - ->where('employees.emp_status', ['active', 'expired']) - ->where('employee_polices.is_active', 1) - ->where('employee_polices.status', ['active', 'expired']) - ->where('employees.client_id', $client_id) - ->where('employees.emp_code', $emp_code) - ->groupBy('employee_polices.client_policy_id') - ->findAll(); - + ->select('client_policy.policy_type_id') + ->join('employees', 'employee_polices.employee_id = employees.id') + ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id') + ->where('employees.is_active', 1) + ->where('employees.emp_status', ['active', 'expired']) + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status', ['active', 'expired']) + ->where('employees.client_id', $client_id) + ->where('employees.emp_code', $emp_code) + ->groupBy('employee_polices.client_policy_id') + ->findAll(); } - public function ptedfitdata($id){ + public function ptedfitdata($id) + { $policy_transaction = new PolicyTransactionController(); $data = $policy_transaction->getInceptionDataForEdit($id); // dd($data); @@ -255,7 +255,7 @@ class TestingController extends BaseController $dataArray = $data['pt_co_share_details']; // Example $cd_ac_pk = 'CD12345'; $role_id = 1; - $team_id = ['6']; + $team_id = ['6']; $insurer_branch = $insurer_branch; return view('pt_calc_table', [ @@ -321,7 +321,7 @@ class TestingController extends BaseController } public function viewRFQNonEb() - { + { $insurerBranchModel = new InsurerBranchModel(); $data['page_name'] = "RFQ NON EB"; $data['insurer'] = $insurerBranchModel->getInsurerBranchesWithInsurerNames(); @@ -329,7 +329,8 @@ class TestingController extends BaseController return $this->loadLayout('view_rfq_non_eb_new', $data); } - public function saverfq(){ + public function saverfq() + { $json = $this->request->getPost('json'); $json = json_encode($json); print_r($json); @@ -348,10 +349,191 @@ class TestingController extends BaseController // print_rr($policy_data['json']); die; $policy_data = json_decode($policy_data['json'], true); $policy_data = array_slice($policy_data, 0, -2); - print_rr($policy_data); die; - dd($policy_data); + print_rr($policy_data); + die; + dd($policy_data); } + + public function mapping_client_id_and_branch_id() + { + + $post_clients_list = $this->getNonDuplicatePostClients(); + + $pre_clients_list = $this->getNonDuplicatePreClients(); + + $log_post_clients_list = $post_clients_list ; + + $log_pre_clients_list = $pre_clients_list ; + + log_message('error', 'Post Clients to be processed: ' . count($log_post_clients_list)); + log_message('error', 'Pre Clients to be processed: ' . count($log_pre_clients_list)); + + + + $matched_Count = 0 ; + $expected_match_count = min(count($post_clients_list), count($pre_clients_list)); + + + if ( + !empty($pre_clients_list) && + !empty($post_clients_list) + ) { + + $postDB = \Config\Database::connect(); + $preDB = \Config\Database::connect('preDB'); + + foreach ($post_clients_list as $index => $post_client) { + + foreach ($pre_clients_list as $index => $pre_client) { + + if (trim($post_client['short_name']) == trim($pre_client['short_name'])) { + + unset($log_post_clients_list[$index]); + unset($log_pre_clients_list[$index]); + + $matched_Count++; + + + $postDB->table('clients')->where('id', $post_client['id'])->update(['pre_client_id' => $pre_client['id']]); + + $preDB->table('clients')->where('id', $pre_client['id'])->update(['post_client_id' => $post_client['id']]); + + // upto here we updated client_id in both dbs. + + $post_branches = $postDB->table('client_branch') + ->where('client_id', $post_client['id']) + ->get() + ->getResultArray() ?? []; + + $pre_branches = $preDB->table('client_branch') + ->where('client_id', $pre_client['id']) + ->get() + ->getResultArray() ?? []; + + if (!empty($post_branches) && !empty($pre_branches)) { + + + foreach ($post_branches as $post_branch) { + + $pre_branch = $preDB->table('client_branch') + ->where('client_id', $pre_client['id']) + ->where('branch_code', $post_branch['branch_code']) + ->get() + ->getRowArray() ?? []; + + if (!empty($pre_branch)) { + $postDB->table('client_branch')->where('id', $post_branch['id'])->update(['pre_branch_id' => $pre_branch['id']]); + } + } + + foreach ($pre_branches as $pre_branch) { + + $post_branch = $postDB->table('client_branch') + ->where('client_id', $post_client['id']) + ->where('branch_code', $pre_branch['branch_code']) + ->get() + ->getRowArray() ?? []; + + if (!empty($post_branch)) { + $preDB->table('client_branch')->where('id', $pre_branch['id'])->update(['post_branch_id' => $post_branch['id']]); + } + } + } + } + } + } + + + log_message('error', 'Expected Match Count : ' . $expected_match_count); + log_message('error', 'Total Matched Count: ' . $matched_Count); + log_message('error', 'Total UnMatched Count: ' . $expected_match_count - $matched_Count); + + + log_message('error','unmatched_reocrds'); + + $log_post_clients_list = array_values($log_post_clients_list); + $log_pre_clients_list = array_values($log_pre_clients_list); + + if( (count($log_pre_clients_list) < count($log_post_clients_list))){ + log_message('error',"unmatched records count from pre- ". count($log_pre_clients_list)); + log_message('error',print_r($log_pre_clients_list,true)); + } else { + log_message('error',"unmatched records count from post - ".count($log_post_clients_list)); + log_message('error',print_r($log_post_clients_list,true)); + } + + + } + + return $this->response->setJSON(['status' => 'success', 'message' => 'Client and Branch mapping completed.'])->setStatusCode(200); + + + } + + + private function getNonDuplicatePostClients() + { + + + $postDB = \Config\Database::connect(); + + $sql = "SELECT * + FROM clients AS post_clients + WHERE post_clients.client_type = 1 + AND post_clients.is_active = 1 + AND (post_clients.short_name NOT IN + ( + SELECT ir_post_clients.short_name + FROM clients as ir_post_clients + WHERE ir_post_clients.client_type = 1 + AND ir_post_clients.short_name IS NOT NULL + AND TRIM(ir_post_clients.short_name) <> '' + AND ir_post_clients.is_active = 1 + GROUP BY ir_post_clients.short_name + HAVING COUNT(*) > 1) + ) + ORDER BY post_clients.short_name"; + + $binds = []; + + $query = $postDB->query($sql, $binds); + + $results = $query->getResultArray() ?? []; + + return $results; + } + + private function getNonDuplicatePreClients() + { + + $preDB = \Config\Database::connect('preDB'); + + $sql = "SELECT * + FROM clients AS pre_clients + WHERE pre_clients.client_type = 1 + AND pre_clients.is_active = 1 + AND (pre_clients.short_name NOT IN + ( + SELECT ir_pre_clients.short_name + FROM clients as ir_pre_clients + WHERE ir_pre_clients.client_type = 1 + AND ir_pre_clients.short_name IS NOT NULL + AND TRIM(ir_pre_clients.short_name) <> '' + AND ir_pre_clients.is_active = 1 + GROUP BY ir_pre_clients.short_name + HAVING COUNT(*) > 1) + ) + ORDER BY pre_clients.short_name"; + + $binds = []; + + $query = $preDB->query($sql, $binds); + + $results = $query->getResultArray() ?? []; + + return $results; + } public function membervalidation($lead_id = 329) { $lead_controll = new LeadsController(); @@ -533,4 +715,97 @@ class TestingController extends BaseController ]; } + + public function logo_renaming(){ + + $directory = ROOTPATH . 'public/uploads/logo/'; + + if (!is_dir($directory)) { + die("Directory not found: $directory"); + } + + $files = scandir($directory); + + $client_logo_files = $this->get_client_logo_files(); + + $rename_files = ""; + $failed_rename_files = ""; + + foreach ($files as $file) { + // Skip system entries + if ($file === '.' || $file === '..' ) { + continue; + } + + + $oldPath = $directory . $file; + + if (is_file($oldPath) && in_array(trim($file) , $client_logo_files)) { + + // Remove all spaces from filename + $newFileName = preg_replace('/\s+|\x{00A0}|\x{200B}|\x{200C}|\x{200D}|\x{FEFF}/u', '', $file); + + $newPath = $directory . $newFileName; + + // Only rename if the name changed + if ($oldPath !== $newPath) { + if (rename($oldPath, $newPath)) { + $rename_files .= "\n Renamed: $file → $newFileName \n"; + } else { + $failed_rename_files .= "\n Failed file: $file \n"; + } + } + } + } + + $dbUpdated = $this->update_client_logo_files(); + + log_message('error', 'Renamed Files: ' . $rename_files); + log_message('error', 'Failed Renames: ' . $failed_rename_files); + log_message('error', 'Database Update Status: ' . ($dbUpdated ? 'Success' : 'No changes made')); + + return $this->response->setJSON(['status' => 'success', + 'message' => 'Logo renaming completed. kindly check backend logs for details', + 'data' => [ + 'renamed_files' => $rename_files, + 'failed_renames' => $failed_rename_files + ] + ])->setStatusCode(200); + } + + public function get_client_logo_files(){ + + $db = \Config\Database::connect(); + + $sql = "SELECT client_logo FROM clients WHERE client_logo IS NOT NULL AND TRIM(client_logo) <> '' "; + + $query = $db->query($sql); + + $results = $query->getResultArray() ?? []; + + $files = array_map(function($item) { + return trim($item['client_logo']); + }, $results); + + return $files; + } + + public function update_client_logo_files(){ + + $db = \Config\Database::connect(); + + $sql = "UPDATE clients + SET client_logo = REPLACE(REPLACE(REPLACE(client_logo, CHAR(160), ''), ' ', ''), '\t', '') + WHERE client_logo IS NOT NULL + AND TRIM(client_logo) <> '' + "; + + $query = $db->query($sql); + + return $db->affectedRows() > 0; + + + } + + } diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index c03ffcc9..f66229f5 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -57,6 +57,7 @@ if (!function_exists('file_Upload')) { if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) { $fileToUpload->move($filepath); $fileName = $fileToUpload->getName(); + $fileName = preg_replace('/[\s\x{00A0}\x{200B}-\x{200D}\x{FEFF}]/u', '', $fileName); return $fileName; } else { return ""; diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index 9abe8929..b84bfae1 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -226,5 +226,18 @@ class ClientModel extends Model return $result; } + public function isDuplicateByClientBranch($value, $field, $clientId, $branchId) + { + $builder = $this->db->table('level_contacts lc') + ->select('lc.id') + ->join('client_branch cb', 'lc.ref_id = cb.id', 'left') + ->where('lc.'.$field, $value) + ->where('lc.contact_type', 'client') + ->where('cb.client_id', $clientId) + ->where('lc.ref_id', $branchId) + ->get(); + + return $builder->getNumRows() > 0 ? true : false; + } } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 132080de..152cad7f 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -55,6 +55,7 @@ class ClientPolicyModel extends Model "cd_ac_pk", "is_lgbtq", "placement_json", + "policy_entry_from", ]; // Callbacks diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 348d309d..041ac791 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -1492,6 +1492,7 @@ class EmployeePolicyModel extends Model tpa.tpa_logo AS tpa_logo, tpa.front_card, tpa.back_card, + tpa.network_hospitals, tpa.short_name AS tpa_short_name' ) @@ -1557,6 +1558,7 @@ class EmployeePolicyModel extends Model tpa.tpa_logo AS tpa_logo, tpa.front_card, tpa.back_card, + tpa.network_hospitals, tpa.short_name AS tpa_short_name' ) diff --git a/app/Models/RTOModel.php b/app/Models/RTOModel.php new file mode 100644 index 00000000..6f5abcab --- /dev/null +++ b/app/Models/RTOModel.php @@ -0,0 +1,57 @@ + + class="btn btn-primary waves-effect waves-light btn-sm ">Fetch Client Branch (Pre-Enrolment)
@@ -86,13 +86,18 @@
+ + + + + - + - +
@@ -193,12 +198,13 @@
+ name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateDuplicateByClientBranch(this, 'email','branchBtnSubmit')" required>
- +
- +
@@ -961,6 +976,121 @@ function validateInput(input, table, field, submitButId){ } + + +function validateDuplicateByClientBranch(input, field, submitButId) { + let value = $(input).val().trim(); + let clientId = $('#client_id_branch').val(); + let branchId = $('#branch_id_primarykey').val(); + let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim(); + let message = label ? label + " is duplicate!" : "Value is duplicate!"; + + console.log(`cId: ${clientId} | bId: ${branchId}`); + + // Don't forgot be careful + // 1 Local duplication check (User entered) + let isLocalDuplicate = false; + $('input[name="' + field + '[]"]').each(function(index) { + let compareVal = $(this).val().trim(); + console.log(`Entered value: ${value} | Contact ${index+1} value: ${$(this).val()}`); + if (this !== input && compareVal !== '' && compareVal === value) { + isLocalDuplicate = true; + return false; + } + }); + + if (isLocalDuplicate) { + console.log(`r u n Local`); + console.log(`duplicate found for ${field}`); + toastr.warning(message, 'WARNING'); + $('#' + submitButId).prop('disabled', true); + return; + } + + // important Skip empty values + if (value === '') { + checkAllFieldsValid(submitButId); + return; + } + + // Don't forgot be careful + // 2 Server-side duplicate check (DB) + $.ajax({ + url: '', + type: 'POST', + data: { + client_id: clientId, + branch_id: branchId, + value: value, + field: field + }, + dataType: 'json', + success: function(response) { + if (response.isDuplicate) { + console.log(`r u n Server`); + console.log(`duplicate found for ${field}`); + toastr.warning(message, 'WARNING'); + $('#' + submitButId).prop('disabled', true); + } else { + console.log(`No duplicate for ${field}`); + checkAllFieldsValid(submitButId); + } + }, + error: function(xhr, status, error) { + console.error('AJAX Error:', error); + } + }); +} + + +// recheck all contacts before enabling submit +function checkAllFieldsValid(submitButId) { + let emailDuplicates = false; + let mobileDuplicates = false; + + // cross check all EMAIL duplicates + let emailSeen = []; + $('input[name="email[]"]').each(function() { + let val = $(this).val().trim(); + if (val && emailSeen.includes(val)) { + emailDuplicates = true; + } else if (val) { + emailSeen.push(val); + } + }); + + // cross check all MOBILE duplicates + let mobileSeen = []; + $('input[name="mobile[]"]').each(function() { + let val = $(this).val().trim(); + if (val && mobileSeen.includes(val)) { + mobileDuplicates = true; + } else if (val) { + mobileSeen.push(val); + } + }); + + if (emailDuplicates || mobileDuplicates) { + $('#' + submitButId).prop('disabled', true); + // show correct message based on what’s duplicated + if (emailDuplicates && mobileDuplicates) { + toastr.warning("Email and Mobile values are duplicate!", "WARNING"); + console.log('Both Email and Mobile duplicates'); + } else if (emailDuplicates) { + toastr.warning("Email duplicate!", "WARNING"); + console.log('Cross Check Email duplicates'); + } else if (mobileDuplicates) { + toastr.warning("Mobile duplicate!", "WARNING"); + console.log('Cross Check Mobile duplicates'); + } + console.log(`btn Dis - true`); + } else { + console.log('unique — enable'); + console.log(`btn Dis - false`); + $('#' + submitButId).prop('disabled', false); + } +} + function getContactsData() { const contacts = []; diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index 567fc409..3dc798d6 100755 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -407,7 +407,7 @@