(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(); ### 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('Asset_model','Asset_model'); $this->load->model('Audit/audit_model','Audit_model'); $this->load->helper(array('form', 'url')); //print_r($business);die(); } 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 assetLandingPage() { $assets_list = $this->Asset_model->get_category_wise_assets(user()->business_id); $this->layout->set('tableData', $assets_list); $this->layout->buffer('main_content', 'Asset/asset_landing_page'); $this->layout->render('default_layout'); } public function assetList($category , $purchase_date_from = null , $purchase_date_to = null) { $table = 'asset'; $assets_list = $this->Asset_model->get_assets(user()->business_id , $category ); foreach ($assets_list as $key => $value) { // update yearly once if($value->last_updated_year != date('Y')) { // update last_updated_year in db $year['last_updated_year'] = date('Y'); // $editCurrentValue = $this->MY_Model->edit_option($year, $value->id, $table); // find difference between two dates $date1 = new DateTime(date('Y-m-d')); $date2 = new DateTime($value->purchase_date); $interval = $date1->diff($date2); $nxt_year = date('Y-m-d', strtotime("+12 months $value->purchase_date")); // echo $nxt_year;die(); // echo $interval->y; die(); // year intervel greater than 0 if($interval->y > 0) { $curr_month = date('n', strtotime($value->purchase_date)); // echo $curr_month;die(); $month_array_for_50_percentage = array(10 , 11 , 12 , 1 , 2 ,3); if (in_array($curr_month, $month_array_for_50_percentage) && date('Y-m-d') > $nxt_year) { $cost = $value->cost; // get depreciation value $category_percentage = $this->Asset_model->get_by_category_id($value->category); // percentage formula calculation $category_percentage = $category_percentage[0]['depreciation_percentage'] / 2; $depreciate_value = $cost * $category_percentage / 100; $cost = abs($depreciate_value - $cost); // echo $cost;die(); $category_percentage = $this->Asset_model->get_by_category_id($value->category); for ($i=0 ; $i < $interval->y ; $i++) { // $category_percentage = $this->Asset_model->get_by_category_id($value->category); $category_per = $category_percentage[0]['depreciation_percentage']; $depreciate_value = $cost * $category_per / 100; $data['current_cost'] = abs($depreciate_value - $cost); $editCurrentValue = $this->MY_Model->edit_option($data, $value->id, $table); $cost = abs($depreciate_value - $cost); } } else { $cost = $value->cost; // get depreciation value $category_percentage = $this->Asset_model->get_by_category_id($value->category); // percentage formula calculation $category_percentage = $category_percentage[0]['depreciation_percentage']; $depreciate_value = $cost * $category_percentage / 100; $cost = abs($depreciate_value - $cost); // $cost = $value->cost; // get depreciation value $category_percentage = $this->Asset_model->get_by_category_id($value->category); for ($i=0 ; $i < $interval->y ; $i++) { $category_per = $category_percentage[0]['depreciation_percentage']; $depreciate_value = $cost * $category_per / 100; // echo $depreciate_value; die(); $data['current_cost'] = abs($depreciate_value- $cost); $editCurrentValue = $this->MY_Model->edit_option($data, $value->id, $table); $cost = abs($depreciate_value - $cost); } } } // year intervel less than 0 else { $curr_month = date('n', strtotime($value->purchase_date)); $month_array_for_50_percentage = array(10 , 11 , 12 , 1 , 2 , 3); if (in_array($curr_month, $month_array_for_50_percentage)) { $cost = $value->cost; // get depreciation value $category_percentage = $this->Asset_model->get_by_category_id($value->category); // percentage formula calculation $category_percentage = $category_percentage[0]['depreciation_percentage'] / 2; $depreciate_value = $cost * $category_percentage / 100; $data['current_cost'] = abs($cost - $depreciate_value); $editCurrentValue = $this->MY_Model->edit_option($data, $value->id, $table); } else if(date('Y-m-d') > $nxt_year) { echo $nxt_year;die(); $cost = $value->cost; // get depreciation value $category_percentage = $this->Asset_model->get_by_category_id($value->category); // percentage formula calculation $depreciate_value = $cost * $category_percentage[0]['depreciation_percentage'] / 100; $data['current_cost'] = abs($cost - $depreciate_value); $editCurrentValue = $this->MY_Model->edit_option($data, $value->id, $table); } else { $data['current_cost'] = $value->cost; $editCurrentValue = $this->MY_Model->edit_option($data, $value->id, $table); } } } } $assets_list = $this->Asset_model->get_assets(user()->business_id , $category, $purchase_date_from , $purchase_date_to); $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; $date = date_create($this->input->post('purchase_date')); $data['purchase_date'] = date_format($date,"Y-m-d"); //file upload confic $asset_image['upload_path'] = APPPATH. '../assets/uploads/'; $asset_image['allowed_types'] = 'gif|jpg|png|jpeg'; $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); // Qr code $qr_data['qrcode_img'] = (new QRCode)->render(base_url().'Asset/view_asset_details/'.md5($create_assets)); $editAssetData = $this->MY_Model->edit_option($qr_data, $create_assets, $table); $editCurrentValue = $this->MY_Model->edit_option($qr_data, $create_assets, $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/'.md5($this->input->post('category'))); } 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|jpeg'; $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']; } // print_r( $action);die(); //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/'.md5($this->input->post('category'))); } public function deleteAsset() { $id = $this->input->post('id'); $assetdata = $this->Asset_model->get_asset__id($id,'asset',user()->business_id); $Data = $this->Asset_model->delete_by_md5_id($id,user()->business_id,'asset'); redirect('Asset/assetList/'.md5($assetdata->category)); } public function deleteMultipleAsset() { $delete_data_id = $this->input->post('data'); foreach ($delete_data_id as $id) { $this->Asset_model->delete_by_md5_id(md5($id),user()->business_id,'asset'); } $data['csrf_hash'] = $this->security->get_csrf_hash(); echo json_encode($data); } public function view_qrcode() { $view_qr_data_id = $this->input->post('data'); $output = array(); foreach ($view_qr_data_id as $id) { $qr = $this->Asset_model->get_asset_id(md5($id), 'asset' , user()->business_id); array_push($output , $qr); } $data['data'] = $output; $data['htmlPage'] = $this->load->view('view_qr.php',$data,true); $data['csrf_hash'] = $this->security->get_csrf_hash(); echo json_encode($data); } 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 Value' , '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 Value' , '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']); //set id $ table name for audit history $this->audit->set('id',$this->input->post('id')); $this->audit->set('table','asset_value'); //fetch old_data before new_data update $this->audit->fetch('old_data'); //update asset value $editAssetValueData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'asset_value'); if($editAssetValueData) { //fetch new_data after post data update $this->audit->fetch('new_data'); //audit history generation for update $this->audit->create_history('update'); } $this->session->set_flashdata('msg', "asset_value"); redirect('Asset/view_asset_details/'.md5($this->input->post('asset_id'))); }else{ $get_latest_asset_value = $this->Asset_model->get_latest_asset_value($this->input->post('asset_id_for_add'),user()->business_id); $pre_current_value = $get_latest_asset_value->current_value; // if($this->input->post('type') == 'Upgrade') // { // $data['current_value'] = $pre_current_value * $this->input->post('value'); // }else if($this->input->post('type') == 'Depreciation') { // $data['current_value'] = $pre_current_value - $this->input->post('value'); // } $data['current_value'] = $pre_current_value * $this->input->post('value'); $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'); // print_r($createAssetValueData);die(); if($createAssetValueData) { //set id $ table name for audit history $this->audit->set('id',$createAssetValueData); $this->audit->set('table','asset_value'); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $this->audit->create_history('insert'); } $this->session->set_flashdata(1); $this->session->set_flashdata('msg', "asset_value"); 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) { //month year for dropdown $date_output = array(); $start = new DateTime; $start->setDate($start->format('Y'), $start->format('n'), 1); // Normalize the day to 1 $start->setTime(0, 0, 0); // Normalize time to midnight $start->sub(new DateInterval('P12M')); $interval = new DateInterval('P1M'); $recurrences = 12; $i = 1; foreach (new DatePeriod($start, $interval, $recurrences, true) as $key => $date) { if ($key == 0 || $key == 3 || $key == 6 || $key == 9 ) { $data1['first'] = $date->format('M Y'); $data1['value'] = "Q$i"; array_push($date_output,$data1); $i++; } if ($key == 2 || $key == 5 || $key == 8 || $key == 11 ) { $data2['second'] = $date->format('M Y'); array_push($date_output,$data2); } // echo $date->format('M Y'), "
"; // attempting to make it more clear to read here } // echo json_encode($date_output); $data = array('asset_id'=> $split[0], 'heading'=>'Add Asset Usage' , 'submit_button_title'=>'Submit' , 'date' => $date_output); } 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']); //set id $ table name for audit history $this->audit->set('id',$this->input->post('id')); $this->audit->set('table','asset_usage'); //fetch old_data before new_data update $this->audit->fetch('old_data'); //update asset value $editAssetUsageData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'asset_usage'); if($editAssetUsageData) { //fetch new_data after post data update $this->audit->fetch('new_data'); //audit history generation for update $this->audit->create_history('update'); } $this->session->set_flashdata('msg', "asset_usage"); 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'); if($createAssetUsageData) { //set id $ table name for audit history $this->audit->set('id',$createAssetUsageData); $this->audit->set('table','asset_usage'); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $this->audit->create_history('insert'); } $this->session->set_flashdata('msg', "asset_usage"); 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(); $valid_from = date_create($this->input->post('valid_from')); $value['valid_from'] = date_format($valid_from,"Y-m-d"); $valid_to = date_create($this->input->post('valid_to')); $value['valid_to'] = date_format($valid_to,"Y-m-d"); unset($value['asset_id_for_add']); //set id $ table name for audit history $this->audit->set('id',$this->input->post('id')); $this->audit->set('table','amc'); //fetch old_data before new_data update $this->audit->fetch('old_data'); //update asset value $editAMCData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'amc'); if($editAMCData) { //fetch new_data after post data update $this->audit->fetch('new_data'); //audit history generation for update $this->audit->create_history('update'); } $this->session->set_flashdata('msg', "asset_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['service_provider'] = $this->input->post('service_provider'); $data['cost'] = $this->input->post('cost'); $data['description'] = $this->input->post('description'); $valid_from = date_create($this->input->post('valid_from')); $data['valid_from'] = date_format($valid_from,"Y-m-d"); $valid_to = date_create($this->input->post('valid_to')); $data['valid_to'] = date_format($valid_to,"Y-m-d"); $data['created_by'] = user()->id; $data['type'] = 3; //(amc service provider type = 3 * in third_parties table) $createAMCData = $this->MY_Model->insert($data, 'amc'); if($createAMCData) { //set id $ table name for audit history $this->audit->set('id',$createAMCData); $this->audit->set('table','amc'); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $this->audit->create_history('insert'); } $this->session->set_flashdata('msg', "asset_amc"); 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 Insurence' , '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 Insurence' , '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(); $valid_from = date_create($this->input->post('valid_from')); $value['valid_from'] = date_format($valid_from,"Y-m-d"); $valid_to = date_create($this->input->post('valid_to')); $value['valid_to'] = date_format($valid_to,"Y-m-d"); unset($value['asset_id_for_add']); //set id $ table name for audit history $this->audit->set('id',$this->input->post('id')); $this->audit->set('table','amc'); //fetch old_data before new_data update $this->audit->fetch('old_data'); //update asset value $editInsuranceData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'amc'); if($editInsuranceData) { //fetch new_data after post data update $this->audit->fetch('new_data'); //audit history generation for update $this->audit->create_history('update'); } $this->session->set_flashdata('msg', "asset_insurance"); 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'); $valid_from = date_create($this->input->post('valid_from')); $data['valid_from'] = date_format($valid_from,"Y-m-d"); $valid_to = date_create($this->input->post('valid_to')); $data['valid_to'] = date_format($valid_to,"Y-m-d"); $data['created_by'] = user()->id; $data['type'] = 4; //(insurance company type = 4 * in third_parties table) $createInsuranceData = $this->MY_Model->insert($data, 'amc'); if($createInsuranceData) { //set id $ table name for audit history $this->audit->set('id',$createInsuranceData); $this->audit->set('table','amc'); //fetch new_data after post data insert $this->audit->fetch('new_data'); //audit history generation for insert $this->audit->create_history('insert'); } $this->session->set_flashdata('msg', "asset_insurance"); redirect('Asset/view_asset_details/'.md5($this->input->post('asset_id_for_add'))); } } public function getAssetImageForm($id) { $data = array('asset_id'=> $id, 'heading'=>'Add File' , '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|jpeg|pdf'; $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); $this->session->set_flashdata('msg', "asset_image"); 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'); $this->session->set_flashdata('msg', "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'); $this->session->set_flashdata('msg', "asset_usage"); redirect('Asset/view_asset_details/'.md5($asset_id)); } public function deleteAssetAMC() { $id = $this->input->post('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'); $this->session->set_flashdata('msg', "asset_amc"); redirect('Asset/view_asset_details/'.md5($asset_id)); } public function deleteAssetImage() { $id = $this->input->post('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'); $this->session->set_flashdata('msg', "asset_image"); redirect('Asset/view_asset_details/'.md5($asset_id)); } public function deleteAssetInsurance() { $id = $this->input->post('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'); $this->session->set_flashdata('msg', "asset_insurance"); redirect('Asset/view_asset_details/'.md5($asset_id)); } public function depreciation_report() { $Data = $this->Asset_model->depreciation_report(user()->business_id); //print_r($Data);die(); $this->layout->set('tableData', $Data); $this->layout->buffer('main_content', 'Asset/depreciation_list'); $this->layout->render('default_layout'); } public function amc_report() { $Data = $this->Asset_model->amc_insurance_report(3,user()->business_id); $this->layout->set('tableData', $Data); $this->layout->buffer('main_content', 'Asset/amc_reports_list'); $this->layout->render('default_layout'); } public function insurance_report() { $Data = $this->Asset_model->amc_insurance_report(4,user()->business_id); $this->layout->set('tableData', $Data); $this->layout->buffer('main_content', 'Asset/insurance_reports_list'); $this->layout->render('default_layout'); } public function masterDataList() { $this->layout->set('manufacturerData', $this->Asset_model->get_third_party_value_by_md5_id(user()->business_id,1)); $this->layout->set('supplierData', $this->Asset_model->get_third_party_value_by_md5_id(user()->business_id,2)); $this->layout->set('service_privoder', $this->Asset_model->get_third_party_value_by_md5_id(user()->business_id,3)); $this->layout->set('insurence', $this->Asset_model->get_third_party_value_by_md5_id(user()->business_id,4)); $this->layout->set('locationsData', $this->MY_Model->select_by_business_id('locations',user()->business_id,1)); $this->layout->set('categoriesData', $this->MY_Model->select_by_category_data('categories',user()->business_id)); $this->layout->set('departmentData', $this->MY_Model->select_by_department_data('department_master',user()->business_id)); $this->layout->set('leaveData', $this->MY_Model->select_by_department_data('leave_master',user()->business_id)); $this->layout->set('enum_value', $this->MY_Model->select_by_department_data('enum',user()->business_id)); $this->layout->buffer('main_content', 'Asset/master_list'); $this->layout->render('default_layout'); } public function getThirdPartyForm($id) { $state = $this->MY_Model->select('state'); if ($id == "manufacture") { $data = array('heading'=> "Manufacturer Details", 'type' => 1 , 'states' => $state , 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('third_party_master_form.php',$data,true); echo json_encode($htmlPage); } else if ($id == "supplier") { $data = array('heading'=> "supplier Details", 'type' => 2 , 'states' => $state , 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('third_party_master_form.php',$data,true); echo json_encode($htmlPage); } else if ($id == "service_privoder") { $data = array('heading'=> "Service Privoder Details", 'type' => 3 , 'states' => $state , 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('third_party_master_form.php',$data,true); echo json_encode($htmlPage); } else if ($id == "insurence") { $data = array('heading'=> "Insurence Details", 'type' => 4 , 'states' => $state , 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('third_party_master_form.php',$data,true); echo json_encode($htmlPage); } else { $table = 'third_parties'; $user_data = $this->Asset_model->get_third_party_by_md5_id($id); $data = array('heading'=> "Edit Details" , 'third_party_data'=> $user_data , 'states' => $state , 'submit_button_title'=>'Update' ); $htmlPage = $this->load->view('third_party_master_form.php',$data,true); echo json_encode($htmlPage); } } public function add_or_edit_ThirdPartyForm() { $table = 'third_parties'; $action = $this->input->post(); $id = $this->input->post('id'); $type = $this->input->post('type'); if ($id) { $userData = $this->MY_Model->edit_option($action, $id, $table); $this->session->set_flashdata('msg', $type); redirect('Asset/masterDataList'); } else { $userData = $this->MY_Model->insert($action, $table); // if($business->is_master_data_entered == 0){ $this->MY_Model->editBusiness(); } // $this->session->set_flashdata('msg', $type); redirect('Asset/masterDataList'); } } public function getLocationForm($id) { if ($id == "location") { $table = 'locations'; $data = array('heading'=> "Location Details", 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('location_master_form.php',$data,true); echo json_encode($htmlPage); } else { $table = 'locations'; $location_data = $this->MY_Model->get_by_md5_id($id, $table); $data = array('heading'=> "Location Details", 'location_data'=> $location_data , 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('location_master_form.php',$data,true); echo json_encode($htmlPage); } } public function add_or_edit_LocationForm() { $table = 'locations'; $action = $this->input->post(); $id = $this->input->post('id'); if ($id) { $userData = $this->MY_Model->edit_option($action, $id, $table); $this->session->set_flashdata('msg', "location"); redirect('Asset/masterDataList'); } else { $userData = $this->MY_Model->insert($action, $table); // if($business->is_master_data_entered == 0){ $this->MY_Model->editBusiness(); } // $this->session->set_flashdata('msg', "location"); redirect('Asset/masterDataList'); } } public function getCatogaryForm($id) { if ($id == "catogary") { $table = 'categories'; $data = array('heading'=> "Catogary Details", 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('catogary_master_form.php',$data,true); echo json_encode($htmlPage); } else { $table = 'categories'; $catogary_data = $this->MY_Model->get_by_md5_id($id, $table); $data = array('heading'=> "Catogary Details", 'catogary_data'=> $catogary_data , 'submit_button_title'=>'Update' ); $htmlPage = $this->load->view('catogary_master_form.php',$data,true); echo json_encode($htmlPage); } } public function add_or_edit_CategoriesForm() { $table = 'categories'; $action = $this->input->post(); $id = $this->input->post('id'); // print_r($id);die(); if ($id) { $userData = $this->MY_Model->edit_option($action, $id, $table); $this->session->set_flashdata('msg', "categories"); redirect('Asset/masterDataList'); } else { $userData = $this->MY_Model->insert($action, $table); // if($business->is_master_data_entered == 0){ $this->MY_Model->editBusiness(); } // $this->session->set_flashdata('msg', "categories"); redirect('Asset/masterDataList'); } } public function getDepartmentForm($id) { if ($id == "department") { $table = 'department_master'; $data = array('heading'=> "Department Details", 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('department_master_form.php',$data,true); echo json_encode($htmlPage); } else { $table = 'department_master'; $department_data = $this->MY_Model->get_by_md5_id($id, $table); $data = array('heading'=> "Department Details", 'department_data'=> $department_data , 'submit_button_title'=>'Update' ); $htmlPage = $this->load->view('department_master_form.php',$data,true); echo json_encode($htmlPage); } } public function add_or_edit_DepartmentForm() { $table = 'department_master'; $action = $this->input->post(); $id = $this->input->post('id'); // print_r($id);die(); if ($id) { $userData = $this->MY_Model->edit_option($action, $id, $table); $this->session->set_flashdata('msg', "department"); redirect('Asset/masterDataList'); } else { $userData = $this->MY_Model->insert($action, $table); // if($business->is_master_data_entered == 0){ $this->MY_Model->editBusiness(); } // $this->session->set_flashdata('msg', "department"); redirect('Asset/masterDataList'); } } public function deleteDepartmentFormData() { $id = $this->input->post('id'); $table = 'department_master'; $user = $this->Asset_model->get_by_id($id , $table); $Data = $this->Asset_model->delete_by_md5_id($id,user()->business_id,$table); $this->session->set_flashdata('msg', "department"); redirect('Asset/masterDataList'); } public function getLeaveForm($id) { if ($id == "leave") { $table = 'leave_master'; $data = array('heading'=> "Leave Details", 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('leave_master_form.php',$data,true); echo json_encode($htmlPage); } else { $table = 'leave_master'; $leave_data = $this->MY_Model->get_by_md5_id($id, $table); $data = array('heading'=> "Leave Details", 'leave_data'=> $leave_data , 'submit_button_title'=>'Update' ); $htmlPage = $this->load->view('leave_master_form.php',$data,true); echo json_encode($htmlPage); } } public function add_or_edit_LeaveForm() { $table = 'leave_master'; $action = $this->input->post(); $id = $this->input->post('id'); if ($id) { $userData = $this->MY_Model->edit_option($action, $id, $table); $this->session->set_flashdata('msg', "leave"); redirect('Asset/masterDataList'); } else { $userData = $this->MY_Model->insert($action, $table); // if($business->is_master_data_entered == 0){ $this->MY_Model->editBusiness(); } // $this->session->set_flashdata('msg', "leave"); redirect('Asset/masterDataList'); } } public function deleteLeaveFormData() { $id = $this->input->post('id'); $table = 'leave_master'; $Data = $this->Asset_model->delete_by_md5_id($id,user()->business_id,$table); $this->session->set_flashdata('msg', "leave"); redirect('Asset/masterDataList'); } /// decline reason public function getDeclineForm($id) { if ($id == "decline") { $table = 'enum'; $data = array('heading'=> "Decline Reason", 'submit_button_title'=>'Add' ); $htmlPage = $this->load->view('Decline_Reason_form.php',$data,true); echo json_encode($htmlPage); } else { $table = 'enum'; $Decline_data = $this->MY_Model->get_by_md5_id($id, $table); $data = array('heading'=> "Decline Reason", 'Decline_data'=> $Decline_data , 'submit_button_title'=>'Update' ); $htmlPage = $this->load->view('Decline_Reason_form.php',$data,true); echo json_encode($htmlPage); } } public function add_or_edit_DeclineForm() { $table = 'enum'; $action = $this->input->post(); $action['is_active'] = 1; $id = $this->input->post('id'); if ($id) { $userData = $this->MY_Model->edit_option($action, $id, $table); $this->session->set_flashdata('msg', "decline"); redirect('Asset/masterDataList'); } else { $userData = $this->MY_Model->insert($action, $table); // if($business->is_master_data_entered == 0){ $this->MY_Model->editBusiness(); } // $this->session->set_flashdata('msg', "decline"); redirect('Asset/masterDataList'); } } public function deleteDeclineFormData() { $id = $this->input->post('id'); $table = 'enum'; $Data = $this->Asset_model->delete_by_md5_id($id,user()->business_id,$table); $this->session->set_flashdata('msg', "decline"); redirect('Asset/masterDataList'); } public function deleteThirdPartyData() { $id = $this->input->post('id'); $table = 'third_parties'; $user = $this->Asset_model->get_by_id($id , $table); $Data = $this->Asset_model->delete_by_md5_id($id,user()->business_id,$table); $this->session->set_flashdata('msg', $user->type); redirect('Asset/masterDataList'); } public function deleteCategoriesFormData() { $id = $this->input->post('id'); $table = 'categories'; $user = $this->Asset_model->get_by_id($id , $table); $Data = $this->Asset_model->delete_by_md5_id($id,user()->business_id,$table); $this->session->set_flashdata('msg', "categories"); redirect('Asset/masterDataList'); } public function getDeleteConfirmationPopup() { $data = array(); $htmlPage = $this->load->view('confirmation_popup.php',$data,true); echo json_encode($htmlPage); } public function filterAssets() { $split = preg_split('/-/', $this->input->post('reservation')); $purchase_date_from = date_format(date_create($split[0]),"Y-m-d"); $purchase_date_to = date_format(date_create($split[1]),"Y-m-d"); redirect('Asset/assetList/'.md5($this->input->post('category')).'/'.$purchase_date_from.'/'.$purchase_date_to); } }