bbone/application/modules/Business/controllers/Business.php
suseendhiran17 c489cb2138 suseendhiran
2023-01-11 12:07:23 +05:30

187 lines
4.8 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();
$this->load->model('MY_Model');
$this->load->model('Business_model');
$this->load->helper(array('form', 'url'));
}
public function index()
{
}
public function business_list()
{
$business_list = $this->Business_model->get_business_details();
$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->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';
$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']);
}
$create_business = $this->MY_Model->insert($data,$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);
$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';
$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
$assetData = $this->MY_Model->edit_option($action, $id, $table);
if($assetData)
{
//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 = $this->Business_model->delete_by_md5_id($id,user()->business_id,'asset');
redirect('business/business_list');
}
}