466 lines
18 KiB
PHP
466 lines
18 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
use chillerlan\QRCode\Data\QRMatrix;
|
|
use chillerlan\QRCode\QRCode;
|
|
use chillerlan\QRCode\QROptions;
|
|
|
|
date_default_timezone_set('Asia/Kolkata');
|
|
|
|
/**
|
|
* AMS
|
|
*
|
|
* @package HMVC
|
|
* @author Venba
|
|
* @copyright 2022 Venba
|
|
* @license https://venbainfotech.com/licenses/MIT MIT License
|
|
* @link <URI> (description)
|
|
* @version GIT: $Id$
|
|
* @since Version 0.0.1
|
|
* @filesource
|
|
*
|
|
*/
|
|
|
|
class Notification extends MX_Controller
|
|
{
|
|
/**
|
|
* [__construct description]
|
|
*
|
|
* @method __construct
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// To inherit directly the attributes of the parent class.
|
|
parent::__construct();
|
|
### Syntax : $this->load->model('Model Path' , 'Alias name');
|
|
### The second parameter (optional) is used to call the method.
|
|
$this->load->model('MY_Model','MY_Model');
|
|
$this->load->model('Notification_model','Notification_model');
|
|
$this->load->helper('mail_helper');
|
|
}
|
|
|
|
|
|
// Function for Mail Send
|
|
public function prepareNotificationData($body,$templateData,$Data,$type,$code){
|
|
|
|
try
|
|
{
|
|
// echo 1;die;
|
|
$getBusinessData = $this->Notification_model->get_admin_and_hr_mail_id(user()->business_id);
|
|
|
|
$managerID = $Data->ManagerId;
|
|
|
|
$managerMail = $this->Notification_model->get_user_data($managerID);
|
|
|
|
|
|
$cc_mail_data = [$getBusinessData->admin_email, $getBusinessData->hr_email, $Data->managerEmail, $Data->delegatePersonEmail];
|
|
|
|
if($Data->delegatePersonEmail == NULL)
|
|
{
|
|
if($Data->managerEmail == NULL){
|
|
|
|
|
|
$cc_mail_data = [$getBusinessData->admin_email, $getBusinessData->hr_email];
|
|
}
|
|
else{
|
|
|
|
$cc_mail_data = [$getBusinessData->admin_email, $getBusinessData->hr_email, $Data->managerEmail];
|
|
}
|
|
}
|
|
|
|
|
|
if($type === 'Email'){
|
|
|
|
if($code === 'APPLY_LEAVE' || $code === 'LEAVE_PERMISSION'){
|
|
|
|
$to = $getBusinessData->hr_email;
|
|
$cc = $cc_mail_data;
|
|
$subject = $templateData->subject;
|
|
$aliasName = $Data->emp_name;
|
|
$result = send_emails($to, $subject, $body, $aliasName, $cc);
|
|
// echo $result; die;
|
|
return $result;
|
|
}
|
|
else if($code === 'APPROVE_LEAVE' || $code === 'APPROVE_PERMISSION'){
|
|
|
|
$to = $Data->emp_email;
|
|
$cc = $cc_mail_data;
|
|
$subject = $templateData->subject;
|
|
$aliasName = 'HR';
|
|
$result = send_emails($to, $subject, $body, $aliasName, $cc);
|
|
// echo $result; die;
|
|
return $result;
|
|
}
|
|
else if($code === 'DECLINE_LEAVE' || $code === 'DECLINE_PERMISSION'){
|
|
|
|
$to = $Data->emp_email;
|
|
$cc = $cc_mail_data;
|
|
$subject = $templateData->subject;
|
|
$aliasName = 'HR';
|
|
$result = send_emails($to, $subject, $body, $aliasName, $cc);
|
|
// echo $result; die;
|
|
return $result;
|
|
}
|
|
else{
|
|
|
|
$to = $Data->emp_email;
|
|
$cc = $cc_mail_data;
|
|
$subject = $templateData->subject;
|
|
$aliasName = 'HR';
|
|
$result = send_emails($to, $subject, $body, $aliasName, $cc);
|
|
// echo $result; die;
|
|
return $result;
|
|
}
|
|
|
|
}
|
|
} catch (Exception $e) {
|
|
echo "An error occurred: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
public function prepareNotificationDataForDelegation($body,$templateData,$Data,$type,$code){
|
|
|
|
$getBusinessData = $this->Notification_model->get_admin_and_hr_mail_id(user()->business_id);
|
|
if($type === 'Email'){
|
|
|
|
$to = $Data->delegatePersonEmail;
|
|
$cc = [$getBusinessData->admin_email, $getBusinessData->hr_email];
|
|
$subject = $templateData->subject;
|
|
$aliasName = $Data->emp_name;
|
|
$result = send_emails($to, $subject, $body, $aliasName, $cc);
|
|
// echo $result; die;
|
|
return $result;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function prepareNotificationDataForExpence($body,$templateData,$Data,$type,$code){
|
|
|
|
// echo $body; die;
|
|
|
|
$getBusinessData = $this->Notification_model->get_admin_and_hr_mail_id(user()->business_id);
|
|
|
|
if(!empty($Data->managerEmail)){
|
|
$mail = [$getBusinessData->admin_email, $Data->managerEmail];
|
|
}else{
|
|
$mail = $getBusinessData->admin_email;
|
|
}
|
|
|
|
$cc_mail_data = [$getBusinessData->admin_email, $getBusinessData->hr_email, $Data->managerEmail, $Data->delegatePersonEmail];
|
|
if($Data->delegatePersonEmail == NULL)
|
|
{
|
|
if($Data->managerEmail == NULL){
|
|
|
|
$cc_mail_data = [$getBusinessData->admin_email, $getBusinessData->hr_email];
|
|
}
|
|
else{
|
|
$cc_mail_data = [$getBusinessData->admin_email, $getBusinessData->hr_email, $Data->managerEmail];
|
|
}
|
|
}
|
|
|
|
|
|
if($type === 'Email'){
|
|
|
|
if($code === 'EXPENCE_CLAIM'){
|
|
|
|
$to = $getBusinessData->hr_email;
|
|
$cc = $mail;
|
|
$subject = $templateData->subject;
|
|
$aliasName = $Data->emp_name;
|
|
$result = send_emails($to, $subject, $body, $aliasName, $cc);
|
|
// echo $result; die('EXPENCE_CLAIM');
|
|
return $result;
|
|
|
|
}else if($code === 'APPROVE_EXPENCE' || ($code === 'DECLINE_EXPENCE')){
|
|
|
|
$to = $Data->emp_email;
|
|
$cc = $cc_mail_data;
|
|
$subject = $templateData->subject;
|
|
$aliasName = 'HR';
|
|
$result = send_emails($to, $subject, $body, $aliasName, $cc);
|
|
// echo $result; die('APPROVE_EXPENCE or DECLINE_EXPENCE');
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// end of Function for Mail Send
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Send Mail For Apply Leave and apply Permission also Approve and Decline
|
|
public function sendNotification($leave_id, $code, $type){
|
|
try {
|
|
$leaveData = collectLeaveData($leave_id);
|
|
// print_r($leaveData);
|
|
$templateData = getTempleteData($code, $type);
|
|
if($code === 'APPLY_LEAVE' || $code === 'LEAVE_PERMISSION'){
|
|
|
|
$FormettedTemplateData = $this->preprocessTemplateData($leaveData,$templateData);
|
|
// print_r($leaveData);
|
|
}
|
|
else if($code === 'APPROVE_LEAVE' || $code === 'APPROVE_PERMISSION'){
|
|
$FormettedTemplateData = $this->preprocessTemplateDataForLeaveApprove($leaveData,$templateData);
|
|
// print_r($FormettedTemplateData);
|
|
// print_r($templateData);
|
|
}
|
|
else if($code === 'DECLINE_LEAVE' || $code === 'DECLINE_PERMISSION'){
|
|
$FormettedTemplateData = $this->preprocessTemplateDataForLeaveDecline($leaveData,$templateData);
|
|
// print_r($FormettedTemplateData);
|
|
// print_r($templateData);
|
|
}
|
|
return $this->prepareNotificationData($FormettedTemplateData,$templateData,$leaveData,$type, $code);
|
|
} catch (Exception $e) {
|
|
echo "An error occurred: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
|
|
public function preprocessTemplateData($leaveData, $templateData){
|
|
|
|
$managerID = $leaveData->ManagerId;
|
|
$managerName = $this->Notification_model->get_user_data($managerID);
|
|
|
|
$inputString = $templateData->placeholder;
|
|
$placeholders = explode(',', $inputString);
|
|
if($leaveData->leave_code === 'permission'){
|
|
if(empty($managerName->name)){
|
|
$perm_date_new = date('d-m-Y', strtotime($leaveData->perm_date_new));
|
|
$values = ['Manager', $leaveData->emp_name, $leaveData->leave_type, $perm_date_new, $leaveData->from_time, $leaveData->to_time, $leaveData->risedby, $leaveData->status, $leaveData->comments];
|
|
}
|
|
else{
|
|
$perm_date_new = date('d-m-Y', strtotime($leaveData->perm_date_new));
|
|
$values = [$managerName->name, $leaveData->emp_name, $leaveData->leave_type, $perm_date_new, $leaveData->from_time, $leaveData->to_time, $leaveData->risedby, $leaveData->status, $leaveData->comments];
|
|
}
|
|
}
|
|
else{
|
|
if(empty($managerName->name)){
|
|
$fromDate = date('d-m-Y', strtotime($leaveData->from_date_new));
|
|
$toDate = date('d-m-Y', strtotime($leaveData->to_date_new));
|
|
|
|
$values = ['Manager', $leaveData->emp_name, $leaveData->no_of_days, $leaveData->leave_type, $fromDate, $toDate, $leaveData->risedby, $leaveData->leave_bal, $leaveData->status, $leaveData->comments];
|
|
|
|
}
|
|
else{
|
|
$fromDate = date('d-m-Y', strtotime($leaveData->from_date_new));
|
|
$toDate = date('d-m-Y', strtotime($leaveData->to_date_new));
|
|
|
|
$values = [$managerName->name, $leaveData->emp_name, $leaveData->no_of_days, $leaveData->leave_type, $fromDate, $toDate, $leaveData->risedby, $leaveData->leave_bal, $leaveData->status, $leaveData->comments];
|
|
|
|
}
|
|
}
|
|
$result = [];
|
|
foreach ($placeholders as $index => $placeholder) {
|
|
$result[] = ['placeholder' => '[' . trim($placeholder, '[]') . ']', 'strval' => $values[$index]];
|
|
}
|
|
// echo($managerID)."<br>";print_r($managerName); echo "IS".$inputString."<br>";
|
|
// echo $templateData->content."<br>";print_r($result);
|
|
// die;
|
|
return $body = replaceTemplateWithData($templateData->content,$result);
|
|
|
|
}
|
|
|
|
public function preprocessTemplateDataForLeaveApprove($leaveData, $templateData){
|
|
|
|
$managerID = $leaveData->ManagerId;
|
|
$managerName = $this->Notification_model->get_user_data($managerID);
|
|
|
|
$inputString = $templateData->placeholder;
|
|
$placeholders = explode(',', $inputString);
|
|
if($leaveData->leave_code === 'permission'){
|
|
$perm_date_new = date('d-m-Y', strtotime($leaveData->perm_date_new));
|
|
$values = [$leaveData->emp_name, $leaveData->from_time, $leaveData->to_time, $perm_date_new, $leaveData->ApproveBy, $leaveData->status];
|
|
}
|
|
else{
|
|
$fromDate = date('d-m-Y', strtotime($leaveData->from_date_new));
|
|
$toDate = date('d-m-Y', strtotime($leaveData->to_date_new));
|
|
|
|
$values = [$leaveData->emp_name, $fromDate, $toDate, $leaveData->no_of_days, $leaveData->ApproveBy, $leaveData->status];
|
|
}
|
|
$result = [];
|
|
foreach ($placeholders as $index => $placeholder) {
|
|
$result[] = ['placeholder' => '[' . trim($placeholder, '[]') . ']', 'strval' => $values[$index]];
|
|
}
|
|
|
|
return $body = replaceTemplateWithData($templateData->content,$result);
|
|
|
|
}
|
|
|
|
public function preprocessTemplateDataForLeaveDecline($leaveData, $templateData){
|
|
|
|
$managerID = $leaveData->ManagerId;
|
|
$managerName = $this->Notification_model->get_user_data($managerID);
|
|
|
|
$inputString = $templateData->placeholder;
|
|
$placeholders = explode(',', $inputString);
|
|
if($leaveData->leave_code === 'permission'){
|
|
$perm_date_new = date('d-m-Y', strtotime($leaveData->perm_date_new));
|
|
$values = [$leaveData->emp_name, $leaveData->from_time, $leaveData->to_time, $perm_date_new, $leaveData->declined_by, $leaveData->status, $leaveData->DReason];
|
|
}
|
|
else{
|
|
$fromDate = date('d-m-Y', strtotime($leaveData->from_date_new));
|
|
$toDate = date('d-m-Y', strtotime($leaveData->to_date_new));
|
|
|
|
$values = [$leaveData->emp_name, $fromDate, $toDate, $leaveData->no_of_days, $leaveData->declined_by, $leaveData->status, $leaveData->DReason];
|
|
}
|
|
$result = [];
|
|
foreach ($placeholders as $index => $placeholder) {
|
|
$result[] = ['placeholder' => '[' . trim($placeholder, '[]') . ']', 'strval' => $values[$index]];
|
|
}
|
|
|
|
return $body = replaceTemplateWithData($templateData->content,$result);
|
|
|
|
}
|
|
|
|
// end of Send Mail For Apply Leave and apply Permission also Approve and Decline
|
|
|
|
|
|
|
|
// Send mail for Assign Delegation
|
|
public function sendNotificationForDelegation($Delecation_id, $code, $type){
|
|
|
|
$delegationData = collectDelegationData($Delecation_id);
|
|
$templateData = getTempleteData($code, $type);
|
|
|
|
$FormettedTemplateData = $this->preprocessTemplateDataForAssignDelegation($delegationData,$templateData);
|
|
return $this->prepareNotificationDataForDelegation($FormettedTemplateData,$templateData,$delegationData,$type, $code);
|
|
|
|
}
|
|
|
|
|
|
public function preprocessTemplateDataForAssignDelegation($Data, $templateData){
|
|
|
|
$inputString = $templateData->placeholder;
|
|
$placeholders = explode(',', $inputString);
|
|
|
|
$values = [$Data->delegatePersonName, $Data->from_date_new, $Data->to_date_new, $Data->emp_name];
|
|
$result = [];
|
|
foreach ($placeholders as $index => $placeholder) {
|
|
$result[] = ['placeholder' => '[' . trim($placeholder, '[]') . ']', 'strval' => $values[$index]];
|
|
}
|
|
|
|
return $body = replaceTemplateWithData($templateData->content,$result);
|
|
|
|
}
|
|
|
|
// end of Send mail for Assign Delegation
|
|
|
|
|
|
|
|
|
|
// Send mail for Applay , Approve, Decline expence
|
|
public function sendNotificationForExpense($ecpence_id, $code, $type){
|
|
|
|
$expenceData = collectExpenceData($ecpence_id);
|
|
$expenceChildData = $this->Notification_model->get_expence_child_data_using_expence_id($ecpence_id);
|
|
|
|
// echo $ecpence_id;
|
|
// echo '--------------------------------------------------------------';
|
|
// echo '<pre>';
|
|
// print_r($expenceData);
|
|
// echo '--------------------------------------------------------------';
|
|
// print_r($expenceChildData); die;
|
|
|
|
|
|
$templateData = getTempleteData($code, $type);
|
|
|
|
if($code === 'EXPENCE_CLAIM'){
|
|
|
|
$FormettedTemplateData = $this->preprocessTemplateDataForExpense($expenceData,$templateData,$expenceChildData);
|
|
}else if($code === 'APPROVE_EXPENCE'){
|
|
|
|
$FormettedTemplateData = $this->preprocessTemplateDataForExpenseApprove($expenceData,$templateData,$expenceChildData);
|
|
}else if($code === 'DECLINE_EXPENCE'){
|
|
|
|
$FormettedTemplateData = $this->preprocessTemplateDataForExpenseDecline($expenceData,$templateData,$expenceChildData);
|
|
|
|
}
|
|
return $this->prepareNotificationDataForExpence($FormettedTemplateData,$templateData,$expenceData,$type, $code);
|
|
}
|
|
|
|
|
|
public function preprocessTemplateDataForExpense($Data, $templateData, $expenceChildData){
|
|
|
|
$inputString = $templateData->placeholder;
|
|
$placeholders = explode(',', $inputString);
|
|
|
|
$tableRows = '';
|
|
foreach ($expenceChildData as $row) {
|
|
$tableRows .= '<tr>';
|
|
$tableRows .= '<td>' . $row['childExpenceDate'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childAmount'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childDescription'] . '</td>';
|
|
$tableRows .= '</tr>';
|
|
}
|
|
|
|
$values =[$Data->managerName, $Data->emp_name];
|
|
$emailTemplate = str_replace('[table_rows]', $tableRows, $templateData->content);
|
|
foreach ($placeholders as $index => $placeholder) {
|
|
$result[] = ['placeholder' => '[' . trim($placeholder, '[]') . ']', 'strval' => $values[$index]];
|
|
}
|
|
|
|
return $body = replaceTemplateWithData($emailTemplate,$result);
|
|
}
|
|
|
|
public function preprocessTemplateDataForExpenseApprove($Data, $templateData, $expenceChildData){
|
|
|
|
$inputString = $templateData->placeholder;
|
|
$placeholders = explode(',', $inputString);
|
|
|
|
$tableRows = '';
|
|
foreach ($expenceChildData as $row) {
|
|
$tableRows .= '<tr>';
|
|
$tableRows .= '<td>' . $row['childExpenceDate'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childAmount'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childDescription'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childStatus'] . '</td>';
|
|
$tableRows .= '</tr>';
|
|
}
|
|
|
|
$values =[$Data->managerName, $Data->emp_name, $Data->status];
|
|
$emailTemplate = str_replace('[table_rows]', $tableRows, $templateData->content);
|
|
foreach ($placeholders as $index => $placeholder) {
|
|
$result[] = ['placeholder' => '[' . trim($placeholder, '[]') . ']', 'strval' => $values[$index]];
|
|
}
|
|
|
|
|
|
$body = replaceTemplateWithData($emailTemplate,$result);
|
|
return $body;
|
|
}
|
|
|
|
public function preprocessTemplateDataForExpenseDecline($Data, $templateData, $expenceChildData){
|
|
|
|
$inputString = $templateData->placeholder;
|
|
$placeholders = explode(',', $inputString);
|
|
|
|
$tableRows = '';
|
|
foreach ($expenceChildData as $row) {
|
|
$tableRows .= '<tr>';
|
|
$tableRows .= '<td>' . $row['childExpenceDate'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childAmount'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childDescription'] . '</td>';
|
|
$tableRows .= '<td>' . $row['childStatus'] . '</td>';
|
|
$tableRows .= '</tr>';
|
|
}
|
|
|
|
$values =[$Data->managerName, $Data->emp_name, $Data->status];
|
|
$emailTemplate = str_replace('[table_rows]', $tableRows, $templateData->content);
|
|
foreach ($placeholders as $index => $placeholder) {
|
|
$result[] = ['placeholder' => '[' . trim($placeholder, '[]') . ']', 'strval' => $values[$index]];
|
|
}
|
|
// echo '<pre>';
|
|
// print_r($result); die;
|
|
|
|
return $body = replaceTemplateWithData($emailTemplate,$result);
|
|
}
|
|
// end of Send mail for Applay , Approve, Decline expence
|
|
|
|
|
|
|
|
}
|