FEAT_COND_EMP_PREMIMUM_CALC
This commit is contained in:
parent
4b02f826ec
commit
66112a637c
@ -110,12 +110,16 @@ class EmployeeController extends AdminController
|
||||
// print_r($this->request->getPost('upload-action-type'));
|
||||
// die();
|
||||
// $empServiceController = new EmployeeServiceController();
|
||||
// $res = $empServiceController->excelFileFormatValidation(['file_id' => '34']);
|
||||
// $res = $empServiceController->excelFileFormatValidation(['file_id' => '12']);
|
||||
// dd($res);
|
||||
|
||||
// $empServiceController = new EmployeeServiceController();
|
||||
// $res = $empServiceController->excelFileDataValidation(['file_id' => '12']);
|
||||
// dd($res);
|
||||
|
||||
// $empServiceController = new EmployeeServiceController();
|
||||
// $res = $empServiceController->employeesOnboard(['file_id' => '34']);
|
||||
// dd($res);
|
||||
|
||||
// if(isset($res['error_summary']) && count($res['error_summary']))
|
||||
// {
|
||||
@ -158,7 +162,7 @@ class EmployeeController extends AdminController
|
||||
$action = $this->request->getPost('upload-action-type');
|
||||
$status = 'inprogress';
|
||||
|
||||
$file_id = $this->fileModel->insert(['file_name' => $filename,'client_id' => $client_id,'policy_id' => $policy_id,'created_by' => $loggedInUserID,'status' => $status,'action' => $action]);
|
||||
$file_id = $this->fileModel->insert(['file_name' => $filename,'client_id' => $client_id,'policy_id' => $policy_id,'created_by' => $loggedInUserID,'status' => $status,'action' => $action]);//here field policy_id have client_policy_id and not policy id from policy master
|
||||
$this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]);
|
||||
|
||||
//start validation process
|
||||
@ -179,8 +183,9 @@ class EmployeeController extends AdminController
|
||||
$data['fileList'] = $this->fileModel
|
||||
->select(['files.*','up.emp_code','up.first_name','pm.name as policy_name','c.short_name'])
|
||||
->join('user_profiles up','files.created_by = up.id')
|
||||
->join('policies pm','files.policy_id = pm.id')
|
||||
->join('clients c','files.client_id = c.id')
|
||||
->join('client_policy cp','files.policy_id = cp.id')
|
||||
->join('policies pm','cp.policy_id = pm.id')
|
||||
->join('clients c','files.client_id = c.id and files.client_id = cp.client_id')
|
||||
->where('files.created_by',8)->orderBy('files.created_at','desc')->findAll();
|
||||
// dd($data['fileList']);die();
|
||||
if($this->request->getMethod() == "get")
|
||||
|
||||
@ -12,6 +12,7 @@ use App\Models\EmployeeModel;
|
||||
use App\Models\EmployeePolicyModel;
|
||||
use App\Models\ClientModel;
|
||||
use App\Models\ClientPolicyModel;
|
||||
use App\Models\PolicesModel;
|
||||
use App\Models\FileModel;
|
||||
|
||||
use App\Controllers\Jobs ;
|
||||
@ -27,6 +28,7 @@ class EmployeeServiceController extends AdminController
|
||||
protected $clientModel;
|
||||
protected $fileModel;
|
||||
protected $clientPolicyModel;
|
||||
protected $policiesModel;
|
||||
protected $general_relationships = ['self' => ['name' => 'Self', 'gender' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'gender' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'gender' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'gender' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'gender' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'gender' => 'F','age_min' => 18,'age_max' => null]];
|
||||
|
||||
protected $inception_excel_columns = ['sno' => ['col_idx' => 0,'col_cell_name' => 'A','col_name' => 'S.No','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'emp_id' => ['col_idx' => 1,'col_cell_name' => 'B','col_name' => 'EMP ID','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'name_of_emp_dep' => ['col_idx' => 2,'col_cell_name' => 'C','col_name' => 'NAME OF EMP/DEP','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'dob' => ['col_idx' => 3,'col_cell_name' => 'D','col_name' => 'DOB','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_dob_diff','params' => ['row','relationship']],'gender' => ['col_idx' => 4,'col_cell_name' => 'E','col_name' => 'Gender','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => ['M','F']],'relationship' => ['col_idx' => 5,'col_cell_name' => 'F','col_name' => 'RELATIONSHIP','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_relationship','params' => ['row','relationship']],'basic_cover_si' => ['col_idx' => 6,'col_cell_name' => 'G','col_name' => 'BASIC COVER SI','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => null],'doj' => ['col_idx' => 7,'col_cell_name' => 'H','col_name' => 'DOJ','is_mandatory' => false,'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_doj','params' => ['row']],'basic_pay' => ['col_idx' => 8,'col_cell_name' => 'I','col_name' => 'Basic Pay','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_basic_pay','params' => ['row']],'band_grade' => ['col_idx' => 9,'col_cell_name' => 'J','col_name' => 'Band/Grade','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_employee_band','params' => ['row']],'designation' => ['col_idx' => 10,'col_cell_name' => 'K','col_name' => 'Designation','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'phone' => ['col_idx' => 11,'col_cell_name' => 'L','col_name' => 'Phone','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'email' => ['col_idx' => 12,'col_cell_name' => 'M','col_name' => 'Email','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'pre_existing_ailments' => ['col_idx' => 13,'col_cell_name' => 'N','col_name' => 'PRE EXISTING AILMENTS','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => ['0','1']],'change_event' => ['col_idx' => 14,'col_cell_name' => 'O','col_name' => 'Change event','is_mandatory' => ['A','DA','D'],'data_type' => 'str','format' => null,'allowed_values' => null],'date_of_exit' => ['col_idx' => 15,'col_cell_name' => 'P','col_name' => 'Date of exit','is_mandatory' => ['D'],'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null],'reason_for_exit' => ['col_idx' => 16,'col_cell_name' => 'Q','col_name' => 'Reason for exit','is_mandatory' => ['D'],'data_type' => 'str','format' => null,'allowed_values' => null],'action' => ['col_idx' => 17,'col_cell_name' => 'R','col_name' => 'Action','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => ['I','A','D','DA'] ]];
|
||||
@ -40,6 +42,7 @@ class EmployeeServiceController extends AdminController
|
||||
$this->clientModel = new ClientModel();
|
||||
$this->fileModel = new FileModel();
|
||||
$this->clientPolicyModel = new ClientPolicyModel();
|
||||
$this->policiesModel = new PolicesModel();
|
||||
}
|
||||
|
||||
public function excelFileFormatValidation($params)
|
||||
@ -332,7 +335,7 @@ class EmployeeServiceController extends AdminController
|
||||
{
|
||||
foreach($res['error_data'] as $key => $value)
|
||||
{
|
||||
array_push($result['error_summary'],$value['code']); //record not avail for deletion
|
||||
array_push($result['error_summary'],$value['code']);
|
||||
$result['error_data'][$rowid][($value['col_name'])]['error'][] = $value['msg'];
|
||||
}
|
||||
}
|
||||
@ -379,5 +382,66 @@ class EmployeeServiceController extends AdminController
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function employeesOnboard($params)
|
||||
{
|
||||
helper('excel_util_helper');
|
||||
//get file name
|
||||
$file_id = $params['file_id'];
|
||||
$file = $this->fileModel->find($file_id);
|
||||
// dd($file);
|
||||
$return = [];
|
||||
if(!isset($file))
|
||||
{
|
||||
//file not found in DB
|
||||
return array('status' => false, 'msg' => 'file not found in DB');
|
||||
}
|
||||
$file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name'];
|
||||
|
||||
//check physical file
|
||||
if(!file_exists($file_name_with_path))
|
||||
{
|
||||
//file not found update status and reason
|
||||
$message = "Physical file not found";
|
||||
// echo $message;
|
||||
$this->myLogger->logme('error',($message . ' for file id ' . $file_id));
|
||||
$this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => json_encode(['error_summary' => array_count_values([5]),'error_data' => $message])])->update();
|
||||
return array('error_summary' => [5], 'error_data' => $message);
|
||||
}
|
||||
|
||||
$columns_to_check = [];
|
||||
if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; }
|
||||
|
||||
// get policy and rack details
|
||||
$policy_terms = $this->clientPolicyModel->getPolicyTermsJson($file['client_id'],$file['policy_id']);
|
||||
// dd($policy_terms);
|
||||
$policy_terms = json_decode($policy_terms[0]->policy_terms);
|
||||
$policy_terms = (array) $policy_terms;// convert obj to array
|
||||
// dd($policy_terms);
|
||||
//get excel data
|
||||
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
|
||||
$excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
|
||||
unset($excel_data[0]);
|
||||
|
||||
|
||||
//get policy slab rates
|
||||
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']);
|
||||
dd($slab_details);
|
||||
|
||||
$employee_data_group_by_family = data_group_by_family($excel_data);
|
||||
dd($employee_data_group_by_family);
|
||||
foreach ($employee_data_group_by_family as $emp_id => $family)
|
||||
{
|
||||
calculate_premimum($family,$policy_terms,$slab_details,$file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -225,8 +225,9 @@ if (!function_exists('name_and_empid_check_in_db'))
|
||||
$res = $employeeModel
|
||||
->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")
|
||||
->where("cp.policy_id",$policy_id)
|
||||
->where("cp.client_policy",$policy_id)
|
||||
->where("employees.client_id",$client_id)
|
||||
->where("ep.client_id",$client_id)
|
||||
->like('name',$row[2],'both')->like('emp_code',$row[1],'both')
|
||||
->findAll();
|
||||
|
||||
@ -363,5 +364,125 @@ if (!function_exists('check_dependent_conflict'))
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('generate_relationship_code'))
|
||||
{
|
||||
function generate_relationship_code($arr)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('calculate_premimum'))
|
||||
{
|
||||
function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr)
|
||||
{
|
||||
// grid type
|
||||
// 1 = premium => si
|
||||
$grid_type = $slab_details['grid_master']['ui_type'];
|
||||
|
||||
if($grid_type != 10 && $grid_type != 11) // 10 & 11 for overall
|
||||
{
|
||||
foreach($family_data as $fkey => $member)
|
||||
{
|
||||
//transform as db row column
|
||||
$transformed_familiy_member_data = transform_excel_data_to_db($member);
|
||||
//generate relationship code
|
||||
$transformed_familiy_member_data = generate_relationship_code($transformed_familiy_member_data);
|
||||
//calculate primimum based on grid type
|
||||
$transformed_familiy_member_data = calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('transform_excel_data_to_db'))
|
||||
{
|
||||
function transform_excel_data_to_db($familyArr,$actionArr)
|
||||
{
|
||||
if($action == 'inception' || $action == 'addition')
|
||||
{
|
||||
|
||||
$policy['basic_cover_si'] = $arr[6];
|
||||
$policy['pre_existing_alignments'] = $arr[13];
|
||||
$policy['date_of_exit'] = isset($arr[15]) ? change_date_format($arr[15],'d-M-Y','Y-m-d') : NULL;
|
||||
$policy['reason_for_exit'] = $arr[16];
|
||||
$policy['client_policy_id'] = $actionArr['policy_id'];
|
||||
|
||||
|
||||
$result['emp_code'] = $arr[1];
|
||||
$result['name'] = $arr[2];
|
||||
$result['dob'] = isset($arr[3]) ? change_date_format($arr[3],'d-M-Y','Y-m-d') : NULL;
|
||||
$result['gender'] = $arr[4];
|
||||
$result['relationship'] = $arr[5];
|
||||
$result['doj'] = isset($arr[7]) ? change_date_format($arr[7],'d-M-Y','Y-m-d') : NULL;
|
||||
$result['basic_pay'] = $arr[8];
|
||||
$result['band'] = $arr[9];
|
||||
$result['designation'] = $arr[10];
|
||||
$result['mobile'] = $arr[11];
|
||||
$result['email_corporate'] = $arr[12];
|
||||
$result['file_id'] = $actionArr['id'];
|
||||
$result['client_id'] = $actionArr['client_id'];
|
||||
$result['change_event'] = $arr[14];
|
||||
$result['action'] = $arr[17];
|
||||
$result['policy_details'] = $policy;
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('calculation_manager'))
|
||||
{
|
||||
function calculation_manager($emp_data,$policy_terms,$slab_details)
|
||||
{
|
||||
// grid type
|
||||
// 1 = premium => si
|
||||
$grid_type = $slab_details['grid_master']['ui_type'];
|
||||
|
||||
switch ($grid_type) {
|
||||
case "1":
|
||||
//GPA - Sum Insured (SI) * Multiplier
|
||||
|
||||
break;
|
||||
case "2":
|
||||
//GPA - Flat Rate for all SI
|
||||
break;
|
||||
case "3":
|
||||
//GMC - SI
|
||||
break;
|
||||
case "4":
|
||||
//GMC - Employees Age band
|
||||
break;
|
||||
case "5":
|
||||
//GMC - Employees Age + SI
|
||||
break;
|
||||
case "6":
|
||||
//GMC - Employees + Dependent Age band
|
||||
break;
|
||||
case "7":
|
||||
//GMC - Employees + Dependent Age + SI
|
||||
break;
|
||||
case "8":
|
||||
//GMC - SI as per Grade or Band
|
||||
break;
|
||||
case "9":
|
||||
//GMC - Flat Rate for all
|
||||
break;
|
||||
case "10":
|
||||
//GMC - Maximum age of Dependents
|
||||
break;
|
||||
case "11":
|
||||
//GMC - Maximum count per Family
|
||||
break;
|
||||
|
||||
default:
|
||||
echo "Not a valid day";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -35,6 +35,8 @@ class ClientPolicyModel extends Model
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"Is_active",
|
||||
"date_of_exit",
|
||||
"reason_for_exit"
|
||||
];
|
||||
|
||||
public function getClientPolicyById($id){
|
||||
@ -101,7 +103,7 @@ class ClientPolicyModel extends Model
|
||||
{
|
||||
return $this->select('policy_terms')
|
||||
->where('client_id',$client_id)
|
||||
->where('policy_id',$policy_id)
|
||||
->where('id',$policy_id)
|
||||
->get()
|
||||
->getResult();
|
||||
|
||||
|
||||
@ -25,5 +25,6 @@ class EmployeeModel extends Model
|
||||
"created_by",
|
||||
"updated_by",
|
||||
"is_active",
|
||||
"file_id"
|
||||
];
|
||||
}
|
||||
|
||||
@ -3,6 +3,9 @@
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
use App\Models\policyGridModel;
|
||||
use App\Models\policyPremium1Model;
|
||||
use App\Models\policyPremium2Model;
|
||||
|
||||
class PolicesModel extends Model
|
||||
{
|
||||
@ -27,4 +30,41 @@ class PolicesModel extends Model
|
||||
->get()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
|
||||
public function getPolicySlabRatesForEmpOnboard($policy_id,$client_id){
|
||||
|
||||
|
||||
// $data = $this->getPolicyPremium($policy_id);
|
||||
// $pattern = '/gmc/i';
|
||||
// $subject = $data[0]->policy_type;
|
||||
// if (preg_match($pattern, $subject)) {
|
||||
// $search_term = 'GMC';
|
||||
// } else {
|
||||
// $search_term = 'GPA';
|
||||
// }
|
||||
|
||||
|
||||
$premium_slab_data = null;
|
||||
// echo !isset($premium_slab_data);die();
|
||||
// if($search_term === 'GPA'){
|
||||
$policyPremium1Model = new policyPremium1Model();
|
||||
$premium_slab_data = $policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll();
|
||||
if((isset($premium_slab_data)))
|
||||
{
|
||||
echo '2';
|
||||
$policyPremium2Model = new policyPremium2Model();
|
||||
$premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll();
|
||||
}
|
||||
// }else{
|
||||
;
|
||||
// }
|
||||
// dd($premium_slab_data);
|
||||
// dd($policyPremium1Model->getLastQuery());
|
||||
//get policy id
|
||||
$grid_id = $premium_slab_data[0]['policy_grid_id'];
|
||||
$policyGridModel = new policyGridModel();
|
||||
$results = $policyGridModel->find($grid_id);
|
||||
return ['slab_rates' => $premium_slab_data,'grid_master' => $results];
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,7 +281,54 @@
|
||||
// for (var ckey in col)
|
||||
// {
|
||||
|
||||
file_error_html += (err_id == 1 ? "<strong>Mandatory values missing</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 2 ? "<strong>Values not in expected format</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 3 ? "<strong>Field contains not allowed values</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 4 ? "<strong>Rule Conflict</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 5 ? "<strong>"+file_error_data['error_data']+"</strong>" : (err_id == 6 ? "<strong>"+file_error_data['error_data']+"</strong>" : ""))))));
|
||||
// file_error_html += (err_id == 1 ? "<strong>Mandatory values missing</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 2 ? "<strong>Values not in expected format</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 3 ? "<strong>Field contains not allowed values</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 4 ? "<strong>Rule Conflict</strong> <span class='badge badge-danger float-right'>"+err_count+"</span>" : (err_id == 5 ? "<strong>"+file_error_data['error_data']+"</strong>" : (err_id == 6 ? "<strong>"+file_error_data['error_data']+"</strong>" : ""))))));
|
||||
// var message;
|
||||
switch (err_id) {
|
||||
case 1:
|
||||
file_error_html += "<strong>Mandatory values missing</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 2:
|
||||
file_error_html += "<strong>Values not in expected format</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 3:
|
||||
file_error_html += "<strong>Field contains not allowed values</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 4:
|
||||
file_error_html += "<strong>Rule Conflict</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 5:
|
||||
file_error_html += "<strong>" + file_error_data['error_data'] + "</strong>";
|
||||
break;
|
||||
case 6:
|
||||
file_error_html += "<strong>" + file_error_data['error_data'] + "</strong>";
|
||||
break;
|
||||
case 7:
|
||||
file_error_html += "<strong>Duplicate entry in file</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 8:
|
||||
file_error_html += "to be config";
|
||||
break;
|
||||
case 9:
|
||||
file_error_html += "<strong>Duplicate entry</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 10:
|
||||
file_error_html += "<strong>Duplicate entry in file</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 11:
|
||||
file_error_html += "<strong>Rule conflict: Dependents not allowed</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 12:
|
||||
file_error_html += "<strong>Rule conflict: Dependent count greater than allowed dependent count</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
case 13:
|
||||
file_error_html += "<strong>Rule conflict: Twofold relationship found within family</strong> <span class='badge badge-danger float-right'>" + err_count + "</span>";
|
||||
break;
|
||||
|
||||
default:
|
||||
file_error_html += "";
|
||||
break;
|
||||
}
|
||||
|
||||
file_error_html += '<br/>';
|
||||
// }
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user