diff --git a/application/modules/Asset/controllers/Asset.php b/application/modules/Asset/controllers/Asset.php index 40d6892..ed0e831 100644 --- a/application/modules/Asset/controllers/Asset.php +++ b/application/modules/Asset/controllers/Asset.php @@ -264,8 +264,23 @@ public function add_or_edit_asset_value() { $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'))); + + //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'); + } + + redirect('asset/view_asset_details/'.md5($this->input->post('asset_id'))); }else{ $data['asset_id'] = $this->input->post('asset_id_for_add'); @@ -277,7 +292,16 @@ public function add_or_edit_asset_value() $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'))); + 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); redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add'))); } @@ -302,14 +326,28 @@ public function getAssetUsageForm($id) 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'))); + + //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'); + } redirect('asset/view_asset_details/'.md5($this->input->post('asset_id'))); }else{ $data['asset_id'] = $this->input->post('asset_id_for_add'); @@ -320,7 +358,16 @@ public function add_or_edit_asset_usage() $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'))); + 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'); + } redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add'))); } } @@ -345,14 +392,28 @@ public function getAssetAMCForm($id) 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'))); + + //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'); + } redirect('asset/view_asset_details/'.md5($this->input->post('asset_id'))); }else{ $data['asset_id'] = $this->input->post('asset_id_for_add'); @@ -365,7 +426,16 @@ public function add_or_edit_asset_amc() $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'))); + 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'); + } redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add'))); } } @@ -397,7 +467,21 @@ public function add_or_edit_asset_insurance() { $value = $this->input->post(); unset($value['asset_id_for_add']); - $editInsuranceData = $this->MY_Model->edit_option($value, $this->input->post('id'), 'amc'); + + //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'); + } redirect('asset/view_asset_details/'.md5($this->input->post('asset_id'))); }else{ $data['asset_id'] = $this->input->post('asset_id_for_add'); @@ -410,6 +494,16 @@ public function add_or_edit_asset_insurance() $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'); + } redirect('asset/view_asset_details/'.md5($this->input->post('asset_id_for_add'))); } } @@ -496,10 +590,9 @@ public function deleteAssetInsurance($id) redirect('asset/view_asset_details/'.md5($asset_id)); } - public function test() + public function get_history() { - $data = $this->Audit_model->get_history(13,'asset',user()->business_id); - print_r($data);die(); + echo $this->input->post(); } diff --git a/application/modules/Asset/views/asset_sub_value_list.php b/application/modules/Asset/views/asset_sub_value_list.php index 0ae4f01..144126f 100644 --- a/application/modules/Asset/views/asset_sub_value_list.php +++ b/application/modules/Asset/views/asset_sub_value_list.php @@ -67,6 +67,8 @@ asset_id;?>" style="font-size: 16px;"> + + diff --git a/application/modules/Dashboard/controllers/Dashboard.php b/application/modules/Dashboard/controllers/Dashboard.php index dbb9683..57a97d0 100644 --- a/application/modules/Dashboard/controllers/Dashboard.php +++ b/application/modules/Dashboard/controllers/Dashboard.php @@ -25,6 +25,7 @@ public function __construct() { // To inherit directly the attributes of the parent class. parent::__construct(); + $this->load->model('Dashboard_model'); } /** @@ -36,14 +37,27 @@ public function __construct() */ public function index() { - $users = array('name' => 'user 1','age' => 35); - $address = array('address' => 'street','pincode' => 741852); - - // echo $this->security->get_csrf_token_name(); echo $this->security->get_csrf_hash();die(); - //pass data to views - $this->layout->set('users', $users); - $this->layout->set('address', $address); - + if(is_admin()) + { + $asset_count = $this->Dashboard_model->get_assets_count(user()->business_id); + $this->layout->set('asset_count', $asset_count); + + $user_count = $this->Dashboard_model->get_users_count(user()->business_id); + $this->layout->set('user_count', $user_count); + + $amc_count = $this->Dashboard_model->get_amc_count(user()->business_id); + $this->layout->set('amc_count', $amc_count); + + $expired_amc_count = $this->Dashboard_model->get_expired_amc_count(user()->business_id); + $this->layout->set('expired_amc_count', $expired_amc_count); + + $insurance_count = $this->Dashboard_model->get_insurance_count(user()->business_id); + $this->layout->set('insurance_count', $insurance_count); + + $expired_insurance_count = $this->Dashboard_model->get_expired_insurance_count(user()->business_id); + $this->layout->set('expired_insurance_count', $expired_insurance_count); + + } $this->layout->buffer('main_content', 'dashboard/dashboard'); $this->layout->render('default_layout'); diff --git a/application/modules/Dashboard/models/Dashboard_model.php b/application/modules/Dashboard/models/Dashboard_model.php new file mode 100644 index 0000000..4c20c9f --- /dev/null +++ b/application/modules/Dashboard/models/Dashboard_model.php @@ -0,0 +1,78 @@ +db->select(); + $this->db->from('asset'); + $this->db->where('business_id', $business_id); + $this->db->where('is_active', 1); + $query = $this->db->get(); + $query = $query->num_rows(); + return $query; + } + + public function get_users_count($business_id) + { + $this->db->select(); + $this->db->from('users'); + $this->db->where('business_id', $business_id); + $this->db->where('is_active', 1); + $query = $this->db->get(); + $query = $query->num_rows(); + return $query; + } + + + public function get_amc_count($business_id) + { + $this->db->select(); + $this->db->from('amc'); + $this->db->where('business_id', $business_id); + $this->db->where('is_active', 1); + $this->db->where('type', 3); + $query = $this->db->get(); + $query = $query->num_rows(); + return $query; + } + + + public function get_expired_amc_count($business_id) + { + $this->db->select(); + $this->db->from('amc'); + $this->db->where('business_id', $business_id); + $this->db->where('is_active', 1); + $this->db->where('type', 3); + $query = $this->db->get(); + $query = $query->num_rows(); + return $query; + } + + public function get_insurance_count($business_id) + { + $this->db->select(); + $this->db->from('amc'); + $this->db->where('business_id', $business_id); + $this->db->where('is_active', 1); + $this->db->where('type', 4); + $query = $this->db->get(); + $query = $query->num_rows(); + return $query; + } + + + public function get_expired_insurance_count($business_id) + { + $this->db->select(); + $this->db->from('amc'); + $this->db->where('business_id', $business_id); + $this->db->where('is_active', 1); + $this->db->where('type', 4); + $query = $this->db->get(); + $query = $query->num_rows(); + return $query; + } + + +} \ No newline at end of file diff --git a/application/modules/Dashboard/views/dashboard.php b/application/modules/Dashboard/views/dashboard.php index 2b9ecaf..c0481f4 100644 --- a/application/modules/Dashboard/views/dashboard.php +++ b/application/modules/Dashboard/views/dashboard.php @@ -2,35 +2,40 @@