diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a94471e9..423e318e 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -141,6 +141,8 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->match(['get','post'],'enrollment-list','EmployeeController::enrollmentClientList'); $routes->get("empby_client_clientbranch/(:any)/(:any)", "EmployeeController::empby_client_clientbranch/$1/$2"); $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); + $routes->get("test-rack-rate", "EmployeeController::testRackRate"); + $routes->post("test-rack-rate", "EmployeeController::testRackRate"); }); @@ -291,9 +293,9 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { -$routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEmployeeActiveOrInactivePolicy"); -$routes->get("getChatResponse", "ChatBotController::getChatResponse"); + + $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->post("storeFireBase", "EmployeeRestController::storeFireBase"); $routes->post("saveMpin", "RestAuthenticationController::saveMpin"); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index ea0b306a..4e87cdb1 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -221,6 +221,7 @@ class EmployeeController extends AdminController //process post variable entry in file table $loggedInUserID = get_session_userid(); + // dd($loggedInUserID); // $loggedInUserID = 8; $client_id = $this->request->getPost('client_id'); @@ -229,7 +230,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, 'client_branch_id' => $branch_id]); //here field policy_id have client_policy_id and not policy id from policy master + $file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id,'uploaded_by' => 1]); //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 @@ -245,9 +246,10 @@ class EmployeeController extends AdminController } - + //for TPA/insurer upload $data['events'] = ['inception' => 'Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; - $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addtion' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; + //for inception upload + $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addtion' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrollment']; $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export']; $data['insurer_or_tpa'] = ['insurer' => 'Insurer', 'tpa' => 'TPA']; @@ -362,6 +364,10 @@ class EmployeeController extends AdminController $filePath = ROOTPATH . 'public/sample_excel/sample_addition.xls'; } else if ($actionType == 'deletion') { $filePath = ROOTPATH . 'public/sample_excel/sample_deletion.xls'; + } else if ($actionType == 'enrollment') { + $filePath = ROOTPATH . 'public/sample_excel/enrollment.xls'; + }else if ($actionType == 'missed_inception') { + $filePath = ROOTPATH . 'public/sample_excel/sample_inception.xls'; } // Check if the file exists @@ -1507,4 +1513,79 @@ class EmployeeController extends AdminController } + public function testRackRate() + { + if ($this->request->getMethod() == 'get') { + $filterData = $this->request->getGet('client_policy_id'); + //just load UI only + $this->loadLayout('rack_rate_test'); + } + + + if ($this->request->getMethod() == 'post') { + $json = $this->request->getJSON(); + // return $this->respond(['dataStatus' => false, 'code' => 200, 'data' => $data], 200); + // $data = (json_decode(json_encode($data),true)); + $client_id = $json->client_id; + $policy_id = $json->policy_id; + $branch_id = $json->branch_id; + $tabledata = $json->data; + + if(count($tabledata)) + { + $family_details = []; + foreach($tabledata as $key => $row) + { + $row = (array)$row; + if(!$row['column12']) + { + + $temp[0] = $row['column1'];//sno + $temp[1] = $row['column2'];//emp code + $temp[2] = $row['column3'];//name + $temp[3] = $row['column4'];//DOB + $temp[4] = strtoupper($row['column5']);//Gender + $temp[5] = $row['column6'];//relation + $temp[6] = $row['column7'];//SI + $temp[7] = $row['column8'];//DOC + $temp[8] = '';//DOJ + $temp[9] = $row['column9'];//BP + $temp[10] = $row['column10'];//band + $temp[11] = '';//designation + $temp[12] = '';//mobile + $temp[13] = '';//EMail + $temp[14] = '';//CE + $temp[15] = '';//RFE + $temp[16] = '';//DOE + $temp[17] = '';//Unit + $temp[18] = $row['column11'];//unit + $family_details[] = $temp; + } + } + } + + // print_r($family_details); + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $family_details], 200); + //get policy details + $policy_details = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); + //get rack rates + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); + //get file array or construnct dummy file array here + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception','client_branch_id' => 1,'created_by' => 1]; + //get familiy details in inception file format array from post method + $family_details = [ + [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, '', '', '', '', '', '', '', '', '',''], + ]; + $data = calculate_premimum_new($family_details,$policy_details,$all_rack_rates,$file); + } + } + } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 80a6c14b..1458100e 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -830,7 +830,7 @@ class EmployeeRestController extends AdminController $count = 0; for ($a=0; $a employeeModel->checkExistingEmployee($dataToInsert[$a]); + $employee = $this->employeeModel->checkExistingEmployee($dataToInsert[$a],$client_branch_id); $emp_id =0; $data_after_gpa_or_gmc =[]; diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 6e678508..0a6a9ba1 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -16,6 +16,10 @@ use App\Models\PolicesModel; use App\Models\FileModel; use App\Models\EmpEndorsementModel; use App\Models\MessageModel; +use App\Models\ClientBranchModel; +use App\Models\NotificationModel; + +use App\Helpers\sendMailNotification; use App\Controllers\Jobs ; use App\Controllers\JobWorker ; @@ -35,6 +39,8 @@ class EmployeeServiceController extends AdminController protected $policiesModel; protected $empEndorsementModel; protected $messageModel; + protected $clientBranchModel; + protected $notificationModel; protected $general_relationships = [ 'self' => [ @@ -266,6 +272,18 @@ class EmployeeServiceController extends AdminController 'format' => null, 'allowed_values' => null ] + , + 'unit' => [ + 'col_idx' => 18, + 'col_cell_name' => 'S', + 'col_name' => 'Unit', + 'is_mandatory' => false, + 'data_type' => 'str', + 'format' => null, + 'allowed_values' => null, + 'custom' => 'check_unit', + 'params' => ['row', 'existing_units'] + ] ]; protected $deletion_excel_columns = [ @@ -565,6 +583,15 @@ class EmployeeServiceController extends AdminController 'format' => null, 'allowed_values' => null, 'custom' => null + ], + 'unit' => [ + 'col_idx' => 12, + 'col_cell_name' => 'M', + 'col_name' => 'Unit', + 'is_mandatory' => false, + 'data_type' => 'str', + 'format' => null, + 'allowed_values' => null ] ]; @@ -586,7 +613,8 @@ class EmployeeServiceController extends AdminController 14 => null, // inception: pre_existing_ailments (PRE EXISTING AILMENTS) -> No match in enrollment 15 => null, // inception: change_event (Change event) -> No match in enrollment 16 => null, // inception: date_of_exit (Date of exit) -> No match in enrollment - 17 => null // inception: reason_for_exit (Reason for exit) -> No match in enrollment + 17 => null, // inception: reason_for_exit (Reason for exit) -> No match in enrollment + 18 => null // inception: reason_for_exit (Reason for exit) -> No match in enrollment ]; protected $enrollment_to_inception_mapping = [ @@ -619,6 +647,8 @@ class EmployeeServiceController extends AdminController $this->policiesModel = new PolicesModel(); $this->empEndorsementModel = new EmpEndorsementModel(); $this->messageModel = new MessageModel(); + $this->clientBranchModel = new ClientBranchModel(); + $this->notificationModel = new NotificationModel(); } public function excelFileFormatValidation($params) @@ -663,6 +693,7 @@ class EmployeeServiceController extends AdminController if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; } if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; } if($file['action'] == 'enrollment'){ $columns_to_check = $this->enrollment_excel_columns; } + if($file['action'] == 'missed_inception'){ $columns_to_check = $this->inception_excel_columns; } $result = ['error_type' => 1,'error_summary' => [], 'error_data' => [] ]; @@ -722,7 +753,10 @@ class EmployeeServiceController extends AdminController $relationship = $this->general_relationships; //get exisiting mobilr nos $existing_mobilenos = $this->employeePolicyModel->getExisitingMobileNos(client_policy_id: $file['policy_id']); - // dd($existing_mobilenos); + + //get existing units in the current branch + $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']); + // dd($existing_units); foreach ($excel_data as $row_key => $row) { //define row wise action/event in temporary variable @@ -734,6 +768,7 @@ class EmployeeServiceController extends AdminController else if($file['action'] == 'correction'){ $current_column_action = 'C'; } else if($file['action'] == 'si_enhancement'){ $current_column_action = 'SI'; } else if($file['action'] == 'enrollment'){ $current_column_action = 'I'; } + else if($file['action'] == 'missed_inception'){ $current_column_action = 'MI'; } //1. avoid empty rows if(check_row_is_empty_or_null($row)) { @@ -862,16 +897,17 @@ class EmployeeServiceController extends AdminController } else //trigger next data validation via job queue server - { - if($file['action'] == 'enrollment') // if current action is enrollment call next validation and return result + { + if($file['action'] == 'enrollment' && $file['uploaded_by'] != 1) // if current action is enrollment and uploaded by HR (0 or NULL) call next validation and return result { + // dd(); $res = $this->excelFileDataValidation(['file_id' => $file['id']]); return $res; } //proceed next data level validation in JOB queue - $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'excelFileDataValidation','payload' => ['file_id' => $file_id]]); + // $job_details = new Jobs(); + // $r = Jobs::addJob(['job_name' => 'excelFileDataValidation','payload' => ['file_id' => $file_id]]); // $jobWorker = new JobWorker(); // JobWorker::processJob($r); @@ -914,6 +950,7 @@ class EmployeeServiceController extends AdminController if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; } if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; } if($file['action'] == 'enrollment'){ $columns_to_check = $this->enrollment_excel_columns; } + if($file['action'] == 'missed_inception'){ $columns_to_check = $this->inception_excel_columns; } // get policy and rack details $policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); @@ -940,7 +977,7 @@ class EmployeeServiceController extends AdminController $relationship = $this->general_relationships; - if(in_array($file['action'],['inception','addition','dependent_addition','deletion','correction','si_enhancement','enrollment']))// the below funcitons are only for I,DA,A + if(in_array($file['action'],['inception','missed_inception','addition','dependent_addition','deletion','correction','si_enhancement','enrollment']))// the below funcitons are only for I,DA,A { $employee_data_group_by_family = data_group_by_family($excel_data,'excel',($file['action'] == 'enrollment' ? 'enrollment' : '')); // dd($employee_data_group_by_family); @@ -968,12 +1005,12 @@ class EmployeeServiceController extends AdminController // dd(array_keys($existing_famility_details[0])); $family = array_merge($family,$existing_famility_details); // kint::dump($family); - $family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array + $family = data_group_by_family($family)[ $emp_id ];// reason to call this again bring self to first index of the array } // kint::dump($family);//die(); //check name dup within a family - if($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition' || $file['action'] == 'enrollment') + if($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition' || $file['action'] == 'enrollment') { $res = name_dup_check_within_family($family,$file['action']);//in both file data & DB data // dd($res); @@ -987,7 +1024,7 @@ class EmployeeServiceController extends AdminController } } - if(($policy_details['base_policy'] == null && ($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment')) || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) // 3 is GMC parents dep addon) + if(($policy_details['base_policy'] == null || $policy_details['base_policy'] == 0 && ($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment')) || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) // 3 is GMC parents dep addon) { $res = check_self_available_in_family($family,$file['action']); if(!$res['is_self_found']) @@ -1010,7 +1047,7 @@ class EmployeeServiceController extends AdminController } - if($file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'inception' || $file['action'] == 'enrollment') + if($file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'inception'|| $file['action'] == 'missed_inception' || $file['action'] == 'enrollment') { $res = check_dependent_conflict($family,$policy_terms,$file['action']); // dd($res); @@ -1081,14 +1118,18 @@ class EmployeeServiceController extends AdminController $r = Jobs::addJob(['job_name' => 'employeesCorrectionProcess','payload' => ['file_id' => $file_id]]); } - else if ($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')//inception OR addition OR dependent addition + else if ($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')//inception OR addition OR dependent addition { //proceed next data level validation in JOB queue - $job_details = new Jobs(); + // $job_details = new Jobs(); $r = Jobs::addJob(['job_name' => 'employeesOnboardPreprocess','payload' => ['file_id' => $file_id]]); // $jobWorker = new JobWorker(); // JobWorker::processJob($r); } + else if($file['action'] == 'enrollment' && $file['uploaded_by'] == 1)// enrollment uploaded by nhance user not by hr + { + $r = Jobs::addJob(['job_name' => 'employeesEnrollmentInsert','payload' => ['file_id' => $file_id]]); + } return $result; @@ -1134,6 +1175,7 @@ class EmployeeServiceController extends AdminController if($file['action'] == 'deletion'){ $columns_to_check = $this->deletion_excel_columns; } if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; } if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; } + if($file['action'] == 'missed_inception'){ $columns_to_check = $this->inception_excel_columns; } // get policy and rack details $policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); @@ -1155,6 +1197,8 @@ class EmployeeServiceController extends AdminController //get policy slab rates $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); // dd($slab_details); + //get existing units in the current branch + $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']); $employee_data_group_by_family = data_group_by_family($excel_data); // dd($employee_data_group_by_family); @@ -1175,7 +1219,7 @@ class EmployeeServiceController extends AdminController } // Kint::dump($family);die(); - $data = calculate_premimum($family,$policy_terms,$slab_details,$file); + $data = calculate_premium_new(family_data:$family,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units); // dd($data); $employee_data_group_by_family[$emp_id] = $data; $this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); @@ -1204,6 +1248,9 @@ class EmployeeServiceController extends AdminController $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_status: ['enrolled','draft'],policy_status:['enrolled','draft']); + //get existing units in the current branch + $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']); + // $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception','created_by' => get_session_userid(),'client_branch_id' => $params['client_branch_id']]; @@ -1214,7 +1261,8 @@ class EmployeeServiceController extends AdminController foreach ($employee_data_group_by_family as $emp_id => $family) { $transformed_famility_details = transform_db_data_to_excel($family); - $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file); + // $data = calculate_premium_new($transformed_famility_details,$policy_terms,$slab_details,$file); + $data = calculate_premium_new(family_data:$transformed_famility_details,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units); // dd($data); $employee_data_group_by_family[$emp_id] = $data; $this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); @@ -1478,10 +1526,9 @@ class EmployeeServiceController extends AdminController { $familiy_data = $params['familiy_data']; $file = $params['file']; - $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); foreach($familiy_data as $fkey => $value) { - if($file['id'] == null || $value['temp']['source'] == 'excel' || (($file['action'] == 'dependent_addition' && ($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)))) //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data) + if($file['id'] == null || $value['temp']['source'] == 'excel' || (($file['action'] == 'dependent_addition' && ($value['temp']['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($value['temp']['premium_type'] == 2 || $value['temp']['premium_type'] == null)))) //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data) { $employee = $this->employeeModel->checkExistingEmp($value,$file['client_branch_id']); @@ -1495,7 +1542,7 @@ class EmployeeServiceController extends AdminController // echo '---------------------------------------'; //start implemet of si enhancement of grid type 10,11 - if(count($employee) && $file['action'] == 'dependent_addition' && $temp['source'] == 'db' && in_array($value['temp']['grid_id'],[10,11]) && ( ($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))) + if(count($employee) && $file['action'] == 'dependent_addition' && $temp['source'] == 'db' && in_array($value['temp']['grid_id'],[10,11]) && ( ($value['temp']['premium_type'] == 1 && (strtolower($value['relationship']) == 'self' || $temp['acting_self'])) || ($value['temp']['premium_type'] == 2 || $value['temp']['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); @@ -1506,6 +1553,7 @@ class EmployeeServiceController extends AdminController //end implemet of si enhancement of grid type //save employee table + $value['relationship'] = ucfirst(trim($value['relationship'])); if(count($employee)) { $value['updated_by'] = $file['created_by']; @@ -1514,6 +1562,7 @@ class EmployeeServiceController extends AdminController $value['client_branch_id'] = $file['client_branch_id']; $log_message = 'Update Employee - '.$employee[0]['name'].'('.$employee[0]['emp_code'].') with PK '.$employee[0]['id']; // $this->myLogger->logme('error',('Update - ' . $employee[0]['id'].' - '. $employee[0]['emp_code'] .' - '.$employee[0]['name'])); + // echo 'insert emp'; } else { @@ -1522,6 +1571,7 @@ class EmployeeServiceController extends AdminController $value['client_branch_id'] = $file['client_branch_id']; $log_message = 'Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK '; // $this->myLogger->logme('error',('Insert - ' . $value['emp_code'] .' - '. $value['name'])); + // echo 'update emp'; } $this->employeeModel->save($value); @@ -1540,6 +1590,7 @@ class EmployeeServiceController extends AdminController $policy_data['status'] = 'active'; $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; + // echo 'insert policy'; } else { @@ -1548,6 +1599,7 @@ class EmployeeServiceController extends AdminController $policy_data['created_by'] = $file['created_by']; $policy_data['status'] = 'active'; $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; + // echo 'update policy'; } $this->employeePolicyModel->save($policy_data); @@ -1557,7 +1609,7 @@ class EmployeeServiceController extends AdminController $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') && $temp['source'] == 'excel') + if(($file['action'] == 'missed_inception' || $file['action'] == 'dependent_addition' || $file['action'] == 'addition') && $temp['source'] == 'excel') { $log_message = $file['action'].' - endorsement'. $value['emp_code'].' - '.$value['name'].' - with policy id'.$emp_policy_id; $this->myLogger->logme('error',$log_message); @@ -1792,8 +1844,173 @@ class EmployeeServiceController extends AdminController $this->messageModel->insert($msg_data); - } - - - +} + + +public function employeesEnrollmentInsert($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); + } + + //get excel data + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + $result = ['error_type' => 2,'error_summary' => [], 'error_data' => [] ]; + $columns_to_check = $this->enrollment_excel_columns; + $keys = array_keys($columns_to_check); + $allowedHighestColumn = end($columns_to_check); + $excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']); + // print_r($keys);die(); + + //remove header + unset($excel_data[0]); + // dd($excel_data); + $emp_emails = []; + + //check is welcome notification enabled + $notification = $this->notificationModel->where('client_id',$file['client_id'])->where('template_name','member_welcome_mail')->first(); + // dd($notification); + $client_details = $this->clientModel->where('id', $file['client_id'])->first(); + + foreach ($excel_data as $key => $row) + { + // dd($key.'-'.count($excel_data)); + $value = []; + $policy_data = []; + + $value['emp_code'] = $row[1]; + $value['name'] = $row[2]; + $value['doj'] = (!empty($row[3]) ? convert_string_to_date($row[3],'Y-m-d'): null); + $value['gender'] = $row[4]; + $value['relationship'] = ucfirst(trim($row[5])); + $value['dob'] = convert_string_to_date($row[6],'Y-m-d'); + $value['email_corporate'] = $row[7]; + $value['mobile'] = $row[8]; + $value['band'] = $row[10]; + $value['basic_pay'] = $row[11]; + $value['unit'] = $row[12]; + $value['family_floater_key'] = null; + $value['client_id'] = $file['client_id']; + $value['client_branch_id'] = $file['client_branch_id']; + + $value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model + if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'Father') { + $relation = 'parent'; + } else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){ + $relation = 'child'; + }else if(strtolower(trim($value['relationship'])) === 'father in Law' || strtolower(trim($value['relationship'])) === 'mother in Law'){ + $relation = 'parent_in_law'; + }else if(strtolower(trim($value['relationship'])) === 'spouse'){ + $relation = 'spouse'; + }else{ + $relation = 'self'; + } + $value['family_floater_key'] = $relation; + + $policy_data['basic_cover_si'] = $row[9]; + $policy_data['client_policy_id'] = $file['policy_id']; + + $employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']); + unset($value['temp']); + //save employee table + // dd($employee['id']); + if($employee !== null) + { + $value['updated_by'] = $file['created_by']; + $value['id'] = $employee['id']; + $value['emp_status'] = 'draft'; + + $log_message = 'Enrollment Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id']; + } + else + { + $value['emp_status'] = 'draft'; + $value['created_by'] = $file['created_by']; + $log_message = 'Enrollment Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK '; + } + + $this->employeeModel->save($value); + $emp_id = $this->employeeModel->getInsertID(); + if($emp_id != 0){ $log_message .= $emp_id; } + else{ $emp_id = $employee['id']; } + + $this->myLogger->logme('error',$log_message); + + //save policy table + $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $file['policy_id']]); + if(count($employee_policy)) + { + $policy_data['updated_by'] = $file['created_by']; + $policy_data['id'] = $employee_policy[0]['id']; + $policy_data['status'] = 'draft'; + + $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; + // echo 'insert policy'; + } + else + { + $policy_data['employee_id'] = $emp_id; + $policy_data['client_policy_id'] = $file['policy_id']; + $policy_data['created_by'] = $file['created_by']; + $policy_data['status'] = 'draft'; + $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; + // echo 'update policy'; + } + + $this->employeePolicyModel->save($policy_data); + $emp_policy_id = $this->employeePolicyModel->getInsertID(); + $this->myLogger->logme('error',$log_message); + + //save email of self for send mail later + if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '') + { + if(strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "") + { + $params['dataToInsert'] = $value; //holds employee master data + $params['notification'] = $notification; + $params['client_data'] = $client_details; + + //store email and mail content via helper to send notification + $emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params); + Kint::dump($emp_emails); + Kint::dump($key.'-'.count($excel_data)); + // if mail count is 20 send bulk mail and reset emp_emails variable + if (count($emp_emails) == 20 || $key == count($excel_data) ) { + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]); + echo 'Mail triggered'; + $emp_emails = []; + } + + } + } + } //end of for loop + + return true; +} + } diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index 21ba4e84..eb9f96e2 100644 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -21,25 +21,120 @@ class JobWorker extends AdminController * Constructs the class */ - 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'], - - 'importInceptionFileValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'], - 'importInceptionUpdateTPAandUHID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'], - 'cashDepositCalculationForInception' => ['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'], - ]; + private static $event_class_mapping = [ + 'add' => [ + 'type' => 'HC', // Handler Category (Possible values: HC, CC, HF) + 'handler' => 'App\Helpers\HttpRequestHelper', + ], + 'sub' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\Jobs\SubJob', + ], + 'fancy_date_time_format' => [ + 'type' => 'HF', // Handler Category (Possible values: HC, CC, HF) + 'handler' => 'fancy_date_time_format', // Likely a custom function + ], + 'addNumber' => [ + 'type' => 'HC', // Handler Category + 'handler' => 'App\Model\HttpRequestHelper', + ], + 'excelFileFormatValidation' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeServiceController', + ], + 'excelFileDataValidation' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeServiceController', + ], + 'employeesOnboardPreprocess' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeServiceController', + ], + 'employeeDisembark' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeServiceController', + ], + 'employeesSIEnhanceProcess' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeServiceController', + ], + 'employeesCorrectionProcess' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeServiceController', + ], + 'send_email' => [ + 'type' => 'HC', // Handler Category + 'handler' => 'App\Helpers\MailHelper', + ], + 'bulk_mail' => [ + 'type' => 'HC', // Handler Category + 'handler' => 'App\Helpers\MailHelper', + ], + 'insertBatchList' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + + // Employee Data Service Events + 'importInceptionFileValidation' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'importInceptionUpdateTPAandUHID' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'cashDepositCalculationForInception' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'sendMailForDownloadingECard' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + + 'importCorrectionValidation' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'importCorrectionUpdateEndorsementID' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + + 'cashDepositCalculationForSIEnhancement' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'importSIEnhancementValidation' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'importSIEnhancementUpdateEndorsementID' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + + 'cashDepositCalculationForDeletion' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'importDeletionValidation' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'importDeletionUpdateEndorsementID' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmpDataServiceController', + ], + 'employeesEnrollmentInsert' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\EmployeeServiceController', + ] +]; + + + public function __construct() { // echo 'HiC';//die(); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 6efaa163..bb6013d5 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -69,15 +69,13 @@ class RestAuthenticationController extends AdminController { try { $mobile_number = $this->request->getJSON()->mobile_number; - $randomNumber = rand(100000, 999999); - $randomNumber = 123456; + $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); if ($employeeData) { - $id= $employeeData["id"]; - $otp = $this->employeeModel->where('id', $id)->set('otp', $randomNumber)->update(); - $result = ['user_verification' => true ,'message' => "Verified Successfully", 'otp'=>$randomNumber]; + + $result = ['user_verification' => true ,'message' => "Verified Successfully"]; return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); } else { $result = ['user_verification' => false , 'message' => "User not found"]; @@ -92,13 +90,13 @@ class RestAuthenticationController extends AdminController public function getVerifiedUserData() { - // try { + try { $mobile_number = $this->request->getJSON()->mobile_number; - $otp = $this->request->getJSON()->otp; + $otp_verification = $this->request->getJSON()->otp_verification; $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); - if ($employeeData && $otp == $employeeData["otp"] || $employeeData && isset($this->request->getJSON()->login_by_hr)) { + if ($employeeData && $otp_verification == true || $employeeData && isset($this->request->getJSON()->login_by_hr)) { $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $data = [ @@ -108,22 +106,19 @@ class RestAuthenticationController extends AdminController 'platform' => $auth['platform'], 'broswer' => $auth['browser'], ]; - - $authdata= $this->authHistoryModel->insert($data); - + $this->authHistoryModel->insert($data); } - $otp_null = $this->employeeModel->where('id', $employeeData["id"])->set('otp', null)->update(); - - + $result = JWTToken::encode($employeeData); - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + } else { return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); } - // } catch (\Exception $e) { - // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); - // } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); + } } public function verifyHrWithMobileNumber() @@ -190,11 +185,6 @@ class RestAuthenticationController extends AdminController - public function employeeLogout() - { - - } - public function getUserIdFromToken() { $id = JWTToken::getUserIdFromToken(); diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php index b64a2a76..484372a7 100644 --- a/app/Filters/AuthJWT.php +++ b/app/Filters/AuthJWT.php @@ -37,6 +37,9 @@ class AuthJWT implements FilterInterface $model->update($id, $data); return true; }else{ + + // if($user_data['token_time_out'] != "" && $user_data['token_time_out'] != NULL) + $data =["token_time_out" => '']; $model->update($id, $data); header('Content-Type: application/json'); diff --git a/app/Helpers/MailHelper.php b/app/Helpers/MailHelper.php index da8d2624..7b1a9bc7 100644 --- a/app/Helpers/MailHelper.php +++ b/app/Helpers/MailHelper.php @@ -18,6 +18,7 @@ class MailHelper { // print_r($params);die; + $myLogger = \Config\Services::mylogger(); $emaill = $params['mail']; $subject = $params['subject']; $message = $params['message']; @@ -48,12 +49,16 @@ class MailHelper $email->setMessage($message); if ($email->send()) { + return json_encode(['status' => 'success','code' => 200, 'message'=>'Email Sent Successfully...','data' => $emaill,],200); } else { + $myLogger->logme('error', "mail sent failed - $emaill"); return json_encode(['status' => 'failed','code' => 404,'message'=>'Email Sent Failed...','data' => $emaill ],404); } } catch (Exception $e) { + $msg = $e->getMessage(); + $myLogger->logme('error', "mail sent failed - $msg"); return json_encode(['status' => 'failed','code' => 500,'data' => $emaill],500); } } diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index d14d71a7..80a40917 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -90,7 +90,7 @@ if(!function_exists('check_relationship')) { // print_r($relationship); // echo '
'; - if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','MI']))// check rule only of action column data available { if($row[5] != null && $row[4] != null)//$row[5] = relationship $row[4] = Gender { @@ -141,7 +141,7 @@ if(!function_exists('check_doj')) function check_doj($row) { - if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','MI']))// check rule only of action column data available { $slug = \Config\Services::slug(); $relationship = $slug->slugify($row[5]); @@ -188,7 +188,7 @@ if(!function_exists('check_employee_band')) { function check_employee_band($row,$policy_terms,$slab_details) { - if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','MI']))// check rule only of action column data available { $is_emp_band_needed = $slab_details['grid_master']['emp_band']; // $is_emp_band_needed = true; @@ -230,7 +230,7 @@ if(!function_exists('check_si')) $return_array = array('status' => true,'error' => ''); $is_si_found = false; $is_age_slab_found = false; - if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','SI']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','SI','MI']))// check rule only of action column data available { $received_si = $row['current_action'] == 'SI' ? $row[3] : $row[6]; foreach ($slab_details['slab_rates'] as $skey => $slab_value) @@ -247,7 +247,7 @@ if(!function_exists('check_si')) } // check age slab - if(in_array(strtoupper($row['current_action']), ['I','A','DA']) && (($slab_value['premium_type'] == 1 && strtolower($row['5']) == 'self' ) || ($slab_value['premium_type'] == 2) ) ) + if(in_array(strtoupper($row['current_action']), ['I','A','DA','MI']) && (($slab_value['premium_type'] == 1 && strtolower($row['5']) == 'self' ) || ($slab_value['premium_type'] == 2) ) ) { if($row[3] != '' && $row[3] != null)// dob { @@ -311,7 +311,7 @@ if(!function_exists('check_basic_pay')) { function check_basic_pay($row,$policy_terms,$slab_details) { - if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','MI']))// check rule only of action column data available { $is_basic_pay_needed = $slab_details['grid_master']['basicpay']; // $is_basic_pay_needed = true; @@ -329,7 +329,7 @@ if (!function_exists('check_dob_diff')) { function check_dob_diff($row,$relationships,$default_age_ratio) { // echo 'called'; - if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','MI']))// check rule only of action column data available { if($row[3] != null && $row[5] != null) { @@ -667,9 +667,10 @@ if (!function_exists('generate_relationship_code')) } } -if (!function_exists('calculate_premimum')) +if (!function_exists('calculate_premium')) { - 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) + function calculate_premium(array $family_data,array $policy_terms,array $slab_details,array $fileArr,string $default_si = null,array $existing_units = []) { // dd($family_data); $slug = \Config\Services::slug(); @@ -865,6 +866,130 @@ if (!function_exists('calculate_premimum')) } } +if (!function_exists('calculate_premium_new')) +{ + function calculate_premium_new(array $family_data,array $policy_terms,array $slab_details,array $fileArr,string $default_si = null,array $existing_units) + { + + //grouping slab details by rack rate name + $temp_slab_rates = []; + $pre_name = ''; + $pre_grid_master = []; + foreach ($slab_details as $key => $value) + { + $pre_grid_master = $value['grid_master']; + unset($value['grid_master']); + if($value['rack_rate_name'] != $pre_name) + { + $pre_name = $value['rack_rate_name']; + $temp_slab_rates[ $value['rack_rate_name'] ]['slab_rates'][] = $value; + } + $temp_slab_rates[ $value['rack_rate_name'] ]['slab_rates'][] = $value; + $temp_slab_rates[ $value['rack_rate_name'] ]['grid_master'] = $pre_grid_master; + } + // dd($temp_slab_rates); + /* 1. construct available/incoming family members composition & count */ + $incoming_familiy_composition = get_familiy_composition($family_data); + // dd($incoming_familiy_composition); + + //2 .get applicable familiy members composition & count from slab details & constrcut an array + //3 in for another loop compare slab level applicable familiy composition with available family composition + $result = []; + foreach($temp_slab_rates as $key => $slab) + { + // dd($slab); + $res = compare_incoming_family_slab_with_configured_slab($slab,$incoming_familiy_composition); + kint::dump($key); + kint::dump($res); + + if($res['is_applicable']) + { + $temp_slab_rates[$key]['is_applicable'] = true; + $temp_slab_rates[$key]['members'] = $res['applicable_members']; + + //get applicable members for current rack rate from over all familiy members and calculate max age and max count,self/acting self and grid type and set it in individual familiy member level + $applicable_members_from_familiy = get_applicable_familiy_members($family_data,$res['applicable_members']); + // dd( $applicable_members_from_familiy); + $is_self_acting_self_set = false; + foreach($applicable_members_from_familiy['index'] as $val) + { + $acting_self = false; + if(!$is_self_acting_self_set) + { + if(strtolower($family_data[$val][5]) == 'self' || !$is_self_acting_self_set) $acting_self = true; + $is_self_acting_self_set = true; + } + + $family_data[$val]['temp'] = ['max_age' => max($applicable_members_from_familiy['max_age']),'max_count' => $applicable_members_from_familiy['max_count'],'grid_name' => $key,'grid_master' => $slab['grid_master'],'acting_self' => $acting_self,'premium_type' => $slab['slab_rates'][0]['premium_type']]; + } + } + else + { + $temp_slab_rates[$key]['is_applicable'] = false; + } + } + // dd(); + + //4. if macthed then the current rack rate is applicable and find common variables link max age,max count,grade, basic pay,SI, self/acting self for current rack rate + + foreach($family_data as $fkey => $member) + { + // dd($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 + + $fileArr['grid_info'] = ['type' => isset($member['temp']['grid_name']) ? $member['temp']['grid_name'] : NULL , 'grid_id' => isset($member['temp']['grid_master']['ui_type']) ? $member['temp']['grid_master']['ui_type'] : NULL]; + + + + //set self (first index of familiy) SI and grade to rest of the familiy + $member[6] = $family_data[0][6]; + $member[10] = $family_data[0][10]; + $member[18] = $family_data[0][18]; + //set default unit if unit is not available in self/members level + if(empty($member[18])){ $member[18] = $existing_units[0]; } + //transform as db row column + $transformed_familiy_member_data = transform_excel_data_to_db($member,$fileArr); + // kint::dump($transformed_familiy_member_data); + //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') + { + $temp_res = generate_relationship_code($transformed_familiy_member_data); + $transformed_familiy_member_data['relationship_code'] = $temp_res['relationship_code']; + $transformed_familiy_member_data['emp_type'] = $temp_res['emp_type_code']; + } + + // // 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', + // 'isPrimaryGridPremiumTypeSingle' => $transformed_familiy_member_data['temp']['premium_type'] == 1, + 'isCurrentRelationshipSelf' => (strtolower($transformed_familiy_member_data['relationship']) == 'self' || (isset($transformed_familiy_member_data['temp']['acting_self']) && $transformed_familiy_member_data['temp']['acting_self'] === true)), + 'isBasicCoverCalculatedToCurrentEmployee' => ($transformed_familiy_member_data['policy_details']['basic_cover_si'] != null && $transformed_familiy_member_data['policy_details']['basic_cover_si'] != 0) + ]; + + $primaryGridTypeCondition = $conditions['isCurrentActionDependentAddition'] && $conditions['isPrimaryGridPremiumTypeSingle'] && $conditions['isCurrentRelationshipSelf'] && $conditions['isBasicCoverCalculatedToCurrentEmployee']; + + // // Final combined condition + if ($conditions['isEmployeeSourceEnrollment'] || $conditions['isEmployeeSourceExcelFile'] || $primaryGridTypeCondition ) { + + $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$temp_slab_rates,$default_si); + + $result[] = $transformed_familiy_member_data; + } + + + // $result[] = $transformed_familiy_member_data; + } + + // dd($result); + return ($result); + // + + + } +} + if (!function_exists('transform_excel_data_to_db')) { @@ -878,14 +1003,16 @@ if (!function_exists('transform_excel_data_to_db')) else if($actionArr['action'] == 'deletion'){ $current_column_action = 'D'; } else if($actionArr['action'] == 'correction'){ $current_column_action = 'C'; } else if($actionArr['action'] == 'si_enhancement'){ $current_column_action = 'SI'; } + else if($actionArr['action'] == 'missed_inception'){ $current_column_action = 'MI'; } - if($actionArr['action'] == 'inception' || $actionArr['action'] == 'addition' || $actionArr['action'] == 'dependent_addition') + if($actionArr['action'] == 'inception' || $actionArr['action'] == 'missed_inception' || $actionArr['action'] == 'addition' || $actionArr['action'] == 'dependent_addition') { $policy['basic_cover_si'] = $memArr[6]; $policy['pre_existing_alignments'] = $memArr[14]; // $policy['date_of_exit'] = isset($memArr[16]) ? change_date_format($memArr[16],'d-M-Y','Y-m-d') : NULL; // $policy['reason_for_exit'] = $memArr[17]; + $policy['client_policy_id'] = $actionArr['policy_id']; $policy['date_coverage'] = isset($memArr[7]) ? convert_string_to_date($memArr[7],'Y-m-d') : NULL; $policy['policy_end_date'] = null; @@ -910,6 +1037,9 @@ if (!function_exists('transform_excel_data_to_db')) $result['file_id'] = $actionArr['id']; $result['client_id'] = $actionArr['client_id']; $result['change_event'] = $memArr[15]; + $result['unit'] = $memArr[18]; + $result['temp'] = []; + if(isset($memArr['temp'])) $result['temp'] = array_merge($result['temp'],$memArr['temp']); $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; @@ -964,13 +1094,21 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details'] = replace_original_data(original_data:$original_emp_policy_records,current_data:$emp_data['policy_details']); // Kint::dump($policy_data); } - } - //end of fetching data from audit history table + + }//end of fetching data from audit history table //gird and calculation start $slug = \Config\Services::slug(); $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']; + $slab_index = isset($emp_data['temp']['grid_name']) ? $emp_data['temp']['grid_name'] : false; + // echo $emp_data['name']; + // kint::dump($slab_index); + if ($slab_index === false) + { + // echo 'not set'; + return false; + } + $temp_slab_rates = $slab_details[ $slab_index ]['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') @@ -984,6 +1122,7 @@ if (!function_exists('premium_calculation_manager')) } // dd($emp_data); $is_match_found = false; + $gst = isset($policy_terms['gst']) && $policy_terms['gst'] != 0 ? $policy_terms['gst'] : 18; switch ($grid_type) { case "1": //GPA - Sum Insured (SI) * Multiplier @@ -991,7 +1130,7 @@ if (!function_exists('premium_calculation_manager')) $employee_received_band = $emp_data['temp']['band']; 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['unit'] == $emp_data['unit']) || ($slab_value['grade'] != null && $slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'])) { $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']); @@ -999,7 +1138,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1011,7 +1150,7 @@ if (!function_exists('premium_calculation_manager')) $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($temp_slab_rates as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit']) { $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']); @@ -1019,7 +1158,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1030,7 +1169,7 @@ if (!function_exists('premium_calculation_manager')) $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; 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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['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']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1038,7 +1177,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1053,7 +1192,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // dd($slab_value); $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1062,7 +1201,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1074,7 +1213,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['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']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1082,7 +1221,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1094,7 +1233,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // echo $emp_data['name']; $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; @@ -1103,7 +1242,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1116,7 +1255,7 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { $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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['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']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1124,7 +1263,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; @@ -1138,7 +1277,7 @@ if (!function_exists('premium_calculation_manager')) 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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['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']; @@ -1147,7 +1286,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1160,7 +1299,7 @@ if (!function_exists('premium_calculation_manager')) 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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) + if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['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']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); @@ -1168,7 +1307,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.',''); $is_match_found = true; break; } @@ -1176,7 +1315,7 @@ if (!function_exists('premium_calculation_manager')) break; case "10": //GMC - Maximum age of Dependents - $max_age = $emp_data['temp']['maxage']; + $max_age = $emp_data['temp']['max_age']; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; // echo $emp_data['name'].'-'.$employee_received_si.'
'; // echo $emp_data['temp']['grid_type'].'
'; @@ -1184,10 +1323,10 @@ if (!function_exists('premium_calculation_manager')) foreach ($temp_slab_rates as $skey => $slab_value) { // echo $slab_value['si'].'-'.$slab_value['age_from'].'-'.$slab_value['age_to'].'-'.$max_age.'
'; - if( $slab_value['si'] == $employee_received_si && + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($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']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self'])) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) ) + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['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']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; @@ -1195,7 +1334,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.','')); $is_match_found = true; break; } @@ -1203,16 +1342,16 @@ if (!function_exists('premium_calculation_manager')) break; case "11": //GMC - Maximum count per Family - $max_count = $emp_data['temp']['maxcount']; - $employee_received_band = $emp_data['temp']['band']; + $max_count = $emp_data['temp']['max_count']; + $employee_received_band = $emp_data['band']; // echo $employee_received_band; $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $emp_data['policy_details']['basic_cover_si'] = null; 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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_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['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && + ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { //calculate premium based on count // echo $emp_data['name']; @@ -1223,9 +1362,9 @@ if (!function_exists('premium_calculation_manager')) $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']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); - $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: $temp_slab_rates,si_amount: $familiy_si_covered,band: $employee_received_band,unit:$emp_data['unit']); $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 + 1)); - $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'] * ($gst/100)),2,'.','')); $is_match_found = true; break; } @@ -1241,7 +1380,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['basic_cover_si'] = null; 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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($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']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1250,7 +1389,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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 + 1)); - $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'] * ($gst/100)),2,'.','')); $is_match_found = true; break; } @@ -1266,7 +1405,7 @@ if (!function_exists('premium_calculation_manager')) $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; 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' || $emp_data['temp']['primary_rack_rate_acting_self'] || $emp_data['temp']['additional_rack_rate_acting_self']) )) ) + if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($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']['acting_self'] ) )) ) { $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; @@ -1275,7 +1414,7 @@ if (!function_exists('premium_calculation_manager')) $emp_data['policy_details']['days'] = (calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days + 1); $emp_data['policy_details']['premium'] = $slab_value['premium']; $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'] * ($gst/100)),2,'.','')); $is_match_found = true; break; } @@ -1295,7 +1434,7 @@ if (!function_exists('premium_calculation_manager')) { $log_message .= ' - skipping, calculating only self..!'; //reset emp si and others policy level data if premium only for self - $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']['basic_cover_si'] = 0; $emp_data['policy_details']['premium'] = 0; $emp_data['policy_details']['rata_premimum'] = 0; @@ -1347,6 +1486,7 @@ if (!function_exists('transform_db_data_to_excel')) $row[14] = $value['pre_existing_alignments']; $row[16] = isset($value['date_of_exit']) ? change_date_format($value['date_of_exit'], 'Y-m-d', 'd-M-Y') : NULL; $row[17] = $value['reason_for_exit']; + $row[18] = $value['unit']; $row[7] = isset($value['date_coverage']) ? change_date_format($value['date_coverage'], 'Y-m-d', 'd-M-Y') : NULL; @@ -1461,11 +1601,12 @@ if(!function_exists('replace_original_data')) if(!function_exists('get_premium_for_si')) { - function get_premium_for_si(array $slab_details,string $si_amount,string $band) + function get_premium_for_si(array $slab_details,string $si_amount,string $band,string $unit) { - foreach ($slab_details['slab_rates'] as $skey => $slab_value) + // dd($slab_details); + foreach ($slab_details as $skey => $slab_value) { - if($slab_value['si'] == $si_amount && $slab_value['grade'] == $band && $slab_value['max_si'] == 0) + if($slab_value['si'] == $si_amount && $slab_value['grade'] == $band && $slab_value['unit'] == $unit && $slab_value['max_si'] == 0) { return $slab_value['premium']; } @@ -1632,4 +1773,254 @@ if(!function_exists('transform_enrollment_row_to_inception_row')) $res[17] = null; // inception: reason_for_exit (Reason for exit) -> No match in enrollment return $res; } +} + +if(!function_exists('get_familiy_composition')) +{ + + function get_familiy_composition($family_data) + { + // dd($family_data); + $family_composition = []; + $slug = \Config\Services::slug(); + foreach ($family_data as $key => $row) + { + // Kint::dump($row); + $relationship = $slug->slugify($row[5]); + // echo $relationship; + if($relationship == 'self') + { + $family_composition['self'] = 1; + } + else if(!array_key_exists('self', $family_composition)) + { + $family_composition['self'] = 0; + } + + if($relationship == 'spouse') + { + $family_composition['spouse'] = 1; + } + else if(!array_key_exists('spouse', $family_composition)) + { + $family_composition['spouse'] = 0; + } + + if($relationship == 'son' || $relationship == 'daughter') + { + $family_composition['childrens'] = (isset($family_composition['childrens']) ? $family_composition['childrens'] + 1 : 1); + } + else if(!array_key_exists('childrens', $family_composition)) + { + $family_composition['childrens'] = 0; + } + + if($relationship == 'father' || $relationship == 'mother') + { + $family_composition['parents'] = (isset($family_composition['parents']) ? $family_composition['parents'] + 1 : 1); + } + else if(!array_key_exists('parents', $family_composition)) + { + $family_composition['parents'] = 0; + } + + if($relationship == 'father-in-law' || $relationship == 'mother-in-law') + { + $family_composition['parents-in-law'] = (isset($family_composition['parents-in-law']) ? $family_composition['parents-in-law'] + 1 : 1); + } + else if(!array_key_exists('parents-in-law', $family_composition)) + { + $family_composition['parents-in-law'] = 0; + } + + } + + return ($family_composition); + } +} + +if(!function_exists('compare_incoming_family_slab_with_configured_slab')) +{ + // function compare_incoming_family_slab_with_configured_slab($slab,$incoming_familiy_composition) + // { + // $relationship_mapping = [ + // "self" => ["self"], + // "spouse" => ["spouse"], + // "childrens" => ["son", "daughter"], + // "parents" => ["father", "mother"], + // "parents-in-law" => ["father-in-law", "mother-in-law"], + // "either-parents-pil" => ["either-parents-pil"] + // ]; + + // $result = ['is_applicable' => false,'applicable_members' => []]; + // $configured_familiy_composition = json_decode($slab['slab_rates'][0]['additional_relationship'],true); + // Kint::dump($incoming_familiy_composition);//die(); + // Kint::dump($configured_familiy_composition);//die(); + // unset($configured_familiy_composition['either-parents-pil']); + // unset($configured_familiy_composition['elders_count']); + + // if(count($configured_familiy_composition)) + // { + // foreach($configured_familiy_composition as $key => $value) + // { + // if($value != 'NA') + // { + // // echo 'OUTSIDE - ' . $value . $incoming_familiy_composition[$key]; + // if(isset($incoming_familiy_composition[$key]) && ($incoming_familiy_composition[$key] == $value || $value == 'any') ) + // { + // // echo 'INSIDE - ' . $value; + // $result['is_applicable'] = true; + // $result['applicable_members'] = array_merge($result['applicable_members'],$relationship_mapping[ $key ]); + // } + // else + // { + // $result['is_applicable'] = false; + // $result['applicable_members'] = []; + // // break; + // } + // } + // } + // } + // else + // { + // $result['is_applicable'] = false; + // $result['applicable_members'] = []; + // } + // // dd($result); + // return $result; + // } + + function compare_incoming_family_slab_with_configured_slab($slab, $incoming_familiy_composition) +{ + $relationship_mapping = [ + "self" => ["self"], + "spouse" => ["spouse"], + "childrens" => ["son", "daughter"], + "parents" => ["father", "mother"], + "parents-in-law" => ["father-in-law", "mother-in-law"], + "either-parents-pil" => ["either-parents-pil"] + ]; + + $result = ['is_applicable' => false, 'applicable_members' => []]; + $configured_familiy_composition = json_decode($slab['slab_rates'][0]['additional_relationship'], true); + + // Remove unnecessary keys + kint::dump($incoming_familiy_composition); + kint::dump($configured_familiy_composition); + unset($configured_familiy_composition['either-parents-pil']); + unset($configured_familiy_composition['elders_count']); + + // foreach ($configured_familiy_composition as $key => $value) { + // if ($value === 0) { + // // If any relationship is zero, make the rack rate not applicable + // return $result; + // } + // } + + if (count($configured_familiy_composition)) { + foreach ($configured_familiy_composition as $key => $value) { + if ( $value != 'NA') { + if (isset($incoming_familiy_composition[$key])) { + if ($incoming_familiy_composition[$key] == $value || $value == 'any') { + $result['is_applicable'] = true; + $result['applicable_members'] = array_merge($result['applicable_members'], $relationship_mapping[$key]); + } else { + $result['is_applicable'] = false; + $result['applicable_members'] = []; + break; + } + } else { + $result['is_applicable'] = false; + $result['applicable_members'] = []; + break; + } + } + } + } else { + $result['is_applicable'] = false; + $result['applicable_members'] = []; + } + // dd($result); + return $result; +} + + +} + +if(!function_exists('get_applicable_familiy_members')) +{ + function get_applicable_familiy_members($family_data,$applicable_members) + { + $slug = \Config\Services::slug(); + $result = ['index' => [],'max_age'=> [],'max_count' => 0]; + foreach ($family_data as $index => $family_member) + { + if(in_array($slug->slugify($family_member[5]),$applicable_members)) + { + $result['index'] = array_merge($result['index'],[$index]); + $result['max_age'] = array_merge($result['max_age'],[calculate_days_bw_dates(from_date: $family_member[3])->y]); + } + } + $result['max_count'] = count($result['index']); + return $result; + } +} + +if(!function_exists('check_unit')) +{ + function check_unit($row,$existing_units) + { + + + if(in_array($row['current_action'], ['I','A','MI']) ) + { + if(count($existing_units) == 1) + { + if(empty(trim($row[18]))) + { + return array('status' => true); + } + } + + if(strtolower($row[5]) == 'self') + { + if(in_array(trim($row[18]),$existing_units)) //18 is unit name + { + return array('status' => true); + } + else if(!empty(trim($row[18]))) + { + return array('status' => false,'error' => 'wrong unit name'); + } + else + { + return array('status' => false,'error' => 'name of the unit is mandantory'); + } + } + else + { + if(empty(trim($row[18]))) + { + return array('status' => true); + } + else + { + if(in_array(trim($row[18]),$existing_units)) //18 is unit name + { + return array('status' => true); + } + else + { + return array('status' => false,'error' => 'wrong unit name'); + } + } + } + + + } + else + { + return array('status' => true); + } + } } \ No newline at end of file diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index cd0bda80..7b8fc5c8 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -149,7 +149,7 @@ class sendMailNotification return $wholeData; } else if($action == 'member_review_and_summary_mail'){ - $array_list = $params['array_list']; + $array_list = $params['array_list'];//employeee lst $client_policy_id = $params['client_policy_id']; $emp_code = $params['emp_code']; $client_id = $params['client_id']; diff --git a/app/Models/ClientBranchModel.php b/app/Models/ClientBranchModel.php index ee36cbb4..100f503d 100644 --- a/app/Models/ClientBranchModel.php +++ b/app/Models/ClientBranchModel.php @@ -39,4 +39,14 @@ class ClientBranchModel extends Model ->getResult(); } + public function getExisitingUnits(string $client_id,string $client_branch_id) + { + $res = $this->select('client_branch.units') + ->where('client_id', $client_id) + ->where('id', $client_branch_id) + ->find(); + //->getResult(); + return (json_decode($res[0]['units'])); + } + } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 13a1e5e7..aa1fb9fa 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -41,6 +41,7 @@ class EmployeeModel extends Model "client_branch_id", "token_time_out", "emp_type", + "unit", "mpin" ]; @@ -105,7 +106,7 @@ class EmployeeModel extends Model public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [],array $client_branch_id = []) { - $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policies.name as policy_name','client_policy.is_addon']) + $result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policies.name as policy_name','client_policy.is_addon']) ->join('employee_polices', 'employee_polices.employee_id = employees.id') ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') ->join('policies', 'policies.id = client_policy.policy_id') @@ -158,9 +159,9 @@ class EmployeeModel extends Model } // for EMP rest API process do not change - public function checkExistingEmployee($arr) + public function checkExistingEmployee($arr,$client_branch_id) { - return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->first(); + return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->where('client_branch_id', $client_branch_id)->first(); } diff --git a/app/Models/FileModel.php b/app/Models/FileModel.php index 51f397ec..9262e796 100644 --- a/app/Models/FileModel.php +++ b/app/Models/FileModel.php @@ -19,6 +19,7 @@ class FileModel extends Model "client_id", "policy_id", "client_branch_id", + "uploaded_by" ]; diff --git a/app/Models/PolicesModel.php b/app/Models/PolicesModel.php index 8fd138a1..cd1c62ba 100644 --- a/app/Models/PolicesModel.php +++ b/app/Models/PolicesModel.php @@ -60,9 +60,20 @@ class PolicesModel extends Model if(isset($premium_slab_data[0]['policy_grid_id'])) { - $grid_id = $premium_slab_data[0]['policy_grid_id']; - $policyGridModel = new PolicyGridModel(); - $grid_type = $policyGridModel->find($grid_id); + $pre_grid_id = 0; + $grid_type = []; + foreach ($premium_slab_data as $key => $value) + { + if($value['policy_grid_id'] != $pre_grid_id) + { + $grid_id = $value['policy_grid_id']; + $policyGridModel = new PolicyGridModel(); + $grid_type = $policyGridModel->find($grid_id); + $premium_slab_data[$key]['grid_master'] = $grid_type; + } + $premium_slab_data[$key]['grid_master'] = $grid_type; + } + } if(isset($additional_premium_slab_data[0]['policy_grid_id'])) { diff --git a/app/Views/rack_rate_test.php b/app/Views/rack_rate_test.php new file mode 100644 index 00000000..6d8d2b58 --- /dev/null +++ b/app/Views/rack_rate_test.php @@ -0,0 +1,689 @@ + + +
+
+
+
+
+ + + +
+
+
+ +
+
+
+ +
+ + +
+
+ +
+ +
+
+ +
+ + + +
+ + +
+
+
+
+
+
+ + + +
+
+
+
+
+ + +
+ + + + + + + + + + + + + + + + + + + + +
SNOEmp codeNameDOBGenderRelationSIDOCBasic payBandUnitDelete
+
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/public/sample_excel/enrollment.xlsx b/public/sample_excel/enrollment.xlsx new file mode 100644 index 00000000..dec7c20f Binary files /dev/null and b/public/sample_excel/enrollment.xlsx differ diff --git a/public/sample_excel/sample_addition.xls b/public/sample_excel/sample_addition.xls index 934df3cd..ae5b59e2 100644 Binary files a/public/sample_excel/sample_addition.xls and b/public/sample_excel/sample_addition.xls differ diff --git a/public/sample_excel/sample_dependent_addition.xls b/public/sample_excel/sample_dependent_addition.xls index 7e0dd112..8660e1b9 100644 Binary files a/public/sample_excel/sample_dependent_addition.xls and b/public/sample_excel/sample_dependent_addition.xls differ diff --git a/public/sample_excel/sample_inception.xls b/public/sample_excel/sample_inception.xls index a8e2aeb1..695c681a 100644 Binary files a/public/sample_excel/sample_inception.xls and b/public/sample_excel/sample_inception.xls differ diff --git a/tests/unit/PremiumCalculationTestNew.php b/tests/unit/PremiumCalculationTestNew.php new file mode 100644 index 00000000..18087991 --- /dev/null +++ b/tests/unit/PremiumCalculationTestNew.php @@ -0,0 +1,228 @@ + 4,'policy_type' => 'GMC','ui_type' => $primary_grid_id,'policy_grid_type' => $primary_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; + $primary_slabs = [ + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship], + [ '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,'additional_relationship' => $primary_relationship] + ]; + + //second slab + $second_relationship = '{"self":"NA","spouse":"NA","childrens":"NA","parents":"any","parents-in-law":"NA","either-parents-pil":0}'; + $second_grid_id = 10; + $second_grid_type = 1; + $second_max_si = 35000000; + $second_grid_name = 'max age'; + $second_grid_master = ['id' => 4,'policy_type' => 'GMC','ui_type' => $second_grid_id,'policy_grid_type' => $second_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; + $second_slabs = [ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 700, 'max_si' => 2500000,'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship ], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1400, 'max_si' => 2000000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2300, 'max_si' => 1800000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2750, 'max_si' => 150000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3500, 'max_si' => 130000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 4250, 'max_si' => 10, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4950, 'max_si' => 5, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 5500, 'max_si' => 5, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship] + + ]; + + // third slab + $third_relationship = '{"self":"NA","spouse":"NA","childrens":"NA","parents":1,"parents-in-law":"NA","either-parents-pil":0}'; + $third_grid_id = 7; + $third_grid_type = 1; + $third_max_si = 35000000; + $third_grid_name = 'age band'; + $third_grid_master = ['id' => 4,'policy_type' => 'GMC','ui_type' => $third_grid_id,'policy_grid_type' => $third_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; + $third_slabs = [ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 701, 'max_si' => 2500000,'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship ], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1401, 'max_si' => 2000000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2301, 'max_si' => 1800000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2751, 'max_si' => 150000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3501, 'max_si' => 130000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 4251, 'max_si' => 10, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4951, 'max_si' => 5, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 5501, 'max_si' => 5, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship] + + ]; + + + // fourth slab + $fourth_relationship = '{"self":"NA","spouse":"NA","childrens":"NA","parents":"NA","parents-in-law":2,"either-parents-pil":0}'; + $fourth_grid_id = 11; + $fourth_grid_type = 2; + $fourth_max_si = 8000000; + $fourth_grid_name = 'age band'; + $fourth_grid_master = ['id' => 4,'policy_type' => 'GMC','ui_type' => $fourth_grid_id,'policy_grid_type' => $fourth_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; + $fourth_slabs = [ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 1111, 'max_si' => $fourth_max_si,'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship ], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 2222, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 3333, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 4444, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 5555, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 6666, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 7777, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 8888, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 8000000, 'premium' => 9999, 'max_si' => 0, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship] + + ]; + + //overall rack rate + $over_all_rack_details = [ 'primary' => [ "slab_rates" => $primary_slabs,'grid_master' => $primary_grid_master], + 'two parent' => ["slab_rates" => $second_slabs,'grid_master' => $second_grid_master], + 'single parent' => ["slab_rates" => $third_slabs,'grid_master' => $third_grid_master], + 'double_parent_in_law' => ["slab_rates" => $fourth_slabs,'grid_master' => $fourth_grid_master] + +]; + + // Sample family data + $family_details = [ + [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, + 'spouse' => 1, + 'childrens' => 2, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + //re organize over_all_rack_details + $all_rack_rates = []; + foreach ($over_all_rack_details as $key => $value) { + foreach ($value['slab_rates'] as $skey => $svalue) { + $svalue['rack_rate_name'] = $key; + $svalue['grid_master'] = $value['grid_master']; + $all_rack_rates[] = $svalue; + } + // dd($value['slab_rates']); + } + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms),'gst' => 5]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception','client_branch_id' => 1,'created_by' => 1]; + $data = calculate_premimum_new($family_details,$policy_details,$all_rack_rates,$file); + //****************************onboard process******************* + // $empServiceController = new EmployeeServiceController(); + // $empServiceController->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); + + // dd(); + //******************************** onboard process**************** + $policy_created_count = 0; + echo "\n"; + $result_to_display = []; + foreach ($data as $key => $value) + { + if(is_array($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 = ($value['temp']['grid_name']); + $temp_grid_type = ($value['temp']['premium_type']); + $temp_grid_type = ($temp_grid_type == 1 ? 'S' : 'I'); + $result_to_display[$key]['premium_type'] = $temp_grid.'#'.$value['temp']['grid_id'].'#'. + ($value['temp']['acting_self'] == true ? 'Self' : 'No' ) .'#'. ($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 + 1); + $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; + } +}