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

This commit is contained in:
aadhavan valli 2024-06-04 13:47:22 +05:30
commit 12b6afd446
19 changed files with 3206 additions and 1199 deletions

View File

@ -1,59 +1,11 @@
# CodeIgniter 4 Framework # CodeIgniter 4 Framework
## What is CodeIgniter? ## Unit Testing
CodeIgniter is a PHP full-stack web framework that is light, fast, flexible and secure. From command propmt run the following cmds
More information can be found at the [official site](https://codeigniter.com).
This repository holds the distributable version of the framework. `php vendor/bin/phpunit tests\unit\GridType11PremiumCalculationTest.php`
It has been built from the
[development repository](https://github.com/codeigniter4/CodeIgniter4).
More information about the plans for version 4 can be found in [CodeIgniter 4](https://forum.codeigniter.com/forumdisplay.php?fid=28) on the forums. Run speeific method
The user guide corresponding to the latest version of the framework can be found `>php vendor/bin/phpunit tests\unit\PremiumCalculationTest.php --filter testPremiumCalculationWithPrimaryRackRateAndAdditionalRackRate`
[here](https://codeigniter4.github.io/userguide/).
## Important Change with index.php
`index.php` is no longer in the root of the project! It has been moved inside the *public* folder,
for better security and separation of components.
This means that you should configure your web server to "point" to your project's *public* folder, and
not to the project root. A better practice would be to configure a virtual host to point there. A poor practice would be to point your web server to the project root and expect to enter *public/...*, as the rest of your logic and the
framework are exposed.
**Please** read the user guide for a better explanation of how CI4 works!
## Repository Management
We use GitHub issues, in our main repository, to track **BUGS** and to track approved **DEVELOPMENT** work packages.
We use our [forum](http://forum.codeigniter.com) to provide SUPPORT and to discuss
FEATURE REQUESTS.
This repository is a "distribution" one, built by our release preparation script.
Problems with it can be raised on our forum, or as issues in the main repository.
## Contributing
We welcome contributions from the community.
Please read the [*Contributing to CodeIgniter*](https://github.com/codeigniter4/CodeIgniter4/blob/develop/CONTRIBUTING.md) section in the development repository.
## Server Requirements
PHP version 7.4 or higher is required, with the following extensions installed:
- [intl](http://php.net/manual/en/intl.requirements.php)
- [mbstring](http://php.net/manual/en/mbstring.installation.php)
> **Warning**
> The end of life date for PHP 7.4 was November 28, 2022. If you are
> still using PHP 7.4, you should upgrade immediately. The end of life date
> for PHP 8.0 will be November 26, 2023.
Additionally, make sure that the following extensions are enabled in your PHP:
- json (enabled by default - don't turn it off)
- [mysqlnd](http://php.net/manual/en/mysqlnd.install.php) if you plan to use MySQL
- [libcurl](http://php.net/manual/en/curl.requirements.php) if you plan to use the HTTP\CURLRequest library

View File

@ -586,11 +586,11 @@ class ClientController extends AdminController
$this->myLogger->logme('error','Client policy CREATE function called'); $this->myLogger->logme('error','Client policy CREATE function called');
$policy_id = $this->request->getPost('policy_id'); $policy_type_id = $this->request->getPost('policy_type_id');
$client_branch_id = $this->request->getPost('client_branch_id'); $client_branch_id = $this->request->getPost('client_branch_id');
$policyCount = $this->clientPolicyModel $policyCount = $this->clientPolicyModel
->where('policy_id', $policy_id) ->where('policy_type_id', $policy_type_id)
->where('client_branch_id', $client_branch_id) ->where('client_branch_id', $client_branch_id)
->countAllResults(); ->countAllResults();
@ -816,7 +816,6 @@ class ClientController extends AdminController
$jsonDataForRelation = json_encode($relation_data); $jsonDataForRelation = json_encode($relation_data);
// if($policy_grid_id == 10 || $policy_grid_id == 11){ // if($policy_grid_id == 10 || $policy_grid_id == 11){
// $premium_type = 1; // $premium_type = 1;
// }else{ // }else{

File diff suppressed because it is too large Load Diff

View File

@ -180,16 +180,31 @@ class EmployeeController extends AdminController
'emplist' => [ 'emplist' => [
'uploaded[emplist]', 'uploaded[emplist]',
'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]', 'mime_in[emplist,application/vnd.ms-excel,application/vnd,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.oasis.opendocument.spreadsheet]',
'max_size[emplist,8192]', 'max_size[emplist,16384]',
], ],
]); ]);
if ($validated) { if ($validated)
{
$avatar = $this->request->getFile('emplist'); $avatar = $this->request->getFile('emplist');
if (!$avatar) {
$this->myLogger->logme("error", 'File not found');
return $this->respond(['dataStatus' => false, 'code' => 400, 'message' => 'File not found'], 400);
}
$is_moved = $avatar->move(WRITEPATH . 'uploads/excel/'); $is_moved = $avatar->move(WRITEPATH . 'uploads/excel/');
if ($is_moved) {
$filename = $avatar->getName(); $filename = $avatar->getName();
// Handle successful upload, e.g., log success or further processing
$this->myLogger->logme("error", 'File move successful');
} else { } else {
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'invalid file'], 200); $this->myLogger->logme("error", 'File move failed');
return $this->respond(['dataStatus' => false, 'code' => 500, 'message' => 'File move failed'], 500);
}
} else {
$this->myLogger->logme("error", 'Upload failed Invalid file');
return $this->respond(['dataStatus' => false, 'code' => 404, 'message' => 'Invalid file'], 404);
} }
//process post variable entry in file table //process post variable entry in file table
@ -358,7 +373,7 @@ class EmployeeController extends AdminController
public function importExport() public function importExport()
{ {
$this->myLogger->logme('error', 'importExport function called'); $this->myLogger->logme('error', 'Import Export -- Function called');
$empDataServiceController = new EmpDataServiceController(); $empDataServiceController = new EmpDataServiceController();
$client_id = $this->request->getPost('client_id'); $client_id = $this->request->getPost('client_id');
@ -386,7 +401,6 @@ class EmployeeController extends AdminController
'file_name' => $file_name, 'file_name' => $file_name,
]; ];
// $event_type = 'si_enhancement';
if ($actions == 'export') { if ($actions == 'export') {
@ -409,7 +423,6 @@ class EmployeeController extends AdminController
session()->setFlashdata('error', "No data was found for this action. The UHID has already been updated."); session()->setFlashdata('error', "No data was found for this action. The UHID has already been updated.");
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} }
} else { } else {
$this->myLogger->logme('error', 'Successfully exported Excel file in {data}.', ['data' => $event_type]); $this->myLogger->logme('error', 'Successfully exported Excel file in {data}.', ['data' => $event_type]);
} }
@ -425,6 +438,13 @@ class EmployeeController extends AdminController
} else if ($event_type == 'si_enhancement') { } else if ($event_type == 'si_enhancement') {
$return = $empDataServiceController->generateExcelForSIEnhancement($batch_data); $return = $empDataServiceController->generateExcelForSIEnhancement($batch_data);
if ($return == 0) {
session()->setFlashdata('error', "Insufficient deposit amount.");
return redirect()->to(base_url('employee/upload'));
}
if (!$return) { if (!$return) {
session()->setFlashdata('error', 'No data found about this action'); session()->setFlashdata('error', 'No data found about this action');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
@ -444,24 +464,20 @@ class EmployeeController extends AdminController
} else if ($actions == 'import') { } else if ($actions == 'import') {
$batch_data['file'] = $this->request->getFile('import_file_data'); $batch_data['file'] = $this->request->getFile('import_file_data');
if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition') {
$file = $this->request->getFile('import_file_data'); $file = $this->request->getFile('import_file_data');
$is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
$filename = $file->getName(); $filename = $file->getName();
$this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]); $this->myLogger->logme('error', 'Inception Import file name : {data}', ['data' => $filename]);
$random_number_count = 4; $random_number_count = 4;
$batch_data['batch_code'] = generate_random_string($random_number_count); $batch_data['batch_code'] = generate_random_string($random_number_count);
$batch_data['created_by'] = get_session_userid(); $batch_data['created_by'] = get_session_userid();
$batch_data['status'] = 'pending'; $batch_data['status'] = 'pending';
$batch_data['file_name'] = $filename; $batch_data['file_name'] = $filename;
if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition') {
$file_id = $this->batchFileModel->insert($batch_data); $file_id = $this->batchFileModel->insert($batch_data);
$job_details = new Jobs(); $job_details = new Jobs();
@ -472,73 +488,66 @@ class EmployeeController extends AdminController
// $return = $empDataServiceController->importInceptionFileValidation(['file_id' => $file_id]); // $return = $empDataServiceController->importInceptionFileValidation(['file_id' => $file_id]);
if ($return == 1) { if ($return == 1) {
session()->setFlashdata('success', 'Data updated successfully. File is being validated.'); session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} else if ($return == 2) { } else {
session()->setFlashdata('error', 'The TPA ID column is either partially or entirely empty.'); session()->setFlashdata($return['status'], $return['message']);
return redirect()->to(base_url('employee/upload'));
} else if ($return == 0) {
session()->setFlashdata('error', 'Please upload the correct file.');
return redirect()->to(base_url('employee/upload'));
} else if ($return == 3) {
session()->setFlashdata('error', 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file');
return redirect()->to(base_url('employee/upload'));
} else if ($return == 4) {
session()->setFlashdata('error', 'The UHID column is either partially or entirely empty.');
return redirect()->to(base_url('employee/upload'));
} else if ($return == 5) {
session()->setFlashdata('error', 'The list of employees provided has already been updated with the UHID, or this is not the correct file');
return redirect()->to(base_url('employee/upload'));
} else if ($return == 6) {
session()->setFlashdata('error', 'The Excel record count exceeds the DB record count.');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} }
} else if ($event_type == 'correction') { } else if ($event_type == 'correction') {
$return = $empDataServiceController->importExcelDataForCorrection($batch_data); $file_id = $this->batchFileModel->insert($batch_data);
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'importCorrectionValidation', 'payload' => ['file_id' => $file_id]]);
$return = 1;
// $return = $empDataServiceController->importCorrectionValidation(['file_id' => $file_id]);
if ($return == 1) { if ($return == 1) {
session()->setFlashdata('success', 'Data updated successfully'); session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} else if ($return == 2) { } else {
session()->setFlashdata('error', 'The Endorsement ID columns are empty.'); session()->setFlashdata('error', $return);
return redirect()->to(base_url('employee/upload'));
} else if ($return == 0) {
session()->setFlashdata('error', 'Please upload the correct file');
return redirect()->to(base_url('employee/upload'));
} else if ($return == 3) {
session()->setFlashdata('error', 'File already uploaded');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} }
} else if ($event_type == 'si_enhancement') { } else if ($event_type == 'si_enhancement') {
$return = $empDataServiceController->importExcelDataForSIEnhancement($batch_data);
$file_id = $this->batchFileModel->insert($batch_data);
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'importSIEnhancementValidation', 'payload' => ['file_id' => $file_id]]);
$return = 1;
// $return = $empDataServiceController->importSIEnhancementValidation(['file_id' => $file_id]);
if ($return == 1) { if ($return == 1) {
session()->setFlashdata('success', 'Data updated successfully'); session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} else if ($return == 2) { } else {
session()->setFlashdata('error', 'The Endorsement ID columns are empty.'); session()->setFlashdata('error', $return);
return redirect()->to(base_url('employee/upload'));
} else if ($return == 0) {
session()->setFlashdata('error', 'Please upload the correct file');
return redirect()->to(base_url('employee/upload'));
} else if ($return == 3) {
session()->setFlashdata('error', 'File already uploaded');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} }
} else if ($event_type == 'deletion') { } else if ($event_type == 'deletion') {
$return = $empDataServiceController->importExcelDataForDeletion($batch_data); $file_id = $this->batchFileModel->insert($batch_data);
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'importDeletionValidation', 'payload' => ['file_id' => $file_id]]);
$return = 1;
// $return = $empDataServiceController->importDeletionValidation(['file_id' => $file_id]);
if ($return == 1) { if ($return == 1) {
session()->setFlashdata('success', 'Data updated successfully'); session()->setFlashdata('success', 'File Uploaded Successfully File is being validated.');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} else if ($return == 2) { } else {
session()->setFlashdata('error', 'The Endorsement ID columns are empty.'); session()->setFlashdata('error', $return);
return redirect()->to(base_url('employee/upload'));
} else if ($return == 0) {
session()->setFlashdata('error', 'Please upload the correct file');
return redirect()->to(base_url('employee/upload'));
} else if ($return == 3) {
session()->setFlashdata('error', 'File already uploaded');
return redirect()->to(base_url('employee/upload')); return redirect()->to(base_url('employee/upload'));
} }
} }
@ -707,6 +716,9 @@ class EmployeeController extends AdminController
public function viewUploadedEmployeeList() public function viewUploadedEmployeeList()
{ {
$empDataServiceController = new EmpDataServiceController();
$file_id = $this->request->getGet('file_id'); $file_id = $this->request->getGet('file_id');
// $emp_data['employees'] = $this->employeePolicyModel->getViewEmpSuccessList($file_id); // $emp_data['employees'] = $this->employeePolicyModel->getViewEmpSuccessList($file_id);
// $html = view('view_file_upload_emp_list', $emp_data); // $html = view('view_file_upload_emp_list', $emp_data);
@ -718,20 +730,21 @@ class EmployeeController extends AdminController
->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left') ->join('clients c', 'files.client_id = c.id and files.client_id = cp.client_id', 'left')
->where('files.id', $file_id)->first(); ->where('files.id', $file_id)->first();
// dd($file_name);
try { try {
$filePath = WRITEPATH . '/uploads/excel/' . $file_name['file_name']; $filePath = WRITEPATH . '/uploads/excel/' . $file_name['file_name'];
if (file_exists($filePath)) { if (file_exists($filePath)) {
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath);
$sheet = $spreadsheet->getActiveSheet();
$highestRowAndColumn = $sheet->getHighestRowAndColumn(); $excel_data = $empDataServiceController->readExcelFileToArray($filePath);
$excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
// dd($excel_data);
$emp_data['thead'] = $excel_data[0]; $emp_data['thead'] = $excel_data[0];
unset($excel_data[0]); unset($excel_data[0]);
$emp_data['tbody'] = $excel_data; $emp_data['tbody'] = $excel_data;
$emp_data['count'] = count($excel_data);
// dd($emp_data);
$html = view('view_file_upload_emp_list', $emp_data); $html = view('view_file_upload_emp_list', $emp_data);
} else { } else {
@ -1210,6 +1223,7 @@ class EmployeeController extends AdminController
$client_id = $file['client_id']; $client_id = $file['client_id'];
$client_policy_id = $file['client_policy_id']; $client_policy_id = $file['client_policy_id'];
$insurer_or_tpa = $file['insurer_or_tpa']; $insurer_or_tpa = $file['insurer_or_tpa'];
$event_type = $file['event_type'];
$error_data = json_decode($file['error_data']); $error_data = json_decode($file['error_data']);
@ -1225,8 +1239,10 @@ class EmployeeController extends AdminController
$excel_data = $empDataServiceController->readExcelFileToArray($file_name_with_path); $excel_data = $empDataServiceController->readExcelFileToArray($file_name_with_path);
$excelErrorData['excel_header'] = $excel_data[0]; $excelErrorData['excel_header'] = $excel_data[0];
unset($excel_data[0]); unset($excel_data[0]);
array_pop($excel_data);
if($event_type == 'inception' || $event_type == 'deletion'){
array_pop($excel_data);
}
$finalArray = []; $finalArray = [];
foreach ($error_data as $key => $values) { foreach ($error_data as $key => $values) {
@ -1242,6 +1258,8 @@ class EmployeeController extends AdminController
}else{ }else{
if($event_type == 'inception'){
if ($insurer_or_tpa == 'tpa') { if ($insurer_or_tpa == 'tpa') {
$error = 'Expected value : TPA ID'; $error = 'Expected value : TPA ID';
@ -1251,6 +1269,11 @@ class EmployeeController extends AdminController
$error = 'Expected value : UHID'; $error = 'Expected value : UHID';
} }
}else{
$error = 'Expected value : ENDORSEMENT ID';
}
} }
$data = ['value' => $excel_data[$row][$column], 'error' => $error,]; $data = ['value' => $excel_data[$row][$column], 'error' => $error,];
$excel_data[$row][$column] = $data; $excel_data[$row][$column] = $data;

View File

@ -1372,7 +1372,7 @@ public function getAddOnPolicy()
if(count($clientPolicy)) if(count($clientPolicy))
{ {
$band = $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('client_branch_id',$this->request->getGet('client_branch_id'))->where('family_floater_key','self')->get()->getRow()->band; $band = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('client_branch_id',$this->request->getGet('client_branch_id'))->where('family_floater_key','self')->get()->getRow()->band;
$PolicyData = []; $PolicyData = [];
foreach ($clientPolicy as $key => $array) { foreach ($clientPolicy as $key => $array) {
$responce = []; $responce = [];

View File

@ -349,6 +349,9 @@ class EmployeeServiceController extends AdminController
unset($excel_data[0]); unset($excel_data[0]);
$relationship = $this->general_relationships; $relationship = $this->general_relationships;
if(in_array($file['action'],['inception','addition','dependent_addition']))// the below funcitons are only for I,DA,A
{
$employee_data_group_by_family = data_group_by_family($excel_data); $employee_data_group_by_family = data_group_by_family($excel_data);
$is_self_available_in_policy_terms = false; $is_self_available_in_policy_terms = false;
@ -452,7 +455,8 @@ class EmployeeServiceController extends AdminController
$result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record already exists"; $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record already exists";
} }
} }
} }// end of foreach
}// end of if current action I,DA,A
// s($result); // s($result);
// die(); // die();
@ -668,7 +672,7 @@ class EmployeeServiceController extends AdminController
// for employee policy table // for employee policy table
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]);
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]);
$this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'inactive','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]);
}; };
//iterate each row //iterate each row
foreach ($excel_data as $col_key => $row) foreach ($excel_data as $col_key => $row)
@ -679,7 +683,10 @@ class EmployeeServiceController extends AdminController
} }
// echo '<br>START- ' . $row[2]; // echo '<br>START- ' . $row[2];
$employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->where('client_branch_id',$file['client_branch_id'])->first(); $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->where('client_branch_id',$file['client_branch_id'])->first();
// $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first();
// dd($employee);
if(is_array($employee) && count($employee))
{
$existing_endorsements = $this->empEndorsementModel->where('actions','d') $existing_endorsements = $this->empEndorsementModel->where('actions','d')
->where('table_name','employees') ->where('table_name','employees')
->where('endorsement_id is null') ->where('endorsement_id is null')
@ -720,6 +727,12 @@ class EmployeeServiceController extends AdminController
} }
} }
}
else
{
$this->myLogger->logme("error",'{emp_code} - {name} not found',['emp_code' => $row[1],'name' => $row[2]]);
}
// print_r($endorsement_data); // print_r($endorsement_data);
@ -848,9 +861,9 @@ class EmployeeServiceController extends AdminController
if($slab_value['si'] == $row[3]) if($slab_value['si'] == $row[3])
{ {
$group_key = rand(100000, 999999); $group_key = rand(100000, 999999);
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $row[3],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $row[3],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]);
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]);
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$employee_policy['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]);
break; break;
} }
} }
@ -887,8 +900,10 @@ class EmployeeServiceController extends AdminController
// Kint::dump($value); // Kint::dump($value);
// Kint::dump($policy_data); // Kint::dump($policy_data);
//start implemet of si enhancement of grid type 10,11 //start implemet of si enhancement of grid type 10,11
if(count($employee) && (($file['action'] == 'dependent_addition' && in_array($value['temp']['source'],[10,11]) && ($slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($slab_details['slab_rates'][0]['premium_type'] == 2 || $slab_details['slab_rates'][0]['premium_type'] == null)))) if(count($employee) && $file['action'] == 'dependent_addition' && $value['temp']['source'] == 'db' && ( ($slab_details['slab_rates'][0]['premium_type'] == 1 && (strtolower($value['relationship']) == 'self' || $temp['additional_rack_rate_acting_self'])) || ($slab_details['slab_rates'][0]['premium_type'] == 2 || $slab_details['slab_rates'][0]['premium_type'] == null)))
{ {
$log_message = 'Employee record from DB,Checking SI for - '.$employee[0]['name'].'('.$employee[0]['emp_code'].')';
$this->myLogger->logme('error',$log_message);
$res = $this->employeesSIEnhanceProcessWhileOnbboard(employee:$employee[0],policy_data: $policy_data,file:$file);// where employee holds existing emp data and policy_data holds new si enhancement $res = $this->employeesSIEnhanceProcessWhileOnbboard(employee:$employee[0],policy_data: $policy_data,file:$file);// where employee holds existing emp data and policy_data holds new si enhancement
if(!$res) if(!$res)
{ {
@ -945,7 +960,19 @@ class EmployeeServiceController extends AdminController
$this->employeePolicyModel->save($policy_data); $this->employeePolicyModel->save($policy_data);
$emp_policy_id = $this->employeePolicyModel->getInsertID(); $emp_policy_id = $this->employeePolicyModel->getInsertID();
if($emp_policy_id != 0){ $log_message .= ' with PK ' . $emp_policy_id; } if($emp_policy_id != 0)//emp policy inserted
{
$log_message .= ' with PK ' . $emp_policy_id;
//make endorsement entry if action is addition OR Dependt addition
if(($file['action'] == 'dependent_addition' || $file['action'] == 'addition') && $value['temp']['source'] == 'excel')
{
$actions = ($file['action'] == 'dependent_addition' ? 'da' : ($file['action'] == 'addition' ? 'a' : NULL));
$addition_endorse_data = ['pk' => $emp_policy_id,'group_key' => rand(100000, 999999),'emp_cdoe' => $value['emp_code'],'table_name' => 'employee_polices','actions' => $actions,'field_name' => 'basic_cover_si','old_value' => NULL,'new_value' => $policy_data['basic_cover_si'],'remarks' => 'addition endorsement','file_id' => $file['id'],'created_by' => $file['created_by']];
$this->employeeEndorsementforAddtionAndDependentAddition($addition_endorse_data);
}
}
else{ $emp_policy_id = $employee_policy[0]['id']; } else{ $emp_policy_id = $employee_policy[0]['id']; }
$this->myLogger->logme('error',$log_message); $this->myLogger->logme('error',$log_message);
@ -954,6 +981,12 @@ class EmployeeServiceController extends AdminController
}// for end }// for end
}//function end }//function end
public function employeeEndorsementforAddtionAndDependentAddition($employee)
{
$this->empEndorsementModel->save($employee);
}
// $employee -> holds existing emp model obj and $policy_data holds new policy changes as array // $employee -> holds existing emp model obj and $policy_data holds new policy changes as array
public function employeesSIEnhanceProcessWhileOnbboard(array $employee,array $policy_data,array $file) public function employeesSIEnhanceProcessWhileOnbboard(array $employee,array $policy_data,array $file)
{ {
@ -964,7 +997,7 @@ class EmployeeServiceController extends AdminController
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($employee_policy['client_policy_id'],$employee['client_id']); $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($employee_policy['client_policy_id'],$employee['client_id']);
//check si has changed in normal case OR check premium only changed, still treat as SI enhancement in grid type 10 //check si has changed in normal case OR check premium only changed, still treat as SI enhancement in grid type 10
if($employee_policy['basic_cover_si'] != $policy_data['basic_cover_si'] || ($slab_details['grid_master']['ui_type'] == 10 && $policy_data['premimum'] != null && $policy_data['premimum'] != "" && $employee_policy['premimum'] != $policy_data['premimum'])) if($employee_policy['basic_cover_si'] != $policy_data['basic_cover_si'] || ($policy_data['premimum'] != null && $policy_data['premimum'] != "" && $employee_policy['premimum'] != $policy_data['premimum']))
{ {
$existing_endorsements = $this->empEndorsementModel->where('actions','si') $existing_endorsements = $this->empEndorsementModel->where('actions','si')
->where('table_name','employee_polices') ->where('table_name','employee_polices')
@ -987,6 +1020,8 @@ class EmployeeServiceController extends AdminController
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
$this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => date('Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]); $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => date('Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement via DA','group_key' => $group_key,'file_id' => $file['id']]);
$this->myLogger->logme('error',($employee['emp_code'].' - '.$employee['name'].'- ( NEW/OLD SI - '.$employee_policy['basic_cover_si'].'/'.$policy_data['basic_cover_si'].')'. '( NEW/OLD PREMIUM - '.$employee_policy['premium'].'/'.$policy_data['premimum'].') '.' - si enhancement via DA')); $this->myLogger->logme('error',($employee['emp_code'].' - '.$employee['name'].'- ( NEW/OLD SI - '.$employee_policy['basic_cover_si'].'/'.$policy_data['basic_cover_si'].')'. '( NEW/OLD PREMIUM - '.$employee_policy['premium'].'/'.$policy_data['premimum'].') '.' - si enhancement via DA'));
$log_message = 'SI enhancement done during dependent_addition - '.$employee[0]['name'].'('.$employee[0]['emp_code'].')';
$this->myLogger->logme('error',$log_message);
return true; //retun true when endorsement inserted return true; //retun true when endorsement inserted
} }
@ -1123,7 +1158,7 @@ class EmployeeServiceController extends AdminController
->join('clients', 'clients.id = files.client_id') ->join('clients', 'clients.id = files.client_id')
->join('client_policy', 'client_policy.id = files.policy_id') ->join('client_policy', 'client_policy.id = files.policy_id')
->join('policies', 'policies.id = client_policy.policy_id') ->join('policies', 'policies.id = client_policy.policy_id')
->join('client_branch', 'client_branch.id = files.client_branch_id') ->join('client_branch', 'client_branch.id = files.client_branch_id','left')
->where('files.id', $file_id) ->where('files.id', $file_id)
->first(); ->first();

View File

@ -16,10 +16,22 @@ class JobWorker extends AdminController
private static $event_class_mapping = [ private static $event_class_mapping = [
'add' => ['type' => 'HC', 'handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC', 'handler' => 'App\\Controllers\\Jobs\SubJob'], 'fancy_date_time_format' => ['type' => 'HF', 'handler' => 'fancy_date_time_format'], 'addNumber' => ['type' => 'HC', 'handler' => 'App\\Model\\HttpRequestHelper'], 'excelFileFormatValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'excelFileDataValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesOnboardPreprocess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeeDisembark' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesSIEnhanceProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesCorrectionProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'send_email' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'bulk_mail' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'insertBatchList' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'], 'add' => ['type' => 'HC', 'handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC', 'handler' => 'App\\Controllers\\Jobs\SubJob'], 'fancy_date_time_format' => ['type' => 'HF', 'handler' => 'fancy_date_time_format'], 'addNumber' => ['type' => 'HC', 'handler' => 'App\\Model\\HttpRequestHelper'], 'excelFileFormatValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'excelFileDataValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesOnboardPreprocess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeeDisembark' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesSIEnhanceProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesCorrectionProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'send_email' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'bulk_mail' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'insertBatchList' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importInceptionFileValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'], 'importInceptionFileValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importInceptionUpdateTPAandUHID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'], 'importInceptionUpdateTPAandUHID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'cashDepositCalculationForInception' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'], 'cashDepositCalculationForInception' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'sendMailForDownloadingECard' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'], 'sendMailForDownloadingECard' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importCorrectionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importCorrectionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'cashDepositCalculationForSIEnhancement' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importSIEnhancementValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importSIEnhancementUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'cashDepositCalculationForDeletion' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importDeletionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importDeletionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
]; ];
public function __construct() public function __construct()
{ {

View File

@ -1,19 +1,25 @@
<?php <?php
use App\Models\EmployeeModel; use App\Models\EmployeeModel;
use App\Models\InsurerModel;
use Kint\Kint; use Kint\Kint;
if(!function_exists('calculate_days_bw_dates')) if(!function_exists('calculate_days_bw_dates'))
{ {
function calculate_days_bw_dates(string $from_date = "", string $to_date ="") function calculate_days_bw_dates(string $from_date = "", string $to_date ="",bool $include_start_date = true)
{ {
if($to_date == ""){ $currentDateTime = new DateTime(); } if($to_date == ""){ $currentDateTime = new DateTime(); }
else{ $currentDateTime = new DateTime($to_date); } else{ $currentDateTime = new DateTime($to_date); }
if($from_date == ""){ $passedDateTime = new DateTime(); } if($from_date == ""){ $passedDateTime = new DateTime(); }
else{ $passedDateTime = new DateTime($from_date); } else{ $passedDateTime = new DateTime($from_date); }
return $interval = $currentDateTime->diff($passedDateTime); $interval = $currentDateTime->diff($passedDateTime);
if ($include_start_date) {
$interval->days += 1;
}
return $interval;
} }
} }
@ -193,10 +199,13 @@ if(!function_exists('check_si'))
if(!$is_si_found && $slab_value['si'] == $received_si) //match si amount if(!$is_si_found && $slab_value['si'] == $received_si) //match si amount
{ {
// echo 'found';
$is_si_found = true; $is_si_found = true;
} }
// check age slab // check age slab
if(in_array(strtoupper($row['current_action']), ['I','A','DA']))
{
if($row[3] != null && DateTime::createFromFormat('d-M-Y', $row[3]) !== false)// dob if($row[3] != null && DateTime::createFromFormat('d-M-Y', $row[3]) !== false)// dob
{ {
$dob = change_date_format($row[3],'d-M-Y','Y-m-d'); $dob = change_date_format($row[3],'d-M-Y','Y-m-d');
@ -219,10 +228,15 @@ if(!function_exists('check_si'))
} }
} }
}//end of check age slab
} }
}
else
{
$is_age_slab_found = true;// send true if age conditin is not applicable
}//end of check age slab
}// end of for loop
} }
if(!$is_si_found) if(!$is_si_found)
@ -405,15 +419,17 @@ if (!function_exists('name_and_empid_check_in_db'))
foreach ($family_data as $rkey => $row) foreach ($family_data as $rkey => $row)
{ {
if(($current_action == 'inception' || $current_action == 'addition') || ($current_action == 'dependent_addition' && (isset($row['temp']) && $row['temp']['source'] != 'db'))) if($current_action != 'dependent_addition' || (isset($row['temp']) && $row['temp']['source'] != 'db'))
{ {
$res = $employeeModel $res = $employeeModel
->join('client_policy cp',"employees.client_id = cp.client_id") ->join('client_policy cp',"employees.client_id = cp.client_id")
->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id") ->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id")
// ->where("cp.id",$policy_id) ->where("cp.id",$policy_id)
->where("employees.client_id",$client_id) ->where("employees.client_id",$client_id)
->where("employees.is_active",1) ->where("employees.is_active",1)
->where("employees.emp_status",'active')
->where("ep.is_active",1) ->where("ep.is_active",1)
->where("ep.status",'active')
// ->where("ep.client_id",$client_id) // ->where("ep.client_id",$client_id)
->where('name',$row[2])->where('emp_code',$row[1]) ->where('name',$row[2])->where('emp_code',$row[1])
->findAll(); ->findAll();
@ -594,28 +610,90 @@ if (!function_exists('calculate_premimum'))
{ {
function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr,$default_si = null) function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr,$default_si = null)
{ {
// // dd($family_data);
// dd($slab_details); $slug = \Config\Services::slug();
// grid type
// 1 = premium => si
$result = []; $result = [];
$grid_type = $slab_details['grid_master']['ui_type']; $primary_grid_type = $slab_details['grid_master']['ui_type'];
$fileArr['grid_type'] = $grid_type;
//gather detailes for additional rack info
$additional_grid_type = isset($slab_details['additional_slab_info']['grid_master']['ui_type']) ? $slab_details['additional_slab_info']['grid_master']['ui_type'] : null;
// dd(isset($slab_details['additional_slab_info']['grid_master']['ui_type']));
$policy_terms_json = ($policy_terms['policy_terms']);
$policy_terms_json = (array) json_decode($policy_terms_json);
// dd($policy_terms);
$primary_rack_rate_applicable_familiy_members = ['self'];
if(isset($policy_terms_json['family_floaters']))
{
$primary_rack_rate_applicable_familiy_members = generate_family_relationship_array((array)$policy_terms_json['family_floaters']);
}
$additional_grid_type_applicable_familiy_members = [];
if($additional_grid_type != null)
{
$additional_grid_type_applicable_familiy_members = (array)json_decode($slab_details['additional_slab_info']['slab_rates'][0]['additional_relationship']);
$additional_grid_type_applicable_familiy_members = generate_family_relationship_array($additional_grid_type_applicable_familiy_members);
}
// Kint::dump($primary_rack_rate_applicable_familiy_members);
// Kint::dump($additional_grid_type_applicable_familiy_members);
//remove common family members in primary array
$primary_rack_rate_applicable_familiy_members = array_diff($primary_rack_rate_applicable_familiy_members,$additional_grid_type_applicable_familiy_members);
// dd($primary_rack_rate_applicable_familiy_members);
//this variable for store emp id and their band for emp band level premium calculation for all famility members (especially for grid type 9) also store max age and max count of a familiy for grid type 10,11 //this variable for store emp id and their band for emp band level premium calculation for all famility members (especially for grid type 9) also store max age and max count of a familiy for grid type 10,11
$emp_details_with_empband_max_age_max_count = []; $emp_details_with_empband_max_age_max_count = [];
//max age amoung familiy //find max age and max count of family members for both primary and additional grid type
$max_age = max(array_map(function($item) {return calculate_days_bw_dates(from_date: $item[3])->y; }, $family_data)); $max_age_and_count = (array_reduce($family_data,function($max_age,$family_member) use ($primary_rack_rate_applicable_familiy_members,$slug) {
if( in_array($slug->slugify($family_member[5]), $primary_rack_rate_applicable_familiy_members))
{
$max_age['primary_rack_rate_max_age'][] = calculate_days_bw_dates(from_date: $family_member[3])->y;
$max_age['primary_rack_rate_max_count'] = $max_age['primary_rack_rate_max_count'] + 1;
}
else
{
$max_age['additional_rack_rate_max_age'][] = calculate_days_bw_dates(from_date: $family_member[3])->y;
$max_age['additional_rack_rate_max_count'] = $max_age['additional_rack_rate_max_count'] + 1;
}
return $max_age;
}, ['primary_rack_rate_max_age' => [], 'additional_rack_rate_max_age' => [],'primary_rack_rate_max_count' => 0,'additional_rack_rate_max_count' => 0]));
$get_max_age_or_count = function($relationship,$flag) use ($slug, $primary_rack_rate_applicable_familiy_members, $max_age_and_count)
{
if(in_array($slug->slugify($relationship),$primary_rack_rate_applicable_familiy_members))
{
return $flag == 'age' ? max($max_age_and_count['primary_rack_rate_max_age']) : $max_age_and_count['primary_rack_rate_max_count'];
}
return $flag == 'age' ? max($max_age_and_count['additional_rack_rate_max_age']) : $max_age_and_count['additional_rack_rate_max_count'];
};
$get_current_member_grid_type = function($relationship) use ($slug, $primary_rack_rate_applicable_familiy_members,$primary_grid_type,$additional_grid_type)
{
if(in_array($slug->slugify($relationship),$primary_rack_rate_applicable_familiy_members))
{
return ['type' => 'primary','grid_id' => $primary_grid_type];
}
return ['type' => 'additional','grid_id' => $additional_grid_type];
};
// Kint::dump($max_age_and_count);dd();
foreach($family_data as $fkey => $member) foreach($family_data as $fkey => $member)
{ {
//get grid type either primary or additional based on current member relationship available in primary_rack_rate_applicable_familiy_members or not. if yes then primaty grid type else additional grid type
$current_grid_info = $get_current_member_grid_type($member[5]);
$fileArr['grid_info'] = $current_grid_info;
//transform as db row column //transform as db row column
$transformed_familiy_member_data = transform_excel_data_to_db($member,$fileArr); $transformed_familiy_member_data = transform_excel_data_to_db($member,$fileArr);
// dd($transformed_familiy_member_data); // dd($transformed_familiy_member_data);
//store emp id and emp band and attach it to their familiy members where band is always empty //store emp id and emp band and attach it to their familiy members where band is always empty
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] : NULL; $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] : NULL;
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : NULL; $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : NULL;
//get emp band and si from self and make it available for whole family
if(strtolower($transformed_familiy_member_data['relationship']) == 'self') if(strtolower($transformed_familiy_member_data['relationship']) == 'self')
{ {
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = $transformed_familiy_member_data['band']; $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = $transformed_familiy_member_data['band'];
@ -623,9 +701,17 @@ if (!function_exists('calculate_premimum'))
} }
//end of store emp id and emp band and attach it to their familiy members where band is always empty //end of store emp id and emp band and attach it to their familiy members where band is always empty
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount'] =count($family_data); $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount'] = $get_max_age_or_count($transformed_familiy_member_data['relationship'],'count');
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage'] = $max_age; $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage'] = $get_max_age_or_count($transformed_familiy_member_data['relationship'],'age');
//set additional_rack_rate_acting_self in emp_details_with_empband_max_age_max_count array
$transformed_familiy_member_data['temp']['additional_rack_rate_acting_self'] = false;
if(!isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['additional_rack_rate_acting_self']) && $current_grid_info['type'] == 'additional')
{
$transformed_familiy_member_data['temp']['additional_rack_rate_acting_self'] = true;
$emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['additional_rack_rate_acting_self'] = true;
}
//generate relationship code //generate relationship code
if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI') if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI')
@ -644,15 +730,33 @@ if (!function_exists('calculate_premimum'))
$transformed_familiy_member_data['policy_details']['basic_cover_si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : $transformed_familiy_member_data['policy_details']['basic_cover_si']; $transformed_familiy_member_data['policy_details']['basic_cover_si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : $transformed_familiy_member_data['policy_details']['basic_cover_si'];
if( $fileArr['id'] == null || $transformed_familiy_member_data['temp']['source'] == 'excel' || ($fileArr['action'] == 'dependent_addition' && in_array($grid_type,[10,11]) && $slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($transformed_familiy_member_data['relationship']) == 'self'))//if file id is null then data coming from enrollment (from DB) otherwise data coming from xcel, so calculate only data from excel (new entry) note: even data coming from excel for event dependet additon we fetch other dependts from db and calculate premium for whole family // this array hold conditions to allow calculate premium amt
{ $conditions = [
'isEmployeeSourceEnrollment' => $fileArr['id'] == null,
'isEmployeeSourceExcelFile' => $transformed_familiy_member_data['temp']['source'] == 'excel',
'isCurrentActionDependentAddition' => $fileArr['action'] == 'dependent_addition',
'isPrimaryGridType' => $transformed_familiy_member_data['temp']['grid_type'] == 'primary',
'isAdditionalGridType' => $transformed_familiy_member_data['temp']['grid_type'] == 'additional',
'isPrimaryGridPremiumTypeSingle' => $slab_details['slab_rates'][0]['premium_type'] == 1,
'isAdditionalPremiumTypeSingle' => isset($slab_details['additional_slab_info']['slab_rates'][0]['premium_type']) ? ( $slab_details['additional_slab_info']['slab_rates'][0]['premium_type'] == 1) : 0,
'isCurrentRelationshipSelf' => strtolower($transformed_familiy_member_data['relationship']) == 'self',
'isBasicCoverCalculatedToCurrentEmployee' => strtolower($transformed_familiy_member_data['policy_details']['basic_cover_si']) != null
];
// same logic for both primay and additional grid type
$primaryGridTypeCondition = $conditions['isCurrentActionDependentAddition'] && $conditions['isPrimaryGridType'] && $conditions['isPrimaryGridPremiumTypeSingle'] && $conditions['isCurrentRelationshipSelf'];
$additionalGridTypeCondition = $conditions['isCurrentActionDependentAddition'] && $conditions['isAdditionalGridType'] && $conditions['isAdditionalPremiumTypeSingle'] && $conditions['isBasicCoverCalculatedToCurrentEmployee'];
// Final combined condition
if ($conditions['isEmployeeSourceEnrollment'] || $conditions['isEmployeeSourceExcelFile'] || $primaryGridTypeCondition || $additionalGridTypeCondition) {
$transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details,$default_si); $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details,$default_si);
$result[] = $transformed_familiy_member_data; $result[] = $transformed_familiy_member_data;
} }
} }
} }
// Kint::dump($emp_details_with_empband_max_age_max_count);
return $result; return $result;
} }
} }
@ -702,7 +806,8 @@ if (!function_exists('transform_excel_data_to_db'))
$result['file_id'] = $actionArr['id']; $result['file_id'] = $actionArr['id'];
$result['client_id'] = $actionArr['client_id']; $result['client_id'] = $actionArr['client_id'];
$result['change_event'] = $memArr[15]; $result['change_event'] = $memArr[15];
$result['temp']['grid_type'] = $actionArr['grid_type']; $result['temp']['grid_type'] = $actionArr['grid_info']['type'];
$result['temp']['grid_id'] = $actionArr['grid_info']['grid_id'];
$result['temp']['action'] = isset($memArr['current_action']) ? $memArr['current_action'] : $current_column_action; $result['temp']['action'] = isset($memArr['current_action']) ? $memArr['current_action'] : $current_column_action;
$result['temp']['source'] = isset($memArr['temp']['source']) ? $memArr['temp']['source'] : 'excel'; $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_id'] = isset($memArr['temp']['emp_id']) ? $memArr['temp']['emp_id'] : null;
@ -722,11 +827,12 @@ if (!function_exists('premium_calculation_manager'))
{ {
function premium_calculation_manager($emp_data,$policy_terms,$slab_details,$default_si = null) function premium_calculation_manager($emp_data,$policy_terms,$slab_details,$default_si = null)
{ {
// Kint::dump($emp_data);
$myLogger = \Config\Services::mylogger(); $myLogger = \Config\Services::mylogger();
// grid type // grid type
// 1 = premium => si // 1 = premium => si
// dd($emp_data); // Kint::dump($emp_data);
//check if the data comes from enrollment (DB) and status is draft then fetch original data of employee from //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 //audit history table then initiate calculation with it. so this data again get updated in emp table
@ -758,14 +864,27 @@ if (!function_exists('premium_calculation_manager'))
//gird and calculation start //gird and calculation start
$slug = \Config\Services::slug(); $slug = \Config\Services::slug();
$grid_type = $slab_details['grid_master']['ui_type']; $grid_type = $emp_data['temp']['grid_id'];
$temp_slab_rates = $emp_data['temp']['grid_type'] == 'primary' ? $slab_details['slab_rates'] : $slab_details['additional_slab_info']['slab_rates'];
//if curent action is dependent addition OR addition then pull insurer master to set whether add one day from employee date of coverage
if($emp_data['temp']['action'] == 'DA' || $emp_data['temp']['action'] == 'A')
{
$insurer = new InsurerModel();
$insurer = ($insurer->find($policy_terms['insurer_id']));
if($insurer['addition_add_day'] == true)
{
$emp_data['policy_details']['date_coverage'] = (new DateTime($emp_data['policy_details']['date_coverage']))->modify('-1 day')->format('Y-m-d');
}
}
// dd($emp_data);
$is_match_found = false; $is_match_found = false;
switch ($grid_type) { switch ($grid_type) {
case "1": case "1":
//GPA - Sum Insured (SI) * Multiplier //GPA - Sum Insured (SI) * Multiplier
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
$employee_received_band = $emp_data['temp']['band']; $employee_received_band = $emp_data['temp']['band'];
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if(($slab_value['si'] == $employee_received_si) || ($slab_value['grade'] != null && $slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si)) if(($slab_value['si'] == $employee_received_si) || ($slab_value['grade'] != null && $slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si))
{ {
@ -774,7 +893,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -785,7 +904,7 @@ if (!function_exists('premium_calculation_manager'))
case "2": case "2":
//GPA - Flat Rate for all SI //GPA - Flat Rate for all SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if($slab_value['si'] == $employee_received_si) if($slab_value['si'] == $employee_received_si)
{ {
@ -794,7 +913,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -804,7 +923,7 @@ if (!function_exists('premium_calculation_manager'))
case "3": case "3":
//GMC - SI //GMC - SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if($slab_value['si'] == $employee_received_si) if($slab_value['si'] == $employee_received_si)
{ {
@ -813,7 +932,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -826,7 +945,7 @@ if (!function_exists('premium_calculation_manager'))
//GMC - Employees Age band //GMC - Employees Age band
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
// dd($employee_received_si); // dd($employee_received_si);
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age))
@ -837,7 +956,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -847,7 +966,7 @@ if (!function_exists('premium_calculation_manager'))
case "5": case "5":
//GMC - Employees Age + SI //GMC - Employees Age + SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age))
@ -857,7 +976,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -867,10 +986,10 @@ if (!function_exists('premium_calculation_manager'))
case "6": case "6":
//GMC - Employees + Dependent Age band //GMC - Employees + Dependent Age band
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{ {
// echo $emp_data['name']; // echo $emp_data['name'];
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
@ -878,7 +997,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -889,17 +1008,17 @@ if (!function_exists('premium_calculation_manager'))
case "7": case "7":
//GMC - Employees + Dependent Age + SI //GMC - Employees + Dependent Age + SI
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{ {
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
@ -911,10 +1030,10 @@ if (!function_exists('premium_calculation_manager'))
//GMC - SI as per Grade or Band //GMC - SI as per Grade or Band
$employee_received_band = $emp_data['temp']['band']; $employee_received_band = $emp_data['temp']['band'];
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{ {
// $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
@ -922,7 +1041,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -933,17 +1052,17 @@ if (!function_exists('premium_calculation_manager'))
//GMC - Flat Rate for all //GMC - Flat Rate for all
$employee_received_band = $emp_data['temp']['band']; $employee_received_band = $emp_data['temp']['band'];
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) if($slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{ {
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','');
$is_match_found = true; $is_match_found = true;
break; break;
@ -954,18 +1073,23 @@ if (!function_exists('premium_calculation_manager'))
//GMC - Maximum age of Dependents //GMC - Maximum age of Dependents
$max_age = $emp_data['temp']['maxage']; $max_age = $emp_data['temp']['maxage'];
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
// echo $emp_data['name'].'-'.$employee_received_si.'<br>';
// echo $emp_data['temp']['grid_type'].'<br>';
$emp_data['policy_details']['basic_cover_si'] = null; $emp_data['policy_details']['basic_cover_si'] = null;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
// echo $slab_value['si'].'-'.$slab_value['age_from'].'-'.$slab_value['age_to'].'-'.$max_age.'<br>';
if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) if( $slab_value['si'] == $employee_received_si &&
($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) &&
(($slab_value['premium_type'] == 1 &&
( (strtolower($emp_data['relationship']) == 'self') || ($emp_data['temp']['additional_rack_rate_acting_self']) )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) )
{ {
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si; $emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
$emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date'];
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true; $is_match_found = true;
break; break;
@ -979,10 +1103,11 @@ if (!function_exists('premium_calculation_manager'))
// echo $employee_received_band; // echo $employee_received_band;
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
$emp_data['policy_details']['basic_cover_si'] = null; $emp_data['policy_details']['basic_cover_si'] = null;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) if($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && (($slab_value['premium_type'] == 1 &&
( (strtolower($emp_data['relationship']) == 'self') || ($emp_data['temp']['additional_rack_rate_acting_self']) )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
{ {
//calculate premium based on count //calculate premium based on count
// echo $emp_data['name']; // echo $emp_data['name'];
@ -994,7 +1119,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = get_premium_for_si(slab_details: $slab_details,si_amount: $familiy_si_covered,band: $employee_received_band); $emp_data['policy_details']['premium'] = get_premium_for_si(slab_details: $slab_details,si_amount: $familiy_si_covered,band: $employee_received_band);
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true; $is_match_found = true;
break; break;
@ -1009,9 +1134,9 @@ if (!function_exists('premium_calculation_manager'))
$employee_relationship = $slug->slugify($emp_data['relationship']); $employee_relationship = $slug->slugify($emp_data['relationship']);
$employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship);
$emp_data['policy_details']['basic_cover_si'] = null; $emp_data['policy_details']['basic_cover_si'] = null;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) ) if( $slab_value['si'] == $employee_received_si && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self'] ) )) )
{ {
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si; $emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
@ -1019,7 +1144,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true; $is_match_found = true;
break; break;
@ -1034,9 +1159,9 @@ if (!function_exists('premium_calculation_manager'))
$employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship);
$emp_data['policy_details']['basic_cover_si'] = null; $emp_data['policy_details']['basic_cover_si'] = null;
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($temp_slab_rates as $skey => $slab_value)
{ {
if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self')) ) if( $slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && (strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['additional_rack_rate_acting_self']) )) )
{ {
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si; $emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
@ -1044,7 +1169,7 @@ if (!function_exists('premium_calculation_manager'))
$emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date'];
$emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days;
$emp_data['policy_details']['premium'] = $slab_value['premium']; $emp_data['policy_details']['premium'] = $slab_value['premium'];
$emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($emp_data['policy_details']['premium'],$emp_data['policy_details']['days'],calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days);
$emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''));
$is_match_found = true; $is_match_found = true;
break; break;
@ -1055,13 +1180,13 @@ if (!function_exists('premium_calculation_manager'))
default: default:
$this->myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found')); $myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found'));
} }
if(!$is_match_found) if(!$is_match_found)
{ {
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
$log_message = '[ client_policy_id : ' .$emp_data['policy_details']['client_policy_id'].' - '. $emp_data['emp_code'].' - '.$emp_data['name'] .' - '. $emp_data['policy_details']['basic_cover_si'] . ', Age : '. $age.' ]'; $log_message = '[ client_policy_id : ' .$emp_data['policy_details']['client_policy_id'].' - '. $emp_data['emp_code'].' - '.$emp_data['name'] .' - '. $emp_data['policy_details']['basic_cover_si'] . ', Age : '. $age.' ]';
if($slab_details['slab_rates'][0]['premium_type'] == 1) if($temp_slab_rates[0]['premium_type'] == 1)
{ {
$log_message .= ' - skipping, calculating only self..!'; $log_message .= ' - skipping, calculating only self..!';
//reset emp si and others policy level data if premium only for self //reset emp si and others policy level data if premium only for self
@ -1085,9 +1210,17 @@ if (!function_exists('premium_calculation_manager'))
if (!function_exists('calculate_pro_rata_premimum')) if (!function_exists('calculate_pro_rata_premimum'))
{ {
function calculate_pro_rata_premimum($premium,$days) function calculate_pro_rata_premimum($premium,$employee_policy_coverage_days,$policy_coverage_days)
{ {
return (float) number_format(($premium / 365) * $days,2,'.',''); return (float) number_format(($premium / ($policy_coverage_days) ) * $employee_policy_coverage_days,2,'.','');
}
}
if (!function_exists('no_of_days_in_current_fin_year'))
{
function no_of_days_in_current_fin_year()
{
return true;
} }
} }
@ -1226,7 +1359,7 @@ if(!function_exists('get_premium_for_si'))
{ {
foreach ($slab_details['slab_rates'] as $skey => $slab_value) foreach ($slab_details['slab_rates'] as $skey => $slab_value)
{ {
if($slab_value['si'] == $si_amount && $slab_value['grade'] == $band) if($slab_value['si'] == $si_amount && $slab_value['grade'] == $band && $slab_value['max_si'] == 0)
{ {
return $slab_value['premium']; return $slab_value['premium'];
} }
@ -1298,3 +1431,46 @@ if(!function_exists('check_dup_mobileno'))
return array('status' => true); return array('status' => true);
} }
} }
if(!function_exists('generate_family_relationship_array'))
{
function generate_family_relationship_array($family_structure_from_policy_terms) {
$family_relationships = [];
// Add self and spouse
if ($family_structure_from_policy_terms['self'] > 0) {
$family_relationships[] = 'self';
}
if ($family_structure_from_policy_terms['spouse'] > 0) {
$family_relationships[] = 'spouse';
}
// Add children
if ($family_structure_from_policy_terms['childrens'] > 0) {
$family_relationships[] = 'son';
$family_relationships[] = 'daughter';
}
// Add parents
if ($family_structure_from_policy_terms['parents'] > 0) {
$family_relationships[] = 'father';
$family_relationships[] = 'mother';
}
// Add parents-in-law
if ($family_structure_from_policy_terms['parents-in-law'] > 0) {
$family_relationships[] = 'father-in-law';
$family_relationships[] = 'mother-in-law';
}
// Add either parents or parents-in-law
if ($family_structure_from_policy_terms['either-parents-pil'] > 0) {
$family_relationships[] = 'father';
$family_relationships[] = 'mother';
$family_relationships[] = 'father-in-law';
$family_relationships[] = 'mother-in-law';
}
return $family_relationships;
}
}

View File

@ -143,7 +143,7 @@ class EmployeePolicyModel extends Model
employees.relationship AS emp_relationship, employees.relationship AS emp_relationship,
employees.relationship_code AS emp_relationship_code, employees.relationship_code AS emp_relationship_code,
TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age, TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age,
'Has Define' as emp_type, employees.emp_type as emp_type,
employee_polices.id as primaryKey, employee_polices.id as primaryKey,
employee_polices.tpa_id, employee_polices.tpa_id,
@ -175,8 +175,13 @@ class EmployeePolicyModel extends Model
) as batch_data ON employee_polices.id = batch_data.emp_policy_id ) as batch_data ON employee_polices.id = batch_data.emp_policy_id
WHERE 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.{$id} IS NULL OR employee_polices.{$id} = '')
AND employees.client_branch_id = '{$client_branch_id}'
AND employee_polices.is_active = 1 AND employee_polices.is_active = 1
AND employees.client_branch_id = '{$client_branch_id}'"; AND employee_polices.status = 'active'
AND employees.is_active = 1
AND employees.emp_status = 'active'
";
// Get the result set // Get the result set
$query = $this->db->query($sql); $query = $this->db->query($sql);
@ -209,7 +214,7 @@ class EmployeePolicyModel extends Model
employees.dob AS emp_dob, employees.dob AS emp_dob,
employees.gender AS emp_gender, employees.gender AS emp_gender,
employees.client_id AS emp_client_id, employees.client_id AS emp_client_id,
'Has Define' AS emp_type, employees.emp_type as emp_type,
employee_polices.uhid, employee_polices.uhid,
employees.relationship_code, employees.relationship_code,
batch_data.emp_policy_id, batch_data.emp_policy_id,
@ -235,12 +240,16 @@ class EmployeePolicyModel extends Model
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
) AS batch_data ON emp_endorsement.pk = batch_data.emp_policy_id ) AS batch_data ON emp_endorsement.pk = batch_data.emp_policy_id
WHERE batch_data.bf IS NULL WHERE employees.client_id = '{$client_id}'
AND batch_data.bl IS NULL
AND employees.client_id = '{$client_id}'
AND employee_polices.client_policy_id = '{$client_policy_id}' AND employee_polices.client_policy_id = '{$client_policy_id}'
AND employees.client_branch_id = '{$client_branch_id}' AND employees.client_branch_id = '{$client_branch_id}'
AND emp_endorsement.actions = 'c' AND emp_endorsement.actions = 'c'
AND employee_polices.is_active = 1
AND employee_polices.status = 'active'
AND employees.is_active = 1
AND employees.emp_status = 'active'
AND (employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '')
AND (employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '')
AND (emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')"; AND (emp_endorsement.endorsement_id IS NULL OR emp_endorsement.endorsement_id = '')";
// Execute the raw query // Execute the raw query
@ -265,13 +274,14 @@ class EmployeePolicyModel extends Model
$query = $this->db->query(" $query = $this->db->query("
SELECT SELECT
a.id as endorsement_primarykey, a.id as endorsement_primarykey,
a.group_key,
employee_polices.id AS primaryKey, employee_polices.id AS primaryKey,
employees.name AS emp_name, employees.name AS emp_name,
employees.emp_code AS emp_code, employees.emp_code AS emp_code,
employees.dob AS emp_dob, employees.dob AS emp_dob,
employees.gender AS emp_gender, employees.gender AS emp_gender,
employees.relationship_code AS emp_relationship_code, employees.relationship_code AS emp_relationship_code,
'Has Define' AS emp_type, employees.emp_type as emp_type,
employee_polices.uhid AS risk_id, employee_polices.uhid AS risk_id,
employee_polices.pre_existing_alignments, employee_polices.pre_existing_alignments,
employee_polices.policy_end_date, employee_polices.policy_end_date,
@ -283,10 +293,15 @@ class EmployeePolicyModel extends Model
sidata.new_basic_cover_si, sidata.new_basic_cover_si,
sidata.new_si_premium, sidata.new_si_premium,
sidata.date_of_coverage, sidata.date_of_coverage,
DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days, DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days,
sidata.new_si_premium - employee_polices.rata_premimum AS difference_premium, sidata.new_si_premium - employee_polices.rata_premimum AS difference_premium,
ROUND((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum, ROUND((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum,
ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst, ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst,
((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total ((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total
FROM FROM
@ -346,14 +361,16 @@ class EmployeePolicyModel extends Model
AND batch_files.actions = 'export' AND batch_files.actions = 'export'
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
) AS batch_data ON employee_polices.id = batch_data.emp_policy_id ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
WHERE
batch_data.bf IS NULL WHERE employee_polices.client_policy_id = '{$client_policy_id}'
AND batch_data.bl IS NULL AND employees.client_branch_id = '{$client_branch_id}'
AND employee_polices.client_policy_id = '{$client_policy_id}'
AND employees.client_branch_id = '{$client_policy_id}'
AND employee_polices.is_active = '1'
AND (a.endorsement_id IS NULL OR a.endorsement_id = '') AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
AND a.field_name = 'si_enhancement_date' AND a.actions = 'si'
AND employee_polices.is_active = 1
AND employee_polices.status = 'active'
AND employees.is_active = 1
AND employees.emp_status = 'active'
group by group_key
"); ");
// Get the result set // Get the result set
@ -374,13 +391,14 @@ class EmployeePolicyModel extends Model
$query = $this->db->query(" $query = $this->db->query("
SELECT DISTINCT SELECT DISTINCT
a.id as endorsement_primarykey, a.id as endorsement_primarykey,
a.group_key,
employee_polices.id as primaryKey, employee_polices.id as primaryKey,
employees.name AS emp_name, employees.name AS emp_name,
employees.emp_code AS emp_code, employees.emp_code AS emp_code,
employees.dob AS emp_dob, employees.dob AS emp_dob,
employees.gender AS emp_gender, employees.gender AS emp_gender,
employees.relationship AS emp_relationship, employees.relationship AS emp_relationship,
'Has Define' as emp_type, employees.emp_type as emp_type,
employee_polices.basic_cover_si, employee_polices.basic_cover_si,
employee_polices.uhid as risk_id, employee_polices.uhid as risk_id,
@ -404,7 +422,7 @@ class EmployeePolicyModel extends Model
FROM FROM
emp_endorsement a emp_endorsement a
LEFT JOIN LEFT JOIN
employees ON a.emp_code = employees.emp_code employees ON a.emp_code = employees.emp_code and a.pk = employees.id
LEFT JOIN LEFT JOIN
employee_polices ON employees.id = employee_polices.employee_id employee_polices ON employees.id = employee_polices.employee_id
@ -439,16 +457,20 @@ class EmployeePolicyModel extends Model
AND batch_files.actions = 'export' AND batch_files.actions = 'export'
AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}'
) AS batch_data ON employee_polices.id = batch_data.emp_policy_id ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id
WHERE
batch_data.bf IS NULL WHERE employee_polices.client_policy_id = {$client_policy_id}
AND batch_data.bl IS NULL
AND employee_polices.client_policy_id = {$client_policy_id}
AND employees.client_branch_id = {$client_branch_id} AND employees.client_branch_id = {$client_branch_id}
AND (a.endorsement_id IS NULL OR a.endorsement_id = '')
AND a.actions = 'd'
AND employee_polices.is_active = 1 AND employee_polices.is_active = 1
AND (a.endorsement_id IS NULL OR a.endorsement_id = '') AND a.field_name = 'status' AND employee_polices.status = 'active'
AND employees.is_active = 1
AND employees.emp_status = 'active'
group by group_key
"); ");
$result = $query->getResult(); $result = $query->getResult();
return $result; return $result;
} }
@ -547,34 +569,62 @@ class EmployeePolicyModel extends Model
public function fetchEmpEndorsementData($fetch_data) public function fetchEmpEndorsementData($fetch_data)
{ {
// dd($fetch_data);
$client_policy_id = $fetch_data['client_policy_id']; $client_policy_id = $fetch_data['client_policy_id'];
$client_branch_id = $fetch_data['client_branch_id'];
$emp_name = $fetch_data['emp_name']; $emp_name = $fetch_data['emp_name'];
$emp_code = $fetch_data['emp_code']; $emp_code = $fetch_data['emp_code'];
// Your raw SQL query // Your raw SQL query
$sql = " $sql = "
SELECT SELECT
ep.id, ee.id as emp_endorsement_primarykey,
MAX(CASE WHEN ee.field_name = 'date_of_exit' THEN ee.new_value END) AS date_of_exit, ep.id as emp_policy_primarykey,
MAX(CASE WHEN ee.field_name = 'reason_for_exit' THEN ee.new_value END) AS reason_for_exit, e.id as employees_primarykey,
MAX(CASE WHEN ee.field_name = 'status' THEN ee.new_value END) AS status ee.group_key,
MAX(
CASE
WHEN ee.field_name = 'date_of_exit' THEN ee.new_value
END
) AS date_of_exit,
MAX(
CASE
WHEN ee.field_name = 'reason_for_exit' THEN ee.new_value
END
) AS reason_for_exit,
MAX(
CASE
WHEN ee.field_name = 'status' THEN ee.new_value
END
) AS status
FROM FROM
emp_endorsement AS ee emp_endorsement AS ee
JOIN JOIN employee_polices AS ep ON ep.id = ee.pk
employee_polices AS ep ON ep.id = ee.pk JOIN employees AS e ON e.emp_code = ee.emp_code
WHERE WHERE
ee.emp_code = '$emp_code' ee.emp_code = '$emp_code'
AND ep.client_policy_id = $client_policy_id AND ep.client_policy_id = '$client_policy_id'
AND e.client_branch_id = '$client_branch_id'
AND ee.name = '$emp_name' AND ee.name = '$emp_name'
AND ee.field_name IN ('date_of_exit', 'reason_for_exit', 'status') AND ee.field_name IN ('date_of_exit', 'reason_for_exit', 'status')
AND ep.is_active = 1
AND ep.status = 'active'
AND e.is_active = 1
AND e.emp_status = 'active'
GROUP BY GROUP BY
ee.emp_code, ee.name, ep.id"; ee.group_key
";
// dd($sql);
// Execute the raw SQL query // Execute the raw SQL query
$query = $this->db->query($sql); $query = $this->db->query($sql);
// Fetch and return results // Fetch and return results
return $row = $query->getRowArray(); $row = $query->getRowArray();
return $row;
} }
@ -659,7 +709,7 @@ class EmployeePolicyModel extends Model
$query2->join('insurers', 'insurers.id = policies.insurer_id'); $query2->join('insurers', 'insurers.id = policies.insurer_id');
$query2->whereIn('e.actions', ['si', 'd']); $query2->whereIn('e.actions', ['si', 'd']);
$query2->where('ep.client_policy_id', $policy_id); $query2->where('ep.client_policy_id', $policy_id);
$query2->where('employees.client_id', $policy_id); $query2->where('employees.client_id', $client_id);
$query1->where('employees.client_branch_id', $branch_id); $query1->where('employees.client_branch_id', $branch_id);
if($status != 0 && !empty($status)){ if($status != 0 && !empty($status)){
@ -933,5 +983,130 @@ class EmployeePolicyModel extends Model
} }
public function bulkUpdateForEndorsement($endorsement_details)
{
// Extract IDs, endorsement_ids, and statuses
$ids = array_column($endorsement_details, 'group_key');
$endorsement_ids = array_column($endorsement_details, 'endorsement_id');
$statuses = array_column($endorsement_details, 'status');
// Escape values for SQL
$escapedIds = array_map([$this->db, 'escape'], $ids);
$escapedEndorsementIds = array_map([$this->db, 'escape'], $endorsement_ids);
$escapedStatuses = array_map([$this->db, 'escape'], $statuses);
// Construct the CASE statements
$caseEndorsementId = array_map(function ($id, $endorsement_id) {
return "WHEN group_key = $id THEN $endorsement_id";
}, $escapedIds, $escapedEndorsementIds);
$caseStatus = array_map(function ($id, $status) {
return "WHEN status = $id THEN $status";
}, $escapedIds, $escapedStatuses);
// Convert cases to a string
$caseEndorsementIdString = implode(' ', $caseEndorsementId);
$caseStatusString = implode(' ', $caseStatus);
// Convert ids to a string
$idsString = implode(', ', $escapedIds);
// Construct the SQL query
$sql = "
UPDATE emp_endorsement
SET
endorsement_id = CASE {$caseEndorsementIdString} END,
status = CASE {$caseStatusString} END
WHERE group_key IN ({$idsString})
";
// Begin a transaction
$this->db->transBegin();
try {
// Execute the query
$this->db->query($sql);
// Commit the transaction
if ($this->db->transStatus() === FALSE) {
// If something went wrong, rollback
$this->db->transRollback();
throw new \Exception('Bulk update failed.');
} else {
// Otherwise, commit
$this->db->transCommit();
}
return $this->db->getLastQuery();
} catch (\Exception $e) {
// Rollback the transaction on error
$this->db->transRollback();
throw $e;
}
}
public function bulkUpdateForCorrection($emp_details){
foreach ($emp_details as $employee) {
$id = $this->db->escape($employee['id']);
$ids[] = $id;
foreach ($employee as $field => $value) {
if ($field === 'id') continue;
$escapedValue = $this->db->escape($value);
if (!isset($caseStatements[$field])) {
$caseStatements[$field] = [];
}
$caseStatements[$field][] = "WHEN id = $id THEN $escapedValue";
}
}
// Construct the CASE strings
$caseStrings = [];
foreach ($caseStatements as $field => $cases) {
$caseStrings[] = "$field = CASE " . implode(' ', $cases) . " END";
}
// Convert ids to a string
$idsString = implode(', ', $ids);
// Construct the SQL query
$sql = "
UPDATE employees
SET " . implode(', ', $caseStrings) . "
WHERE id IN ($idsString)
";
// Begin a transaction
$this->db->transBegin();
try {
// Execute the query
$this->db->query($sql);
// Commit the transaction
if ($this->db->transStatus() === FALSE) {
// If something went wrong, rollback
$this->db->transRollback();
throw new \Exception('Bulk update failed.');
} else {
// Otherwise, commit
$this->db->transCommit();
}
return $this->db->getLastQuery();
} catch (\Exception $e) {
// Rollback the transaction on error
$this->db->transRollback();
throw $e;
}
}
} }

View File

@ -18,6 +18,7 @@ class InsurerModel extends Model
"created_by", "created_by",
"updated_by", "updated_by",
"is_active", "is_active",
"addition_add_day"
]; ];

View File

@ -39,7 +39,9 @@ class PolicesModel extends Model
{ {
$premium_slab_data = null; $premium_slab_data = null;
$additional_premium_slab_data = null;
$grid_type = null; $grid_type = null;
$additional_grid_type = null;
$policyPremium1Model = new PolicyPremium1Model(); $policyPremium1Model = new PolicyPremium1Model();
$premium_slab_data = $policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); $premium_slab_data = $policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll();
@ -48,7 +50,12 @@ class PolicesModel extends Model
{ {
// echo '2'; // echo '2';
$policyPremium2Model = new PolicyPremium2Model(); $policyPremium2Model = new PolicyPremium2Model();
$premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); $premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1,'rack_rate_type' => 0])->findAll();
//check any additional rack rate configured
$additional_premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1,'rack_rate_type' => 1])->findAll();
} }
if(isset($premium_slab_data[0]['policy_grid_id'])) if(isset($premium_slab_data[0]['policy_grid_id']))
@ -57,7 +64,14 @@ class PolicesModel extends Model
$policyGridModel = new PolicyGridModel(); $policyGridModel = new PolicyGridModel();
$grid_type = $policyGridModel->find($grid_id); $grid_type = $policyGridModel->find($grid_id);
} }
if(isset($additional_premium_slab_data[0]['policy_grid_id']))
{
$additional_grid_id = $additional_premium_slab_data[0]['policy_grid_id'];
$policyGridModel = new PolicyGridModel();
$additional_grid_type = $policyGridModel->find($additional_grid_id);
}
return ['slab_rates' => $premium_slab_data,'grid_master' => $grid_type];
return ['slab_rates' => $premium_slab_data,'grid_master' => $grid_type,'additional_slab_info' => ['slab_rates' => $additional_premium_slab_data,'grid_master' => $additional_grid_type]];
} }
} }

View File

@ -79,11 +79,11 @@
<?php } else if ($file['status'] == 'failed-1') { ?> <?php } else if ($file['status'] == 'failed-1') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip" failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" data-placement="top"
title="The list of employees provided has already been updated with the TPA ID."></a> title="<?= $file['event_type'] == 'inception' ? 'The list of employees provided has already been updated with the TPA ID.' : 'The list of employees provided has already been updated with the ENDORSEMENT ID.' ?> "></a>
<?php } else if ($file['status'] == 'failed-2') { ?> <?php } else if ($file['status'] == 'failed-2') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip" failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" data-placement="top"
title="The list of employees provided has already been updated with the UHID."></a> title="<?= $file['event_type'] == 'inception' ? 'The list of employees provided has already been updated with the UHID.' : 'The list of employees provided has already been updated with the ENDORSEMENT ID.' ?>"></a>
<?php } else if ($file['status'] == 'failed-3') { ?> <?php } else if ($file['status'] == 'failed-3') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip" failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" data-placement="top"
@ -91,6 +91,9 @@
<?php } else if ($file['status'] == 'failed-4') { ?> <?php } else if ($file['status'] == 'failed-4') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip" failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="Physical File Not Found."></a> data-placement="top" title="Physical File Not Found."></a>
<?php } else if ($file['status'] == 'failed-5') { ?>
failed <a class="fe-alert-circle" style="color: #000;" data-toggle="tooltip"
data-placement="top" title="Wrong File Uploaded"></a>
<?php } else { ?> <?php } else { ?>
<?php echo $file['status']; ?> <?php echo $file['status']; ?>
<?php } ?> <?php } ?>

View File

@ -14,7 +14,7 @@
<th>Policy</th> <th>Policy</th>
<th>TPA</th> <th>TPA</th>
<th>Date</th> <th>Date</th>
<th>Enrollment Status</th> <th>Enrollment <br> Status</th>
<th>Status</th> <th>Status</th>
<th>Action</th> <th>Action</th>
</tr> </tr>
@ -252,7 +252,7 @@
<td>${item.insurer_short} - ${item.insurer_branch_name}</td> <td>${item.insurer_short} - ${item.insurer_branch_name}</td>
<td>${item.policy_name} (${item.policy_type_name})</td> <td>${item.policy_name} (${item.policy_type_name})</td>
<td>${tpaValue}</td> <td>${tpaValue}</td>
<td>${(item.policy_start_date)} / ${(item.policy_end_date)}</td> <td>${(item.policy_start_date)} / <br> ${(item.policy_end_date)}</td>
<td style="text-align: center;">${(enrollmentStatus)}</td> <td style="text-align: center;">${(enrollmentStatus)}</td>
<td>${checkDateStatus(item.policy_end_date, 1)}</td> <td>${checkDateStatus(item.policy_end_date, 1)}</td>
<td> <td>
@ -474,7 +474,7 @@
<td>${item.insurer_short} - ${item.insurer_branch_name}</td> <td>${item.insurer_short} - ${item.insurer_branch_name}</td>
<td>${item.policy_name} (${item.policy_type_name})</td> <td>${item.policy_name} (${item.policy_type_name})</td>
<td>${tpaValue}</td> <td>${tpaValue}</td>
<td>${rearrangeDateFormat(item.policy_start_date)} - ${rearrangeDateFormat(item.policy_end_date)}</td> <td>${rearrangeDateFormat(item.policy_start_date)} / <br> ${rearrangeDateFormat(item.policy_end_date)}</td>
<td style="text-align: center;">${(enrollmentStatus)}</td> <td style="text-align: center;">${(enrollmentStatus)}</td>
<td>${checkDateStatus(item.policy_end_date, 1)}</td> <td>${checkDateStatus(item.policy_end_date, 1)}</td>
<td> <td>

View File

@ -20,6 +20,10 @@
border-radius: .25rem; border-radius: .25rem;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out; transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
} }
.table-responsive {
overflow-x: auto;
}
</style> </style>
<div class="row" id="client_list"> <div class="row" id="client_list">
@ -32,6 +36,7 @@
</div> </div>
</div> </div>
<div class="table-responsive">
<table class="table table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="0" <table class="table table-hover m-0 table-centered dt-responsive nowrap w-100" cellspacing="0"
id="tickets-table"> id="tickets-table">
<thead class="bg-light"> <thead class="bg-light">
@ -131,6 +136,7 @@
</table> </table>
</div> </div>
</div> </div>
</div>
</div><!-- end col --> </div><!-- end col -->
</div> </div>

View File

@ -20,8 +20,8 @@ option:disabled {
<div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion1"> <div id="collapseTwo" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion1">
<div class="card-body"> <div class="card-body">
<!-- <div class="text-center"> --> <!-- <div class="text-center"> -->
<form class="parsley-examples" id="emp-upload-form" <form class="parsley-examples" id="emp-upload-form" action="<?php echo base_url().'employee/upload'?>" method="post" enctype="multipart/form-data">
action="<?php echo base_url().'employee/upload'?>" method="post">
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>" <input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>"
id="csrf_token"> id="csrf_token">
@ -38,14 +38,14 @@ option:disabled {
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label>Branch</label> <br /> <label>Branch</label> <br />
<select name="branch_id" class="form-control" id="branch_id"> <select name="branch_id" class="form-control" id="branch_id" required>
<option value="0">Select</option> <option value="0">Select</option>
</select> </select>
</div> </div>
<div class="form-group col-md-4"> <div class="form-group col-md-4">
<label>Policy</label> <br /> <label>Policy</label> <br />
<select name="policy_id" class="form-control" id="policy_id" onchange="checkPolicyTermsAndRackRatesHasDefiend(event)"> <select name="policy_id" class="form-control" id="policy_id" onchange="checkPolicyTermsAndRackRatesHasDefiend(event)" required>
<option value="0">Select</option> <option value="0">Select</option>
</select> </select>
</div> </div>
@ -214,7 +214,21 @@ $(document).ready(function() {
// console.log('submit called'); // console.log('submit called');
if(!checkValues()){
toastr.warning('Form is Empty', 'warning')
return false;
}
$('#client_id').val()
$('#policy_id').val()
$('#branch_id').val()
$('#upload-action-type').val()
var isValid = $('#emp-upload-form').parsley().validate(); var isValid = $('#emp-upload-form').parsley().validate();
console.log('isValid', isValid)
if (!isValid) { if (!isValid) {
console.log('Form is Empty', 'Warning'); console.log('Form is Empty', 'Warning');
return; return;
@ -933,7 +947,7 @@ function checkPolicyTermsAndRackRatesHasDefiend(event)
setTimeout(function() { setTimeout(function() {
$('.loader').fadeOut(); $('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow'); $('.loader-mask').delay(350).fadeOut('slow');
}, 1000); }, 300);
console.log('check policy responce', response); console.log('check policy responce', response);
@ -965,7 +979,7 @@ function checkPolicyTermsAndRackRatesHasDefiend(event)
setTimeout(function() { setTimeout(function() {
$('.loader').fadeOut(); $('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow'); $('.loader-mask').delay(350).fadeOut('slow');
}, 1000); }, 300);
// toastr.error('Something went wrong! Try Later', 'Error'); // toastr.error('Something went wrong! Try Later', 'Error');
console.error('Error fetching data from checkPolicyTermsAndRackRatesHasDefiend API:', error); console.error('Error fetching data from checkPolicyTermsAndRackRatesHasDefiend API:', error);
return false; return false;
@ -976,5 +990,36 @@ function checkPolicyTermsAndRackRatesHasDefiend(event)
} }
function checkValues() {
var clientId = $('#client_id').val();
var policyId = $('#policy_id').val();
var branchId = $('#branch_id').val();
var uploadActionType = $('#upload-action-type').val();
if (!clientId || clientId == '0') {
// alert('Client ID is empty or zero');
return false;
}
if (!policyId || policyId == '0') {
// alert('Policy ID is empty or zero');
return false;
}
if (!branchId || branchId == '0') {
// alert('Branch ID is empty or zero');
return false;
}
if (!uploadActionType || uploadActionType == '0') {
// alert('Upload action type is empty or zero');
return false;
}
// If all values are valid, return true
return true;
}
//--------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------
</script> </script>

View File

@ -81,7 +81,7 @@
class="mdi mdi-dots-horizontal"></i></a> class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right"> <div class="dropdown-menu dropdown-menu-right">
<?php if($file['status'] == 'failed') { ?> <?php if($file['status'] == 'failed') { ?>
<a data-id="<?= htmlspecialchars(json_encode($file)) ?>" data-toggle="modal" <a data-id="<?= htmlspecialchars(json_encode(['client_id' => $file['client_id'], 'client_policy_id' => $file['client_policy_id'], 'action' => $file['action']])) ?>" data-toggle="modal"
data-target="#file-upload-modal" class="dropdown-item upload_button" href="#"><i data-target="#file-upload-modal" class="dropdown-item upload_button" href="#"><i
class="mdi mdi-upload mr-2 text-muted font-18 vertical-middle"></i>Re-Upload</a> class="mdi mdi-upload mr-2 text-muted font-18 vertical-middle"></i>Re-Upload</a>
<?php } ?> <?php } ?>
@ -136,7 +136,7 @@
<div class="modal-dialog modal-dialog-centered"> <div class="modal-dialog modal-dialog-centered">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">Reupload the file</h4> <h4 class="modal-title" id="myCenterModalLabel">ReUpload the file</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
@ -158,7 +158,7 @@
<script> <script>
$('body').on('click', '.view_emp_list', function() { $('body').on('click', '.view_emp_list', function() {
console.log('file_id'); console.log('file_id', 'file_id');
$('#emp_data_success').empty(); $('#emp_data_success').empty();
$('#title').html(' '); $('#title').html(' ');
var file_id = $(this).attr('data-id'); var file_id = $(this).attr('data-id');

View File

@ -902,6 +902,7 @@ $("#AdditionalGridForm").submit(function(event) {
if (!checkCheckboxes()) { if (!checkCheckboxes()) {
event.preventDefault(); event.preventDefault();
return;
} }
var isValid = $('#AdditionalGridForm').parsley().validate(); var isValid = $('#AdditionalGridForm').parsley().validate();
@ -2648,12 +2649,11 @@ function createCheckboxes(obj, additional_relationship) {
$.each(obj, function(key, value) { $.each(obj, function(key, value) {
if (value > 0 && key != 'either-parents-pil') { if (value > 0 && key != 'either-parents-pil') {
const isChecked = additional_relationship && typeof additional_relationship === 'object' && additional_relationship[key] == 1 ? 'checked' : ''; const isChecked = additional_relationship && typeof additional_relationship === 'object' && additional_relationship[key] == 1 ? 'checked' : '';
key = formatString(key);
console.log('isChecked', isChecked); console.log('isChecked', isChecked);
html += ` html += `
<div class="col-2"> <div class="col-2">
<input class="relation_checkbox" type="checkbox" name="${key}" ${isChecked}> <input class="relation_checkbox" type="checkbox" name="${key}" ${isChecked}>
<label style="position: relative;left: 18px;bottom: 30px;">${key}</label> <label style="position: relative;left: 18px;bottom: 30px;">${formatString(key)}</label>
</div>`; </div>`;
// console.log(html); // console.log(html);
} }
@ -2743,6 +2743,7 @@ $('#del_btn').click(function() {
function checkCheckboxes() { function checkCheckboxes() {
var checkboxes = $('input.relation_checkbox'); var checkboxes = $('input.relation_checkbox');
var checkedCount = checkboxes.filter(':checked').length; var checkedCount = checkboxes.filter(':checked').length;
var uncheckedCount = checkboxes.not(':checked').length; var uncheckedCount = checkboxes.not(':checked').length;
@ -2753,7 +2754,7 @@ function checkCheckboxes() {
if (checkedCount < 1) { if (checkedCount < 1) {
toastr.warning('You must select at least one checkbox.', 'Warning'); toastr.warning('You must select at least one checkbox.', 'Warning');
return false; return false;
} else if (checkedCount != uncheckedCount) { } else if (checkedCount == uncheckedCount) {
toastr.warning('You can not select all of the checkboxes', 'Waraning'); toastr.warning('You can not select all of the checkboxes', 'Waraning');
return false; return false;
} }

View File

@ -22,7 +22,7 @@ table.dataTable tbody td {
</thead> </thead>
<tbody class="font-12"> <tbody class="font-12">
<?php for ($i = 1; $i <= count($tbody); $i++): ?> <?php for ($i = 1; $i <= $count; $i++): ?>
<tr> <tr>
<?php foreach ($tbody[$i] as $data): ?> <?php foreach ($tbody[$i] as $data): ?>
<td> <td>

View File

@ -0,0 +1,154 @@
<?php
namespace App\Tests;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
use Config\Services;
use Tests\Support\Libraries\ConfigReader;
// use App\Helpers\excel_util_helper;
use Kint\Kint;
class PremiumCalculationTest extends CIUnitTestCase
{
public function testPremiumCalculationWithPrimaryRackRateAndAdditionalRackRate($MY_PARAM = 'TATATATATA')
{
helper('excel_util_helper');
$param = getenv('MY_PARAM');
echo isset($param) && $param != NULL ? $param : $MY_PARAM;
$additional_relationship = '{"self":0,"spouse":0,"childrens":1,"parents":0,"parents-in-law":0,"either-parents-pil":0}';
$primary_grid_id = 11;
$additional_grid_id = 10;
$primary_grid_type = 2;
$addtional_grid_type = 2;
$primary_max_si = 35000000;
$slab_details = [ 'slab_rates' =>[
[ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => $primary_max_si,'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 3500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 4500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => $primary_max_si, 'premium' => 15000, 'max_si' => 0, 'premium_type' => $primary_grid_type, 'relationship' => null],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 30000000, 'premium' => 30000, 'max_si' => 0, 'premium_type' => $primary_grid_type, 'relationship' => null]
],
'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => $primary_grid_id,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0],
'additional_slab_info' => [
'slab_rates' =>[
[ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship ],
[ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2000, 'max_si' => 1800000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2500, 'max_si' => 150000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3000, 'max_si' => 130000, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 3500, 'max_si' => 10, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4000, 'max_si' => 5, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship],
[ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $additional_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 4500, 'max_si' => 5, 'premium_type' => $addtional_grid_type, 'relationship' => null,'additional_relationship' => $additional_relationship]],
'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => $additional_grid_id,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]]
];
// Sample family data
$family_details = [ 'TEST001' =>
[2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', NULL, '', '', 'G', '', '', '', '', '', '',''],
[1,'TEST001','Jane Doe', '01-Jan-1985', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', '0', '', '', ''],
[3,'TEST001','Peter Doe', '01-Jan-1955', 'M', 'Father', '', NULL, '', '', '', '', '', '', '', '', '',''],
[4,'TEST001','Mary Doe', '01-Jan-1953', 'F', 'Mother', '', NULL, '', '', '', '', '', '', '', '', '',''],
[5,'TEST001','Grace Doe', '01-Jan-1954', 'F', 'Mother in law', '', NULL, '', '', '', '', '', '', '', '', '',''],
[6,'TEST001','George Doe', '01-Jan-1948', 'M', 'Father in law', '', NULL, '', '', '', '', '', '', '', '', '',''],
[7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', '',''],
[6,'TEST001','Bob Doe', '01-Jan-1993', 'M', 'son', '50000', NULL, '', '', '', '', '', '', '', '', '',''],
];
// Sample policy terms
$policy_terms = [
'family_floater' => true,
'family_floaters' => [
'self' => 1,
'childrens' => 2,
'spouse' => 1,
'either-parents-pil' => 0,
'parents' => 2,
'parents-in-law' => 2,
],
];
$policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)];
$file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception'];
$data = calculate_premimum($family_details,$policy_details,$slab_details,$file);
$policy_created_count = 0;
echo "\n";
$result_to_display = [];
foreach ($data as $key => $value)
{
$result_to_display[$key]['emp_code'] = $value['emp_code'];
$result_to_display[$key]['name'] = $value['name'].'('.calculate_days_bw_dates($value['dob'])->y.')';
$result_to_display[$key]['relation'] = $value['relationship'];
$temp_grid = substr($value['temp']['grid_type'],0,1);
$temp_grid_type = ($temp_grid == 'p' ? $primary_grid_type : $addtional_grid_type);
$temp_grid_type = ($temp_grid_type == 1 ? 'S' : 'I');
$result_to_display[$key]['premium_type'] = $temp_grid.'#'.$value['temp']['grid_id'].'#'.
($value['temp']['additional_rack_rate_acting_self'] == true ? 'Y' : 'N' ) .'#'. ($temp_grid_type) ;
$result_to_display[$key]['si'] = $value['policy_details']['basic_cover_si'];
$result_to_display[$key]['premium'] = $value['policy_details']['premium'];
$result_to_display[$key]['policy days'] = calculate_days_bw_dates($policy_details['policy_start_date'],$policy_details['policy_end_date'])->days;
$result_to_display[$key]['no of days'] = $value['policy_details']['days'];
$result_to_display[$key]['rata_premimum'] = $value['policy_details']['rata_premimum'];
$result_to_display[$key]['gst'] = $value['policy_details']['gst'];
if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; }
}
TableDisplay::displayTable($result_to_display);
$this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0));
}
}
class TableDisplay
{
public static function displayTable(array $data)
{
if (empty($data)) {
echo "No data to display.\n";
return;
}
// Calculate column widths
$columns = array_keys($data[0]);
$widths = array_map(function ($col) use ($data) {
$maxWidth = strlen($col);
foreach ($data as $row) {
$maxWidth = max($maxWidth, strlen($row[$col]));
}
return $maxWidth;
}, $columns);
// Print header
echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL;
foreach ($columns as $i => $col) {
echo str_pad($col, $widths[$i]) . " | ";
}
echo PHP_EOL;
echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL;
// Print rows
foreach ($data as $row) {
foreach ($columns as $i => $col) {
echo str_pad($row[$col], $widths[$i]) . " | ";
}
echo PHP_EOL;
}
echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL;
}
}