FIX_checkVehicleDuplicate(ENDDATE 00-00-0000 Validation)

This commit is contained in:
sanjeev.p 2026-02-02 10:29:30 +05:30
parent 73bd213a07
commit cbed0c8305

View File

@ -718,7 +718,7 @@ class EnquiryController extends ResourceController
// --- 1. Input Validation --- // --- 1. Input Validation ---
$reg_no = $this->request->getGet("reg_no"); $reg_no = $this->request->getGet("reg_no");
if (!$reg_no) { if (empty($reg_no)) {
return $this->response->setJSON([ return $this->response->setJSON([
'status' => 'error', 'status' => 'error',
'message' => 'Please provide a valid vehicle registration number.' 'message' => 'Please provide a valid vehicle registration number.'
@ -772,14 +772,20 @@ class EnquiryController extends ResourceController
]); ]);
} }
// --- 4. Step 3: Compare end_date >= CURRENT_DATE --- $endDate = $policy["end_date"] ?? '';
$currentDate = date("Y-m-d"); $currentDate = date("Y-m-d");
// The policy is active if the end_date is TODAY or in the FUTURE. // --- 4. Step 3 Check if date is missing or invalid format (0000-00-00)
if ($policy["end_date"] >= $currentDate) { if (empty($endDate) || $endDate === "0000-00-00") {
// ACTIVE POLICY → 'exists' return $this->response->setJSON([
$msg = $enquiry["name"]." with policy ".$policy["policy_number"]." for vehicle ".$reg_no." already exists and is active."; "status" => "exists",
"message" => "Policy exists but end date is invalid for $reg_no"
]);
}
// --- 5. Step 4 Compare Dates
$msg = $enquiry["name"]." with policy ".$policy["policy_number"]." for vehicle ".$reg_no." already exists and is active.";
if ($endDate >= $currentDate) {
return $this->response->setJSON([ return $this->response->setJSON([
"status" => "exists", "status" => "exists",
"message" => $msg, "message" => $msg,
@ -790,10 +796,10 @@ class EnquiryController extends ResourceController
]); ]);
} }
// POLICY expired (end_date is in the past) // --- 6. POLICY expired (end_date is in the past)
return $this->response->setJSON([ return $this->response->setJSON([
"status" => "not exists", "status" => "not exists",
"message" => "Policy exists but is expired for vehicle number " . $reg_no "message" => "Policy exists but expired on $endDate for vehicle $reg_no"
]); ]);
} }