From 9ed31be17e8f0fd7135b969957b943a57fd05dbb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 28 Jul 2020 14:29:56 +1000 Subject: [PATCH] remove legacy setting option --- app/DataMapper/CompanySettings.php | 2 - app/Http/Controllers/InvoiceController.php | 3 ++ .../OpenAPI/CompanySettingsSchema.php | 2 +- app/Models/Invoice.php | 37 +++++++++++++------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 65c98a14a3c5..2ee72347d74b 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -25,7 +25,6 @@ class CompanySettings extends BaseSettings /*Invoice*/ public $auto_archive_invoice = false; - public $lock_sent_invoices = false; public $lock_invoices = 'off'; //off,when_sent,when_paid @@ -391,7 +390,6 @@ class CompanySettings extends BaseSettings 'show_currency_code' => 'bool', 'send_reminders' => 'bool', 'enable_client_portal_tasks' => 'bool', - 'lock_sent_invoices' => 'bool', 'auto_archive_invoice' => 'bool', 'auto_archive_quote' => 'bool', 'auto_convert_quote' => 'bool', diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 8033d1ad1923..e9e3cf6bcb61 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -392,6 +392,9 @@ class InvoiceController extends BaseController return $request->disallowUpdate(); } + if($invoice->isLocked()) + return response()->json(['message' => 'Invoice is locked, no modifications allowed']); + $invoice = $this->invoice_repo->save($request->all(), $invoice); event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars())); diff --git a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php index 893c6cb7454d..fe19347cc086 100644 --- a/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php +++ b/app/Http/Controllers/OpenAPI/CompanySettingsSchema.php @@ -30,7 +30,7 @@ * @OA\Property(property="custom_message_unpaid_invoice", type="string", example="Please pay invoices immediately", description="____________"), * @OA\Property(property="custom_message_paid_invoice", type="string", example="Thanks for paying this invoice!", description="____________"), * @OA\Property(property="custom_message_unapproved_quote", type="string", example="Please approve quote", description="____________"), - * @OA\Property(property="lock_sent_invoices", type="boolean", example=true, description="____________"), + * @OA\Property(property="lock_invoices", type="boolean", example=true, description="____________"), * @OA\Property(property="auto_archive_invoice", type="boolean", example=true, description="____________"), * @OA\Property(property="auto_archive_quote", type="boolean", example=true, description="____________"), * @OA\Property(property="auto_convert_quote", type="boolean", example=true, description="____________"), diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 4006e4a1f868..590bd9fcff92 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -266,17 +266,6 @@ class Invoice extends BaseModel } } - /** - * If True, prevents an invoice from being - * modified once it has been marked as sent - * - * @return boolean isLocked - */ - public function isLocked(): bool - { - return $this->client->getSetting('lock_sent_invoices'); - } - public function isPayable(): bool { if($this->status_id == Invoice::STATUS_DRAFT && $this->is_deleted == false){ @@ -437,6 +426,32 @@ class Invoice extends BaseModel }); } + /** + * Filtering logic to determine + * whether an invoice is locked + * based on the current status of the invoice + * @return boolean [description] + */ + public function isLocked() :bool + { + $locked_status = $this->client->getSetting('lock_invoices'); + + switch ($locked_status) { + case 'off': + return false; + break; + case 'when_sent': + return $this->status_id == self::STATUS_DRAFT; + break; + case 'when_paid': + return $this->status_id == self::STATUS_PAID || $this->status_id == self::STATUS_PARTIAL; + break; + default: + return false; + break; + } + } + /* Graveyard */ // /**