diff --git a/app/Controllers/QuotationController.php b/app/Controllers/QuotationController.php index e698b67..4565b89 100644 --- a/app/Controllers/QuotationController.php +++ b/app/Controllers/QuotationController.php @@ -347,7 +347,7 @@ class QuotationController extends ResourceController $policyPdf = $this->request->getFile('policy_pdf_file_name'); /* ------------------------------------------------------ - * CASE 1: Update Policy (policy_id + file uploaded) + * Update Policy (policy_id + file uploaded) * ------------------------------------------------------ */ if (!empty($policyId) && $policyPdf && $policyPdf->isValid()) { @@ -404,37 +404,34 @@ class QuotationController extends ResourceController $this->QuotationModel->update($quotationId, $quotationData); - return $this->respond([ - 'status' => 'success', - 'code' => 200, - 'msg' => 'Quotation updated successfully' - ], 200); } /* ------------------------------------------------------ * CASE 3: Create New Quotation * ------------------------------------------------------ */ - $quotationData['created_by'] = $data['created_by'] ?? 0; - $quotationData['status'] = 'Accepted'; + if (empty($quotationId)) + { + $quotationData['created_by'] = $data['created_by'] ?? 0; + $quotationData['status'] = 'Accepted'; - $newQuotationId = $this->QuotationModel->insert($quotationData, true); - - - /* -------------------------------------------- - * Update Enquiry (Quotation Accepted) - * -------------------------------------------- */ - $this->EnquiryModel->update($data['enquiry_id'], [ - 'broker_id' => $data['broker_id'] ?? 0, - 'vehicle_type_id' => $data['vehicle_type_id'] ?? 0, - 'status' => 'Proposal Accepted' - ]); + $newQuotationId = $this->QuotationModel->insert($quotationData, true); + /* -------------------------------------------- + * Update Enquiry (Quotation Accepted) + * -------------------------------------------- */ + $this->EnquiryModel->update($data['enquiry_id'], [ + 'broker_id' => $data['broker_id'] ?? 0, + 'vehicle_type_id' => $data['vehicle_type_id'] ?? 0, + 'status' => 'Proposal Accepted' + ]); + } + /* ------------------------------------------------------ * If file uploaded → Create Policy * ------------------------------------------------------ */ - if ($policyPdf && $policyPdf->isValid()) { + if (empty($policyId) && $policyPdf && $policyPdf->isValid()) { $uploadDir = WRITEPATH . 'uploads/policy/policy_pdf/'; if (!is_dir($uploadDir)) {