diff --git a/application/config/development/autoload.php b/application/config/development/autoload.php index 47a3ba2..367fa04 100644 --- a/application/config/development/autoload.php +++ b/application/config/development/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('email'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url'); +$autoload['helper'] = array('url', 'mail'); /* | ------------------------------------------------------------------- diff --git a/application/config/production/autoload.php b/application/config/production/autoload.php index 47a3ba2..367fa04 100644 --- a/application/config/production/autoload.php +++ b/application/config/production/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); +$autoload['libraries'] = array('email'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url'); +$autoload['helper'] = array('url', 'mail'); /* | ------------------------------------------------------------------- diff --git a/application/config/testing/autoload.php b/application/config/testing/autoload.php index 1eac0b5..6cafc14 100644 --- a/application/config/testing/autoload.php +++ b/application/config/testing/autoload.php @@ -58,7 +58,7 @@ | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array('session','database'); +$autoload['libraries'] = array('session','database','email'); /* | ------------------------------------------------------------------- @@ -89,7 +89,7 @@ | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url','custom'); +$autoload['helper'] = array('url','custom','mail', 'data'); /* | ------------------------------------------------------------------- diff --git a/application/config/testing/config.php b/application/config/testing/config.php index faf2337..1f213ef 100644 --- a/application/config/testing/config.php +++ b/application/config/testing/config.php @@ -102,7 +102,7 @@ | setting this variable to TRUE (boolean). See the user guide for details. | */ -$config['enable_hooks'] = FALSE; +$config['enable_hooks'] = TRUE; /* |-------------------------------------------------------------------------- diff --git a/application/config/testing/hooks.php b/application/config/testing/hooks.php index a8f38a5..9e912d6 100644 --- a/application/config/testing/hooks.php +++ b/application/config/testing/hooks.php @@ -11,3 +11,11 @@ | https://codeigniter.com/user_guide/general/hooks.html | */ + +$hook['pre_controller'] = array( + 'class' => 'MyHooks', + 'function' => 'initialize', + 'filename' => 'MyHooks.php', + 'filepath' => 'hooks', +); + diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 4ee740f..2047308 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -50,6 +50,7 @@ public function __construct() ### Syntax : $this->load->module('module_name', $params, $object_name); $this->load->module('Layout'); $this->load->module('Audit'); + $this->load->module('Notification'); } } diff --git a/application/helpers/custom_helper.php b/application/helpers/custom_helper.php index 76bda5f..0489ec8 100644 --- a/application/helpers/custom_helper.php +++ b/application/helpers/custom_helper.php @@ -78,6 +78,22 @@ function user() } } + if (!function_exists('business')) + { + function business() + { + $ci =& get_instance(); + $business = $ci->auth_model->get_logged_business(user()->business_id); + if (empty($business)) + { + $ci->auth_model->logout(); + } else { + return $business; + } + + } + } + if (!function_exists('employee')) { function employee() diff --git a/application/helpers/data_helper.php b/application/helpers/data_helper.php new file mode 100644 index 0000000..b3ac23c --- /dev/null +++ b/application/helpers/data_helper.php @@ -0,0 +1,58 @@ +Notification_model->get_leave_data_using_leave_id($id); +} + +} + +if (!function_exists('collectDelegationData')) { + + function collectDelegationData($id){ + + $ci =& get_instance(); + return $ci->Notification_model->get_delegation_data_using_delegation_id($id); + } + +} + +if (!function_exists('collectExpenceData')) { + + function collectExpenceData($id){ + + $ci =& get_instance(); + return $ci->Notification_model->get_expence_data_using_expence_id($id); + } + +} + + +if (!function_exists('getTempleteData')) { + + function getTempleteData($code, $type){ + + $ci =& get_instance(); + return $ci->Notification_model->get_template_data_using_code($code, $type); + } + +} + +if (!function_exists('replaceTemplateWithData')) { + + function replaceTemplateWithData($originalTemplate, $placeholders) { + $notificationContent = $originalTemplate; + foreach ($placeholders as $value) { + $notificationContent = str_replace($value['placeholder'], $value['strval'], $notificationContent); + } + return $notificationContent; + } + +} + + +?> \ No newline at end of file diff --git a/application/helpers/mail_helper.php b/application/helpers/mail_helper.php new file mode 100644 index 0000000..9cf17b4 --- /dev/null +++ b/application/helpers/mail_helper.php @@ -0,0 +1,156 @@ +sender_mail); + + + try { + $mailer = new PHPMailer(true); + log_message('info', 'phpmailer loaded'); + + $mailer->isSMTP(); + $mailer->CharSet = 'utf-8'; + $mailer->Host=business()->mail_hostname; + $mailer->SMTPSecure = business()->mail_security; + $mailer->SMTPAuth =true; + $mailer->SMTPDebug = 2; + $mailer->Username=business()->mail_username; + $mailer->Password=business()->mail_password; + $mailer->Port=business()->mail_port_no; + $mailer->setFrom(business()->sender_mail, $aliasName); + $mailer->addAddress($to); + + // Add CC recipients + if ($cc !== null) { + if (is_array($cc)) { + foreach ($cc as $ccRecipient) { + $mailer->addCC($ccRecipient); + } + } else { + $mailer->addCC($cc); + } + } + + // Add BCC recipients + if ($bcc !== null) { + if (is_array($bcc)) { + foreach ($bcc as $bccRecipient) { + $mailer->addBCC($bccRecipient); + } + } else { + $mailer->addBCC($bcc); + } + } + + $mailer->Subject=$subject; + $mailer->isHTML(true); + $mailer->Body=$body; + + $attachmentPath = '/path/to/your/attachment/' . $receipt; + + if (file_exists($attachmentPath)) { + $mailer->addAttachment($attachmentPath); + } + + $mailer->send(); + + return true; + log_message('info', 'success : mail sendsuccessfully'); + + } catch (Exception $e) { + + return 'Error: ' . $mailer->ErrorInfo; + log_message('info', 'Error : '.$mailer->ErrorInfo); + + } +} + + + +} + +if (!function_exists('send_emails_forgot_password')) { + + function send_emails_forgot_password($to, $subject, $body, $aliasName = '', $cc = null, $bcc = null, $receipt = null) + { + + log_message('info', 'send_mail_helper_loadded'); + log_message('info', 'Receiptent mail - '.$to.' - subject - '.$subject.' - body - '.$body); + log_message('info', 'Sender mail '.business()->sender_mail); + + + try { + $mailer = new PHPMailer(true); + log_message('info', 'phpmailer loaded'); + + $mailer->isSMTP(); + $mailer->CharSet = 'utf-8'; + $mailer->Host='smtp.sendgrid.net'; + $mailer->SMTPSecure = 'tls'; + $mailer->SMTPAuth =true; + $mailer->SMTPDebug = 2; + $mailer->Username='apikey'; + $mailer->Password='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'; + $mailer->Port='587'; + $mailer->setFrom('no-reply@tripapprovaltool.com'); + $mailer->addAddress($to); + + // Add CC recipients + if ($cc !== null) { + if (is_array($cc)) { + foreach ($cc as $ccRecipient) { + $mailer->addCC($ccRecipient); + } + } else { + $mailer->addCC($cc); + } + } + + // Add BCC recipients + if ($bcc !== null) { + if (is_array($bcc)) { + foreach ($bcc as $bccRecipient) { + $mailer->addBCC($bccRecipient); + } + } else { + $mailer->addBCC($bcc); + } + } + + $mailer->Subject=$subject; + $mailer->isHTML(true); + $mailer->Body=$body; + + $attachmentPath = '/path/to/your/attachment/' . $receipt; + + if (file_exists($attachmentPath)) { + $mailer->addAttachment($attachmentPath); + } + + $mailer->send(); + + return true; + log_message('info', 'success : mail sendsuccessfully'); + + } catch (Exception $e) { + + return 'Error: ' . $mailer->ErrorInfo; + log_message('info', 'Error : '.$mailer->ErrorInfo); + + } + } + + + + } + +?> \ No newline at end of file diff --git a/application/hooks/MyHooks.php b/application/hooks/MyHooks.php new file mode 100644 index 0000000..d9b080b --- /dev/null +++ b/application/hooks/MyHooks.php @@ -0,0 +1,15 @@ +load->database(); + $sql = "UPDATE `delegation` SET is_active = 0 WHERE to_date < CURDATE(); "; + $data = $CI->db->query($sql); + } + +} + diff --git a/application/modules/Auth/controllers/Auth.php b/application/modules/Auth/controllers/Auth.php index 46b2d1d..83b2558 100644 --- a/application/modules/Auth/controllers/Auth.php +++ b/application/modules/Auth/controllers/Auth.php @@ -166,6 +166,62 @@ public function sendMail(){ } } + public function sendOTP(){ + + $mail = $this->input->get('email'); + $otp = $this->input->get('otp'); + $where = 'email'; + $user = $this->auth_model->validateUserForOtp($mail, $where); + $id = $user->id; + $data['csrf_hash'] = $this->security->get_csrf_hash(); + $data['id'] = $id; + $data['email'] = $mail; + + + $body =` + + +
+

One-Time Password (OTP) Verification

+

Hello,

+

Your One-Time Password (OTP) for verification is:

+
+ `. $otp .` +
+

This OTP is valid for a short period. Please do not share it with anyone.

+

If you did not request this OTP, please ignore this email.

+

Thank you!

+
+

© 2023

+ +
+ + `; + + $subject = 'Forgot Password OTP Send'; + + $result = send_emails_forgot_password($mail, $subject, $body); + + if($result){ + $data['csrf_hash'] = $this->security->get_csrf_hash(); + $data['status'] = "success"; + $data['id'] = $id; + $data['email'] = $mail; + echo json_encode($data); + + }else{ + + $data['csrf_hash'] = $this->security->get_csrf_hash(); + $data['status'] = "failed"; + $data['id'] = $id; + $data['email'] = $mail; + $data['result'] = $result; + echo json_encode($data); + } + + } + + public function verify_otp(){ $id = $this->input->post('id'); @@ -177,7 +233,7 @@ public function verify_otp(){ if ($user->otp == $user_entered_otp) { - $data['generate_otp'] = $generate_otp; + $data['generate_otp'] = $user->otp; $data['user_entered_otp'] = $user_entered_otp; $data['csrf_hash'] = $this->security->get_csrf_hash(); $data['status'] = "success"; diff --git a/application/modules/Auth/models/Auth_model.php b/application/modules/Auth/models/Auth_model.php index 15d4fd1..ad38b6f 100644 --- a/application/modules/Auth/models/Auth_model.php +++ b/application/modules/Auth/models/Auth_model.php @@ -34,6 +34,15 @@ public function get_logged_user() } } + public function get_logged_business( $id) + { + $this->db->select('B.*'); + $this->db->from('business as B'); + $this->db->where('B.uid', $id); + $query = $this->db->get(); + return $query->row(); + } + public function get_logged_employee() { if ($this->is_logged_in()) { diff --git a/application/modules/Auth/views/otp_verification.php b/application/modules/Auth/views/otp_verification.php index 130f599..ca18e08 100644 --- a/application/modules/Auth/views/otp_verification.php +++ b/application/modules/Auth/views/otp_verification.php @@ -78,7 +78,7 @@
-

Time remaining: 90 seconds

+

Time remaining: 90 seconds

@@ -124,7 +124,7 @@ function send_otp() { $('input[name=csrf_test_name]').val(response.csrf_hash); $('#span_msg').html('invalid username').css('color', 'red'); } else { - //for OTP Send success Lable + // for OTP Send success Lable new PNotify({ title: 'OTP Send Successfully', text: 'Check Your Mail', @@ -133,7 +133,6 @@ function send_otp() { delay: 2000 }); - //update the csrf to the form $('input[name=csrf_test_name]').val(response.csrf_hash); $('#hidden_otp').val(response.otp); @@ -141,6 +140,38 @@ function send_otp() { $('#id').val(response.id); $('#submitButton').show(); $('#email').prop('required', false); + + + $.ajax({ + type: "get", + url: "Auth/sendOTP", + data: {email : email, otp : response.otp}, + json: true, + success: function(response) { + response = jQuery.parseJSON(response) + alert(response); + if (response.status == "failed") { + new PNotify({ + title: 'OTP Send Failed', + text: response.result, + type: 'warning', + styling: 'bootstrap3', + delay: 2000 + }); + } else { + new PNotify({ + title: 'OTP Send Sucessfully', + type: 'success', + styling: 'bootstrap3', + delay: 2000 + }); + } + }, + error: function(jqXHR, textStatus, err) { + alert('text status ' + textStatus + ', err ' + err) + } + }); + } }, error: function(jqXHR, textStatus, err) { @@ -205,7 +236,6 @@ function startTimer(seconds) { if (seconds <= 0) { clearInterval(timer); $('#timer').html('Did not Recive the OTP pleace click the Resend OTP Button'); - // Enable the button after the timer reaches zero $('#sendotpbtn').prop('disabled', false); } }, 1000); diff --git a/application/modules/Business/controllers/Business.php b/application/modules/Business/controllers/Business.php index 6ddfec8..e3010c0 100644 --- a/application/modules/Business/controllers/Business.php +++ b/application/modules/Business/controllers/Business.php @@ -148,16 +148,16 @@ public function create_business() } - public function get_business($id, $uid) + public function get_business($id) { - + //select dropdown values $this->layout->set('stateData', $this->MY_Model->select('state')); // select business value by id $table="business"; $businessData = $this->Business_model->get_business_by_md5_id($id); - $businessModuleData = $this->Business_model->get_business_modules($uid); + $businessModuleData = $this->Business_model->get_business_modules($id); $this->layout->set('ModuleData', $this->MY_Model->select('modules')); $this->layout->set('businessModuleData', $businessModuleData); $this->layout->set('businessData', $businessData); diff --git a/application/modules/Business/models/Business_model.php b/application/modules/Business/models/Business_model.php index 9fcd114..c12e405 100644 --- a/application/modules/Business/models/Business_model.php +++ b/application/modules/Business/models/Business_model.php @@ -19,7 +19,7 @@ public function get_business_by_md5_id($id) $this->db->from('business B'); $this->db->join('state', 'state.id = B.state', 'left'); $this->db->where('B.is_active', 1); - $this->db->where('md5(B.id)', $id); + $this->db->where('md5(B.uid)', $id); $query = $this->db->get(); $query = $query->row(); return $query; @@ -37,7 +37,7 @@ public function get_business_modules($business_id) $this->db->select('permit_modules.*,modules.modules'); $this->db->from('permit_modules'); $this->db->join('modules', 'permit_modules.module_id = modules.id and modules.is_active = 1', 'left'); - $this->db->where('uid', $business_id); + $this->db->where('md5(uid)', $business_id); $this->db->where('permit_modules.is_active', 1); $query = $this->db->get(); return $query->result(); diff --git a/application/modules/Business/views/add_business.php b/application/modules/Business/views/add_business.php index c1cf26a..cf4d1b1 100644 --- a/application/modules/Business/views/add_business.php +++ b/application/modules/Business/views/add_business.php @@ -197,7 +197,7 @@ class="form-control" onkeyup="check_if_exists(this.id, this.value, this.name)"> -

+

@@ -240,6 +240,57 @@ class="form-control" onkeyup="check_if_exists(this.id, this.value, this.name)">
+


+
+
+
Mail Configurations
+

+ + + +
+ +
+ +
+ + +
+ +
+
+ + +
+ + +
+ +
+ + +
+ +
+ +
+ + + +
+ +
+ +
+ + +
+ +
+
+ + +
diff --git a/application/modules/Business/views/business_list.php b/application/modules/Business/views/business_list.php index d92ea11..426341f 100644 --- a/application/modules/Business/views/business_list.php +++ b/application/modules/Business/views/business_list.php @@ -77,7 +77,7 @@ is_active == 1) { ?> -   +     is_active == 0) { ?> diff --git a/application/modules/Business/views/confirmation_popup.php b/application/modules/Business/views/confirmation_popup.php index d6f94c0..df8f874 100644 --- a/application/modules/Business/views/confirmation_popup.php +++ b/application/modules/Business/views/confirmation_popup.php @@ -6,7 +6,7 @@
diff --git a/application/modules/Business/views/edit_business.php b/application/modules/Business/views/edit_business.php index 14ffcc6..8a82e1e 100644 --- a/application/modules/Business/views/edit_business.php +++ b/application/modules/Business/views/edit_business.php @@ -178,7 +178,11 @@ class="form-control" onkeyup="check_if_exists(this.id, this.value, this.name)" /
+
+ + +
+ @@ -212,7 +217,7 @@ class="form-control" onkeyup="check_if_exists(this.id, this.value, this.name)" /

-

+

@@ -257,6 +262,57 @@ class="form-control" type="text">
+


+
+
+
Mail Configurations
+

+ + + +
+ +
+ +
+ + +
+ +
+
+ + +
+ + +
+ +
+ + +
+ +
+ +
+ + + +
+ +
+ +
+ + +
+ +
+
+ + +
diff --git a/application/modules/Delegation/controllers/Delegation.php b/application/modules/Delegation/controllers/Delegation.php index aa1d62e..b99dbf0 100644 --- a/application/modules/Delegation/controllers/Delegation.php +++ b/application/modules/Delegation/controllers/Delegation.php @@ -54,11 +54,19 @@ public function Assign_Delecation() { $data = $this->input->post(); $data['business_id'] = user()->business_id; - $data['delegated_at'] = date('d-m-Y H:i'); $data['is_active'] = 1; + $data['from_date'] = date('Y-m-d', strtotime($this->input->post('from_date'))); + $data['to_date'] = date('Y-m-d', strtotime($this->input->post('to_date'))); + $table="delegation"; - $Delecation = $this->MY_Model->insert($data, $table); + $Delecation_id = $this->MY_Model->insert($data, $table); + + if($Delecation_id){ + $code = 'ASSIGN_DELEGATION'; + $type = 'Email'; + $this->notification->sendNotificationForDelegation($Delecation_id, $code, $type); + } $this->session->set_flashdata('Success', 'Delegation Assigned Successfully'); @@ -85,10 +93,10 @@ public function Edit_Create_Delecation() $action = $this->input->post(); unset($action['id']); $id = $this->input->post('id'); - //var_dump($id); die(); $action['business_id'] = user()->business_id; - $action['updated_at'] = date('d-m-Y H:i a'); $action['is_active'] = 1; + $action['from_date'] = date('Y-m-d', strtotime($this->input->post('from_date'))); + $action['to_date'] = date('Y-m-d', strtotime($this->input->post('to_date'))); $table="delegation"; $Delecation = $this->MY_Model->edit_option($action, $id, $table); @@ -119,7 +127,7 @@ public function checkUniqueValue() $data = $this->input->get('emp_id'); $table = 'delegation'; $where = 'delegated_to'; - $result = $this->MY_Model->checkUniqueValueInDataBase($table, $where, $data); + $result = $this->Delegation_model->checkUniqueValueInDataBase($table, $where, $data); if(count($result)){ $this->output->set_output(true); }else{ diff --git a/application/modules/Delegation/models/Delegation_model.php b/application/modules/Delegation/models/Delegation_model.php index 40bb671..482e5d3 100644 --- a/application/modules/Delegation/models/Delegation_model.php +++ b/application/modules/Delegation/models/Delegation_model.php @@ -84,5 +84,15 @@ public function Expencecancle($id, $data) return; } + public function checkUniqueValueInDataBase($table, $where, $data){ + + $this->db->select('*'); + $this->db->from($table); + $this->db->where($where, $data); + $this->db->where('is_active', 1); + return $this->db->get()->result_array(); + + } + } \ No newline at end of file diff --git a/application/modules/Delegation/views/delegation_form.php b/application/modules/Delegation/views/delegation_form.php index ac759c3..d88bcab 100644 --- a/application/modules/Delegation/views/delegation_form.php +++ b/application/modules/Delegation/views/delegation_form.php @@ -1,12 +1,6 @@ - - - - - - - - - + + + @@ -108,28 +102,32 @@ - - - - - - - - - + + + + +

Someone has contacted you!

+

+

Sender Details


+ + + + + + + +
Name
Suseendhiran
+ + "; + $subject ="test email"; + $result = send_emails($to, $subject, $body); + + if ($result === true) { + echo 'Email sent successfully'; + } else { + echo 'Errors: ' . $result; + } + + } } diff --git a/application/modules/Employee/views/emp_list.php b/application/modules/Employee/views/emp_list.php index a0d0b16..2342b4e 100644 --- a/application/modules/Employee/views/emp_list.php +++ b/application/modules/Employee/views/emp_list.php @@ -12,6 +12,7 @@

Employee Details

diff --git a/application/modules/Expence/controllers/Expence.php b/application/modules/Expence/controllers/Expence.php index f376adc..a3b0a5d 100644 --- a/application/modules/Expence/controllers/Expence.php +++ b/application/modules/Expence/controllers/Expence.php @@ -294,6 +294,10 @@ public function expence_list_view($id) { $expence_list = $this->Expence_model->get_expense_child_data2($id); $get_expense_name = $this->Expence_model->get_expense_data_not_md5($id); + $expence_list_with_delegation = $this->Expence_model->get_all_leave_request_by_manager_id_with_delegation(user()->business_id, user()->id); + if($expence_list_with_delegation == NULL){ + $expence_list_with_delegation = []; + } $this->layout->set('tableData', $expence_list); $this->layout->set('expense_name', $get_expense_name); $this->layout->buffer('main_content', 'Expence/expence_list_view'); @@ -337,26 +341,32 @@ public function getDeleteConfirmationPopup() public function Approve_Expence() { - $id=$this->input->post('id'); + $id=$this->input->post('id'); + // echo $id; die; $action['status'] = 'Approved'; $action['approved_by']= user()->name; $action['approved_at'] = date('Y-m-d h:i:s'); $table = "expense"; - $this->MY_Model->edit_option($action, $id, $table); + $expence_id = $this->MY_Model->edit_option($action, $id, $table); $this->Expence_model->approve_child_expense($action, $id); + if($expence_id){ + $code = 'APPROVE_EXPENCE'; + $type = 'Email'; + $this->notification->sendNotificationForExpense($id, $code, $type); + } $this->session->set_flashdata('Create', '1'); redirect('Expence/expence_list'); } public function Approve_Child_Expence() { - if($this->input->get('reason')) + if($this->input->post('declinedata')) { - $id=$this->input->get('id'); - $expense_id=$this->input->get('expence_id'); + $id=$this->input->post('id'); + $expense_id=$this->input->post('expence_id'); $decline_action['status'] = 'Declined'; $decline_action['decline_by'] = user()->name; - $decline_action['decline_reason'] = $this->input->get('reason'); + $decline_action['decline_reason'] = $this->input->post('declinedata'); $is_decline = $this->Expence_model->approve_child_expense_2($decline_action, $id); if($is_decline == true) @@ -371,7 +381,12 @@ public function Approve_Child_Expence() else if($count->approve_count >= 1 && $count->declined_count >= 1) { $status_update['status'] = 'Partially approved'; - return $this->MY_Model->edit_option($status_update, $expense_id, $table); + $id_for_expence = $this->MY_Model->edit_option($status_update, $expense_id, $table); + if($id_for_expence){ + $code = 'APPROVE_EXPENCE'; + $type = 'Email'; + $this->notification->sendNotificationForExpense($expense_id, $code, $type); + } } else if($count->declined_count >= 1 && $count->approve_count == 0 && $count->pending_count == 0) { @@ -381,6 +396,8 @@ public function Approve_Child_Expence() return $this->MY_Model->edit_option($status_update, $expense_id, $table); } } + + redirect('Expence/expence_list_view/'.$this->input->post('expence_id')); } else @@ -403,7 +420,12 @@ public function Approve_Child_Expence() else if($count->approve_count >= 1 && $count->declined_count >= 1) { $status_update['status'] = 'Partially approved'; - $this->MY_Model->edit_option($status_update, $expense_id, $table); + $id_for_expence = $this->MY_Model->edit_option($status_update, $expense_id, $table); + if($id_for_expence){ + $code = 'APPROVE_EXPENCE'; + $type = 'Email'; + $this->notification->sendNotificationForExpense($expense_id, $code, $type); + } } else if($count->approve_count >= 1 && $count->declined_count == 0 && $count->pending_count == 0) { @@ -423,15 +445,28 @@ public function Approve_Child_Expence() } + public function getDeclineConfirmationPopup() + { + $data = array(); + $htmlPage = $this->load->view('confirmation_popup_2.php',$data,true); + echo json_encode($htmlPage); + } + public function Decline_expence() { - $id=$this->input->get('id'); + $id=$this->input->post('id'); + // echo $id; die; $data['status'] = 'Declined'; $data['decline_by'] = user()->name; - $data['decline_reason'] = $this->input->get('reason'); - $this->Expence_model->ExpenceDecline($id, $data); + $data['decline_reason'] = $this->input->get('declinedata'); + $expence_id = $this->Expence_model->ExpenceDecline($id, $data); $this->Expence_model->Expence_Decline_Child($id, $data); - return true; + if($expence_id){ + $code = 'DECLINE_EXPENCE'; + $type = 'Email'; + $this->notification->sendNotificationForExpense($id, $code, $type); + } + redirect('Expence/expence_list'); } @@ -476,8 +511,13 @@ public function submit() $table1 = 'expense'; $data['status'] = "pending"; $data['updated_on'] = date('Y-m-d h:i:s'); - $this->MY_Model->edit_option($data, $id, $table1); - $this->Expence_model->update_to_submit_all($id, $data); + $expence_id = $this->MY_Model->edit_option($data, $id, $table1); + $expence_child_id = $this->Expence_model->update_to_submit_all($id, $data); + if($expence_child_id){ + $code = 'EXPENCE_CLAIM'; + $type = 'Email'; + $this->notification->sendNotificationForExpense($id, $code, $type); + } redirect('Expence/emp_expence_list'); } diff --git a/application/modules/Expence/models/Expence_model.php b/application/modules/Expence/models/Expence_model.php index 227efe6..eab16ac 100644 --- a/application/modules/Expence/models/Expence_model.php +++ b/application/modules/Expence/models/Expence_model.php @@ -151,7 +151,7 @@ public function ExpenceDecline($id, $data) $this->db->where('id',$id); $this->db->where('status', 'pending'); $this->db->update('expense', $data); - return; + return true; } public function Expence_Decline_Child($id, $data) @@ -214,7 +214,7 @@ public function update_to_submit_all($id, $data) $this->db->where('expense_id',$id); $this->db->where('status', 'Draft'); $this->db->update('expense_child', $data); - return; + return true; } @@ -241,4 +241,51 @@ public function get_status_update($id) } + + + public function get_delegated_user_id($business_id, $user_id){ + $this->db->select('emp_id'); + $this->db->from('delegation'); + $this->db->where('business_id', $business_id); + $this->db->where('delegated_to', $user_id); + $this->db->where('is_active', 1); + $query = $this->db->get(); + $result_array = $query->result_array(); + $emp_ids = array_column($result_array, 'emp_id'); + return $emp_ids; + } + + public function get_all_leave_request_by_manager_id_with_delegation($business_id, $loggeduserid) + { + + $delegated_users_id_list = $this->get_delegated_user_id($business_id, $loggeduserid); + $count = count($delegated_users_id_list); + + if($count > 0) + { + foreach ($delegated_users_id_list as $user_id) { + + $this->db->select('A.* ,U1.name as emp_name, U2.name as ApproveBy, U3.name as DeclineBy, U4.name as Risedby, E.manager as manager_id, LM.type as leave_type, D.from_date as delegate_f_date, D.to_date as delegate_t_date, D.delegated_to, D.emp_id'); + $this->db->from('leave_list A'); + $this->db->join('users U1', 'U1.id = A.emp_id', 'left'); + $this->db->join('users U2', 'U2.id = A.approved_by', 'left'); + $this->db->join('users U3', 'U3.id = A.declined_by', 'left'); + $this->db->join('users U4', 'U4.id = A.risedby', 'left'); + $this->db->join('employees E', 'E.user_id = A.emp_id', 'left'); + $this->db->join('delegation D', 'D.business_id = A.business_id', 'left'); + $this->db->join('leave_master LM', 'LM.id = A.type', 'left'); + $this->db->where('A.business_id', $business_id); + $this->db->where('E.manager', $user_id); //User ID as Employee ID + // $this->db->where('D.emp_id', $user_id); + $this->db->order_by('A.id','DESC'); + $this->db->where('A.is_active', 1); + $query = $this->db->get(); + $query = $query->result(); + return $query; + } + } + + + } + } \ No newline at end of file diff --git a/application/modules/Expence/views/confirmation_popup_2.php b/application/modules/Expence/views/confirmation_popup_2.php new file mode 100644 index 0000000..3ed8924 --- /dev/null +++ b/application/modules/Expence/views/confirmation_popup_2.php @@ -0,0 +1,23 @@ + + + + diff --git a/application/modules/Expence/views/edit_expence.php b/application/modules/Expence/views/edit_expence.php index e04f637..7393033 100644 --- a/application/modules/Expence/views/edit_expence.php +++ b/application/modules/Expence/views/edit_expence.php @@ -453,8 +453,8 @@ function createAndAppendFormGroup() { html1 += '' html1 += '
' - html1 += '' - html1 += '
' + html1 += '' + html1 += '
' html1 += '
' html1 += '
' diff --git a/application/modules/Expence/views/emp_expence_list.php b/application/modules/Expence/views/emp_expence_list.php index cd19bae..91f1af4 100644 --- a/application/modules/Expence/views/emp_expence_list.php +++ b/application/modules/Expence/views/emp_expence_list.php @@ -34,7 +34,7 @@ cursor: pointer; } div.dataTables_wrapper div.dataTables_filter{ - margin-top: -30px !important; //search to up + margin-top: -30px !important; } .alert-success { diff --git a/application/modules/Expence/views/expence_list.php b/application/modules/Expence/views/expence_list.php index 3165c6f..9f48177 100644 --- a/application/modules/Expence/views/expence_list.php +++ b/application/modules/Expence/views/expence_list.php @@ -21,7 +21,7 @@ .modal-content_default { background-color: #fefefe; - margin: 15% auto;s + margin: 15% auto; padding: 20px; border: 1px solid #888; width: 380px; @@ -34,7 +34,8 @@ } div.dataTables_wrapper div.dataTables_filter{ - margin-top: -30px !important; //search to up + margin-top: -30px !important; +} @@ -199,11 +200,8 @@ status == 'pending') { ?>   - - -   - +   + @@ -275,6 +273,21 @@ } }); }); + +$('.test').click(function() { + var id = $(this).attr('id'); + var url = "Expence/Decline_expence"; + + $.ajax({ + url: "Expence/getDeclineConfirmationPopup", + type:"GET", + success:function(data){ + $('#popup').html(JSON.parse(data)); + $('.delete_id').attr('value',id); + $('.delete_url').attr('action',url); + } + }); +}); diff --git a/application/modules/Expence/views/expence_list_view.php b/application/modules/Expence/views/expence_list_view.php index 184941c..e743e75 100644 --- a/application/modules/Expence/views/expence_list_view.php +++ b/application/modules/Expence/views/expence_list_view.php @@ -21,7 +21,7 @@ .modal-content_default { background-color: #fefefe; - margin: 15% auto;s + margin: 15% auto; padding: 20px; border: 1px solid #888; width: 380px; @@ -34,7 +34,8 @@ } div.dataTables_wrapper div.dataTables_filter{ - margin-top: -30px !important; //search to up + margin-top: -30px !important; +} @@ -156,7 +157,6 @@ } } ?>" - autocomplete='off' required /> @@ -226,10 +226,8 @@ status == 'pending') { ?>   - - -   +   + @@ -276,6 +274,23 @@ } }); }); + +$('.test').click(function() { + var id = $(this).attr('id'); + var expence_id = document.getElementById('expense_id').value; + var url = "Expence/Approve_Child_Expence"; + + $.ajax({ + url: "Expence/getDeclineConfirmationPopup", + type:"GET", + success:function(data){ + $('#popup').html(JSON.parse(data)); + $('.delete_id').attr('value',id); + $('.expence_id').attr('value',expence_id); + $('.delete_url').attr('action',url); + } + }); +}); diff --git a/application/modules/Leave/controllers/Leave.php b/application/modules/Leave/controllers/Leave.php index 0b7b45b..d6119f8 100644 --- a/application/modules/Leave/controllers/Leave.php +++ b/application/modules/Leave/controllers/Leave.php @@ -78,7 +78,6 @@ public function applyLeave($update = null) $this->session->set_flashdata('error', 0); $this->layout->buffer('main_content', 'Leave/apply_leave'); $this->layout->render('Employee_Layout'); - } public function get_emp_leave_count() @@ -149,6 +148,14 @@ public function createLeave() $perm_data['created_time'] = date('H:i A'); $table="leave_list"; $create_permission = $this->MY_Model->insert($perm_data,$table); + + //for notification + if($create_permission){ + $code = 'LEAVE_PERMISSION'; + $type = 'Email'; + $this->notification->sendNotification($create_permission, $code, $type); + } + $this->session->set_flashdata('Success', '1'); redirect('Leave/LeaveHistory'); } @@ -259,7 +266,12 @@ public function createLeave() redirect('Leave/applyLeave/'.'update'); } - + + if($create_leave){ + $code = 'APPLY_LEAVE'; + $type = 'Email'; + $this->notification->sendNotification($create_leave, $code, $type); + } //audit if($create_leave) @@ -431,6 +443,13 @@ public function getDeleteConfirmationPopup() echo json_encode($htmlPage); } + public function getDeclineConfirmationPopup() + { + $data = array(); + $htmlPage = $this->load->view('confirmation_popup_2.php',$data,true); + echo json_encode($htmlPage); + } + public function ApproveLeave() { $id=$this->input->post('id'); @@ -438,36 +457,34 @@ public function ApproveLeave() $emp_id = $this->Leave_model->get_emp_id($id); $no_of_days = $this->Leave_model->get_Leave_nodays($id,); $leave_year = date('Y', strtotime($no_of_days->from_date)); - //print_r($no_of_days); die('approveleave'); - + $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); + if($leave_type->leave_code !== 'permission') + { $remaining_days = $this->Leave_model->remaining_days($emp_id, user()->business_id, $leave_year, $no_of_days->type); - //print_r($remaining_days); die(); $balance_days = $remaining_days[0]->remaining_days - $no_of_days->no_of_days; - if($remaining_days[0]->remaining_days <= 0){ - - $data['status'] = 'Declined'; - $data['declined_by']= user()->id; - $data['declined_at'] = date('d-m-Y H:i:s'); - $data['DReason'] = 'No sufficient leave balance'; - $this->Leave_model->LeaveDecline($id, $data); - redirect('Leave/leaveList'); - - } - else - { - $data['leave_bal'] = $balance_days; - $days['remaining_days'] = $balance_days; - $this->Leave_model->emp_leave_days_update($emp_id, $days, $leave_year, $business_id, $no_of_days->type); - + $data['leave_bal'] = $balance_days; + $days['remaining_days'] = $balance_days; + $this->Leave_model->emp_leave_days_update($emp_id, $days, $leave_year, $business_id, $no_of_days->type); + } + $data['status'] = 'Approved'; $data['approved_by']= user()->id; $data['approved_at'] = date('d-m-Y H:i:s'); - // print_r($data); die; - $this->Leave_model->LeaveApprove($id, $data); + $leave_approve = $this->Leave_model->LeaveApprove($id, $data); + if($leave_approve){ + + if($leave_type->leave_code === 'permission'){ + $code = 'APPROVE_PERMISSION'; + } + else{ + $code = 'APPROVE_LEAVE'; + } + $type = 'Email'; + $this->notification->sendNotification($id, $code, $type); + } redirect('Leave/leaveList'); - } } @@ -484,6 +501,7 @@ public function ManagerLeaveApprove() $emp_id = $this->Leave_model->get_emp_id($id); $no_of_days = $this->Leave_model->get_Leave_nodays($id,); $leave_year = date('Y', strtotime($no_of_days->from_date)); + $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); $remaining_days = $this->Leave_model->remaining_days($emp_id, user()->business_id, $leave_year, $no_of_days->type); $balance_days = $remaining_days[0]->remaining_days - $no_of_days->no_of_days; @@ -496,21 +514,70 @@ public function ManagerLeaveApprove() $data['status'] = 'Approved'; $data['approved_by']= user()->name; $data['approved_at'] = date('d-m-Y H:i:s'); - $this->Leave_model->LeaveApprove($id, $data); + $leave_approve = $this->Leave_model->LeaveApprove($id, $data); + if($leave_approve){ + + if($leave_type->leave_code === 'permission'){ + $code = 'APPROVE_PERMISSION'; + } + else{ + $code = 'APPROVE_LEAVE'; + } + $type = 'Email'; + $this->notification->sendNotification($id, $code, $type); + } redirect('Leave/manager_approvel'); } public function Decline() { - $id=$this->input->get('id'); + $id=$this->input->post('id'); $data['status'] = 'Declined'; $data['declined_by']= user()->name; $data['declined_at'] = date('d-m-Y H:i:s'); - $data['DReason'] = $this->input->get('reason'); - $this->Leave_model->LeaveDecline($id, $data); - return true; + $data['DReason'] = $this->input->post('declinedata'); + $leave_decline = $this->Leave_model->LeaveDecline($id, $data); + $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); + if($leave_decline){ + if($leave_type->leave_code === 'permission'){ + $code = 'DECLINE_PERMISSION'; + } + else{ + $code = 'DECLINE_LEAVE'; + } + $type = 'Email'; + $return = $this->notification->sendNotification($id, $code, $type); + + } + redirect('Leave/leaveList'); + } + public function managerDecline() + { + $id=$this->input->post('id'); + $data['status'] = 'Declined'; + $data['declined_by']= user()->name; + $data['declined_at'] = date('d-m-Y H:i:s'); + $data['DReason'] = $this->input->post('declinedata'); + $leave_decline = $this->Leave_model->LeaveDecline($id, $data); + $leave_type = $this->Leave_model->get_leave_data_using_leave_id($id); + if($leave_decline){ + if($leave_type->leave_code === 'permission'){ + $code = 'DECLINE_PERMISSION'; + } + else{ + $code = 'DECLINE_LEAVE'; + } + $type = 'Email'; + $return = $this->notification->sendNotification($id, $code, $type); + + } + redirect('Leave/manager_approvel'); + + } + + public function cancled() { $id=$this->input->get('id'); @@ -553,4 +620,6 @@ public function manager_approvel() $this->layout->render('Employee_Layout'); } + + } \ No newline at end of file diff --git a/application/modules/Leave/models/Leave_model.php b/application/modules/Leave/models/Leave_model.php index 7defa85..b77428b 100644 --- a/application/modules/Leave/models/Leave_model.php +++ b/application/modules/Leave/models/Leave_model.php @@ -18,6 +18,43 @@ public function get_leave_with_emp_name($business_id) } + public function get_leave_data_using_leave_id($leave_id) + { + $this->db->select('A.* ,U1.name as emp_name, U1.email as emp_email, U2.name as ApproveBy, U3.name as DeclineBy, U4.name as Risedby, E.manager as ManagerId, LM.code as leave_code, LM.type as leave_type'); + $this->db->from('leave_list A'); + $this->db->join('users U1', 'U1.id = A.emp_id', 'left'); + $this->db->join('users U2', 'U2.id = A.approved_by', 'left'); + $this->db->join('users U3', 'U3.id = A.declined_by', 'left'); + $this->db->join('users U4', 'U4.id = A.risedby', 'left'); + $this->db->join('employees E', 'E.user_id = A.emp_id', 'left'); + $this->db->join('leave_master LM', 'LM.id = A.type', 'left'); + $this->db->where('A.id', $leave_id); + $this->db->order_by('A.id','DESC'); + $this->db->where('A.is_active', 1); + $query = $this->db->get(); + if ($query->num_rows() > 0) { + return $row = $query->row(); + } else { + return false; + } + + } + + + public function get_template_data_using_code($code, $type){ + $this->db->select('*'); + $this->db->from('templates'); + $this->db->where('templet_code', $code); + $this->db->where('templet_type', $type); + $query = $this->db->get(); + if ($query->num_rows() > 0) { + return $query->row(); + } else { + return false; + } + } + + public function get_user_name($user_id){ $this->db->select('name'); @@ -238,7 +275,7 @@ public function LeaveApprove($id, $data) $this->db->where('id',$id); $this->db->update('leave_list', $data); - return; + return true; } @@ -247,7 +284,7 @@ public function LeaveDecline($id, $data) $this->db->where('id',$id); $this->db->where('status', 'pending'); $this->db->update('leave_list', $data); - return; + return true; } public function Leavecancle($id, $data) diff --git a/application/modules/Leave/views/apply_leave.php b/application/modules/Leave/views/apply_leave.php index e84b1af..f86ae67 100644 --- a/application/modules/Leave/views/apply_leave.php +++ b/application/modules/Leave/views/apply_leave.php @@ -302,7 +302,7 @@ $('#type').on('change',function() { let id = $("#user_dropdown").val(); - var type_id = $('option:selected', this).attr('id'); + var type_id = $('option:selected', this).val(); var fromdate = document.getElementById("fromdate").value; diff --git a/application/modules/Leave/views/confirmation_popup.php b/application/modules/Leave/views/confirmation_popup.php index f3a4d10..8a11622 100644 --- a/application/modules/Leave/views/confirmation_popup.php +++ b/application/modules/Leave/views/confirmation_popup.php @@ -5,8 +5,8 @@