Merge branch 'main' of bitbucket.org:jubilian/nhance_partner_be

This commit is contained in:
sanjeev.p 2025-12-31 13:19:05 +05:30
commit 3b72c275c5
4 changed files with 108 additions and 5 deletions

View File

@ -133,6 +133,8 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) {
//endorsement
$routes->get('endorsement/endorsementList', 'EndorsementController::endorsementList');
$routes->post('endorsement/createEndorsement', 'EndorsementController::createEndorsement');
$routes->post('endorsement/updateEndorsement', 'EndorsementController::updateEndorsement');
$routes->get('endorsement/downloadEndorsementCompletionFile', 'EndorsementController::downloadEndorsementCompletionFile');
//dashboard
$routes->get('dashboard/managerDashboard', 'DashboardController::managerDashboard');

View File

@ -109,7 +109,7 @@ class EndorsementController extends ResourceController
->where('partner_policy.policy_number', $reqData['policy_number'])
->first();
if (empty($policy)) {
if (empty($policy) && $reqData['policy_from'] == 'Internal') {
return $this->respond(['status' => 'failed','code' => 404,'data' => 'Policy not found'], 200);
}
@ -128,13 +128,14 @@ class EndorsementController extends ResourceController
// Prepare endorsement data
$endorsementData = [
'policy_number' => $policy['policy_number'],
'policy_from' => $reqData['policy_from'],
'policy_number' => $policy['policy_number'] ?? $reqData['policy_number'],
'client_policy_id' => $policy['client_policy_id'] ?? null,
'insurer_id' => $policy['insurer_id'] ?? null,
'insurer_branch_id' => $policy['insurer_branch_id'] ?? null,
'client_id' => $policy['client_id'] ?? null,
'agent_id' => $policy['agent_id'] ?? null,
'manager_id' => $policy['manager_id'] ?? null,
'manager_id' => $reqData['manager_id'] ?? null,
'endorsement_type' => $reqData['endorsement_type'],
'endorsement_description'=> $reqData['endorsement_description'],
'endorsement_no' => $reqData['endorsement_no'] ?? null,
@ -144,8 +145,67 @@ class EndorsementController extends ResourceController
'is_active' => 1
];
// ✅ Insert endorsement
if (!$this->EndorsementModel->insert($endorsementData)) {
return $this->respond([ 'status' => 'failed', 'code' => 422, 'data' => $this->EndorsementModel->errors()], 422);
}
return $this->respond([ 'status' => 'success', 'code' => 200, 'data' => ['endorsement_id' => $this->EndorsementModel->getInsertID()] ], 200);
} catch (\Exception $e) {
return $this->respond([ 'status' => 'failed', 'code' => 500, 'data' => $e->getMessage() ], 500);
}
}
public function updateEndorsement()
{
try {
$endorsementId = $this->request->getPost('id');
if (!$endorsementId) {
return $this->respond([ 'status' => 'failed', 'code' => 400, 'data' => 'endorsementId is required' ], 200);
}
$reqData = $this->request->getPost();
// Fetch existing record
$endorsement = $this->EndorsementModel->find($endorsementId);
if (empty($endorsement)) {
return $this->respond([ 'status' => 'failed', 'code' => 404, 'data' => 'Endorsement not found' ], 200);
}
// Handle upload (endorsement completion file)
$uploadFile = $this->request->getFile('endorsement_completion_file');
$uploadedCompletionFile = $endorsement['endorsement_completion_file']; // keep old if not replaced
if ($uploadFile && $uploadFile->isValid()) {
$uploadPath = WRITEPATH . 'uploads/endorsement/';
if (!is_dir($uploadPath)) {
mkdir($uploadPath, 0777, true);
}
$uploadedCompletionFile = time() . '_' . $uploadFile->getRandomName();
$uploadFile->move($uploadPath, $uploadedCompletionFile);
}
// Prepare data to update
$updateData = [
'endorsement_type' => $reqData['endorsement_type'] ?? $endorsement['endorsement_type'],
'endorsement_description' => $reqData['endorsement_description'] ?? $endorsement['endorsement_description'],
'endorsement_no' => $reqData['endorsement_no'] ?? $endorsement['endorsement_no'],
'status' => $reqData['status'] ,
'endorsement_completion_file' => $uploadedCompletionFile,
'contact_person' => $reqData['contact_person'] ,
'financia_or_non_financial' => $reqData['financia_or_non_financial'] ,
'endorsement_premium' => $reqData['endorsement_premium'] ,
'pending_days' => $reqData['pending_days'] ,
'updated_by' => $reqData['updated_by'] ?? null,
];
if (!$this->EndorsementModel->update($endorsementId, $updateData)) {
return $this->respond([
'status' => 'failed',
'code' => 422,
@ -156,7 +216,7 @@ class EndorsementController extends ResourceController
return $this->respond([
'status' => 'success',
'code' => 200,
'data' => ['endorsement_id' => $this->EndorsementModel->getInsertID()]
'data' => ['endorsement_id' => $endorsementId, 'message' => 'Endorsement updated successfully']
], 200);
} catch (\Exception $e) {
@ -169,6 +229,40 @@ class EndorsementController extends ResourceController
}
public function downloadEndorsementCompletionFile()
{
try {
$id = $this->request->getGet('id');
if (!$id) {
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'ID is required'], 200);
}
// Fetch record from DB
$fileRecord = $this->EndorsementModel->find($id);
if (!$fileRecord) {
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'File not found'], 200);
}
$filePath = WRITEPATH . 'uploads/endorsement/' . $fileRecord['endorsement_completion_file'];
if (!file_exists($filePath)) {
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'File missing on server'], 200);
}
// Force file download
return $this->response->download($filePath, null);
} catch (\Exception $e) {
return $this->respond(['status' => 'failed', 'code' => 500, 'message' => $e->getMessage()], 500);
}
}

View File

@ -12,6 +12,7 @@ class EndorsementModel extends Model
protected $useSoftDeletes = false;
protected $allowedFields = [
'policy_from',
'client_id',
'client_policy_id',
'insurer_id',
@ -24,6 +25,11 @@ class EndorsementModel extends Model
'endorsement_description',
'status',
'endorsement_file_name',
'endorsement_completion_file',
'contact_person',
'financia_or_non_financial',
'endorsement_premium',
'pending_days',
'created_at',
'updated_by',
'updated_at',

View File

@ -14,6 +14,7 @@ class EndorsementTypeModel extends Model
protected $returnType = 'array';
protected $allowedFields = [
'endorsement_type',
'is_active',
'created_by',