Merge branch 'main' of bitbucket.org:jubilian/nhance_partner_be
This commit is contained in:
commit
6b307dd8bd
@ -875,11 +875,11 @@ class DashboardController extends ResourceController
|
|||||||
$builder = $this->db->table('partner_policy pp');
|
$builder = $this->db->table('partner_policy pp');
|
||||||
|
|
||||||
$builder->select("
|
$builder->select("
|
||||||
pp.premium_amount,
|
|
||||||
pp.agent_id AS PP_agent_id,
|
|
||||||
pa.id AS agent_id,
|
pa.id AS agent_id,
|
||||||
pa.name AS agent_name,
|
pa.name AS agent_name,
|
||||||
pa.agent_code AS agent_code,
|
pa.agent_code AS agent_code,
|
||||||
|
pp.agent_id AS PP_agent_id,
|
||||||
|
SUM(pp.premium_amount) AS total_premium_amount,
|
||||||
CASE
|
CASE
|
||||||
WHEN pa.is_active = 1 THEN 'Active Agent'
|
WHEN pa.is_active = 1 THEN 'Active Agent'
|
||||||
ELSE 'Inactive Agent'
|
ELSE 'Inactive Agent'
|
||||||
@ -887,20 +887,13 @@ class DashboardController extends ResourceController
|
|||||||
DATE_FORMAT(pp.created_on, '%d-%m-%Y') AS created_date_ui_formatted,
|
DATE_FORMAT(pp.created_on, '%d-%m-%Y') AS created_date_ui_formatted,
|
||||||
pp.created_on AS created_date_sql_formatted
|
pp.created_on AS created_date_sql_formatted
|
||||||
");
|
");
|
||||||
|
$builder->join('partner_agent pa', 'pa.id = pp.agent_id', 'left');
|
||||||
$builder->join(
|
$builder->where('pp.manager_id', $manager_id);
|
||||||
'partner_agent pa',
|
|
||||||
'pa.id = pp.agent_id',
|
|
||||||
'left'
|
|
||||||
);
|
|
||||||
|
|
||||||
$builder->where('pp.manager_id',$manager_id);
|
|
||||||
|
|
||||||
$builder->where('pp.premium_amount <', 50000);
|
$builder->where('pp.premium_amount <', 50000);
|
||||||
$builder->where("pp.created_on >= $interval", null, false); // false = prevent escaping raw SQL
|
$builder->where("pp.created_on >= $interval", null, false); // raw SQL
|
||||||
$builder->orderBy('pp.created_on', 'DESC');
|
$builder->groupBy('pa.id');
|
||||||
$result = $builder->get()->getResultArray();
|
$builder->orderBy('total_premium_amount', 'DESC');
|
||||||
return $result;
|
$builder->orderBy('created_date_sql_formatted', 'DESC');
|
||||||
|
return $builder->get()->getResultArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -682,9 +682,80 @@ class EnquiryController extends ResourceController
|
|||||||
return $this->respond(['status' => 'success','data' => $enquiryId ], 200);
|
return $this->respond(['status' => 'success','data' => $enquiryId ], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkDuplicate()
|
public function checkVehicleDuplicate()
|
||||||
{
|
{
|
||||||
$request = $this->request->getGet("reg_no");
|
// --- 1. Input Validation ---
|
||||||
|
$reg_no = $this->request->getGet("reg_no");
|
||||||
|
|
||||||
|
if (!$reg_no) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'status' => 'error',
|
||||||
|
'message' => 'Please provide a valid vehicle registration number.'
|
||||||
|
])->setStatusCode(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 2. Step 1: Check in partner_enquiry (Active/Latest Record) ---
|
||||||
|
// Get the LATEST ACTIVE enquiry record for the registration number
|
||||||
|
$enquiry = $this->db->table("partner_enquiry")
|
||||||
|
->select("*")
|
||||||
|
->where("reg_no", $reg_no)
|
||||||
|
->where("is_active", 1) // Only consider active enquiries
|
||||||
|
->orderBy("id", "DESC")
|
||||||
|
->get()
|
||||||
|
->getRowArray();
|
||||||
|
|
||||||
|
// If no active enquiry is found, the vehicle is considered 'not' a duplicate
|
||||||
|
if (!$enquiry) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
"status" => "not exists",
|
||||||
|
"message" => "No active record found for this vehicle number in enquiries."
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: The previous check for $enquiry["is_active"] == 0 is now redundant
|
||||||
|
// because the query already filters for where("is_active", 1).
|
||||||
|
|
||||||
|
// --- 3. Step 2: Check in partner_policy (Active Policy for Enquiry) ---
|
||||||
|
// Get the LATEST ACTIVE policy for the found enquiry
|
||||||
|
$policy = $this->db->table("partner_policy")
|
||||||
|
->select("*")
|
||||||
|
->where("enquiry_id", $enquiry["id"])
|
||||||
|
->where("is_active", 1) // Only consider active policies
|
||||||
|
->orderBy("id", "DESC")
|
||||||
|
->get()
|
||||||
|
->getRowArray();
|
||||||
|
|
||||||
|
// If no active policy is found for the active enquiry, return "not"
|
||||||
|
if (!$policy) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
"status" => "exists",
|
||||||
|
"message" => "Vehicle enquiry found but no active policy issued."
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 4. Step 3: Compare end_date >= CURRENT_DATE ---
|
||||||
|
$currentDate = date("Y-m-d");
|
||||||
|
|
||||||
|
// The policy is active if the end_date is TODAY or in the FUTURE.
|
||||||
|
if ($policy["end_date"] >= $currentDate) {
|
||||||
|
// ACTIVE POLICY → 'exists'
|
||||||
|
$msg = $enquiry["name"]." with policy ".$policy["policy_number"]." for vehicle ".$reg_no." already exists and is active.";
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
"status" => "exists",
|
||||||
|
"message" => $msg,
|
||||||
|
"ref" => [
|
||||||
|
"enquiry" => $enquiry,
|
||||||
|
"policy" => $policy
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POLICY expired (end_date is in the past)
|
||||||
|
return $this->response->setJSON([
|
||||||
|
"status" => "not exists",
|
||||||
|
"message" => "Policy exists but is expired for vehicle number " . $reg_no
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -697,5 +768,4 @@ class EnquiryController extends ResourceController
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user