FEATURE_newApi exportDataByClientPolicyId and getCashDepositData : GWM

This commit is contained in:
bitbucket 2024-04-22 16:02:46 +05:30
parent e1e852b473
commit 37c1102181
3 changed files with 110 additions and 50 deletions

View File

@ -246,6 +246,7 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi
$routes->post("/calculatePremium", "EmployeeRestController::calculatePremium");
$routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
$routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile");
@ -263,6 +264,9 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
$routes->get("getClientDetails", "EmployeeRestController::getClientDetails");
$routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy");
$routes->get("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn");
$routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId");
$routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData");
});
$routes->post("sendEmail", "EmployeeRestController::send_email");

View File

@ -384,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);
}
@ -1353,67 +1430,45 @@ public function iAgreeForAddOn()
->where('is_active', 1 )
->set(array('emp_status'=>'enrolled'))
->update();
$this->employeePolicyModel->where('client_policy_id', $client_policy_id )
->where('is_active', 1 )
->set(array('status'=>'enrolled'))
->update();
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);
}
//Post method - which receives client_policy id and empcode of the family.
//Pull records againest emp code and calculate premium
// retun array
public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null)//family level
{
helper('excel_util_helper');
$client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId;
$emp_code = $this->request->getVar('emp_code') ?? $empCode;
$default_si = $this->request->getVar('si') ?? $default_si;// si amt which choosed in add on policy
// dd($client_policy_id);
public function getCashDepositData()
{
$client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id'];
// get policy and rack details
$policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id);
$policy_type = $policy_terms[0]->is_addon;
$base_policy = $policy_terms[0]->base_policy;
$policy_terms = (array) $policy_terms[0];// convert obj to array
$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 = [];
//get policy slab rates
$slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id);
// print_r($slab_details);die();
foreach ($ClientPolicyData as $key => $value) {
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']);
if(!count($existing_famility_details) && $policy_type == 2)//top up addon only
{
//get basepolicy id then pull emplist from base policy if only current policy is DA addon policy and emplist is zero
// echo 'inside';
$client_policy_id = $base_policy;
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']);
$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;
array_push($result,$data);
}
$file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception'];
// dd($this->employeeModel->getLastQuery());
// print_r($existing_famility_details);die();
$employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db');
// dd($employee_data_group_by_family);
foreach ($employee_data_group_by_family as $emp_id => $family)
if($result)
{
$transformed_famility_details = transform_db_data_to_excel($family);
$data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
}
if($clientPolicyId != null && $empCode != null)
{
return $employee_data_group_by_family;
return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 404),'data' => $result ], 200);
}else{
// dd ($employee_data_group_by_family);
return $this->respond(['status' => 'success','code' => (count($employee_data_group_by_family) ? 200 : 404),'data' => [$employee_data_group_by_family] ], 200);
return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200);
}
}

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();
}