FIX_VechileValidation
This commit is contained in:
parent
f5eb5646c1
commit
2a07d24bda
@ -712,7 +712,9 @@ class EnquiryController extends ResourceController
|
|||||||
])->setStatusCode(400);
|
])->setStatusCode(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($reg_no == 'New' || $reg_no == 'new' || $reg_no == 'NEW') {
|
$normalized_input = strtoupper(preg_replace('/[^A-Za-z0-9]/', '', $reg_no));
|
||||||
|
|
||||||
|
if ($normalized_input === 'NEW') {
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
"status" => "not exists",
|
"status" => "not exists",
|
||||||
"message" => "No active record found for this vehicle number in enquiries."
|
"message" => "No active record found for this vehicle number in enquiries."
|
||||||
@ -723,34 +725,33 @@ class EnquiryController extends ResourceController
|
|||||||
// Get the LATEST ACTIVE enquiry record for the registration number
|
// Get the LATEST ACTIVE enquiry record for the registration number
|
||||||
$enquiry = $this->db->table("partner_enquiry")
|
$enquiry = $this->db->table("partner_enquiry")
|
||||||
->select("*")
|
->select("*")
|
||||||
->where("reg_no", $reg_no)
|
->where("is_active", 1)
|
||||||
->where("is_active", 1) // Only consider active enquiries
|
->groupStart()
|
||||||
|
// This replaces common separators in the DB column with empty strings
|
||||||
|
->where("REPLACE(REPLACE(REPLACE(reg_no, ' ', ''), '-', ''), '.', '') =", $normalized_input)
|
||||||
|
->groupEnd()
|
||||||
->orderBy("id", "DESC")
|
->orderBy("id", "DESC")
|
||||||
->get()
|
->get()
|
||||||
->getRowArray();
|
->getRowArray();
|
||||||
|
|
||||||
// If no active enquiry is found, the vehicle is considered 'not' a duplicate
|
|
||||||
if (!$enquiry) {
|
if (!$enquiry) {
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
"status" => "not exists",
|
"status" => "not exists",
|
||||||
"message" => "No active record found for this vehicle number in enquiries."
|
"message" => "No active record found for $reg_no"
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: The previous check for $enquiry["is_active"] == 0 is now redundant
|
// NOTE: The previous check for $enquiry["is_active"] == 0 is now redundant
|
||||||
// because the query already filters for where("is_active", 1).
|
// because the query already filters for where("is_active", 1).
|
||||||
|
|
||||||
// --- 3. Step 2: Check in partner_policy (Active Policy for Enquiry) ---
|
// --- 3. Step 2: Check in partner_policy (Active Policy for Enquiry) ---
|
||||||
// Get the LATEST ACTIVE policy for the found enquiry
|
// Get the LATEST ACTIVE policy for the found enquiry
|
||||||
$policy = $this->db->table("partner_policy")
|
$policy = $this->db->table("partner_policy")
|
||||||
->select("*")
|
|
||||||
->where("enquiry_id", $enquiry["id"])
|
->where("enquiry_id", $enquiry["id"])
|
||||||
->where("is_active", 1) // Only consider active policies
|
->where("is_active", 1)
|
||||||
->orderBy("id", "DESC")
|
->orderBy("id", "DESC")
|
||||||
->get()
|
->get()
|
||||||
->getRowArray();
|
->getRowArray();
|
||||||
|
|
||||||
// If no active policy is found for the active enquiry, return "not"
|
|
||||||
if (!$policy) {
|
if (!$policy) {
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
"status" => "exists",
|
"status" => "exists",
|
||||||
@ -782,15 +783,5 @@ class EnquiryController extends ResourceController
|
|||||||
"message" => "Policy exists but is expired for vehicle number " . $reg_no
|
"message" => "Policy exists but is expired for vehicle number " . $reg_no
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user