From a5a368b7db0a5b1f627461ddd9d69835cab8858b Mon Sep 17 00:00:00 2001 From: velz Date: Wed, 31 Jul 2024 08:41:02 +0530 Subject: [PATCH 1/7] CHANGE_TESTCASE_DELETED --- tests/unit/PremiumCalculationTestNew.php | 236 ----------------------- 1 file changed, 236 deletions(-) delete mode 100644 tests/unit/PremiumCalculationTestNew.php diff --git a/tests/unit/PremiumCalculationTestNew.php b/tests/unit/PremiumCalculationTestNew.php deleted file mode 100644 index 93eca137..00000000 --- a/tests/unit/PremiumCalculationTestNew.php +++ /dev/null @@ -1,236 +0,0 @@ - 4,'policy_type' => 'GMC','ui_type' => $primary_grid_id,'policy_grid_type' => $primary_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; - $primary_slabs = [ - [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 500, 'max_si' => $primary_max_si,'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 3500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4000, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 4500, 'max_si' => $primary_max_si, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => $primary_max_si, 'premium' => 15000, 'max_si' => 0, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $primary_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 30000000, 'premium' => 30000, 'max_si' => 0, 'premium_type' => $primary_grid_type, 'relationship' => null,'additional_relationship' => $primary_relationship,'unit' => $primary_unit] - ]; - - //second slab - $second_relationship = '{"self":"NA","spouse":"NA","childrens":"NA","parents":"any","parents-in-law":"NA","either-parents-pil":0}'; - $second_grid_id = 10; - $second_unit = 'unit1'; - $second_grid_type = 1; - $second_max_si = 35000000; - $second_grid_name = 'max age'; - $second_grid_master = ['id' => 4,'policy_type' => 'GMC','ui_type' => $second_grid_id,'policy_grid_type' => $second_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; - $second_slabs = [ - [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 700, 'max_si' => 2500000,'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit ], - [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1400, 'max_si' => 2000000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2300, 'max_si' => 1800000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2750, 'max_si' => 150000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3500, 'max_si' => 130000, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 4250, 'max_si' => 10, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4950, 'max_si' => 5, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $second_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 5500, 'max_si' => 5, 'premium_type' => $second_grid_type, 'relationship' => null,'additional_relationship' => $second_relationship,'unit' => $second_unit] - - ]; - - // third slab - $third_relationship = '{"self":"NA","spouse":"NA","childrens":"NA","parents":1,"parents-in-law":"NA","either-parents-pil":0}'; - $third_grid_id = 7; - $third_unit = 'unit1'; - $third_grid_type = 1; - $third_max_si = 35000000; - $third_grid_name = 'age band'; - $third_grid_master = ['id' => 4,'policy_type' => 'GMC','ui_type' => $third_grid_id,'policy_grid_type' => $third_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; - $third_slabs = [ - [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 701, 'max_si' => 2500000,'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit ], - [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 1401, 'max_si' => 2000000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 2301, 'max_si' => 1800000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 2751, 'max_si' => 150000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 3501, 'max_si' => 130000, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 4251, 'max_si' => 10, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 4951, 'max_si' => 5, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $third_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 5501, 'max_si' => 5, 'premium_type' => $third_grid_type, 'relationship' => null,'additional_relationship' => $third_relationship,'unit' => $third_unit] - - ]; - - - // fourth slab - $fourth_relationship = '{"self":"NA","spouse":"NA","childrens":"NA","parents":"NA","parents-in-law":2,"either-parents-pil":0}'; - $fourth_grid_id = 11; - $fourth_unit = 'unit1'; - $fourth_grid_type = 2; - $fourth_max_si = 8000000; - $fourth_grid_name = 'age band'; - $fourth_grid_master = ['id' => 4,'policy_type' => 'GMC','ui_type' => $fourth_grid_id,'policy_grid_type' => $fourth_grid_name,'is_dependent_allowed' => 1,'max_dependent_age' => 0,'max_dependent_count' => 1,'basicpay' => 0,'emp_band' => 0]; - $fourth_slabs = [ - [ 'id' => 322, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 0, 'age_to' => 18, 'grade' => 'A', 'si' => 5000000, 'premium' => 1111, 'max_si' => $fourth_max_si,'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit ], - [ 'id' => 323, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 19, 'age_to' => 25, 'grade' => 'B', 'si' => 5000000, 'premium' => 2222, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 26, 'age_to' => 35, 'grade' => 'C', 'si' => 5000000, 'premium' => 3333, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 36, 'age_to' => 45, 'grade' => 'D', 'si' => 5000000, 'premium' => 4444, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 46, 'age_to' => 55, 'grade' => 'E', 'si' => 5000000, 'premium' => 5555, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 56, 'age_to' => 75, 'grade' => 'F', 'si' => 5000000, 'premium' => 6666, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 76, 'age_to' => 85, 'grade' => 'G', 'si' => 5000000, 'premium' => 7777, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 5000000, 'premium' => 8888, 'max_si' => $fourth_max_si, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit], - [ 'id' => 324, 'client_id' => 61, 'client_policy_id' => 63, 'policy_grid_id' => $fourth_grid_id, 'age_from' => 86, 'age_to' => 100, 'grade' => 'G', 'si' => 8000000, 'premium' => 9999, 'max_si' => 0, 'premium_type' => $fourth_grid_type, 'relationship' => null,'additional_relationship' => $fourth_relationship,'unit' => $fourth_unit] - - ]; - - //overall rack rate - $over_all_rack_details = [ 'primary' => [ "slab_rates" => $primary_slabs,'grid_master' => $primary_grid_master], - 'two parent' => ["slab_rates" => $second_slabs,'grid_master' => $second_grid_master], - 'single parent' => ["slab_rates" => $third_slabs,'grid_master' => $third_grid_master], - 'double_parent_in_law' => ["slab_rates" => $fourth_slabs,'grid_master' => $fourth_grid_master] - -]; - - // Sample family data - $family_details = [ - [2,'TEST001','John Doe', '01-Jan-1988', 'M', 'Self', '5000000', NULL, '', '', 'G', '', '', '', '', '', '','','unit1'], - [1,'TEST001','Jane Doe', '01-Jan-1985', 'F', 'Spouse', 5000000, '01-Jan-2024', '01-Jan-2020', 50000, 'A', 'Manager', '1234567890', 'john.doe@example.com', '0', '', '', '',''], - - // [3,'TEST001','Peter Doe', '01-Jan-1955', 'M', 'Father', '', NULL, '', '', '', '', '', '', '', '', '','',''], - [4,'TEST001','Mary Doe', '01-Jan-1953', 'F', 'Mother', '', NULL, '', '', '', '', '', '', '', '', '','',''], - [5,'TEST001','Grace Doe', '01-Jan-1954', 'F', 'Mother in law', '', NULL, '', '', '', '', '', '', '', '', '','',''], - //[6,'TEST001','George Doe', '01-Jan-1948', 'M', 'Father in law', '', NULL, '', '', '', '', '', '', '', '', '','',''], - [7,'TEST001','Alice Doe', '01-Jan-1990', 'F', 'Daughter', 5000000, '01-Jan-2024', '01-Jan-2024', 40000, 'B', 'Supervisor', '9876543210', '', '', '', '','',''], - [6,'TEST001','Bob Doe', '01-Jan-1993', 'M', 'son', '50000', NULL, '', '', '', '', '', '', '', '', '','',''], - ]; - - // Sample policy terms - $policy_terms = [ - 'family_floater' => true, - 'family_floaters' => [ - 'self' => 1, - 'spouse' => 1, - 'childrens' => 2, - 'either-parents-pil' => 0, - 'parents' => 2, - 'parents-in-law' => 2, - ], - ]; - //re organize over_all_rack_details - $all_rack_rates = []; - foreach ($over_all_rack_details as $key => $value) { - foreach ($value['slab_rates'] as $skey => $svalue) { - $svalue['rack_rate_name'] = $key; - $svalue['grid_master'] = $value['grid_master']; - $all_rack_rates['slab_rates'][] = $svalue; - } - // dd($value['slab_rates']); - } - - // dd($all_rack_rates); - $policy_details = ['base_policy' => null,"policy_start_date" => "2023-02-02","policy_end_date" => "2024-02-02","policy_terms" => json_encode($policy_terms),'gst' => 5]; - $file = ['id' => null,'client_id' => 10,'policy_id' => 10,'action' => 'inception','client_branch_id' => 1,'created_by' => 1]; - $existing_units = ['unit1']; - $data = calculate_premium_new(family_data:$family_details,policy_terms: $policy_details,slab_details : $all_rack_rates,fileArr: $file, existing_units:$existing_units); - - //****************************onboard process******************* - // $empServiceController = new EmployeeServiceController(); - // $empServiceController->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); - - // dd(); - //******************************** onboard process**************** - $policy_created_count = 0; - echo "\n"; - $result_to_display = []; - foreach ($data as $key => $value) - { - if(is_array($value)) - { - $result_to_display[$key]['emp_code'] = $value['emp_code']; - $result_to_display[$key]['name'] = $value['name'].'('.calculate_days_bw_dates($value['dob'])->y.')'; - $result_to_display[$key]['relation'] = $value['relationship']; - $temp_grid = ($value['temp']['grid_name']); - $temp_grid_type = ($value['temp']['premium_type']); - $temp_grid_type = ($temp_grid_type == 1 ? 'S' : 'I'); - $result_to_display[$key]['premium_type'] = $temp_grid.'#'.$value['temp']['grid_id'].'#'. - ($value['temp']['acting_self'] == true ? 'Self' : 'No' ) .'#'. ($temp_grid_type) ; - $result_to_display[$key]['si'] = $value['policy_details']['basic_cover_si']; - $result_to_display[$key]['premium'] = $value['policy_details']['premium']; - $result_to_display[$key]['policy days'] = (calculate_days_bw_dates($policy_details['policy_start_date'],$policy_details['policy_end_date'])->days + 1); - $result_to_display[$key]['no of days'] = $value['policy_details']['days']; - $result_to_display[$key]['rata_premimum'] = $value['policy_details']['rata_premimum']; - $result_to_display[$key]['gst'] = $value['policy_details']['gst']; - - if(!empty($value['policy_details']['premium'])){ $policy_created_count = $policy_created_count + 1; } - } - } - - TableDisplay::displayTable($result_to_display); - $this->assertTrue(($policy_created_count >= 1 || $policy_created_count = 0)); - } - -} - - -class TableDisplay -{ - public static function displayTable(array $data) - { - if (empty($data)) { - echo "No data to display.\n"; - return; - } - - // Calculate column widths - $columns = array_keys($data[0]); - $widths = array_map(function ($col) use ($data) { - $maxWidth = strlen($col); - foreach ($data as $row) { - $maxWidth = max($maxWidth, strlen($row[$col])); - } - return $maxWidth; - }, $columns); - - // Print header - echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL; - foreach ($columns as $i => $col) { - echo str_pad($col, $widths[$i]) . " | "; - } - echo PHP_EOL; - echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL; - - // Print rows - foreach ($data as $row) { - foreach ($columns as $i => $col) { - echo str_pad($row[$col], $widths[$i]) . " | "; - } - - echo PHP_EOL; - } - echo str_repeat('-', array_sum($widths) + count($columns) * 3) . PHP_EOL; - } -} From 6a159ac276f929e29d933b0ea24a1f7010d65070 Mon Sep 17 00:00:00 2001 From: velz Date: Wed, 31 Jul 2024 14:33:01 +0530 Subject: [PATCH 2/7] FIX_TESTRACKRATE_PAGE --- app/Controllers/EmployeeController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 82328ba1..d0791f8c 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -1563,7 +1563,10 @@ class EmployeeController extends AdminController foreach($data as $key => $member ) { // ~dd($member); - $data[$key]['policy_details']['no_of_days'] = $member['policy_details']['date_coverage'] ? (calculate_days_bw_dates($member['policy_details']['date_coverage'],$member['policy_details']['policy_end_date'])->days + 1) : ''; + if(is_array($member)) + { + $data[$key]['policy_details']['no_of_days'] = $member['policy_details']['date_coverage'] ? (calculate_days_bw_dates($member['policy_details']['date_coverage'],$member['policy_details']['policy_end_date'])->days + 1) : ''; + } } return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $data], 200); From d26e4fd952b452207962b98d85377c5ae15845a2 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 31 Jul 2024 14:51:36 +0530 Subject: [PATCH 3/7] FEAT_SEND_MANUAL_REMAINDER_AND_UPLOAD_ENROLL_FILE : RV --- app/Config/Routes.php | 4 +- app/Controllers/DashboardController.php | 258 ++++++++++++++------ app/Controllers/EmployeeController.php | 19 +- app/Models/ClientPolicyModel.php | 21 ++ app/Views/DashBoard.php | 2 +- app/Views/client_list.php | 2 +- app/Views/client_policy.php | 6 +- app/Views/employee_data_list.php | 2 +- app/Views/enrollment_dash.php | 10 +- app/Views/enrollment_list.php | 307 ++++++++++++++++++++++-- app/Views/layout/header.php | 2 +- app/Views/policy_grid.php | 24 +- 12 files changed, 528 insertions(+), 129 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3e79d7a7..440895a8 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -273,11 +273,13 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get("get_client_details/(:any)", "ClientController::getClientDetails/$1"); $routes->get("featch_dashboard_data/(:any)", "DashboardController::featch_dashboard_data/$1"); $routes->get("remove_rack_rate/(:any)", "ClientController::removeRackRate/$1"); + $routes->get("get_client_policy_list_for_remainder/(:any)", "EmployeeController::get_client_policy_list_for_remainder/$1"); + $routes->get("send_manual_remainder/(:any)", "DashboardController::sendManualRemainder/$1"); }); $routes->cli('cli/processjob', 'JobWorker::processJob'); $routes->cli('cli/processjobs', 'JobWorker::processJobs'); -$routes->cli('cli/enrollment_status', 'DashboardController::enrollment_status'); +$routes->cli('cli/updatePolicyEnrollmentStatus', 'DashboardController::updatePolicyEnrollmentStatus'); $routes->get("processjob", "JobWorker::processJob"); diff --git a/app/Controllers/DashboardController.php b/app/Controllers/DashboardController.php index 79a90517..fe61b51f 100644 --- a/app/Controllers/DashboardController.php +++ b/app/Controllers/DashboardController.php @@ -27,6 +27,10 @@ class DashboardController extends AdminController protected $messageModel; protected $clientModel; protected $userMessageModel; + protected $clientPolicyModel; + protected $notificationModel; + protected $employeePolicyModel; + protected $myLogger; public function __construct() @@ -34,32 +38,37 @@ class DashboardController extends AdminController set_session_context('Dashboard'); $this->messageModel = new MessageModel(); $this->userMessageModel = new UserMessageModel(); + $this->clientPolicyModel = new ClientPolicyModel(); + $this->notificationModel = new NotificationModel(); + $this->employeePolicyModel = new EmployeePolicyModel(); + $this->clientModel = new ClientModel(); + $this->myLogger = \Config\Services::mylogger(); - $this->clientModel = new ClientModel(); + } public function dashboard() { $data = []; - + $results = $this->clientModel->select('clients.id as client_id, clients.client_name, clients.short_name, client_branch.id as client_branch_id, client_branch.branch_name, client_branch.branch_code, employees.id as employee_id, employees.name as employee_name, employees.relationship, employees.emp_code, employees.emp_status, auth_history.user_type, client_policy.policy_type_id, client_policy.id as client_policy_id') - ->join('client_branch', 'clients.id = client_branch.client_id', 'left') - ->join('client_policy', 'client_branch.id = client_policy.client_branch_id', 'left') - ->join('employees', 'client_branch.id = employees.client_branch_id', 'left') - ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') - ->findAll(); - + ->join('client_branch', 'clients.id = client_branch.client_id', 'left') + ->join('client_policy', 'client_branch.id = client_policy.client_branch_id', 'left') + ->join('employees', 'client_branch.id = employees.client_branch_id', 'left') + ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') + ->findAll(); + $pendingActionsController = new PendingActionsController; $pendingActionsData = $pendingActionsController->getPendingActionsForDashBoard(); $groupedData = []; - + foreach ($results as $row) { $clientId = $row['client_id']; $clientName = $row['client_name']; @@ -70,7 +79,7 @@ class DashboardController extends AdminController $clientPolicyId = $row['client_policy_id']; $policyTypeId = $row['policy_type_id']; - $employeeId =''; + $employeeId = ''; if ($employeeId != $row['employee_id']) { $employeeId = $row['employee_id']; } else { @@ -104,7 +113,7 @@ class DashboardController extends AdminController 'employees' => [] ]; } - + // Add the client policy to the branch's policies list if it exists, not already added, and policyTypeId is not equal to 1 if ($clientPolicyId !== null && $policyTypeId != 1 && !in_array(['client_policy_id' => $clientPolicyId, 'policy_type_id' => $policyTypeId], $groupedData[$clientId]['branches'][$branchId]['client_policies'])) { $groupedData[$clientId]['branches'][$branchId]['client_policies'][] = [ @@ -112,8 +121,8 @@ class DashboardController extends AdminController 'policy_type_id' => $policyTypeId ]; } - - // Append employee info to the branch's employees list if relationship is 'Self' and not already added + + // Append employee error to the branch's employees list if relationship is 'Self' and not already added $employeeKey = $employeeId . '-' . $employeeName; // unique key to identify an employee if ($employeeId !== null && $employeeRelationship == 'Self' && !isset($groupedData[$clientId]['branches'][$branchId]['employees'][$employeeKey])) { $groupedData[$clientId]['branches'][$branchId]['employees'][$employeeKey] = [ @@ -142,7 +151,7 @@ class DashboardController extends AdminController } $client['branches'] = array_values($client['branches']); } - + $data['client_branch_emp_list'] = $groupedData; $session = \Config\Services::session(); $session->set('enrollment_data', json_encode($data)); @@ -150,15 +159,12 @@ class DashboardController extends AdminController $data['pendingActionsData'] = $pendingActionsData; // print_r($data);die; - + echo view('layout/header'); echo view('DashBoard', $data); echo view('layout/footer'); } - - - public function getDashboardNotifications() { @@ -187,89 +193,61 @@ class DashboardController extends AdminController } - public static function enrollment_status() { + public function updatePolicyEnrollmentStatus() + { $clientModel = new ClientModel(); $clientPolicyModel = new ClientPolicyModel(); $notificationModel = new NotificationModel(); $employeePolicyModel = new EmployeePolicyModel(); $myLogger = \Config\Services::mylogger(); - $client_policy_data = $clientPolicyModel->findAll(); + // $myLogger->logme('error', 'enrollment_status function called'); + + $client_policy_data = $clientPolicyModel->getPolicyDetailsForRemainder(); + $myLogger->logme('error', 'Fetched client policy data'); + + // dd($client_policy_data); + $currentDate = date('d'); + // $myLogger->logme('error', 'Current date: ' . $currentDate); // Update policy status based on start and end dates foreach ($client_policy_data as $client_policy) { + $id = $client_policy['id']; $openDate = date('d', strtotime($client_policy['open_date'])); $closeDate = date('d', strtotime($client_policy['close_date'])); + + // $myLogger->logme('error', 'Processing client policy ID: ' . $id); + // $myLogger->logme('error', 'Open date: ' . $openDate . ', Close date: ' . $closeDate); + if ($currentDate == $openDate) { $clientPolicyModel->update($id, ['open_for_enrollment' => 1]); - } - + $myLogger->logme('error', 'Updated policy ID ' . $id . ' to open for enrollment.'); + } + if ($closeDate < $currentDate) { $clientPolicyModel->update($id, ['open_for_enrollment' => 0]); + $myLogger->logme('error', 'Updated policy ID ' . $id . ' to close for enrollment.'); } } - $reminder_whole_mail = []; - - foreach ($client_policy_data as $client_policy) { - // Fetch client data - $client_data = $clientModel->find($client_policy['client_id']); - - // Fetch notification settings - $notification_data = $notificationModel->where('client_id', $client_policy['client_id']) - ->where('template_name', 'member_reminder_mail') - ->first(); - - // Check if notification should be sent - if ($notification_data && $notification_data['enabled'] == 1 && $currentDate == date('d', strtotime($client_policy['reminder_date'])) ) { - // Fetch all employees related to the client policy - $employees = $employeePolicyModel->select('employees.*') - ->join('employees', 'employee_polices.employee_id = employees.id', 'left') - ->where('employee_polices.client_policy_id', $client_policy['id']) - ->where('employees.emp_status', 'draft') - ->where('employee_polices.status', 'draft') - ->where('employees.relationship', 'Self') - ->findAll(); - // Process each employee - foreach ($employees as $employee) { - if($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self'){ - $params['emp_data'] = $employee; - $params['client_data'] = $client_data; - $params['notification_data'] = $notification_data; - - // Send the mail notification - $reminder_whole_mail[] = sendMailNotification::sendMailNotification('member_reminder_mail', $params); - } - } - } - } - - // Process and queue bulk emails - $temp_whole_data = []; - $count = 0; - - foreach ($reminder_whole_mail as $whole_index => $values) { - foreach ($values as $index => $value) { - $temp_whole_data[] = $value; - $count++; - - if ($count == 20 || ($whole_index == count($reminder_whole_mail) - 1 && $index == count($values) - 1)) { - if (!empty($temp_whole_data)) { - Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $temp_whole_data]); - $temp_whole_data = []; - $count = 0; - } - } - } - } - if(count($temp_whole_data) > 0){ - Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $temp_whole_data]); + // Mail send function + // $myLogger->logme('error', 'Calling sendRemainderMail function'); + if( $currentDate == date('d', strtotime($client_policy['reminder_date']))){ + $result = $this->sendRemainderMail($client_policy_data); + }else{ + $result = false; } - return json_encode(true); + // $myLogger->logme('error', 'enrollment_status function completed'); + if($result){ + return json_encode(['status' => true, 'message' => 'Mail send successfully']); + }else{ + return json_encode(['status' => false, 'message' => 'There is no data to send']); + } } + public function featch_dashboard_data($type) { @@ -308,4 +286,128 @@ class DashboardController extends AdminController } + public function sendRemainderMail($client_policy_data) + { + // $this->myLogger->logme('error', 'sendRemainderMail function called'); + + $reminder_whole_mail = []; + + foreach ($client_policy_data as $client_policy) { + + // Fetch client data + $client_data = $this->clientModel->find($client_policy['client_id']); + + // Fetch notification settings + $notification_data = $this->notificationModel + ->where('client_id', $client_policy['client_id']) + ->where('template_name', 'member_reminder_mail') + ->first(); + + // $this->myLogger->logme('error', 'Notification data fetched: ' . json_encode($notification_data)); + + // Check if notification should be sent + if ($notification_data && $notification_data['enabled'] == 1 && !empty($notification_data['mail_content'])) { + $this->myLogger->logme('error', 'Notification should be sent for client policy ID: ' . $client_policy['id']); + + // Fetch all employees related to the client policy + $employees = $this->employeePolicyModel + ->select('employees.*') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('employee_polices.client_policy_id', $client_policy['id']) + ->where('employees.emp_status', 'draft') + ->where('employees.is_active', 1) + ->where('employee_polices.status', 'draft') + ->where('employee_polices.is_active', 1) + ->where('employees.relationship', 'Self') + ->findAll(); + + // Process each employee + foreach ($employees as $employee) { + + if ($employee['emp_status'] == 'draft' && $employee['relationship'] == 'Self') { + $this->myLogger->logme('error', 'Employee status and relationship check passed for employee ID: ' . $employee['id']); + + // Mail params + $params['emp_data'] = $employee; + $params['client_data'] = $client_data; + $params['notification_data'] = $notification_data; + + // Send the mail notification + $mail_result = sendMailNotification::sendMailNotification('member_reminder_mail', $params); + // $this->myLogger->logme('error', 'Mail sent result: ' . json_encode($mail_result)); + $reminder_whole_mail[] = $mail_result; + } + } + } else { + $this->myLogger->logme('error', 'Notification not sent for client policy ID: ' . $client_policy['id']); + } + } + + $this->myLogger->logme('error', 'Whole email, count: ' . $reminder_whole_mail); + + // Process and queue bulk emails + $temp_whole_data = []; + $count = 0; + + foreach ($reminder_whole_mail as $whole_index => $values) { + foreach ($values as $index => $value) { + $temp_whole_data[] = $value; + $count++; + $this->myLogger->logme('error', 'Queueing email, count: ' . $count); + + if ($count == 20 || ($whole_index == count($reminder_whole_mail) - 1 && $index == count($values) - 1)) { + if (!empty($temp_whole_data)) { + Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $temp_whole_data]); + $this->myLogger->logme('error', 'Added bulk mail job: ' . json_encode($temp_whole_data)); + $temp_whole_data = []; + $count = 0; + } + } + } + } + + if (count($temp_whole_data) > 0) { + Jobs::addJob(['job_name' => 'bulk_mail', 'payload' => $temp_whole_data]); + $this->myLogger->logme('error', 'Added final bulk mail job: ' . json_encode($temp_whole_data)); + return true; + } + + if(count($reminder_whole_mail) > 0){ + return true; + }else{ + return false; + } + + } + + + public function sendManualRemainder($client_id, $client_branch_id) + { + $this->myLogger->logme('error', "sendManualRemainder called with client_id: {$client_id}, client_branch_id: {$client_branch_id}"); + + $client_policy_data = $this->clientPolicyModel->getPolicyDetailsForRemainder($client_id, $client_branch_id); + // print_r($client_policy_data); die; + // print_r($this->clientPolicyModel->getLastQuery()); die; + // $this->myLogger->logme('error', "Policy details fetched: " . json_encode($client_policy_data)); + + if ($client_policy_data) { + $result = $this->sendRemainderMail($client_policy_data); + $this->myLogger->logme('error', "Manual Remainder Mail sending result: " . ($result ? 'success' : 'failure')); + + if ($result) { + $this->myLogger->logme('error', 'Manual Remainder Mail sent successfully'); + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Mail sent successfully'], 200); + } else { + $this->myLogger->logme('error', 'Failed to send manual remainder mail, no data to send'); + return $this->respond(['status' => false, 'code' => 200, 'message' => 'There is no data to send','message2' => 'Failed' ], 200); + } + + } else { + $this->myLogger->logme('error', 'No policy data found to send'); + return $this->respond(['status' => false, 'code' => 200, 'message' => 'There is no data to send', 'message2' => 'No policy data found to send'], 200); + } + } + + + } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 82328ba1..4f70758b 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -192,6 +192,7 @@ class EmployeeController extends AdminController // } if ($this->request->getMethod() == 'post') { + //validate uploaded file $filename = ''; $validated = $this->validate([ @@ -255,7 +256,7 @@ class EmployeeController extends AdminController //for TPA/insurer upload $data['events'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; //for inception upload - $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addtion' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrollment']; + $data['actions'] = ['inception' => 'Inception (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'addition' => 'Addition (Employee + Dependents)', 'dependent_addtion' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement','enrollment' => 'Enrolment']; $data['import_or_export'] = ['import' => 'Import', 'export' => 'Export']; $data['insurer_or_tpa'] = ['insurer' => 'Insurer', 'tpa' => 'TPA']; @@ -1642,4 +1643,20 @@ class EmployeeController extends AdminController } } + + public function get_client_policy_list_for_remainder($client_id, $client_branch_id) + { + $policies = $this->clientPolicyModel + ->select('client_policy.*, policy_type.policy_type as policy_name') + ->join('policy_type', 'policy_type.id = client_policy.policy_type_id') + ->where('client_policy.client_id', $client_id) + ->where('client_policy.client_branch_id', $client_branch_id) + ->where('client_policy.is_active', 1) + ->where('client_policy.policy_status', 1) + ->whereIn('client_policy.policy_type_id', [2, 3]) + ->findAll(); + + return $this->respond(['status' => true, 'code' => 200, 'data' => $policies], 200); + + } } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 29027630..506b6605 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -388,5 +388,26 @@ public function getCliendDataForExcelFileName($client_policy_id){ } +//for this using in CRONE JOB +public function getPolicyDetailsForRemainder($client_id = null, $branch_id = null) +{ + $builder = $this->table('client_policy') + ->where('client_policy.is_addon', 1) + ->where('client_policy.open_for_enrollment', 1) + ->where('client_policy.inception_type', 2) + ->where('client_policy.is_active', 1) + ->where('client_policy.policy_status', 1) + ->whereIn('client_policy.policy_type_id', [2, 3]); + + if ($client_id && $branch_id) { + $builder->where('client_policy.client_id', $client_id) + ->where('client_policy.client_branch_id', $branch_id); + } + + return $builder->get()->getResultArray(); + + + } + } diff --git a/app/Views/DashBoard.php b/app/Views/DashBoard.php index c174e936..8f2a5aff 100644 --- a/app/Views/DashBoard.php +++ b/app/Views/DashBoard.php @@ -59,7 +59,7 @@ body { diff --git a/app/Views/client_list.php b/app/Views/client_list.php index f0609f71..8d015165 100644 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -58,7 +58,7 @@ table.dataTable thead th {