508 lines
18 KiB
PHP
508 lines
18 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 Asset 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('Asset_model');
|
|
$this->load->model('Audit_model');
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
|
|
$this->layout->set('users', "gowtham");
|
|
$this->layout->buffer('main_content', 'Asset/index');
|
|
$this->layout->render('default_layout');
|
|
|
|
|
|
}
|
|
|
|
public function addAsset($id='empty')
|
|
{
|
|
if($id != 'empty')
|
|
{
|
|
$assetData = $this->Asset_model->get_asset_by_md5_id($id,user()->business_id);
|
|
$this->layout->set('assetData', $assetData);
|
|
}
|
|
$this->layout->set('manufacturerData', $this->MY_Model->select_by_business_id_and_type('third_parties',user()->business_id,1));
|
|
$this->layout->set('suppliorData', $this->MY_Model->select_by_business_id_and_type('third_parties',user()->business_id,2));
|
|
$this->layout->set('locationsData', $this->MY_Model->select_by_business_id('locations',user()->business_id));
|
|
$this->layout->set('categoriesData', $this->MY_Model->select_by_business_id('categories',user()->business_id));
|
|
$this->layout->set('statusData', $this->MY_Model->select('status'));
|
|
|
|
$this->layout->buffer('main_content', 'Asset/add_asset');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
public function assetList()
|
|
{
|
|
|
|
$assets_list = $this->Asset_model->get_assets(user()->business_id);
|
|
$this->layout->set('tableData', $assets_list);
|
|
$this->layout->buffer('main_content', 'Asset/asset_list');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
public function createAssets()
|
|
{
|
|
$data=$this->input->post();
|
|
$data['business_id'] = user()->business_id;
|
|
$data['created_by'] = user()->name;
|
|
|
|
//file upload confic
|
|
$asset_image['upload_path'] = APPPATH. '../assets/uploads/';
|
|
$asset_image['allowed_types'] = 'gif|jpg|png';
|
|
$asset_image['max_size'] = 80000;
|
|
//upload
|
|
$this->load->library('upload', $asset_image);
|
|
$this->upload->initialize($asset_image);
|
|
if ( ! $this->upload->do_upload('asset_img'))
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
} else{
|
|
$upload_asset_image = $this->upload->data();
|
|
$data['asset_img'] = $upload_asset_image['file_name'];
|
|
}
|
|
|
|
$table="asset";
|
|
|
|
//create asset
|
|
$create_assets = $this->MY_Model->insert($data,$table);
|
|
if($create_assets)
|
|
{
|
|
//set id $ table name for audit history
|
|
$this->audit->set('id',$create_assets);
|
|
$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');
|
|
}
|
|
|
|
redirect('asset/assetList');
|
|
|
|
}
|
|
|
|
|
|
public function editAsset($id)
|
|
{
|
|
//select dropdown values
|
|
$this->layout->set('manufacturerData', $this->MY_Model->select_by_business_id_and_type('third_parties',user()->business_id,1));
|
|
$this->layout->set('suppliorData', $this->MY_Model->select_by_business_id_and_type('third_parties',user()->business_id,2));
|
|
$this->layout->set('locationsData', $this->MY_Model->select_by_business_id('locations',user()->business_id));
|
|
$this->layout->set('categoriesData', $this->MY_Model->select_by_business_id('categories',user()->business_id));
|
|
$this->layout->set('statusData', $this->MY_Model->select('status'));
|
|
// select asset value by id
|
|
$table="asset";
|
|
$assetData = $this->Asset_model->get_asset_by_md5_id($id,user()->business_id);
|
|
$asset_value = $this->Asset_model->get_by_asset_id($id,'asset_value',user()->business_id);
|
|
$asset_usage = $this->Asset_model->get_by_asset_id($id,'asset_usage',user()->business_id);
|
|
$asset_amc = $this->Asset_model->get_amc_with_join($id,user()->business_id);
|
|
$asset_insurance = $this->Asset_model->get_insurance_with_join($id,user()->business_id);
|
|
$asset_images = $this->Asset_model->get_by_asset_id($id,'asset_images',user()->business_id);
|
|
$asset_history = $this->Audit_model->get_history($id,'asset',user()->business_id);
|
|
$data = array('asset_id'=>$assetData->id,'asset_value' => $asset_value ,'asset_usage' => $asset_usage , 'asset_amc' =>$asset_amc ,'asset_insurance'=>$asset_insurance, 'asset_images'=>$asset_images , 'asset_history'=>$asset_history);
|
|
$sub_asset_value_htmlPage = $this->load->view('asset_sub_value_list.php',$data,true);
|
|
$this->layout->set('sub_asset_value_htmlPage', $sub_asset_value_htmlPage);
|
|
$this->layout->set('editData', $assetData);
|
|
$this->layout->buffer('main_content', 'Asset/edit_asset');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
public function editAssets()
|
|
{
|
|
|
|
$table="asset";
|
|
$action = $this->input->post();
|
|
|
|
$date = date_create($this->input->post('purchase_date'));
|
|
$action['purchase_date'] = date_format($date,"Y-m-d");
|
|
|
|
|
|
$id = $this->input->post('id');
|
|
//file upload confic
|
|
$asset_image['upload_path'] = APPPATH. '../assets/uploads/';
|
|
$asset_image['allowed_types'] = 'gif|jpg|png';
|
|
$asset_image['max_size'] = 80000;
|
|
//upload
|
|
$this->load->library('upload', $asset_image);
|
|
$this->upload->initialize($asset_image);
|
|
if ( ! $this->upload->do_upload('asset_img'))
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
|
|
unset($action['asset_img']);
|
|
} else{
|
|
$upload_asset_image = $this->upload->data();
|
|
$action['asset_img'] = $upload_asset_image['file_name'];
|
|
|
|
}
|
|
|
|
|
|
//set id $ table name for audit history
|
|
$this->audit->set('id',$this->input->post('id'));
|
|
$this->audit->set('table','asset');
|
|
//fetch old_data before new_data update
|
|
$this->audit->fetch('old_data');
|
|
//update asset value
|
|
$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');
|
|
}
|
|
redirect('asset/assetList');
|
|
|
|
}
|
|
|
|
public function deleteAsset($id)
|
|
{
|
|
$Data = $this->Asset_model->delete_by_md5_id($id,user()->business_id,'asset');
|
|
redirect('asset/assetList');
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function view_asset_details($id)
|
|
{
|
|
$tab = $this->session->flashdata();
|
|
// $tab = 1;
|
|
//print_r($tab);die();
|
|
// select asset value by id
|
|
$table="asset";
|
|
$assetData = $this->Asset_model->get_asset_by_md5_id($id,user()->business_id);
|
|
// select asset sub values by id
|
|
$asset_value = $this->Asset_model->get_by_asset_id($id,'asset_value',user()->business_id);
|
|
$asset_usage = $this->Asset_model->get_by_asset_id($id,'asset_usage',user()->business_id);
|
|
$asset_amc = $this->Asset_model->get_amc_with_join($id,user()->business_id);
|
|
$asset_insurance = $this->Asset_model->get_insurance_with_join($id,user()->business_id);
|
|
$asset_images = $this->Asset_model->get_by_asset_id($id,'asset_images',user()->business_id);
|
|
$asset_history = $this->Audit_model->get_history($id,'asset',user()->business_id);
|
|
$data = array('asset_id'=>$assetData->id,'asset_value' => $asset_value ,'asset_usage' => $asset_usage , 'asset_amc' =>$asset_amc ,'asset_insurance'=>$asset_insurance, 'asset_images'=>$asset_images,'asset_history'=>$asset_history,'tab'=>$tab);
|
|
$sub_asset_value_htmlPage = $this->load->view('asset_sub_value_list.php',$data,true);
|
|
$this->layout->set('sub_asset_value_htmlPage', $sub_asset_value_htmlPage);
|
|
$this->layout->set('editData', $assetData);
|
|
$this->layout->set('viewData', 1);
|
|
$this->layout->buffer('main_content', 'Asset/edit_asset');
|
|
$this->layout->render('default_layout');
|
|
|
|
}
|
|
|
|
// public function getAssetDetails($id)
|
|
// {
|
|
// $asset_value = $this->Asset_model->get_by_asset_id($id,'asset_value',user()->business_id);
|
|
// $asset_usage = $this->Asset_model->get_by_asset_id($id,'asset_usage',user()->business_id);
|
|
// $asset_amc = $this->Asset_model->get_by_asset_id($id,'amc',user()->business_id);
|
|
// $data = array('asset_value' => $asset_value ,'asset_usage' => $asset_usage , 'asset_amc' =>$asset_amc);
|
|
|
|
// $htmlPage = $this->load->view('asset_sub_value_list.php',$data,true);
|
|
// echo json_encode($htmlPage);
|
|
// }
|
|
|
|
|
|
|
|
public function getAssetValueForm($id)
|
|
{
|
|
|
|
$split = preg_split('/_/', $id);
|
|
if(count($split) > 1)
|
|
{
|
|
$data = array('asset_id'=> $split[0], 'heading'=>'Add Asset Values' , 'submit_button_title'=>'Submit');
|
|
}else{
|
|
$asset_value_data = $this->MY_Model->get_by_md5_id($id,'asset_value');
|
|
$data = array('assetValueData'=>$asset_value_data ,'heading'=>'Edit Asset Values' , 'submit_button_title'=>'Update');
|
|
}
|
|
|
|
$htmlPage = $this->load->view('asset_value_form.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
|
|
|
|
public function add_or_edit_asset_value()
|
|
{
|
|
if($this->input->post('id'))
|
|
{
|
|
$value = $this->input->post();
|
|
unset($value['asset_id_for_add']);
|
|
$editAssetValueData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'asset_value');
|
|
//$this->view_asset_details(md5($this->input->post('asset_id')));
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id')));
|
|
}else{
|
|
$data['asset_id'] = $this->input->post('asset_id_for_add');
|
|
$data['business_id'] = user()->business_id;
|
|
$data['type'] = $this->input->post('type');
|
|
$data['name'] = $this->input->post('name');
|
|
$data['value'] = $this->input->post('value');
|
|
$data['percentage'] = $this->input->post('percentage');
|
|
$data['description'] = $this->input->post('description');
|
|
$data['created_by'] = user()->id;
|
|
$createAssetValueData = $this->MY_Model->insert($data, 'asset_value');
|
|
//$this->view_asset_details(md5($this->input->post('asset_id_for_add')));
|
|
$this->session->set_flashdata(1);
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add')));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAssetUsageForm($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
|
|
if(count($split) > 1)
|
|
{
|
|
$data = array('asset_id'=> $split[0], 'heading'=>'Add Asset Usage' , 'submit_button_title'=>'Submit');
|
|
}else{
|
|
$asset_usage_data = $this->MY_Model->get_by_md5_id($id,'asset_usage');
|
|
$data = array('assetUsageData'=>$asset_usage_data ,'heading'=>'Edit Asset Usage' , 'submit_button_title'=>'Update');
|
|
}
|
|
|
|
$htmlPage = $this->load->view('asset_usage_form.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
public function add_or_edit_asset_usage()
|
|
{
|
|
if($this->input->post('id'))
|
|
{
|
|
$value = $this->input->post();
|
|
unset($value['asset_id_for_add']);
|
|
$editAssetUsageData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'asset_usage');
|
|
// $this->view_asset_details(md5($this->input->post('asset_id')));
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id')));
|
|
}else{
|
|
$data['asset_id'] = $this->input->post('asset_id_for_add');
|
|
$data['business_id'] = user()->business_id;
|
|
$data['date_from'] = $this->input->post('date_from');
|
|
$data['date_to'] = $this->input->post('date_to');
|
|
$data['quater'] = $this->input->post('quater');
|
|
$data['shift'] = $this->input->post('shift');
|
|
$data['created_by'] = user()->id;
|
|
$createAssetUsageData = $this->MY_Model->insert($data, 'asset_usage');
|
|
//$this->view_asset_details(md5($this->input->post('asset_id_for_add')));
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add')));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getAssetAMCForm($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
$serviceProviderData = $this->MY_Model->select_by_business_id_and_type('third_parties',user()->business_id,3);
|
|
if(count($split) > 1)
|
|
{
|
|
$data = array('asset_id'=> $split[0], 'serviceProviderData'=>$serviceProviderData, 'heading'=>'Add AMC' , 'submit_button_title'=>'Submit');
|
|
}else{
|
|
$asset_amc_data = $this->Asset_model->get_amc_by_id_with_join($id);
|
|
$data = array('serviceProviderData'=>$serviceProviderData,'assetAMCData'=>$asset_amc_data ,'heading'=>'Edit AMC' , 'submit_button_title'=>'Update');
|
|
}
|
|
|
|
$htmlPage = $this->load->view('asset_amc_form.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
public function add_or_edit_asset_amc()
|
|
{
|
|
if($this->input->post('id'))
|
|
{
|
|
$value = $this->input->post();
|
|
unset($value['asset_id_for_add']);
|
|
$editAMCData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'amc');
|
|
//$this->view_asset_details(md5($this->input->post('asset_id')));
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id')));
|
|
}else{
|
|
$data['asset_id'] = $this->input->post('asset_id_for_add');
|
|
$data['business_id'] = user()->business_id;
|
|
$data['service_provider'] = $this->input->post('service_provider');
|
|
$data['cost'] = $this->input->post('cost');
|
|
$data['description'] = $this->input->post('description');
|
|
$data['valid_from'] = $this->input->post('valid_from');
|
|
$data['valid_to'] = $this->input->post('valid_to');
|
|
$data['created_by'] = user()->id;
|
|
$data['type'] = 3; //(amc service provider type = 3 * in third_parties table)
|
|
$createAMCData = $this->MY_Model->insert($data, 'amc');
|
|
//$this->view_asset_details(md5($this->input->post('asset_id_for_add')));
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add')));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function getAssetInsuranceForm($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
$insuranceData = $this->MY_Model->select_by_business_id_and_type('third_parties',user()->business_id,4);
|
|
if(count($split) > 1)
|
|
{
|
|
$data = array('asset_id'=> $split[0], 'insuranceData'=>$insuranceData, 'heading'=>'Add AMC' , 'submit_button_title'=>'Submit');
|
|
}else{
|
|
$asset_insurance_data = $this->Asset_model->get_insurance_by_id_with_join($id);
|
|
$data = array('insuranceData'=>$insuranceData,'assetInsuranceData'=>$asset_insurance_data ,'heading'=>'Edit AMC' , 'submit_button_title'=>'Update');
|
|
}
|
|
|
|
$htmlPage = $this->load->view('asset_insurance_form.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
|
|
|
|
|
|
public function add_or_edit_asset_insurance()
|
|
{
|
|
if($this->input->post('id'))
|
|
{
|
|
$value = $this->input->post();
|
|
unset($value['asset_id_for_add']);
|
|
$editInsuranceData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'amc');
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id')));
|
|
}else{
|
|
$data['asset_id'] = $this->input->post('asset_id_for_add');
|
|
$data['business_id'] = user()->business_id;
|
|
$data['insurance_company'] = $this->input->post('insurance_company');
|
|
$data['cost'] = $this->input->post('cost');
|
|
$data['description'] = $this->input->post('description');
|
|
$data['valid_from'] = $this->input->post('valid_from');
|
|
$data['valid_to'] = $this->input->post('valid_to');
|
|
$data['created_by'] = user()->id;
|
|
$data['type'] = 4; //(insurance company type = 4 * in third_parties table)
|
|
$createInsuranceData = $this->MY_Model->insert($data, 'amc');
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add')));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getAssetImageForm($id)
|
|
{
|
|
|
|
$data = array('asset_id'=> $id, 'heading'=>'Add Image' , 'submit_button_title'=>'Submit');
|
|
$htmlPage = $this->load->view('asset_image_form.php',$data,true);
|
|
echo json_encode($htmlPage);
|
|
}
|
|
|
|
public function add_asset_image()
|
|
{
|
|
|
|
$data['business_id'] = user()->business_id;
|
|
$data['created_by'] = user()->id;
|
|
$data['asset_id'] = $this->input->post('asset_id');
|
|
|
|
//file upload confic
|
|
$asset_image['upload_path'] = APPPATH. '../assets/uploads/';
|
|
$asset_image['allowed_types'] = 'gif|jpg|png';
|
|
$asset_image['max_size'] = 80000;
|
|
//upload
|
|
$this->load->library('upload', $asset_image);
|
|
$this->upload->initialize($asset_image);
|
|
if ( ! $this->upload->do_upload('image'))
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
} else{
|
|
$upload_asset_image = $this->upload->data();
|
|
$data['image'] = $upload_asset_image['file_name'];
|
|
}
|
|
//print_r($data);die();
|
|
$table="asset_images";
|
|
$create_assets = $this->MY_Model->insert($data,$table);
|
|
redirect('asset/view_asset_details/'.md5($this->input->post('asset_id')));
|
|
|
|
}
|
|
|
|
public function deleteAssetValue($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
$key = $split[0];
|
|
$asset_id = $split[1];
|
|
$Data = $this->Asset_model->delete_by_md5_id($key,user()->business_id,'asset_value');
|
|
redirect('asset/view_asset_details/'.md5($asset_id));
|
|
}
|
|
public function deleteAssetUsage($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
$key = $split[0];
|
|
$asset_id = $split[1];
|
|
$Data = $this->Asset_model->delete_by_md5_id($key,user()->business_id,'asset_usage');
|
|
redirect('asset/view_asset_details/'.md5($asset_id));
|
|
}
|
|
public function deleteAssetAMC($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
$key = $split[0];
|
|
$asset_id = $split[1];
|
|
$Data = $this->Asset_model->delete_by_md5_id($key,user()->business_id,'amc');
|
|
redirect('asset/view_asset_details/'.md5($asset_id));
|
|
}
|
|
public function deleteAssetImage($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
$key = $split[0];
|
|
$asset_id = $split[1];
|
|
$Data = $this->Asset_model->delete_by_md5_id($key,user()->business_id,'asset_images');
|
|
redirect('asset/view_asset_details/'.md5($asset_id));
|
|
}
|
|
public function deleteAssetInsurance($id)
|
|
{
|
|
$split = preg_split('/_/', $id);
|
|
$key = $split[0];
|
|
$asset_id = $split[1];
|
|
$Data = $this->Asset_model->delete_by_md5_id($key,user()->business_id,'amc');
|
|
redirect('asset/view_asset_details/'.md5($asset_id));
|
|
}
|
|
|
|
public function test()
|
|
{
|
|
$data = $this->Audit_model->get_history(13,'asset',user()->business_id);
|
|
print_r($data);die();
|
|
|
|
}
|
|
|
|
|
|
}
|