Merge branch 'main' of bitbucket.org:jubilian/nhance_partner_be
This commit is contained in:
commit
792d5a740a
@ -64,7 +64,7 @@ class ClaimController extends ResourceController
|
||||
$to_date = $this->request->getGet('to_date');
|
||||
|
||||
$builder = $this->db->table('partner_claims pc')
|
||||
->select('pc.*,
|
||||
->select("pc.*,
|
||||
i.name as insurer_name,
|
||||
i.short_name as insurer_short_name,
|
||||
pct.claim_type as claim_type_value,
|
||||
@ -73,7 +73,12 @@ class ClaimController extends ResourceController
|
||||
tcs.claim_status as claim_status_value,
|
||||
pp.start_date as policy_start_date,
|
||||
pp.end_date as policy_end_date,
|
||||
v.vehicle_no as reg_no')
|
||||
pp.rc_no as reg_no,
|
||||
CASE
|
||||
WHEN pc.reg_no IS NULL OR pc.reg_no = '' THEN pp.rc_no
|
||||
ELSE pc.reg_no
|
||||
END AS reg_no
|
||||
")
|
||||
->join('insurers i', 'i.id = pc.insurer_id', 'left')
|
||||
->join('partner_claim_type_master pct', 'pct.id = pc.claim_type', 'left')
|
||||
->join('partner_agent pa', 'pa.id = pc.agent_id', 'left')
|
||||
@ -145,23 +150,25 @@ class ClaimController extends ResourceController
|
||||
try {
|
||||
$reqData = $this->request->getPost();
|
||||
|
||||
if (empty($reqData['policy_number']) || empty($reqData['claim_description']) || empty($reqData['claim_type'])) {
|
||||
if (empty($reqData['policy_number']) || empty($reqData['claim_type']) || empty($reqData['policy_from'])) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 400,
|
||||
'data' => 'policy_number, claim_description and claim_type are required',
|
||||
'data' => 'policy_number, claim_type and policy_from are required',
|
||||
], 400);
|
||||
}
|
||||
|
||||
$policy = $this->PolicyModel
|
||||
->select('partner_policy.*, Q.insurer_id, E.mobile as client_mobile, E.email as client_email, E.broker_id')
|
||||
->join('partner_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left')
|
||||
->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left')
|
||||
->where('partner_policy.policy_number', $reqData['policy_number'])
|
||||
->first();
|
||||
if($reqData['policy_from'] === 'Internal') {
|
||||
$policy = $this->PolicyModel
|
||||
->select('partner_policy.*, Q.insurer_id, E.mobile as client_mobile, E.email as client_email, E.broker_id')
|
||||
->join('partner_quotation Q', 'Q.id = partner_policy.quotation_id AND Q.status = "Accepted"', 'left')
|
||||
->join('partner_enquiry E', 'E.id = partner_policy.enquiry_id', 'left')
|
||||
->where('partner_policy.policy_number', $reqData['policy_number'])
|
||||
->first();
|
||||
|
||||
if (empty($policy)) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'Policy not found'], 404);
|
||||
if (empty($policy)) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'Policy not found'], 404);
|
||||
}
|
||||
}
|
||||
|
||||
$status = $this->ClaimStatusModel
|
||||
@ -176,9 +183,11 @@ class ClaimController extends ResourceController
|
||||
|
||||
$claimData = [
|
||||
'claim_status_id' => $reqData['claim_status_id'] ?? $status['id'],
|
||||
'policy_id' => $policy['id'],
|
||||
'policy_no' => $policy['policy_number'],
|
||||
'insurer_id' => $policy['insurer_id'] ?? null,
|
||||
'policy_id' => $policy['id'] ?? null,
|
||||
'policy_no' => $policy['policy_number'] ?? $reqData['policy_number'] ?? null,
|
||||
'claim_number' => $reqData['claim_number'] ?? null,
|
||||
'policy_from' => $reqData['policy_from'],
|
||||
'insurer_id' => $policy['insurer_id'] ?? $reqData['insurer_id'] ?? null,
|
||||
'broker_id' => $reqData['broker_id'] ?? $policy['broker_id'] ?? null,
|
||||
'insured_name' => $reqData['insured_name'] ?? $policy['insured_name'] ?? null,
|
||||
'mobile' => $reqData['mobile'] ?? $policy['client_mobile'] ?? null,
|
||||
@ -188,7 +197,7 @@ class ClaimController extends ResourceController
|
||||
'claim_type' => $reqData['claim_type'],
|
||||
'date_of_incident' => format_date_for_database($reqData['date_of_incident'] ?? null),
|
||||
'place_of_incident' => $reqData['place_of_incident'] ?? null,
|
||||
'claim_description' => $reqData['claim_description'],
|
||||
'claim_description' => $reqData['claim_description'] ?? null,
|
||||
'spot_surveyor_name' => $reqData['spot_surveyor_name'] ?? null,
|
||||
'spot_surveyor_contact' => $reqData['spot_surveyor_contact'] ?? null,
|
||||
'workshop_surveyor_name' => $reqData['workshop_surveyor_name'] ?? null,
|
||||
@ -196,6 +205,7 @@ class ClaimController extends ResourceController
|
||||
'remark' => $reqData['remark'] ?? null,
|
||||
'is_active' => 1,
|
||||
'created_by' => $reqData['created_by'] ?? null,
|
||||
'reg_no' => $reqData['reg_no'] ?? null,
|
||||
];
|
||||
|
||||
$this->db->transStart();
|
||||
@ -274,6 +284,7 @@ class ClaimController extends ResourceController
|
||||
'workshop_surveyor_contact',
|
||||
'remark',
|
||||
'is_active',
|
||||
'policy_from',
|
||||
];
|
||||
|
||||
foreach ($allowedUpdateFields as $field) {
|
||||
@ -306,6 +317,12 @@ class ClaimController extends ResourceController
|
||||
$updateData['updated_by'] = $reqData['updated_by'];
|
||||
}
|
||||
|
||||
if($reqData['policy_from'] === 'External') {
|
||||
$updateData['reg_no'] = $reqData['reg_no'] ?? null;
|
||||
$updateData['claim_number'] = $reqData['claim_number'] ?? null;
|
||||
$updateData['policy_no'] = $reqData['policy_number'] ?? null;
|
||||
}
|
||||
|
||||
if (!empty($updateData) && !$this->ClaimModel->update((int) $claimId, $updateData)) {
|
||||
return $this->respond(['status' => 'failed', 'code' => 422, 'data' => $this->ClaimModel->errors()], 422);
|
||||
}
|
||||
@ -348,7 +365,7 @@ class ClaimController extends ResourceController
|
||||
}
|
||||
|
||||
$claim = $this->db->table('partner_claims pc')
|
||||
->select('pc.*,
|
||||
->select("pc.*,
|
||||
i.name as insurer_name,
|
||||
i.short_name as insurer_short_name,
|
||||
pct.claim_type as claim_type_value,
|
||||
@ -357,7 +374,12 @@ class ClaimController extends ResourceController
|
||||
tcs.claim_status as claim_status_value,
|
||||
pp.start_date as policy_start_date,
|
||||
pp.end_date as policy_end_date,
|
||||
v.vehicle_no as reg_no')
|
||||
|
||||
CASE
|
||||
WHEN pc.reg_no IS NULL OR pc.reg_no = '' THEN v.vehicle_no
|
||||
ELSE pc.reg_no
|
||||
END AS reg_no
|
||||
")
|
||||
->join('insurers i', 'i.id = pc.insurer_id', 'left')
|
||||
->join('partner_claim_type_master pct', 'pct.id = pc.claim_type', 'left')
|
||||
->join('partner_agent pa', 'pa.id = pc.agent_id', 'left')
|
||||
@ -503,9 +525,11 @@ class ClaimController extends ResourceController
|
||||
private function collectClaimUploadFiles(): array
|
||||
{
|
||||
$filesToProcess = [];
|
||||
|
||||
|
||||
// getFileMultiple() works when input name is claim_files[]
|
||||
$multiple = $this->request->getFileMultiple('claim_files');
|
||||
if (!empty($multiple)) {
|
||||
|
||||
if (!empty($multiple) && is_array($multiple)) {
|
||||
foreach ($multiple as $uploadedFile) {
|
||||
if ($this->isValidUploadFile($uploadedFile)) {
|
||||
$filesToProcess[] = $uploadedFile;
|
||||
@ -513,12 +537,20 @@ class ClaimController extends ResourceController
|
||||
}
|
||||
return $filesToProcess;
|
||||
}
|
||||
|
||||
|
||||
// Fallback: getFile() may return an array of files in some CI4 versions
|
||||
$single = $this->request->getFile('claim_files');
|
||||
if ($this->isValidUploadFile($single)) {
|
||||
|
||||
if (is_array($single)) {
|
||||
foreach ($single as $uploadedFile) {
|
||||
if ($this->isValidUploadFile($uploadedFile)) {
|
||||
$filesToProcess[] = $uploadedFile;
|
||||
}
|
||||
}
|
||||
} elseif ($this->isValidUploadFile($single)) {
|
||||
$filesToProcess[] = $single;
|
||||
}
|
||||
|
||||
|
||||
return $filesToProcess;
|
||||
}
|
||||
|
||||
|
||||
@ -36,6 +36,9 @@ class ClaimModel extends Model
|
||||
'is_active',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'claim_number',
|
||||
'policy_from',
|
||||
'reg_no',
|
||||
];
|
||||
|
||||
// Auto timestamps
|
||||
|
||||
Loading…
Reference in New Issue
Block a user