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/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 441aa098..f7a6f0f2 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 @@ -3583,5 +3589,61 @@ 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) + { + if (empty($mobile_no)) { + return 0; // mobile is empty, return policy count 0 + } + + try { + $db2 = \Config\Database::connect('preDB'); + } catch (\Throwable $e) { + log_message('error', 'DB connection to preDB failed: ' . $e->getMessage()); + return 0; + } + + try { + $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(); + return $query->getNumRows(); + + } catch (\Throwable $e) { + log_message('error', 'Query failed in getPreEmployeePolicyCount: ' . $e->getMessage()); + return 0; + } + } } \ No newline at end of file