diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index b765eb52..28721878 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -1394,9 +1394,9 @@ class EmployeeServiceController extends AdminController // Kint::dump($family); $data = calculate_premium_new(family_data:$family,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units); - if($file['action'] == 'dependent_addition') { - $data = validatet_family_floter_rata_premium($data); - } + // if($file['action'] == 'dependent_addition') { + // $data = validatet_family_floter_rata_premium($data); + // } // dd($data); $employee_data_group_by_family[$emp_id] = $data; $this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 1547e007..e970d9b5 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -3208,116 +3208,116 @@ } - public function reportBDSNew() - { - // ๐งญ Basic Page Info - $data['tab_name'] = 'BDS Report'; - $data['page_name'] = 'BDS Report'; + public function reportBDSNew() + { + // ๐งญ Basic Page Info + $data['tab_name'] = 'BDS Report'; + $data['page_name'] = 'BDS Report'; - // ๐ Dropdown Data - $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance']; - $data['client_type'] = [1 => 'Group', 2 => 'Individual']; - $data['issuing_type'] = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over']; - $data['policy_status'] = [ - 'pending' => 'Pending', - 'exported_to_insurer' => 'Exported to Insurer', - 'imported_from_insurer'=> 'Imported from Insurer', - 'exported_to_tpa' => 'Exported to TPA', - 'imported_from_tpa' => 'Imported from TPA', - 'completed' => 'Completed' - ]; - $data['invoice_status_array'] = [ - 'yet_to_generate' => 'Yet to Generate', - 'generated' => 'Generated', - 'send' => 'Send', - 'recived' => 'Recived', - ]; - $data['date_type'] = [ - 'policy_issue_date' => 'Policy Issue Date', - 'policy_start_date' => 'Policy Start Date', - 'policy_end_date' => 'Policy End Date', - 'data_received_date' => 'Data Received Date', - 'closure_date' => 'Closure Date', - 'statement_month' => 'Statement Month', - ]; + // ๐ Dropdown Data + $data['issuer'] = [1 => 'JIBS', 2 => 'Nhance']; + $data['client_type'] = [1 => 'Group', 2 => 'Individual']; + $data['issuing_type'] = [1 => 'Fresh', 2 => 'Renewal', 3 => 'Roll Over']; + $data['policy_status'] = [ + 'pending' => 'Pending', + 'exported_to_insurer' => 'Exported to Insurer', + 'imported_from_insurer'=> 'Imported from Insurer', + 'exported_to_tpa' => 'Exported to TPA', + 'imported_from_tpa' => 'Imported from TPA', + 'completed' => 'Completed' + ]; + $data['invoice_status_array'] = [ + 'yet_to_generate' => 'Yet to Generate', + 'generated' => 'Generated', + 'send' => 'Send', + 'recived' => 'Recived', + ]; + $data['date_type'] = [ + 'policy_issue_date' => 'Policy Issue Date', + 'policy_start_date' => 'Policy Start Date', + 'policy_end_date' => 'Policy End Date', + 'data_received_date' => 'Data Received Date', + 'closure_date' => 'Closure Date', + 'statement_month' => 'Statement Month', + ]; - // ๐ข Fetch Active Data - $data['insurer'] = $this->insurerModel->where('is_active', 1)->findAll(); - $data['policy_types'] = $this->policyTypeModel->where('is_active', 1)->findAll(); - $data['clients'] = $this->clientModel->where('is_active', 1)->findAll(); - $data['users'] = $this->userModel->where('is_active', 1)->findAll(); - $data['policy_count'] = $this->policyTransactionModel->where('is_active', 1)->countAllResults(); + // ๐ข Fetch Active Data + $data['insurer'] = $this->insurerModel->where('is_active', 1)->findAll(); + $data['policy_types'] = $this->policyTypeModel->where('is_active', 1)->findAll(); + $data['clients'] = $this->clientModel->where('is_active', 1)->findAll(); + $data['users'] = $this->userModel->where('is_active', 1)->findAll(); + $data['policy_count'] = $this->policyTransactionModel->where('is_active', 1)->countAllResults(); - // ๐ Filters - $start_date = $this->request->getGet('start_date'); - $end_date = $this->request->getGet('end_date'); - $client_id = $this->request->getGet('client_id'); - $insurer_id = $this->request->getGet('insurer_id'); - $policy_type_id = $this->request->getGet('policy_type_id'); - $date_type = $this->request->getGet('date_type'); - $issuer = $this->request->getGet('issuer'); - $client_branch_id = $this->request->getGet('client_branch_id'); - $insurer_branch_id = $this->request->getGet('insurer_branch_id'); - $client_policy_id = $this->request->getGet('client_policy_id'); - $user_id = $this->request->getGet('user_id'); + // ๐ Filters + $start_date = $this->request->getGet('start_date'); + $end_date = $this->request->getGet('end_date'); + $client_id = $this->request->getGet('client_id'); + $insurer_id = $this->request->getGet('insurer_id'); + $policy_type_id = $this->request->getGet('policy_type_id'); + $date_type = $this->request->getGet('date_type'); + $issuer = $this->request->getGet('issuer'); + $client_branch_id = $this->request->getGet('client_branch_id'); + $insurer_branch_id = $this->request->getGet('insurer_branch_id'); + $client_policy_id = $this->request->getGet('client_policy_id'); + $user_id = $this->request->getGet('user_id'); - // Handle statement month range - if ($date_type == 'statement_month') { - $start_date = (string) date('Y-m-01', strtotime($start_date)); - $end_date = (string) date('Y-m-31', strtotime($end_date)); - } + // Handle statement month range + if ($date_type == 'statement_month') { + $start_date = (string) date('Y-m-01', strtotime($start_date)); + $end_date = (string) date('Y-m-31', strtotime($end_date)); + } - // Ensure default values - $start_date = $start_date ?: 0; - $end_date = $end_date ?: 0; - $client_id = $client_id ?: 0; - $insurer_id = $insurer_id ?: 0; - $policy_type_id = $policy_type_id ?: 0; - $date_type = $date_type ?: 0; - $issuer = $issuer ?: 0; - $client_branch_id = $client_branch_id ?: 0; - $insurer_branch_id = $insurer_branch_id ?: 0; - $client_policy_id = $client_policy_id ?: 0; - $user_id = $user_id ?: 0; + // Ensure default values + $start_date = $start_date ?: 0; + $end_date = $end_date ?: 0; + $client_id = $client_id ?: 0; + $insurer_id = $insurer_id ?: 0; + $policy_type_id = $policy_type_id ?: 0; + $date_type = $date_type ?: 0; + $issuer = $issuer ?: 0; + $client_branch_id = $client_branch_id ?: 0; + $insurer_branch_id = $insurer_branch_id ?: 0; + $client_policy_id = $client_policy_id ?: 0; + $user_id = $user_id ?: 0; - // ๐งพ Handle POST requests (Dashboard filters) - if ($this->request->is('post')) { - $isFromDashboard = $this->request->getPost('is_dashboard'); + // ๐งพ Handle POST requests (Dashboard filters) + if ($this->request->is('post')) { + $isFromDashboard = $this->request->getPost('is_dashboard'); - if (!empty($isFromDashboard) && $isFromDashboard == 1) { - $ids = array_filter(explode(',', $this->request->getPost('ids'))); + if (!empty($isFromDashboard) && $isFromDashboard == 1) { + $ids = array_filter(explode(',', $this->request->getPost('ids'))); - if (!empty($ids)) { - $idsStr = implode(',', array_map('intval', $ids)); // sanitize IDs - $where = "policy_transaction.id IN ($idsStr)"; - } else { - $where = []; // No valid IDs + if (!empty($ids)) { + $idsStr = implode(',', array_map('intval', $ids)); // sanitize IDs + $where = "policy_transaction.id IN ($idsStr)"; + } else { + $where = []; // No valid IDs + } } } + + // ๐ Fetch report data + $data['report_list'] = $this->policyTransactionModel->reportBDSNew( + $start_date, + $end_date, + $client_id, + $insurer_id, + $policy_type_id, + $date_type, + $issuer, + $client_branch_id, + $insurer_branch_id, + $client_policy_id, + $user_id, + $where ?? '' + ); + + $data['list_new'] = true; + + // ๐งฉ Load View + $this->loadLayout('report_bds_filter', $data); } - // ๐ Fetch report data - $data['report_list'] = $this->policyTransactionModel->reportBDSNew( - $start_date, - $end_date, - $client_id, - $insurer_id, - $policy_type_id, - $date_type, - $issuer, - $client_branch_id, - $insurer_branch_id, - $client_policy_id, - $user_id, - $where ?? '' - ); - - $data['list_new'] = true; - - // ๐งฉ Load View - $this->loadLayout('report_bds_filter', $data); - } - } diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index f48f7ce0..f3e97d0c 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -1022,8 +1022,8 @@ if (!function_exists('transform_excel_data_to_db')) { } } -if (!function_exists('premium_calculation_manager_old')) { - function premium_calculation_manager_old($emp_data, $policy_terms, $slab_details, $default_si = null) +if (!function_exists('premium_calculation_manager')) { + function premium_calculation_manager($emp_data, $policy_terms, $slab_details, $default_si = null) { // dd($emp_data,$policy_terms,$slab_details,$default_si); @@ -1429,8 +1429,8 @@ if (!function_exists('premium_calculation_manager_old')) { } } -if (!function_exists('premium_calculation_manager')) { - function premium_calculation_manager($emp_data, $policy_terms, $slab_details, $default_si = null) +if (!function_exists('premium_calculation_manager_new')) { + function premium_calculation_manager_new($emp_data, $policy_terms, $slab_details, $default_si = null) { // dd($emp_data,$policy_terms,$slab_details,$default_si); diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index 7f3ca607..b5015dbd 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -826,8 +826,16 @@ $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); - $builder->where('policy_transaction.' . $date_type . '>=', $startDate) - ->where('policy_transaction.' . $date_type . '<=', $endDate); + // $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + // ->where('policy_transaction.' . $date_type . '<=', $endDate); + + if($date_type == "policy_issue_date"){ + $builder->where("pt_co_share_details.pt_policy_issue_date >=", $startDate) + ->where("pt_co_share_details.pt_policy_issue_date <=", $endDate); + }else{ + $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + ->where('policy_transaction.' . $date_type . '<=', $endDate); + } } // if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0){ @@ -1043,8 +1051,18 @@ // Optimize Date Filtering if (!empty($start_date) && !empty($end_date) && !empty($date_type)) { - $builder->where("policy_transaction.$date_type >=", date('Y-m-d 00:00:00', strtotime($start_date))) - ->where("policy_transaction.$date_type <=", date('Y-m-d 23:59:59', strtotime($end_date))); + + $startDate = change_date_format($start_date, 'd/m/Y', 'Y-m-d 00:00:00'); + $endDate = change_date_format($end_date, 'd/m/Y', 'Y-m-d 23:59:59'); + + if($date_type == "policy_issue_date"){ + $builder->where("pt_co_share_details.pt_policy_issue_date >=", $startDate) + ->where("pt_co_share_details.pt_policy_issue_date <=", $endDate); + + }else{ + $builder->where("policy_transaction.$date_type >=", $startDate) + ->where("policy_transaction.$date_type <=", $startDate); + } } // Apply Filters Only When Necessary @@ -1080,6 +1098,7 @@ // Optimize Query Execution $builder->orderBy('policy_transaction.id', 'desc'); $data = $builder->get()->getResultArray(); + // dd($this->db->getLastQuery()); return $data; } @@ -1134,11 +1153,17 @@ if ($start_date != 0 && $end_date != 0 && $date_type != 0) { - $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); - $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); + $startDate = change_date_format($start_date, 'd/m/Y', 'Y-m-d 00:00:00'); + $endDate = change_date_format($end_date, 'd/m/Y', 'Y-m-d 23:59:59'); + + if($date_type == "policy_issue_date"){ + $builder->where("pt_co_share_details.pt_policy_issue_date >=", $startDate) + ->where("pt_co_share_details.pt_policy_issue_date <=", $endDate); + }else{ + $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + ->where('policy_transaction.' . $date_type . '<=', $endDate); + } - $builder->where('policy_transaction.' . $date_type . '>=', $startDate) - ->where('policy_transaction.' . $date_type . '<=', $endDate); } else { // $fromDate = date('Y-m-d', strtotime('-30 days')); @@ -1177,7 +1202,7 @@ } $builder->orderBy('policy_transaction.id', 'desc'); - + // dd($this->db->getLastQuery()); return $builder->get()->getResultArray(); } @@ -1315,8 +1340,17 @@ $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); - $builder->where('policy_transaction.' . $date_type . '>=', $startDate) - ->where('policy_transaction.' . $date_type . '<=', $endDate); + // $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + // ->where('policy_transaction.' . $date_type . '<=', $endDate); + + if($date_type == "policy_issue_date"){ + $builder->where("pt_co_share_details.pt_policy_issue_date >=", $startDate) + ->where("pt_co_share_details.pt_policy_issue_date <=", $endDate); + }else{ + $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + ->where('policy_transaction.' . $date_type . '<=', $endDate); + } + } else { $fromDate = date('Y-m-d', strtotime('-90 days')); @@ -1356,8 +1390,10 @@ $builder->orderBy('policy_transaction.id', 'desc'); + $return_data = $builder->get()->getResultArray(); + // dd(db_connect()->getLastQuery()); - return $builder->get()->getResultArray(); + return $return_data; } public function getBusinessReportList($start_date = 0, $end_date = 0, $client_id = 0, $insurer_id = 0, $policy_type_id = 0, $date_type = 0, $issuer = 0, $status = 0) @@ -1418,8 +1454,16 @@ $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); - $builder->where('policy_transaction.' . $date_type . '>=', $startDate) - ->where('policy_transaction.' . $date_type . '<=', $endDate); + // $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + // ->where('policy_transaction.' . $date_type . '<=', $endDate); + + if($date_type == "policy_issue_date"){ + $builder->where("pt_co_share_details.pt_policy_issue_date >=", $startDate) + ->where("pt_co_share_details.pt_policy_issue_date <=", $endDate); + }else{ + $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + ->where('policy_transaction.' . $date_type . '<=', $endDate); + } } else { $fromDate = date('Y-m-d', strtotime('-90 days')); @@ -1521,8 +1565,17 @@ $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); - $builder->where('policy_transaction.' . $date_type . '>=', $startDate) - ->where('policy_transaction.' . $date_type . '<=', $endDate); + // $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + // ->where('policy_transaction.' . $date_type . '<=', $endDate); + + if($date_type == "policy_issue_date"){ + $builder->where("pt_co_share_details.pt_policy_issue_date >=", $startDate) + ->where("pt_co_share_details.pt_policy_issue_date <=", $endDate); + }else{ + $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + ->where('policy_transaction.' . $date_type . '<=', $endDate); + } + } else { $fromDate = date('Y-m-d', strtotime('-90 days')); @@ -1627,8 +1680,16 @@ $startDate = date('Y-m-d 00:00:00', strtotime($start_date)); $endDate = date('Y-m-d 23:59:59', strtotime($end_date)); - $builder->where('policy_transaction.' . $date_type . '>=', $startDate) - ->where('policy_transaction.' . $date_type . '<=', $endDate); + // $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + // ->where('policy_transaction.' . $date_type . '<=', $endDate); + + if($date_type == "policy_issue_date"){ + $builder->where("pt_co_share_details.pt_policy_issue_date >=", $startDate) + ->where("pt_co_share_details.pt_policy_issue_date <=", $endDate); + }else{ + $builder->where('policy_transaction.' . $date_type . '>=', $startDate) + ->where('policy_transaction.' . $date_type . '<=', $endDate); + } } else { $fromDate = date('Y-m-d', strtotime('-90 days')); $toDate = date('Y-m-d 23:59:59'); diff --git a/app/Views/policy_transaction_endorsement_form.php b/app/Views/policy_transaction_endorsement_form.php index e135fec3..b427f55c 100644 --- a/app/Views/policy_transaction_endorsement_form.php +++ b/app/Views/policy_transaction_endorsement_form.php @@ -440,7 +440,7 @@