CHANGE_UPDATE_ENROLLMENT_STATUS_FUNCTION AND_SEND_CRONE_MAIL_FUNCTION_FOR_REMAINDER_MAIL : RV

This commit is contained in:
VENKATESHWARAN 2024-10-11 13:49:09 +05:30
parent b371c2a941
commit 4a13d7c721
4 changed files with 177 additions and 76 deletions

View File

@ -12,7 +12,9 @@ $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']);
// Reminder Mail Notification
$routes->get("reminder_mail", "NotificationController::reminder_mail");
$routes->get("testing", "ClientController::Testing");
// $routes->get("testing", "ClientController::Testing");
// $routes->get("testing", "DashboardController::updatePolicyEnrollmentStatus");
$routes->get("testing", "DashboardController::sendCroneRemainderMail");
$routes->get("update-policy-terms-for-corrections", "ClientController::updatePolicyTermsForCorrections");
$routes->get("update_rack_rate_json", "ClientController::updateRackRateJson");
$routes->get("updatajson", "EmpDataServiceController::updatajson");
@ -284,6 +286,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get("get_policy_type_for_base_policy/(:any)", "ClientController::getPolicyTypeForBasePolicy/$1");
$routes->get("get_client_details/(:any)", "ClientController::getClientDetails/$1");
$routes->get("featch_dashboard_data/(:any)", "DashboardController::featch_dashboard_data/$1");
$routes->get("send_manual_remainder/(:any)", "DashboardController::sendManualRemainder/$1");
$routes->get("remove_rack_rate/(:any)", "ClientController::removeRackRate/$1");
$routes->get("rename_rack_rate_tab/(:any)", "ClientController::renameRackRateTab/$1");
$routes->post("create_excel_template", "MasterController::createExcelTemplate");
@ -363,6 +366,8 @@ $routes->cli('cli/new_gmail_token', 'MasterController::generateNewGmailAPIToken'
$routes->cli('cli/send_mail_cli(/:any)?', 'MasterController::testGmailAPIViaCLI$1');
$routes->cli('cli/app_check_list', 'MasterController::appCheckList');
$routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken');
$routes->cli('cli/updatePolicyEnrollmentStatus', 'DashboardController::updatePolicyEnrollmentStatus');
$routes->cli('cli/sendCroneRemainderMail', 'DashboardController::sendCroneRemainderMail');

View File

@ -202,59 +202,71 @@ class DashboardController extends AdminController
public function updatePolicyEnrollmentStatus()
{
$clientModel = new ClientModel();
$clientPolicyModel = new ClientPolicyModel();
$notificationModel = new NotificationModel();
$employeePolicyModel = new EmployeePolicyModel();
$myLogger = \Config\Services::mylogger();
// $myLogger->logme('error', 'enrollment_status function called');
$client_policy_data = $clientPolicyModel->getPolicyDetailsForRemainder();
$myLogger->logme('error', 'Fetched client policy data');
$client_policy_data = $clientPolicyModel->getPolicyDetailsForEnrollment();
$myLogger->logme('error', 'Fetched client policy data for Enrollment Status update');
// dd($client_policy_data);
$currentDate = date('d');
// $myLogger->logme('error', 'Current date: ' . $currentDate);
$currentDate = date('d-m-Y');
$openEnrollment = [];
$closeEnrollment = [];
// Update policy status based on start and end dates
foreach ($client_policy_data as $client_policy) {
$id = $client_policy['id'];
$openDate = date('d', strtotime($client_policy['open_date']));
$closeDate = date('d', strtotime($client_policy['close_date']));
// $myLogger->logme('error', 'Processing client policy ID: ' . $id);
// $myLogger->logme('error', 'Open date: ' . $openDate . ', Close date: ' . $closeDate);
$openDate = date('d-m-Y', strtotime($client_policy['open_date']));
$closeDate = date('d-m-Y', strtotime($client_policy['close_date']));
if ($currentDate == $openDate) {
$clientPolicyModel->update($id, ['open_for_enrollment' => 1]);
$openEnrollment[] = $id;
$myLogger->logme('error', 'Updated policy ID ' . $id . ' to open for enrollment.');
}
if ($closeDate < $currentDate) {
$clientPolicyModel->update($id, ['open_for_enrollment' => 0]);
$closeEnrollment[] = $id;
$myLogger->logme('error', 'Updated policy ID ' . $id . ' to close for enrollment.');
}
}
$myLogger->logme('error', 'enrollment_status function completed');
return $this->respond([
'status' => true,
'message' => 'updated Policy Enrollment Status',
'open_policy_count' => count($openEnrollment),
'close_policy_count' => count($closeEnrollment),
'open_policy_ids' => $openEnrollment,
'close_policy_ids' => $closeEnrollment,
]);
}
public function sendCroneRemainderMail()
{
$clientPolicyModel = new ClientPolicyModel();
$myLogger = \Config\Services::mylogger();
$client_policy_data = $clientPolicyModel->getPolicyDetailsForRemainder();
$myLogger->logme('error', 'Fetched client policy data');
// dd($client_policy_data);
// Mail send function
// $myLogger->logme('error', 'Calling sendRemainderMail function');
if( $currentDate == date('d', strtotime($client_policy['reminder_date']))){
$result = $this->sendRemainderMail($client_policy_data);
}else{
$result = false;
}
// $myLogger->logme('error', 'enrollment_status function completed');
$result = $this->sendRemainderMail($client_policy_data, 'crone');
$myLogger->logme('error', 'sendCroneRemainderMail function completed');
if($result){
return json_encode(['status' => true, 'message' => 'Mail send successfully']);
}else{
return json_encode(['status' => false, 'message' => 'There is no data to send']);
}
}
public function featch_dashboard_data($type)
{
@ -292,65 +304,133 @@ class DashboardController extends AdminController
return $this->respond(['status' => true, 'data' => $data], 200);
}
public function sendRemainderMail($client_policy_data)
public function sendRemainderMail($client_policy_data, $send_mail_for_manual_or_crone = null)
{
// $this->myLogger->logme('error', 'sendRemainderMail function called');
// dd($client_policy_data, $send_mail_for_manual_or_crone);
$reminder_whole_mail = [];
foreach ($client_policy_data as $client_policy) {
// Fetch client data
$client_data = $this->clientModel->find($client_policy['client_id']);
// Fetch notification settings
$notification_data = $this->notificationModel
->where('client_id', $client_policy['client_id'])
->where('template_name', 'member_reminder_mail')
->first();
// $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data));
// Check if notification should be sent
if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) {
$this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']);
// Fetch all employees related to the client policy
$employees = $this->employeePolicyModel
->select('employees.*')
->join('employees', 'employee_polices.employee_id = employees.id', 'left')
->where('employee_polices.client_policy_id', $client_policy['id'])
->where('employees.emp_status', 'draft')
->where('employees.is_active', 1)
->where('employee_polices.status', 'draft')
->where('employee_polices.is_active', 1)
->where('employees.relationship', 'Self')
->findAll();
// Process each employee
foreach ($employees as $employee) {
if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') {
$this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']);
// Mail params
$params['emp_data'] = $employee;
$params['client_data'] = $client_data;
$params['notification_data'] = $notification_data;
// Send the mail notification
$mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params);
// $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result));
$reminder_whole_mail[] = $mail_result;
if(empty($send_mail_for_manual_or_crone)){
// echo '1';
// Fetch client data
$client_data = $this->clientModel->find($client_policy['client_id']);
// Fetch notification settings
$notification_data = $this->notificationModel
->where('client_id', $client_policy['client_id'])
->where('template_name', 'member_reminder_mail')
->first();
// $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data));
// Check if notification should be sent
if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) {
$this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']);
// Fetch all employees related to the client policy
$employees = $this->employeePolicyModel
->select('employees.*')
->join('employees', 'employee_polices.employee_id = employees.id', 'left')
->where('employee_polices.client_policy_id', $client_policy['id'])
->where('employees.emp_status', 'draft')
->where('employees.is_active', 1)
->where('employee_polices.status', 'draft')
->where('employee_polices.is_active', 1)
->where('employees.relationship', 'Self')
->findAll();
// Process each employee
foreach ($employees as $employee) {
if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') {
$this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']);
// Mail params
$params['emp_data'] = $employee;
$params['client_data'] = $client_data;
$params['notification_data'] = $notification_data;
// Send the mail notification
$mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params);
// $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result));
$reminder_whole_mail[] = $mail_result;
}
}
} else {
$this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']);
}
} else {
// echo '2';
$currentDate = date('d-m-Y');
if($currentDate == date('d-m-Y', strtotime($client_policy['reminder_date']))){
// echo '3';
$client_data = $this->clientModel->find($client_policy['client_id']);
// Fetch notification settings
$notification_data = $this->notificationModel
->where('client_id', $client_policy['client_id'])
->where('template_name', 'member_reminder_mail')
->first();
// Check if notification should be sent
if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) {
// echo '4';
$this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']);
// Fetch all employees related to the client policy
$employees = $this->employeePolicyModel
->select('employees.*')
->join('employees', 'employee_polices.employee_id = employees.id', 'left')
->where('employee_polices.client_policy_id', $client_policy['id'])
->where('employees.emp_status', 'draft')
->where('employees.is_active', 1)
->where('employee_polices.status', 'draft')
->where('employee_polices.is_active', 1)
->where('employees.relationship', 'Self')
->findAll();
// Process each employee
foreach ($employees as $employee) {
if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') {
$this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']);
// Mail params
$params['emp_data'] = $employee;
$params['client_data'] = $client_data;
$params['notification_data'] = $notification_data;
// Send the mail notification
$mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params);
// $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result));
$reminder_whole_mail[] = $mail_result;
}
}
} else {
// echo '5';
$this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']);
}
}
} else {
$this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']);
}
}
$this->myLogger->logme('error', 'Whole email, count: ' . $reminder_whole_mail);
// dd($reminder_whole_mail);
// $this->myLogger->logme('error', 'Whole email, count: ' . $reminder_whole_mail);
// Process and queue bulk emails
$temp_whole_data = [];
@ -387,7 +467,6 @@ class DashboardController extends AdminController
}
public function sendManualRemainder($client_id, $client_branch_id)
{
$this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}");
@ -414,7 +493,6 @@ class DashboardController extends AdminController
return $this->respond(['status' => false, 'code' => 200, 'message' => 'There is no data to send', 'message2' => 'No policy data found to send'], 200);
}
}
}

View File

@ -50,9 +50,12 @@ class sendMailNotification
$app_link = $_ENV['App_Url'];
$mail_content = $notification_data['mail_content'];
$nhance_logo = $_ENV['NHANCE_LOGO'];
$client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo'];
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
$mail_content = str_replace("[[nhance_logo]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $mail_content);
$mail_content = str_replace("[[client_logo]]", "<img src='$client_logo' alt='Client Logo' width='20'>", $mail_content);
$mail_content = str_replace("[[app_link]]", "<a href='$app_link'>Review Details</a>", $mail_content);
if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) {
if(isset($emp_data['relationship'])){

View File

@ -404,9 +404,24 @@ public function getPolicyDetailsForRemainder($client_id = null, $branch_id = nul
}
return $builder->get()->getResultArray();
}
//for this using in CRONE JOB
public function getPolicyDetailsForEnrollment($client_id = null, $branch_id = null)
{
$builder = $this->table('client_policy')
->where('client_policy.is_active', 1)
->where('client_policy.policy_status', 1)
->where('client_policy.open_date IS NOT NULL')
->where('client_policy.close_date IS NOT NULL');
if ($client_id && $branch_id) {
$builder->where('client_policy.client_id', $client_id)
->where('client_policy.client_branch_id', $branch_id);
}
return $builder->get()->getResultArray();
}
}