diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3d63bd2..5c7499a 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -129,6 +129,7 @@ $routes->group('api', ['filter' => 'appSignature'], function ($routes) { $routes->post('policy/calculateCommissionRequest', 'PolicyController::calculateCommissionRequest'); $routes->get("policy/vehicleTypeMaster", "PolicyController::vehicleTypeMaster"); $routes->get("policy/fuelTypeMaster", "PolicyController::fuelTypeMaster"); + $routes->get("policy/softdelete", "PolicyController::softdelete"); //claims diff --git a/app/Controllers/PolicyController.php b/app/Controllers/PolicyController.php index fcaa7e9..3c94ad4 100644 --- a/app/Controllers/PolicyController.php +++ b/app/Controllers/PolicyController.php @@ -1318,6 +1318,79 @@ class PolicyController extends ResourceController } + public function softdelete() + { + try { + $policyId = (int) $this->request->getGet('policy_id'); + + if (!$policyId) { + return $this->respond([ + 'status' => 'failed', + 'code' => 400, + 'data' => 'policy_id is required' + ], 400); + } + + $policy = $this->PolicyModel->find($policyId); + + if (!$policy) { + return $this->respond([ + 'status' => 'failed', + 'code' => 404, + 'data' => 'Data Not Found' + ], 404); + } + + // Start DB transaction + $db = \Config\Database::connect(); + $db->transStart(); + + // Soft delete policy + $this->PolicyModel->update($policyId, ['is_active' => 0]); + + // Soft delete quotation + if (!empty($policy['quotation_id'])) { + $this->QuotationModel->update( + (int) $policy['quotation_id'], + ['is_active' => 0] + ); + } + + // Soft delete enquiry + if (!empty($policy['enquiry_id'])) { + $this->EnquiryModel->update( + (int) $policy['enquiry_id'], + ['is_active' => 0] + ); + } + + $db->transComplete(); + + if ($db->transStatus() === false) { + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'data' => 'Failed to delete data' + ], 500); + } + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'data' => 'Deleted Successfully!' + ], 200); + + } catch (\Throwable $e) { + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => $e->getMessage() + ], 500); + } + } + + +