Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
VENKATESHWARAN 2024-04-27 10:43:33 +05:30
commit 32cbae7204
6 changed files with 178 additions and 8 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

@ -286,7 +286,7 @@ class EmployeeRestController extends AdminController
->where('client_policy_id',$value['policy_details']['client_policy_id'] )
->where('employee_id' , $value['temp']['emp_id'] )
->where('is_active', 1 )
->set(array('premium'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] ))
->set(array('premium'=> $value['policy_details']['premium'] , 'gst'=> $value['policy_details']['gst'] ))
->update();
}
@ -1017,13 +1017,15 @@ public function getEmployeePolicy()
$id = $this->request->getGet('id');
$emp_code = $this->request->getGet('emp_code');
$client_id = $this->request->getGet('client_id');
// This is an array containing keys to be removed from the terms and conditions array
$keysToRemove = ["removable_keys"];
// Retrieve employee policy data by passing the employee primary key
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
// Retrieve employee and dependents data by passing the employee code
$employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('is_active', 1 )->where('is_addon_value',0)->findAll();
$employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('client_id',$client_id)
->where('is_active', 1 )->where('is_addon_value',0)->findAll();
// dd($empPolicy);
if ($empPolicy) {
@ -1032,6 +1034,7 @@ public function getEmployeePolicy()
foreach ($empPolicy as $array) {
// Reset employee array
$empData = $employeeData;
// Removes specific keys from the decoded array and assigns the result to $refusingData
$decodedArray = json_decode($array->Policy_Terms);
@ -1045,9 +1048,10 @@ public function getEmployeePolicy()
// Construct value for policy type GPA
if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
// Filter employee data where the family_floater_key is 'self'
$selfData = array_filter($empData, fn($arr) => trim(strtolower($arr['family_floater_key'])) === 'self');
$self['is_value_exist'] = true;
$self['data']['family_floater_key'] = 'self';
$self['data']['employee_id'] = $id;
@ -1244,8 +1248,8 @@ public function getAddOnPolicy()
{
try {
$addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',1)->findAll();
$GMCEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',0)->findAll();
$addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',1)->findAll();
$GMCEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',0)->findAll();
$clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll();

View File

@ -77,7 +77,7 @@ class RestAuthenticationController extends AdminController
if ($employeeData) {
$id= $employeeData["id"];
$otp = $this->employeeModel->where('id', $id)->set('otp', $randomNumber)->update();
$result = ['user_verification' => true , 'otp'=>$randomNumber];
$result = ['user_verification' => true ,'message' => "Verified Successfully", 'otp'=>$randomNumber];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else {
$result = ['user_verification' => false , 'message' => "User not found"];
@ -136,7 +136,7 @@ class RestAuthenticationController extends AdminController
if ($HrData) {
$id= $HrData["id"];
$otp = $this->hrModel->where('id', $id)->set('otp', $randomNumber)->update();
$result = ['user_verification' => true , 'otp'=>$randomNumber];
$result = ['user_verification' => true ,'message' => "Verified Successfully", 'otp'=>$randomNumber];
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
} else {
$result = ['user_verification' => false , 'message' => "User not found"];

View File

@ -340,6 +340,8 @@ if (!function_exists('name_and_empid_check_in_db'))
->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
// ->where("cp.id",$policy_id)
->where("employees.client_id",$client_id)
->where("employees.is_active",1)
->where("ep.is_active",1)
// ->where("ep.client_id",$client_id)
->where('name',$row[2])->where('emp_code',$row[1])
->findAll();
@ -634,6 +636,8 @@ if (!function_exists('transform_excel_data_to_db'))
$result['temp']['source'] = isset($memArr['temp']['source']) ? $memArr['temp']['source'] : 'excel';
$result['temp']['emp_id'] = isset($memArr['temp']['emp_id']) ? $memArr['temp']['emp_id'] : null;
$result['temp']['emp_policy_id'] = isset($memArr['temp']['emp_policy_id']) ? $memArr['temp']['emp_policy_id'] : null;
$result['temp']['policy_status'] = isset($memArr['temp']['policy_status']) ? $memArr['temp']['policy_status'] : null;
$result['temp']['emp_status'] = isset($memArr['temp']['emp_status']) ? $memArr['temp']['emp_status'] : null;
$result['policy_details'] = $policy;
return $result;
@ -650,6 +654,36 @@ if (!function_exists('premium_calculation_manager'))
// grid type
// 1 = premium => si
// 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 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'];
@ -1004,6 +1038,8 @@ if (!function_exists('transform_db_data_to_excel'))
$row['temp']['source'] = 'db';
$row['temp']['emp_id'] = $value['emp_id'];
$row['temp']['emp_policy_id'] = $value['emp_policy_id'];
$row['temp']['emp_status'] = $value['emp_status'];
$row['temp']['policy_status'] = $value['status'];
array_push($return_data, ($row));
}
@ -1028,4 +1064,64 @@ if (!function_exists('compare_excel_cell_range'))
}
return [];
}
}
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' 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();
if(count($res))
{ $temp = [];
foreach($res as $row)
{
$temp[ $row['field_name'] ] = $row['old_value'];
}
return $temp;
}
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,13 +78,20 @@ 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'])
// ->where('relationship_code',$arr['relationship_code'])
->where('is_active',1)
->where('gender',$arr['gender'])
->where('dob',$arr['dob'])
->find();
}
else
{
return $this->where('id',$arr['temp']['emp_id'])->find();
}
}

View File

@ -109,6 +109,7 @@ class EmployeePolicyModel extends Model
{
return $this->where('employee_id',$arr['employee_id'])
->where('client_policy_id',$arr['client_policy_id'])
->where('is_active',1)
->find();
}