526 lines
20 KiB
PHP
526 lines
20 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 Expence extends Admin_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('Expence_model','Expence_model');
|
|
$this->load->model('Employee/Employee_model','Emp_model');
|
|
$this->load->model('Audit/Audit_model','audit_model');
|
|
$this->load->helper(array('form', 'url'));
|
|
|
|
}
|
|
|
|
public function expence_form()
|
|
{
|
|
$id = $this->input->get('id');
|
|
$expense_data = $this->Expence_model->get_expense_data($id);
|
|
$expense_child_data = $this->Expence_model->get_expense_child_data($id);
|
|
$this->layout->set('expense_child_data', $expense_child_data);
|
|
$this->layout->buffer('main_content', 'Expence/expence_form');
|
|
$this->layout->render('Employee_Layout');
|
|
}
|
|
|
|
public function get_emp_name()
|
|
{
|
|
$emp = $this->Expence_model->get_employee_name(user()->business_id);
|
|
$html = '<option>--select Employee--</option>';
|
|
foreach($emp as $val)
|
|
{
|
|
if($val->user_id != user()->id)
|
|
{
|
|
$html .='<option id="'.$val->manager.'" value="'.$val->user_id.'">'.$val->name.'</option>';
|
|
}
|
|
}
|
|
echo json_encode($html);
|
|
}
|
|
|
|
public function rise_expence_request()
|
|
{
|
|
|
|
$data = $this->input->post('emp_id');
|
|
if(!empty($data)){
|
|
$emp_id =$this->input->post('emp_id');
|
|
}else{
|
|
$emp_id = user()->id;
|
|
}
|
|
$get_manager_id = $this->Expence_model->get_manager_id($emp_id);
|
|
|
|
if($get_manager_id[0]->manager == null){
|
|
|
|
$manager = 0;
|
|
}else{
|
|
|
|
$manager = $get_manager_id[0]->manager;
|
|
}
|
|
|
|
$data1 = array(
|
|
'created_by'=>user()->id,
|
|
'requested_for'=>$emp_id ,
|
|
'expense_name'=>$this->input->post('expense_name'),
|
|
'business_reason'=>$this->input->post('business_reason'),
|
|
'manager_id' => $manager,
|
|
'business_id' => user()->business_id,
|
|
'status'=>'Draft',
|
|
);
|
|
$table="expense";
|
|
$create_Expence = $this->MY_Model->insert($data1,$table);
|
|
|
|
$count = count($this->input->post('date_of_expence'));
|
|
for($i=0;$i<$count;$i++)
|
|
{
|
|
|
|
$data2 = array(
|
|
'expense_id' => $create_Expence,
|
|
'emp_id'=>$emp_id ,
|
|
'business_id' => user()->business_id,
|
|
'manager_id' => $manager,
|
|
'status' => 'Draft',
|
|
'date_of_expense'=> $this->input->post('date_of_expence')[$i],
|
|
'amount' => $this->input->post('amount')[$i],
|
|
'description' => $this->input->post('description')[$i],
|
|
);
|
|
$this->load->library('upload');
|
|
|
|
$config['upload_path'] = APPPATH. '../assets/uploads/Expence_Bill/';
|
|
$config['allowed_types'] = 'jpg|png|jpeg|pdf';
|
|
$config['max_size'] = 80000;
|
|
$config['file_name'] = time(). '_' . $_FILES['bill']['name'][$i];
|
|
|
|
$_FILES['userfile']['name'] = $_FILES['bill']['name'][$i];
|
|
$_FILES['userfile']['type'] = $_FILES['bill']['type'][$i];
|
|
$_FILES['userfile']['tmp_name'] = $_FILES['bill']['tmp_name'][$i];
|
|
$_FILES['userfile']['error'] = $_FILES['bill']['error'][$i];
|
|
$_FILES['userfile']['size'] = $_FILES['bill']['size'][$i];
|
|
|
|
$this->upload->initialize($config);
|
|
if ($this->upload->do_upload('userfile'))
|
|
{
|
|
$upload_image = $this->upload->data();
|
|
$data2['bill'] = $upload_image['file_name'];
|
|
}
|
|
else
|
|
{
|
|
$error = $this->upload->display_errors();
|
|
}
|
|
|
|
$table="expense_child";
|
|
$create_expence_list = $this->MY_Model->insert($data2,$table);
|
|
}
|
|
|
|
|
|
$this->session->set_flashdata('Create', '1');
|
|
redirect('Expence/Emp_Expence_List');
|
|
}
|
|
|
|
|
|
public function edit_expence($id)
|
|
{
|
|
$expense_data = $this->Expence_model->get_expense_data($id);
|
|
$expense_child_data = $this->Expence_model->get_expense_child_data($id);
|
|
$this->layout->set('expense_data', $expense_data);
|
|
$this->layout->set('expense_child_data', $expense_child_data);
|
|
$this->layout->buffer('main_content', 'Expence/edit_expence');
|
|
$this->layout->render('Employee_Layout');
|
|
}
|
|
|
|
|
|
public function edit_rise_expence_request()
|
|
{
|
|
$id = $this->input->post('expense_pid');
|
|
$data = $this->input->post('emp_id');
|
|
if(!empty($data)){
|
|
$emp_id =$this->input->post('emp_id');
|
|
}else{
|
|
$emp_id = user()->id;
|
|
}
|
|
$get_manager_id = $this->Expence_model->get_manager_id($emp_id);
|
|
|
|
if($get_manager_id[0]->manager == null){
|
|
|
|
$manager = 0;
|
|
}else{
|
|
|
|
$manager = $get_manager_id[0]->manager;
|
|
}
|
|
|
|
|
|
$data1 = array(
|
|
'created_by'=>user()->id,
|
|
'requested_for'=>$emp_id ,
|
|
'expense_name'=>$this->input->post('expense_name'),
|
|
'business_reason'=>$this->input->post('business_reason'),
|
|
'manager_id' => $manager,
|
|
'business_id' => user()->business_id,
|
|
'status'=>'Draft',
|
|
);
|
|
$table="expense";
|
|
$create_Expence = $this->MY_Model->edit_option($data1, $id, $table);
|
|
|
|
$count = count($this->input->post('date_of_expence'));
|
|
for($i=0;$i<$count;$i++)
|
|
{
|
|
$expense_child_id = $this->input->post('expense_child_id')[$i];
|
|
$data2 = array(
|
|
'date_of_expense'=> $this->input->post('date_of_expence')[$i],
|
|
'amount' => $this->input->post('amount')[$i],
|
|
'description' => $this->input->post('description')[$i],
|
|
);
|
|
$this->load->library('upload');
|
|
|
|
$config['upload_path'] = APPPATH. '../assets/uploads/Expence_Bill/';
|
|
$config['allowed_types'] = 'jpg|png|jpeg|pdf';
|
|
$config['max_size'] = 80000;
|
|
$config['file_name'] = time(). '_' . $_FILES['bill']['name'][$i];
|
|
|
|
$_FILES['userfile']['name'] = $_FILES['bill']['name'][$i];
|
|
$_FILES['userfile']['type'] = $_FILES['bill']['type'][$i];
|
|
$_FILES['userfile']['tmp_name'] = $_FILES['bill']['tmp_name'][$i];
|
|
$_FILES['userfile']['error'] = $_FILES['bill']['error'][$i];
|
|
$_FILES['userfile']['size'] = $_FILES['bill']['size'][$i];
|
|
|
|
$this->upload->initialize($config);
|
|
if ($this->upload->do_upload('userfile'))
|
|
{
|
|
$upload_image = $this->upload->data();
|
|
$data2['bill'] = $upload_image['file_name'];
|
|
}
|
|
else
|
|
{
|
|
$error = $this->upload->display_errors();
|
|
}
|
|
|
|
|
|
$table="expense_child";
|
|
$update_expence_list = $this->MY_Model->edit_option($data2, $expense_child_id, $table);
|
|
|
|
}
|
|
|
|
if($this->input->post('date_of_expence2'))
|
|
{
|
|
|
|
$count = count($this->input->post('date_of_expence2'));
|
|
for($i=0;$i<$count;$i++)
|
|
{
|
|
|
|
$data2 = array(
|
|
'expense_id' => $this->input->post('expense_pid'),
|
|
'emp_id'=>$emp_id ,
|
|
'business_id' => user()->business_id,
|
|
'manager_id' => $manager,
|
|
'status' => 'Draft',
|
|
'date_of_expense'=> $this->input->post('date_of_expence2')[$i],
|
|
'amount' => $this->input->post('amount2')[$i],
|
|
'description' => $this->input->post('description2')[$i],
|
|
);
|
|
$this->load->library('upload');
|
|
|
|
$config['upload_path'] = APPPATH. '../assets/uploads/Expence_Bill/';
|
|
$config['allowed_types'] = 'jpg|png|jpeg|pdf';
|
|
$config['max_size'] = 80000;
|
|
$config['file_name'] = time(). '_' . $_FILES['bill2']['name'][$i];
|
|
|
|
$_FILES['userfile']['name'] = $_FILES['bill2']['name'][$i];
|
|
$_FILES['userfile']['type'] = $_FILES['bill2']['type'][$i];
|
|
$_FILES['userfile']['tmp_name'] = $_FILES['bill2']['tmp_name'][$i];
|
|
$_FILES['userfile']['error'] = $_FILES['bill2']['error'][$i];
|
|
$_FILES['userfile']['size'] = $_FILES['bill2']['size'][$i];
|
|
|
|
$this->upload->initialize($config);
|
|
if ($this->upload->do_upload('userfile'))
|
|
{
|
|
$upload_image = $this->upload->data();
|
|
$data2['bill'] = $upload_image['file_name'];
|
|
}
|
|
else
|
|
{
|
|
$error = $this->upload->display_errors();
|
|
}
|
|
|
|
$table="expense_child";
|
|
$create_expence_list = $this->MY_Model->insert($data2,$table);
|
|
//print_r($this->db->last_query()); die;
|
|
}
|
|
|
|
}
|
|
|
|
redirect('Expence/Emp_Expence_List');
|
|
|
|
}
|
|
|
|
public function expence_list()
|
|
{
|
|
$business_id = user()->business_id;
|
|
$expence_list = $this->Expence_model->get_expence_list($business_id);
|
|
$get_count_amount = $this->Expence_model->get_count_amount();
|
|
// $get_business_admin = $this->Expence_model->get_business_admin();
|
|
$this->layout->set('count_amount', $get_count_amount);
|
|
$this->layout->set('tableData', $expence_list);
|
|
$this->layout->buffer('main_content', 'Expence/expence_list');
|
|
$this->layout->render('Employee_Layout');
|
|
}
|
|
|
|
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');
|
|
$this->layout->render('Employee_Layout');
|
|
}
|
|
|
|
public function expence_list2()
|
|
{
|
|
$id = $this->input->get('id');
|
|
$expence_list2 = $this->Expence_model->get_expence_child_list($id);
|
|
echo json_encode($expence_list2);
|
|
}
|
|
|
|
public function Emp_Expence_List()
|
|
{
|
|
$business_id = user()->business_id;
|
|
$expence_list = $this->Expence_model->get_expence_list_all($business_id);
|
|
$get_count_amount = $this->Expence_model->get_count_amount();
|
|
$this->layout->set('count_amount', $get_count_amount);
|
|
$this->layout->set('tableData', $expence_list);
|
|
$this->layout->buffer('main_content', 'Expence/emp_expence_list');
|
|
$this->layout->render('Employee_Layout');
|
|
}
|
|
|
|
public function Emp_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);
|
|
$this->layout->set('tableData', $expence_list);
|
|
$this->layout->set('expense_name', $get_expense_name);
|
|
$this->layout->buffer('main_content', 'Expence/emp_expence_list_view');
|
|
$this->layout->render('Employee_Layout');
|
|
}
|
|
|
|
public function getDeleteConfirmationPopup()
|
|
{
|
|
$data = array();
|
|
$htmlPage = $this->load->view('confirmation_popup.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
public function Approve_Expence()
|
|
{
|
|
$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";
|
|
$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->post('declinedata'))
|
|
{
|
|
$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->post('declinedata');
|
|
$is_decline = $this->Expence_model->approve_child_expense_2($decline_action, $id);
|
|
|
|
if($is_decline == true)
|
|
{
|
|
$count = $this->Expence_model->get_status_update($expense_id);
|
|
$table = "expense";
|
|
if($count->pending_count >= 1)
|
|
{
|
|
$status_update['status'] = 'pending';
|
|
$this->MY_Model->edit_option($status_update, $expense_id, $table);
|
|
}
|
|
else if($count->approve_count >= 1 && $count->declined_count >= 1)
|
|
{
|
|
$status_update['status'] = 'Partially approved';
|
|
$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)
|
|
{
|
|
|
|
$status_update['status'] = 'Declined';
|
|
$status_update['decline_by'] = user()->name;
|
|
return $this->MY_Model->edit_option($status_update, $expense_id, $table);
|
|
}
|
|
}
|
|
|
|
redirect('Expence/expence_list_view/'.$this->input->post('expence_id'));
|
|
|
|
}
|
|
else
|
|
{
|
|
$id=$this->input->post('id');
|
|
$expense_id=$this->input->post('expence_id');
|
|
$action['status'] = 'Approved';
|
|
$action['approved_at'] = date('Y-m-d h:i:s');
|
|
$action['approved_by']= user()->name;
|
|
$is_approve = $this->Expence_model->approve_child_expense_2($action, $id);
|
|
if($is_approve == true)
|
|
{
|
|
$count = $this->Expence_model->get_status_update($expense_id);
|
|
$table = "expense";
|
|
if($count->pending_count >= 1)
|
|
{
|
|
$status_update['status'] = 'pending';
|
|
$this->MY_Model->edit_option($status_update, $expense_id, $table);
|
|
}
|
|
else if($count->approve_count >= 1 && $count->declined_count >= 1)
|
|
{
|
|
$status_update['status'] = 'Partially approved';
|
|
$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)
|
|
{
|
|
|
|
$status_update['status'] = 'Approved';
|
|
$action['approved_at'] = date('Y-m-d h:i:s');
|
|
$status_update['approved_by'] = user()->name;
|
|
$this->MY_Model->edit_option($status_update, $expense_id, $table);
|
|
|
|
}
|
|
}
|
|
|
|
redirect('Expence/expence_list_view/'.$this->input->post('expence_id'));
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
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->post('id');
|
|
// echo $id; die;
|
|
$data['status'] = 'Declined';
|
|
$data['decline_by'] = user()->name;
|
|
$data['decline_reason'] = $this->input->get('declinedata');
|
|
$expence_id = $this->Expence_model->ExpenceDecline($id, $data);
|
|
$this->Expence_model->Expence_Decline_Child($id, $data);
|
|
if($expence_id){
|
|
$code = 'DECLINE_EXPENCE';
|
|
$type = 'Email';
|
|
$this->notification->sendNotificationForExpense($id, $code, $type);
|
|
}
|
|
redirect('Expence/expence_list');
|
|
}
|
|
|
|
|
|
public function getCancelConfirmationPopup()
|
|
{
|
|
$data = array();
|
|
$htmlPage = $this->load->view('confirmation_popup.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
public function cancled_expence()
|
|
{
|
|
$id=$this->input->post('id');
|
|
$data['status'] = 'Cancelled';
|
|
$data['cancelled_at'] = date('Y-m-d h:i:s');
|
|
$first = $this->Expence_model->Expencecancle($id, $data);
|
|
$second = $this->Expence_model->Expencecancle_child($id, $data);
|
|
redirect('Expence/emp_expence_list');
|
|
}
|
|
|
|
public function remove_row()
|
|
{
|
|
$get_count_from_child = $this->Expence_model->get_expense_child_data(md5($this->input->post('expence_id')));
|
|
$count = count($get_count_from_child);
|
|
if($count === 1)
|
|
{
|
|
$this->session->set_flashdata('remove_row', '1');
|
|
redirect('Expence/edit_expence/'.md5($this->input->post('expence_id')));
|
|
}
|
|
else
|
|
{
|
|
$id = $this->input->post('id');
|
|
$delete = $this->Expence_model->remove_row($id);
|
|
redirect('Expence/edit_expence/'.md5($this->input->post('expence_id')));
|
|
}
|
|
|
|
}
|
|
|
|
public function submit()
|
|
{
|
|
$id = $this->input->post('id');
|
|
$table1 = 'expense';
|
|
$data['status'] = "pending";
|
|
$data['updated_on'] = date('Y-m-d h:i:s');
|
|
$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');
|
|
}
|
|
|
|
|
|
}
|