From f6882f9b2f903eae487a2876aabd099c0a67bd4e Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 26 Jul 2024 11:24:47 +0530 Subject: [PATCH] CHANGE_ENROLLMENT_STATUS_AND_REMINDER_MAIL : AADHAVAN --- app/Config/Routes.php | 3 +- app/Controllers/ClientController.php | 29 +- app/Controllers/DashboardController.php | 1 - app/Controllers/EmployeeController.php | 13 +- app/Controllers/JobWorker.php | 72 +++++ app/Helpers/sendMailNotification.php | 48 +++- app/Models/ClientPolicyModel.php | 1 + app/Views/client_policy.php | 41 +++ app/Views/enrollment_dash.php | 337 ++++++++++++++++++++---- app/Views/enrollment_list.php | 44 ++++ app/Views/layout/header.php | 9 +- 11 files changed, 512 insertions(+), 86 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b701d493..a94471e9 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -138,7 +138,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->post("upload", "EmployeeController::employeesUplodWithEvents"); $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); $routes->get("endorsement-list", "EmployeeController::endorsementList"); - $routes->get("enrollment-list", "EmployeeController::enrollmentClientList"); + $routes->match(['get','post'],'enrollment-list','EmployeeController::enrollmentClientList'); $routes->get("empby_client_clientbranch/(:any)/(:any)", "EmployeeController::empby_client_clientbranch/$1/$2"); $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); }); @@ -270,6 +270,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->cli('cli/processjob', 'JobWorker::processJob'); $routes->cli('cli/processjobs', 'JobWorker::processJobs'); +$routes->cli('cli/enrollment_status', 'JobWorker::enrollment_status'); $routes->get("processjob", "JobWorker::processJob"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 788a31ca..5ffe24f3 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -729,7 +729,7 @@ class ClientController extends AdminController $base_policy = $this->request->getPost('base_policy'); - $insurerValue = (string) $this->request->getPost('insurer'); + $insurerValue = (string) $this->request->getPost('insurer'); list($insurerBranchId, $insurerId) = explode('-', $insurerValue); @@ -814,8 +814,17 @@ class ClientController extends AdminController $data['policy_no'] = $this->request->getPost('policy_no'); - $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); - $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + if($data['inception_type'] == 2){ + $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); + $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + $data['reminder_date'] = change_date_format($this->request->getPost('reminder_date'), 'd-m-Y', 'Y-m-d'); + + }else{ + $data['policy_start_date'] = null; + $data['policy_end_date'] = null; + $data['reminder_date'] = null; + } + $data['created_by'] = get_session_userid(); $insert = $this->clientPolicyModel->insert($data); @@ -851,8 +860,8 @@ class ClientController extends AdminController $data['tpa_id'] = $tpaId; $data['policy_type_id'] = $this->request->getPost('policy_type_id'); $data['policy_no'] = $this->request->getPost('policy_no'); - $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); - $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + // $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); + // $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); $data['insured'] = $this->request->getPost('insured'); $data['no_of_lives'] = $this->request->getPost('no_of_lives'); @@ -874,6 +883,16 @@ class ClientController extends AdminController $data['cd_ac_no'] = $this->request->getPost('cd_ac_no'); $data['gst'] = $this->request->getPost('gst'); + if($data['inception_type'] == 2){ + $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); + $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + $data['reminder_date'] = change_date_format($this->request->getPost('reminder_date'), 'd-m-Y', 'Y-m-d'); + }else{ + $data['policy_start_date'] = null; + $data['policy_end_date'] = null; + $data['reminder_date'] = null; + } + if($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 3 || $policy_type_id == 6 || $policy_type_id == 7){ $data['is_addon'] = 1; diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 43ebcb94..7a29a9a3 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -35,7 +35,6 @@ class DashboardController extends AdminController { $data = []; - $results = $this->clientModel->select('clients.id as client_id, clients.client_name, clients.short_name, client_branch.id as client_branch_id, client_branch.branch_name, client_branch.branch_code, employees.id as employee_id, diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 96458c17..ea0b306a 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -674,8 +674,15 @@ class EmployeeController extends AdminController $branch_list = $this->clientBranchModel->findAll(); $data['client_list'] = $client_list; $data['branch_list'] = $branch_list; - $this->myLogger->logme('error', 'list called'); - $this->loadLayout('enrollment_list', $data); + + // Get session data if available + $data['selected_client_id'] = session()->get('client_id'); + $data['selected_branch_id'] = session()->get('branch_id'); + $data['selected_type'] = session()->get('type'); + + $this->myLogger->logme('error', 'list called'); + return $this->loadLayout('enrollment_list', $data); + } public function empby_client_clientbranch($client_id, $branch_id) @@ -718,7 +725,7 @@ class EmployeeController extends AdminController $employeeId = $row['employee_id']; } - + return json_encode($groupedData); } diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index 38fd648a..21ba4e84 100644 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -4,6 +4,13 @@ namespace App\Controllers; use App\Models\JobModel; +use App\Models\ClientModel; +use App\Models\ClientPolicyModel; +use App\Models\NotificationModel; +use App\Models\EmployeePolicyModel; + +use App\Helpers\sendMailNotification; + class JobWorker extends AdminController { const STATUS_DONE = 'done'; @@ -228,6 +235,71 @@ class JobWorker extends AdminController } + public static function enrollment_status() { + $clientModel = new ClientModel(); + $clientPolicyModel = new ClientPolicyModel(); + $notificationModel = new NotificationModel(); + $employeePolicyModel = new EmployeePolicyModel(); + $myLogger = \Config\Services::mylogger(); + + $client_policy_data = $clientPolicyModel->where('is_active', 1) + ->where('policy_status', 1) + ->where('inception_type', 2) + ->findAll(); + $currentDate = date('Y-m-d'); + + // Update policy status based on start and end dates + foreach ($client_policy_data as $client_policy) { + $id = $client_policy['id']; + + if ($currentDate == $client_policy['policy_start_date']) { + $clientPolicyModel->update($id, ['open_for_enrollment' => 1]); + } + if ($client_policy['policy_end_date'] < $currentDate) { + $clientPolicyModel->update($id, ['open_for_enrollment' => 0]); + } + } + + $reminder_whole_mail = []; + foreach ($client_policy_data as $client_policy) { + $employee = $employeePolicyModel->select('employees.*') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->first(); + $client_data = $clientModel->find($client_policy['client_id']); + $notification_data = $notificationModel->where('client_id', $client_policy['client_id']) + ->where('template_name', 'member_reminder_mail') + ->first(); + + if ($notification_data && $notification_data['enabled'] == 1 && $currentDate == $client_policy['reminder_date']) { + $params['emp_data'] = $employee; + $params['client_data'] = $client_data; + $params['notification_data'] = $notification_data; + $reminder_whole_mail[] = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + } + } + // Process and queue bulk emails + $temp_whole_data = []; + $count = 0; + foreach ($reminder_whole_mail as $whole_index => $values) { + foreach ($values as $index => $value) { + $temp_whole_data[] = $value; + $count++; + + if ($count == 20 || ($whole_index == count($reminder_whole_mail) - 1 && $index == count($values) - 1)) { + if (!empty($temp_whole_data)) { + Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $temp_whole_data]); + $temp_whole_data = []; + $count = 0; + } + } + } + } + + return json_encode(true); + } + + } diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 5a35ccd2..cd0bda80 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -12,7 +12,7 @@ class sendMailNotification { public static function sendMailNotification($action, $params) { - print_r($params);die; + $wholeData =[]; if ($action == 'member_welcome_mail') { $dataToInsert = $params['dataToInsert']; $notification = $params['notification']; @@ -37,7 +37,6 @@ class sendMailNotification } return $wholeData; } else if($action == 'member_reminder_mail'){ - $EmployeeModel = new EmployeeModel(); $emp_data = $params['emp_data']; $notification_data = $params['notification_data']; @@ -51,27 +50,46 @@ class sendMailNotification $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); - if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) { + if(isset($emp_data['relationship'])){ + if ($emp_data['relationship'] == 'Self') { + if(count($emp_data) > 0){ + $mail =''; + if ($emp_data['relationship'] == 'Self') { + $employee_name =$emp_data['name']; + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail = $emp_data['email_corporate']; + } + } + }else{ + $mail =''; + } + + }else{ + $employee_name =$emp_data['name']; + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail = $emp_data['email_corporate']; + } + + if (isset($mail) && !empty($mail)) { + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + } + }else{ foreach ($emp_data as $key => $value) { - if ($value['relationship'] != 'Self') { - + if ($value['relationship'] != 'Self') { $emp_data = $EmployeeModel->where('client_id', $client_data['id'])->where('emp_code', $value['emp_code'])->where('is_active',1)->findAll(); - if(count($emp_data) > 1){ $mail =''; foreach ($emp_data as $key => $values) { if ($value['relationship'] == 'Self') { $employee_name =$values['name']; $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail = $values['email_corporate']; } } }else{ $mail =''; } - }else{ $employee_name =$value['name']; $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); @@ -81,13 +99,15 @@ class sendMailNotification $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; } } - if (count($wholeData) < 1) { - $wholeData = []; - } - return $wholeData; - }else{ - return "false"; } + + if (count($wholeData) < 1) { + $wholeData = []; + } + return $wholeData; + // }else{ + // return "false"; + // } } else if($action == 'member_ecard_mail'){ $notification = $params['notification']; diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 05d09c98..9a4f3c0c 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -19,6 +19,7 @@ class ClientPolicyModel extends Model "policy_type_id", "policy_start_date", "policy_end_date", + "reminder_date", "insured", "no_of_employees", "no_of_lives", diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index b0862573..527d4450 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -112,6 +112,10 @@ +
+ + +
@@ -174,6 +178,23 @@ + + + + + + + -
+ + +
-
-
-
-
- - -
-
-
-
-
- +
+
+ +
+
+ +
+
+
+ +
+
+ +
+ diff --git a/app/Views/enrollment_list.php b/app/Views/enrollment_list.php index f35d7753..b483e4c1 100644 --- a/app/Views/enrollment_list.php +++ b/app/Views/enrollment_list.php @@ -228,6 +228,7 @@ }, success: function(response) { var data = JSON.parse(response); + console.log(data); var table = $('#tickets-table').DataTable(); table.clear(); @@ -277,6 +278,12 @@ }); table.draw(); + + function getUrlParameter(name) { + var params = new URLSearchParams(window.location.search); + return params.get(name); + } + }, error: function(xhr, status, error) { console.error('Error fetching data from API:', error); @@ -286,6 +293,43 @@ $(document).ready(function() { + function getUrlParameter(name) { + var params = new URLSearchParams(window.location.search); + return params.get(name); + } + + // Check for URL parameters and set form values + var client_id = getUrlParameter('client_id'); + var branch_id = getUrlParameter('branch_id'); + var type = getUrlParameter('type'); + + if (client_id) { + $('#clients').val(client_id).trigger('change'); // Set client ID and trigger change event to populate branches + } + + if (branch_id) { + setTimeout(function() { // Ensure branches are populated before setting branch ID + $('#branch_id').val(branch_id).trigger('change'); + if($('#branch_id').val() != 0){ + $('#get-emp-list').click().trigger(); + + + } + }, 500); + + } + if (history.pushState) { + var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname; + window.history.pushState({path: newUrl}, '', newUrl); + } + + setTimeout(() => { + // var type = getUrlParameter('type'); + console.log("------------------------"); + console.log(type); + $('#' + type).click().trigger(); + }, 1000); + $('#clients').select2(); $('#branch_id').select2(); var table = $('#tickets-table').DataTable({ diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index f430ce9e..3296938b 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -71,10 +71,11 @@ }); } - - - - + + + + +