351 lines
10 KiB
PHP
351 lines
10 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
/**
|
|
* 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 Business 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('Business_model','Business_model');
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
public function business_list()
|
|
{
|
|
|
|
$business_list = $this->Business_model->get_business_details();
|
|
// echo '<pre>';
|
|
// print_r($business_list); die;
|
|
$this->layout->set('tableData', $business_list);
|
|
$this->layout->buffer('main_content', 'Business/business_list');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
public function add_business()
|
|
{
|
|
|
|
$this->layout->set('stateData', $this->MY_Model->select('state'));
|
|
$this->layout->set('ModuleData', $this->MY_Model->select('modules'));
|
|
$this->layout->buffer('main_content', 'Business/add_business');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
|
|
public function create_business()
|
|
{
|
|
$data = $this->input->post();
|
|
|
|
$data['created_by'] = user()->id;
|
|
//file upload confic
|
|
$logo_file['upload_path'] = APPPATH. '../assets/uploads/logo';
|
|
$logo_file['allowed_types'] = 'gif|jpg|png|jpeg';
|
|
$logo_file['max_size'] = 80000;
|
|
//upload
|
|
$this->load->library('upload', $logo_file);
|
|
$this->upload->initialize($logo_file);
|
|
if ( ! $this->upload->do_upload('logo'))
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
} else{
|
|
$upload_logo = $this->upload->data();
|
|
$data['logo'] = $upload_logo['file_name'];
|
|
}
|
|
|
|
$table="business";
|
|
$add_admin = 0;
|
|
if($this->input->post('add_admin'))
|
|
{
|
|
$add_admin = $this->input->post('add_admin');
|
|
unset($data['add_admin']);
|
|
}
|
|
|
|
$modules = $this->input->post('module_id');
|
|
if($modules !== NULL && $modules !== ''){
|
|
|
|
$count = count($modules);
|
|
|
|
for($i=0;$i<$count;$i++)
|
|
{
|
|
$mdata['module_id'] = $this->input->post('module_id')[$i];
|
|
$mdata['uid'] = $this->input->post('uid');
|
|
$mdata['is_active'] = 1;
|
|
$add_module = $this->MY_Model->insert($mdata, "permit_modules");
|
|
}
|
|
}
|
|
unset($data['module_id']);
|
|
$create_business = $this->MY_Model->insert($data,$table);
|
|
|
|
if($create_business){
|
|
$data1=[
|
|
'business_id' => $this->input->post('uid'),
|
|
'type'=> 'Permission',
|
|
'days'=> '0',
|
|
'is_active' => '1',
|
|
'code ' => 'permission'
|
|
];
|
|
$data2=[
|
|
'business_id' => $this->input->post('uid'),
|
|
'type'=> 'Casual Leave',
|
|
'days'=> '0',
|
|
'is_active' => '1',
|
|
];
|
|
$table = "leave_master";
|
|
$leavemaster1 = $this->MY_Model->insert($data1,$table);
|
|
$leavemaster2 = $this->MY_Model->insert($data2,$table);
|
|
}
|
|
|
|
// audit history
|
|
if($create_business)
|
|
{
|
|
//set id $ table name for audit history
|
|
$this->audit->set('id',$create_business);
|
|
$this->audit->set('table',$table);
|
|
//fetch new_data after post data insert
|
|
$this->audit->fetch('new_data');
|
|
//audit history generation for insert
|
|
$test = $this->audit->create_history('insert');
|
|
}
|
|
//print_r($create_business); die();
|
|
// $create_business = 3;
|
|
if($add_admin == 1)
|
|
{
|
|
redirect('User/addUser/'.$create_business);
|
|
}else{
|
|
redirect('Business/business_list');
|
|
}
|
|
|
|
}
|
|
|
|
|
|
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($id);
|
|
$this->layout->set('ModuleData', $this->MY_Model->select('modules'));
|
|
$this->layout->set('businessModuleData', $businessModuleData);
|
|
$this->layout->set('businessData', $businessData);
|
|
$this->layout->buffer('main_content', 'Business/edit_business');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
public function edit_business()
|
|
{
|
|
$action = $this->input->post();
|
|
$id = $this->input->post('id');
|
|
|
|
//file upload confic
|
|
$logo_file['upload_path'] = APPPATH. '../assets/uploads/logo';
|
|
$logo_file['allowed_types'] = 'gif|jpg|png|jpeg';
|
|
$logo_file['max_size'] = 80000;
|
|
//upload
|
|
$this->load->library('upload', $logo_file);
|
|
$this->upload->initialize($logo_file);
|
|
if ( ! $this->upload->do_upload('logo'))
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
unset($action['logo']);
|
|
} else{
|
|
$upload_logo = $this->upload->data();
|
|
$action['logo'] = $upload_logo['file_name'];
|
|
}
|
|
|
|
$table="business";
|
|
//set id $ table name for audit history
|
|
$this->audit->set('id',$this->input->post('id'));
|
|
$this->audit->set('table','business');
|
|
//fetch old_data before new_data update
|
|
$this->audit->fetch('old_data');
|
|
|
|
//insert new data
|
|
$get_business_module_is_active = $this->Business_model->get_business_module_is_active($this->input->post('uid'));
|
|
|
|
if(count($get_business_module_is_active) != 0)
|
|
{
|
|
$DbData = [];
|
|
foreach($get_business_module_is_active as $key => $val){
|
|
array_push($DbData,$val->module_id);
|
|
}
|
|
|
|
if($this->input->post('module_id') == null)
|
|
{
|
|
$module_id_array = [];
|
|
}else{
|
|
$module_id_array = $this->input->post('module_id');
|
|
}
|
|
|
|
$differentValues1 = array_diff($module_id_array , $DbData);
|
|
$differentValues2 = array_diff($DbData , $module_id_array);
|
|
$final_array = array_merge($differentValues1, $differentValues2);
|
|
|
|
if(count($final_array) != 0)
|
|
{
|
|
foreach($final_array as $key => $value){
|
|
$check_if_exist = $this->Business_model->get_group_module_data_by_id($this->input->post('uid'), $value);
|
|
if($check_if_exist)
|
|
{
|
|
$this->Business_model->delete_group_module_data_by_id($this->input->post('uid') , $value);
|
|
$data['is_active'] = 0;
|
|
$this->Business_model->diable_module_in_group_permisssion($value, $data);
|
|
|
|
|
|
}else{
|
|
$mdata['module_id'] = $value;
|
|
$mdata['uid'] = $this->input->post('uid');
|
|
$mdata['is_active'] = 1;
|
|
$add_module = $this->MY_Model->insert($mdata, "permit_modules");
|
|
$data['is_active'] = 1;
|
|
$this->Business_model->Enable_module_in_group_permisssion($value, $data);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{ for($i=0;$i<count($this->input->post('module_id'));$i++)
|
|
{
|
|
$mdata['module_id'] = $this->input->post('module_id')[$i];
|
|
$mdata['uid'] = $this->input->post('uid');
|
|
$mdata['is_active'] = 1;
|
|
$add_module = $this->MY_Model->insert($mdata, "permit_modules");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unset($action['module_id']);
|
|
$businessData = $this->MY_Model->edit_option($action, $id, $table);
|
|
if($businessData)
|
|
{
|
|
//fetch new_data after post data update
|
|
$this->audit->fetch('new_data');
|
|
//audit history generation for update
|
|
$test = $this->audit->create_history('update');
|
|
}
|
|
if(is_superadmin()){ redirect('Business/business_list');}
|
|
else if(is_admin()){ redirect('User/businessProfile/'.md5(user()->business_id)); }
|
|
|
|
}
|
|
|
|
public function delete_business($id)
|
|
{
|
|
$data['is_active'] = 0;
|
|
$Data = $this->Business_model->delete_by_md5_id($id,$data);
|
|
redirect('Business/business_list');
|
|
}
|
|
|
|
public function activate_business($id)
|
|
{
|
|
$data['is_active'] = 1;
|
|
$Data = $this->Business_model->delete_by_md5_id($id,$data);
|
|
redirect('Business/business_list');
|
|
}
|
|
|
|
public function checkUniqueBusinessData()
|
|
{
|
|
$data = $this->input->get('value');
|
|
$table = 'business';
|
|
$where = $this->input->get('name');
|
|
$result = $this->MY_Model->checkUniqueValueInDataBase($table, $where, $data);
|
|
if(count($result)){
|
|
$this->output->set_output(true);
|
|
}else{
|
|
$this->output->set_output(false);
|
|
}
|
|
}
|
|
|
|
//===================== MODULES =================================================
|
|
|
|
public function add_module()
|
|
{
|
|
$this->layout->buffer('main_content', 'Business/add_module_form');
|
|
$this->layout->render('default_layout');
|
|
}
|
|
|
|
public function create_add_module()
|
|
{
|
|
$table = 'modules';
|
|
$data = $this->input->post();
|
|
$data['is_active'] = 1;
|
|
$add_module = $this->MY_Model->insert($data, $table);
|
|
redirect('Business/module_list');
|
|
}
|
|
|
|
public function module_list()
|
|
{
|
|
$table = 'modules';
|
|
$module_list = $this->MY_Model->select($table);
|
|
$this->layout->set('module_list', $module_list);
|
|
$this->layout->buffer('main_content', 'Business/module_list');
|
|
$this->layout->render('default_layout');
|
|
}
|
|
|
|
public function edit_module($id)
|
|
{
|
|
$table = 'modules';
|
|
$module_data = $this->MY_Model->get_by_md5_id($id, $table);
|
|
$this->layout->set('module_data', $module_data);
|
|
$this->layout->buffer('main_content', 'Business/edit_modules');
|
|
$this->layout->render('default_layout');
|
|
}
|
|
|
|
public function edit_module_data()
|
|
{
|
|
$table = 'modules';
|
|
$id = $this->input->post('id');
|
|
$action = $this->input->post();
|
|
$action['is_active'] = 1;
|
|
$add_module = $this->MY_Model->edit_option($action, $id, $table);
|
|
redirect('Business/module_list');
|
|
}
|
|
|
|
public function getDeleteConfirmationPopup()
|
|
{
|
|
$data = array();
|
|
$htmlPage = $this->load->view('confirmation_popup.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
|
|
} |