From 47722d56788f5d8579b9206c15c757b53017b1aa Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 23 Jul 2024 15:06:15 +0530 Subject: [PATCH 1/5] CHANGE_DYNAMIC_RR&ENROLLMENT&MISSED_INCEPTION&MINOR_ISSUES --- app/Config/Routes.php | 2 + app/Controllers/EmployeeController.php | 91 ++- app/Controllers/EmployeeRestController.php | 2 +- app/Controllers/EmployeeServiceController.php | 265 ++++++- app/Controllers/JobWorker.php | 133 +++- app/Filters/AuthJWT.php | 3 + app/Helpers/MailHelper.php | 5 + app/Helpers/excel_util_helper.php | 489 +++++++++++-- app/Helpers/sendMailNotification.php | 2 +- app/Models/ClientBranchModel.php | 10 + app/Models/EmployeeModel.php | 9 +- app/Models/FileModel.php | 1 + app/Models/PolicesModel.php | 17 +- app/Views/rack_rate_test.php | 689 ++++++++++++++++++ public/sample_excel/enrollment.xlsx | Bin 0 -> 7646 bytes public/sample_excel/sample_addition.xls | Bin 9728 -> 9728 bytes .../sample_dependent_addition.xls | Bin 7680 -> 7680 bytes public/sample_excel/sample_inception.xls | Bin 9728 -> 9728 bytes tests/unit/PremiumCalculationTestNew.php | 228 ++++++ 19 files changed, 1840 insertions(+), 106 deletions(-) create mode 100644 app/Views/rack_rate_test.php create mode 100644 public/sample_excel/enrollment.xlsx create mode 100644 tests/unit/PremiumCalculationTestNew.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 77cf4c62..0a25f065 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -137,6 +137,8 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); $routes->get("endorsement-list", "EmployeeController::endorsementList"); $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); + $routes->get("test-rack-rate", "EmployeeController::testRackRate"); + $routes->post("test-rack-rate", "EmployeeController::testRackRate"); }); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index ec8467e6..45022686 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -212,6 +212,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'); @@ -220,7 +221,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 @@ -236,9 +237,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']; @@ -357,6 +359,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 @@ -674,14 +680,14 @@ class EmployeeController extends AdminController // client_policy_id pull draft and enrolled status employees and proceed to calculatin and make entry in DB public function initiateManualEmployeesOnboardProcess($client_policy_id) { - $client_data = $this->clientPolicyModel->select('clients.client_name as client_name, policies.name as policy_name') + $client_data = $this->clientPolicyModel->select('clients.client_name as client_name, policies.name as policy_name,client_branch_id') ->join('clients', 'clients.id = client_policy.client_id') ->join('policies', 'policies.id = client_policy.policy_id') ->where('client_policy.id', $client_policy_id) ->first(); $empServiceController = new EmployeeServiceController(); - $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id]); + $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id,'client_branch_id' => $client_data['client_branch_id']]); // dd($res); $count = count($res); @@ -1370,4 +1376,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 10aac50d..09d08c51 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -823,7 +823,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 fdeca4c1..8133244d 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,9 +1248,12 @@ 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()]; + $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']]; // dd($this->employeeModel->getLastQuery()); // Kint::dump($existing_famility_details);die(); $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); @@ -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 38fd648a..c6bf8829 100644 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -14,25 +14,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/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 0c8c7067..0b9e75b0 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -125,7 +125,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 c6083a49..87e68975 100644 --- a/app/Models/ClientBranchModel.php +++ b/app/Models/ClientBranchModel.php @@ -38,4 +38,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 adffe7ff..37844905 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -40,7 +40,8 @@ class EmployeeModel extends Model "is_createdby_hr", "client_branch_id", "token_time_out", - "emp_type" + "emp_type", + "unit" ]; // Callbacks @@ -104,7 +105,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') @@ -157,9 +158,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 0000000000000000000000000000000000000000..dec7c20ffda4228bd47b41a2be60ea38311f37f9 GIT binary patch literal 7646 zcmaJ`1z1#V)216)I;2awYf0&D>5}g5QbHOL3F&T-5S9)pDVLV+4hiWJ_!r;z`sDNf z-govoXLqmbJae8iGiUCZdsO6M;c%dkkdUB4_)fK<9tkSsw~>pvohvKL!?`@JL#c}m zE%eYglHr1T;W<)HVY7lvGX)oEJGH~p+K9aF;Nx=%Y%H|5)m<^puU_Ao6f7z@FfFpt z${R*#=tRJ@(wh1gb$`8c_GaZ7%zf2^$tSJmD9+&WPFe00ydpY~@9P#Thq8U5C_f6l zWx8huCGE^3Q_mx59+|*ewT~=cZpMhs; z)@jwt1Od%-$pn2W?Z6D(7ArSAmD!sf#ZOgm=xa-Wan|Q;_GmvkHKDZSMNooDj9hcH z!>ZWsgLA&Btyhg+eL@H!35V`~KRqYM^`ZPjLF|ud?)9U>E3j>DhEodX>od8VvLlX6 zvKU3V8Ft1-(DS#N*QYc$Pk?ID`f{7N#1!d>Yr-2CNN*El&HHBfN#WD?4!vyoyY=k5 zqcrEDWtgfsSDz`HJyb9RYg$i!QoqPiX3xVlSe#crxTZ$=Xcagak$vD3x~?9F?i9B$ooXE4TdHb z10{b3>@cpaQv4l$uBbp)P4e|SyJtY zc?>f^ZVTQsLNZ~S+Ob)8ZWkgsA*BAAI)iqbqL`R zuGqmW@RA_0p?b+^3kH%|-hBZCDNy234iILxa}O=g?I^D)RM58>ykrWDY_CSvmr1$X z+{u;g$uCcAgspH*txr3r2Mt#DB3nWbB0)N8Jc(dsYuSRw)kJS_tXXf3xzWJ3FOY z6`1arPcR8hQsCLVR=fi7+FONj=k6Iz=Bbb#4iZbF4x!uuv(8+&v?Br0XcbI3B!j1U zMd%$c5ekaAfg3ss#Z)jJLvVLn9OM)*_2K5dRvf(e`PwG_<>1xH8n8?d=MPemfTx+{ zli+pI+&1UU1XS|XE4b@d&+f}CTci@e@ZSC2cd%a>b0)12?pC9Dsf zs|}?+0-fT{>=wVw9S(bF*?fV8kF+cpYu@Q6c|&&~Sir*}Ge&g<2~R(^k^#h0<~2^? z9-KryLhE`0kZFnI)u+UkboK$zWzd__3mO||Y8!mT3#ww}JcvK8j-zL`h8hTFBq-Bm;XVnSb|lrH0hVoirbppUq@1O zy2nDi$+!?b&m#RN!VIjGS$Us}kexj*dDdyr=fdyrQnY-eMZ)G@FI3``1!yc2<5Xb; zl4(KtH*2V?50p4~rVLgNv?ckTwoNhke6*hd@Cy~^X&&ayCNop%-)>?dv=C6e?mG`(LL(4#htQ5pgecDXk< zu-g^{wQ6_m?v+ihSs!vuwDIP5b~q>~JNAFeH3Yvw%GJu;+|8Bs*BARk+G*7`a82Wb zq#dJ_&Go_MX@RS&FF&@eY>fiqJDwFyV658S7JriS61*v}-&0XTj)Wqd=_- zedGN8tu3Zno@8gSlal@O>$;GW@E&R-#r;DJOET%YFYp7V31h^{`}pAf;hN91dIOnW zL7%Du$hXu5Fmw4_h)HSq#9O3M)5VA5s?m@e%o)S*(ekv>2h@7MUmz-l$~YvUN$&xk zH0j47v08zKoLJN4yQBMf-g-%>)0j?1a-rss*5&VgYk@{D5Zb~k%kgA z44`wS-k}EeVav^1qWGtsFL)*RH}?Cgw_|lI!iCDC-nAP%FC>+f>yApT5=x`H6R=>G zWngR0VNY(6pzj^g%EoQ$UG>em{sP+?9BNR{nZ`G z3aZy{uJaPBw*)NlOZrI{5e*YYRLaKWXjHjRT)uVK;%W`hf1a{Sa&Ig%TM_tP0|wJ@ zt)Q45-lwIPJ_au4%(>q7eNf-6{JG3{DtV7QNGSvjdYx{r){%U*B;%`F;d5D3diGvx z{#sUpxk&1BtV_f|`&PBo1!=kv>c(4@=KIpnv~rG&sqK&o4P7%i z7Pn~VGVR)RkwmN+*QGmFNz+l3b8{D$C+G4)9-(#}$pYy0y5E@wc<^H^*ycr?l8)p? z7cnwd8e3Csa;FQf8NJa5gK}2X*(7*-3ALc5VkcZf+ZZv6<2m&jl`iSIuU<<8@DrG29rz54(9I+_2^Q6=p#cuBi0_$+dA63d8B9mze{SQd> zm7-FLeHsF>&e%r<9xhoNRAo~n0IG6cl30I361vnT7r`2fQjSXl$+bjT7Y!?KEyZ*$ za*fl_trM2$mFwJ2uhbWSYbsa|-44Hu0lIfJEWo_yLyQVP>gFZk$8FoW8B02?6uR0_ zS>^MN+QausgLo#BRo#u;nou|nDiH25w1Sr^5KM2gF89Cr_CzLo8b_DvUM@_$TtE3H zl1%<|KN+e@n4=z8BKHU!X+=}5ggFjbb*9dmO$ZtwXWV~ux?1hmgX z>x<>KKB+AR+1>kTNvGt64rmY0{*)*YKJY6Bp4tMA#*nNsW;@-^mO{*U3Ckaajj^29=@4}h@!nU z!gh1}o-_Matl|CgfrOW5-L>Ccq#5rcr!k@DUe+K&cfY}>_eq(hQyM|oc$!eSo`q|7 zs@@ou#F|YTT*>Z5)D`I<8B|@5h&cPwC}~)g^s^Axw@`%Hk!K(Z@_FLDZ6F;%{}=n5 zCt4rjc$TS+_IdZpZY>t<8hdZ>Z3g-n2jS(m`0$ghEAO9z;UZ>9l)R6ff~O+`oJ#9X zZx@}o(8~Pp?(jT1cc&RnL(dQ=H>q%|2%3Gc++(VqX{#}Se2aw7wDGHELiOk4r(A+N zJfHe%_v~_+)eBTOe7~)-myOgbbTerhB*RKy>a<(&ZbwqkB+*jb58~(m1ls>Jjm#}t z6TEv5P$jFb%Aht^(3~jW-1>*FDt`}$^`13YTlyq)78>E zed?-iNr!477oj&)!?jIOPeC~`KoA$E)|KxK2Mm;I+iB9ve8oBK)Mm%)GMt;0xxG2-uk$Zp{i0>$n8pTpy;M~7vyG_pGqufFn8zq7zv65Y#xen{ zp?$Djy+PY;GzB!w4kh!-m5{+^?71%dSPZh&DS_khD0N9- z_-QeS5@V5xPZgN*ro4?``ZJhAYFk{^5H7KhJ(sSxM{Nqej0+A6_3Kd?Y*0}ux&C3v zt5wkCcx`~wSq9&oKYEyA*6p=)nV;`4uGbeocp*$WI%J&r$aUc3u?PhLMoi;RT;F_%NRd|ZaR?OJD;a{~nlX%+)D9_l1XK_8q^UVCOSZr7p7o&+H)1E5V_cIEZGS=U}NBueM|_DN$<7 zCOZXib~DnYj8fINWR|lEX0-$4D}?f~k_{v|6_^f4UF$T^1gl%v057yZ%tp4R)E~jz zd^{X^E7m-KM$eZ>Rk_k*K?9sGU1hCQ{=r~A7kVTAOQgp17&5#^LR(vVT3%aIo zhsL`_Ui;ZR<9uCAVsGH`!QtbGBJo~qduf&UHWR64s*Vx8R>RZplXexN8oNHyhtsv9 zzL-V>p!e5zZ6ec#UHR7e&SSXku@V(GF_cAqZJeyBP9Na5fG4f;UTHUn-r}uRvz^cl zuaYE;*9fhGfQsKQ>!g6UQW4PeB$R8J148x8NF?UFYC1K&UM;nfUIicBr6utB3VK&j zx9mS9yCi|{^%h4O0vd^j+S8a*$xHQ+EB2mtpVJ87B)XTHKY`wCyp^IToUtzedAB!N zd2H@B8Pg``pg7U)0r$g_z7D+=k#BjuYPn+IF0#!R$@SGvO-ZJy#K1OMp~8?fx-i-P zWbljLH4qPBgEXTwJgSx6XDFy7S09WqwsU@Zkx?vdEG*k0Ai5Idn3&moX;3reAl}>i z1ig)OWc#qwu=)=D;r)?n@BVrZp--40&F()_D3Gl5K%ux=8M~O9sk^yYJ6Qf|h%*xA z)H>M!p^!|Ya6rKvzQ$&+`hzW!j_Mf7wi!g|Qmj~fd|sIA8B>$oOudwOH%Ob}XZ1zb zE*(U>;ViO>rs#lbJ&;goDe_L$7eO zS{Ka^ja#*v6w$n0VJ6WW`)}SVZITlVNs4!4V`GWcYPcaZ3*$G#~`UIRq2_*)2qWx#ceqc+7A8 z#Rsa1+H|o2TDEXa4r}-F->5NdVWBh@?!dljsZ+3%wc@ouzA06-B1XzV%<2Z)ScV#Z zop9d%@=R*CMP0=Vh~(BYm0^qPx3`#S_)=qVfcZRi9KYIt{JjS;eHC~`LyiLvQ85K$ zdo2IRc_jU%o%x7GrC!2`pwR%|WWcVJx}6QYvpPPxM^V82=(*xJp}wyx!N?H_YQHsp ze0B_Tb&!!4Z4^^PU`v*?o~9Y8Y<#!pJ-%R4InAfOpC23nZDYlTNhYwE7|Jpc+_l=c5q zNn9iaVb&_B5&+f%*WFpn-sdKrjeVBP{G_n?@gq(CHWI>MP1+mA0b6wCCe7?}s5Ky! zHJujytZo@yPpD'S>#PM=~qqXo$~c+Ke7pJ1FM`f#*f>I^Y;mFHASNxM~pudGTu zn)c9KVshS~iM$!Cd zs==S(AG^YPu!-WL-XjE8REM@&-5c^y8BAc-+ovt`K69EI=7Pc3GnU^T7r)#Rw^(}c zQ_ahcRXKWJAi5nvp1|StA!y=w+@mD54S6yAldOPBtU_ z;)L`Pr#PY+W;CQ>I_zF7F|p|GXDP6$Z|!4X#~CG*<>k4Z9l$>iaoJl*_C*EI*QH`g z?M(yDUFjU=;t)%60=;Zhf?!3h>UpoDFk@4WxrlcX36U-^vcyW3k)X{}K&O&rYx#<6&?Fu8?v9|%KJy;t!J_6ANu)Rsi?%_If6fpO zh0pKEcXxGjwEtz)p-(8CY&an+3q?pXb1x9zkAb521YTUkF4jT2I`%0>`TJ4@9mIr@ z2`h~Y-HLw%%wXCyvNF;`VB*O$X2;tCKG}}`<(H&yvNsTznmwlUso=x=p`)0{ZGlBN zHU-l|%jii!Qx+;oN3~36HLjSU&Xm1X=y?7Y6RI;I*jJQ(z^kKO?pygMW=n^ci;fh& z_Ia-?=kOn%Yh@BDAPKVTBgpaZ&!s2s=-_7V;AZr~+sWM3;1^S((GMAc09r2?bM;kM zKfsF7Sz|Cs7fS%COqH?5z25JCI6owOrow<^@U1vW`v|OO(PAE-_%V-0`x$6pO_e{I zN=3mnXF%{(iV*eGk(pqhg)J;gr~bxq!|~!gU{xDFuIa^76#{xt;h8?&d%T8SLj^?7BIWC!-0v_cAoJu~RC@vc45X z^41#h81`F^y2IlO_J=Ctk`xfa3lEE;gcFa>6E`5qeKxuzUu=KW^OZsHcfD2$q3mOX zWf{(BAD&MuBJt$ybH4?Q_@Dd!KdSCeEsxuihwkmS96|Q;_wN7J z@;`gIKNUW%*B)N(-@*W~4n*OfJU+{#|iKOIDX40-lOGz!^oejAE%lBwj&k9+y5hF k{;A+`u>ZG$8;FAck(*TH;UVt@6cifdg9VAcx?i^YKZYAN%>V!Z literal 0 HcmV?d00001 diff --git a/public/sample_excel/sample_addition.xls b/public/sample_excel/sample_addition.xls index 934df3cdd3aff1c66d5ab4b18a5a7886a1581ad9..ae5b59e278f16ea9667144099846df482f8edd60 100644 GIT binary patch delta 863 zcmY+COK1~O6o&sZGnq*;O()Zt$)k@vn$|R?4+^fVUPGCil(3-Dp-wc z!9~x?g-`{pOYPvYh%N*d;zAKrM8QQDiXyrZ5xsMpbkbSOaL)hz=bm%!G-sMK4_@oa zFY@2$i!{5iv~cdknVe?hF1mnA;+Y?7H0HSs}id>+O=&b;c zEA9bG@o6_tX}<1GQieC&kWvIyMwU0-8ujviug~gh`Bka(^C_=J1N@{z(PZTufAMP7 zyr8cragk9`#Nic1o*fZ;Dx+N~*isnQ-_#SC#mS2qX!D1mg>z5DRdHasIsJVW#cro~m Ie-9e!f4Pp7_5c6? delta 955 zcmY*X&r1|x7=FHQX7<MQrUOmSZZJh-z0|DY@rRrE8~vMjb7nsMeto|;ZY z6zGXF<*T$xE4#FkwY82`a>q3kY2Ru1rI4?t}9ZkWr^{6SjJH~gWHZ)*OD ztkl)0nby$eo6N7`&}O0GmqWUx>1Q`vbgPT57EnWlHVO?0=#p&aq~+3-@M)vui(~YnG~!Q$ zTDwbYv$oP1o2|8jv|l>Ms=B)>KyO_)t=6TETphM$1>fBvgC3gsm*q1?>Lg|v!|u#D c)xBy0Z%)6uyt*gIGo7I6-4enL{tU;B{~Y;|r2qf` diff --git a/public/sample_excel/sample_dependent_addition.xls b/public/sample_excel/sample_dependent_addition.xls index 7e0dd11268506c3b9252cad8b0deda3b9b174d5e..8660e1b9b7a9ad2d357e32e94d3f0b8a31b79938 100644 GIT binary patch delta 527 zcmY+9J4*vW6ot>7oy{(Zo84@7V~h}uN#&ze5s`Fa=L4|`q7czSQ`n_2#==&?!Cu7| z*hH4pilvB^1QY~+fgp%rAvha@s{_Mu?>XPOcdDb+(b|K~-pOm|D>S)OT3TORP4gH| z&<2#{DGaQw6$XmMG`DdI11J{#mhAaznul-(0`fj|?n8fNZzufB#Ejv3RYNC&xHRJG zF{VfnhtYi+5<}*eHcedsQsT;dRXH$Q5*OAyrMz$~LYq1^{7^Y!FJj6U&6jc8ohM;} delta 519 zcmY+9yDtP$7{$+bXJ&Wo*qw)&v0lTXL!uFaVkIjg9zisc?G$AB3nW;DLPK%+10-IF zhFr81614;g357pEp;JiQ>$TkG<~!&7&b?o;x7d4hW3pR_J9C!C`bYaG`i3Lj#V*Q$ zDS7g3BP02?TrSc*>>&x{a!Qh#aw9#4eGrgU(1C*f+G0KN$jBG-$yy?lA15n}9gLI3 zw^Lix&O7au_z*<^s`$D6!cUw$RSDO%XxYM|DwEZlmMw35&I}CCL21^Yp%8?>z7G9g z-hhEux0H_|hO<;@jw6msr}CFKk^16WzaO+=WBX5m14jl*fGdBvDXzRzDkBz?kcWt` z`5E%~pw+;qAI5vX$Lrbs#Hike>7$zM8H#i`Uan&cXxn QjP8qzbQhyQyj91w4u93-5^$>V$SW}(luy1_z*()X$QOx9Z%vxY{0QA=XW2oIFd@O{dB-wB`hq!l@EGT6b!!hYq?~E8Fp_Qt736x5oPD*)~O!m2>pf zt(EhfzN&QbjEVw|v=q5_h@Vplo0Y^VmC#R(?pnFf;dRNc-f8o?DbcY^Fn5G2;&d)##;xJb#1WVn!U#Rh zv?>)lrr;lH~Dy~mFLa~xb|5Z<~x|-Xsn)}+8jp-ZnbhwZYPc2>Fd+*(QMg`6B Nn}ti_9seFM)c;wam7@Rv delta 954 zcmY*XJ!lj`6#iy*?{|~?N%k)H6Yp*llT+73BC#ffQ0q2n1<9 zVdsF530_^ zYX0$*)TdE1t)jy>nP0(yjcna5`Sg&cpV?^BLp^kL0acV~JzEzQ+Rhe}9g|^=IAjjh z#RxTq0wki5QM${>LHf!_r+HK(V-(HR#W-Ec1)3NmYGn6vGsmjFwHPdn;Sfg#-%O03 z(-`l+-T1t@GpEKJ<3~J>!}KRN?OFCxbBgo<@}UzX+7_Xqx3RA z>Q4Att4C|Gw%i??rL{%c&7Wmet*|0O^tLeEr{0R-wYQf{dp`=p20bt{uS+Kl>jY*w ik5entS7_cTN1LtU`xlS41v#eeHJzJ66uiG95#v8G+mz4% 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; + } +} From f80df3f37b1a6dde9e21415dbbc647c420b1f918 Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 23 Jul 2024 16:05:01 +0530 Subject: [PATCH 2/5] FIX_SYNTAX_ERR --- app/Models/EmployeeModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 8af1c19d..aa1fb9fa 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -41,7 +41,7 @@ class EmployeeModel extends Model "client_branch_id", "token_time_out", "emp_type", - "unit" + "unit", "mpin" ]; From 7bade8ce01cad64b8a44e3d6bde23f2458a3d92f Mon Sep 17 00:00:00 2001 From: bitbucket Date: Thu, 25 Jul 2024 11:26:07 +0530 Subject: [PATCH 3/5] CHANGES_in rest login api in employee login : GWM --- app/Config/Routes.php | 4 +-- .../RestAuthenticationController.php | 36 +++++++------------ 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3a17a26a..0163d762 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -286,9 +286,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/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(); From f6882f9b2f903eae487a2876aabd099c0a67bd4e Mon Sep 17 00:00:00 2001 From: aadhavan valli Date: Fri, 26 Jul 2024 11:24:47 +0530 Subject: [PATCH 4/5] CHANGE_ENROLLMENT_STATUS_AND_REMINDER_MAIL : AADHAVAN --- app/Config/Routes.php | 3 +- app/Controllers/ClientController.php | 29 +- app/Controllers/DashboardController.php | 1 - app/Controllers/EmployeeController.php | 13 +- app/Controllers/JobWorker.php | 72 +++++ app/Helpers/sendMailNotification.php | 48 +++- app/Models/ClientPolicyModel.php | 1 + app/Views/client_policy.php | 41 +++ app/Views/enrollment_dash.php | 337 ++++++++++++++++++++---- app/Views/enrollment_list.php | 44 ++++ app/Views/layout/header.php | 9 +- 11 files changed, 512 insertions(+), 86 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b701d493..a94471e9 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -138,7 +138,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->post("upload", "EmployeeController::employeesUplodWithEvents"); $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); $routes->get("endorsement-list", "EmployeeController::endorsementList"); - $routes->get("enrollment-list", "EmployeeController::enrollmentClientList"); + $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"); }); @@ -270,6 +270,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->cli('cli/processjob', 'JobWorker::processJob'); $routes->cli('cli/processjobs', 'JobWorker::processJobs'); +$routes->cli('cli/enrollment_status', 'JobWorker::enrollment_status'); $routes->get("processjob", "JobWorker::processJob"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 788a31ca..5ffe24f3 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -729,7 +729,7 @@ class ClientController extends AdminController $base_policy = $this->request->getPost('base_policy'); - $insurerValue = (string) $this->request->getPost('insurer'); + $insurerValue = (string) $this->request->getPost('insurer'); list($insurerBranchId, $insurerId) = explode('-', $insurerValue); @@ -814,8 +814,17 @@ class ClientController extends AdminController $data['policy_no'] = $this->request->getPost('policy_no'); - $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); - $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + if($data['inception_type'] == 2){ + $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); + $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + $data['reminder_date'] = change_date_format($this->request->getPost('reminder_date'), 'd-m-Y', 'Y-m-d'); + + }else{ + $data['policy_start_date'] = null; + $data['policy_end_date'] = null; + $data['reminder_date'] = null; + } + $data['created_by'] = get_session_userid(); $insert = $this->clientPolicyModel->insert($data); @@ -851,8 +860,8 @@ class ClientController extends AdminController $data['tpa_id'] = $tpaId; $data['policy_type_id'] = $this->request->getPost('policy_type_id'); $data['policy_no'] = $this->request->getPost('policy_no'); - $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); - $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + // $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); + // $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); $data['insured'] = $this->request->getPost('insured'); $data['no_of_lives'] = $this->request->getPost('no_of_lives'); @@ -874,6 +883,16 @@ class ClientController extends AdminController $data['cd_ac_no'] = $this->request->getPost('cd_ac_no'); $data['gst'] = $this->request->getPost('gst'); + if($data['inception_type'] == 2){ + $data['policy_start_date'] = change_date_format($this->request->getPost('policy_start_date'), 'd-m-Y', 'Y-m-d'); + $data['policy_end_date'] = change_date_format($this->request->getPost('policy_end_date'), 'd-m-Y', 'Y-m-d'); + $data['reminder_date'] = change_date_format($this->request->getPost('reminder_date'), 'd-m-Y', 'Y-m-d'); + }else{ + $data['policy_start_date'] = null; + $data['policy_end_date'] = null; + $data['reminder_date'] = null; + } + if($policy_type_id == 1 || $policy_type_id == 2 || $policy_type_id == 3 || $policy_type_id == 6 || $policy_type_id == 7){ $data['is_addon'] = 1; diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 43ebcb94..7a29a9a3 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -35,7 +35,6 @@ class DashboardController extends AdminController { $data = []; - $results = $this->clientModel->select('clients.id as client_id, clients.client_name, clients.short_name, client_branch.id as client_branch_id, client_branch.branch_name, client_branch.branch_code, employees.id as employee_id, diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 96458c17..ea0b306a 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -674,8 +674,15 @@ class EmployeeController extends AdminController $branch_list = $this->clientBranchModel->findAll(); $data['client_list'] = $client_list; $data['branch_list'] = $branch_list; - $this->myLogger->logme('error', 'list called'); - $this->loadLayout('enrollment_list', $data); + + // Get session data if available + $data['selected_client_id'] = session()->get('client_id'); + $data['selected_branch_id'] = session()->get('branch_id'); + $data['selected_type'] = session()->get('type'); + + $this->myLogger->logme('error', 'list called'); + return $this->loadLayout('enrollment_list', $data); + } public function empby_client_clientbranch($client_id, $branch_id) @@ -718,7 +725,7 @@ class EmployeeController extends AdminController $employeeId = $row['employee_id']; } - + return json_encode($groupedData); } diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index 38fd648a..21ba4e84 100644 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -4,6 +4,13 @@ namespace App\Controllers; use App\Models\JobModel; +use App\Models\ClientModel; +use App\Models\ClientPolicyModel; +use App\Models\NotificationModel; +use App\Models\EmployeePolicyModel; + +use App\Helpers\sendMailNotification; + class JobWorker extends AdminController { const STATUS_DONE = 'done'; @@ -228,6 +235,71 @@ class JobWorker extends AdminController } + public static function enrollment_status() { + $clientModel = new ClientModel(); + $clientPolicyModel = new ClientPolicyModel(); + $notificationModel = new NotificationModel(); + $employeePolicyModel = new EmployeePolicyModel(); + $myLogger = \Config\Services::mylogger(); + + $client_policy_data = $clientPolicyModel->where('is_active', 1) + ->where('policy_status', 1) + ->where('inception_type', 2) + ->findAll(); + $currentDate = date('Y-m-d'); + + // Update policy status based on start and end dates + foreach ($client_policy_data as $client_policy) { + $id = $client_policy['id']; + + if ($currentDate == $client_policy['policy_start_date']) { + $clientPolicyModel->update($id, ['open_for_enrollment' => 1]); + } + if ($client_policy['policy_end_date'] < $currentDate) { + $clientPolicyModel->update($id, ['open_for_enrollment' => 0]); + } + } + + $reminder_whole_mail = []; + foreach ($client_policy_data as $client_policy) { + $employee = $employeePolicyModel->select('employees.*') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->first(); + $client_data = $clientModel->find($client_policy['client_id']); + $notification_data = $notificationModel->where('client_id', $client_policy['client_id']) + ->where('template_name', 'member_reminder_mail') + ->first(); + + if ($notification_data && $notification_data['enabled'] == 1 && $currentDate == $client_policy['reminder_date']) { + $params['emp_data'] = $employee; + $params['client_data'] = $client_data; + $params['notification_data'] = $notification_data; + $reminder_whole_mail[] = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + } + } + // Process and queue bulk emails + $temp_whole_data = []; + $count = 0; + foreach ($reminder_whole_mail as $whole_index => $values) { + foreach ($values as $index => $value) { + $temp_whole_data[] = $value; + $count++; + + if ($count == 20 || ($whole_index == count($reminder_whole_mail) - 1 && $index == count($values) - 1)) { + if (!empty($temp_whole_data)) { + Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $temp_whole_data]); + $temp_whole_data = []; + $count = 0; + } + } + } + } + + return json_encode(true); + } + + } diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 5a35ccd2..cd0bda80 100644 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -12,7 +12,7 @@ class sendMailNotification { public static function sendMailNotification($action, $params) { - print_r($params);die; + $wholeData =[]; if ($action == 'member_welcome_mail') { $dataToInsert = $params['dataToInsert']; $notification = $params['notification']; @@ -37,7 +37,6 @@ class sendMailNotification } return $wholeData; } else if($action == 'member_reminder_mail'){ - $EmployeeModel = new EmployeeModel(); $emp_data = $params['emp_data']; $notification_data = $params['notification_data']; @@ -51,27 +50,46 @@ class sendMailNotification $mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content); $mail_content = str_replace("[[nhance_logo]]", "Nhance Logo", $mail_content); $mail_content = str_replace("[[app_link]]", "Review Details", $mail_content); - if ($emp_data && (isset($notification_data) && $notification_data['enabled'] == 1)) { + if(isset($emp_data['relationship'])){ + if ($emp_data['relationship'] == 'Self') { + if(count($emp_data) > 0){ + $mail =''; + if ($emp_data['relationship'] == 'Self') { + $employee_name =$emp_data['name']; + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail = $emp_data['email_corporate']; + } + } + }else{ + $mail =''; + } + + }else{ + $employee_name =$emp_data['name']; + $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); + $mail = $emp_data['email_corporate']; + } + + if (isset($mail) && !empty($mail)) { + $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; + } + }else{ foreach ($emp_data as $key => $value) { - if ($value['relationship'] != 'Self') { - + if ($value['relationship'] != 'Self') { $emp_data = $EmployeeModel->where('client_id', $client_data['id'])->where('emp_code', $value['emp_code'])->where('is_active',1)->findAll(); - if(count($emp_data) > 1){ $mail =''; foreach ($emp_data as $key => $values) { if ($value['relationship'] == 'Self') { $employee_name =$values['name']; $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); - $mail = $values['email_corporate']; } } }else{ $mail =''; } - }else{ $employee_name =$value['name']; $mail_content = str_replace("[[member_name]]", $employee_name, $mail_content); @@ -81,13 +99,15 @@ class sendMailNotification $wholeData[] = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content, 'bcc'=> $client_data['common_mails']]; } } - if (count($wholeData) < 1) { - $wholeData = []; - } - return $wholeData; - }else{ - return "false"; } + + if (count($wholeData) < 1) { + $wholeData = []; + } + return $wholeData; + // }else{ + // return "false"; + // } } else if($action == 'member_ecard_mail'){ $notification = $params['notification']; diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 05d09c98..9a4f3c0c 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -19,6 +19,7 @@ class ClientPolicyModel extends Model "policy_type_id", "policy_start_date", "policy_end_date", + "reminder_date", "insured", "no_of_employees", "no_of_lives", diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index b0862573..527d4450 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -112,6 +112,10 @@ +
+ + +
@@ -174,6 +178,23 @@ + + + + + + + -
+ + +
-
-
-
-
- - -
-
-
-
-
- +
+
+ +
+
+ +
+
+
+ +
+
+ +
+ diff --git a/app/Views/enrollment_list.php b/app/Views/enrollment_list.php index f35d7753..b483e4c1 100644 --- a/app/Views/enrollment_list.php +++ b/app/Views/enrollment_list.php @@ -228,6 +228,7 @@ }, success: function(response) { var data = JSON.parse(response); + console.log(data); var table = $('#tickets-table').DataTable(); table.clear(); @@ -277,6 +278,12 @@ }); table.draw(); + + function getUrlParameter(name) { + var params = new URLSearchParams(window.location.search); + return params.get(name); + } + }, error: function(xhr, status, error) { console.error('Error fetching data from API:', error); @@ -286,6 +293,43 @@ $(document).ready(function() { + function getUrlParameter(name) { + var params = new URLSearchParams(window.location.search); + return params.get(name); + } + + // Check for URL parameters and set form values + var client_id = getUrlParameter('client_id'); + var branch_id = getUrlParameter('branch_id'); + var type = getUrlParameter('type'); + + if (client_id) { + $('#clients').val(client_id).trigger('change'); // Set client ID and trigger change event to populate branches + } + + if (branch_id) { + setTimeout(function() { // Ensure branches are populated before setting branch ID + $('#branch_id').val(branch_id).trigger('change'); + if($('#branch_id').val() != 0){ + $('#get-emp-list').click().trigger(); + + + } + }, 500); + + } + if (history.pushState) { + var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname; + window.history.pushState({path: newUrl}, '', newUrl); + } + + setTimeout(() => { + // var type = getUrlParameter('type'); + console.log("------------------------"); + console.log(type); + $('#' + type).click().trigger(); + }, 1000); + $('#clients').select2(); $('#branch_id').select2(); var table = $('#tickets-table').DataTable({ diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index f430ce9e..3296938b 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -71,10 +71,11 @@ }); } - - - - + + + + +