FIX_MERGE : RV

This commit is contained in:
VENKATESHWARAN 2024-07-26 18:07:47 +05:30
commit 0883ce592b
26 changed files with 2381 additions and 224 deletions

View File

@ -141,9 +141,11 @@ $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");
$routes->get("test-rack-rate", "EmployeeController::testRackRate");
$routes->post("test-rack-rate", "EmployeeController::testRackRate");
});
@ -273,6 +275,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");
@ -293,9 +296,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");

View File

@ -740,7 +740,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);
@ -825,8 +825,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);
@ -863,8 +872,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');
@ -886,6 +895,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;

View File

@ -226,6 +226,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');
@ -234,7 +235,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
@ -250,8 +251,10 @@ class EmployeeController extends AdminController
}
//for TPA/insurer upload
$data['events'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed 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'];
@ -366,6 +369,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
@ -678,8 +685,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)
@ -722,7 +736,7 @@ class EmployeeController extends AdminController
$employeeId = $row['employee_id'];
}
return json_encode($groupedData);
}
@ -1491,4 +1505,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);
}
}
}

View File

@ -830,7 +830,7 @@ class EmployeeRestController extends AdminController
$count = 0;
for ($a=0; $a <count($dataToInsert) ; $a++)
{
$employee = $this->employeeModel->checkExistingEmployee($dataToInsert[$a]);
$employee = $this->employeeModel->checkExistingEmployee($dataToInsert[$a],$client_branch_id);
$emp_id =0;
$data_after_gpa_or_gmc =[];
@ -1363,8 +1363,10 @@ class EmployeeRestController extends AdminController
$result = ' ';
foreach ($array as $key => $value) {
if ($value > 0) {
if($value != 0 && $key ==='either-parents-pil') {
if($value == 1 && $key ==='either-parents-pil') {
$result .= ' + Either 2 Parents or 2 Parents in law';
}if($value == 2 && $key ==='either-parents-pil') {
$result .= ' + Any 2 of Parents and Parents in law';
}else if($value != 0 && $key ==='spouse') {
$string = str_replace('-', ' ', $key);
$string = ucwords($string);
@ -1373,11 +1375,15 @@ class EmployeeRestController extends AdminController
$result = 'Can Add Self ';
}else if($value != 0 && $key ==='childrens') {
if($value > 1){ $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child'; }
}else if($value != 0 && $key ==='elders_count') {
}else{
$string = str_replace('-', ' ', $key);
$string = ucwords($string);
$result .= ' + '.$value.' '.$string;
}
}
}
@ -1874,7 +1880,7 @@ class EmployeeRestController extends AdminController
{
$transformed_famility_details = transform_db_data_to_excel($family);
// print_r($transformed_famility_details);die();
$data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si);
$data = calculate_premium($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
@ -2404,7 +2410,8 @@ class EmployeeRestController extends AdminController
$firebase->send($message);
return $this->response->setJSON(['status' => 'success']);
} catch (MessagingException $e) {
return $this->response->setJSON(['status' => 'error', 'message' => $e->getMessage()]);
//return $this->response->setJSON(['status' => 'error', 'message' => $e->getMessage()]);
log_message('error', $e->getMessage());
}
}

View File

@ -16,6 +16,10 @@ use App\Models\PolicesModel;
use App\Models\FileModel;
use App\Models\EmpEndorsementModel;
use App\Models\MessageModel;
use App\Models\ClientBranchModel;
use App\Models\NotificationModel;
use App\Helpers\sendMailNotification;
use App\Controllers\Jobs ;
use App\Controllers\JobWorker ;
@ -35,6 +39,8 @@ class EmployeeServiceController extends AdminController
protected $policiesModel;
protected $empEndorsementModel;
protected $messageModel;
protected $clientBranchModel;
protected $notificationModel;
protected $general_relationships = [
'self' => [
@ -266,6 +272,18 @@ class EmployeeServiceController extends AdminController
'format' => null,
'allowed_values' => null
]
,
'unit' => [
'col_idx' => 18,
'col_cell_name' => 'S',
'col_name' => 'Unit',
'is_mandatory' => false,
'data_type' => 'str',
'format' => null,
'allowed_values' => null,
'custom' => 'check_unit',
'params' => ['row', 'existing_units']
]
];
protected $deletion_excel_columns = [
@ -565,6 +583,15 @@ class EmployeeServiceController extends AdminController
'format' => null,
'allowed_values' => null,
'custom' => null
],
'unit' => [
'col_idx' => 12,
'col_cell_name' => 'M',
'col_name' => 'Unit',
'is_mandatory' => false,
'data_type' => 'str',
'format' => null,
'allowed_values' => null
]
];
@ -586,7 +613,8 @@ class EmployeeServiceController extends AdminController
14 => null, // inception: pre_existing_ailments (PRE EXISTING AILMENTS) -> No match in enrollment
15 => null, // inception: change_event (Change event) -> No match in enrollment
16 => null, // inception: date_of_exit (Date of exit) -> No match in enrollment
17 => null // inception: reason_for_exit (Reason for exit) -> No match in enrollment
17 => null, // inception: reason_for_exit (Reason for exit) -> No match in enrollment
18 => null // inception: reason_for_exit (Reason for exit) -> No match in enrollment
];
protected $enrollment_to_inception_mapping = [
@ -619,6 +647,8 @@ class EmployeeServiceController extends AdminController
$this->policiesModel = new PolicesModel();
$this->empEndorsementModel = new EmpEndorsementModel();
$this->messageModel = new MessageModel();
$this->clientBranchModel = new ClientBranchModel();
$this->notificationModel = new NotificationModel();
}
public function excelFileFormatValidation($params)
@ -663,6 +693,7 @@ class EmployeeServiceController extends AdminController
if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; }
if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; }
if($file['action'] == 'enrollment'){ $columns_to_check = $this->enrollment_excel_columns; }
if($file['action'] == 'missed_inception'){ $columns_to_check = $this->inception_excel_columns; }
$result = ['error_type' => 1,'error_summary' => [], 'error_data' => [] ];
@ -722,7 +753,10 @@ class EmployeeServiceController extends AdminController
$relationship = $this->general_relationships;
//get exisiting mobilr nos
$existing_mobilenos = $this->employeePolicyModel->getExisitingMobileNos(client_policy_id: $file['policy_id']);
// dd($existing_mobilenos);
//get existing units in the current branch
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']);
// dd($existing_units);
foreach ($excel_data as $row_key => $row)
{
//define row wise action/event in temporary variable
@ -734,6 +768,7 @@ class EmployeeServiceController extends AdminController
else if($file['action'] == 'correction'){ $current_column_action = 'C'; }
else if($file['action'] == 'si_enhancement'){ $current_column_action = 'SI'; }
else if($file['action'] == 'enrollment'){ $current_column_action = 'I'; }
else if($file['action'] == 'missed_inception'){ $current_column_action = 'MI'; }
//1. avoid empty rows
if(check_row_is_empty_or_null($row))
{
@ -862,16 +897,17 @@ class EmployeeServiceController extends AdminController
}
else //trigger next data validation via job queue server
{
if($file['action'] == 'enrollment') // if current action is enrollment call next validation and return result
{
if($file['action'] == 'enrollment' && $file['uploaded_by'] != 1) // if current action is enrollment and uploaded by HR (0 or NULL) call next validation and return result
{
// dd();
$res = $this->excelFileDataValidation(['file_id' => $file['id']]);
return $res;
}
//proceed next data level validation in JOB queue
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'excelFileDataValidation','payload' => ['file_id' => $file_id]]);
// $job_details = new Jobs();
// $r = Jobs::addJob(['job_name' => 'excelFileDataValidation','payload' => ['file_id' => $file_id]]);
// $jobWorker = new JobWorker();
// JobWorker::processJob($r);
@ -914,6 +950,7 @@ class EmployeeServiceController extends AdminController
if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; }
if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; }
if($file['action'] == 'enrollment'){ $columns_to_check = $this->enrollment_excel_columns; }
if($file['action'] == 'missed_inception'){ $columns_to_check = $this->inception_excel_columns; }
// get policy and rack details
$policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']);
@ -940,7 +977,7 @@ class EmployeeServiceController extends AdminController
$relationship = $this->general_relationships;
if(in_array($file['action'],['inception','addition','dependent_addition','deletion','correction','si_enhancement','enrollment']))// the below funcitons are only for I,DA,A
if(in_array($file['action'],['inception','missed_inception','addition','dependent_addition','deletion','correction','si_enhancement','enrollment']))// the below funcitons are only for I,DA,A
{
$employee_data_group_by_family = data_group_by_family($excel_data,'excel',($file['action'] == 'enrollment' ? 'enrollment' : ''));
// dd($employee_data_group_by_family);
@ -968,12 +1005,12 @@ class EmployeeServiceController extends AdminController
// dd(array_keys($existing_famility_details[0]));
$family = array_merge($family,$existing_famility_details);
// kint::dump($family);
$family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array
$family = data_group_by_family($family)[ $emp_id ];// reason to call this again bring self to first index of the array
}
// kint::dump($family);//die();
//check name dup within a family
if($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition' || $file['action'] == 'enrollment')
if($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition' || $file['action'] == 'enrollment')
{
$res = name_dup_check_within_family($family,$file['action']);//in both file data & DB data
// dd($res);
@ -987,7 +1024,7 @@ class EmployeeServiceController extends AdminController
}
}
if(($policy_details['base_policy'] == null && ($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment')) || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) // 3 is GMC parents dep addon)
if(($policy_details['base_policy'] == null || $policy_details['base_policy'] == 0 && ($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'enrollment')) || ($policy_details['policy_type_id'] == 3 && $is_self_available_in_policy_terms)) // 3 is GMC parents dep addon)
{
$res = check_self_available_in_family($family,$file['action']);
if(!$res['is_self_found'])
@ -1010,7 +1047,7 @@ class EmployeeServiceController extends AdminController
}
if($file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'inception' || $file['action'] == 'enrollment')
if($file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'inception'|| $file['action'] == 'missed_inception' || $file['action'] == 'enrollment')
{
$res = check_dependent_conflict($family,$policy_terms,$file['action']);
// dd($res);
@ -1081,14 +1118,18 @@ class EmployeeServiceController extends AdminController
$r = Jobs::addJob(['job_name' => 'employeesCorrectionProcess','payload' => ['file_id' => $file_id]]);
}
else if ($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')//inception OR addition OR dependent addition
else if ($file['action'] == 'inception' || $file['action'] == 'missed_inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition')//inception OR addition OR dependent addition
{
//proceed next data level validation in JOB queue
$job_details = new Jobs();
// $job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'employeesOnboardPreprocess','payload' => ['file_id' => $file_id]]);
// $jobWorker = new JobWorker();
// JobWorker::processJob($r);
}
else if($file['action'] == 'enrollment' && $file['uploaded_by'] == 1)// enrollment uploaded by nhance user not by hr
{
$r = Jobs::addJob(['job_name' => 'employeesEnrollmentInsert','payload' => ['file_id' => $file_id]]);
}
return $result;
@ -1134,6 +1175,7 @@ class EmployeeServiceController extends AdminController
if($file['action'] == 'deletion'){ $columns_to_check = $this->deletion_excel_columns; }
if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; }
if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; }
if($file['action'] == 'missed_inception'){ $columns_to_check = $this->inception_excel_columns; }
// get policy and rack details
$policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']);
@ -1155,6 +1197,8 @@ class EmployeeServiceController extends AdminController
//get policy slab rates
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']);
// dd($slab_details);
//get existing units in the current branch
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']);
$employee_data_group_by_family = data_group_by_family($excel_data);
// dd($employee_data_group_by_family);
@ -1175,7 +1219,7 @@ class EmployeeServiceController extends AdminController
}
// Kint::dump($family);die();
$data = calculate_premimum($family,$policy_terms,$slab_details,$file);
$data = calculate_premium_new(family_data:$family,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
$this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]);
@ -1204,6 +1248,9 @@ class EmployeeServiceController extends AdminController
$existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_status: ['enrolled','draft'],policy_status:['enrolled','draft']);
//get existing units in the current branch
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']);
// $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception'];
$file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception','created_by' => get_session_userid(),'client_branch_id' => $params['client_branch_id']];
@ -1214,7 +1261,8 @@ class EmployeeServiceController extends AdminController
foreach ($employee_data_group_by_family as $emp_id => $family)
{
$transformed_famility_details = transform_db_data_to_excel($family);
$data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file);
// $data = calculate_premium_new($transformed_famility_details,$policy_terms,$slab_details,$file);
$data = calculate_premium_new(family_data:$transformed_famility_details,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units);
// dd($data);
$employee_data_group_by_family[$emp_id] = $data;
$this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]);
@ -1478,10 +1526,9 @@ class EmployeeServiceController extends AdminController
{
$familiy_data = $params['familiy_data'];
$file = $params['file'];
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']);
foreach($familiy_data as $fkey => $value)
{
if($file['id'] == null || $value['temp']['source'] == 'excel' || (($file['action'] == 'dependent_addition' && ($slab_details['slab_rates'][0]['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($slab_details['slab_rates'][0]['premium_type'] == 2 || $slab_details['slab_rates'][0]['premium_type'] == null)))) //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data)
if($file['id'] == null || $value['temp']['source'] == 'excel' || (($file['action'] == 'dependent_addition' && ($value['temp']['premium_type'] == 1 && strtolower($value['relationship']) == 'self') || ($value['temp']['premium_type'] == 2 || $value['temp']['premium_type'] == null)))) //insert data come from excel and from db i.e. ( $file['id'] == null for enrollment data)
{
$employee = $this->employeeModel->checkExistingEmp($value,$file['client_branch_id']);
@ -1495,7 +1542,7 @@ class EmployeeServiceController extends AdminController
// echo '---------------------------------------';
//start implemet of si enhancement of grid type 10,11
if(count($employee) && $file['action'] == 'dependent_addition' && $temp['source'] == 'db' && in_array($value['temp']['grid_id'],[10,11]) && ( ($slab_details['slab_rates'][0]['premium_type'] == 1 && (strtolower($value['relationship']) == 'self' || $temp['additional_rack_rate_acting_self'])) || ($slab_details['slab_rates'][0]['premium_type'] == 2 || $slab_details['slab_rates'][0]['premium_type'] == null)))
if(count($employee) && $file['action'] == 'dependent_addition' && $temp['source'] == 'db' && in_array($value['temp']['grid_id'],[10,11]) && ( ($value['temp']['premium_type'] == 1 && (strtolower($value['relationship']) == 'self' || $temp['acting_self'])) || ($value['temp']['premium_type'] == 2 || $value['temp']['premium_type'] == null)))
{
$log_message = 'Employee record from DB,Checking SI for - '.$employee[0]['name'].'('.$employee[0]['emp_code'].')';
$this->myLogger->logme('error',$log_message);
@ -1506,6 +1553,7 @@ class EmployeeServiceController extends AdminController
//end implemet of si enhancement of grid type
//save employee table
$value['relationship'] = ucfirst(trim($value['relationship']));
if(count($employee))
{
$value['updated_by'] = $file['created_by'];
@ -1514,6 +1562,7 @@ class EmployeeServiceController extends AdminController
$value['client_branch_id'] = $file['client_branch_id'];
$log_message = 'Update Employee - '.$employee[0]['name'].'('.$employee[0]['emp_code'].') with PK '.$employee[0]['id'];
// $this->myLogger->logme('error',('Update - ' . $employee[0]['id'].' - '. $employee[0]['emp_code'] .' - '.$employee[0]['name']));
// echo 'insert emp';
}
else
{
@ -1522,6 +1571,7 @@ class EmployeeServiceController extends AdminController
$value['client_branch_id'] = $file['client_branch_id'];
$log_message = 'Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK ';
// $this->myLogger->logme('error',('Insert - ' . $value['emp_code'] .' - '. $value['name']));
// echo 'update emp';
}
$this->employeeModel->save($value);
@ -1540,6 +1590,7 @@ class EmployeeServiceController extends AdminController
$policy_data['status'] = 'active';
$log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si'];
// echo 'insert policy';
}
else
{
@ -1548,6 +1599,7 @@ class EmployeeServiceController extends AdminController
$policy_data['created_by'] = $file['created_by'];
$policy_data['status'] = 'active';
$log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si'];
// echo 'update policy';
}
$this->employeePolicyModel->save($policy_data);
@ -1557,7 +1609,7 @@ class EmployeeServiceController extends AdminController
$log_message .= ' with PK ' . $emp_policy_id;
//make endorsement entry if action is addition OR Dependt addition
if(($file['action'] == 'dependent_addition' || $file['action'] == 'addition') && $temp['source'] == 'excel')
if(($file['action'] == 'missed_inception' || $file['action'] == 'dependent_addition' || $file['action'] == 'addition') && $temp['source'] == 'excel')
{
$log_message = $file['action'].' - endorsement'. $value['emp_code'].' - '.$value['name'].' - with policy id'.$emp_policy_id;
$this->myLogger->logme('error',$log_message);
@ -1792,8 +1844,173 @@ class EmployeeServiceController extends AdminController
$this->messageModel->insert($msg_data);
}
}
public function employeesEnrollmentInsert($params)
{
helper('excel_util_helper');
//get file name
$file_id = $params['file_id'];
$file = $this->fileModel->find($file_id);
// dd($file);
$return = [];
if(!isset($file))
{
//file not found in DB
return array('status' => false, 'msg' => 'file not found in DB');
}
$file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name'];
//check physical file
if(!file_exists($file_name_with_path))
{
//file not found update status and reason
$message = "Physical file not found";
// echo $message;
$this->myLogger->logme('error',($message . ' for file id ' . $file_id));
$this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => json_encode(['error_summary' => array_count_values([5]),'error_data' => $message])])->update();
return array('error_summary' => [5], 'error_data' => $message);
}
//get excel data
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path);
$sheet = $spreadsheet->getActiveSheet();
$highestRowAndColumn = $sheet->getHighestRowAndColumn();
$result = ['error_type' => 2,'error_summary' => [], 'error_data' => [] ];
$columns_to_check = $this->enrollment_excel_columns;
$keys = array_keys($columns_to_check);
$allowedHighestColumn = end($columns_to_check);
$excel_data = $sheet->rangeToArray('A1:' . $allowedHighestColumn['col_cell_name'] . $highestRowAndColumn['row']);
// print_r($keys);die();
//remove header
unset($excel_data[0]);
// dd($excel_data);
$emp_emails = [];
//check is welcome notification enabled
$notification = $this->notificationModel->where('client_id',$file['client_id'])->where('template_name','member_welcome_mail')->first();
// dd($notification);
$client_details = $this->clientModel->where('id', $file['client_id'])->first();
foreach ($excel_data as $key => $row)
{
// dd($key.'-'.count($excel_data));
$value = [];
$policy_data = [];
$value['emp_code'] = $row[1];
$value['name'] = $row[2];
$value['doj'] = (!empty($row[3]) ? convert_string_to_date($row[3],'Y-m-d'): null);
$value['gender'] = $row[4];
$value['relationship'] = ucfirst(trim($row[5]));
$value['dob'] = convert_string_to_date($row[6],'Y-m-d');
$value['email_corporate'] = $row[7];
$value['mobile'] = $row[8];
$value['band'] = $row[10];
$value['basic_pay'] = $row[11];
$value['unit'] = $row[12];
$value['family_floater_key'] = null;
$value['client_id'] = $file['client_id'];
$value['client_branch_id'] = $file['client_branch_id'];
$value['temp']['emp_id'] = null; // dummy value for using exisitng funciton in model
if (strtolower(trim($value['relationship'])) === 'mother' || strtolower(trim($value['relationship'])) === 'Father') {
$relation = 'parent';
} else if(strtolower(trim($value['relationship'])) === 'son' || strtolower(trim($value['relationship'])) === 'daughter'){
$relation = 'child';
}else if(strtolower(trim($value['relationship'])) === 'father in Law' || strtolower(trim($value['relationship'])) === 'mother in Law'){
$relation = 'parent_in_law';
}else if(strtolower(trim($value['relationship'])) === 'spouse'){
$relation = 'spouse';
}else{
$relation = 'self';
}
$value['family_floater_key'] = $relation;
$policy_data['basic_cover_si'] = $row[9];
$policy_data['client_policy_id'] = $file['policy_id'];
$employee = $this->employeeModel->checkExistingEmployee($value,$file['client_branch_id']);
unset($value['temp']);
//save employee table
// dd($employee['id']);
if($employee !== null)
{
$value['updated_by'] = $file['created_by'];
$value['id'] = $employee['id'];
$value['emp_status'] = 'draft';
$log_message = 'Enrollment Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id'];
}
else
{
$value['emp_status'] = 'draft';
$value['created_by'] = $file['created_by'];
$log_message = 'Enrollment Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK ';
}
$this->employeeModel->save($value);
$emp_id = $this->employeeModel->getInsertID();
if($emp_id != 0){ $log_message .= $emp_id; }
else{ $emp_id = $employee['id']; }
$this->myLogger->logme('error',$log_message);
//save policy table
$employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $file['policy_id']]);
if(count($employee_policy))
{
$policy_data['updated_by'] = $file['created_by'];
$policy_data['id'] = $employee_policy[0]['id'];
$policy_data['status'] = 'draft';
$log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si'];
// echo 'insert policy';
}
else
{
$policy_data['employee_id'] = $emp_id;
$policy_data['client_policy_id'] = $file['policy_id'];
$policy_data['created_by'] = $file['created_by'];
$policy_data['status'] = 'draft';
$log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si'];
// echo 'update policy';
}
$this->employeePolicyModel->save($policy_data);
$emp_policy_id = $this->employeePolicyModel->getInsertID();
$this->myLogger->logme('error',$log_message);
//save email of self for send mail later
if (isset($notification) && $notification['enabled'] == 1 && $notification['mail_content'] != '')
{
if(strtolower($value['relationship']) == 'self' && $value['email_corporate'] != "")
{
$params['dataToInsert'] = $value; //holds employee master data
$params['notification'] = $notification;
$params['client_data'] = $client_details;
//store email and mail content via helper to send notification
$emp_emails[] = sendMailNotification::sendMailNotification('member_welcome_mail', $params);
Kint::dump($emp_emails);
Kint::dump($key.'-'.count($excel_data));
// if mail count is 20 send bulk mail and reset emp_emails variable
if (count($emp_emails) == 20 || $key == count($excel_data) ) {
$job_details = new Jobs();
$r = Jobs::addJob(['job_name' => 'bulk_mail','payload' => $emp_emails]);
echo 'Mail triggered';
$emp_emails = [];
}
}
}
} //end of for loop
return true;
}
}

View File

@ -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';
@ -14,25 +21,120 @@ class JobWorker extends AdminController
* Constructs the class
*/
private static $event_class_mapping = [
'add' => ['type' => 'HC', 'handler' => 'App\\Helpers\\HttpRequestHelper'], 'sub' => ['type' => 'CC', 'handler' => 'App\\Controllers\\Jobs\SubJob'], 'fancy_date_time_format' => ['type' => 'HF', 'handler' => 'fancy_date_time_format'], 'addNumber' => ['type' => 'HC', 'handler' => 'App\\Model\\HttpRequestHelper'], 'excelFileFormatValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'excelFileDataValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesOnboardPreprocess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeeDisembark' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesSIEnhanceProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'employeesCorrectionProcess' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmployeeServiceController'], 'send_email' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'bulk_mail' => ['type' => 'HC', 'handler' => 'App\\Helpers\\MailHelper'], 'insertBatchList' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importInceptionFileValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importInceptionUpdateTPAandUHID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'cashDepositCalculationForInception' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'sendMailForDownloadingECard' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importCorrectionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importCorrectionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'cashDepositCalculationForSIEnhancement' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importSIEnhancementValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importSIEnhancementUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'cashDepositCalculationForDeletion' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importDeletionValidation' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
'importDeletionUpdateEndorsementID' => ['type' => 'CC', 'handler' => 'App\\Controllers\\EmpDataServiceController'],
];
private static $event_class_mapping = [
'add' => [
'type' => 'HC', // Handler Category (Possible values: HC, CC, HF)
'handler' => 'App\Helpers\HttpRequestHelper',
],
'sub' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\Jobs\SubJob',
],
'fancy_date_time_format' => [
'type' => 'HF', // Handler Category (Possible values: HC, CC, HF)
'handler' => 'fancy_date_time_format', // Likely a custom function
],
'addNumber' => [
'type' => 'HC', // Handler Category
'handler' => 'App\Model\HttpRequestHelper',
],
'excelFileFormatValidation' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',
],
'excelFileDataValidation' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',
],
'employeesOnboardPreprocess' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',
],
'employeeDisembark' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',
],
'employeesSIEnhanceProcess' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',
],
'employeesCorrectionProcess' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',
],
'send_email' => [
'type' => 'HC', // Handler Category
'handler' => 'App\Helpers\MailHelper',
],
'bulk_mail' => [
'type' => 'HC', // Handler Category
'handler' => 'App\Helpers\MailHelper',
],
'insertBatchList' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
// Employee Data Service Events
'importInceptionFileValidation' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'importInceptionUpdateTPAandUHID' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'cashDepositCalculationForInception' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'sendMailForDownloadingECard' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'importCorrectionValidation' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'importCorrectionUpdateEndorsementID' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'cashDepositCalculationForSIEnhancement' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'importSIEnhancementValidation' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'importSIEnhancementUpdateEndorsementID' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'cashDepositCalculationForDeletion' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'importDeletionValidation' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'importDeletionUpdateEndorsementID' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmpDataServiceController',
],
'employeesEnrollmentInsert' => [
'type' => 'CC', // Handler Category
'handler' => 'App\Controllers\EmployeeServiceController',
]
];
public function __construct()
{
// echo 'HiC';//die();
@ -228,6 +330,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);
}
}

View File

@ -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,36 +106,31 @@ 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()
{
try {
$mobile_number = $this->request->getJSON()->mobile_number;
$randomNumber = rand(100000, 999999);
$randomNumber = 123456;
$HrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first();
if ($HrData) {
$id= $HrData["id"];
$otp = $this->hrModel->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"];
@ -154,10 +147,10 @@ class RestAuthenticationController extends AdminController
{
try {
$mobile_number = $this->request->getJSON()->mobile_number;
$otp = $this->request->getJSON()->otp;
$otp_verification = $this->request->getJSON()->otp_verification;
$hrData = $this->hrModel->where('mobile', $mobile_number)->first();
if ($hrData && $otp == $hrData["otp"]) {
if ($hrData && $otp_verification == true) {
$auth = HttpRequestHelper::getRequestInfo();
if ($auth) {
$data = [
@ -168,10 +161,10 @@ class RestAuthenticationController extends AdminController
'broswer' => $auth['browser'],
];
$authdata= $this->authHistoryModel->insert($data);
$this->authHistoryModel->insert($data);
}
$otp_null = $this->hrModel->where('id', $hrData["id"])->set('otp', null)->update();
$hrData = $this->hrModel ->select('level_contacts.* , client_branch.client_id as client_id')
->join('client_branch', 'level_contacts.ref_id = client_branch.id', 'left')
@ -179,7 +172,7 @@ class RestAuthenticationController extends AdminController
->find();
$result = JWTToken::encode($hrData['0']);
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);
}
@ -190,11 +183,6 @@ class RestAuthenticationController extends AdminController
public function employeeLogout()
{
}
public function getUserIdFromToken()
{
$id = JWTToken::getUserIdFromToken();

View File

@ -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');

View File

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

View File

@ -90,7 +90,7 @@ if(!function_exists('check_relationship'))
{
// print_r($relationship);
// echo '<br>';
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.'<br>';
// echo $emp_data['temp']['grid_type'].'<br>';
@ -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.'<br>';
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);
}
}
}

View File

@ -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]]", "<img src='$nhance_logo' alt='Nhance Logo' width='20'>", $mail_content);
$mail_content = str_replace("[[app_link]]", "<a href='$app_link'>Review Details</a>", $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'];
@ -129,7 +149,7 @@ class sendMailNotification
return $wholeData;
} else if($action == 'member_review_and_summary_mail'){
$array_list = $params['array_list'];
$array_list = $params['array_list'];//employeee lst
$client_policy_id = $params['client_policy_id'];
$emp_code = $params['emp_code'];
$client_id = $params['client_id'];

View File

@ -39,4 +39,14 @@ class ClientBranchModel extends Model
->getResult();
}
public function getExisitingUnits(string $client_id,string $client_branch_id)
{
$res = $this->select('client_branch.units')
->where('client_id', $client_id)
->where('id', $client_branch_id)
->find();
//->getResult();
return (json_decode($res[0]['units']));
}
}

View File

@ -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",

View File

@ -41,6 +41,7 @@ class EmployeeModel extends Model
"client_branch_id",
"token_time_out",
"emp_type",
"unit",
"mpin"
];
@ -105,7 +106,7 @@ class EmployeeModel extends Model
public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [],array $client_branch_id = [])
{
$result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policies.name as policy_name','client_policy.is_addon'])
$result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policies.name as policy_name','client_policy.is_addon'])
->join('employee_polices', 'employee_polices.employee_id = employees.id')
->join('client_policy', 'client_policy.id = employee_polices.client_policy_id')
->join('policies', 'policies.id = client_policy.policy_id')
@ -158,9 +159,9 @@ class EmployeeModel extends Model
}
// for EMP rest API process do not change
public function checkExistingEmployee($arr)
public function checkExistingEmployee($arr,$client_branch_id)
{
return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->first();
return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->where('client_branch_id', $client_branch_id)->first();
}

View File

@ -19,6 +19,7 @@ class FileModel extends Model
"client_id",
"policy_id",
"client_branch_id",
"uploaded_by"
];

View File

@ -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']))
{

View File

@ -112,6 +112,10 @@
<label for="policy_end_date">Policy End Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter End Date " name="policy_end_date" id="end_date" required>
</div>
<div class="form-group col-md-4">
<label for="reminder_date">Reminder Date<span class="text-danger">*</span></label>
<input value="" type="text" class="form-control" placeholder="Enter Reminder Date " name="reminder_date" id="reminder_date" required>
</div>
<div class="form-group col-md-4" id="policy_status_field">
<label for="policy_status">Policy Status</label>
<input value="" type="text" class="form-control" placeholder="Policy Status" id="policy_status" readonly>
@ -174,6 +178,23 @@
<?php include('other_policy_terms.php'); ?>
<script>
$('#inception_type').change(function () {
var start_data = $('#start_date').parent();
var end_data = $('#end_date').parent();
var reminder_data = $('#reminder_date').parent();
if($(this).prop('checked')){
$(start_data).show();
$(end_data).show();
$(reminder_data).show();
}else{
$(start_data).hide();
$(end_data).hide();
$(reminder_data).hide();
}
})
var policy_PrimaryKey = $('#client_id_policy').val();
var policy_client = $('#policy_PrimaryKey').val();
@ -218,6 +239,13 @@
allowInput: false
});
var reminderDatePicker = flatpickr("#reminder_date", {
dateFormat: "d-m-Y",
defaultDate: endDate,
allowInput: false
});
$('#add_form').hide();
$('.btnBack').hide();
@ -323,6 +351,8 @@
// ordering: false
});
});
$('.btnAdd').click(function() {
@ -727,6 +757,7 @@
$('#policy_no').val(res.data.policy_no);
$('#start_date').val(rearrangeDateFormat(res.data.policy_start_date));
$('#end_date').val(rearrangeDateFormat(res.data.policy_end_date));
$('#reminder_date').val(rearrangeDateFormat(res.data.reminder_date));
$('#policy_status').val(checkDateStatus(res.data.policy_end_date));
$('#gst_no').val(gst);
$('#policy_status_field').show();
@ -1205,6 +1236,7 @@
$('#policy_no').val('');
$('#start_date').val('');
$('#end_date').val('');
$('#reminder_date').val('');
$('#base_policy').val('').change();
var client_id = $('#client_id_policy').val();
@ -1305,6 +1337,14 @@
$('#base_policy').prop('required', false);
$('#base_danger').hide();
}
if($('#inception_type').prop('checked')){
}else{
$('#start_date').parent().hide();
$('#end_date').parent().hide();
$('#reminder_date').parent().hide();
}
})
@ -1375,6 +1415,7 @@
var dataId = 0;
$(document).ready(function() {
$('#base_policy').change(function() {
var client_policy_id = $(this).val() ? $(this).val() : 0;

View File

@ -1,115 +1,336 @@
<!-- Bootstrap CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Bootstrap JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.bundle.min.js"></script>
<!-- Bootstrap JS (ensure this is included) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
<style>
/* Existing CSS ... */
.carousel-control-prev {
left: -38px;
}
.status-option {
padding: 0.5rem !important;
background-color: darkgrey;
}
.emp-count-view-click {
cursor: pointer;
}
.emp-status .col-6 {
/* padding-bottom: 1rem; */
padding-bottom: 0.3rem;
}
.emp-status label {
font-weight: bold;
}
.client-branch-label {
padding: 0.2rem;
border-radius: 0.2rem;
display: inline-block;
}
.scroll-container {
display: flex;
overflow-x: auto;
white-space: nowrap;
}
.scroll-item {
flex: 0 0 auto;
width: 25%; /* Adjust based on the number of items you want to show */
width: 33%; /* Adjust based on the number of items you want to show */
box-sizing: border-box;
padding: 0 10px;
}
.center_text{
text-align: center;
}
.card-body {
padding: 0rem ;
@media (min-width: 1200px) {
.col-xl-3 {
max-width: 32% !important;
}
}
.number_css{
.center_text {
text-align: center;
}
.card-body {
padding: 1rem;
}
.number_css {
font-family: Roboto, sans-serif;
color: #343a40;
text-align: center;
}
.label_bottom_reduce{
.label_bottom_reduce {
margin-bottom: .0rem;
}
.search-input {
margin-bottom: 1rem;
padding: 0.5rem;
border-radius: 0.25rem;
border: 1px solid #ced4da;
width: 100%;
}
.carousel-inner {
position: relative;
overflow: hidden;
}
.carousel-item {
height: auto; /* Adjust if needed */
/* margin-left: 80px; */
}
.card {
margin: 0 auto; /* Center card in carousel item */
}
.carousel-control-prev, .carousel-control-next {
width: 5%;
height: 100%;
}
.carousel-control-prev-icon, .carousel-control-next-icon {
background-color: rgba(0,0,0,0.5); /* Change color as needed */
}
.carousel-control-prev-icon {
background-image: url('data:image/svg+xml;charset=utf8,%3Csvg xmlns%3D"http://www.w3.org/2000/svg" fill%3D"%23000000" viewBox%3D"0 0 8 8"%3E%3Cpath d%3D"M2.5 0L4 1.5 1.5 4 4 6.5 2.5 8 0 4 2.5 0z"/%3E%3C/svg%3E');
}
.carousel-control-next-icon {
background-image: url('data:image/svg+xml;charset=utf8,%3Csvg xmlns%3D"http://www.w3.org/2000/svg" fill%3D"%23000000" viewBox%3D"0 0 8 8"%3E%3Cpath d%3D"M5.5 8L4 6.5 6.5 4 4 1.5 5.5 0l4 4-4 4z"/%3E%3C/svg%3E');
}
.show-item {
display: inline-block !important;
}
.hide-item {
display: none !important;
}
.content-page {
background-color: #e8eff5;
}
html {
background-color: #e8eff5;
}
</style>
<div class="tab-pane fade" id="enrollment-dash-tab">
<div class="tab-pane fade" id="enrollment-dash-tab">
<div class="row visa_status_count_view">
<div class="col-12">
<div class="card">
<div class="card-header"></div>
<div class="card-body status-option" id="statusContent" style="padding: 0.5rem !important;background-color: #edf1f5;">
<div class="scroll-container">
<?php foreach ($client_branch_emp_list as $clients) { ?>
<?php foreach ($clients['branches'] as $branches) { ?>
<div class="scroll-item">
<div class="card">
<div class="card-body emp-count-view-click">
<div class="d-flex justify-content-center">
<div class="col-12 center_text" style="background-color: #02a8b5;">
<label for="" class="client-branch-label">
<?php echo isset($clients['short_name']) ? $clients['short_name'] : 'N/A'; ?> -
<?php echo isset($branches['branch_name']) ? $branches['branch_name'] : 'N/A'; ?>
</label>
<div class="card" style="border: 0px;">
<div class="card-body status-option" id="statusContent" style="padding: 0.5rem !important;background-color: white;">
<!-- Search Input Field -->
<div class="row">
<div class="col-3">
<select class="form-control" name="" id="">
<option value="">Open Enrollment</option>
<option value="">Close Enrollment</option>
</select>
</div>
<div class="col-5"></div>
<div class="col-4">
<input type="text" id="searchInput" class="search-input" placeholder="Search by client or branch">
</div>
</div>
<!-- Carousel Structure -->
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel" data-interval="false">
<div class="carousel-inner">
<?php
$itemsPerSlide = 3; // Number of items per slide
$currentItem = 0; // Counter for items
$isActive = true; // Variable to set the first item as active
foreach ($client_branch_emp_list as $clients) {
foreach ($clients['branches'] as $branches) {
// Start a new carousel item if needed
if ($currentItem % $itemsPerSlide == 0) {
if (!$isActive) echo '</div>'; // Close previous carousel item
echo '<div class="carousel-item' . ($isActive ? ' active' : '') . '">';
$isActive = false;
}
?>
<!-- New Card Layout for each item -->
<div class="col-xl-3 col-md-6 d-inline-block scroll-item carousel-slide-item" data-client="<?php echo $clients['short_name']; ?>" data-branch="<?php echo $branches['branch_name']; ?>">
<div class="card" style="box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);">
<div class="card-header" >
<div class="row">
<div class="col-8 center_text emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100 text-center" >
<h3 class="my-2 py-1 number_css" ><span data-plugin="counterup" style="margin-left: 113px;font-size: 2.0rem;" onclick="enrollment_list(this, 'emp_count_view_click')"><?php echo isset($branches['employees']) ? count($branches['employees']) : '0'; ?></span></h3>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 center_text emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100 text-center" >
<h5 class="text-muted font-weight-normal mt-0 text-truncate" title="Branch Info" style="text-align: center;"><?php echo isset($clients['short_name']) ? $clients['short_name'] : 'N/A'; ?> - <?php echo isset($branches['branch_name']) ? $branches['branch_name'] : 'N/A'; ?></h5>
</div>
</div>
</div>
<!-- <div class="col-3 center_text emp-count-view-click" >
<div class="d-flex justify-content-between">
<div class="w-100 text-center" >
<p class="mb-0 text-muted">
<span class="text-success mr-2"></span>
<span class="text-nowrap">Emp Count</span>
</p>
</div>
</div>
</div> -->
</div>
</div>
<div class="row emp-status">
<div class="col-12 center_text">
<span class="number_css" style="font-size: x-large;"><?php echo isset($branches['employees']) ? count($branches['employees']) : '0'; ?></span><br>
<i class="fa fa-users" aria-hidden="true"></i>
<div class="card-body add_card_background_random" >
<input type="text" class="client_id" value="<?php echo $clients['client_id']; ?>" hidden>
<input type="text" class="client_branch_id" value="<?php echo $branches['client_branch_id'] ?>" hidden>
<div class="row emp-status" style="margin-top: -9px;">
<div class="col-6 center_text emp-count-view-click" >
<span style="font-size: large;color: white !important;" class="number_css" onclick="enrollment_list(this, 'emp_logged_in_view_click')"><?php echo isset($branches['emp_login']) ? $branches['emp_login'] : '0'; ?></span><br>
<span class="text-nowrap " style="color: currentColor;font-size: 15px;">Logged-In</span>
</div>
<div class="col-6 center_text emp-count-view-click" >
<span style="font-size: large;color: white !important;" class="number_css" onclick="enrollment_list(this, 'emp_not_logged_in_view_click')"><?php echo isset($branches['emp_login']) ? count($branches['employees']) - $branches['emp_login'] : '0'; ?></span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;margin-left: -13px;">Not Logged-In</span>
</div>
<div class="col-6 center_text">
<span style="font-size: x-large;" class="number_css"><?php echo isset($branches['emp_login']) ? $branches['emp_login'] : '0'; ?></span><br>
<label class="label_bottom_reduce" for="" style="color: gray;font-family: var(--bs-body-font-family);font-size: var(--bs-body-font-size);">Logged-In</label>
</div>
<div class="col-6 center_text">
<span style="font-size: x-large;" class="number_css"><?php echo isset($branches['emp_enroll']) ? count($branches['employees']) - $branches['emp_enroll'] : '0'; ?></span><br>
<label class="label_bottom_reduce" for="" style="color: gray;font-family: var(--bs-body-font-family);font-size: var(--bs-body-font-size);">Draft</label>
</div>
<div class="col-6 center_text">
<span style="font-size: x-large;" class="number_css"><?php echo isset($branches['emp_login']) ? count($branches['employees']) - $branches['emp_login'] : '0'; ?></span><br>
<label class="label_bottom_reduce" for="" style="color: gray;font-family: var(--bs-body-font-family);font-size: var(--bs-body-font-size);">Not Logged-In</label>
</div>
<div class="col-6 center_text">
<span style="font-size: x-large;" class="number_css"><?php echo isset($branches['emp_enroll']) ? $branches['emp_enroll'] : '0'; ?></span><br>
<label class="label_bottom_reduce" for="" style="color: gray;font-family: var(--bs-body-font-family);font-size: var(--bs-body-font-size);">Enrolled</label>
<div class="row emp-status" style="margin-top: -9px;">
<div class="col-6 center_text emp-count-view-click" >
<span style="font-size: large;color: white !important;" class="number_css" onclick="enrollment_list(this, 'emp_not_enrolled_view_click')"><?php echo isset($branches['emp_enroll']) ? count($branches['employees']) - $branches['emp_enroll'] : '0'; ?></span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;">Draft</span>
</div>
<div class="col-6 center_text emp-count-view-click" >
<span style="font-size: large;color: white !important;" class="number_css" onclick="enrollment_list(this, 'emp_enrolled_view_click')"><?php echo isset($branches['emp_enroll']) ? $branches['emp_enroll'] : '0'; ?></span><br>
<span class="text-nowrap" style="color: currentColor;font-size: 15px;">Enrolled</span>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } ?>
<?php
$currentItem++;
}
}
if ($currentItem % $itemsPerSlide != 0) echo '</div>'; // Close the last carousel item
?>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<!-- <span class="carousel-control-prev-icon" aria-hidden="true"></span> -->
<!-- <span class="sr-only">Previous</span> -->
<i class="fas fa-angle-left"></i>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('.scroll-container').on('wheel', function(e) {
if (e.originalEvent.deltaY < 0) {
this.scrollLeft -= 100; // Adjust scroll speed
} else {
this.scrollLeft += 100; // Adjust scroll speed
}
e.preventDefault();
});
$(document).ready(function() {
// Scroll functionality
$('.scroll-container').on('wheel', function(e) {
if (e.originalEvent.deltaY < 0) {
this.scrollLeft -= 100; // Adjust scroll speed
} else {
this.scrollLeft += 100; // Adjust scroll speed
}
e.preventDefault();
});
// Search functionality
$('#searchInput').on('input', function() {
var searchValue = $(this).val().toLowerCase();
var firstVisibleItem = null;
$('.scroll-item').each(function() {
var itemText = $(this).find('h5').text().toLowerCase();
if (itemText.indexOf(searchValue) > -1) {
$(this).removeClass('hide-item').addClass('show-item'); // Show item
if (!firstVisibleItem) {
firstVisibleItem = $(this);
}
} else {
$(this).removeClass('show-item').addClass('hide-item'); // Hide item
}
});
if (firstVisibleItem) {
// Remove active class from all carousel items
$('.carousel-item').removeClass('active');
// Add active class to the parent carousel item of the first visible item
firstVisibleItem.closest('.carousel-item').addClass('active');
// Scroll to the first visible item
$('html, body').animate({
scrollTop: firstVisibleItem.offset().top
}, 500);
}
});
});
function enrollment_list(current_element, type) {
var clientId = $(current_element).closest('.carousel-slide-item').find('.client_id').val();
var branchId = $(current_element).closest('.carousel-slide-item').find('.client_branch_id').val();
var baseUrl = '<?php echo base_url(); ?>'; // Adjust this to your actual base URL if needed
var url = baseUrl + 'employee/enrollment-list'; // Change this to the actual URL of your enroller_list page
var params = new URLSearchParams({
client_id: clientId,
branch_id: branchId,
type: type
});
// Redirect to the constructed URL with parameters
window.location.href = `${url}?${params.toString()}`;
}
document.addEventListener('DOMContentLoaded', function() {
// Array of predefined colors
var colors = ['yellowgreen', 'indianred', 'cadetblue', 'burlywood', 'darkolivegreen'];
// Counter to keep track of the current color index
var colorIndex = 0;
// Apply a color from the array to each card-header in sequence
document.querySelectorAll('.add_card_background_random').forEach(function(header) {
header.style.backgroundColor = colors[colorIndex];
colorIndex = (colorIndex + 1) % colors.length; // Move to the next color, cycling back to 0 if needed
});
});
</script>

View File

@ -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({

View File

@ -71,10 +71,11 @@
});
}
</script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css"/>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<style>

View File

@ -0,0 +1,689 @@
<style>
.table th,
.table td {
padding: 4px;
}
table.dataTable tbody td {
padding: 4px 4px !important;
}
.btn .btn-secondary .buttons-csv .buttons-html5 .my_class {
position: relative;
left: 79px;
}
/* Add styles for the table and its elements as needed */
.disabled {
background-color: #ddd; /* Set desired gray color for disabled rows */
}
.small-width {
width: 5%;
}
.medium-width {
width: 10%;
}
.large-width {
width: 15%;
}
.extra-large-width {
width: 20%;
}
</style>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="row">
<div class="col-xl-12">
<div id="accordion" class="mb-3">
<div class="card mb-1">
<h5 class="m-1">
<a id="toggleIcon" class="text-dark float-right" data-toggle="collapse" href="#collapseOne" aria-expanded="true">
<i id="icon" class="mdi mdi-chevron-down mr-1 text-primary" style="font-size: 28px;"></i>
</a>
</h5>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
<!-- <div class="text-center"> -->
<div class="form-row">
<div class="form-group col-md-4">
<label>Client</label> <br />
<select class="form-control" id="clients">
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Branch</label> <br />
<select name="branch_id" class="form-control" id="branch_id">
<option value="0">Select</option>
</select>
</div>
<div class="form-group col-md-4">
<label>Policy</label> <br />
<select class="form-control" id="policies">
<option value="0">Select</option>
</select>
</div>
</div>
<div class="row">
<!-- <div class="col-6" style="text-align: right;">
<a href="<?= base_url("employee/endorsement-list"); ?>" class="btn btn-primary waves-effect waves-light" id="get-emp-list" onclick="fetchEmpolyeeList(event);">Submit</a>
</div> -->
<div class="col-12" style="text-align: right;">
<a href="<?= base_url("employee/endorsement-list"); ?>" class="btn btn-primary waves-effect waves-light" id="get-emp-list" onclick="calculatePremium(event);" >calc</a>
<a href="#" class="btn btn-primary waves-effect waves-light" id="get-emp-list" onclick="addRowToTable(event);">+</a>
</div>
<!-- <button onclick="addRowToTable()">Add Row</button> -->
</div>
<!-- </div> -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row" id="client_list">
<div class="col-12">
<div class="card">
<div class="card-body">
<div class="row" style="padding-bottom: 10px;">
<!-- <div class="col-6" style="align-self: center;">
<h4 style="position: relative;">Endorsement List</h4>
</div> -->
<div id="suggestion-box" style="display: none; position: absolute; background-color: #fff; border: 1px solid #ccc; padding: 5px; z-index: 100;">
Suggestions, pick any one
<ul id="suggestions"></ul>
</div>
</div>
<table class="table table-hover m-0 table-centered dt-responsive w-100" cellspacing="0" id="emptable">
<thead class="bg-light">
<tr>
<th class="small-width">SNO</th>
<th class="small-width">Emp code</th>
<th class="large-width">Name</th>
<th class="large-width">DOB</th>
<th class="small-width">Gender</th>
<th class="medium-width">Relation</th>
<th class="large-width">SI</th>
<th class="medium-width">DOC</th>
<th class="medium-width">Basic pay</th>
<th class="small-width">Band</th>
<th class="small-width">Unit</th>
<th class="small-width">Delete</th>
</tr>
</thead>
<tbody id='emptablebody'>
</tbody>
</table>
</div>
</div>
</div><!-- end col -->
</div>
<div class="modal fade" id="centermodal" tabindex="-1" role="dialog" aria-hidden="true" >
<div class="modal-dialog modal-dialog-centered" style="max-width:80%;">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">Center modal</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<h5>Overflowing text to show scroll behavior</h5>
<p>Cras mattis consectetur purus sit amet fermentum. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Morbi leo risus, porta ac consectetur ac, vestibulum at eros.</p>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.</p>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script>
$(document).ready(function() {
// Initialize select2
$("#clients").select2();
$("#policies").select2();
$("#branch_id").select2();
});
// Declare a global variable to store API response data
var clientPolicies = [];
var clientPoliciesWithBranch = {
policies: []
};
var client_id = '<?= isset($getData) ? $getData['client_id'] : '0' ?>';
var client_branch_id = '<?= isset($getData) ? $getData['branch_id'] : '0' ?>';
$(window).on("load", function() {
console.log("window loaded");
// $('#centermodal').modal('show');
fetchClientPolicies();
});
function fetchClientPolicies() {
$('#loader').show();
var apiURL = '<?php echo base_url(); ?>' + 'util/clients-with-policies';
console.log('fetchClientPolicies');
// console.log(apiURL);
$.ajax({
url: apiURL,
method: 'GET',
headers: {
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
// console.log(response.code);
// console.log(response.dataStatus);
// console.log(response.data);
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
try {
clientPolicies = (response.data);
response.data.forEach(policy => {
// console.log('policies', policy.policies);
policy.policies.forEach(p => {
clientPoliciesWithBranch.policies.push(p);
});
});
// console.log(clientPolicies);
appendClients(clientPolicies);
setTimeout(function() {
if (client_id) {
var foundPolicies = clientPolicies.find(function(item) {
// console.log(typeof item.id)
return item.id == client_id;
});
appendBranch(foundPolicies.branchs);
}
}, 500);
setTimeout(function() {
if (client_branch_id) {
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
// console.log('item', item);
return item.branch_id === client_branch_id;
});
if (foundPolicies) {
// console.log('foundPolicies', foundPolicies);
appendPolicies(foundPolicies);
} else {
console.log('No policies found for the selected client');
}
}
}, 500);
} catch (error) {
console.error('Error parsing API response data:', error);
}
} else if (response.code === 404 && response.dataStatus === false) {
console.error('no data found', response);
} else {
console.error('Something went wrong!');
}
},
error: function(xhr, status, error) {
console.error('Error fetching data from API:', error);
}
});
$('#loader').hide();
}
function appendClients(data) {
var clientID = <?= isset($getData) ? $getData['client_id'] : '0' ?>;
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.client_name
});
if (clientID == item.id) {
option.attr('selected', true);
}
$('#clients').append(option);
});
}
function appendBranch(data) {
$('#branch_id').empty();
$('#branch_id').append($('<option>', {
value: '0',
text: 'Select'
}));
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.id,
text: item.branch_name
});
if (client_branch_id == item.id) {
option.attr('selected', true);
}
$('#branch_id').append(option);
});
}
function appendPolicies(data) {
$('#policies').empty();
$('#policies').append($('<option>', {
value: '0',
text: 'Select'
}));
var PolicyID = <?= isset($getData) ? $getData['policy_id'] : '0' ?>;
// console.log(PolicyID)
$.each(data, function(index, item) {
var option = $('<option>', {
value: item.client_policy_id,
text: `${item.name ?? ''} - ${item.policy_no ?? ''} - ${item.policy_type ?? ''}`
});
if (PolicyID == item.client_policy_id) {
option.attr('selected', true);
}
$('#policies').append(option);
});
}
$(document).ready(function() {
$('#clients').on('change', function() {
$('#policies').empty();
$('#policies').append($('<option>', {
value: '0',
text: 'Select'
}));
var selectedClient = $(this).val();
// console.log(selectedClient);
// $('#selectedOptionInfo').text('Selected option: ' + selectedOption);
// Check if the selected option exists in apiData
var foundPolicies = clientPolicies.find(function(item) {
return item.id === selectedClient;
});
// console.log(foundPolicies.branchs);
appendBranch(foundPolicies.branchs);
});
});
$(document).ready(function() {
$('#branch_id').on('change', function() {
var selectedClient = $(this).val();
// console.log('selectedBranch', selectedClient);
// console.log('clientPolicies', clientPoliciesWithBranch);
var foundPolicies = clientPoliciesWithBranch.policies.filter(function(item) {
// console.log('item', item);
return item.branch_id === selectedClient;
});
if (Array.isArray(foundPolicies) && foundPolicies.length === 0) {
appendPolicies(foundPolicies);
toastr.warning('No policies found for the selected client branch.');
} else {
// console.log('foundPolicies', foundPolicies);
appendPolicies(foundPolicies);
}
});
});
// Function to convert object to query parameters
function objectToQueryString(obj) {
return Object.keys(obj).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`).join('&');
}
function calculatePremium() {
event.preventDefault(); // Prevent default action
let table = document.getElementById('emptable');
let tabledata = getTableDataAsJson(table);
// return;
var client_id = $('#clients').val();
var policy_id = $('#policies').val();
var branch_id = $('#branch_id').val();
// console.log(client_id + '-' + policy_id);
// if (client_id == '0' || policy_id == '0') {
// alert('Please select values in both dropdowns.');
// return;
// }
var queryParams = {
client_id: client_id,
policy_id: policy_id,
branch_id: branch_id,
data: tabledata,
};
// $('#loader').show();
var apiURL = '<?php echo base_url(); ?>' + 'employee/test-rack-rate';
console.log('calculatePremium');
// console.log(apiURL);
$.ajax({
url: apiURL,
method: 'POST',
headers: {
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest"
},
data: JSON.stringify(queryParams),
success: function(response) {
console.log(response);
var myModal = new bootstrap.Modal(document.getElementById('centermodal'), { keyboard: true });
// Show the modal
myModal.show();
// return;
// console.log(response.dataStatus);
// console.log(response.data);
if (response.code === 200 && response.dataStatus === true && response.data !== "") {
// $("#centermodal").modal('show');
console.log('success');
} else if (response.code === 404 && response.dataStatus === false) {
console.error('no data found', response);
} else {
console.error('Something went wrong!');
}
},
error: function(xhr, status, error) {
console.error('Error fetching data from API:', error);
}
});
// $('#loader').hide();
}
document.getElementById('toggleIcon').addEventListener('click', function() {
var icon = document.getElementById('icon');
icon.classList.toggle('mdi-chevron-down');
icon.classList.toggle('mdi-chevron-up');
});
function formatNumberToIndianLocale(value, field_name, action) {
// Check if the value is a valid number (either as a number or as a string)
if (!isNaN(value) && !isNaN(parseFloat(value)) && field_name != 'No of Days') {
// Convert the value to a number and format it using Indian English locale
var return_val = parseFloat(value).toLocaleString('en-IN');
if (field_name == 'Period of non coverage') {
return value + ' days';
}
if (field_name == 'Total Amount') {
return '₹ ' + return_val + ' ( To be Refunded )';
}
if (field_name == 'Total') {
if (action == 'd') {
return '₹ ' + return_val + ' ( To be Refunded )';
} else if (action == 'si') {
return '₹ ' + return_val + ' ( To be paid )';
}
}
return '₹ ' + return_val;
} else {
// Return the original value if it's not a valid number
return value;
}
}
$('.close').click(function() {
$('#table_data').empty();
})
const suggestionBox = document.getElementById("suggestion-box");
const suggestionsList = document.getElementById("suggestions");
function addRowToTable() {
const tableBody = document.getElementById("emptablebody");
const existingRowCount = tableBody.rows.length;
const newRow = document.createElement("tr");
let newCell;
// SNO with auto-increment
newCell = document.createElement("td");
newCell.textContent = existingRowCount + 1;
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// Emp code (assuming you want an input field)
newCell = document.createElement("td");
newCell.innerHTML = 'FAM001';
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// Name (assuming you want an input field)
newCell = document.createElement("td");
newCell.innerHTML = '';
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// **HERE'S WHERE YOU ADD CELLS FOR OTHER COLUMNS**
// DOB (assuming you want a date input field)
newCell = document.createElement("td");
// newCell.innerHTML = '<input type="date" class="form-control">'; // Adjust for your needs
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// Gender (assuming you want a date input field)
newCell = document.createElement("td");
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
// newCell.addEventListener("input", handleInput);
newRow.appendChild(newCell);
// relationship (assuming you want a date input field)
newCell = document.createElement("td");
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newCell.addEventListener("input", handleInput);
newRow.appendChild(newCell);
// SI (assuming you want a date input field)
newCell = document.createElement("td");
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// DOC (assuming you want a date input field)
newCell = document.createElement("td");
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// BP (assuming you want a date input field)
newCell = document.createElement("td");
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// band (assuming you want a date input field)
newCell = document.createElement("td");
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// unit (assuming you want a date input field)
newCell = document.createElement("td");
newCell.innerHTML = ''; // Adjust for your needs
newCell.contentEditable = "true"; // Make the cell editable (if needed)
newCell.style.border = "1px solid";
newRow.appendChild(newCell);
// ... Add remaining cells and content
// Create a checkbox for disabled
newCell = document.createElement("td");
newCell.style.border = "1px solid";
newCell.innerHTML = '<i class="material-icons" onclick="deleteRow(event)">&#xe872;</i>';
const checkBox = document.createElement("input");
checkBox.type = "checkbox";
checkBox.addEventListener("change", function() {
newRow.classList.toggle("disabled");
});
newCell.appendChild(checkBox);
newRow.appendChild(newCell);
tableBody.appendChild(newRow);
}
function deleteRow(button) {
// console.log(button.target.parentElement.parentElement);
// console.log(button.parentNode.parentNode);
const tableBody = document.getElementById("emptablebody");
const rowToDelete = button.target.parentElement.parentElement;
tableBody.removeChild(rowToDelete);
}
let focusedCell;
function handleInput(event) {
focusedCell = event.target;
const inputValue = focusedCell.textContent.trim();
if (inputValue.length > 1) { // Show suggestions only after 2 characters
showSuggestions(inputValue);
} else {
hideSuggestions();
}
}
function showSuggestions(inputValue) {
console.log(inputValue);
const suggestions = ["Self", "Spouse", "Son","Daughter","Father","Mother","Father in law",'Mother in law','M','F']; // Replace with your logic or API call
const filteredSuggestions = suggestions.filter(s => s.toLowerCase().startsWith(inputValue.toLowerCase()));
console.log(filteredSuggestions);
console.log(filteredSuggestions.length);
suggestionsList.innerHTML = ""; // Clear previous suggestions
if(filteredSuggestions.length)
{
suggestionBox.style.display = "block"; // Show the suggestion box
for (const suggestion of filteredSuggestions) {
const listItem = document.createElement("li");
listItem.textContent = suggestion;
listItem.addEventListener("click", function() {
console.log(focusedCell);
if (focusedCell) { // Check if a cell is focused
focusedCell.textContent = suggestion; // Set the selected suggestion in the focused cell
}
hideSuggestions();
});
suggestionsList.appendChild(listItem);
}
// Position the suggestion box near the input field (optional)
const cellRect = focusedCell.parentNode.getBoundingClientRect();
// console.log(cellRect.left);
// console.log(cellRect.right);
suggestionBox.style.left = 170 + "px";
suggestionBox.style.top = 50 + "px";
}
}
function hideSuggestions() {
suggestionBox.style.display = "none";
suggestionsList.innerHTML = ""; // Clear suggestions
}
function getTableDataAsJson(table) {
// let index = {'1' : 'sno','2' : 'emp_code'};
const tableBody = table.querySelector("tbody");
if (!tableBody) {
console.error("Error: Table does not have a tbody element.");
return null;
}
// Get all rows
const rows = tableBody.querySelectorAll("tr");
// Create an empty array to store JSON data
const jsonData = [];
// Loop through each row
for (const row of rows) {
const cells = row.querySelectorAll("td");
const rowData = {}; // Create an object to hold cell data
// Loop through each cell in the row
for (let i = 0; i < cells.length; i++) {
const cellContent = cells[i].textContent.trim();
// You can adjust the property name logic if needed (e.g., use cell index as key)
const isCheckbox = i === 11;
if (isCheckbox) {
rowData[`column${i + 1}`] = cells[i].querySelector("input[type='checkbox']").checked;
} else {
rowData[`column${i + 1}`] = cellContent; // Use descriptive column names (optional)
}
}
// Add the row data object to the JSON array
jsonData.push(rowData);
}
console.log(jsonData);
return jsonData;
}
</script>

Binary file not shown.

View File

@ -0,0 +1,228 @@
<?php
namespace App\Tests;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
use Config\Services;
use Tests\Support\Libraries\ConfigReader;
use App\Controllers\EmployeeServiceController;
use CodeIgniter\Test\DatabaseTestTrait;
use Kint\Kint;
class PremiumCalculationTestNew extends CIUnitTestCase
{
use DatabaseTestTrait;
protected $migrate = false;
//primary, single parent, double parent, and double parent in law
public function testPremiumCalculation($MY_PARAM = 'default')
{
helper('excel_util_helper');
$param = getenv('MY_PARAM');
// echo isset($param) && $param != NULL ? $param : $MY_PARAM;
//first slab
$primary_relationship = '{"self":1,"spouse":"any","childrens":"any","parents":"NA","parents-in-law":"NA","either-parents-pil":0}';
$primary_grid_id = 7;
$primary_grid_type = 2;
$primary_max_si = 35000000;
$primary_grid_name = 'dependent + age + SI';
$primary_grid_master = ['id' => 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;
}
}