FIX_TRUNCATE_FILE_DATA

This commit is contained in:
velz 2024-04-27 08:43:52 +05:30
parent bfda5bef90
commit abc77ab60e
3 changed files with 134 additions and 11 deletions

View File

@ -886,6 +886,68 @@ class EmployeeController extends AdminController
$this->loadLayout('id_card_view');
}
public function truncateFileData() //truncateFileDataIn DB (de activate rows)
{
$file_id = $this->request->uri->getSegment(3);
// $file_id = 112;
$file = $this->fileModel->find($file_id);
// $file['action'] = 'si_enhancement';
// $result = [];
// !dd($file);
if($file['action'] == 'inception' || $file['action'] == 'dependent_addition' || $file['action'] == 'addition')
{
$result = $this->employeeModel->getEmpListByFileId(file_id: $file_id,emp_status: ['active'],policy_status:['active']);
// ~dd($result);
if(count($result))
{
return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'File data already processed'], 200);
}
else
{
//update emp and emp plocies
$db = db_connect();
$query = "UPDATE employees JOIN employee_polices ON employees.id = employee_polices.employee_id and employees.file_id = $file_id SET employees.emp_status = 'truncated', employee_polices.status = 'truncated', employees.is_active = 0,employee_polices.is_active = 0 WHERE employees.file_id = $file_id";
$db->query($query);
$affectedRows = $db->affectedRows();
// $affectedRows = 10;
//update file status
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
return $this->respond(['dataStatus' => true,'code' => 200,'data' => round($affectedRows/2)], 200);
}
}
else if($file['action'] == 'si_enhancement' || $file['action'] == 'correction' || $file['action'] == 'deletion')
{
$res = $this->empEndorsementModel->select(['count(id) as count'])
->where('emp_endorsement.file_id',$file_id)
->groupStart()
->where('emp_endorsement.endorsement_id is not null')
->orwhereIn('emp_endorsement.status',['complete'])
->groupEnd()
->get()
->getResult();
// print_r($this->empEndorsementModel->getLastQuery());
// echo $res[0]->count;die();
if($res[0]->count == 0)
{
//update truncated status to db
$this->empEndorsementModel->where('file_id',$file_id)
->set(['status' => 'truncated'])
->update();
//update file status
$this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
return $this->respond(['dataStatus' => true,'code' => 200,'data' => 'success'], 200);
}
else
{
return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'File data already processed'], 200);
}
}
}

View File

@ -656,17 +656,33 @@ if (!function_exists('premium_calculation_manager'))
// dd($emp_data);
//check if the data comes from enrollment (DB) and status is draft then fetch original data of employee from
//audit history table then initiate calculation with it. so this data again get updated in emp and policy table
//audit history table then initiate calculation with it. so this data again get updated in emp table
// if($emp_data['temp']['emp_status'] == 'draft' && $emp_data['temp']['policy_status'] == 'draft')
// {
// $original_emp_records = get_emp_records_from_audit_history($emp_data['temp']['emp_id']);
// if(is_array($original_emp_records))
// {
// print_r($original_emp_records);
// }
// }
//end of fetching data from audit history table
//check emp records
if($file['id'] == null && $emp_data['temp']['emp_status'] == 'draft' && $emp_data['temp']['policy_status'] == 'draft')
{
$original_emp_records = get_emp_records_from_audit_history($emp_data['temp']['emp_id']);
if(is_array($original_emp_records))
{
// Kint::dump($original_emp_records);
// $emp_data = replace_original_data(original_data:$original_emp_records,current_data:$emp_data);
// Kint::dump($value);
}
}
//check emp policy records
if($file['id'] == null && $emp_data['temp']['emp_status'] == 'draft' && $emp_data['temp']['policy_status'] == 'draft')
{
$original_emp_policy_records = get_emp_policy_records_from_audit_history($emp_data['temp']['emp_policy_id']);
if(is_array($original_emp_policy_records))
{
// Kint::dump($original_emp_records);
// $emp_data['policy_details'] = replace_original_data(original_data:$original_emp_policy_records,current_data:$emp_data['policy_details']);
// Kint::dump($policy_data);
}
}
//end of fetching data from audit history table
//gird and calculation start
$slug = \Config\Services::slug();
$grid_type = $slab_details['grid_master']['ui_type'];
@ -1055,7 +1071,7 @@ if(!function_exists('get_emp_records_from_audit_history'))
function get_emp_records_from_audit_history($employee_id)
{
$db = db_connect();
$query = "SELECT min(id) as id,pk,table_name,field_name,old_value FROM venbaehn_nhance.auditing_history where pk = $employee_id and table_name = 'employees'group by field_name order by id asc";
$query = "SELECT min(id) as id,pk,table_name,field_name,old_value FROM venbaehn_nhance.auditing_history where pk = $employee_id and table_name = 'employees' and field_name in ('name','dob','gender','mobile','email_corporate','relationship') group by field_name order by id asc";
$res = $db->query($query);
// echo $db->getLastQuery();
$res = $res->getResultArray();
@ -1070,4 +1086,42 @@ if(!function_exists('get_emp_records_from_audit_history'))
return false;
}
}
if(!function_exists('get_emp_policy_records_from_audit_history'))
{
function get_emp_policy_records_from_audit_history($emp_policy_id)
{
$db = db_connect();
$query = "SELECT min(id) as id,pk,table_name,field_name,old_value FROM venbaehn_nhance.auditing_history where pk = $emp_policy_id and table_name = 'employee_polices' and field_name in ('basic_cover_si','premium','gst') group by field_name order by id asc";
$res = $db->query($query);
// echo $db->getLastQuery();
$res = $res->getResultArray();
if(count($res))
{ $temp = [];
foreach($res as $row)
{
$temp[ $row['field_name'] ] = $row['old_value'];
}
return $temp;
}
return false;
}
}
if(!function_exists('replace_original_data'))
{
function replace_original_data(array $original_data,array $current_data)
{
foreach($original_data as $key => $data)
{
if(array_key_exists($key, $current_data))
{
$current_data [$key] = $data;
}
}
return $current_data;
}
}

View File

@ -78,6 +78,8 @@ class EmployeeModel extends Model
public function checkExistingEmp($arr)
{
if($arr['temp']['emp_id'] == null)
{
return $this->where('emp_code',$arr['emp_code'])
->where('name',$arr['name'])
->where('client_id',$arr['client_id'])
@ -85,6 +87,11 @@ class EmployeeModel extends Model
->where('gender',$arr['gender'])
->where('dob',$arr['dob'])
->find();
}
else
{
return $this->where('id',$arr['temp']['emp_id'])->find();
}
}