diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 9165cc0f..10a0b636 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3832,15 +3832,17 @@ class EmployeeRestController extends AdminController // 'Under Process' => [5, 6, 7, 10, 19, 23, 45, 50, 29, 33, 51, 39, 43, 56], // ]; - $client_claim_status = [ - 'Claim Received' => [1, 2, 3, 15, 16, 17, 18, 25, 26, 27, 28, 35, 36, 37, 38], - 'Under Process' => [5, 6, 7, 10, 19, 23, 45, 50, 29, 33, 51, 39, 43, 56], - 'Information Required' => [4], - 'Approved' => [9, 20, 30, 40], - 'Settled' => [11, 24, 34], - 'Denial Review Awaited' => [66], - 'Rejected' => [8, 49, 55, 60], - ]; + // $client_claim_status = [ + // 'Claim Received' => [1, 2, 3, 15, 16, 17, 18, 25, 26, 27, 28, 35, 36, 37, 38], + // 'Under Process' => [5, 6, 7, 10, 19, 23, 45, 50, 29, 33, 51, 39, 43, 56], + // 'Information Required' => [4], + // 'Approved' => [9, 20, 30, 40], + // 'Settled' => [11, 24, 34], + // 'Denial Review Awaited' => [66], + // 'Rejected' => [8, 49, 55, 60], + // ]; + + $client_claim_status = $this->getClaimStatusGrouped(); foreach ($ticket_data as $key => $value) { @@ -3888,6 +3890,32 @@ class EmployeeRestController extends AdminController return $this->response->setJSON(['ticket_data' => $ticket_data])->setStatusCode(200); } + public function getClaimStatusGrouped() + { + // Fetch active claim statuses + $ticketClaimStatus = $this->claimStatusModel + ->select('id, display_name') + ->where('display_name IS NOT NULL') + ->where('is_active', 1) + ->findAll(); + + $result = []; + + foreach ($ticketClaimStatus as $row) { + $name = $row['display_name']; + $id = $row['id']; + + if (!isset($result[$name])) { + $result[$name] = []; + } + + $result[$name][] = $id; + } + + return $result; + } + + // not in use did for testing function encrypt_for_sso(): string { diff --git a/app/Controllers/RuleImportController.php b/app/Controllers/RuleImportController.php index 830ad17e..f5579aac 100644 --- a/app/Controllers/RuleImportController.php +++ b/app/Controllers/RuleImportController.php @@ -487,7 +487,8 @@ class RuleImportController extends AdminController public function deleteCommissionData($id) { - $return = $this->updateCommissionRules($id); + $return = $this->removeCommissionRules($id); + // dd($return); if($return['status'] == true){ $this->commissionFilesModel->where('id', $id)->set(['is_active' => 0])->update(); @@ -497,7 +498,69 @@ class RuleImportController extends AdminController } } - public function updateCommissionRules($id) + public function deActiveCommissionRules($id) + { + // 1. Fetch commission record + $commission_data = $this->commissionFilesModel + ->where('is_active', 1) + ->where('id', $id) + ->first(); + + if (!$commission_data) { + $this->myLogger->logme("error", "Commission record not found for ID: $id"); + return ['status' => false, 'message' => 'Commission record not found']; + } + + // 2. Convert commission_month → OCT2025 + $month = date("M", strtotime($commission_data['commission_month'])); + $year = date("Y", strtotime($commission_data['commission_month'])); + $monthFolder = strtoupper($month . $year); + + // 3. Path + $fileName = $commission_data['insurer_id'] . '_' . $commission_data['department'] . '.json'; + $filePath = WRITEPATH . "uploads/commission/rules/" . $monthFolder . "/" . $fileName; + + if (!file_exists($filePath)) { + $this->myLogger->logme("error", "Rule file not found: $filePath"); + return ['status' => false, 'message' => 'Rule file not found']; + } + + // 4. Read JSON + $json = file_get_contents($filePath); + $rules = json_decode($json, true); + // dd($rules); + + if (!is_array($rules)) { + $this->myLogger->logme("error", "Invalid JSON structure in file: $filePath"); + return ['status' => false, 'message' => 'Invalid rule file']; + } + + // 5. Mark matching rule as deleted + $ruleFound = false; + foreach ($rules as &$rule) { + if (!isset($rule['is_deleted']) && isset($rule['file_id']) && $rule['file_id'] == $id) { + $rule['is_deleted'] = true; // <-- NEW FEATURE + $ruleFound = true; + } + } + + if (!$ruleFound) { + $this->myLogger->logme("error", "No rule found with file_id: $id in file: $filePath"); + return ['status' => false, 'message' => 'Rule not found in file']; + } + + // 6. Always save file back (No unlink) + file_put_contents($filePath, json_encode($rules, JSON_PRETTY_PRINT)); + + $this->myLogger->logme("error", "Rule marked deleted and file updated: $filePath"); + + return [ + 'status' => true, + 'message' => 'Rule marked as deleted and file updated successfully' + ]; + } + + public function removeCommissionRules($id) { // 1. Fetch commission record $commission_data = $this->commissionFilesModel