diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index fb78c67b..4ca4505d 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -594,7 +594,7 @@ class ClientController extends AdminController $data['insurer'] = $this->insurerBranchModel->getInsurerBranchesWithInsurerNames(); $data['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); $data['state'] = $this->stateModel->getAllStates(); - $data['RM'] = $this->userModel->findAll(); + $data['RM'] = $this->userModel->where('is_active', 1)->findAll(); $data['policyGridData'] = $this->policyGridModel->findAll(); $data['policy_types'] = $this->policyTypeModel->findAll(); $data['policy_type'] = ['1' => 'Base Policy', '2' => 'SI Topup', '3' => 'Dependent Addon']; @@ -717,7 +717,7 @@ class ClientController extends AdminController $this->myLogger->logme('error', 'Edit Client Onboarding function called'); $headerData['page_name'] = 'Edit Client Onboarding'; - $editData['RM'] = $this->userModel->findAll(); + $editData['RM'] = $this->userModel->where('is_active', 1)->findAll(); $editData['tpa'] = $this->tpaBranchModel->getTpaBranchesWithTpaNames(); $editData['state'] = $this->stateModel->getAllStates(); $editData['police'] = $this->policesModel->findAll(); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index f46fc522..2d7bf436 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2532,10 +2532,6 @@ class EmployeeRestController extends AdminController $result = []; foreach ($ClientPolicyData as $key => $ClientPolicyValue) { - - - - if($ClientPolicyValue['policy_type_id'] == 1) { $policyGroup = 'gpa'; @@ -2555,11 +2551,7 @@ class EmployeeRestController extends AdminController } $terms = json_decode($ClientPolicyValue['policy_terms'] , true); - $data['policy_terms'] = isset($terms['enrollment_display_key']) - && !empty($terms['enrollment_display_key']) - ? $terms['enrollment_display_key'] - : $this->policyTermsFiter($terms, $policyGroup); - $terms = json_decode($ClientPolicyValue['policy_terms']); + $data['policy_terms'] = isset($terms['enrollment_display_key']) && !empty($terms['enrollment_display_key']) ? $terms['enrollment_display_key'] : $this->policyTermsFiter($terms, $policyGroup); $data['client_id'] = $ClientPolicyValue['client_id']; diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index b361c5b3..8d926761 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -628,12 +628,16 @@ class LeadsController extends BaseController public function createRFQ() { - - // print_r($this->request->getPost('json')); die(); - $data = $this->request->getPost(); - $lead_id = $data['lead_id']; + $lead_id = $data['lead_id'] ?? null; + + if (!$lead_id) { + return $this->respond(['status' => false, 'message' => 'Lead ID is required'], 400); + } + $data['type'] = 1; + + // Deactivate existing RFQs for this lead and type $this->RFQModel ->where('lead_id', $lead_id) ->where('type', 1) @@ -641,41 +645,40 @@ class LeadsController extends BaseController ->set('is_active', 0) ->update(); - $registrationJson = $data['registration_json'] ?? null; // Use null coalescing operator for safety + // Handle registration_json + if (empty($data['registration_json'])) { + // Fetch the latest registration_json if not provided + $latest = $this->RFQModel + ->select('registration_json') + ->where('lead_id', $lead_id) + ->orderBy('id', 'DESC') + ->first(); - if ($registrationJson) { - // If registration_json is provided, insert the data directly - $result = $this->RFQModel->insert($data); - } else { - // If registration_json is not provided, fetch the latest registration_json from the database - $this->RFQModel->select('registration_json') - ->where("lead_id", $lead_id) - ->order_by('id', 'DESC') // Assuming 'id' is an auto-increment field - ->limit(1); - - $query = $this->RFQModel->get(); - $latestRegistrationJson = $query->row()->registration_json ?? null; - - if ($latestRegistrationJson) { - // If a valid registration_json is found, update the data and insert - $data['registration_json'] = $latestRegistrationJson; - $result = $this->RFQModel->insert($data); - } else { - // If no registration_json is found, insert the data as-is - $result = $this->RFQModel->insert($data); + if (!empty($latest['registration_json'])) { + $data['registration_json'] = $latest['registration_json']; } } - if ($result) { + // Insert new RFQ + $insertId = $this->RFQModel->insert($data); - $message = "RFQ submitted successfully"; - if ($data['submit_type'] == 'QCR') { - $message = "QCR submitted successfully"; - } - return $this->respond(['status' => true, 'id' => $result, 'message' => $message, 'data' => $data], 200); + if ($insertId) { + $message = ($data['submit_type'] ?? '') == 'QCR' ? 'QCR submitted successfully' : 'RFQ submitted successfully'; + return $this->respond([ + 'status' => true, + 'id' => $insertId, + 'message' => $message, + 'data' => $data + ], 200); } - return $this->respond(['status' => false, 'id' => $result, 'message' => "Failed to create RFQ", 'data' => $data], 200); + $message = ($data['submit_type'] ?? '') == 'QCR' ? 'Failed to create QCR' : 'Failed to create RFQ'; + return $this->respond([ + 'status' => false, + 'id' => null, + 'message' => $message, + 'data' => $data + ], 200); } public function createQCR() @@ -2575,15 +2578,19 @@ class LeadsController extends BaseController public function constructNonEbExcelToSaveTemp($lead_id, $type, $propsal_and_insurer = null) { - $rfq_data = $this->RFQModel->getRFQTableDataWithLeadIDAndType($lead_id, $type); - $lead_data = json_decode($rfq_data['custom_fields'], true) ?? []; if (!is_array($lead_data)) { $lead_data = []; } $lead_data = array_merge(['Insured' => $rfq_data['client_name']], $lead_data); + $policy_registration_data = []; + if(isset($rfq_data['registration_json']) && !empty($rfq_data['registration_json'])){ + $policy_registration_data = json_decode($rfq_data['registration_json'], true); + } + // dd($policy_registration_data); + // if(!empty($rfq_data['fin_years_claims'])){ // $claim_details = json_decode($rfq_data['fin_years_claims'], true) ?? []; // if(!empty($claim_details['finyear'])){ diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 3d141b2b..27114883 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -118,7 +118,7 @@ class RestAuthenticationController extends AdminController ->where('employees.emp_status !=', 'truncated') ->where('employees.email_corporate', $email) ->where('EP.is_active', 1) - ->whereIn('EP.status', ['draft', 'enrolled']) + ->whereIn('EP.status', ['active']) ->first(); if (isset($employeeData['employee_id'])) { diff --git a/app/Models/RFQModel.php b/app/Models/RFQModel.php index 24d18529..4ffbf9d4 100644 --- a/app/Models/RFQModel.php +++ b/app/Models/RFQModel.php @@ -68,6 +68,7 @@ class RFQModel extends Model tpa_branch.branch_name as tpa_branch_name, policy_type.policy_type, rfq.json, + rfq.registration_json ') ->join('leads', 'rfq.lead_id = leads.id') ->join('policy_type', 'leads.policy_type_id = policy_type.id') diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 1e7d1cbc..0abdf8d5 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -563,7 +563,7 @@ - +