CHANGE_CLIENT_POLICY_OPEN_ENROLLMENT_MAIL_HELPER_BULK_MAIL : AADHAVAN

This commit is contained in:
aadhavan valli 2024-04-03 15:26:58 +05:30
parent 9121ece484
commit 23d78871de
7 changed files with 127 additions and 46 deletions

View File

@ -307,6 +307,8 @@ class ClientController extends AdminController
} elseif ($data['is_download_btn']) {
$data['is_download_btn'] = 1;
}
// print_r($data);die;
$update = $this->clientModel->update($id,$data);
@ -1311,7 +1313,7 @@ class ClientController extends AdminController
$termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first();
if(empty($termsData['policy_terms'])){
return $this->respond(['status' => false,'code' => 200,'message' => 'This Policy does not Create Terms'], 200);
return $this->respond(['status' => false,'code' => 200,'message' => 'Please define policy terms '], 200);
}
@ -1338,11 +1340,21 @@ class ClientController extends AdminController
if($racRate == 0){
return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy has no Data for Rac Rate'], 200);
return $this->respond(['status' => false,'code' => 200,'message' => 'Please define policy premium'], 200);
}
$policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update();
return $this->respond(['status' => true,'code' => 200, 'message' => 'Policy Status Updated Successfully', 'data' => $termsData, 'racRate' => $racRate], 200);
$json_data ='';
$open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id )->set('open_for_enrollment', 1)->update();
if ($open_for_enrollment) {
$open_for_enrollment_1 = $this->clientPolicyModel->where('id', $client_policy_id )->find();
$open_for_enrollment_value = $open_for_enrollment_1[0]['open_for_enrollment'];
$client_policy_id_value = $client_policy_id;
$json_data = json_encode(['open_for_enrollment' => $open_for_enrollment_value, 'client_policy_id' => $client_policy_id_value]);
}
return $this->respond(['status' => true,'code' => 200, 'message' => 'Policy Status Updated Successfully', 'data' => $termsData, 'racRate' => $racRate, 'open_for_enrollment' => $json_data], 200);

View File

@ -511,12 +511,17 @@ class EmployeeRestController extends AdminController
$client_id = $this->request->getPost('client_id');
$policy_id = $this->request->getPost('policy_id');
$token = $this->request->headers()['Auth']->getValue();
$decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
$jwt = $this->request->getHeader('Authorization');
$jwtParts = explode(' ', $jwt);
$token = $jwtParts[1];
$decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true);
// get the employee id from token
$employee_id = $decodedPayload['id'];
$client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->first();
if ($client_policy) {
@ -689,6 +694,7 @@ class EmployeeRestController extends AdminController
$basic_cover_si[]= $basic_cover_si_value;
}
}
$count = 0;
for ($a=0; $a <count($dataToInsert) ; $a++)
{
$employee = $this->employeeModel->checkExistingEmployee($dataToInsert[$a]);
@ -765,10 +771,23 @@ class EmployeeRestController extends AdminController
$data['policy_name']=$policy['name'];
$message = view('mail_welcome', $data);
if ($dataToInsert[$a]['relationship'] == 'Self' && $mail != null || $mail != '') {
$count++;
$wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $message];
}
// print_r($wholeData);
// if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') {
// $job_details = new Jobs();
// $r = Jobs::addJob(['job_name' => 'send_email','payload' => ['mail' => $mail, 'subject' => $subject,'message'=> $message]]);
// }
if($count == 20 || $a == count($dataToInsert)-1){
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $wholeData]);
// $wholeData[]= $r;
// Mailhelper::bulk_mail($wholeData);
$wholeData = [];
$count = 0;
}
// print_r($r);//die();
// $jobWorker = new JobWorker();

View File

@ -14,7 +14,7 @@ class JobWorker extends AdminController
* Constructs the class
*/
private static $event_class_mapping = ['add' => ['type' => 'HC','handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC','handler' => 'App\\Controllers\\Jobs\SubJob'],'fancy_date_time_format' => [ 'type' => 'HF','handler' => 'fancy_date_time_format'],'addNumber' => ['type' => 'HC','handler' => 'App\\Model\\HttpRequestHelper'],'excelFileFormatValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'excelFileDataValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'employeeOnboard' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'send_email' => ['type' => 'HC','handler' => 'App\\Helpers\\MailHelper']];
private static $event_class_mapping = ['add' => ['type' => 'HC','handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC','handler' => 'App\\Controllers\\Jobs\SubJob'],'fancy_date_time_format' => [ 'type' => 'HF','handler' => 'fancy_date_time_format'],'addNumber' => ['type' => 'HC','handler' => 'App\\Model\\HttpRequestHelper'],'excelFileFormatValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'excelFileDataValidation' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'employeeOnboard' => ['type' => 'CC','handler' => 'App\\Controllers\\EmployeeServiceController'],'send_email' => ['type' => 'HC','handler' => 'App\\Helpers\\MailHelper'],'bulk_mail' => ['type' => 'HC','handler' => 'App\\Helpers\\MailHelper']];
public function __construct()
{
// echo 'HiC';//die();
@ -199,4 +199,7 @@ class JobWorker extends AdminController
}
}
}

View File

@ -9,6 +9,8 @@ use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
use App\Models\JobModel;
class MailHelper
{
@ -18,6 +20,7 @@ class MailHelper
$subject = $params['subject'];
$message = $params['message'];
try {
$email = \Config\Services::email();
$email->setMailType('html');
$email->setFrom('bbone@venbait.in', 'Nhance');
@ -37,5 +40,26 @@ class MailHelper
return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500);
}
}
public static function bulk_mail(array $mails = [])
{
$model = new JobModel();
$start = microtime(true);
$runtime= 0;
try {
foreach ( $mails as $index=>$mail) {
$runtime = microtime(true) - $start;
$send_mail = self::send_email($mail);
}
return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...'],200);
} catch (\Throwable $th) {
return json_encode(['status' => 'failed','code' => 500],500);
}
}
}
?>

View File

@ -86,31 +86,34 @@ if (!function_exists('compressImage')) {
if (!function_exists('fancy_date_time_format'))
{
function fancy_date_time_format($datetime,$return_type = 'fancy') {
date_default_timezone_set('Asia/Kolkata');
$currentDateTime = new DateTime();
$passedDateTime = new DateTime($datetime);
// Calculate the interval between the current time and the passed datetime
$interval = $currentDateTime->diff($passedDateTime);
// return change_date_format($datetime,'Y-m-d H:i:s','d M Y h:i a');
// If the interval is more than 1 month, return the original datetime
if ($interval->m > 1 || $interval->y > 0) {
if($return_type = 'fancy'){ return change_date_format($datetime,'Y-m-d H:i:s','d M Y h:i a'); }
return $datetime;
} elseif ($interval->m == 1 && $interval->y == 0) {
return "1 month ago";
} elseif ($interval->d >= 7) {
$weeks = floor($interval->d / 7);
return $weeks == 1 ? "1 week ago" : "$weeks weeks ago";
} elseif ($interval->d >= 1) {
return $interval->d == 1 ? "1 day ago" : $interval->d . " days ago";
} elseif ($interval->h >= 1) {
return $interval->h == 1 ? "1 hour ago" : $interval->h . " hours ago";
} elseif ($interval->i >= 1) {
return $interval->i == 1 ? "1 minute ago" : $interval->i . " minutes ago";
} else {
return "Just now";
// Calculate the interval between the current time and the passed datetime
$interval = $currentDateTime->diff($passedDateTime);
// If the interval is more than 1 month or the year is different, return the original datetime
if ($interval->m > 1 || $interval->y != 0) {
if ($return_type == 'fancy') {
return change_date_format($datetime, 'Y-m-d H:i:s', 'd M Y h:i a');
}
return $datetime;
} elseif ($interval->m == 1 && $interval->y == 0) {
return "1 month ago";
} elseif ($interval->d >= 7) {
$weeks = floor($interval->d / 7);
return $weeks == 1 ? "1 week ago" : "$weeks weeks ago";
} elseif ($interval->d >= 1) {
return $interval->d == 1 ? "1 day ago" : $interval->d . " days ago";
} elseif ($interval->h >= 1) {
return $interval->h == 1 ? "1 hour ago" : $interval->h . " hours ago";
} elseif ($interval->i >= 1) {
return $interval->i == 1 ? "1 minute ago" : $interval->i . " minutes ago";
} else {
return "Just now";
}
}
}

View File

@ -194,9 +194,9 @@
if (policy_PrimaryKey !== '') {
var policyTable = '';
var data = <?= isset($client_policy) ? json_encode($client_policy) : '[]' ?>;
console.log('client_policy_data',data)
// console.log('client_policy_data',data)
data.forEach(function(item) {
console.log(item.open_for_enrollment);
var patternGMC = /gmc/i; // Case insensitive pattern for 'gmc'
var patternGPA = /gpa/i; // Case insensitive pattern for 'gpa'
var subject = item.policy_type_name;
@ -225,8 +225,13 @@
<a href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a href="#" data-id="${item.id}" id="${search_term}" class="dropdown-item btnPolicyMaster" data-toggle="modal"><i class="mdi mdi-wrench mr-2 text-muted font-18 vertical-middle"></i>Terms</a>
<a href="#" data-id="${item.id}" id="${search_term}"class="dropdown-item btnPolicyModel" data-toggle="modal" data-target="#bs-example-modal-lg"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Rac Rate</a>
<a href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnOpenEnroll"><i class="mdi mdi-file-lock mr-2 text-muted font-18 vertical-middle"></i>Open Enrollment</a>
</div>
`;
if (item.open_for_enrollment == 0) {
policyTable +=`<a href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnOpenEnroll"><i class="mdi mdi-file-lock mr-2 text-muted font-18 vertical-middle"></i>Open Enrollment</a> `;
}else{
policyTable +=`<a href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnOpenEnroll" style="pointer-events:none; background-color: lightgrey;"><i class="mdi mdi-file-lock mr-2 text-muted font-18 vertical-middle" ></i>Open Enrollment</a> `;
}
policyTable += ` </div>
</div>
</td>
</tr>
@ -509,13 +514,28 @@
client_policy_id : client_policy_id,
},
success: function(res) {
// console.log(res);
console.log(res);
if(res) {
if (res.open_for_enrollment) {
var json_decode=JSON.parse(res.open_for_enrollment);
var open_for_enrollment=json_decode.open_for_enrollment;
var client_policy_id=json_decode.client_policy_id;
if (open_for_enrollment == 1) {
// console.log($('[data-id="' + client_policy_id + '"]');
$('.btnOpenEnroll').each(function(index, element) {
if ($(element).data('id') == client_policy_id) {
$(element).css({'background-color': 'lightgrey', 'pointer-events': 'none'});
}
});
}
}
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
if(res.status === true){
toastr.success(res.message, 'Success');
}else if(res.status === false){
toastr.warning(res.message, 'Warning');
}

View File

@ -157,7 +157,7 @@ paths:
summary: 'Add a new EmployeeUpload to the store'
operationId: EmployeeUpload
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -317,7 +317,7 @@ paths:
summary: 'RelationshipList'
operationId: RelationshipList
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -340,7 +340,7 @@ paths:
summary: 'GetEmployeeAndDependence'
operationId: GetEmployeeAndDependence
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -368,7 +368,7 @@ paths:
summary: 'EditEmployeeAndDependence'
operationId: EditEmployeeAndDependence
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -461,7 +461,7 @@ paths:
summary: 'AddEmployeeAndDependence'
operationId: AddEmployeeAndDependence
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -551,7 +551,7 @@ paths:
summary: 'GetEmployeePolicy'
operationId: GetEmployeePolicy
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -584,7 +584,7 @@ paths:
summary: 'CreateOrUpdateEmployeePolicySiAmount'
operationId: CreateOrUpdateEmployeePolicySiAmount
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -627,7 +627,7 @@ paths:
summary: 'DeleteDependence'
operationId: DeleteDependence
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -655,7 +655,7 @@ paths:
summary: 'GetEmployeeAndDependenceByClientId'
operationId: GetEmployeeAndDependenceByClientId
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true
@ -688,7 +688,7 @@ paths:
summary: 'GetClientPolicy'
operationId: GetClientPolicy
parameters:
- name: auth
- name: Authorization
in: header
description: an authorization header
required: true