diff --git a/app/Config/Database.php b/app/Config/Database.php index 1a43584f..b0c2a6e3 100755 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -74,6 +74,21 @@ class Database extends Config 'busyTimeout' => 1000, ]; + public $preDB = [ + 'DSN' => '', + 'hostname' => 'localhost', + 'username' => 'root', + 'password' => 'root', + 'database' => 'other_db', + 'DBDriver' => 'MySQLi', + 'DBPrefix' => '', + 'pConnect' => false, + 'DBDebug' => (ENVIRONMENT !== 'production'), + 'charset' => 'utf8', + 'DBCollat' => 'utf8_general_ci', + ]; + + public function __construct() { parent::__construct(); diff --git a/app/Config/Routes.php b/app/Config/Routes.php index cc528822..914e0d78 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -458,6 +458,7 @@ $routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpi $routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationController::verifyEmployeeWithEmailId"); $routes->post("/employeeRest/updateEmpOTP", "RestAuthenticationController::updateEmpOTP"); $routes->post("/employeeRest/updateEmpMPIN", "RestAuthenticationController::updateEmpMPIN"); +$routes->post("employeeRest/forgotMPIN", "RestAuthenticationController::forgotMPIN"); // $routes->post("/employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 441aa098..d46c085b 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2760,6 +2760,11 @@ class EmployeeRestController extends AdminController ->where('client_branch_id',$this->request->getGet('client_branch_id')) ->where('family_floater_key','self')->where('is_active', 1 ) ->get()->getRow()->name; + + //for get the pre enrollment policy count + $empMobileNo = $this->request->getGet('mobile_no'); + $prePolicyCount = $this->getPreEmployeePolicyCount($empMobileNo); + $whereArrayForId = []; foreach ( $employeeData as $key => $value) { array_push($whereArrayForId, $value['id']); } @@ -2807,6 +2812,7 @@ class EmployeeRestController extends AdminController $data['heading'] = $ClientPolicyValue['policy_long_name']; $data['claims_grace_date'] = $this->convertDateFormatDisplay($ClientPolicyValue['claims_grace_date']); $data['policy_status'] = $policy_status_key; + $data['pre_policy_count'] = $prePolicyCount; // $data['policy_terms'] = $terms; // if($ClientPolicyValue['policy_type_id'] == 1){ $data['heading'] = 'Group Personal Accident Coverage'; }else @@ -2859,7 +2865,7 @@ class EmployeeRestController extends AdminController } - return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'emp_name' => $employeeName ], 200); + return $this->respond(['status' => 'success','code' => 200,'data' => $result , 'emp_name' => $employeeName, 'pre_policy_count' => $prePolicyCount ], 200); }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200); @@ -3583,5 +3589,76 @@ class EmployeeRestController extends AdminController } } + public function getEmployeePolicyCount() + { + $db2 = \Config\Database::connect('preDB'); + + $mobile_no = $this->request->getGet('mobile_no'); + + $builder = $db2->table('employees') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.mobile', $mobile_no) + ->groupBy('employee_polices.client_policy_id'); + + $query = $builder->get(); + $count = $query->getNumRows(); // count grouped rows manually + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'policy_count' => $count + ], 200); + } + + public function getPreEmployeePolicyCount($mobile_no) + { + log_message('error', 'getPreEmployeePolicyCount called with mobile: ' . var_export($mobile_no, true)); + + if (empty($mobile_no)) { + log_message('error', 'Mobile number is empty or null.'); + return 0; + } + + try { + log_message('error', 'Attempting to connect to preDB...'); + $db2 = \Config\Database::connect('preDB'); + log_message('error', 'Connection to preDB successful.'); + } catch (\Throwable $e) { + log_message('error', 'DB connection to preDB failed: ' . $e->getMessage()); + return 0; + } + + try { + log_message('error', 'Building query to count employee policies...'); + $builder = $db2->table('employees') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('cp.enrolment_visibility', 1) + ->where('cp.open_for_enrollment', 1) + ->whereIn('cp.policy_type_id', [1,2,6,7]) + ->where('employees.mobile', $mobile_no) + ->groupBy('employee_polices.client_policy_id'); + + log_message('error', 'Executing policy count query...'); + $query = $builder->get(); + $count = $query->getNumRows(); + + log_message('error', 'Policy count result: ' . $count); + return $count; + + } catch (\Throwable $e) { + log_message('error', 'Query failed in getPreEmployeePolicyCount: ' . $e->getMessage()); + return 0; + } + } + } \ No newline at end of file diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 0cb10174..9a275f79 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -2037,7 +2037,7 @@ class PolicyTransactionController extends BaseController //insurer statement list page public function statementList() { - // dd($this->validateInsurerStatement(['file_id' => 49])); + // dd($this->validateInsurerStatement(['file_id' => 49])); // for check validateInsurerStatementfunction with hard coded file id always un command $data['insurers'] = $this->insurerModel->where('is_active',1)->findAll(); $today = date('Y-m-d'); $fromday = $from_date = date('Y-m-d', strtotime('-180 days', strtotime($today))); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index de52b208..04e15dfb 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -512,13 +512,20 @@ class RestAuthenticationController extends AdminController } $mpin = $this->request->getJSON()->mpin; + $is_mpin_skipped = $this->request->getJSON()->is_mpin_skipped; + $is_biometric_enabled = $this->request->getJSON()->is_biometric_enabled; + $mpin_data_to_updata = [ + 'mpin' => $mpin, + 'is_mpin_skipped' => $is_mpin_skipped, + 'is_biometric_enabled' => $is_biometric_enabled + ]; if ($employeeData) { $id= $employeeData["id"]; - $updateMpin = $this->employeeModel->where('id', $id)->set('mpin', $mpin)->update(); + $updateMpin = $this->employeeModel->where('id', $id)->set( $mpin_data_to_updata)->update(); if($updateMpin){ $result = ['user_verification' => true , 'message' => "Mpin Updated"]; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); @@ -639,7 +646,7 @@ class RestAuthenticationController extends AdminController if ($employeeData && $employeeData["mpin"] != null) { - return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"]],200); + return $this->respond(['status' => 'success','code' => 200,'data' => "Mpin - exist" , 'Mpin' =>$employeeData["mpin"], 'is_mpin_skipped' => $employeeData['is_mpin_skipped'], 'is_biometric_enabled' => $employeeData['is_biometric_enabled']],200); } else { return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200); } @@ -648,6 +655,88 @@ class RestAuthenticationController extends AdminController } } + public function forgotMPIN() + { + try { + log_message('info', 'forgotMPIN() called.'); + + $json = $this->request->getJSON(); + $mobile_number = $json->mobile_number ?? null; + $email_id = $json->email_id ?? null; + + log_message('info', 'Received input - Mobile: ' . var_export($mobile_number, true) . ', Email: ' . var_export($email_id, true)); + + // Step 1: Check input + if (!$mobile_number && !$email_id) { + log_message('error', 'Mobile number and email ID are both missing.'); + return $this->respond([ + 'status' => 'failed', + 'code' => 400, + 'message' => 'Mobile number or email ID is required.' + ], 400); + } + + // Step 2: Fetch employee data + if ($mobile_number) { + log_message('info', 'Looking up employee by mobile number: ' . $mobile_number); + $employeeData = $this->employeeModel + ->where('mobile', $mobile_number) + ->where('relationship', 'self') + ->first(); + } else { + log_message('info', 'Looking up employee by email: ' . $email_id); + $employeeData = $this->employeeModel + ->where('email_corporate', $email_id) + ->where('relationship', 'self') + ->first(); + } + + // Step 3: Found employee + if (!empty($employeeData)) { + log_message('info', 'Employee found: ID = ' . $employeeData['id']); + + $updateData = [ + 'mpin' => null, + 'is_mpin_skipped' => null, + 'is_biometric_enabled' => null + ]; + + log_message('info', 'Updating employee MPIN fields to null for ID: ' . $employeeData['id']); + + $updated = $this->employeeModel + ->where('id', $employeeData['id']) + ->set($updateData) + ->update(); + + if ($updated) { + log_message('info', 'MPIN reset successful for employee ID: ' . $employeeData['id']); + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'MPIN reset successfully.' + ], 200); + } else { + log_message('error', 'Failed to update MPIN fields for employee ID: ' . $employeeData['id']); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Could not reset MPIN values.', + ], 500); + } + } else { + // Step 4: Not found in local DB — call external fallback + log_message('warning', 'Employee not found locally. Falling back to third-party API.'); + return $this->respond(['status' => 'failed','code' => 404,'data' => "Employee not found"],200); } + } catch (\Throwable $e) { + log_message('error', 'Exception in forgotMPIN(): ' . $e->getMessage()); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Server error: ' . $e->getMessage() + ], 500); + } + } + // TokenController.php public function bookstackLoginToken() diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 1807f9b9..1cc20a2e 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -1854,7 +1854,7 @@ class TicketController extends BaseController $this->loadLayout("ticket_feedback_list",$data); } - public function getMoreInfo($requestFrom = null , $ticket_id) { + public function getMoreInfo($requestFrom = null , $ticket_id = null) { if($requestFrom == null){ $ticket_id = $this->request->getPost('ticket_id'); diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 141fe725..55e7a04c 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -475,7 +475,7 @@ if (!function_exists('name_and_empid_check_in_db')) { ->where("ep.is_active", 1) ->where("ep.status", 'active') // ->where("ep.client_id",$client_id) - ->where('name', trim($row[2]))->where('emp_code', trim($row[1])) + ->where('TRIM(name)', trim($row[2]))->where('TRIM(emp_code)', trim($row[1])) ->findAll(); // kint::dump($employeeModel->getLastQuery()->getQuery()); diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 6f4af68b..bb62234e 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -42,7 +42,9 @@ class EmployeeModel extends Model "token_time_out", "emp_type", "unit", - "mpin" + "mpin", + "is_mpin_skipped", + "is_biometric_enabled", ]; // Callbacks diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 7e2679ea..6ac2e4ee 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -98,6 +98,14 @@ min-height: 0; } + body[data-sidebar-size=condensed] .navbar-custom { + left: 155px !important; + } + + body[data-sidebar-size=condensed] .logo-box { + width: 155px !important; + } + .navbar-custom { top: -10px !important; height: 61px !important; @@ -542,7 +550,7 @@