From f045e21c3aaef84c11f18252ffffa5ff0fff01ed Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Thu, 3 Jul 2025 18:01:19 +0530 Subject: [PATCH 1/7] CHANGE_HR_API_AND_SAVE_MPIN_API : RV --- app/Config/Routes.php | 3 +- app/Controllers/EmployeeRestController.php | 2 +- .../RestAuthenticationController.php | 164 ++++++++++++++---- 3 files changed, 133 insertions(+), 36 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index cc54d104..fe5de65b 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -358,7 +358,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('getPolicyTypeFields', 'LeadsController::getPolicyTypeFields'); $routes->get('removeMultiFile', 'LeadsController::removeMultiFile'); $routes->get('removeInstallments', 'LeadsController::removeInstallments'); - $routes->get('constructHrAccessData', 'ClientController::constructHrAccessData'); + $routes->get('viewHrAccessData', 'ClientController::viewHrAccessData'); + $routes->post('saveHrAccessData', 'ClientController::saveHrAccessData'); }); $routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d9a89de8..c8191df2 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2316,7 +2316,7 @@ class EmployeeRestController extends AdminController - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id ') + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id, DATE_FORMAT(client_policy.policy_end_date, "%d-%m-%Y") AS policy_expiry_date ') ->where('client_policy.client_id', $this->request->getGet('client_id') ) ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) ->where('client_policy.is_active', 1 ) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 04e15dfb..64eca662 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -187,44 +187,140 @@ class RestAuthenticationController extends AdminController } + // public function updateEmpMPIN() + // { + // $requestData = $this->request->getJSON(); + // print_r($requestData); die; + // $mobile_number = $requestData->mobile_number ?? null; + // $email_id = $requestData->email_id ?? null; + // $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; + // $old_mpin = $requestData->old_mpin ?? null; + // $is_mpin_skipped = $requestData->is_mpin_skipped ?? null; + // $is_biometric_enabled = $requestData->is_biometric_enabled ?? null; + + // if (!$new_mpin) { + // return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); + // } + + // $query = $this->employeeModel->where('relationship', 'self'); + + // if ($mobile_number) { + // $query->where('mobile', $mobile_number); + // } elseif ($email_id) { + // $query->where('email_corporate', $email_id); + // } else { + // return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); + // } + + // if (!empty($old_mpin)) { + // $query->where('mpin', $old_mpin); + // } + + // // Fetch employee data + // $employeeData = $query->first(); + + // if (!$employeeData) { + // return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); + // } + + // if(!empty($is_mpin_skipped) && !empty($is_biometric_enabled)){ + // $mpin_data_to_updata = [ + // 'mpin' => $new_mpin, + // 'is_mpin_skipped' => $is_mpin_skipped, + // 'is_biometric_enabled' => $is_biometric_enabled + // ]; + // }else{ + // $mpin_data_to_updata = ['mpin' => $new_mpin]; + // } + + // // Update MPIN + // $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_updata); + + // return true; + // } + public function updateEmpMPIN() { - $requestData = $this->request->getJSON(); - $mobile_number = $requestData->mobile_number ?? null; - $email_id = $requestData->email_id ?? null; - $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; - $old_mpin = $requestData->old_mpin ?? null; - - if (!$new_mpin) { - return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); + try { + log_message('info', 'MPIN update request received.'); + + $requestData = $this->request->getJSON(); + log_message('debug', 'Request data: ' . json_encode($requestData)); + + $mobile_number = $requestData->mobile_number ?? null; + $email_id = $requestData->email_id ?? null; + $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; + $old_mpin = $requestData->old_mpin ?? null; + $is_mpin_skipped = $requestData->is_mpin_skipped ?? null; + $is_biometric_enabled = $requestData->is_biometric_enabled ?? null; + + if (!$new_mpin) { + log_message('warning', 'MPIN is missing.'); + return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); + } + + $query = $this->employeeModel->where('relationship', 'self'); + log_message('info', 'Query initialized with relationship=self'); + + if ($mobile_number) { + $query->where('mobile', $mobile_number); + log_message('info', "Filtering by mobile number: {$mobile_number}"); + } elseif ($email_id) { + $query->where('email_corporate', $email_id); + log_message('info', "Filtering by email ID: {$email_id}"); + } else { + log_message('warning', 'Neither mobile number nor email ID provided.'); + return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); + } + + if (!empty($old_mpin)) { + $query->where('mpin', $old_mpin); + log_message('info', "Verifying old MPIN: {$old_mpin}"); + } + + $employeeData = $query->first(); + log_message('debug', 'Employee lookup result: ' . json_encode($employeeData)); + + if (!$employeeData) { + log_message('warning', 'Employee not found or invalid old MPIN.'); + return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); + } + + $mpin_data_to_update = ['mpin' => $new_mpin]; + + if ($is_mpin_skipped != null && $is_biometric_enabled != null) { + $mpin_data_to_update['is_mpin_skipped'] = $is_mpin_skipped; + $mpin_data_to_update['is_biometric_enabled'] = $is_biometric_enabled; + log_message('info', 'Updating MPIN, MPIN skip flag, and biometric flag.'); + } else { + log_message('info', 'Updating MPIN only.'); + } + + $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_update); + + if ($updated) { + log_message('info', "MPIN updated successfully for employee ID: {$employeeData['id']}"); + return $this->response->setJSON([ + 'status' => true, + 'message' => 'MPIN updated successfully.' + ]); + } else { + log_message('error', "Failed to update MPIN for employee ID: {$employeeData['id']}"); + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Failed to update MPIN.' + ]); + } + } catch (\Exception $e) { + log_message('critical', 'Exception in updateEmpMPIN: ' . $e->getMessage()); + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Unexpected error occurred.', + 'error' => $e->getMessage() + ]); } - - $query = $this->employeeModel->where('relationship', 'self'); - - if ($mobile_number) { - $query->where('mobile', $mobile_number); - } elseif ($email_id) { - $query->where('email_corporate', $email_id); - } else { - return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); - } - - if (!empty($old_mpin)) { - $query->where('mpin', $old_mpin); - } - - // Fetch employee data - $employeeData = $query->first(); - - if (!$employeeData) { - return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); - } - - // Update MPIN - $updated = $this->employeeModel->update($employeeData['id'], ['mpin' => $new_mpin]); - - return true; } + From 119ba2122ae04e6eab522cfd4751f370dfb6bd4c Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 5 Jul 2025 09:52:43 +0530 Subject: [PATCH 2/7] CHANGE_HR_API_CD_SUB_TYPE_ECARD_DOWNLOAD_LINK_AND_OTHERS : RV --- app/Controllers/LeadsController.php | 10 +++++----- app/Models/ClientPolicyModel.php | 16 ++++++++++++++-- app/Models/EmployeePolicyModel.php | 26 +++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 59a9dea4..56f7f1d0 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -1280,8 +1280,8 @@ class LeadsController extends BaseController 'No of Employees at Inception' => $rfq_data['incept_emp_count'], 'Total Sum Insured at Inception ' => $rfq_data['total_si_at_incept'], 'Policy Period' => !empty($rfq_data['policy_start_date']) && !empty($rfq_data['policy_end_date']) ? date('d-m-Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d-m-Y', strtotime($rfq_data['policy_end_date'])) : "To be decided", - 'Insurer' => $rfq_data['insurer_name'] ?? " - ", - 'TPA' => $rfq_data['tpa_name'] ?? " - ", + // 'Insurer' => $rfq_data['insurer_name'] ?? " - ", + // 'TPA' => $rfq_data['tpa_name'] ?? " - ", 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "", ]; } @@ -1322,11 +1322,11 @@ class LeadsController extends BaseController 'No of Employees at Renewal' => $rfq_data['renewal_emp_count'], 'Total Sum Insured at Renewal ' => $rfq_data['total_si_at_renewal'], 'Policy Period' => !empty($rfq_data['policy_start_date']) && !empty($rfq_data['policy_end_date']) ? date('d-m-Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d-m-Y', strtotime($rfq_data['policy_end_date'])) : "To be decided", - 'Insurer' => $rfq_data['insurer_name'] ?? " - ", - 'TPA' => $rfq_data['tpa_name'] ?? " - ", + // 'Insurer' => $rfq_data['insurer_name'] ?? " - ", + // 'TPA' => $rfq_data['tpa_name'] ?? " - ", 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "", 'Existing Insurer' => $rfq_data['insurer_name'], - 'TPA ' => $rfq_data['tpa_name'], + // 'TPA ' => $rfq_data['tpa_name'], ]; } } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 5c43b52e..14d6b065 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -249,8 +249,19 @@ class ClientPolicyModel extends Model } - public function getDepositData($clientId, $insurerId, $cd_ac_pk = null) - { + public function getDepositData($clientId, $insurerId, $cd_ac_pk = null, $subTypeOptions = null) + { + + if($subTypeOptions != null){ + $caseSql = "CASE cash_deposit.sub_type"; + foreach ($subTypeOptions as $key => $label) { + $caseSql .= " WHEN {$key} THEN " . $this->db->escape($label); + } + $caseSql .= " ELSE 'Unknown' END AS sub_type_text"; + }else{ + $caseSql = ""; + } + // Fetch the deposit data based on client and insurer IDs $query = $this->db->table('cash_deposit') ->select('cash_deposit.*') @@ -260,6 +271,7 @@ class ClientPolicyModel extends Model // ->select('policies.name as policy_name') ->select('policy_type.policy_type') ->select('user_profiles.first_name as username') + ->select($caseSql) ->join('user_profiles', 'user_profiles.id = cash_deposit.created_by', 'left') ->join('insurers', 'insurers.id = cash_deposit.insurer_id', 'left') ->join('clients', 'clients.id = cash_deposit.client_id', 'left') diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index f6ff81ed..ec4b9222 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -224,7 +224,28 @@ class EmployeePolicyModel extends Model public function getEmployeePolicy($client_id = 0, $policy_id = 0, $status = [], $branch_id = 0, $emp_code = "", $emp_name = "") { // dd($status); - + $ecard_download_link = " + CASE + WHEN + LOWER(emp.relationship) = 'self' AND + employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '' AND + employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '' + THEN + CASE + WHEN + (employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '') + AND + (employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '') + THEN + CONCAT('" . base_url('download-e-card/') . "', employee_polices.rand_string, '/1') + ELSE + null + END + ELSE + NULL + END AS ecard_download_link + "; + $result = $this->select([ 'employee_polices.*', 'policy_type.policy_type as policy_name', @@ -257,6 +278,7 @@ class EmployeePolicyModel extends Model 'client_branch.branch_code as client_branch_code', 'cp.policy_no', 'cp.policy_type_id', + $ecard_download_link ]) ->join('employees emp', 'employee_polices.employee_id = emp.id') ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy @@ -603,6 +625,7 @@ class EmployeePolicyModel extends Model $insurer_or_tpa = $ref_data['insurer_or_tpa']; $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 = '')"; + $subquery_endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "WHERE (endorsement_id IS NOT NULL OR endorsement_id != '')" : "WHERE (endorsement_id IS NULL OR endorsement_id = '')"; $query = $this->db->query(" @@ -676,6 +699,7 @@ class EmployeePolicyModel extends Model CAST(MAX(CASE WHEN field_name = 'premium' THEN old_value END) AS DECIMAL(10,2)) AS old_si_premium, MAX(CASE WHEN field_name = 'si_enhancement_date' THEN new_value END) AS date_of_coverage FROM emp_endorsement + $subquery_endorsement_condition GROUP BY emp_code ) AS sidata ON a.emp_code = sidata.emp_code WHERE employee_polices.client_policy_id = '{$client_policy_id}' From 30955f09c6ab29f41d268d63068d0fe8dcefef47 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 5 Jul 2025 11:07:27 +0530 Subject: [PATCH 3/7] CHANGE_TICKET_API : RV --- app/Controllers/EmployeeRestController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index c8191df2..e8cb43c7 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2552,12 +2552,16 @@ class EmployeeRestController extends AdminController 'tm.awb_no_courier_name', 'tm.non_id_reason', 'tm.pay_initiate_date', - 'tm.approved_description' + 'tm.approved_description', + 'pt.policy_type as policy_type', + 'cp.policy_no as client_policy_no', ]); $builder->join('insurers i', 'i.id = tm.insurer_id AND i.is_active = 1', 'left'); $builder->join('clients c', 'c.id = tm.client_id AND c.is_active = 1', 'left'); $builder->join('ticket_claim_status tcs', 'tcs.id = tm.claim_status_id AND tcs.is_active = 1', 'left'); + $builder->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left'); + $builder->join('policy_type pt', 'cp.policy_type_id = pt.id', 'left'); $builder->where('tm.is_active', 1); From 43f7d62ede175ae391f855a25a031868c9ee16ef Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 7 Jul 2025 11:52:11 +0530 Subject: [PATCH 4/7] FIX_GTLI_RACK_RATE_ISSUE : RV --- app/Views/policy_grid.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index d0e825f6..dc0bb146 100755 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -393,6 +393,8 @@ $('body').on('click', '.btnPolicyModel', function() $("#hidden_unit").val(branch_units[0]); console.log('unit', branch_units[0]); $("#gpa_unit1").val(branch_units[0]); + $("#gpa_unit2").val(branch_units[0]); + $("#gpa_unit3").val(branch_units[0]); } var data_for_the_rack_rate = JSON.parse(res.premiumData) ?? []; var groupedData = groupByRackRateName(data_for_the_rack_rate) ?? []; @@ -747,7 +749,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa var id_var = 'grid_'; - var default_unit = $('#hidden_unit').val(); + var default_unit = $('#hidden_unit').val() ?? ""; var dataIdValue = '' @@ -787,7 +789,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -864,7 +866,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
From 95b801018db88fded4e82f1283f7947719253e19 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Mon, 7 Jul 2025 22:36:30 +0530 Subject: [PATCH 5/7] CHANGE_MPIN_API_CLAIMS_RACK_RATE : RV --- app/Config/Routes.php | 2 + .../RestAuthenticationController.php | 298 +++++++++++++++--- app/Models/EmployeeModel.php | 2 + app/Views/policy_grid.php | 23 +- app/Views/ticket_form_handler.php | 248 +++++++++------ 5 files changed, 415 insertions(+), 158 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index fe5de65b..457388ff 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -543,6 +543,8 @@ $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEm $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); $routes->post("sendEmail", "EmployeeRestController::send_email"); $routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData"); +$routes->get("cdTransactionData", "EmployeeRestController::cdTransactionData"); +$routes->match( ['get', 'post'], 'claimsSearch','EmployeeRestController::claimsSearch'); $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrolledDetails"); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 64eca662..e31ecb2a 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -340,9 +340,31 @@ class RestAuthenticationController extends AdminController }else{ if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->where('employees.emp_status !=', 'truncated') + ->first(); } else { - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->where('otp', $otp) + ->first(); } } @@ -364,7 +386,7 @@ class RestAuthenticationController extends AdminController $result = JWTToken::encode($employeeData); if(isset($this->request->getJSON()->otp)){ - $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update(); + $this->employeeModel->where('id', $employeeData['id'])->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update(); } return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); @@ -602,9 +624,31 @@ class RestAuthenticationController extends AdminController $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->orderBy('id', 'desc') + ->first(); } else { - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->orderBy('id', 'desc') + ->first(); } $mpin = $this->request->getJSON()->mpin; @@ -650,14 +694,43 @@ class RestAuthenticationController extends AdminController $old_mpin = $this->request->getJSON()->old_mpin; $mpin = $this->request->getJSON()->new_mpin; - if (isset($mobile_number)) - { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); - }else{ - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + // if (isset($mobile_number)) + // { + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + // }else{ + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + // } + + if (isset($mobile_number)) { + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->where('employees.mpin', $old_mpin) + ->orderBy('id', 'desc') + ->first(); + } else { + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->where('employees.mpin', $old_mpin) + ->orderBy('id', 'desc') + ->first(); } - if ($employeeData) { $id= $employeeData["id"]; @@ -681,45 +754,142 @@ class RestAuthenticationController extends AdminController } } + // public function verifyMpin() + // { + // try { + + // $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; + // $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; + // $mpin = $this->request->getJSON()->mpin; + // if (isset($mobile_number)) + // { + // // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel + // ->select('employees.*') + // ->join('employee_polices', 'employees.id = employee_polices.employee_id') + // ->where('employees.mobile', $mobile_number) + // ->where('employees.relationship', 'Self') + // ->where('employee_polices.is_active', 1) + // ->whereIn('employee_polices.status', ['active']) + // ->where('employees.is_active', 1) + // ->whereIn('employees.emp_status', ['active']) + // ->get(); + // }else{ + // // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel + // ->select('employees.*') + // ->join('employee_polices', 'employees.id = employee_polices.employee_id') + // ->where('employees.email_corporate', $email_id) + // ->where('employee_polices.is_active', 1) + // ->whereIn('employee_polices.status', ['active']) + // ->where('employees.is_active', 1) + // ->whereIn('employees.emp_status', ['active']) + // ->where("employees.relationship", "Self") // RAW SQL condition + // ->first(); + + // } + // if ($employeeData && $mpin == $employeeData["mpin"]) { + + // $auth = HttpRequestHelper::getRequestInfo(); + // if ($auth) { + // $data = [ + // 'user_id' => $employeeData['id'], + // 'user_type' => 'employee', + // 'ip' => $auth['ip'], + // 'platform' => $auth['platform'], + // 'broswer' => $auth['browser'], + // ]; + + // $authdata= $this->authHistoryModel->insert($data); + + // } + + // $result = JWTToken::encode($employeeData); + // // $result = $employeeData; + // return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + // } else { + // return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); + // } + // } catch (\Exception $e) { + // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); + // } + // } + public function verifyMpin() { try { + $requestData = $this->request->getJSON(true); - $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; - $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; - $mpin = $this->request->getJSON()->mpin; - if (isset($mobile_number)) - { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); - }else{ - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $mobile_number = $requestData['mobile_number'] ?? null; + $email_id = $requestData['email_id'] ?? null; + $mpin = $requestData['mpin'] ?? null; + // print_r($mpin); + + if (!$mpin) { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'MPIN is required'], 400); } - if ($employeeData && $mpin == $employeeData["mpin"]) { - $auth = HttpRequestHelper::getRequestInfo(); + if ($mobile_number) { + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->first(); + } elseif ($email_id) { + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->first(); + } else { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Mobile number or Email ID is required'], 400); + } + + // print_r($employeeData); die; + + if ($employeeData && isset($employeeData['mpin']) && $mpin === $employeeData['mpin']) { + + $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { - $data = [ - 'user_id' => $employeeData['id'], - 'user_type' => 'employee', - 'ip' => $auth['ip'], - 'platform' => $auth['platform'], - 'broswer' => $auth['browser'], - ]; - - $authdata= $this->authHistoryModel->insert($data); - + $this->authHistoryModel->insert([ + 'user_id' => $employeeData['id'], + 'user_type' => 'employee', + 'ip' => $auth['ip'], + 'platform' => $auth['platform'], + 'broswer' => $auth['browser'], // Note: typo in 'broswer' retained if it's your actual DB field + ]); } + $token = JWTToken::encode($employeeData); - - $result = JWTToken::encode($employeeData); - // $result = $employeeData; - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'data' => $token + ], 200); } else { - return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); + return $this->respond([ + 'status' => 'failed', + 'code' => 404, + 'data' => 'Invalid MPIN' + ], 200); } } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'data' => $e->getMessage() + ], 500); } } @@ -732,13 +902,33 @@ class RestAuthenticationController extends AdminController if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->orderBy('id', 'desc') + ->first(); }else{ - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->orderBy('id', 'desc') + ->first(); } - - if ($employeeData && $employeeData["mpin"] != null) { @@ -776,17 +966,31 @@ class RestAuthenticationController extends AdminController 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(); + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->where('employees.emp_status', ['active']) + ->first(); } else { log_message('info', 'Looking up employee by email: ' . $email_id); $employeeData = $this->employeeModel - ->where('email_corporate', $email_id) - ->where('relationship', 'self') - ->first(); + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->where('employees.emp_status', ['active']) + ->first(); } + log_message('info', '$employeeData : ' . json_encode($employeeData)); + // Step 3: Found employee if (!empty($employeeData)) { log_message('info', 'Employee found: ID = ' . $employeeData['id']); diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index bb62234e..1bc55f06 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -271,6 +271,8 @@ class EmployeeModel extends Model ->join('employee_polices', 'employees.id = employee_polices.employee_id', 'left') ->where('employees.is_active', 1) ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', "active") + ->where('employee_polices.status', "active") ->where('employees.emp_code', $emp_code); if(!empty($client_id)){ diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index dc0bb146..6626d85e 100755 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -92,7 +92,6 @@
- @@ -144,7 +143,7 @@
- + Rename
@@ -191,10 +190,9 @@ $(document).on('click', '.close', function() { var rarc_rate_json_array = []; $(document).on('submit', 'form[id^="GridForm_"]', function(event) { - console.log('submitted function called') - event.preventDefault(); // Prevent the default form submission + console.log('submitted function called') var form = $(this); console.log('form', form) @@ -830,12 +828,12 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
- +
@@ -1424,16 +1422,16 @@ function appendGridtHtml(ui_type = false, secondary = false, data = false) html = `
- +
- +
- +
@@ -1450,7 +1448,7 @@ function appendGridtHtml(ui_type = false, secondary = false, data = false) html = `
- +
@@ -1484,7 +1482,7 @@ function appendGridtHtml(ui_type = false, secondary = false, data = false)
- +
@@ -3358,7 +3356,6 @@ function appendNewTab(tabNameData = null, data = null) newTabPane.innerHTML = `
- @@ -3409,7 +3406,7 @@ function appendNewTab(tabNameData = null, data = null)
- + Delete Rename
diff --git a/app/Views/ticket_form_handler.php b/app/Views/ticket_form_handler.php index 2b3b700c..c454791f 100644 --- a/app/Views/ticket_form_handler.php +++ b/app/Views/ticket_form_handler.php @@ -43,18 +43,16 @@ -