diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 169be10..2ceea24 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -48,6 +48,7 @@ public function __construct() // $this->global_data['copyright_from_mycontroller'] = $date; // $this->load->vars($this->global_data); $this->load->module('layout'); + } } diff --git a/application/core/MY_Model.php b/application/core/MY_Model.php index 7bd2c55..b39c0d8 100644 --- a/application/core/MY_Model.php +++ b/application/core/MY_Model.php @@ -259,6 +259,16 @@ function get_settings() $query = $query->row(); return $query; } - + + function getData($table,$id,$business_id) + { + $this->db->select(); + $this->db->from($table); + $this->db->where('business_id', $business_id); + $this->db->where('id', $id); + $query = $this->db->get(); + $query = $query->row(); + return $query; + } } diff --git a/application/helpers/custom_helper.php b/application/helpers/custom_helper.php index 98cb73a..24952ac 100644 --- a/application/helpers/custom_helper.php +++ b/application/helpers/custom_helper.php @@ -180,4 +180,41 @@ function day_different($to){ return ''; } } + } + + + // audit history function + if(!function_exists('audit_history')){ + function audit_history($postData,$table,$business_id){ + + if($table != ''){ + $id = $postData->id; + $ci =& get_instance(); + $TableData = $ci->MY_Model->getData($table,$id,$business_id); + $Output = array(); + foreach($postData as $postDatakey=>$postDatavalue) + { + foreach($TableData as $TableDatakey=>$TableDatavalue) + { + if($postDatakey == $TableDatakey) + { + if($postDatavalue != $TableDatavalue) + { + $data['table_name'] = $table; + $data['column_name'] = $postDatakey; + $data['old_value'] = $TableDatavalue; + $data['new_value'] = $postDatavalue; + $data['created_by'] = user()->id; + $data['business_id'] = $business_id; + $data['primary_id'] = $id; + array_push($Output,$data); + } + } + } + } + return $Output; + }else{ + return ''; + } + } } \ No newline at end of file diff --git a/application/modules/Asset/controllers/Asset.php b/application/modules/Asset/controllers/Asset.php index 757f31c..86c8709 100644 --- a/application/modules/Asset/controllers/Asset.php +++ b/application/modules/Asset/controllers/Asset.php @@ -108,7 +108,7 @@ public function editAsset($id) $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,'amc',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); $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); @@ -130,8 +130,6 @@ public function editAssets() $action['purchase_date'] = date_format($date,"Y-m-d"); - - //print_r($action);die(); $id = $this->input->post('id'); //file upload confic $asset_image['upload_path'] = APPPATH. '../assets/uploads/'; @@ -150,7 +148,8 @@ public function editAssets() $action['asset_img'] = $upload_asset_image['file_name']; } - + + $assetData = $this->MY_Model->edit_option($action, $id, $table); @@ -471,7 +470,27 @@ public function deleteAssetInsurance($id) redirect('asset/view_asset_details/'.md5($asset_id)); } - + public function test() + { + + + + + + $id = 1; + $table = "asset"; + $assetData = $this->MY_Model->getData($table,$id,user()->business_id); + + $object = (object) $action; + $data = audit_history($object,$table,user()->business_id); + print_r($data);die(); + + echo ""; + + $data = audit_history($assetData,$table,user()->business_id); + print_r($assetData); + + } } diff --git a/application/modules/Asset/models/Asset_model.php b/application/modules/Asset/models/Asset_model.php index a6c4ddd..b554811 100644 --- a/application/modules/Asset/models/Asset_model.php +++ b/application/modules/Asset/models/Asset_model.php @@ -107,5 +107,7 @@ public function delete_by_md5_id($id,$business_id,$table) $this->db->update($table); return; } + + } \ No newline at end of file diff --git a/application/modules/Asset/views/add_asset.php b/application/modules/Asset/views/add_asset.php index 13af30f..3b9840d 100644 --- a/application/modules/Asset/views/add_asset.php +++ b/application/modules/Asset/views/add_asset.php @@ -188,7 +188,7 @@