diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 0e2fea4b..1461a8d5 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -17,6 +17,8 @@ $routes->get('/logout', 'LoginController::logout'); $routes->get('/oauth2callback', 'LoginController::receiveGoogleOAuthResponse'); $routes->get('/auth/google', 'LoginController::initiateGoogleOAuth'); $routes->get('/update-emp-policy-status', 'ClientController::updateEmpAndPolicyStatus'); +$routes->get('download-e-card/(:segment)/(:segment)', 'EmployeeController::generateIDCardForEmployee/$1/$2'); + $routes->group("/user", ["filter" => "authMVC"], function($routes){ @@ -114,6 +116,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function($routes){ $routes->post("upload", "EmployeeController::employeesUplodWithEvents"); $routes->get("excel_error/(:any)", "EmployeeController::getExcelFileErrors/$1"); $routes->get("endorsement-list", "EmployeeController::endorsementList"); + $routes->get("truncate/(:any)", "EmployeeController::truncateFileData/$1"); }); @@ -216,7 +219,9 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){ $routes->get("view-success-emp-list", "EmployeeController::viewUploadedEmployeeList/$1"); $routes->get("fetch-policy-for-policy-type", "ClientController::fetchPolicyDataForPolicyType/$1"); $routes->get("fetch-emp-count/(:any)", "EmployeeController::getEmpCount/$1"); - + $routes->get("init-Emp-onboard/(:any)", "EmployeeController::initiateManualEmployeesOnboardProcess/$1"); + $routes->get("full-excel-error-file/(:any)", "EmployeeController::downloadFullExcelErrorFile/$1"); + $routes->get("id-card", "EmployeeController::viewECard/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); @@ -261,7 +266,15 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy"); $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); $routes->get("getAddOnPolicy", "EmployeeRestController::getAddOnPolicy"); - $routes->get("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); + $routes->post("iAgreeForAddOn", "EmployeeRestController::iAgreeForAddOn"); + + $routes->get("exportDataByClientPolicyId", "EmployeeRestController::exportDataByClientPolicyId"); + $routes->get("getCashDepositData", "EmployeeRestController::getCashDepositData"); + $routes->get("exportCashDepositData", "EmployeeRestController::exportCashDepositData"); + + $routes->get("removeEmpAndEmpPolicyData", "EmployeeRestController::removeEmpAndEmpPolicyData"); + + }); $routes->post("sendEmail", "EmployeeRestController::send_email"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 2b5354d5..6c76b45b 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -921,6 +921,39 @@ class ClientController extends AdminController } $data = $this->request->getPost(); $insert = true; + }else if($policy_grid_id == '12'){ + + $premium=$this->request->getPost('12_premium[]'); + $sum_insure =$this->request->getPost('12_si[]'); + $relationship =$this->request->getPost('12_relationship[]'); + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['relationship'] = $relationship[$i]; + + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; + }else if($policy_grid_id == '13'){ + + $premium=$this->request->getPost('13_premium[]'); + $sum_insure =$this->request->getPost('13_si[]'); + $age_from =$this->request->getPost('13_age_from[]'); + $age_to =$this->request->getPost('13_age_to[]'); + $relationship =$this->request->getPost('13_relationship[]'); + + for ($i=0; $i < count($premium) ; $i++) { + $data['premium'] = str_replace(',', '',$premium[$i]); + $data['si'] = str_replace(',', '', $sum_insure[$i]); + $data['age_from'] = $age_from[$i]; + $data['age_to'] = $age_to[$i]; + $data['relationship'] = $relationship[$i]; + + $dataa= $this->policyPremium2Model->insert($data); + } + $data = $this->request->getPost(); + $insert = true; } if($insert){ @@ -1003,17 +1036,31 @@ class ClientController extends AdminController $family_floater=json_decode($record['policy_terms'])->family_floater; } + $policy_terms_data = json_decode($record['policy_terms']); + $self = ""; + if ($policy_terms_data !== null && isset($policy_terms_data->family_floaters)) { + $self = $policy_terms_data->family_floaters; + } + $emp_count = $this->employeeModel ->join('client_policy cp',"employees.client_id = cp.client_id") ->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id") ->where("employees.client_id",$record['client_id']) ->where("employees.emp_status",'active') ->countAllResults(); - if($emp_count == 0){ - $emp_count = true; - }else{ - $emp_count = false; - } + + $data = $this->employeePolicyModel->select('employee_polices.id') + ->where('employee_polices.is_active', 1) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->findAll(); + + $emp_count = count($data); + + // if($emp_count == 0){ + // $emp_count = true; + // }else{ + // $emp_count = false; + // } $data = $this->policesModel->getPolicyPremium($record['policy_id']); @@ -1054,26 +1101,25 @@ class ClientController extends AdminController if($search_term === 'GMC'){ $resultss = []; - if ($family_floater == 1) { + try { foreach ($results as $index => $record) { - if ($index == '8' || $index == '7') { - // Clearing the $results array - $resultss[$index] = $record; + if ($self->self == 1 && $self->spouse == 0 && $self->childrens == 0 && $self->parents == 0 && $self->{'parents-in-law'} == 0 && $self->{'either-parents-pil'} == 0 && $family_floater == 0) { + if ($index == '0' || $index == '1' || $index == '2') { + $resultss[$index] = $record; + } + } else { + if ($index == '3' || $index == '4' || $index == '5' || $index == '6' || $index == '8' || $index == '7' || $index == '9' || $index == '10') { + $resultss[$index] = $record; + } } } - }else if($family_floater == 0){ - foreach ($results as $index => $record) { - if ($index == '0' || $index == '1' || $index == '2' || $index == '3' || $index == '4' || $index == '5' || $index == '6') { - // Clearing the $results array - $resultss[$index] = $record; - } - } - }else{ - foreach ($results as $index => $record) { - $resultss[$index] = $record; - } + } catch (\Exception $e) { + $resultss = $results; // Reset $resultss to an empty array if an exception occurs } + + + $premiumDataa =''; if ($family_floater == 0) { // print_r($premiumData);die; @@ -1086,7 +1132,7 @@ class ClientController extends AdminController else if($family_floater == 1){ if(count($premiumData) == 0){ $premiumDataa = $premiumData; - }else if ($premiumData[0]['policy_grid_id'] == '10' || $premiumData[0]['policy_grid_id'] == '11') { + }else if ($premiumData[0]['policy_grid_id'] == '10' || $premiumData[0]['policy_grid_id'] == '11' ) { $premiumDataa = $premiumData; } }else{ @@ -1103,15 +1149,15 @@ class ClientController extends AdminController // echo "hello"; // return json_encode($premiumData); - return $this->respond(['status' => true,'code' => 200,'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name,], 200); + return $this->respond(['status' => true,'code' => 200,'data' => $resultss, 'premiumData' => json_encode($premiumDataa), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); }else if($search_term === 'GPA'){ - return $this->respond(['status' => true,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name,], 200); + return $this->respond(['status' => true,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); }else{ - return $this->respond(['status' => false,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name,], 200); + return $this->respond(['status' => false,'code' => 200,'data' => $results, 'premiumData' => json_encode($premiumData), 'count' => $emp_count, 'policy_name' => $policy_name, 'family_floater' => $family_floater, 'self' => $self], 200); } } diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 01216aa6..80095b64 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -24,6 +24,10 @@ use App\Controllers\Jobs; use PhpOffice\PhpSpreadsheet\Spreadsheet; // use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; +use PhpOffice\PhpSpreadsheet\IOFactory; +use PhpOffice\PhpSpreadsheet\Reader\Exception as SpreadsheetReaderException; + +use function PHPUnit\Framework\returnSelf; class EmpDataServiceController extends BaseController { @@ -104,6 +108,8 @@ class EmpDataServiceController extends BaseController // Fetch employee data for export from the database $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); + // dd($objects); + $totals = 0; foreach ($objects as $key => $value) { @@ -479,6 +485,12 @@ class EmpDataServiceController extends BaseController $file = $import_data['file']; $data = $this->readExcelToArray($file); + + if (!$data) { + + return 0; + } + unset($data[0]); array_pop($data); $count = count($data); @@ -490,8 +502,17 @@ class EmpDataServiceController extends BaseController try { - if ($value[15] === null) { - $missing_id[] = $key + 1; + + if ($import_data['insurer_or_tpa'] == 'tpa') { + + if ($value[15] === null) { + $missing_id[] = $key + 1; + } + } else if ($import_data['insurer_or_tpa'] == 'insurer') { + + if ($value[16] === null) { + $missing_id[] = $key + 1; + } } $emp_code = $value[2]; @@ -501,26 +522,30 @@ class EmpDataServiceController extends BaseController $db = \Config\Database::connect(); // Execute the query - $query = $db->table('employee_polices') - ->select('employee_polices.id') - ->join('employees', 'employees.id = employee_polices.employee_id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employees.name', $name) - ->where('employees.emp_code', $emp_code) - ->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")') - ->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")') - ->where('employee_polices.is_active', 1) - ->limit(1) - ->get(); + $query = $db->table('employee_polices'); + $query->select('employee_polices.id'); + $query->join('employees', 'employees.id = employee_polices.employee_id'); + $query->where('employee_polices.client_policy_id', $client_policy_id); + $query->where('employees.client_id', $client_id); + $query->where('employees.name', $name); + $query->where('employees.emp_code', $emp_code); + if ($import_data['insurer_or_tpa'] == 'tpa') { + + $query->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")'); + } else if ($import_data['insurer_or_tpa'] == 'insurer') { + + $query->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")'); + } + $query->where('employee_polices.is_active', 1); + $query->limit(1); // Get the result - $result = $query->getRowArray(); + $result = $query->get()->getRowArray(); if (isset($result['id']) && $result['id'] !== null) { $empty_emp_tpa_uh_ids[] = $result['id']; } } catch (\Exception $e) { - // Handle the exception here + return 0; } } @@ -529,17 +554,43 @@ class EmpDataServiceController extends BaseController $missing_id_count = count($missing_id); $empty_id_count = count($empty_emp_tpa_uh_ids); - // dd($count, $missing_id_count, $empty_id_count, $data, $empty_emp_tpa_uh_ids); - if ($missing_id_count != $count && $missing_id_count != 0) { + if ($import_data['insurer_or_tpa'] == 'tpa') { - return 2; + if ($empty_id_count == 0) { + + return 3; + } + + if ($missing_id_count != 0) { + + return 2; + } + } else if ($import_data['insurer_or_tpa'] == 'insurer') { + + if ($empty_id_count == 0) { + + return 5; + } + + if ($missing_id_count != 0) { + + return 4; + } } - if ($empty_emp_tpa_uh_ids != $count && $empty_id_count == 0) { + // if ($missing_id_count != $count) { + + // return 2; + // } + + + // if ($empty_emp_tpa_uh_ids != $count) { + + // return 3; + // } + - return 3; - } // dd($empty_emp_tpa_uh_ids); @@ -557,40 +608,46 @@ class EmpDataServiceController extends BaseController // dd($import_data, $empty_emp_tpa_uh_ids); + $tpa_id = []; + $uhid = []; + foreach ($data as $key => $value) { + $tpa_id[] = $value[15]; + $uhid[] = $value[16]; + } - if (!empty($value) && (isset($value[15]) || isset($value[16]))) { + foreach ($empty_emp_tpa_uh_ids as $key => $id) { - $tpa_id = $value[15] !== null ? $value[15] : ''; - $uhid = $value[16] !== null ? $value[16] : ''; + $dataToUpdateTPAID = ['tpa_id' => $tpa_id[$key]]; + $dataToUpdateUHID = ['uhid' => $uhid[$key]]; + + $this->employeePolicyModel->where('id', $id) + ->where('(employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = "")') + ->set($dataToUpdateTPAID)->update(); - foreach ($empty_emp_tpa_uh_ids as $id) { - // Update employee policies based on the ID - $this->employeePolicyModel->where('id', $id)->set(['tpa_id' => $tpa_id, 'uhid' => $uhid])->update(); - } + $this->employeePolicyModel->where('id', $id) + ->where('(employee_polices.uhid IS NULL OR employee_polices.uhid = "")') + ->set($dataToUpdateUHID)->update(); + } + - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; + if($import_data['insurer_or_tpa'] == 'tpa'){ - } else { - - return 0; - } + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + $depositeData = [ + 'employeeIds' => $empty_emp_tpa_uh_ids, + 'client_id' => $client_id, + 'client_policy_id' => $client_policy_id, + 'count' => $count, + 'event' => $import_data['event_type'], + 'policy_name' => $policy_name['policy_name'], + ]; + + $this->cashDepositCalculationForInception($depositeData); + } - - $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); - $depositeData = [ - 'employeeIds' => $empty_emp_tpa_uh_ids, - 'client_id' => $client_id, - 'client_policy_id' => $client_policy_id, - 'count' => $count, - 'event' => $import_data['event_type'], - 'policy_name' => $policy_name['policy_name'], - ]; - - $this->cashDepositCalculationForInception($depositeData); return 1; } @@ -1200,7 +1257,7 @@ class EmpDataServiceController extends BaseController $description = 'The following amount of Rs. ' . $amount->total_sum . '/- has been debited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.'; $data = [ - 'amount' => $amount->total_sum, + 'amount' => $amount->total_sum ?? 0, 'sub_type_id' => 4, 'client_id' => $arrayData['client_id'], 'insurer_id' => $insurer_id['insurer_id'], @@ -1470,34 +1527,42 @@ class EmpDataServiceController extends BaseController + public function readExcelToArray($file) { - if ($file->isValid() && !$file->hasMoved()) { $file = $file; + + try { - $reader = new Xlsx(); - $spreadsheet = $reader->load($file->getPathname()); - - // Get the active sheet - $sheet = $spreadsheet->getActiveSheet(); - - // Iterate through rows to read data - $data = []; - foreach ($sheet->getRowIterator() as $row) { - $rowData = []; - foreach ($row->getCellIterator() as $cell) { - $rowData[] = $cell->getValue(); + $reader = IOFactory::createReaderForFile($file->getPathname()); + $spreadsheet = $reader->load($file->getPathname()); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Iterate through rows to read data + $data = []; + foreach ($sheet->getRowIterator() as $row) { + $rowData = []; + foreach ($row->getCellIterator() as $cell) { + $rowData[] = $cell->getValue(); + } + $data[] = $rowData; } - $data[] = $rowData; + + return $data; + + } catch (SpreadsheetReaderException $e) { + + error_log('PhpSpreadsheet reader exception: ' . $e->getMessage()); + return false; } - - return $data; } else { - return false; } } + public function insertBatchFileAndBatchListForImportExcel($data, $ids) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index b3b0160d..bfcc61d9 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -26,6 +26,10 @@ use App\Controllers\EmpDataServiceController; use CodeIgniter\API\ResponseTrait; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\IOFactory; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; + +use Dompdf\Dompdf; class EmployeeController extends AdminController { @@ -245,18 +249,23 @@ class EmployeeController extends AdminController { $file_id = $this->request->uri->getSegment(3); $empServiceController = new EmployeeServiceController(); - + $result['file_id'] = $file_id; + // Render views and capture output $result = $empServiceController->getExcelErrorData($file_id); - // echo '
';
-        // print_r($result); die;
-        if($result){
+        if ($result != 0) {
+
             echo view('excel_errors', $result);
-        }else{
+        } else if ($result == 0) {
+
+            $data['message'] = 'File Not Found Physically';
+            return view('errors/404', $data);
+
+        } else {
+
             echo view('errors/html/production');
         }
-    
     }
 
     /**
@@ -348,8 +357,14 @@ class EmployeeController extends AdminController
                 
                 $return = $empDataServiceController->generateExcelForAdditionandInception($batch_data);  
                 if(!$return){
-                     session()->setFlashdata('error', 'No data found about this action');
-                     return redirect()->to(base_url('employee/upload')); 
+                    if($insurer_or_tpa == 'tpa'){
+                        session()->setFlashdata('error', "No data was found for this action. The TPA ID has already been updated.");
+                        return redirect()->to(base_url('employee/upload')); 
+
+                    }else if($insurer_or_tpa == 'insurer'){
+                        session()->setFlashdata('error', "No data was found for this action. The UHID has already been updated.");
+                        return redirect()->to(base_url('employee/upload')); 
+                    }
                 }  else{
                     $this->myLogger->logme('error','Successfully exported Excel file in {data}.', ['data' => $event_type]);
                 }
@@ -398,16 +413,28 @@ class EmployeeController extends AdminController
                     return redirect()->to(base_url('employee/upload'));
 
                 }else if($return == 2){
-                    session()->setFlashdata('error', 'The TPA ID or UHID columns are empty.');
+                    session()->setFlashdata('error', 'The TPA ID column is either partially or entirely empty.');
                     return redirect()->to(base_url('employee/upload'));
 
                 }else if($return == 0){
-                    session()->setFlashdata('error', 'Please upload the correct file, something went wrong.');
+                    session()->setFlashdata('error', 'Please upload the correct file.');
                     return redirect()->to(base_url('employee/upload'));
+
                 }else if($return == 3){
-                    session()->setFlashdata('error', 'File already uploaded');
+                    session()->setFlashdata('error', 'The list of employees provided has already been updated with the TPA ID, or this is not the correct file');
                     return redirect()->to(base_url('employee/upload'));
-                }            }else if($event_type == 'correction'){
+
+                }else if($return == 4){
+                    session()->setFlashdata('error', 'The UHID column is either partially or entirely empty.');
+                    return redirect()->to(base_url('employee/upload'));
+
+                }else if($return == 5){
+                    session()->setFlashdata('error', 'The list of employees provided has already been updated with the UHID, or this is not the correct file');
+                    return redirect()->to(base_url('employee/upload'));
+
+                }            
+
+             }else if($event_type == 'correction'){
 
                 $return = $empDataServiceController->importExcelDataForCorrection($batch_data);
                 if($return == 1){
@@ -419,7 +446,7 @@ class EmployeeController extends AdminController
                     return redirect()->to(base_url('employee/upload'));
 
                 }else if($return == 0){
-                    session()->setFlashdata('error', 'Please upload the correct file, something went wrong.');
+                    session()->setFlashdata('error', 'Please upload the correct file');
                     return redirect()->to(base_url('employee/upload'));
                 }else if($return == 3){
                     session()->setFlashdata('error', 'File already uploaded');
@@ -438,7 +465,7 @@ class EmployeeController extends AdminController
                     return redirect()->to(base_url('employee/upload'));
 
                 }else if($return == 0){
-                    session()->setFlashdata('error', 'Please upload the correct file, something went wrong.');
+                    session()->setFlashdata('error', 'Please upload the correct file');
                     return redirect()->to(base_url('employee/upload'));
                 }else if($return == 3){
                     session()->setFlashdata('error', 'File already uploaded');
@@ -457,7 +484,7 @@ class EmployeeController extends AdminController
                     return redirect()->to(base_url('employee/upload'));
 
                 }else if($return == 0){
-                    session()->setFlashdata('error', 'Please upload the correct file, something went wrong.');
+                    session()->setFlashdata('error', 'Please upload the correct file');
                     return redirect()->to(base_url('employee/upload'));
                 }else if($return == 3){
                     session()->setFlashdata('error', 'File already uploaded');
@@ -564,10 +591,21 @@ class EmployeeController extends AdminController
     // this funciton initiate Inception/adition/DA of employees data only form enrollment app when passing
     // client_policy_id pull draft and enrolled status employees and proceed to calculatin and make entry in DB
     public function initiateManualEmployeesOnboardProcess($client_policy_id)
-    {
-        $empServiceController = new EmployeeServiceController();
-        $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id]);
-        dd($res);
+    {   
+       $client_data = $this->clientPolicyModel->select('clients.client_name as client_name, policies.name as policy_name')
+       ->join('clients', 'clients.id = client_policy.client_id')
+       ->join('policies', 'policies.id = client_policy.policy_id')
+       ->where('client_policy.id', $client_policy_id)
+       ->first();
+
+       $empServiceController = new EmployeeServiceController();
+       $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => $client_policy_id]);
+       // dd($res);
+
+       $count = count($res);
+       $message =  $count . ' Employees are Initiate Onboard Process againts Client '. $client_data['client_name'] . ' and the Policy is ' . $client_data['policy_name'] ;
+       session()->setFlashdata('success1',  $message);
+       return redirect()->to(base_url('/employee/upload'));
     }
 
 
@@ -641,6 +679,7 @@ class EmployeeController extends AdminController
             
                 $highestRowAndColumn = $sheet->getHighestRowAndColumn();
                 $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']);
+                // dd($excel_data);
                 $emp_data['thead'] = $excel_data[0];
                 unset($excel_data[0]);
                 $emp_data['tbody'] = $excel_data;
@@ -652,7 +691,7 @@ class EmployeeController extends AdminController
                 $html = '
No Data Found
'; } - return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $html, 'file_data' => $file_name], 200); + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $html, 'file_data' => $file_name, 'excel_data' => $excel_data], 200); } catch (\Exception $e) { // Handle exception @@ -665,9 +704,9 @@ class EmployeeController extends AdminController public function getEmpCount($id = null){ - $data = $this->employeeModel->select('employees.id') - ->join('clients', 'clients.id = employees.client_id') - ->where('employees.client_id', $id) + $data = $this->employeePolicyModel->select('employee_polices.id') + ->where('employee_polices.is_active', 1) + ->where('employee_polices.client_policy_id', $id) ->findAll(); $emp_count = count($data); @@ -683,5 +722,209 @@ class EmployeeController extends AdminController } + + public function downloadFullExcelErrorFile($file_id = 137, $rowIndex = 1, $colIndex = 1) + { + // Get file data from the database + $file_data = $this->fileModel->find($file_id); + + $error = json_decode($file_data['reason']); + // echo '
';
+        //    print_r($error); die;
+        //    dd($error);
+    
+        // Check if the file exists
+        if (!$file_data) {
+            $error_message = "File not found";
+            $this->myLogger->logme('error', $error_message . ' for file id ' . $file_id);
+            return $error_message;
+        }
+    
+        $fileName = $file_data['file_name'];
+        $filePath = WRITEPATH . '/uploads/excel/' . $fileName;
+    
+        // Check if the file exists
+        if (!file_exists($filePath)) {
+            $error_message = "File not found";
+            $this->myLogger->logme('error', $error_message . ' for file id ' . $file_id);
+            return $error_message;
+        }
+    
+        // Load the Excel file
+        $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath);
+        $sheet = $spreadsheet->getActiveSheet();
+
+        //  echo '
';
+
+        foreach ($error->error_data as $index => $error_data) {
+
+            $rowIndex = $index+1;
+
+            if( $error->error_type == 1 ){
+
+                foreach ($error_data as $key => $value) {
+               
+                    $colIndex = $value->col_idx+1;
+                    
+                    $originalValue = $sheet->getCell([$colIndex, $rowIndex])->getValue();
+        
+                    $newValue =  implode(', ',$value->error);
+                    $val = $originalValue . ' ( ' . $newValue . ' )';
+                    $sheet->setCellValue([$colIndex, $rowIndex],  $val);
+                
+                    $style = [
+                        'fill' => [
+                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
+                            'startColor' => ['rgb' => 'ffad99'] // Red color
+                        ]
+                    ];
+                    
+                    $sheet->getStyle([$colIndex, $rowIndex])->applyFromArray($style);
+    
+                }
+            }else if( $error->error_type == 2){
+
+
+                foreach ($error_data as $key => $value) {
+               
+                    
+                    $originalValue = $sheet->getCell([1, $rowIndex])->getValue();
+        
+                    $newValue =  implode(', ',$value->error);
+                    $val = $originalValue . ' ( ' . $newValue . ' )';
+                    $sheet->setCellValue([$colIndex, $rowIndex],  $val);
+                
+                    $style = [
+                        'fill' => [
+                            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
+                            'startColor' => ['rgb' => 'ffad99'] // Red color
+                        ]
+                    ];
+                    $sheet->getStyle([$colIndex, $rowIndex])->applyFromArray($style);
+    
+                }
+
+            }
+
+       }
+    
+
+    
+        // Create a new filename for the modified Excel file
+        $newFileName = 'modified_' . $fileName;
+    
+        // Save the modified Excel file to a new location
+        $newFilePath = WRITEPATH . '/uploads/excel/' . $newFileName;
+        $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
+        $writer->save($newFilePath);
+    
+        // Set headers to force download
+        $response = service('response');
+        $response->setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+        $response->setHeader('Content-Disposition', 'attachment;filename="' . $newFileName . '"');
+        $response->setHeader('Cache-Control', 'max-age=0');
+        $response->setHeader('Content-Length', filesize($newFilePath));
+        $response->setBody(file_get_contents($newFilePath));
+    
+        // Delete the temporary file
+        unlink($newFilePath);
+    
+        // Return the response
+        return $response;
+    }
+    
+    public function generateIDCardForEmployee($emp_code, $client_policy_id)
+    {   
+        $dompdf = new Dompdf();
+
+        $data['data'] = $this->employeePolicyModel->getECardDataUsingMd5($client_policy_id, $emp_code);
+        // $this->loadLayout('id_card_view', $data); exit;
+
+        $html =  view('id_card_view', $data);
+        // $html = str_replace('', '', $html);
+
+        $dompdf->loadHtml($html);
+
+        // (Optional) Setup the paper size and orientation
+        $dompdf->setPaper('A4', 'landscape');
+
+        // Render the HTML as PDF
+        $dompdf->render();
+
+        // Output the generated PDF to Browser
+        $dompdf->stream();
+        
+    }
+
+    public function viewECard()
+    {
+        $this->loadLayout('id_card_view');
+    }
+    
+
+    public function truncateFileData() //truncateFileDataIn DB (de activate rows)
+    {
+         $file_id = $this->request->uri->getSegment(3);
+         // $file_id = 112;
+         $file = $this->fileModel->find($file_id);
+         // $file['action'] = 'si_enhancement';
+         // $result = [];
+         // !dd($file);
+         if($file['action'] == 'inception' || $file['action'] == 'dependent_addition' || $file['action'] == 'addition')
+         {
+            $result = $this->employeeModel->getEmpListByFileId(file_id: $file_id,emp_status: ['active'],policy_status:['active']);
+            // ~dd($result);
+            if(count($result))
+           {
+            return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'File data already processed'], 200);
+           }
+           else
+           {
+
+                //update emp and emp plocies
+                $db = db_connect();
+                $query = "UPDATE employees JOIN employee_polices ON employees.id = employee_polices.employee_id and employees.file_id = $file_id SET employees.emp_status = 'truncated', employee_polices.status = 'truncated', employees.is_active = 0,employee_polices.is_active = 0 WHERE employees.file_id = $file_id";
+                $db->query($query);
+                $affectedRows = $db->affectedRows();
+                // $affectedRows = 10;
+
+                //update file status
+                $this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
+
+            return $this->respond(['dataStatus' => true,'code' => 200,'data' => round($affectedRows/2)], 200);
+           }
+         }
+         else if($file['action'] == 'si_enhancement' || $file['action'] == 'correction' || $file['action'] == 'deletion')
+         {
+            $res = $this->empEndorsementModel->select(['count(id) as count'])
+                                      ->where('emp_endorsement.file_id',$file_id)
+                                      ->groupStart()
+                                        ->where('emp_endorsement.endorsement_id is not null')
+                                        ->orwhereIn('emp_endorsement.status',['complete'])
+                                      ->groupEnd()
+                                       ->get()
+                                       ->getResult();
+            // print_r($this->empEndorsementModel->getLastQuery());
+             // echo $res[0]->count;die();
+            if($res[0]->count == 0)
+            {
+                //update truncated status to db
+                $this->empEndorsementModel->where('file_id',$file_id)
+                                      ->set(['status' => 'truncated'])
+                                      ->update();
+                //update file status
+                $this->fileModel->where('id', $file_id)->set(['status' => 'truncated'])->update();
+                return $this->respond(['dataStatus' => true,'code' => 200,'data' => 'success'], 200);
+            }
+            else
+            {
+                return $this->respond(['dataStatus' => false,'code' => 404,'message' => 'File data already processed'], 200);
+            }
+         }
+           
+    }
+    
+    
+    
     
 }
\ No newline at end of file
diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php
index 1631a100..f25e56cf 100644
--- a/app/Controllers/EmployeeRestController.php
+++ b/app/Controllers/EmployeeRestController.php
@@ -172,16 +172,19 @@ class EmployeeRestController extends AdminController
     {
         try {
             $data = $this->request->getJSON();
-           
+
+            
             if ($data) {
+
                 $Count = 0;
                 foreach ($data as $item) {
                     if (isset($item->id)) {
                         //update old data
                         $id = $item->id;
                         $item->family_floater_key = $this->RelationshipMap($item->relationship);
+                        $item->gender = $this->GenderMap($item->relationship , $item->emp_code);
                         $item->dob = $this->convertDateFormatYMD($item->dob);
-                        $item->emp_status = 'Draft';
+                        $item->emp_status = 'draft';
                         $employee = $this->employeeModel->where('is_active', 1 )->update($id, (array)$item);
                         if ($employee) {
                             $Count++;
@@ -189,15 +192,12 @@ class EmployeeRestController extends AdminController
                       }else{
                         //create new data
                         $item->family_floater_key = $this->RelationshipMap($item->relationship);
+                        $item->gender = $this->GenderMap($item->relationship , $item->emp_code);
                         $item->dob = $this->convertDateFormatYMD($item->dob);
-                        $item->emp_status = 'Draft';
-                        $employee = $this->employeeModel->where('is_active', 1 )->insert($item);
+                        $item->emp_status = 'draft';
+                        $employee = $this->employeeModel->insert($item);
                    
                         if ($employee) {
-                         if(!isset($item->is_addon_value))
-                         {
-                            $this->createEmployeePolicyData($employee,$item->emp_code,$item->client_id,$item->client_policy_id);
-                         }
                             $Count++;
                         }
 
@@ -206,6 +206,18 @@ class EmployeeRestController extends AdminController
                 }
     
                 if ($Count > 0) {
+
+                    if(!isset($data[0]->is_addon_value))
+                    {
+                       $this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id);
+                    }else{
+                       $this->createEmployeePolicyData($employee , $data[0]->emp_code , $data[0]->client_id , $data[0]->client_policy_id , $data[0]->basic_cover_si);
+                    }
+
+
+                    $this->updatePremiumAmount($data[0]->client_policy_id , $data[0]->emp_code);
+
+                    
                     $result = [];
                     return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
                 } else {
@@ -219,34 +231,70 @@ class EmployeeRestController extends AdminController
         
     }
 
-    public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id)
+    public function createEmployeePolicyData($employee_id,$emp_code,$client_id,$client_policy_id,$basic_cover_si = null)
     {
-
- 
-           
+    
+            if($basic_cover_si == null)
+            {
             $client_policy = $this->clientPolicyModel->where('id', $client_policy_id)->where('client_id', $client_id)->first();
             $policy_terms = json_decode($client_policy['policy_terms']);
             $basic_cover_si = $policy_terms->sum_insured;
+            }
 
-            $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id);
-            $SlabRatesArray = $getSlabAndGridData['slab_rates'];
-            $premium = $this->findPremiumAmount($SlabRatesArray, $basic_cover_si);
+            $checkDataExist = $this->employeePolicyModel->where('employee_id',$employee_id)->where('client_policy_id',$client_policy_id)->first();
 
+            if($checkDataExist){
 
+                $this->employeePolicyModel
+                    ->where('client_policy_id',$client_policy_id )
+                    ->where('employee_id' , $employee_id )
+                    ->where('is_active', 1 )
+                    ->set(array('basic_cover_si'=> $basic_cover_si ))
+                    ->update();     
 
-            $data['employee_id']= $employee_id;
-            $data['client_policy_id']= $client_policy_id;
-            $data['basic_cover_si']= $basic_cover_si;
-            $data['premium']= $premium;
-    
-            $this->employeePolicyModel->insert($data);
-                
+            }else{
+
+                $data['employee_id']= $employee_id;
+                $data['client_policy_id']= $client_policy_id;
+                $data['basic_cover_si']= $basic_cover_si;
+                $data['status']= 'draft';
+
+                $this->employeePolicyModel->insert($data);
+
+            }
             
             return true;             
-           
-       
     }
 
+    public function updatePremiumAmount($client_policy_id , $emp_code)
+    {
+        $response = $this->calculatePremium($client_policy_id , $emp_code);
+
+        if(count($response[$emp_code]))
+        {
+            
+            foreach ($response[$emp_code] as $key => $value) 
+            {
+               
+                $checkIfExist = $this->employeePolicyModel->where('employee_id', $value['temp']['emp_id'])
+                                                           ->where('client_policy_id', $value['policy_details']['client_policy_id'])
+                                                           ->where('is_active', 1 )
+                                                           ->findAll();
+                if($checkIfExist) 
+                {  
+                    $this->employeePolicyModel
+                    ->where('client_policy_id',$value['policy_details']['client_policy_id'] )
+                    ->where('employee_id' , $value['temp']['emp_id'] )
+                    ->where('is_active', 1 )
+                    ->set(array('premium'=> $value['policy_details']['rata_premimum'] , 'gst'=> $value['policy_details']['gst'] ))
+                    ->update();        
+                   
+                }
+            }
+        }
+    }
+
+
     public function RelationshipMap($value){
        
             if ($value === 'Mother' || $value === 'Father') {
@@ -260,6 +308,19 @@ class EmployeeRestController extends AdminController
             }
     }
 
+    public function GenderMap($value,$empCode){
+       
+        if ($value === 'Mother' || $value === 'Daughter' || $value === 'Mother in Law') {
+            return  'F';
+        } else if($value === 'Son' || $value === 'Father' || $value === 'Father in Law'){
+            return 'M';
+        }else if($value === 'Spouse'){
+
+            $Gender = $this->employeeModel->where('emp_code',$empCode)->where('relationship','Self')->get()->getRow()->gender;
+            if($Gender == 'M'){ return  'F'; }else{ return 'M'; }
+        }
+}
+
     private function convertDateFormatYMD($dateString)
     {
         // Attempt to create a DateTime object from the provided date string
@@ -323,6 +384,83 @@ class EmployeeRestController extends AdminController
             }
         
             
+        } catch (\Exception $e) {
+            return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
+        }
+        
+    }
+
+
+    public function exportDataByClientPolicyId()
+    {
+        try {
+            $empData =   $this->employeePolicyModel->getEmployeePolicy( client_id:$this->request->getGet('client_id'),policy_id: $this->request->getGet('client_policy_id'),status:0);
+
+        if(count($empData))
+        {
+            // Define headers and map database fields to Excel fields
+            $headers = [
+                'Employee Code' => 'emp_code',
+                'Name' => 'name',
+                'Relationship' => 'relationship',
+                'DOB' => 'dob',
+                'Gender' => 'gender',
+                'Mobile' => 'mobile',
+                'Email' => 'email_corporate',
+                'SI' => 'basic_cover_si',
+                'Premium' => 'rata_premimum',
+                'Policy Name' => 'policy_name',
+                'Insurer Branch Name' => 'insurer_branch_name',
+                'TPA Name' => 'tpa_name',
+                'Status' => 'emp_status'
+            ];
+
+            // Create a new Spreadsheet object
+            $spreadsheet = new Spreadsheet();
+
+            // Get the active sheet
+            $sheet = $spreadsheet->getActiveSheet();
+
+            // Add headers
+            $column = 'A';
+            foreach ($headers as $header => $dbField) {
+                $sheet->setCellValue($column . '1', $header);
+                $column++;
+            }
+
+            // Add data
+            $row = 2;
+            foreach ($empData as $employee) {
+                $column = 'A';
+                foreach ($headers as $dbField) {
+                    $sheet->setCellValue($column . $row, $employee[$dbField]);
+                    $column++;
+                }
+                $row++;
+            }
+
+
+            // Set the header for download
+            $filename =  $empData[0]['policy_name'].'-Enrollment.xlsx';
+            header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+            header('Content-Disposition: attachment;filename="' . $filename . '"');
+            header('Cache-Control: max-age=0');
+
+            // Save the Excel file to output
+            $writer = new Xlsx($spreadsheet);
+            $writer->save('php://output');
+            exit;
+
+            return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200);
+
+        }else{
+
+            return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200);
+        }
+           
+           
+        
+            
         } catch (\Exception $e) {
             return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
         }
@@ -340,9 +478,9 @@ class EmployeeRestController extends AdminController
             foreach ($ClientPolicyData as $key => $value) {
                 $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']);
                 if($value['is_addon'] == "2"){
-                    $value['type'] = 'SI-TopUp';
+                    $value['type'] = 'SI TopUp';
                 }else if($value['is_addon'] == "3"){
-                    $value['type'] = 'Dependent-AddOn';
+                    $value['type'] = 'Dependent AddOn';
                 }else{
                     $value['type'] = $getSlabAndGridData['grid_master']['policy_type'];
                 }
@@ -509,27 +647,27 @@ class EmployeeRestController extends AdminController
                                                    ->where('client_policy_id', $value->client_policy_id)
                                                    ->where('is_active', 1 )
                                                    ->findAll();
-            $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($value->client_policy_id,$value->client_id);
-            $SlabRatesArray = $getSlabAndGridData['slab_rates'];
-            $premium = $this->findPremiumAmount($SlabRatesArray, $value->basic_cover_si);
+           
 
             // dd($checkIfExist);
             if ($checkIfExist) {
 
-                    $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id,  $value->employee_id, $value->basic_cover_si,$premium);
+                    $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id,  $value->employee_id, $value->basic_cover_si);
 
                 }else{
 
                     $data['employee_id']= $value->employee_id;
                     $data['client_policy_id']= $value->client_policy_id;
                     $data['basic_cover_si']= $value->basic_cover_si;
-                    $data['premium']= $premium;
-                    $data['status'] = 'Draft';
+                    $data['status'] = 'draft';
             
                     $this->employeePolicyModel->insert($data);
                 }
             }
-                return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);             
+
+            $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code);
+
+            return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);             
            
         } catch (\Exception $e) {
             return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
@@ -624,8 +762,8 @@ class EmployeeRestController extends AdminController
                 $file_data =$this->fileModel->insert($extractData);
 
                 $extra = [];
-                if (count($data[0]) == 10) {
-                    $value = ['S.No','Emp Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI'];
+                if (count($data[0]) == 11) {
+                    $value = ['Sno','Emp_Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI','Grade'];
                     $check_miss_match = [];
                     for ($i=0; $i respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 200);
                 }
 
@@ -720,13 +858,14 @@ class EmployeeRestController extends AdminController
                             'email_corporate' => $extra['7'][$index],
                             'mobile'=> $extra['8'][$index],
                             'client_id' => $client_id,
-                            'emp_status'=>'draft'
+                            'emp_status'=>'draft',
+                            'band'=> $extra['10'][$index],
                             
                         ];
                         $basic_cover_si_value = null;
                         
                         //Grid id is 10 and 11 sum insure value add only for self other grid type self sum insure is for the dependence
-                            if ($policy_permium_2['policy_grid_id'] == 10 || $policy_permium_2['policy_grid_id'] == 11) {
+                            if (isset($policy_permium_2['policy_grid_id']) == 10 || isset($policy_permium_2['policy_grid_id']) == 11) {
                                 if (strtolower($extra['5'][$index]) == 'self') {
                                     $basic_cover_si_value = $extra['9'][$index];
                                 }else{
@@ -856,7 +995,7 @@ class EmployeeRestController extends AdminController
                     // $return_log = json_decode($return_log);
                     // $this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]);
                 }
-            return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 404);
+            return $this->respond(['status' => 'success', 'code' => 200, 'message' => "Success" ], 200);
             }else{
                 return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Client id and Client Policy id is Not Match!" ], 404);
             }
@@ -933,8 +1072,19 @@ public function getEmployeePolicy()
 
                     // Map family floaters that already exist in the employee table
                     $familyFloates = $array->Policy_Terms->family_floaters;
+                    
                     // Generate Notes string based on  familyFloates terms
                     $array->notes = $this->FloterNotesConvertion($familyFloates);
+                    
+                    if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1)
+                    {  
+                        $array->floter_text_heading = 'Floater Sum Insured';
+                        $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.';
+                    }else{ 
+                        $array->floter_text_heading = 'Sum Insured';
+                        $array->floter_text_description = '';
+                    }
+
                     // Convert familyFloaters terms data to plain array 
                     $floters = $this->FloterConvertion($familyFloates);
 
@@ -1003,9 +1153,9 @@ public function getEmployeePolicy()
 
                 }
                 
-                $result[] = $array;
+               // $result[] = $array;
             }
-          
+            return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);
             
 
         }else{
@@ -1059,6 +1209,8 @@ public function FloterNotesConvertion($array){
                 $string = ucwords($string);
                 $result .= ' + '.$string;
             }else if($value != 0 && $key ==='self') {
+            }else if($value != 0 && $key ==='childrens') {
+                if($value > 1){  $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child';  }
             }else{
                 $string = str_replace('-', ' ', $key);
                 $string = ucwords($string);
@@ -1066,7 +1218,7 @@ public function FloterNotesConvertion($array){
             }
         }
     }
-
+    
     return $result;
 }
 
@@ -1116,6 +1268,16 @@ public function getAddOnPolicy()
         $responce['is_addon'] = $array['is_addon'];
         $responce['open_for_enrollment'] = $array['open_for_enrollment'];
         $responce['policy_terms'] = $decodedArray;
+        
+        if(count($getSlabAndGridData['slab_rates'])){
+            if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1)
+            {  
+                $responce['floter_text_heading'] = 'Floater Sum Insured';
+            }else{ 
+                $responce['floter_text_heading'] =  'Sum Insured';
+            }
+        } 
+       
 
         if($array['is_addon'] == 3)
         {
@@ -1128,8 +1290,9 @@ public function getAddOnPolicy()
 
 
                     $data = [];
-                    $dependent_and_si_value = null;
-                    $dependent_and_si_premium_value = null;
+                    $dependent_and_si_value = 0;
+                    $dependent_and_si_premium_value = 0;
+                    $dependent_and_si_gst_value = 0;
                     foreach ($floters as $familyFloatesValue) { 
                         $dependent =   preg_replace('/\d/', '', $familyFloatesValue);
                         if(count($addOnEmployeeData)){
@@ -1137,7 +1300,8 @@ public function getAddOnPolicy()
                                 if ($value['family_floater_key'] === $dependent) {
                                     $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow();
                                     if(isset($employee_policy->basic_cover_si)){  $dependent_and_si_value = $employee_policy->basic_cover_si; }
-                                    if(isset($employee_policy->premium)){   $dependent_and_si_premium_value = $employee_policy->premium;}
+                                    if(isset($employee_policy->premium)){   $dependent_and_si_premium_value = $dependent_and_si_premium_value + $employee_policy->premium;}
+                                    if(isset($employee_policy->gst)){   $dependent_and_si_gst_value = $dependent_and_si_gst_value + $employee_policy->gst;}
                                     
                                     $temp['is_value_exist'] = true;
                                     $temp['data']['family_floater_key'] = $familyFloatesValue;
@@ -1214,6 +1378,7 @@ public function getAddOnPolicy()
                     $responce['family_floaters_of_dependent_and_si_array'] = $data;
                     $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value;
                     $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value;
+                    $responce['family_floaters_of_dependent_and_gst_value'] = $dependent_and_si_gst_value;
 
 
                     
@@ -1228,13 +1393,15 @@ public function getAddOnPolicy()
 
 
             $only_si_array = [];
-            $only_si_value = null;
-            $only_si_premium_value = null;
+            $only_si_value = 0;
+            $only_si_premium_value = 0;
+            $only_si_gst_value = 0;
             foreach ($GMCEmployeeData as $key => $value) {
 
                     $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow();
                     if(isset($employee_policy->basic_cover_si)){  $only_si_value = $employee_policy->basic_cover_si; }
-                    if(isset($employee_policy->premium)){   $only_si_premium_value = $employee_policy->premium;}
+                    if(isset($employee_policy->premium)){   $only_si_premium_value = $only_si_premium_value + $employee_policy->premium;}
+                    if(isset($employee_policy->gst)){   $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;}
                     $temp3['is_value_exist'] = true;
                     $temp3['data']['employee_id'] = $value['id'];
                     $temp3['data']['relationship'] = $value['relationship'];
@@ -1250,6 +1417,7 @@ public function getAddOnPolicy()
             $responce['family_floaters_of_only_si_array'] = $only_si_array;
             $responce['family_floaters_of_only_si_value'] = $only_si_value;
             $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value;
+            $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value;
 
             if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){
             return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200);
@@ -1261,7 +1429,7 @@ public function getAddOnPolicy()
         }
 
 
-       // return $this->respond(['status' => 'success','code' => 200,'data' => ['addon_policy'=>$responce]], 200);
+         return $this->respond(['status' => 'success','code' => 200,'data' => []], 200);
 
         }else{
             return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
@@ -1274,58 +1442,291 @@ public function getAddOnPolicy()
 public function iAgreeForAddOn()
 { 
 
-    $emp_code = $this->request->getGet('emp_code');
-    $client_policy_id = $this->request->getGet('client_policy_id');
-    $client_id = $this->request->getGet('client_id');
+    $emp_code = $this->request->getPost('emp_code');
+    $postData = json_decode($this->request->getBody(), true);
+    $client_policy_id = $postData['client_policy_id'];
 
     $this->employeeModel->where('emp_code', $emp_code )
                         ->where('is_active', 1 )
-                        ->set(array('emp_status'=>'Enrolled'))
+                        ->set(array('emp_status'=>'enrolled'))
                         ->update();
-    $this->employeePolicyModel->where('client_id', $client_id )
-                              ->where('client_policy_id', $client_policy_id )
-                              ->where('is_active', 1 )
-                              ->set(array('status'=>'Enrolled'))
-                              ->update();
+                        
+    if (!is_null($client_policy_id) && is_array($client_policy_id))
+    {
+        foreach ($client_policy_id as $key => $value) 
+        {
+            $this->employeePolicyModel->where('client_policy_id', $value )
+                                        ->where('is_active', 1 )
+                                        ->set(array('status'=>'enrolled'))
+                                        ->update();
+        }
+    }
+   
     return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200);
 }
 
 //Post method  - which receives client_policy id and empcode of the family.
 //Pull records againest emp code and calculate premium 
 // retun array
-public function calculatePremium()//family level
+public function calculatePremium($clientPolicyId = null , $empCode = null, $default_si = null)//family level
 { 
     helper('excel_util_helper');
-    $client_policy_id = $this->request->getVar('client_policy_id');
-    $emp_code = $this->request->getVar('emp_code');
+    $client_policy_id = $this->request->getVar('client_policy_id') ?? $clientPolicyId;
+    $emp_code = $this->request->getVar('emp_code') ?? $empCode;
+    $default_si = $this->request->getVar('si') ?? $default_si;// si amt which choosed in add on policy
     // dd($client_policy_id);
 
+
     $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id'];
     // get policy and rack details
     $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id);
+    $policy_type = $policy_terms[0]->is_addon;
+    $base_policy = $policy_terms[0]->base_policy;
     $policy_terms = (array) $policy_terms[0];// convert obj to array
 
     //get policy slab rates 
     $slab_details = $this->policesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id);
+    // print_r($slab_details);die();
 
     $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']);
 
+    if(!count($existing_famility_details) && $policy_type == 2)//top up addon only
+    {
+        //get basepolicy id then pull emplist from base policy if only current policy is DA addon policy and emplist is zero
+        // echo 'inside';
+        $client_policy_id = $base_policy;
+        $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_code: $emp_code,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']);
+    }
+
     $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception'];
     // dd($this->employeeModel->getLastQuery());
-    // dd($existing_famility_details);die();
+    // print_r($existing_famility_details);die();
      $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db');
-     // dd($employee_data_group_by_family);
+     // print_r(($employee_data_group_by_family));die();
      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);
+        // print_r($transformed_famility_details);die();
+         $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file,$default_si);
          // dd($data);
          $employee_data_group_by_family[$emp_id] = $data;
          
      }
 
-     // dd ($employee_data_group_by_family);
+     if($clientPolicyId != null && $empCode != null)
+     {
+       return $employee_data_group_by_family;
+     }else{
+        // dd ($employee_data_group_by_family);
      return $this->respond(['status' => 'success','code' => (count($employee_data_group_by_family) ? 200 : 404),'data' => [$employee_data_group_by_family] ], 200);
+
+     }
+     
 }
 
+
+public function getCashDepositData()
+{
+
+    $ClientPolicyData =  $this->clientPolicyModel->select('client_policy.client_id as clientId , client_policy.insurer_id as insurerId,insurers.name as insurer_name')
+                                                ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left')
+                                                ->where('client_policy.client_id', $this->request->getGet('client_id') )
+                                                ->groupBy('client_policy.insurer_id')
+                                                ->findAll();
+    $result = [];
+
+    if(count($ClientPolicyData))
+    {
+        foreach ($ClientPolicyData as $key => $value) {
+
+            $data['clientId'] = $value['clientId'];
+            $data['insurerId'] = $value['insurerId'];
+            $data['insurerName'] = $value['insurer_name'];
+            $data['depositData'] = $this->clientPolicyModel->getdepositData($value['clientId'],$value['insurerId']); 
+            $data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0;
+    
+            $data['policyDetails'] = [];
+            $ClientPolicyData =$this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon')
+                                                        ->join('policies', 'client_policy.policy_id = policies.id', 'left')
+                                                        ->where('client_policy.insurer_id',  $value['insurerId'] )
+                                                        ->where('client_policy.client_id', $this->request->getGet('client_id') )
+                                                        ->findAll();
+            foreach ($ClientPolicyData as $key => $value) 
+            {
+                $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']);
+                if($value['is_addon'] == "2"){ $value['type'] = 'SI TopUp'; }else if($value['is_addon'] == "3"){ $value['type'] = 'Dependent AddOn'; }else{ $value['type'] = $getSlabAndGridData['grid_master']['policy_type']; }
+                $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0);
+                $enrolledCount = 0;
+                $draftCount = 0;
+                if(count($employeeDetails))
+                {
+                    foreach ($employeeDetails as $item) {
+                        if ($item['emp_status'] === 'enrolled') {
+                            $enrolledCount++;
+                        } elseif ($item['emp_status'] === 'draft') {
+                            $draftCount++;
+                        }
+                    }
+                }
+               
+                $value['totalMembersCount'] = count($employeeDetails);
+                $value['membersCountOfEnrolled'] = $enrolledCount;
+                $value['membersCountOfDraft'] = $draftCount;
+    
+                array_push($data['policyDetails'],$value);
+            }
+    
+    
+            array_push($result,$data);
+        
+        }
+    }
+
+   
+
+     if($result)
+     {
+        return $this->respond(['status' => 'success','code' => (count($result) ? 200 : 404),'data' => $result ], 200);
+     }else{
+        return $this->respond(['status' => 'failed','code' => (count($result) ? 200 : 404),'data' => [] ], 200);
+     }
+     
+}
+
+
+
+
+public function exportCashDepositData()
+{
+
+    $CashDepositData = $this->clientPolicyModel->getdepositData($this->request->getGet('client_id'),$this->request->getGet('insurer_id')); 
+
+    // echo '
';print_r($CashDepositData); echo '
';die; + + if(count($CashDepositData)) + { + // Define headers and map database fields to Excel fields + $headers = [ + 'Date' => 'created_at', + 'Type' => 'transaction_type', + 'Amount' => 'amount', + 'Balance' => 'balance', + 'Description' => 'description', + 'Insurer Name' => 'insurer_name', + 'Client Name' => 'clientname' + ]; + + // Create a new Spreadsheet object + $spreadsheet = new Spreadsheet(); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Add headers + $column = 'A'; + foreach ($headers as $header => $dbField) { + $sheet->setCellValue($column . '1', $header); + $column++; + } + + // Add data + $row = 2; + foreach ($CashDepositData as $Cashvalue) { + $column = 'A'; + foreach ($headers as $dbField) { + $sheet->setCellValue($column . $row, $Cashvalue->$dbField); + $column++; + } + $row++; + } + + + // Set the header for download + $filename = $CashDepositData[0]->insurer_name.'-CashDeposit.xlsx'; + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $filename . '"'); + header('Cache-Control: max-age=0'); + + // Save the Excel file to output + $writer = new Xlsx($spreadsheet); + $writer->save('php://output'); + exit; + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => []], 200); + + }else{ + + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 200); + } + +} + + +public function removeEmpAndEmpPolicyData() +{ + try { + + $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll(); + + if(count($clientPolicy)) + { + + + if($clientPolicy[0]['is_addon'] == 2)//Topup + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 0 )->findAll(); + if(count($empData)) + { + foreach ($empData as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + + } + } + + } + else if($clientPolicy[0]['is_addon'] == 3)//Dependent addon + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 1 )->findAll(); + if(count($empData)) + { + foreach ($empData as $key => $value) { + + $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) + ->where('employee_id', $value['id'] ) + ->set(array('is_active'=> 0 )) + ->update(); + + } + + $this->employeeModel->where('emp_code', $this->request->getGet('emp_code') ) + ->where('is_active', 1 )->where('is_addon_value', 1 ) + ->set(array('is_active'=> 0 )) + ->update(); + } + + } + + + + return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); + + }else{ + return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 404); + } + + + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } + +} + + + } \ No newline at end of file diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 6007b717..46fb73ee 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -35,7 +35,7 @@ class EmployeeServiceController extends AdminController protected $empEndorsementModel; protected $general_relationships = ['self' => ['name' => 'Self', 'gender' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'gender' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'gender' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'gender' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'gender' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'gender' => 'F','age_min' => 18,'age_max' => null]]; - protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship','policy_terms']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>16,'col_cell_name'=>'Q','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>17,'col_cell_name'=>'R','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; + protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship','policy_terms']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; protected $deletion_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'change_event'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'Change event','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; @@ -568,7 +568,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']); - $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']; + $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception','created_by' => get_session_userid()]; // dd($this->employeeModel->getLastQuery()); // Kint::dump($existing_famility_details);die(); $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); @@ -619,14 +621,14 @@ class EmployeeServiceController extends AdminController $group_key = rand(100000, 999999); //for emp table - $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key]); + $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]); // dd( $this->empEndorsementModel->getLastQuery()); // $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'change_event','old_value' => $data['change_event'],'new_value' => 'deletion','created_by' => $file['created_by'],'remarks' => 'general deletion']); // for employee policy table - $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key]); - $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key]); - $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key]); + $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]); + $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]); + $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion','group_key' => $group_key,'file_id' => $file['id']]); }; //iterate each row foreach ($excel_data as $col_key => $row) @@ -736,7 +738,7 @@ class EmployeeServiceController extends AdminController if(!count($existing_endorsements)) { $group_key = rand(100000, 999999); - $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employees','actions' => 'c','name' => $employee['name'],'field_name' => $field_name,'old_value' => $employee[ $field_name ],'new_value' => $field_value,'created_by' => $file['created_by'],'remarks' => $row[7],'date_of_correction' => change_date_format($row[5],'d-M-Y','Y-m-d'),'group_key' => $group_key]); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employees','actions' => 'c','name' => $employee['name'],'field_name' => $field_name,'old_value' => $employee[ $field_name ],'new_value' => $field_value,'created_by' => $file['created_by'],'remarks' => $row[7],'date_of_correction' => change_date_format($row[5],'d-M-Y','Y-m-d'),'group_key' => $group_key,'file_id' => $file['id']]); } @@ -801,9 +803,9 @@ class EmployeeServiceController extends AdminController if($slab_value['si'] == $row[3]) { $group_key = rand(100000, 999999); - $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $row[3],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key]); - $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key]); - $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key]); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $row[3],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement','group_key' => $group_key,'file_id' => $file['id']]); break; } } @@ -956,6 +958,7 @@ class EmployeeServiceController extends AdminController { $error_message = "File not found"; $this->myLogger->logme('error',($error_message . ' for file id ' . $file_id)); + return 0; } $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index b283bc5a..4b14a8bd 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -130,6 +130,7 @@ class RestAuthenticationController extends AdminController 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) { diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index 95f164c8..5c29ce41 100644 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -112,6 +112,10 @@ if (! function_exists('transform_objects_to_array_for_inception')) { // Iterate through each object foreach ($objects as $obj) { + + $TPAID = isset($obj->tpa_id) && $obj->tpa_id !== '' ? $obj->tpa_id : ''; + $UHID = isset($obj->uhid) && $obj->uhid !== '' ? $obj->uhid : ''; + // Extract all values for the object $rowData = [ $serialNumber++, // Serial Number diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 3d8b9421..84ed0c24 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -247,22 +247,33 @@ if (!function_exists('data_group_by_family')) function data_group_by_family($emp_data,$data_source = 'excel') { $result = []; + // dd($emp_data); foreach ($emp_data as $rkey => $row) { if($data_source == 'excel') { if(!check_row_is_empty_or_null($row)) { - $result[$row[1]][] = $row; + if(strtolower($row[5]) == 'self' && isset($result[$row[1]])) + { + array_unshift($result[$row[1]],$row); + }else + { + $result[$row[1]][] = $row; + } } - }else if($data_source = 'db') { - $result[$row['emp_code']][] = $row; + if(strtolower($row['relationship']) == 'self' && isset($result[$row['emp_code']])) + { + array_unshift($result[$row['emp_code']],$row); + }else + { + $result[$row['emp_code']][] = $row; + } } } - return $result; } } @@ -509,7 +520,7 @@ if (!function_exists('generate_relationship_code')) if (!function_exists('calculate_premimum')) { - function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr) + function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr,$default_si = null) { // // dd($fileArr); @@ -530,10 +541,13 @@ if (!function_exists('calculate_premimum')) // dd($transformed_familiy_member_data); //store emp id and emp band and attach it to their familiy members where band is always empty - $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = null; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] : NULL; + + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = isset($emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']) ? $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] : NULL; if(strtolower($transformed_familiy_member_data['relationship']) == 'self') { $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = $transformed_familiy_member_data['band']; + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si'] = $transformed_familiy_member_data['policy_details']['basic_cover_si']; } //end of store emp id and emp band and attach it to their familiy members where band is always empty @@ -555,10 +569,11 @@ if (!function_exists('calculate_premimum')) $transformed_familiy_member_data['temp']['band'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']; $transformed_familiy_member_data['temp']['maxage'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage']; $transformed_familiy_member_data['temp']['maxcount'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount']; + $transformed_familiy_member_data['policy_details']['basic_cover_si'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['si']; if( $fileArr['id'] == null || (in_array($grid_type,[10,11]) || $transformed_familiy_member_data['temp']['source'] == 'excel'))//if file id is null then data coming from enrollment (from DB) otherwise data coming from xcel, so calculate only data from excel (new entry) note: even data coming from excel for event dependet additon we fetch other dependts from db and calculate premium for whole family { - $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details); + $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details,$default_si); $result[] = $transformed_familiy_member_data; } @@ -588,8 +603,8 @@ if (!function_exists('transform_excel_data_to_db')) $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['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]) ? change_date_format($memArr[7],'d-M-Y','Y-m-d') : NULL;; $policy['policy_end_date'] = null; @@ -630,20 +645,23 @@ if (!function_exists('transform_excel_data_to_db')) if (!function_exists('premium_calculation_manager')) { - function premium_calculation_manager($emp_data,$policy_terms,$slab_details) + function premium_calculation_manager($emp_data,$policy_terms,$slab_details,$default_si = null) { // grid type // 1 = premium => si + // dd($emp_data); + $slug = \Config\Services::slug(); $grid_type = $slab_details['grid_master']['ui_type']; switch ($grid_type) { case "1": //GPA - Sum Insured (SI) * Multiplier - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['si'] == $employee_received_si) { + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['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; @@ -658,11 +676,12 @@ if (!function_exists('premium_calculation_manager')) break; case "2": //GPA - Flat Rate for all SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['si'] == $employee_received_si) { + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['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; @@ -676,11 +695,12 @@ if (!function_exists('premium_calculation_manager')) break; case "3": //GMC - SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { if($slab_value['si'] == $employee_received_si) { + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['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; @@ -694,13 +714,17 @@ if (!function_exists('premium_calculation_manager')) break; case "4": + //GMC - Employees Age band - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + // dd($employee_received_si); foreach ($slab_details['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)) { + // dd($slab_value); + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['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; @@ -714,13 +738,13 @@ if (!function_exists('premium_calculation_manager')) break; case "5": //GMC - Employees Age + SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $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)) { - + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['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; @@ -734,13 +758,13 @@ if (!function_exists('premium_calculation_manager')) break; case "6": //GMC - Employees + Dependent Age band - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == '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']); $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; @@ -754,13 +778,13 @@ if (!function_exists('premium_calculation_manager')) break; case "7": //GMC - Employees + Dependent Age + SI - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == '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']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; @@ -776,14 +800,14 @@ if (!function_exists('premium_calculation_manager')) case "8": //GMC - SI as per Grade or Band $employee_received_band = $emp_data['temp']['band']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; - + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; @@ -798,13 +822,13 @@ if (!function_exists('premium_calculation_manager')) case "9": //GMC - Flat Rate for all $employee_received_band = $emp_data['temp']['band']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { - // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; + $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; @@ -819,20 +843,20 @@ if (!function_exists('premium_calculation_manager')) case "10": //GMC - Maximum age of Dependents $max_age = $emp_data['temp']['maxage']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; $emp_data['policy_details']['basic_cover_si'] = null; foreach ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age)) + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { - $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $employee_received_si : null); - $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (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'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); - $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); - $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); - $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); - $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + $emp_data['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']; + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } @@ -842,30 +866,84 @@ if (!function_exists('premium_calculation_manager')) //GMC - Maximum count per Family $max_count = $emp_data['temp']['maxcount']; $employee_received_band = $emp_data['temp']['band']; - $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + // 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 ($slab_details['slab_rates'] as $skey => $slab_value) { - if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band) && (($slab_value['premium_type'] == 1 && strtolower($emp_data['relationship']) == 'self') || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) )) { //calculate premium based on count + // echo $emp_data['name']; $familiy_si_covered = $employee_received_si * $max_count; $familiy_si_covered = ($familiy_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $familiy_si_covered); - $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $familiy_si_covered : null); - $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (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'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); - $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); - $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); - $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); - $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + $emp_data['policy_details']['basic_cover_si'] = $familiy_si_covered; + $emp_data['policy_details']['date_coverage'] = (empty($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($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); break; } } break; + case "12": + //GMC - Employee + relationship + + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $employee_relationship = $slug->slugify($emp_data['relationship']); + $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); + $emp_data['policy_details']['basic_cover_si'] = null; + foreach ($slab_details['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['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = (empty($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($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); + + break; + } + } + break; + + case "13": + //GMC - Employee + relationship + age + $employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si; + $employee_relationship = $slug->slugify($emp_data['relationship']); + $employee_relationship = ($employee_relationship == 'daughter' || $employee_relationship == 'son' ? $employee_relationship = 'child' : $employee_relationship); + $emp_data['policy_details']['basic_cover_si'] = null; + $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; + foreach ($slab_details['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['policy_details']['basic_cover_si'] = $employee_received_si; + $emp_data['policy_details']['date_coverage'] = (empty($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($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')); + + break; + } + } + break; + + + default: echo "Not a valid grid"; } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 2c27280b..e5b4e591 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -185,6 +185,7 @@ class ClientPolicyModel extends Model ->where('cash_deposit.client_id', $clientId) ->where('cash_deposit.insurer_id', $insurerId) // Add this line to filter by insurer_id + ->orderBy('cash_deposit.id', 'DESC') ->get() ->getResult(); } diff --git a/app/Models/EmpEndorsementModel.php b/app/Models/EmpEndorsementModel.php index 8be6c38c..ab20b712 100644 --- a/app/Models/EmpEndorsementModel.php +++ b/app/Models/EmpEndorsementModel.php @@ -25,7 +25,8 @@ class EmpEndorsementModel extends Model "created_by", "updated_by", "is_active", - "remarks" + "remarks", + "file_id" ]; // Callbacks diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 50b0eadf..fe534ebf 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -139,4 +139,30 @@ class EmployeeModel extends Model return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->first(); } + + public function getEmpListByFileId(int $file_id,array $emp_status = [],array $policy_status = []) + { + $result = $this->select(['employees.id as emp_id', 'employees.client_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']) + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.is_active',1) + ->where('employees.file_id',$file_id) + ->where('employee_polices.is_active',1) + // ->where('employee_polices.uhid is not null') + // ->where('employee_polices.tpa_id is not null') + ->groupStart() + ->orWhere('employee_polices.uhid is not null') + ->orWhere('employee_polices.tpa_id is not null') + ->groupEnd() + ->when(count($emp_status), function($query) use ($emp_status){ + return $query->whereIn('employees.emp_status', $emp_status); + }) + ->when(count($policy_status), function($query) use ($policy_status){ + return $query->whereIn('employee_polices.status', $policy_status); + }) + ->findAll(); + // ~dd($this->db->getLastQuery()); + + return ($result); + } + } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 084247bf..3198d873 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -79,13 +79,17 @@ class EmployeePolicyModel extends Model ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach ->join('clients cm', 'cp.client_id = cm.id') //cm - client master ->where('emp.client_id',$client_id) - ->where('employee_polices.client_policy_id',$policy_id); + ->where('employee_polices.is_active',1) + ->where('emp.is_active',1) + ->where('employee_polices.client_policy_id',$policy_id) + ->orderBy('emp.emp_code','ASC')->orderBy('employee_polices.employee_id','ASC'); + if($status != 0 && !empty($status)){ $result->where('employee_polices.status', $status); } - $result = $result->findAll(); + $result = $result->findAll(); return ($result); } @@ -106,6 +110,16 @@ class EmployeePolicyModel extends Model { $client_policy_id = $ref_data['client_policy_id']; $insurer_or_tpa = $ref_data['insurer_or_tpa']; + $event = $ref_data['event_type']; + + if($insurer_or_tpa == 'tpa'){ + + $id = 'tpa_id'; + + }else if($insurer_or_tpa == 'insurer'){ + + $id = 'uhid'; + } $sql = " SELECT @@ -120,6 +134,8 @@ class EmployeePolicyModel extends Model 'Has Define' as emp_type, employee_polices.id as primaryKey, + employee_polices.tpa_id, + employee_polices.uhid, employee_polices.pre_existing_alignments, employee_polices.basic_cover_si, employee_polices.date_coverage, @@ -141,15 +157,12 @@ class EmployeePolicyModel extends Model batch_files.batch_code as bf FROM batch_files LEFT JOIN batch_list ON batch_files.batch_code = batch_list.batch_code - WHERE batch_files.event_type = 'inception' + WHERE batch_files.event_type = '{$event}' AND batch_files.actions = 'export' AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' ) as batch_data ON employee_polices.id = batch_data.emp_policy_id - WHERE batch_data.bf IS NULL - AND batch_data.bl IS NULL - AND employee_polices.client_policy_id = '{$client_policy_id}' - AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '') - AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '') + WHERE employee_polices.client_policy_id = '{$client_policy_id}' + AND (employee_polices.{$id} IS NULL OR employee_polices.{$id} = '') AND employee_polices.is_active = 1"; // Get the result set @@ -555,7 +568,7 @@ class EmployeePolicyModel extends Model // } - public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si,$premium) + public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si,$premium = 0) { @@ -659,12 +672,14 @@ class EmployeePolicyModel extends Model ->where('employee_polices.client_policy_id',$policy_id); $result->whereIn('employee_polices.status', ['draft', 'enrolled']); + $result->whereIn('emp.emp_status', ['draft', 'enrolled']); $result = $result->findAll(); return ($result); } - public function getViewEmpSuccessList($file_id){ + public function getViewEmpSuccessList($file_id) + { return $this->db->table('employees emp') ->select(['employee_polices.*','pm.name as policy_name','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active','emp.mobile as mobile']) ->join('employee_polices', 'employee_polices.employee_id = emp.id') @@ -679,5 +694,55 @@ class EmployeePolicyModel extends Model ->whereIn('employee_polices.status', ['draft', 'enrolled']) ->get()->getResultArray(); } + + public function getECardDataUsingMd5($client_policy_id, $emp_code){ + + $result = $this->db->table('employees e') + ->select('e.id, + e.name, e.mobile, + e.relationship, + e.relationship_code, + e.emp_code, + e.email_personal, + e.email_corporate, + e.gender, + e.dob, + e.doj, + e.band, + TIMESTAMPDIFF(YEAR, e.dob, CURDATE()) AS emp_age, + + ep.tpa_id, + ep.uhid, + ep.policy_end_date, + + clients.client_name, + clients.short_name AS client_short_name, + + policies.name AS policy_name, + + insurers.name AS insurer_name, + insurers.short_name AS insurer_short_name, + + tpa.name AS tpa_name, + tpa.short_name AS tpa_short_name' + ) + + ->join('employee_polices ep', 'ep.employee_id = e.id') + ->join('client_policy cp', 'cp.id = ep.client_policy_id') + ->join('clients', 'clients.id = cp.client_id') + ->join('policies', 'policies.id = cp.policy_id') + ->join('insurers', 'insurers.id = cp.insurer_id') + ->join('tpa', 'tpa.id = cp.tpa_id') + ->where('e.emp_status', 'active') + ->where('e.is_active', '1') + ->where('ep.status', 'active') + ->where('ep.is_active', '1') + ->where('MD5(e.emp_code)', $emp_code) + ->where('MD5(ep.client_policy_id)', $client_policy_id) + ->get() + ->getResultArray(); + + return $result; + } } \ No newline at end of file diff --git a/app/Models/PolicyPremium2Model.php b/app/Models/PolicyPremium2Model.php index e390dcc7..85ee9972 100644 --- a/app/Models/PolicyPremium2Model.php +++ b/app/Models/PolicyPremium2Model.php @@ -24,6 +24,7 @@ class PolicyPremium2Model extends Model "updated_by", 'is_active', 'premium_type', + 'relationship', ]; diff --git a/app/Views/employee_upload.php b/app/Views/employee_upload.php index 959e1509..e6fccef7 100644 --- a/app/Views/employee_upload.php +++ b/app/Views/employee_upload.php @@ -1,3 +1,10 @@ +
@@ -124,7 +131,7 @@
@@ -152,6 +159,10 @@ $('#file_upload').hide(); $(document).ready(function() { + + has('success1')): ?> + toastr.success('getFlashdata('success1') ?>', 'success'); + // Initialize select2 $("#client_id").select2(); $("#policy_id").select2(); @@ -478,10 +489,10 @@ $(document).ready(function() { $('#client_id').on('change', function() { var selectedClient = $(this).val(); + console.log('selectedClient', selectedClient); // $('#selectedOptionInfo').text('Selected option: ' + selectedOption); - // Check if the selected option exists in apiData var foundPolicies = clientPolicies.find(function(item) { return item.id === selectedClient; @@ -489,64 +500,6 @@ $(document).ready(function() { console.log(foundPolicies.policies); appendPolicies(foundPolicies.policies); - var apiURL = '' + 'util/fetch-emp-count/' + selectedClient; - console.log(apiURL); - $.ajax({ - url: apiURL, - method: 'GET', - headers: { - "Content-Type": "application/json", - "X-Requested-With": "XMLHttpRequest" - }, - success: function(response) { - - console.log('responce data emp_count', response); - - if (response.code === 200 && response.dataStatus === true && response.data !== "") { - try { - console.log(response.emp_count.length) - if(response.emp_count > 0){ - - var select = document.getElementById("upload-action-type"); - for (var i = 0; i < select.options.length; i++) { - if (select.options[i].value === "inception") { - select.options[i].disabled = true; - break; - } - } - }else{ - - var select = document.getElementById("upload-action-type"); - for (var i = 0; i < select.options.length; i++) { - if (select.options[i].value === "inception") { - select.options[i].disabled = false; - break; - } - } - } - - } 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); - var select = document.getElementById("upload-action-type"); - for (var i = 0; i < select.options.length; i++) { - if (select.options[i].value === "inception") { - select.options[i].disabled = false; - break; - } - } - } - }); }); }); @@ -637,6 +590,12 @@ document.getElementById('toggleIcon1').addEventListener('click', function() { $('#fetch_enrolled_data').click(function() { + var policy_id = $('#policy_id').val(); + var uri = '' + policy_id; + console.log(policy_id); + console.log(uri); + $('#fetch_btn').attr('href', uri); + $('#emp_data').empty(); var client_id = $('#client_id').val(); var policy_id = $('#policy_id').val(); @@ -700,5 +659,75 @@ $('#fetch_enrolled_data').click(function() }) +$(document).ready(function() { + + $('#policy_id').change(function(){ + + var selectedpolicy = $(this).val(); + console.log('selectedpolicy',selectedpolicy) + + var apiURL = '' + 'util/fetch-emp-count/' + selectedpolicy; + console.log(apiURL); + $.ajax({ + url: apiURL, + method: 'GET', + headers: { + "Content-Type": "application/json", + "X-Requested-With": "XMLHttpRequest" + }, + success: function(response) { + + console.log('responce data emp_count', response); + + if (response.code === 200 && response.dataStatus === true && response.data !== "") { + try { + console.log(response.emp_count.length) + if(response.emp_count > 0){ + + var select = document.getElementById("upload-action-type"); + for (var i = 0; i < select.options.length; i++) { + if (select.options[i].value === "inception") { + select.options[i].disabled = true; + break; + } + } + }else{ + + var select = document.getElementById("upload-action-type"); + for (var i = 0; i < select.options.length; i++) { + if (select.options[i].value === "inception") { + select.options[i].disabled = false; + break; + } + } + } + + } 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); + var select = document.getElementById("upload-action-type"); + for (var i = 0; i < select.options.length; i++) { + if (select.options[i].value === "inception") { + select.options[i].disabled = false; + break; + } + } + } + }); + }) + +}) + + //-------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/app/Views/excel_errors.php b/app/Views/excel_errors.php index 0e8b070e..7c09353c 100644 --- a/app/Views/excel_errors.php +++ b/app/Views/excel_errors.php @@ -66,6 +66,7 @@ table.dataTable tbody td { +
@@ -118,6 +119,12 @@ $(document).ready(function() { extend: 'excel', text: 'Excel', // Set the title for the Excel button title: 'ExcelErrorData', // Set your custom title here + }, + { + text: 'Excel Error', // Set the text for the custom button + action: function (e, dt, node, config) { + window.location.href = ''; + } } ], paging: false, // Disable pagination diff --git a/app/Views/file_list.php b/app/Views/file_list.php index 0eb25a30..a3bf934f 100644 --- a/app/Views/file_list.php +++ b/app/Views/file_list.php @@ -86,6 +86,11 @@ data-target="#full-width-modal-emp-list" class="dropdown-item view_emp_list" href="#">View + + Truncate + @@ -225,6 +230,80 @@ $('body').on('click', '.upload_button', function() { $('#file_upload_actions').val(fileId.action) }) +$('body').on('click', '.truncate', function() { + event.preventDefault(); + // console.log(event); + var fileId = JSON.parse(this.getAttribute('data-id')); + // alert('Hi' + fileId); + + Swal.fire({ + title: "Do you want to truncate data from uploaded file?", + showCancelButton: true, + confirmButtonText: "Delete", + confirmButtonColor: "#ff3333", + }).then((result) => { + + console.log(result); + if (result.isConfirmed) { + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); + var apiURL = '' + 'employee/truncate/' + fileId; + $.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); + setTimeout(function() { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + }, 1000); + + + if (response.code === 200 && response.dataStatus === true && response.data !== "") { + Swal.fire({ + title: "Deleted!", + // text: "Data from truncated", + icon: "success" + }); + } else if (response.code === 404 && response.dataStatus === false) { + console.error('no data found', response); + Swal.fire({ + title: "Failed!", + text: response.message, + icon: "error" + }); + } else { + + Swal.fire({ + title: "Failed!", + text: 'Something went wrong! Try later', + icon: "error" + }); + } + }, + error: function(xhr, status, error) { + setTimeout(function() { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + }, 1000); + + console.error('Error fetching data from API:', error); + toastr.error('Something went wrong! Try later', 'Error'); + } + }); + + } + }); + + +}) + $('#uploadForm').submit(function() { diff --git a/app/Views/id_card_view.php b/app/Views/id_card_view.php new file mode 100644 index 00000000..b646bb87 --- /dev/null +++ b/app/Views/id_card_view.php @@ -0,0 +1,80 @@ + + + + + + + Driving License ID Card + + + + +
+ + $value) { ?> + + + + + + +
+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +
+
+
+

Terms and Conditions

+

This card is non-transferable and is valid at network hospitals only.

+
    +
  • will enable Card Holder to avail cashless hospitalization only on the basis of +
  • +
  • In the case of photoless identity cards issued to beneficiaries, acceptable + proof
  • +
  • Notify the authorities in case of any changes to your personal information.
  • +
  • The mentioned covers are add-ons by paying additional premium and available only if opted by the policyholders.
  • +
+
+
+
+
+ + + button + + + + + \ No newline at end of file diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index 89946fec..289392f5 100644 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -27,16 +27,17 @@
-
+ +

@@ -66,7 +67,7 @@ $('#btnGridSubmit').hide(); $('.close').click(function() { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -92,7 +93,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa if (dataIdValue == '1') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -164,7 +165,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa `; } else if (dataIdValue == '2') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -186,7 +187,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '3') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -211,7 +212,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '4') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } grid_html = ` @@ -245,7 +246,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '5') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -278,7 +279,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '6') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -313,7 +314,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '7') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -346,7 +347,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '8') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -376,7 +377,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '9') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -406,7 +407,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '10') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -438,7 +439,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa } else if (dataIdValue == '11') { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } @@ -469,8 +470,92 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa `; + } else if (dataIdValue == '12') { + + for (var i = 1; i <= 13; i++) { + $('#grid_' + i).remove(); + } + + grid_html = ` + +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
`; + + } else if (dataIdValue == '13') { + + for (var i = 1; i <= 13; i++) { + $('#grid_' + i).remove(); + } + + grid_html = ` + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
`; + } else { - for (var i = 1; i <= 11; i++) { + for (var i = 1; i <= 13; i++) { $('#grid_' + i).remove(); } grid_html = ''; @@ -597,6 +682,7 @@ $('body').on('click', '.btnPolicyModel', function() { $('.loader').fadeIn(); $('.loader-mask').fadeIn(); + $.ajax({ url: '', type: "GET", @@ -608,6 +694,14 @@ $('body').on('click', '.btnPolicyModel', function() { $('#GridForm')[0].reset(); + if(res.family_floater == 1){ + $('#premium_type').show(); + $('#individual').prop('checked', true) + }else{ + $('#premium_type').hide(); + $('#individual').prop('checked', false) + } + setTimeout(function() { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); @@ -620,7 +714,7 @@ $('body').on('click', '.btnPolicyModel', function() { $('#nameOfThePolicy').html(' - ' + res.policy_name); $('#grid_emp_count').val(res.count); - if (res.count == false) { + if (res.count > 0) { console.log('count -- 2', res.count); $("#btnGridSubmit_2").hide(); } else { @@ -634,7 +728,8 @@ $('body').on('click', '.btnPolicyModel', function() { } var policy_grid_id_value = ''; - if (res.premiumData && res.premiumData.length > 0 && res.premiumData[0].policy_grid_id) { + if (res.premiumData && res.premiumData.length > 0 && res.premiumData[0] + .policy_grid_id) { policy_grid_id_value = res.premiumData[0].policy_grid_id; } @@ -649,23 +744,26 @@ $('body').on('click', '.btnPolicyModel', function() { }); $('#grid').html(policeGridOptionHTML); - if(res.premiumData[0].hasOwnProperty('premium_type')){ + if (res.premiumData[0].hasOwnProperty('premium_type')) { if (res.premiumData[0].premium_type == '2') { $('#individual').prop('checked', true) $('#single').prop('checked', false) - } else if (res.premiumData[0].premium_type == '1') { + } else if (res.premiumData[0].premium_type == '1') { $('#single').prop('checked', true) $('#individual').prop('checked', false) + + } else { + $('#single').prop('checked', false) + $('#individual').prop('checked', false) } } - var si_or_bp_value = ''; if (res.premiumData && res.premiumData.length > 0) { @@ -732,8 +830,8 @@ $('body').on('click', '.btnPolicyModel', function() { $('#grid').empty(); $('#nameOfThePolicy').html(''); $('#GridForm').hide(); - $('#no_data').html('The policy has no Policy Rac Rate'); - toastr.warning("The policy has no Policy Rac Rate", "Warning") + $('#no_data').html('The policy has no Policy Rack Rate'); + toastr.warning("The policy has no Policy Rack Rate", "Warning") } @@ -1101,6 +1199,78 @@ function appendGridtHtml(ui_type = false, data = false, ) { `; + } else if (ui_type == '12') { + + html = ` +
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
`; + } else if (ui_type == '13') { + + html = ` +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + +
+
`; } @@ -1113,8 +1283,6 @@ function appendGridtHtml(ui_type = false, data = false, ) { Count++ - - // Number to word $(document).keyup(function(event) { if (event.target) { diff --git a/app/Views/view_file_upload_emp_list.php b/app/Views/view_file_upload_emp_list.php index 11554d1f..2d61789d 100644 --- a/app/Views/view_file_upload_emp_list.php +++ b/app/Views/view_file_upload_emp_list.php @@ -21,7 +21,7 @@ table.dataTable tbody td { - + diff --git a/composer.json b/composer.json index 77501e0f..2dd9d301 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "ext-intl": "*", "ext-json": "*", "ext-mbstring": "*", + "dompdf/dompdf": "^2.0", "firebase/php-jwt": "^6.10", "google/apiclient": "^2.15.0", "laminas/laminas-escaper": "^2.9", diff --git a/public/assets/images/1.jpg b/public/assets/images/1.jpg new file mode 100644 index 00000000..3404d32c Binary files /dev/null and b/public/assets/images/1.jpg differ diff --git a/public/assets/images/1.svg b/public/assets/images/1.svg new file mode 100644 index 00000000..d145a0e0 --- /dev/null +++ b/public/assets/images/1.svg @@ -0,0 +1,471 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/assets/images/2.jpg b/public/assets/images/2.jpg new file mode 100644 index 00000000..572bdfa1 Binary files /dev/null and b/public/assets/images/2.jpg differ diff --git a/tests/unit/GridType11PremiumCalculationTest.php b/tests/unit/GridType11PremiumCalculationTest.php new file mode 100644 index 00000000..5c6a5ef1 --- /dev/null +++ b/tests/unit/GridType11PremiumCalculationTest.php @@ -0,0 +1,177 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => 1, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 5000000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => 1, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => 1, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', 'G', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); + } + + public function testType11PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 500000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => NULL, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 500000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => NULL, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '500000', '', '', '', 'C', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType11PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'A', 'si' => 500000, 'premium' => 500, 'max_si' => 2500000,'premium_type' => NULL, 'relationship' => null], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => 2000000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'C', 'si' => 500000, 'premium' => 400, 'max_si' => 1800000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'D', 'si' => 5000000, 'premium' => 800, 'max_si' => 150000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'E', 'si' => 5000000, 'premium' => 8000, 'max_si' => 130000, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'F', 'si' => 5000000, 'premium' => 14000, 'max_si' => 10, 'premium_type' => NULL, 'relationship' => null], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 11, 'age_from' => null, 'age_to' => null, 'grade' => 'G', 'si' => 5000000, 'premium' => 12000, 'max_si' => 5, 'premium_type' => NULL, 'relationship' => null]], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 11,'policy_grid_type' => 'Employees + Relationship + max count','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', '', '01-Jan-2024', '01-Jan-2020', 50000, '', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '500000', '', '', '', 'C', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + +} \ No newline at end of file diff --git a/tests/unit/GridType12PremiumCalculationTest.php b/tests/unit/GridType12PremiumCalculationTest.php new file mode 100644 index 00000000..8615a834 --- /dev/null +++ b/tests/unit/GridType12PremiumCalculationTest.php @@ -0,0 +1,177 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'child'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 15000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); + } + + public function testType12PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'child'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'father'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 15000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => NULL, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType12PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => null, 'age_to' => null, 'grade' => null, 'si' => 5000000, 'premium' => 50, 'max_si' => 0,'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 25000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 20000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'child'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 18000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'father'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 15000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 2, 'age_from' => null, 'age_to' => null, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 12,'policy_grid_type' => 'Employees + Relationship','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1990', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + +} \ No newline at end of file diff --git a/tests/unit/GridType13PremiumCalculationTest.php b/tests/unit/GridType13PremiumCalculationTest.php new file mode 100644 index 00000000..24d7aaa3 --- /dev/null +++ b/tests/unit/GridType13PremiumCalculationTest.php @@ -0,0 +1,177 @@ +[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 1, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1990', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue(($policy_created_count = 1 || $policy_created_count = 0)); + } + + public function testType13PremiumCalculationWithPremiumTypeNull() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => NULL, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + + public function testType13PremiumCalculationWithPremiumTypeTwo() + { + helper('excel_util_helper'); + + $slab_details = [ 'slab_rates' =>[ + [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 12, 'age_from' => 18, 'age_to' => 35, 'grade' => null, 'si' => 5000000, 'premium' => 500, 'max_si' => 0,'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 1500, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'self'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 18, 'age_to' => 35, 'grade' => '', 'si' => 5000000, 'premium' => 400, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 55, 'grade' => '', 'si' => 5000000, 'premium' => 800, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'spouse'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 8000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 36, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 14000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'father-in-law'], + [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => 4, 'age_from' => 40, 'age_to' => 65, 'grade' => '', 'si' => 5000000, 'premium' => 12000, 'max_si' => 0, 'premium_type' => 2, 'relationship' => 'mother-in-law']], + + 'grid_master' => ['id' => 4,'policy_type' => 'GMC','ui_type' => 13,'policy_grid_type' => 'Employees + Relationship + age','is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 0,'basicpay' => 0,'emp_band' => 0,] + ]; + // Sample family data + $family_details = [ 'TEST001' => + [1,'TEST001','Jane Doe', '01-Jan-1988', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', 'None', '', '', ''], + [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', '', '', '', '', '', '', '', '', '', ''], + [3,'TEST001','Peter Doe', '01-Jan-1990', 'M', 'Father', '', '', '', '', '', '', '', '', '', '', ''], + [4,'TEST001','Mary Doe', '01-Jan-1990', 'F', 'Mother', '', '', '', '', '', '', '', '', '', '', ''], + [5,'TEST001','Grace Doe', '01-Jan-1990', 'F', 'Mother in law', '', '', '', '', '', '', '', '', '', '', ''], + [6,'TEST001','George Doe', '01-Jan-1990', 'M', 'Father in law', '', '', '', '', '', '', '', '', '', '', ''], + [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', ''], + [8,'TEST001','Bob Doe', '01-Jan-1990', 'M', 'Son', '5000000', '', '', '', '', '', '', '', '', '', ''], +]; + + // Sample policy terms + $policy_terms = [ + 'family_floater' => true, + 'family_floaters' => [ + 'childrens' => 2, + 'spouse' => 1, + 'either-parents-pil' => 0, + 'parents' => 2, + 'parents-in-law' => 2, + ], + ]; + + $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms)]; + $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception']; + $data = calculate_premimum($family_details,$policy_details,$slab_details,$file); + $policy_created_count = 0; + echo "\n"; + foreach ($data as $key => $value) + { + echo $value['emp_code'].' - '.$value['name'].' - '.$value['relationship'].' - '.$value['policy_details']['basic_cover_si'].' - '.$value['policy_details']['premium']."\n"; + if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } + } + // Kint::dump($data); + $this->assertTrue($policy_created_count > 1); + } + + +} \ No newline at end of file