diff --git a/app/Controllers/InvoiceController.php b/app/Controllers/InvoiceController.php index a0d4dc6..1bee73e 100644 --- a/app/Controllers/InvoiceController.php +++ b/app/Controllers/InvoiceController.php @@ -123,8 +123,10 @@ class InvoiceController extends ResourceController $invoiceId = $this->InvoiceModel->insert($invoiceData); - if (!$invoiceId) { throw new DataException("Failed to create invoice"); } - + if ($invoiceId === false) { + log_message('error', json_encode($this->InvoiceModel->errors())); + return $this->respond(['status' => 'failed', 'message' => 'Failed to create invoice', 'error' => json_encode($this->InvoiceModel->errors())], 500); + } } else { // Invoice number should NOT change on update diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index fcd4002..f6e3d11 100644 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -36,9 +36,8 @@ class InvoiceModel extends Model // Validation (optional) protected $validationRules = [ - 'invoice_no' => 'required|max_length[100]', + 'invoice_no' => 'required', 'invoice_amount' => 'decimal', - 'agent_id' => 'required|integer', 'invoice_date' => 'required|valid_date', ];