AuditHistory:GWM
This commit is contained in:
parent
42581e727b
commit
69e975549a
@ -47,7 +47,8 @@ public function __construct()
|
||||
// Copyright
|
||||
// $this->global_data['copyright_from_mycontroller'] = $date;
|
||||
// $this->load->vars($this->global_data);
|
||||
$this->load->module('layout');
|
||||
$this->load->module('layout');
|
||||
$this->load->module('audit');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ public function insert($data,$table){
|
||||
function edit_option($action, $id, $table){
|
||||
$this->db->where('id',$id);
|
||||
$this->db->update($table,$action);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
// edit function
|
||||
|
||||
@ -87,9 +87,22 @@ public function createAssets()
|
||||
$upload_asset_image = $this->upload->data();
|
||||
$data['asset_img'] = $upload_asset_image['file_name'];
|
||||
}
|
||||
//print_r($data);die();
|
||||
|
||||
$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');
|
||||
|
||||
}
|
||||
@ -150,9 +163,20 @@ public function editAssets()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$assetData = $this->MY_Model->edit_option($action, $id, $table);
|
||||
//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');
|
||||
|
||||
}
|
||||
@ -473,22 +497,28 @@ public function deleteAssetInsurance($id)
|
||||
public function test()
|
||||
{
|
||||
|
||||
$this->audit->set('id',1);
|
||||
$this->audit->set('table','asset');
|
||||
// $test = $this->audit->fetch('old_data');
|
||||
|
||||
// $this->audit->set('id',2);
|
||||
$this->audit->fetch('new_data');
|
||||
|
||||
$test = $this->audit->create_history('insert');
|
||||
|
||||
// $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 "</br>";
|
||||
|
||||
$id = 1;
|
||||
$table = "asset";
|
||||
$assetData = $this->MY_Model->getData($table,$id,user()->business_id);
|
||||
// $data = audit_history($assetData,$table,user()->business_id);
|
||||
|
||||
$object = (object) $action;
|
||||
$data = audit_history($object,$table,user()->business_id);
|
||||
print_r($data);die();
|
||||
|
||||
echo "</br>";
|
||||
|
||||
$data = audit_history($assetData,$table,user()->business_id);
|
||||
print_r($assetData);
|
||||
print_r($test);
|
||||
|
||||
}
|
||||
|
||||
|
||||
113
application/modules/Audit/controllers/Audit.php
Normal file
113
application/modules/Audit/controllers/Audit.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH')) 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 Layout
|
||||
*/
|
||||
class Audit extends MX_Controller
|
||||
{
|
||||
public $table;
|
||||
public $id;
|
||||
public $old_data = array();
|
||||
public $new_data = array();
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// To inherit directly the attributes of the parent class.
|
||||
parent::__construct();
|
||||
$this->load->model('MY_Model');
|
||||
}
|
||||
|
||||
// set table name and primary key for current data
|
||||
public function set()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
if($args[0] == 'id'){ $this->id = $args[1]; }
|
||||
else if($args[0] == 'table'){ $this->table = $args[1]; }
|
||||
|
||||
}
|
||||
|
||||
// fetching old or new data
|
||||
public function fetch()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$data = $this->MY_Model->getData($this->table,$this->id,user()->business_id);
|
||||
if($args[0] == 'old_data'){ $this->old_data = $data; return $this->old_data; }
|
||||
else if($args[0] == 'new_data'){ $this->new_data = $data; return $this->new_data; }
|
||||
|
||||
}
|
||||
|
||||
//construct audit history and insert audit data into history table
|
||||
public function create_history()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if($args[0] == 'update')
|
||||
{
|
||||
$Output = array();
|
||||
foreach($this->new_data as $postDatakey=>$postDatavalue)
|
||||
{
|
||||
foreach($this->old_data as $TableDatakey=>$TableDatavalue)
|
||||
{
|
||||
if($postDatakey == $TableDatakey)
|
||||
{
|
||||
if($postDatavalue != $TableDatavalue)
|
||||
{
|
||||
$data['table_name'] = $this->table;
|
||||
$data['column_name'] = $postDatakey;
|
||||
$data['old_value'] = $TableDatavalue;
|
||||
$data['new_value'] = $postDatavalue;
|
||||
$data['created_by'] = user()->id;
|
||||
$data['business_id'] = user()->business_id;
|
||||
$data['primary_id'] = $this->id;
|
||||
$data['created_at'] = date("Y-m-d h:i:s");
|
||||
array_push($Output,$data);
|
||||
$this->MY_Model->insert($data,'history');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $Output;
|
||||
}else if($args[0] == 'insert') {
|
||||
$Output = array();
|
||||
foreach($this->new_data as $postDatakey=>$postDatavalue)
|
||||
{
|
||||
if($postDatakey != 'id' && $postDatakey != 'created_by ' && $postDatakey != 'is_active' && $postDatakey != 'created_at')
|
||||
{
|
||||
$data['table_name'] = $this->table;
|
||||
$data['column_name'] = $postDatakey;
|
||||
$data['new_value'] = $postDatavalue;
|
||||
$data['created_by'] = user()->id;
|
||||
$data['business_id'] = user()->business_id;
|
||||
$data['primary_id'] = $this->id;
|
||||
$data['created_at'] = date("Y-m-d h:i:s");
|
||||
array_push($Output,$data);
|
||||
$this->MY_Model->insert($data,'history');
|
||||
}
|
||||
}
|
||||
return $Output;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -137,8 +137,9 @@ public function edit_business()
|
||||
|
||||
$table="business";
|
||||
$assetData = $this->MY_Model->edit_option($action, $id, $table);
|
||||
redirect('business/business_list');
|
||||
|
||||
if(is_superadmin()){ redirect('business/business_list');}
|
||||
else if(is_admin()){ redirect('user/businessProfile/'.md5(user()->business_id)); }
|
||||
|
||||
}
|
||||
|
||||
public function deleteAsset($id)
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<a href="<?php echo base_url();?>asset/test" class="btn btn-sm btn-primary">history</a>
|
||||
|
||||
<div>
|
||||
<p>LOGGEDIN : <?php echo check_auth()?></p>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user