diff --git a/README.md b/README.md index 39af52c..b12dc3e 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # README # This README would normally document whatever steps are necessary to get your application up and running. +This is test cmd for checking auto deploy ### What is this repository for? ### diff --git a/app/Config/Routes.php b/app/Config/Routes.php index cbb5b40..d5cc961 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -434,8 +434,6 @@ $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDr //Employee login api's $routes->post("/employeeRest/verifyEmployeeNumber", "RestAuthenticationController::verifyEmployeeWithMobileNumber"); $routes->post("/employeeRest/getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); -$routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin"); -$routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin"); $routes->post("/employeeRest/verifyEmployeeEmailId", "RestAuthenticationController::verifyEmployeeWithEmailId"); // $routes->post("/employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); @@ -450,10 +448,23 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->post("getId", "RestAuthenticationController::getUserIdFromToken"); }); +// MPIN api's $routes->post("employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); $routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMpin"); +$routes->post("/employeeRest/verifyMpin", "RestAuthenticationController::verifyMpin"); +$routes->post("/employeeRest/checkMpin", "RestAuthenticationController::checkMpin"); $routes->post("employeeRest/forgotMPIN", "RestAuthenticationController::forgotMPIN"); -$routes->post("calculatePremium", "EmployeeRestController::calculatePremium"); +$routes->post("employeeRest/updateMobileNumber", "RestAuthenticationController::updateMobileNumber"); + +// PASSWORD api's +$routes->post("employeeRest/savePassword", "RestAuthenticationController::savePassword"); +$routes->post("employeeRest/changePassword", "RestAuthenticationController::changePassword"); +$routes->post("employeeRest/verifyPassword", "RestAuthenticationController::verifyPassword"); +$routes->post("employeeRest/verifyOtp", "RestAuthenticationController::verifyOtp"); +$routes->post("employeeRest/checkPassword", "RestAuthenticationController::checkPassword"); +$routes->get("employeeRest/downloadSampleExcel", "EmployeeRestController::downloadSampleExcel"); + + // $routes->post("employeeRest/createOrUpdateEmployeePolicySiAmount", "EmployeeRestController::createOrUpdateEmployeePolicySiAmount"); // $routes->post("employeeRest/calculatePremium", "EmployeeRestController::calculatePremium"); @@ -505,11 +516,12 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->post("hrFileUpload", "EmployeeRestController::hrFileUpload"); }); + $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); $routes->post("sendEmail", "EmployeeRestController::send_email"); $routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData"); - +$routes->post("calculatePremium", "EmployeeRestController::calculatePremium"); $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrolledDetails"); //crone job @@ -530,5 +542,7 @@ $routes->get('notification_mail_header',"NotificationController::notification_ma $routes->get('notification_mail_footer',"NotificationController::notification_mail_footer"); - +$routes->group('test',function($routes){ + $routes->get('logo_renaming','TestingController::logo_renaming'); +}); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d2eb167..5afb6bb 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -684,6 +684,12 @@ class ClientController extends AdminController $insert = $this->clientModel->insert($data); if ($insert) { $client_data = $this->clientModel->where(['id' => $insert, 'is_active' => 1])->first(); + + $client_id = $insert; + $default_template_creation = $this->createDefaultMailTemplate($client_id , $client_data); + if($default_template_creation == false){ + $this->myLogger->logme('error', 'Default Mail Template Creation Failed for Client ID: {data}', ['data' => $client_id]); + } return $this->respond(['status' => true, 'code' => 200, 'data' => $client_data], 200); } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200); @@ -5334,6 +5340,76 @@ class ClientController extends AdminController } + public function createDefaultMailTemplate($client_id , $client_data){ + + $member_welcome_mail_template = $this->notificationModel->where('client_id',NULL)->where('template_name','member_welcome_mail')->get()->getResultArray()[0]??[]; + + $member_remainder_mail_template = $this->notificationModel->where('client_id',NULL)->where('template_name','member_reminder_mail')->get()->getResultArray()[0]??[]; + + $member_review_and_summary_mail_template = $this->notificationModel->where('client_id',NULL)->where('template_name','member_review_and_summary_mail')->get()->getResultArray()[0]??[]; + + $default_member_welcome_mail_template = [ + 'client_id' => $client_id, + 'template_name' => 'member_welcome_mail', + 'subject' => $member_welcome_mail_template['subject']??'', + 'mail_content' => $member_welcome_mail_template['mail_content']??'', + 'mail_content_json'=> $member_welcome_mail_template['mail_content_json']??'', + + 'created_by' => get_session_userid(), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_by' => null, + 'updated_at' => date('Y-m-d H:i:s'), + 'mail_content_copy'=> null + ]; + + $default_member_remainder_mail_template = [ + 'client_id' => $client_id, + 'template_name' => 'member_reminder_mail', + 'subject' => $member_remainder_mail_template['subject']??'', + 'mail_content' => $member_remainder_mail_template['mail_content']??'', + 'mail_content_json'=> $member_remainder_mail_template['mail_content_json']??'', + + 'created_by' => get_session_userid(), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_by' => null, + 'updated_at' => date('Y-m-d H:i:s'), + 'mail_content_copy'=> null + ]; + + $default_member_review_and_summary_mail_template = [ + 'client_id' => $client_id, + 'template_name' => 'member_review_and_summary_mail', + 'subject' => $member_review_and_summary_mail_template['subject']??'', + 'mail_content' => $member_review_and_summary_mail_template['mail_content']??'', + 'mail_content_json'=> $member_review_and_summary_mail_template['mail_content_json']??'', + + 'created_by' => get_session_userid(), + 'created_at' => date('Y-m-d H:i:s'), + 'updated_by' => null, + 'updated_at' => date('Y-m-d H:i:s'), + 'mail_content_copy'=> null + ]; + + $this->myLogger->logme('error', 'Default Mail Template Data ' . json_encode([ + $default_member_welcome_mail_template, + $default_member_remainder_mail_template, + $default_member_review_and_summary_mail_template + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); + + + + $default_templates_inserted = $this->notificationModel->insertBatch([ + $default_member_welcome_mail_template, + $default_member_remainder_mail_template, + $default_member_review_and_summary_mail_template + ]); + + + return $default_templates_inserted ? true : false; + + + } + diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 564fc92..dcb7ec7 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -412,27 +412,48 @@ class EmployeeController extends AdminController * @return redirect back with an error message if the file is not found, otherwise sends the file to the user for download. */ - public function downloadSampleExcelFile($actionType = null) + public function downloadSampleExcelFile($actionType = null, $return_type = 0) { // $actionType = $this->request->getGet(); $filePath = ''; + // Path to your file if ($actionType == 'inception') { - $filePath = ROOTPATH . 'public/sample_excel/sample_inception.xls'; + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/sample_inception.xls') + : ROOTPATH . 'public/sample_excel/sample_inception.xls'; } else if ($actionType == 'correction') { - $filePath = ROOTPATH . 'public/sample_excel/sample_correction .xls'; + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/sample_correction.xls') + : ROOTPATH . 'public/sample_excel/sample_correction.xls'; } else if ($actionType == 'si_enhancement') { - $filePath = ROOTPATH . 'public/sample_excel/sample_si_enhancement.xls'; + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/sample_si_enhancement.xls') + : ROOTPATH . 'public/sample_excel/sample_si_enhancement.xls'; } else if ($actionType == 'dependent_addtion') { - $filePath = ROOTPATH . 'public/sample_excel/sample_dependent_addition.xls'; + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/sample_dependent_addition.xls') + : ROOTPATH . 'public/sample_excel/sample_dependent_addition.xls'; } else if ($actionType == 'addition') { - $filePath = ROOTPATH . 'public/sample_excel/sample_addition.xls'; + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/sample_addition.xls') + : ROOTPATH . 'public/sample_excel/sample_addition.xls'; } else if ($actionType == 'deletion') { - $filePath = ROOTPATH . 'public/sample_excel/sample_deletion.xls'; + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/sample_deletion.xls') + : ROOTPATH . 'public/sample_excel/sample_deletion.xls'; } else if ($actionType == 'enrollment') { - $filePath = ROOTPATH . 'public/sample_excel/enrollment.xlsx'; - }else if ($actionType == 'missed_inception') { - $filePath = ROOTPATH . 'public/sample_excel/sample_inception.xls'; + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/enrollment.xlsx') + : ROOTPATH . 'public/sample_excel/enrollment.xlsx'; + } else if ($actionType == 'missed_inception') { + $filePath = ($return_type == 1) + ? base_url('public/sample_excel/sample_inception.xls') + : ROOTPATH . 'public/sample_excel/sample_inception.xls'; + } + + if($return_type == 1){ + return $filePath; } // Check if the file exists diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 904f54a..0cd0fdd 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -504,7 +504,8 @@ class EmployeeRestController extends AdminController if ($dateTime instanceof \DateTime) { return $dateTime->format('Y-m-d'); } else { - return null; + // return null; + return change_date_format($dateString); } } @@ -799,9 +800,17 @@ class EmployeeRestController extends AdminController $empServiceController = new EmployeeServiceController(); $result = $empServiceController->excelFileFormatValidation(['file_id' => $file_id]); if(isset($result['error_summary']) && count($result['error_summary'])) - { - $result = $empServiceController->getExcelErrorData($file_id); - return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "file upload failed with errors",'data' => $result], 200); + { + if(isset($result['error_type'])){ + $result = $empServiceController->getExcelErrorData($file_id); + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "file upload failed with errors",'data' => $result], 200); + }else { + $message = "file upload failed with errors"; + if(isset($result['error_data'])){ + $message = $result['error_data']; + } + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => $message,'data' => $result], 200); + } } @@ -1093,9 +1102,19 @@ class EmployeeRestController extends AdminController }else{ return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Client id and Client Policy id is Not Match!" ], 404); } - } catch (\Exception $e) { - $this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine() . '----' . $e->getTraceAsString())); - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } catch (\Throwable $th) { + $this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine() . '----' . $th->getTraceAsString())); + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + return $this->respond(['status' => 'failed','code' => 500,'data' => $th->getMessage(), 'error_data' => $errorData], 500); } @@ -1781,7 +1800,7 @@ class EmployeeRestController extends AdminController $post_branch_id = $this->request->getGet('post_branch_id'); - if ($pre_client_id != null) { + if (!empty($pre_client_id)) { $client = $this->clientModel->where('id', $pre_client_id)->first(); @@ -1809,16 +1828,14 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404); } - } elseif ($post_client_id != null) { + } elseif (!empty($post_client_id)) { - $restAuthController = new RestAuthenticationController; $queryParams = [ 'client_id' => $post_client_id, 'client_branch_id' => $post_branch_id ]; - return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails'); } else { @@ -3426,6 +3443,7 @@ class EmployeeRestController extends AdminController $request = $this->request->getJSON(true); $mobile_no = $request['mobile_number'] ?? null; + $email_id = $request['email_id'] ?? null; $client_short_name = $request['client_short_name'] ?? null; log_message('error', 'STEP 2: Received input - ' . json_encode($request)); @@ -3434,12 +3452,16 @@ class EmployeeRestController extends AdminController $clientId = null; if (!empty($client_short_name)) { log_message('error', 'STEP 3: Looking up client with short_name: ' . $client_short_name); + $client_data = $this->clientModel ->where('is_active', 1) ->where('short_name', $client_short_name) ->first(); - if ($client_data) { + // $sql = "SELECT * FROM clients WHERE is_active = 1 AND short_name = ? LIMIT 1"; + // $client_data = db_connect()->query($sql, [$client_short_name])->getRowArray(); + + if (!empty($client_data)) { $clientId = $client_data['id']; log_message('error', 'STEP 4: Found client ID: ' . $clientId); } else { @@ -3450,8 +3472,8 @@ class EmployeeRestController extends AdminController } // Step 5: Validate mobile number - if (empty($mobile_no)) { - log_message('error', 'STEP 5: Mobile number is empty or null. Returning 0.'); + if (empty($mobile_no) && empty($email_id)) { + log_message('error', 'STEP 5: Mobile number and Email is empty or null. Returning 0.'); return $this->respond(['data' => 0]); } @@ -3469,7 +3491,6 @@ class EmployeeRestController extends AdminController ->where('cp.open_for_enrollment', 1) ->where('cp.policy_status', 1) ->whereIn('cp.policy_type_id', [1, 2, 6, 7]) - ->where('employees.mobile', $mobile_no) ->orderBy('employees.created_at', 'desc') ->groupBy('employee_polices.client_policy_id'); @@ -3480,6 +3501,16 @@ class EmployeeRestController extends AdminController log_message('error', 'STEP 7: No client ID filter applied.'); } + if (!empty($mobile_no)) { + $builder->where('employees.mobile', $mobile_no); + log_message('error', 'STEP 7: Applied mobile_no filter: ' . $mobile_no); + } + + if (!empty($email_id)) { + $builder->where('employees.email_corporate', $email_id); + log_message('error', 'STEP 7: Applied email_id filter: ' . $email_id); + } + $count = $builder->get()->getNumRows(); log_message('error', 'STEP 8: Final policy count = ' . $count); @@ -3491,6 +3522,8 @@ class EmployeeRestController extends AdminController } + + //-------------------------------------------------------------------------------------------- public function hrFileUpload() { @@ -3627,6 +3660,17 @@ class EmployeeRestController extends AdminController } } + public function downloadSampleExcel() + { + $employeeController = new EmployeeController(); + $file_path = $employeeController->downloadSampleExcelFile('enrollment', 1); + if(empty($file_path)){ + return $this->respond(['status' => "success", 'code' => 404, 'data' => "", "message" => "Sample file not avilable"], 200); + }else{ + return $this->respond(['status' => "success", 'code' => 200, 'data' => $file_path], 200); + } + + } } \ No newline at end of file diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 6140f45..9ce3443 100755 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -135,7 +135,7 @@ class LeadsController extends BaseController // dd($data); // Fetch leads data - $data ['lead_data_list'] = $this->leadsModel->getLeadDataForLising(); + $data['lead_data_list'] = $this->leadsModel->getLeadDataForLising(); // Load layout and pass data $this->loadLayout('leads_list', $data); diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index 0c3890f..88306b8 100755 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -246,7 +246,10 @@ class NotificationController extends AdminController // Insert file attachment record if ($this->MailAttachmentModel->insert($data)) { // Retrieve active attachments to return in response - $attachment_data = $this->MailAttachmentModel->where('is_active', 1)->findAll(); + $attachment_data = $this->MailAttachmentModel + ->where('notification_id',$find_notification['id']) + ->where('is_active', 1)->findAll(); + return $this->respond([ 'status' => true, 'code' => 200, diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index f187422..69d9e5e 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -152,6 +152,11 @@ class RestAuthenticationController extends AdminController } $otp = random_int(100000, 999999); + if($mobile_number == '9442741776') + { + $otp = '123456'; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: setting 123456 for IOS APP TESTING = " . json_encode($employeeData)); + } $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Final employee data to verify = " . json_encode($employeeData)); @@ -192,7 +197,14 @@ class RestAuthenticationController extends AdminController $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: Calling callThirdPartyAPI for updateEmpOTP"); } - + //skip sms for live test no + if($mobile_number == '9442741776') + { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyEmployeeWithMobileNumber: skip SMS sent for IOS APP TESTING = " . ($mobile_number)); + $result = ['user_verification' => true ,'message' => "Verified Successfully" ]; + return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + } //send sms $SMSResult = sendOtpSms($mobile_number, $otp); if ($SMSResult['status'] == 'success') @@ -551,6 +563,7 @@ class RestAuthenticationController extends AdminController ->first(); $otp = random_int(100000, 999999); + $data->otp = $otp; if ($HrData) { @@ -597,11 +610,9 @@ class RestAuthenticationController extends AdminController } else { // Call the third-party API function - $reqData = $this->request->getJSON(); - $reqData->otp = $otp; - return $this->callThirdPartyAPI($this->request->getJSON(),'verifyHrWithEmail'); - + return $this->callThirdPartyAPI($data,'verifyHrWithEmail'); } + } catch (\Throwable $th) { return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } @@ -617,9 +628,9 @@ class RestAuthenticationController extends AdminController if (isset($mobile_number)) { - $hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->where('otp', $otp)->first(); + $hrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->where('is_active', 1)->where('otp', $otp)->first(); }else{ - $hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('otp', $otp)->first(); + $hrData = $this->hrModel->where('email', $email)->where('contact_type', 'client')->where('is_active', 1)->where('otp', $otp)->first(); } if ($hrData) @@ -647,6 +658,9 @@ class RestAuthenticationController extends AdminController ->join('clients', 'client_branch.client_id = clients.id', 'left') ->where('level_contacts.mobile', $mobile_number ) ->where('level_contacts.contact_type', 'client') + ->where('level_contacts.is_active', 1) + ->where('clients.is_active', 1) + ->where('client_branch.is_active', 1) ->findAll(); //set otp value null $this->hrModel->where('mobile', $mobile_number)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update(); @@ -658,6 +672,9 @@ class RestAuthenticationController extends AdminController ->join('clients', 'client_branch.client_id = clients.id', 'left') ->where('level_contacts.email', $email ) ->where('level_contacts.contact_type', 'client') + ->where('level_contacts.is_active', 1) + ->where('clients.is_active', 1) + ->where('client_branch.is_active', 1) ->findAll(); //set otp value null $this->hrModel->where('email', $email)->where('otp', $otp)->where('contact_type', 'client')->set(['otp'=>null])->update(); @@ -1300,4 +1317,485 @@ class RestAuthenticationController extends AdminController } -} \ No newline at end of file + // -------------- EMP MOBILE NUMBER UPDATE API'S ------------------------------------------------------------------------------------------------------------- + + public function updateMobileNumber() + { + log_message('error', ' '); + log_message('error', ' ************************************* UPDATE MOBILE START **************************************** '); + log_message('error', ' '); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Function called"); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $payload = $this->request->getJSON(true); + + $email_id = $payload['email_id'] ?? null; + $new_mobile = $payload['new_mobile_number'] ?? null; + + if (empty($email_id) || empty($new_mobile)) { + return $this->respond([ + 'status' => 'failed', + 'code' => 400, + 'message' => 'Email ID and new mobile number are required' + ], 400); + } + + $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id]); + // print_r($empdata); die; + + if(empty($empdata)){ + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: No employee data found both PRE & POST"); + log_message('error', ' '); + log_message('error', '************************ PRE END ********************************'); + $result = ['user_verification' => false , 'message' => "User not found"]; + return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); + } + + $employeeData = []; + if (isset($empdata['pre']) && !empty($empdata['pre'])) { + $employeeData = $empdata['pre']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Using PRE data"); + } + + if (isset($employeeData['employee_id'])) + { + // Update mobile number + $updated = $this->employeeModel->update($employeeData['employee_id'], [ + 'mobile' => $new_mobile, + ]); + + if ($updated) { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Mobile number updated successfully"); + log_message('error', ' '); + log_message('error', ' ************************************* UPDATE MOBILE END **************************************** '); + log_message('error', ' '); + + //If post-enrollment data exist update the same mobile number from pre-enrollment. + if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + + $payload['client_id'] = $empdata['post']['client_id']; + $payload['employee_id'] = $empdata['post']['employee_id']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Client_id and employee_id from POST data to update the Mobile number"); + + $this->callThirdPartyAPI($payload, 'updateMobileNumber'); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Calling callThirdPartyAPI for updateMobileNumber"); + } + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'Mobile number updated successfully', + ], 200); + + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Failed to update mobile number"); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Failed to update mobile number' + ], 500); + } + + }else{ + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Employee not found with email in the PRE DATABASE, falling back to third-party API"); + + // Call the third-party API function + if (!empty($empdata['post']['client_id'])) { + $payload->client_id = $empdata['post']['client_id']; + } + return $this->callThirdPartyAPI($payload, 'updateMobileNumber'); + log_message('error', ' '); + log_message('error', '************************ PRE END ********************************'); + + } + + } catch (\Throwable $th) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Exception: " . $th->getMessage()); + + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Exception occurred', + 'error_data' => $errorData + ], 500); + } + } + + // ------------------------------------------------------------------------------------------------------------------------------------------------------------ + + public function savePassword() + { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Received payload = " . json_encode($this->request->getJSON() ?? [])); + try { + + $payload = $this->request->getJSON(); + // print_r($payload); die; + $mobile_number = $payload->mobile_number ?? null; + $email_id = $payload->email_id ?? null; + $client_id = $payload->client_id ?? null; + $plain_password = $payload->password ?? null; + $confirm_password = $payload->confirm_password ?? null; + + if (empty($plain_password) || empty($confirm_password)) { + return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Both password cannot be empty'], 400); + } + + if($plain_password !== $confirm_password){ + return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Password and confirm password not matched'], 400); + } + + $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number ]); + // print_r($empdata); die; + + if(empty($empdata)){ + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: No employee data found both PRE and POST"); + $result = ['user_verification' => false , 'message' => "User not found"]; + return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); + } + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: empdata = " . json_encode($empdata)); + + $employeeData = []; + if (isset($empdata['pre']) && !empty($empdata['pre'])) { + $employeeData = $empdata['pre']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Using PRE data from empdata"); + } + + if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + $payload->client_id = $empdata['post']['client_id']; + $payload->employee_id = $empdata['post']['employee_id']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Added client_id & employee_id to requestData to get the POST employee data"); + } + + if (isset($employeeData['employee_id'])) { + + $id = $employeeData['employee_id']; + $hashedPassword = password_hash($plain_password, PASSWORD_DEFAULT); + + $updateData = [ + 'password' => $hashedPassword, + ]; + + $updated = $this->employeeModel->where('id', $id)->set($updateData)->update(); + + if ($updated) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Password saved successfully"); + $this->callThirdPartyAPI($payload, 'savePassword'); + $result = ['user_verification' => true, 'message' => "Password saved successfully"]; + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Password save failed"); + $result = ['user_verification' => true, 'message' => "Password not saved"]; + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $result], 200); + } + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Employee not found with email or mobile in the PRE DATABASE, falling back to third-party API"); + $result = ['user_verification' => false, 'message' => "User not found"]; + return $this->callThirdPartyAPI($payload, 'savePassword'); + } + + } catch (\Throwable $th) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString()); + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + return $this->respond(['status' => 'failed', 'code' => 500, 'message' => $th->getMessage(), 'error_data' => $errorData], 500); + } + } + + public function changePassword() + { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $payload = $this->request->getJSON(true); + $mobile_number = $payload['mobile_number'] ?? null; + $email_id = $payload['email_id'] ?? null; + $client_id = $payload['client_id'] ?? null; + $old_password = $payload['old_password'] ?? null; + $new_password = $payload['new_password'] ?? null; + $confirm_password = $payload['confirm_password'] ?? null; + + if (empty($new_password) || empty($confirm_password) || empty($old_password)) { + return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'old_password , New password and Confirm password are required' ], 400); + } + + // Fetch employee details + $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number ]); + // print_r($empdata); die; + + if(empty($empdata)){ + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: No employee data found both PRE and POST"); + $result = ['user_verification' => false , 'message' => "User not found"]; + return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); + } + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: empdata = " . json_encode($empdata)); + + $employeeData = []; + if (isset($empdata['pre']) && !empty($empdata['pre'])) { + $employeeData = $empdata['pre']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Using PRE data from empdata"); + } + + if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + $payload['client_id'] = $empdata['post']['client_id']; + $payload['employee_id'] = $empdata['post']['employee_id']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Added client_id & employee_id to requestData to get the POST employee data"); + } + + if (isset($employeeData['employee_id']) && password_verify($old_password, $employeeData['password'])) { + + // Hash new password + $newHashedPassword = password_hash($new_password, PASSWORD_DEFAULT); + + // Update password and clear OTP + $updated = $this->employeeModel->update($employeeData['employee_id'], [ + 'password' => $newHashedPassword, + ]); + + if ($updated) { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Password updated successfully"); + + // Call the third-party API function + $this->callThirdPartyAPI($payload, 'changePassword'); + return $this->respond(['status' => 'success','code' => 200,'message' => 'Password changed successfully' ], 200); + } else { + return $this->respond(['status' => 'failed','code' => 500,'message' => 'Failed to update password'], 500); + } + + }else{ + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Employee not verified - calling third-party API fallback to get the POST employee data"); + + // Call the third-party API function + return $this->callThirdPartyAPI($payload, 'changePassword'); + } + + } catch (\Throwable $th) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Exception: " . $th->getMessage()); + return $this->respond(['status' => 'failed', 'code' => 500, 'message' => $th->getMessage()], 500); + } + } + + public function verifyPassword() + { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $requestData = $this->request->getJSON(true); + $mobile_number = $requestData['mobile_number'] ?? null; + $email_id = $requestData['email_id'] ?? null; + $client_id = $requestData['client_id'] ?? null; + $password = $requestData['password'] ?? null; + + if (!$password) { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => "", 'message' => 'Password is required'], 400); + } + + // ๐Ÿ”น Fetch employee data + $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number]); + // print_r($empdata); die; + + if(empty($empdata)){ + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyMpin: No employee data found both PRE and POST"); + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => ""], 200); + } + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyMpin: empdata = " . json_encode($empdata)); + + $employeeData = []; + if (isset($empdata['pre']) && !empty($empdata['pre'])) { + $employeeData = $empdata['pre']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyMpin: Using PRE data from empdata"); + } + + if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + $requestData['client_id'] = $empdata['post']['client_id']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyMpin: Added client_id to requestData to get the POST employee data"); + } + + // ๐Ÿ”น Verify password hash + if (isset($employeeData['employee_id']) && password_verify($password, $employeeData['password'])) { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Verified employee found"); + + // โœ… Log authentication info + $auth = HttpRequestHelper::getRequestInfo(); + if ($auth) { + $this->authHistoryModel->insert([ + 'user_id' => $employeeData['employee_id'], + 'user_type' => 'employee', + 'ip' => $auth['ip'], + 'platform' => $auth['platform'], + 'broswer' => $auth['browser'], + ]); + } + + // โœ… Generate JWT token + unset($employeeData['employee_id']); + $employeeData['token_type'] = "pre"; + $token = JWTToken::encode($employeeData); + + // Call the third-party API function + $apiResponse = $this->callThirdPartyAPI($requestData, 'verifyPassword'); + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $token, 'post_enrollment' => json_decode($apiResponse, true)], 200); + + } else { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Employee not verified - calling third-party API fallback to get the POST employee data"); + + // Call the third-party API function + $apiResponse = $this->callThirdPartyAPI($requestData, 'verifyPassword'); + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => "", 'post_enrollment' => json_decode($apiResponse, true)], 200); + } + + } catch (\Throwable $th) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine()); + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => "", 'message' => $th->getMessage(), 'error_data' => $errorData], 500); + } + } + + public function verifyOtp() + { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $requestData = $this->request->getJSON(true); + $mobile_number = $requestData['mobile_number'] ?? null; + $email_id = $requestData['email_id'] ?? null; + $client_id = $requestData['client_id'] ?? null; + $otp = $requestData['otp'] ?? null; + + if (!$otp) { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => "", 'message' => 'OTP is required'], 400); + } + + // ๐Ÿ”น Fetch employee data + $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number]); + // print_r($empdata); die; + + if(empty($empdata)){ + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: No employee data found both PRE and POST"); + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => ""], 200); + } + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: empdata = " . json_encode($empdata)); + + $employeeData = []; + if (isset($empdata['pre']) && !empty($empdata['pre'])) { + $employeeData = $empdata['pre']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Using PRE data from empdata"); + } + + if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + $requestData['client_id'] = $empdata['post']['client_id']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Added client_id to requestData to get the POST employee data"); + } + + // ๐Ÿ”น Verify password hash + if ($employeeData && $employeeData['otp'] == $otp) { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Verified employee found"); + $this->employeeModel->where('id', $employeeData['id'])->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update(); + return $this->respond(['status' => 'success', 'code' => 200, 'message' => "OTP verified succesfully"], 200); + + } else { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Employee not verified - calling third-party API fallback to get the POST employee data"); + + // Call the third-party API function + return $this->callThirdPartyAPI($requestData, 'verifyOtp'); + } + + } catch (\Exception $e) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyOtp: Exception: " . $e->getMessage() . " --- Line: " . $e->getLine()); + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => "", 'message' => $e->getMessage()], 500); + } + } + + public function checkPassword() + { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Request payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $payload = $this->request->getJSON() ?? []; + $mobile_number = $payload->mobile_number ?? null; + $email_id = $payload->email_id ?? null; + + $empdata = RestAuthHelper::getPreAndPostDataByEmailOrMobile(['email_id' => $email_id, 'mobile_number' => $mobile_number, 'check_mpin' => true]); + // print_r($empdata); die; + + if(empty($empdata)){ + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: No employee data found both PRE and POST"); + return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200); + } + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: empdata = " . json_encode($empdata)); + + $employeeData = []; + if (isset($empdata['pre']) && !empty($empdata['pre'])) { + $employeeData = $empdata['pre']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Using PRE data from empdata"); + } + + $requestData = $this->request->getJSON(); + if (isset($empdata['post']['client_id']) && !empty($empdata['post']['client_id'])) { + $requestData->client_id = $empdata['post']['client_id']; + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Added client_id to requestData to get the POST employee data"); + } + + + if ($employeeData && $employeeData["password"] != null) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Mpin - Exist"); + return $this->respond(['status' => 'success','code' => 200,'data' => "", 'message' => "Password - exist"],200); + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - checkPassword: Password - not found in PRE so call the thirdpartapi to the POST to check the MPIN"); + return $this->callThirdPartyAPI($requestData, 'checkPassword'); + } + + } catch (\Exception $e) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - Exception: " . $e->getMessage() . " --- Line: " . $e->getLine() . " --- Trace: " . $e->getTraceAsString()); + return $this->respond(['status' => 'failed','code' => 500,'data' => "", 'message' => $e->getMessage()],500); + } + } + +} + diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php new file mode 100644 index 0000000..90c2e87 --- /dev/null +++ b/app/Controllers/TestingController.php @@ -0,0 +1,100 @@ +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 or Failed')); + + 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/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 79a9b23..37fc8e2 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -979,6 +979,7 @@ if (!function_exists('calculate_premium_new')) //4. if macthed then the current rack rate is applicable and find common variables link max age,max count,grade, basic pay,SI, self/acting self for current rack rate + // log_message('error', 'CALCULATION_MEMBER_PREMIUM_FAMIL_DATA ' . json_encode($family_data)); foreach($family_data as $fkey => $member) { // dd($member); @@ -992,6 +993,13 @@ if (!function_exists('calculate_premium_new')) $member[6] = $family_data[0][6]; $member[10] = $family_data[0][10]; $member[18] = $family_data[0][18]; + + // If the member's date of coverage is empty, then use the selfโ€™s date of coverage + if(empty($member[7])){ + $member[7] = $family_data[0][7]; + } + + // log_message('error', 'CALCULATION_MEMBER_PREMIUM ' . json_encode($member)); //set default unit if unit is not available in self/members level if(empty($member[18])){ $member[18] = $existing_units[0]; } //transform as db row column diff --git a/app/Helpers/header.php b/app/Helpers/header.php index 2ade2b0..7f3f66e 100755 --- a/app/Helpers/header.php +++ b/app/Helpers/header.php @@ -56,18 +56,18 @@ - + + +
@@ -5,6 +71,18 @@
+ +
+ +
+ +
+
@@ -322,6 +400,9 @@ $(document).ready(function() { // Get today's date var today = new Date(); + + const showExpired = $('#chk-show-expired').is(':checked'); + var startDatePicker = flatpickr("#start_date", { dateFormat: "d-m-Y", defaultDate: today, @@ -436,7 +517,8 @@ $(document).ready(function() { si_mapping = ` SI Mapping`; } - + if(showExpired == false && checkDateStatus(item.policy_end_date) != 'Expired'){ + policyTable += ` @@ -457,7 +539,7 @@ $(document).ready(function() { ${auto_si_menu} ${si_mapping}`; // Conditionally render the delete option based on the role - if (role !== 3 && role !== 4) { + if (role != 3 && role != 4) { policyTable += ` Delete`; @@ -470,6 +552,7 @@ $(document).ready(function() { `; + } }); $('#policy_table').append(policyTable); @@ -478,9 +561,11 @@ $(document).ready(function() { $('#table-client-policy').DataTable({ - paging: true, - searching: false, - // ordering: false + paging: true, + searching: true, + autoWidth: false, + responsive: true, + }); @@ -491,6 +576,8 @@ $('.btnAdd').click(function() { fetchClientBranch() + $('#notification_slider').hide(); + $('#policy_form')[0].reset(); $('#add_form').show(); $('#table_list').hide(); @@ -524,6 +611,7 @@ $('.btnAdd').click(function() { $('.btnBack').click(function() { + $('#notification_slider').show(); $('#policy_form')[0].reset(); $('#add_form').hide(); $('#table_list').show(); @@ -548,6 +636,8 @@ $("#policy_form").submit(function(event) { event.preventDefault(); + $('#notification_slider').show(); + policy_PrimaryKey = $('#client_id_policy').val(); policy_client = $('#policy_PrimaryKey').val(); @@ -689,6 +779,8 @@ $("#policy_form").submit(function(event) { auto_si_menu = `Auto SI`; } + if(checkDateStatus(item.policy_end_date) != 'Expired'){ + policyTable += ` @@ -709,20 +801,24 @@ $("#policy_form").submit(function(event) { Rack Rate ${auto_si_menu}`; - // Conditionally render the delete option based on the role - if (role !== 3 && role !== 4) { - policyTable += - ` - Delete`; - } + // Conditionally render the delete option based on the role + if (role != 3 && role != 4) { + policyTable += + ` + Delete`; + } - policyTable += ` - - - - - `; - }); + policyTable += ` + + + + + `; + + + } + + }); $('#policy_table').append(policyTable); // console.log(policyTable); @@ -748,7 +844,11 @@ $("#policy_form").submit(function(event) { //console.log('Unknown error occurred', 'Warning'); } }, 1000); + }, + complete:function(){ + $('notification_slider').show(); } + }); }); @@ -812,6 +912,9 @@ $('body').on('click', '.btnPolicyEdit', function() { var policy_form_action = ''; var policy_id = $(this).attr('data-id'); + + $('#notification_slider').hide(); + $('.loader').fadeIn(); $('.loader-mask').fadeIn(); @@ -1035,6 +1138,10 @@ $('body').on('click', '.btnPolicyEdit', function() { $('.loader-mask').delay(350).fadeOut('slow'); //console.log('Something Wrong!', 'warning'); }, 1000); + }, + complete:function() { + $('#notification_slider').hide(); + console.log('complete call'); } }); }); @@ -2142,4 +2249,174 @@ function featchClient() { //---------------------------------------------------------------------------------------------------- + + + \ No newline at end of file diff --git a/app/Views/enrollment_list.php b/app/Views/enrollment_list.php index bc59899..8d3810d 100755 --- a/app/Views/enrollment_list.php +++ b/app/Views/enrollment_list.php @@ -99,10 +99,8 @@
-
- -
+
@@ -111,7 +109,6 @@
Emp Count

0

-
@@ -168,10 +165,20 @@
+
+
+
+
+
+
Draft
+

0

+
+
+
+
+
- - @@ -297,16 +304,16 @@ }); } - function filterTable(columnIndex, filterValue) - { - var table = $('#tickets-table').DataTable(); + // function filterTable(columnIndex, filterValue) + // { + // var table = $('#tickets-table').DataTable(); - // Reset the search filter for all columns - table.columns().search('').draw(); + // // Reset the search filter for all columns + // table.columns().search('').draw(); - // Apply the filter to the specified column - table.column(columnIndex).search(filterValue).draw(); - } + // // Apply the filter to the specified column + // table.column(columnIndex).search(filterValue).draw(); + // } function fetchEmpolyeeList(event) { @@ -357,28 +364,45 @@ return; } var enrolled_count = 0; + var not_enrolled_count = 0; var loggedIn_count = 0; + var not_loggedIn_count = 0; + var self_count = 0; + var draft_count = 0; + data.forEach(function(employee, index) { + if(employee.relationship.toLowerCase() === "self"){ + self_count++ + } + if(employee.emp_status === 'enrolled'){ var enrolled = 'Yes'; enrolled_count++; }else{ var enrolled = 'No'; + if (employee.relationship.toLowerCase() === "self") { + not_enrolled_count++; + } } - if(employee.user_type === 'employee'){ + if(employee.relationship.toLowerCase() === "self" && employee.user_type === 'employee'){ var loggedIn = 'Yes'; loggedIn_count++; }else{ if (employee.relationship && employee.relationship.toLowerCase() === "self") { var loggedIn = 'No'; + not_loggedIn_count ++; }else{ var loggedIn = '-'; } } + if(employee.relationship.toLowerCase() === "self" && enrolled == "No" && loggedIn == "Yes"){ + draft_count++; + } + table.row.add([ index + 1, employee.employee_name, @@ -387,15 +411,15 @@ enrolled, loggedIn ]); - - $('#emp_count_view').html(data.length); - $('#emp_enrolled_view').html(enrolled_count); - $('#emp_not_enrolled_view').html(data.length - enrolled_count); - $('#emp_logged_in_view').html(loggedIn_count); - $('#emp_not_logged_in_view').html(data.length - loggedIn_count); - }); + $('#emp_count_view').html(self_count); + $('#emp_enrolled_view').html(enrolled_count); + $('#emp_not_enrolled_view').html(not_enrolled_count); + $('#emp_logged_in_view').html(loggedIn_count); + $('#emp_not_logged_in_view').html(not_loggedIn_count); + $('#emp_draft_view').html(draft_count); + table.draw(); function getUrlParameter(name) { @@ -490,91 +514,167 @@ }); - $('#emp_enrolled_view_click').on('click', function() { + // $('#emp_enrolled_view_click').on('click', function() { - console.log($(this).hasClass('click_hover')); - if ($(this).hasClass('click_hover')) { - // $(this).removeClass('click_hover'); - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - table.columns().search('').draw(); // Clear all filters and show all data - }else{ - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - $('#emp_enrolled_view_click').addClass('click_hover'); - filterTable(4, 'Yes'); // Filter "Enrolled" column (4th column, index 3) - } + // console.log($(this).hasClass('click_hover')); + // if ($(this).hasClass('click_hover')) { + // // $(this).removeClass('click_hover'); + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // table.columns().search('').draw(); // Clear all filters and show all data + // }else{ + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // $('#emp_enrolled_view_click').addClass('click_hover'); + // filterTable(4, 'Yes'); // Filter "Enrolled" column (4th column, index 3) + // } + // }); + + // $('#emp_not_enrolled_view_click').on('click', function() { + // if ($(this).hasClass('click_hover')) { + // // $(this).removeClass('click_hover'); + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // table.columns().search('').draw(); // Clear all filters and show all data + // }else{ + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // $('#emp_not_enrolled_view_click').addClass('click_hover'); + // filterTable(4, 'No'); // Filter "Enrolled" column (4th column, index 3) + // } + // }); + + // $('#emp_logged_in_view_click').on('click', function() { + // if ($(this).hasClass('click_hover')) { + // // $(this).removeClass('click_hover'); + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // table.columns().search('').draw(); // Clear all filters and show all data + // }else{ + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // $('#emp_logged_in_view_click').addClass('click_hover'); + // filterTable(5, 'Yes'); // Filter "Logged-In" column (5th column, index 4) + // } + // }); + + // $('#emp_not_logged_in_view_click').on('click', function() { + // if ($(this).hasClass('click_hover')) { + // // $(this).removeClass('click_hover'); + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // table.columns().search('').draw(); // Clear all filters and show all data + // }else{ + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // $('#emp_not_logged_in_view_click').addClass('click_hover'); + // filterTable(5, 'No'); // Filter "Logged-In" column (5th column, index 4) + // } + // }); + + // $('#emp_draft_view_click').on('click', function() { + // var table = $('#tickets-table').DataTable(); + + // if ($(this).hasClass('click_hover')) { + // // Remove active class and reset filters + // $('.click_hover').removeClass('click_hover'); + // table.columns().search('').draw(); // Clear all filters + // } else { + // // Remove existing active state and set new one + // $('.click_hover').removeClass('click_hover'); + // $(this).addClass('click_hover'); + + // // Apply both filters simultaneously + // filterTableMultiple([ + // { column: 5, value: 'Yes' }, + // { column: 4, value: 'No' } + // ]); + // } + // }); + + // $('#emp_count_view_click').on('click', function() { + // if ($(this).hasClass('click_hover')) { + // // $(this).removeClass('click_hover'); + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // table.columns().search('').draw(); // Clear all filters and show all data + // }else{ + // $('.click_hover').each(function() { + // $(this).removeClass('click_hover'); + // }); + // $('#emp_count_view_click').addClass('click_hover'); + // table.columns().search('').draw(); // Clear all filters and show all data + // } + // }); + + // === Attach click handlers === + $('#emp_enrolled_view_click').on('click', function() { + handleFilterClick('emp_enrolled_view_click', [{ column: 4, value: 'Yes' }]); }); $('#emp_not_enrolled_view_click').on('click', function() { - if ($(this).hasClass('click_hover')) { - // $(this).removeClass('click_hover'); - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - table.columns().search('').draw(); // Clear all filters and show all data - }else{ - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - $('#emp_not_enrolled_view_click').addClass('click_hover'); - filterTable(4, 'No'); // Filter "Enrolled" column (4th column, index 3) - } + handleFilterClick('emp_not_enrolled_view_click', [ + { column: 3, value: 'Self' }, + { column: 4, value: 'No' } + ]); }); $('#emp_logged_in_view_click').on('click', function() { - if ($(this).hasClass('click_hover')) { - // $(this).removeClass('click_hover'); - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - table.columns().search('').draw(); // Clear all filters and show all data - }else{ - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - $('#emp_logged_in_view_click').addClass('click_hover'); - filterTable(5, 'Yes'); // Filter "Logged-In" column (5th column, index 4) - } + handleFilterClick('emp_logged_in_view_click', [{ column: 5, value: 'Yes' }]); }); $('#emp_not_logged_in_view_click').on('click', function() { - if ($(this).hasClass('click_hover')) { - // $(this).removeClass('click_hover'); - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - table.columns().search('').draw(); // Clear all filters and show all data - }else{ - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - $('#emp_not_logged_in_view_click').addClass('click_hover'); - filterTable(5, 'No'); // Filter "Logged-In" column (5th column, index 4) - } + handleFilterClick('emp_not_logged_in_view_click', [{ column: 5, value: 'No' }]); + }); + + // ๐Ÿ”น Attach click handlers + $('#emp_draft_view_click').on('click', function() { + handleFilterClick('emp_draft_view_click', [ + { column: 5, value: 'Yes' }, // Logged-in = Yes + { column: 4, value: 'No' } // Enrolled = No + ]); }); $('#emp_count_view_click').on('click', function() { - if ($(this).hasClass('click_hover')) { - // $(this).removeClass('click_hover'); - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - table.columns().search('').draw(); // Clear all filters and show all data - }else{ - $('.click_hover').each(function() { - $(this).removeClass('click_hover'); - }); - $('#emp_count_view_click').addClass('click_hover'); - table.columns().search('').draw(); // Clear all filters and show all data - } + // Just reset all filters โ€” no column filter needed + handleFilterClick('emp_count_view_click', [{ column: 3, value: 'Self' }]); }); toggleContent(); }); + // Common function to handle DataTable filter toggling + function handleFilterClick(buttonId, filters = null) { + var table = $('#tickets-table').DataTable(); + var $button = $('#' + buttonId); + + if ($button.hasClass('click_hover')) { + // Remove highlight and clear filters + $('.click_hover').removeClass('click_hover'); + table.columns().search('').draw(); + } else { + // Remove existing active state, set new one + $('.click_hover').removeClass('click_hover'); + $button.addClass('click_hover'); + + // Apply multiple filters (array of {column, value}) + table.columns().search(''); // clear existing filters + if(filters){ + filters.forEach(f => table.column(f.column).search(f.value)); + } + table.draw(); + } + } + function toggleContent() { var content = document.getElementById("statusContent"); diff --git a/app/Views/layout/footer.php b/app/Views/layout/footer.php index 5026672..a412cef 100755 --- a/app/Views/layout/footer.php +++ b/app/Views/layout/footer.php @@ -85,8 +85,8 @@ - - + + diff --git a/app/Views/layout/footer_old.php b/app/Views/layout/footer_old.php index ac8fee4..fc456fd 100644 --- a/app/Views/layout/footer_old.php +++ b/app/Views/layout/footer_old.php @@ -85,8 +85,8 @@ - - + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index aa201ad..586695f 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -62,9 +62,9 @@ - + - --> diff --git a/app/Views/layout/header_new.php b/app/Views/layout/header_new.php index 28af0f0..297f7f2 100644 --- a/app/Views/layout/header_new.php +++ b/app/Views/layout/header_new.php @@ -62,18 +62,18 @@ - + diff --git a/app/Views/layout/header_old.php b/app/Views/layout/header_old.php index aa201ad..80e7a83 100644 --- a/app/Views/layout/header_old.php +++ b/app/Views/layout/header_old.php @@ -62,18 +62,18 @@ - + diff --git a/app/Views/mail_template.php b/app/Views/mail_template.php index 2eb5f07..e4f6f20 100644 --- a/app/Views/mail_template.php +++ b/app/Views/mail_template.php @@ -1,3 +1,20 @@ + + @@ -10,8 +27,8 @@ @@ -47,15 +85,21 @@ -
+
- - + -
- Client Logo +
+