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

This commit is contained in:
velz 2024-04-24 11:34:11 +05:30
commit b5b3deee94
9 changed files with 240 additions and 64 deletions

View File

@ -263,7 +263,10 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
$routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy");
$routes->get("getClientDetails", "EmployeeRestController::getClientDetails");
$routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy");
$routes->get("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
$routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
$routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData");
});
$routes->post("sendEmail", "EmployeeRestController::send_email");

View File

@ -1048,11 +1048,19 @@ class ClientController extends AdminController
->where("employees.emp_status",'active')
->countAllResults();
if($emp_count == 0){
$emp_count = true;
}else{
$emp_count = false;
}
$data = $this->employeePolicyModel->select('employee_polices.id')
->where('employee_polices.is_active', 1)
->where('employee_polices.client_policy_id', $client_policy_id)
->findAll();
$emp_count = count($data);
// if($emp_count == 0){
// $emp_count = true;
// }else{
// $emp_count = false;
// }
$data = $this->policesModel->getPolicyPremium($record['policy_id']);

View File

@ -108,6 +108,8 @@ class EmpDataServiceController extends BaseController
// Fetch employee data for export from the database
$objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data);
// dd($objects);
$totals = 0;
foreach ($objects as $key => $value) {
@ -606,35 +608,28 @@ class EmpDataServiceController extends BaseController
// dd($import_data, $empty_emp_tpa_uh_ids);
$tpa_id = [];
$uhid = [];
foreach ($data as $key => $value) {
if (!empty($value)) {
if ($import_data['insurer_or_tpa'] == 'tpa') {
$tpa_id = $value[15] !== null ? $value[15] : '';
$uhid = $value[16] !== null ? $value[16] : '';
$data = ['tpa_id' => $tpa_id, 'uhid' => $uhid];
} else if ($import_data['insurer_or_tpa'] == 'insurer') {
$tpa_id = $value[15] !== null ? $value[15] : '';
$uhid = $value[16] !== null ? $value[16] : '';
$data = ['tpa_id' => $tpa_id, 'uhid' => $uhid];
}
foreach ($empty_emp_tpa_uh_ids as $id) {
$this->employeePolicyModel->where('id', $id)->set($data)->update();
}
} else {
return 0;
}
$tpa_id[] = $value[15];
$uhid[] = $value[16];
}
foreach ($empty_emp_tpa_uh_ids as $key => $id) {
$dataToUpdateTPAID = ['tpa_id' => $tpa_id[$key]];
$dataToUpdateUHID = ['uhid' => $uhid[$key]];
$this->employeePolicyModel->where('id', $id)
->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")')
->set($dataToUpdateTPAID)->update();
$this->employeePolicyModel->where('id', $id)
->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")')
->set($dataToUpdateUHID)->update();
}
if($import_data['insurer_or_tpa'] == 'tpa'){
@ -1262,7 +1257,7 @@ class EmpDataServiceController extends BaseController
$description = 'The following amount of Rs. ' . $amount->total_sum . '/- has been debited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
$data = [
'amount' => $amount->total_sum,
'amount' => $amount->total_sum ?? 0,
'sub_type_id' => 4,
'client_id' => $arrayData['client_id'],
'insurer_id' => $insurer_id['insurer_id'],

View File

@ -351,8 +351,14 @@ class EmployeeController extends AdminController
$return = $empDataServiceController->generateExcelForAdditionandInception($batch_data);
if(!$return){
session()->setFlashdata('error', 'No data found about this action');
return redirect()->to(base_url('employee/upload'));
if($insurer_or_tpa == 'tpa'){
session()->setFlashdata('error', "No data was found for this action. The TPA ID has already been updated.");
return redirect()->to(base_url('employee/upload'));
}else if($insurer_or_tpa == 'insurer'){
session()->setFlashdata('error', "No data was found for this action. The UHID has already been updated.");
return redirect()->to(base_url('employee/upload'));
}
} else{
$this->myLogger->logme('error','Successfully exported Excel file in {data}.', ['data' => $event_type]);
}

View File

@ -170,9 +170,10 @@ class EmployeeRestController extends AdminController
public function addEmployeeAndDependence()
{
// try {
try {
$data = $this->request->getJSON();
if ($data) {
$Count = 0;
@ -197,10 +198,6 @@ class EmployeeRestController extends AdminController
$employee = $this->employeeModel->insert($item);
if ($employee) {
if(!isset($item->is_addon_value))
{
$this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id);
}
$Count++;
}
@ -212,8 +209,14 @@ class EmployeeRestController extends AdminController
if(!isset($data[0]->is_addon_value))
{
$this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code);
$this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id);
}else{
$this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si);
}
$this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code);
$result = [];
return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
@ -222,18 +225,21 @@ class EmployeeRestController extends AdminController
return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404);
}
}
// } catch (\Exception $e) {
// return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
// }
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
}
}
public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id)
public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id,$basic_cover_si = null)
{
if($basic_cover_si == null)
{
$client_policy = $this->clientPolicyModel->where('id', $client_policy_id)->where('client_id', $client_id)->first();
$policy_terms = json_decode($client_policy['policy_terms']);
$basic_cover_si = $policy_terms->sum_insured;
}
$checkDataExist = $this->employeePolicyModel->where('employee_id',$employee_id)->where('client_policy_id',$client_policy_id)->first();
@ -378,6 +384,83 @@ class EmployeeRestController extends AdminController
}
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
}
}
public function exportDataByClientPolicyId()
{
try {
$empData = $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0);
if(count($empData))
{
// Define headers and map database fields to Excel fields
$headers = [
'Employee Code' => 'emp_code',
'Name' => 'name',
'Relationship' => 'relationship',
'DOB' => 'dob',
'Gender' => 'gender',
'Mobile' => 'mobile',
'Email' => 'email_corporate',
'SI' => 'basic_cover_si',
'Premium' => 'rata_premimum',
'Policy Name' => 'policy_name',
'Insurer Branch Name' => 'insurer_branch_name',
'TPA Name' => 'tpa_name',
'Status' => 'emp_status'
];
// Create a new Spreadsheet object
$spreadsheet = new Spreadsheet();
// Get the active sheet
$sheet = $spreadsheet->getActiveSheet();
// Add headers
$column = 'A';
foreach ($headers as $header => $dbField) {
$sheet->setCellValue($column . '1', $header);
$column++;
}
// Add data
$row = 2;
foreach ($empData as $employee) {
$column = 'A';
foreach ($headers as $dbField) {
$sheet->setCellValue($column . $row, $employee[$dbField]);
$column++;
}
$row++;
}
// Set the header for download
$filename = $empData[0]['policy_name'].'-Enrollment.xlsx';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
// Save the Excel file to output
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');
exit;
return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
}else{
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
}
} catch (\Exception $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
}
@ -989,6 +1072,7 @@ public function getEmployeePolicy()
// Map family floaters that already exist in the employee table
$familyFloates = $array->Policy_Terms->family_floaters;
// Generate Notes string based on familyFloates terms
$array->notes = $this->FloterNotesConvertion($familyFloates);
// Convert familyFloaters terms data to plain array
@ -1059,9 +1143,9 @@ public function getEmployeePolicy()
}
$result[] = $array;
// $result[] = $array;
}
return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);
}else{
@ -1115,6 +1199,8 @@ public function FloterNotesConvertion($array){
$string = ucwords($string);
$result .= ' + '.$string;
}else if($value != 0 && $key ==='self') {
}else if($value != 0 && $key ==='childrens') {
if($value > 1){ $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child'; }
}else{
$string = str_replace('-', ' ', $key);
$string = ucwords($string);
@ -1122,7 +1208,7 @@ public function FloterNotesConvertion($array){
}
}
}
return $result;
}
@ -1323,7 +1409,7 @@ public function getAddOnPolicy()
}
// return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200);
return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);
}else{
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
@ -1336,19 +1422,26 @@ public function getAddOnPolicy()
public function iAgreeForAddOn()
{
$emp_code = $this->request->getGet('emp_code');
$client_policy_id = $this->request->getGet('client_policy_id');
$client_id = $this->request->getGet('client_id');
$emp_code = $this->request->getPost('emp_code');
$postData = json_decode($this->request->getBody(), true);
$client_policy_id = $postData['client_policy_id'];
$this->employeeModel->where('emp_code', $emp_code )
->where('is_active', 1 )
->set(array('emp_status'=>'Enrolled'))
->set(array('emp_status'=>'enrolled'))
->update();
$this->employeePolicyModel->where('client_id', $client_id )
->where('client_policy_id', $client_policy_id )
->where('is_active', 1 )
->set(array('status'=>'Enrolled'))
->update();
if (!is_null($client_policy_id) && is_array($client_policy_id))
{
foreach ($client_policy_id as $key => $value)
{
$this->employeePolicyModel->where('client_policy_id', $value )
->where('is_active', 1 )
->set(array('status'=>'enrolled'))
->update();
}
}
return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200);
}
@ -1411,4 +1504,69 @@ public function calculatePremium($clientPolicyId = null , $empCode = null, $defa
}
public function getCashDepositData()
{
$ClientPolicyData = $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name')
->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
->where('client_policy.client_id', $this->request->getGet('client_id') )
->groupBy('client_policy.insurer_id')
->findAll();
$result = [];
foreach ($ClientPolicyData as $key => $value) {
$data['clientId'] = $value['clientId'];
$data['insurerId'] = $value['insurerId'];
$data['insurerName'] = $value['insurer_name'];
$data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']);
$data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0;
$data['policyDetails'] = [];
$ClientPolicyData =$this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon')
->join('policies', 'client_policy.policy_id = policies.id', 'left')
->where('client_policy.insurer_id', $value['insurerId'] )
->where('client_policy.client_id', $this->request->getGet('client_id') )
->findAll();
foreach ($ClientPolicyData as $key => $value)
{
$getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']);
if($value['is_addon'] == "2"){ $value['type'] = 'SI TopUp'; }else if($value['is_addon'] == "3"){ $value['type'] = 'Dependent AddOn'; }else{ $value['type'] = $getSlabAndGridData['grid_master']['policy_type']; }
$employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0);
$enrolledCount = 0;
$draftCount = 0;
if(count($employeeDetails))
{
foreach ($employeeDetails as $item) {
if ($item['emp_status'] === 'enrolled') {
$enrolledCount++;
} elseif ($item['emp_status'] === 'draft') {
$draftCount++;
}
}
}
$value['totalMembersCount'] = count($employeeDetails);
$value['membersCountOfEnrolled'] = $enrolledCount;
$value['membersCountOfDraft'] = $draftCount;
array_push($data['policyDetails'],$value);
}
array_push($result,$data);
}
if($result)
{
return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 404),'data' => $result ], 200);
}else{
return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200);
}
}
}

View File

@ -112,6 +112,10 @@ if (! function_exists('transform_objects_to_array_for_inception')) {
// Iterate through each object
foreach ($objects as $obj) {
$TPAID = isset($obj->tpa_id) && $obj->tpa_id !== '' ? $obj->tpa_id : '';
$UHID = isset($obj->uhid) && $obj->uhid !== '' ? $obj->uhid : '';
// Extract all values for the object
$rowData = [
$serialNumber++, // Serial Number

View File

@ -185,6 +185,7 @@ class ClientPolicyModel extends Model
->where('cash_deposit.client_id', $clientId)
->where('cash_deposit.insurer_id', $insurerId) // Add this line to filter by insurer_id
->orderBy('cash_deposit.id', 'DESC')
->get()
->getResult();
}

View File

@ -106,6 +106,7 @@ class EmployeePolicyModel extends Model
{
$client_policy_id = $ref_data['client_policy_id'];
$insurer_or_tpa = $ref_data['insurer_or_tpa'];
$event = $ref_data['event_type'];
if($insurer_or_tpa == 'tpa'){
@ -129,6 +130,8 @@ class EmployeePolicyModel extends Model
'Has Define' as emp_type,
employee_polices.id as primaryKey,
employee_polices.tpa_id,
employee_polices.uhid,
employee_polices.pre_existing_alignments,
employee_polices.basic_cover_si,
employee_polices.date_coverage,
@ -150,13 +153,11 @@ class EmployeePolicyModel extends Model
batch_files.batch_code as bf
FROM batch_files
LEFT JOIN batch_list ON batch_files.batch_code = batch_list.batch_code
WHERE batch_files.event_type = 'inception'
WHERE batch_files.event_type = '{$event}'
AND batch_files.actions = 'export'
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
) as batch_data ON employee_polices.id = batch_data.emp_policy_id
WHERE batch_data.bf IS NULL
AND batch_data.bl IS NULL
AND employee_polices.client_policy_id = '{$client_policy_id}'
WHERE employee_polices.client_policy_id = '{$client_policy_id}'
AND (employee_polices.{$id} IS NULL OR employee_polices.{$id} = '')
AND employee_polices.is_active = 1";

View File

@ -711,7 +711,7 @@ $('body').on('click', '.btnPolicyModel', function() {
$('#nameOfThePolicy').html(' - ' + res.policy_name);
$('#grid_emp_count').val(res.count);
if (res.count == false) {
if (res.count > 0) {
console.log('count -- 2', res.count);
$("#btnGridSubmit_2").hide();
} else {