diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 74cfa7ad..85c0936a 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3571,6 +3571,20 @@ class EmployeeRestController extends AdminController $get_docs_name = $this->request->getPost('claim_doc_names') ?? []; $policy_transaction_id = $this->request->getPost('policy_transaction_id') ?? null; + $client_policy_data = $this->clientPolicyModel->where('id', $received_data['client_policy_id'] ?? null)->first(); + + $isduplicate = checkDuplicateClaim([ + 'doa' => change_date_format($received_data['doa'] ?? '') ?? null, + 'emp_code' => $received_data['emp_code'] ?? null, + 'claim_amount' => $received_data['claim_amount'] ?? null, + 'policy_no' => $client_policy_data['policy_no'] ?? null + ]); + + if($isduplicate){ + $response = ['status' => false, 'message' => 'Claim already exist']; + return $this->respond($response, 200); + } + if(!empty($policy_transaction_id)){ $response = $this->retailClaimInitiate($received_data); return $this->respond($response, 200); diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 1585b803..048202c2 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -6,6 +6,7 @@ use App\Models\BatchFileModelFileModel; use App\Controllers\GoogleDriveController; use App\Models\BatchFileModel; use App\Controllers\ApiServiceController; +use App\Models\TicketMasterModel; // File: app/Helpers/Uuid_helper.php @@ -978,3 +979,33 @@ if (!function_exists('generate_ecard_download_link_based_on_tpa')) { } } +if (!function_exists('checkDuplicateClaim')) { + + function checkDuplicateClaim(array $params): bool + { + $ticketMaster = new TicketMasterModel(); + $query = $ticketMaster->where('is_active', 1); + + if(!empty($params['doa']) && !empty($params['claim_amount'])){ + return false; + } + + $hasValidCondition = false; + + foreach ($params as $key => $value) { + if ($value !== null && $value !== '') { + $query->where($key, $value); + $hasValidCondition = true; + } + } + + if (!$hasValidCondition) { + return false; + } + + $result = $query->countAllResults(); + if($result > 0){ return true; }else{ return false; } + } +} + +