Endoresment update changes : GWM
This commit is contained in:
parent
e6a21bddea
commit
2e00095510
@ -133,6 +133,7 @@ $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');
|
||||
|
||||
//dashboard
|
||||
$routes->get('dashboard/managerDashboard', 'DashboardController::managerDashboard');
|
||||
|
||||
@ -157,6 +157,74 @@ class EndorsementController extends ResourceController
|
||||
}
|
||||
}
|
||||
|
||||
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' => 'Completed', // Fixed Update to Completed
|
||||
'endorsement_completion_file' => $uploadedCompletionFile,
|
||||
'updated_by' => $reqData['updated_by'] ?? null,
|
||||
];
|
||||
|
||||
if (!$this->EndorsementModel->update($endorsementId, $updateData)) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 422,
|
||||
'data' => $this->EndorsementModel->errors()
|
||||
], 422);
|
||||
}
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
'code' => 200,
|
||||
'data' => ['endorsement_id' => $endorsementId, 'message' => 'Endorsement updated successfully']
|
||||
], 200);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->respond([
|
||||
'status' => 'failed',
|
||||
'code' => 500,
|
||||
'data' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -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,7 @@ class EndorsementModel extends Model
|
||||
'endorsement_description',
|
||||
'status',
|
||||
'endorsement_file_name',
|
||||
'endorsement_completion_file',
|
||||
'created_at',
|
||||
'updated_by',
|
||||
'updated_at',
|
||||
|
||||
@ -14,7 +14,7 @@ class EndorsementTypeModel extends Model
|
||||
protected $returnType = 'array';
|
||||
|
||||
protected $allowedFields = [
|
||||
'policy_from',
|
||||
|
||||
'endorsement_type',
|
||||
'is_active',
|
||||
'created_by',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user