CHANGE_EMPLOYEE_REST_FILE_UPLOAD_MAIL : AADHAVAN
This commit is contained in:
parent
2f96dd8d47
commit
e09b7199b8
@ -44,7 +44,7 @@ class Filters extends BaseConfig
|
||||
*/
|
||||
public array $globals = [
|
||||
'before' => [
|
||||
'HttpRequestLog' => ['except' => 'processjob'],
|
||||
'HttpRequestLog' => ['except' => 'cli/*'],
|
||||
// 'csrf',
|
||||
// 'invalidchars',
|
||||
],
|
||||
|
||||
@ -6,7 +6,7 @@ use CodeIgniter\Router\RouteCollection;
|
||||
* @var RouteCollection $routes
|
||||
*/
|
||||
// $routes->get('/', 'LoginController::index');
|
||||
$routes->get('/test', 'Home::test');
|
||||
$routes->get('/test', 'Home::index');
|
||||
$routes->get('/login', 'LoginController::index');///auth/google
|
||||
$routes->get('/logout', 'LoginController::logout');
|
||||
$routes->get('/oauth2callback', 'LoginController::receiveGoogleOAuthResponse');
|
||||
@ -191,7 +191,8 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){
|
||||
$routes->post("import-export", "EmployeeController::importExport");
|
||||
});
|
||||
|
||||
$routes->cli('processjob', 'JobWorker::processJob');
|
||||
$routes->cli('cli/processjob', 'JobWorker::processJob');
|
||||
$routes->cli('cli/processjobs', 'JobWorker::processJobs');
|
||||
|
||||
|
||||
|
||||
@ -215,6 +216,7 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi
|
||||
|
||||
$routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy");
|
||||
|
||||
$routes->post("employeeUpload", "EmployeeRestController::employeeUpload");
|
||||
|
||||
$routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
|
||||
$routes->post("employeeUpload", "EmployeeRestController::employeeUpload");
|
||||
|
||||
@ -18,6 +18,9 @@ use App\Models\RelationshipModel;
|
||||
use App\Models\FileModel;
|
||||
use App\Models\ClientPolicyModel;
|
||||
|
||||
use App\Controllers\Jobs ;
|
||||
use App\Controllers\JobWorker ;
|
||||
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
@ -411,26 +414,31 @@ class EmployeeRestController extends AdminController
|
||||
$highestRow = $sheet->getHighestRow();
|
||||
$highestColumn = $sheet->getHighestColumn();
|
||||
|
||||
$data = [];
|
||||
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
|
||||
$data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
|
||||
// print_r($excel_data);die();
|
||||
// $data = [];
|
||||
// $data[] =$excel_data;
|
||||
|
||||
// print_r($data);die;
|
||||
// Iterate through each row
|
||||
for ($row = 1; $row <= $highestRow; $row++) {
|
||||
// Initialize the row data array
|
||||
$rowData = [];
|
||||
// for ($row = 1; $row <= $highestRow; $row++) {
|
||||
// // Initialize the row data array
|
||||
// $rowData = [];
|
||||
|
||||
// Iterate through each column in the row
|
||||
for ($col = 'A'; $col <= $highestColumn; $col++) {
|
||||
// Get the cell value
|
||||
$value = $sheet->getCell($col . $row)->getValue();
|
||||
|
||||
// Add the cell value to the row data array
|
||||
$rowData[] = $value;
|
||||
}
|
||||
|
||||
// Add the row data to the main data array
|
||||
$data[] = $rowData;
|
||||
}
|
||||
// // Iterate through each column in the row
|
||||
// for ($col = 'A'; $col <= $highestColumn; $col++) {
|
||||
// // Get the cell value
|
||||
// $value = $sheet->getCell($col . $row)->getValue();
|
||||
// // print_r($value);
|
||||
// // Add the cell value to the row data array
|
||||
// $rowData[] = $value;
|
||||
// }
|
||||
|
||||
// // Add the row data to the main data array
|
||||
// $data[] = $rowData;
|
||||
// }
|
||||
// print_r($data);die;
|
||||
|
||||
$extractData['file_name']= $filename;
|
||||
$extractData['client_id']= $client_id;
|
||||
@ -442,6 +450,10 @@ class EmployeeRestController extends AdminController
|
||||
$file_data =$this->fileModel->insert($extractData);
|
||||
|
||||
$extra = [];
|
||||
//this change the column name into index number
|
||||
for ($i = 0; $i < count($data[0]); $i++) {
|
||||
$data[0][$i] = $i;
|
||||
}
|
||||
for ($i = 0; $i < count($data); $i++) {
|
||||
if ($i == 0) {
|
||||
// Loop through the first row to extract keys
|
||||
@ -462,27 +474,64 @@ class EmployeeRestController extends AdminController
|
||||
// print_r("Extra", $extra);die;
|
||||
$dataToInsert = [];
|
||||
$basic_cover_si= [];
|
||||
foreach ($extra['id'] as $index => $id) {
|
||||
$record = [
|
||||
// 'id' => $id,
|
||||
'emp_code' => isset($extra['emp_code'][$index]) ? $extra['emp_code'][$index] : 0,
|
||||
'name' => $extra['name'][$index],
|
||||
// Check if the 'doj' key exists before accessing it
|
||||
'doj' => isset($extra['doj'][$index]) ? $extra['doj'][$index] : null,
|
||||
'gender' => $extra['gender'][$index],
|
||||
'relationship' => $extra['relationship'][$index],
|
||||
'dob' => $extra['dob'][$index],
|
||||
'email_personal' => $extra['Email'][$index],
|
||||
'client_id' => $client_id,
|
||||
];
|
||||
$record2 = [
|
||||
'basic_cover_si' => isset($extra['sum_insure'][$index]) ? $extra['sum_insure'][$index] : 0,
|
||||
];
|
||||
// print_r($extra);die;
|
||||
foreach ($extra['0'] as $index => $id) {
|
||||
$relation ='';
|
||||
if ($extra['5'][$index] === 'Mother' || $extra['5'][$index] === 'Father') {
|
||||
$relation = 'parent';
|
||||
} else if($extra['5'][$index] === 'Son' || $extra['5'][$index] === 'Daughter'){
|
||||
$relation = 'child';
|
||||
}else if($extra['5'][$index] === 'Father in Law' || $extra['5'][$index] === 'Mother in Law'){
|
||||
$relation = 'parent_in_law';
|
||||
}else if($extra['5'][$index] === 'Spouse'){
|
||||
$relation = 'spouse';
|
||||
}else{
|
||||
$relation = 'self';
|
||||
}
|
||||
|
||||
// Simplified formatDate function
|
||||
|
||||
$dataToInsert[] = $record;
|
||||
$basic_cover_si[]= $record2;
|
||||
|
||||
// Assigning formatted dates
|
||||
// print_r($extra['3']);die;
|
||||
$doj = $extra['3'][$index] ;
|
||||
$dob = $extra['6'][$index] ;
|
||||
|
||||
|
||||
// Change date format for $doj
|
||||
$doj_new_format = date('Y-m-d', strtotime($doj)); // $doj_new_format will be "2001-02-12"
|
||||
|
||||
// Change date format for $dob
|
||||
$dob_new_format = date('Y-m-d', strtotime($dob));
|
||||
|
||||
// Your existing code here
|
||||
|
||||
$emp_code =isset($extra['1'][$index]) ? $extra['1'][$index] : 0;
|
||||
$name = $extra['2'][$index];
|
||||
|
||||
if($emp_code != 0 && $name != '' || $name != null){
|
||||
$record = [
|
||||
// 'id' => $id,
|
||||
'emp_code' => $emp_code,
|
||||
'name' => $name,
|
||||
// Check if the 'doj' key exists before accessing it
|
||||
'doj' => $doj_new_format,
|
||||
'gender' => $extra['4'][$index],
|
||||
'relationship' => $extra['5'][$index],
|
||||
'family_floater_key' => $relation,
|
||||
'dob' => $dob_new_format,
|
||||
'email_corporate' => $extra['7'][$index],
|
||||
'mobile'=> $extra['8'][$index],
|
||||
'client_id' => $client_id,
|
||||
|
||||
];
|
||||
$record2 = [
|
||||
'basic_cover_si' => isset($extra['9'][$index]) ? $extra['9'][$index] : 0,
|
||||
];
|
||||
$dataToInsert[] = $record;
|
||||
$basic_cover_si[]= $record2;
|
||||
}
|
||||
}
|
||||
// print_r("dataToInsert", $dataToInsert);die;
|
||||
for ($a=0; $a <count($dataToInsert) ; $a++)
|
||||
{
|
||||
$employee = $this->employeeModel->checkExistingEmpEntrollment($dataToInsert[$a]);
|
||||
@ -496,6 +545,7 @@ class EmployeeRestController extends AdminController
|
||||
$this->myLogger->logme('error',('Update - ' . $employee['id'].' - '. $employee['emp_code'] .' - '.$employee['name']));
|
||||
}
|
||||
}else{
|
||||
|
||||
$result = $this->employeeModel->insert($dataToInsert[$a]);
|
||||
$emp_id =$result;
|
||||
if ($result) {
|
||||
@ -529,13 +579,24 @@ class EmployeeRestController extends AdminController
|
||||
// print_r($dataToInsert[$a]['email_personal']);die;
|
||||
$policy = $this->clientPolicyModel->where('id', $policy_id)->first();
|
||||
$policy_name = $this->policesModel->where('id', $policy['policy_id'])->first();
|
||||
$mail = $dataToInsert[$a]['email_personal'];
|
||||
$mail = $dataToInsert[$a]['email_corporate'];
|
||||
$subject = 'Welcome, Employee Benefit Program Enrolment';
|
||||
$message = 'Dear ' . $dataToInsert[$a]['name'] . ",<br> We are glad to welcome you to the employee benefit program ," .$policy_name['name'] ."offered by your employer, <br><br><br> Click on the link below to review your personal and family details:<br><a href='https://venbait.in/nhance/app/dev'>Review Details</a>" ;
|
||||
$return_log = MailHelper::send_email($mail,$subject, $message);
|
||||
$return_log = json_decode($return_log);
|
||||
|
||||
$this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]);
|
||||
// $message = 'Dear ' . $dataToInsert[$a]['name'] . ",<br> We are glad to welcome you to the employee benefit program ," .$policy_name['name'] ."offered by your employer, <br><br><br> Click on the link below to review your personal and family details:<br><a href='https://venbait.in/nhance/app/dev'>Review Details</a>" ;
|
||||
$data['employee_name']=$dataToInsert[$a]['name'];
|
||||
$data['policy_name']=$policy_name['name'];
|
||||
|
||||
$message = view('mail_welcome', $data);
|
||||
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]]);
|
||||
}
|
||||
|
||||
// print_r($r);//die();
|
||||
// $jobWorker = new JobWorker();
|
||||
//JobWorker::processJob($r);
|
||||
// $return_log = MailHelper::send_email($mail,$subject, $message);
|
||||
// $return_log = json_decode($return_log);
|
||||
// $this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ class Home extends PublicController
|
||||
{
|
||||
public function index(): string
|
||||
{
|
||||
return view('welcome_message');
|
||||
return view('mail_welcome');
|
||||
}
|
||||
|
||||
public function test()
|
||||
|
||||
@ -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']];
|
||||
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']];
|
||||
public function __construct()
|
||||
{
|
||||
// echo 'HiC';//die();
|
||||
@ -27,12 +27,39 @@ class JobWorker extends AdminController
|
||||
// }
|
||||
}
|
||||
|
||||
public static function processJobs(array $jobdata = [])
|
||||
{
|
||||
// echo 'listen';//die();
|
||||
$query = "
|
||||
SELECT id, name, payload, uuid
|
||||
FROM jobs
|
||||
WHERE status=?
|
||||
ORDER BY created_dt ASC";
|
||||
$where_condition = [self::STATUS_QUEUED];
|
||||
$db = \Config\Database::connect();
|
||||
$jobs = $db->query($query, $where_condition)->getResult();
|
||||
|
||||
if(count($jobs))
|
||||
{
|
||||
// echo count($jobs);
|
||||
// print_r($jobs);die;
|
||||
foreach($jobs as $key => $job)
|
||||
{
|
||||
// echo $job->id.' - '.$job->name;
|
||||
//sleep(1);
|
||||
|
||||
SELF::processjob(['id' => $job->id,'uuid' => $job->uuid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* process jobs
|
||||
*/
|
||||
public static function processJob(array $jobdata = [])
|
||||
{
|
||||
// echo 'listen';//die();
|
||||
// print_r($jobdata);
|
||||
// echo 'listen';
|
||||
// die();
|
||||
$query = "
|
||||
SELECT id, name, payload, uuid
|
||||
FROM jobs
|
||||
@ -61,7 +88,9 @@ class JobWorker extends AdminController
|
||||
|
||||
echo "\nProcessing job id - " . $job->id . "\n";
|
||||
echo "Job name - " . $job->name . "\n";
|
||||
|
||||
// print_r(SELF::$event_class_mapping);
|
||||
// echo array_key_exists($job->name,SELF::$event_class_mapping) ? 'mapped' : 'notmapped';
|
||||
// die();
|
||||
try
|
||||
{
|
||||
$start = microtime(true);
|
||||
@ -69,7 +98,7 @@ class JobWorker extends AdminController
|
||||
$job_status = self::STATUS_RUNNING;
|
||||
$db->query("UPDATE jobs SET status=? WHERE id=? AND uuid=?", [$job_status, $job->id,$job->uuid]);
|
||||
|
||||
if (!array_key_exists($job->name,SeLf::$event_class_mapping))
|
||||
if (!array_key_exists($job->name,SELF::$event_class_mapping))
|
||||
{
|
||||
throw new \RuntimeException('Job ' . $job->name . ' handler not registered');
|
||||
}
|
||||
@ -145,6 +174,7 @@ class JobWorker extends AdminController
|
||||
|
||||
// echo "Job $job->id $job_status. Response - $response \n";
|
||||
echo "Job $job->id $job_status \n";
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -12,11 +12,15 @@ use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
class MailHelper
|
||||
{
|
||||
static function send_email($emaill, $subject, $message)
|
||||
public static function send_email($params)
|
||||
{
|
||||
$emaill = $params['mail'];
|
||||
$subject = $params['subject'];
|
||||
$message = $params['message'];
|
||||
try {
|
||||
$email = \Config\Services::email();
|
||||
$email->setFrom('bbone@venbait.in', 'Venkat');
|
||||
$email->setMailType('html');
|
||||
$email->setFrom('bbone@venbait.in', 'Nhance');
|
||||
|
||||
$email->setTo($emaill);
|
||||
|
||||
@ -33,12 +37,5 @@ class MailHelper
|
||||
return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function logme($message, $email) {
|
||||
// Your logging logic here
|
||||
// For example, writing to a log file
|
||||
file_put_contents('path/to/log/file.txt', $message . "\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -23,6 +23,7 @@ class EmployeeModel extends Model
|
||||
"mobile",
|
||||
"gender",
|
||||
"dob",
|
||||
"doj",
|
||||
"otp",
|
||||
"family_floater_key",
|
||||
"emp_status",
|
||||
|
||||
23
app/Views/mail_welcome.php
Normal file
23
app/Views/mail_welcome.php
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container" style="max-width: 500px; margin: 20px auto; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .1); min-height: 100px; position: relative;">
|
||||
<div class="logo" style="display: flex; justify-content: center; align-items: center; margin: 30px auto 0;">
|
||||
<img src="<?= base_url()."public"; ?>/assets/images/Nhance-Logo-Final.png" alt="cc-logo" width="180" height="30" border="0" style="width: 180px;">
|
||||
</div>
|
||||
<div class="illustration" style="width: 100%; text-align: center; box-shadow: 0 10px 20px -5px rgba(0, 0, 0, .05); border-radius: 0 0 50% 50% / 1%; text-align: center;">
|
||||
<div class="hgroup" style="text-align: center; padding: 50px 30px 30px;">
|
||||
<span class="name" style="display: block; color: #0267C1; font-weight: 600; font-size: 1.1rem;">Dear, <?= isset($employee_name) ? $employee_name : '' ?></span>
|
||||
<p class="rad" style="margin: 0!important; text-align: center!important; font-size: 18px!important;">We are glad to welcome you to the employee benefit program, <?= isset($policy_name) ? $policy_name : '' ?> offered by your employer.</p>
|
||||
</div>
|
||||
<button class="explore" style="padding: 15px 25px; background: linear-gradient(to right, #0267C1, #0280EF); border-radius: 50px; border: 0; color: #fff; transition: all .2s ease-in-out; cursor: pointer; box-shadow: 0 5px 10px rgba(0, 0, 0, .1); margin-bottom: 15px;">
|
||||
<a href="https://venbait.in/nhance/app/dev" style="text-decoration: none; color: #fff;">Review Details</a>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -17,6 +17,7 @@
|
||||
"firebase/php-jwt": "^6.10",
|
||||
"google/apiclient": "^2.15.0",
|
||||
"laminas/laminas-escaper": "^2.9",
|
||||
"php-amqplib/php-amqplib": "^2.8",
|
||||
"phpmailer/phpmailer": "^6.9",
|
||||
"phpoffice/phpspreadsheet": "^2.0",
|
||||
"psr/log": "^1.1",
|
||||
|
||||
BIN
public/assets/images/Nhance-Logo-Final.png
Normal file
BIN
public/assets/images/Nhance-Logo-Final.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
Loading…
Reference in New Issue
Block a user