diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 73d1cc0b..5449dedb 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -609,7 +609,7 @@ class ClientController extends AdminController $data['is_addon'] = $this->request->getPost('is_addon'); $data['base_policy'] = $this->request->getPost('base_policy'); $data['policy_status'] = 1; - $data['inception_type'] = $this->request->getPost('inception_type') ? 1 : 2; + $data['inception_type'] = $this->request->getPost('inception_type') ? 2 : 1; @@ -701,7 +701,7 @@ class ClientController extends AdminController $data['is_addon'] = $this->request->getPost('is_addon'); $data['base_policy'] = $this->request->getPost('base_policy'); $data['policy_status'] = 1; - $data['inception_type'] = $this->request->getPost('inception_type') ? 1 : 2; + $data['inception_type'] = $this->request->getPost('inception_type') ? 2 : 1; $policy_terms = $this->clientPolicyModel->where('id', $this->request->getPost('base_policy'))->first(); @@ -1531,77 +1531,82 @@ class ClientController extends AdminController public function updateClientPolicyStatus() { - $client_policy_id = $this->request->getGet('client_policy_id'); - $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); - $message = 'Policy updated Successfully' ; - if($record['open_for_enrollment'] == 0){ - $open_for_enrollment_update_value = 1; - $message = 'Update Open Enrollment Successfully'; - }else if($record['open_for_enrollment'] == 1){ - $open_for_enrollment_update_value = 0; - $message = 'Update Open Enrollment Successfully'; - } - - $data = $this->policesModel->getPolicyPremium($record['policy_id']); - $pattern = '/gmc/i'; - $subject = $data[0]->policy_type; - if (preg_match($pattern, $subject)) { - $search_term = 'GMC'; - } else { - $search_term = 'GPA'; - } - - if($search_term === 'GPA'){ - $racRate = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); - }else if($search_term === 'GMC'){ - $racRate = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); - } - - $termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first(); - if(empty($termsData['policy_terms'])){ - return $this->respond(['status' => false,'code' => 200,'message' => 'Please define policy terms '], 200); - } + $client_policy_id = $this->request->getGet('client_policy_id'); + $message = 'Policy updated Successfully'; - $termsData = json_decode($termsData['policy_terms']); + $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); - if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200); - } + if ($record['open_for_enrollment'] == 0) { + $open_for_enrollment_update_value = 1; + $message = 'Enrollment Opened Successfully'; + } else if ($record['open_for_enrollment'] == 1) { + $open_for_enrollment_update_value = 0; + $message = 'Enrollment Closed Successfully'; + } - if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Sum Insured field is empty'], 200); - } - - // Check if 'family_floater' key exists and has a value - if (isset($termsData->family_floater) && $termsData->family_floater == null) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Family Floater field is empty'], 200); - } - - // Check if 'family_floaters' key exists and has a value - if (isset($termsData->family_floaters) && is_array($termsData->family_floaters) && count($termsData->family_floaters) <= 0) { - return $this->respond(['status' => false,'code' => 200,'message' => 'The Policy terms Family Members field is empty'], 200); - $familyFloatersCount = count($termsData->family_floaters); - } + $data = $this->policesModel->getPolicyPremium($record['policy_id']); + $pattern = '/gmc/i'; + $subject = $data[0]->policy_type; + if (preg_match($pattern, $subject)) { + $search_term = 'GMC'; + } else { + $search_term = 'GPA'; + } - if($racRate == 0){ + if ($search_term === 'GPA') { + $racRate = $this->policyPremium1Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); + } else if ($search_term === 'GMC') { + $racRate = $this->policyPremium2Model->where(['client_id' => $record['client_id'], 'client_policy_id' => $client_policy_id, 'is_active' => 1])->countAllResults(); + } - return $this->respond(['status' => false,'code' => 200,'message' => 'Please define policy premium'], 200); - } + $termsData = $this->clientPolicyModel->where(['id' => $client_policy_id, 'is_active' => 1])->first(); + if (empty($termsData['policy_terms'])) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define policy terms '], 200); + } - $policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update(); - $json_data =''; - $open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id )->set('open_for_enrollment', $open_for_enrollment_update_value)->update(); - if ($open_for_enrollment) { - $open_for_enrollment_1 = $this->clientPolicyModel->where('id', $client_policy_id )->find(); - $open_for_enrollment_value = $open_for_enrollment_1[0]['open_for_enrollment']; - $client_policy_id_value = $client_policy_id; - $json_data = json_encode(['open_for_enrollment' => $open_for_enrollment_value, 'client_policy_id' => $client_policy_id_value]); - } + $termsData = json_decode($termsData['policy_terms']); - return $this->respond(['status' => true,'code' => 200, 'message' => $message, 'data' => $termsData, 'racRate' => $racRate, 'open_for_enrollment' => $json_data], 200); + if (isset($termsData->sum_insured) && empty($termsData->sum_insured)) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty', 'data' => $record], 200); + } + if (isset($termsData->SumInsured) && empty($termsData->sum_insured)) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Sum Insured field is empty'], 200); + } + + // Check if 'family_floater' key exists and has a value + if (isset($termsData->family_floater) && $termsData->family_floater == null) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Floater field is empty'], 200); + } + + // Check if 'family_floaters' key exists and has a value + if (isset($termsData->family_floaters) && is_array($termsData->family_floaters) && count($termsData->family_floaters) <= 0) { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'The Policy terms Family Members field is empty'], 200); + $familyFloatersCount = count($termsData->family_floaters); + } + + if ($racRate == 0) { + + return $this->respond(['status' => false, 'code' => 200, 'message' => 'Please define policy premium'], 200); + } + + // $policy_status = $this->clientPolicyModel->where('id', $client_policy_id )->set('policy_status', 1)->update(); + + $json_data = ''; + $open_for_enrollment = $this->clientPolicyModel->where('id', $client_policy_id)->set('open_for_enrollment', $open_for_enrollment_update_value)->update(); + if ($open_for_enrollment) { + $open_for_enrollment_1 = $this->clientPolicyModel->where('id', $client_policy_id)->find(); + $open_for_enrollment_value = $open_for_enrollment_1[0]['open_for_enrollment']; + $client_policy_id_value = $client_policy_id; + + $json_data = json_encode(['open_for_enrollment' => $open_for_enrollment_value, 'client_policy_id' => $client_policy_id_value]); + } + + + + return $this->respond(['status' => true, 'code' => 200, 'message' => $message, 'data' => $termsData, 'racRate' => $racRate, 'open_for_enrollment' => $json_data, 'client_policy_data' => $record], 200); } diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 5e1a1adb..af0710f0 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -27,6 +27,7 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Reader\Xlsx; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Reader\Exception as SpreadsheetReaderException; +use PhpParser\Node\Expr\Cast\Double; use function PHPUnit\Framework\returnSelf; @@ -108,16 +109,24 @@ class EmpDataServiceController extends BaseController { // Fetch employee data for export from the database $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); + + $insurer_id = $this->clientPolicyModel->where('id', $export_data['client_policy_id'])->first(); - // dd($objects); - + $cash_balance = $this->clientDepositModel->where('client_id',$export_data['client_id'] )->where('insurer_id', $insurer_id['insurer_id'])->orderBy('id', 'DESC')->first(); + + $totals = 0; foreach ($objects as $key => $value) { $totals += $value->total; } - + if((int) $cash_balance['balance'] < (int) $totals){ + + return 0; + } + + // Log the count of exported data $count = count($objects); $export_data['count'] = $count; diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index ff465d78..b1b33241 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -345,7 +345,15 @@ class EmployeeController extends AdminController if ($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition') { $return = $empDataServiceController->generateExcelForAdditionandInception($batch_data); + + if($return == 0){ + + session()->setFlashdata('error', "The insurer has an insufficient deposit amount."); + return redirect()->to(base_url('employee/upload')); + } + if (!$return) { + 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')); @@ -353,6 +361,7 @@ class EmployeeController extends AdminController 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]); } diff --git a/app/Views/client_policy.php b/app/Views/client_policy.php index fb5cd99f..782c000d 100644 --- a/app/Views/client_policy.php +++ b/app/Views/client_policy.php @@ -14,6 +14,7 @@