From 654bf7a23f5907687e6ed0892920cce409267da5 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 27 Apr 2022 09:05:16 +1000 Subject: [PATCH] Disable gateway refund options for GoCardless --- app/DataMapper/CompanySettings.php | 2 ++ app/Http/Controllers/ClientController.php | 2 ++ app/Http/Controllers/InvoiceController.php | 2 ++ app/Import/Providers/BaseImport.php | 2 -- app/Models/Gateway.php | 2 +- app/Repositories/PaymentRepository.php | 2 +- app/Services/Invoice/HandleCancellation.php | 2 ++ app/Services/Invoice/InvoiceService.php | 13 +++++++++++++ 8 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index ec223897bdd0..ac89c714a27e 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -271,8 +271,10 @@ class CompanySettings extends BaseSettings public $use_credits_payment = 'off'; //always, option, off //@implemented public $hide_empty_columns_on_pdf = false; public $email_from_name = ''; + public $auto_archive_invoice_cancelled = false; public static $casts = [ + 'auto_archive_invoice_cancelled' => 'bool', 'email_from_name' => 'string', 'show_all_tasks_client_portal' => 'string', 'entity_send_time' => 'int', diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index ce6ed40da855..0026090298bb 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -107,6 +107,8 @@ class ClientController extends BaseController */ public function index(ClientFilters $filters) { + set_time_limit(45); + $clients = Client::filter($filters); return $this->listResponse($clients); diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 51ad55d86ab7..8694695d7fde 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -119,6 +119,8 @@ class InvoiceController extends BaseController */ public function index(InvoiceFilters $filters) { + set_time_limit(45); + $invoices = Invoice::filter($filters); return $this->listResponse($invoices); diff --git a/app/Import/Providers/BaseImport.php b/app/Import/Providers/BaseImport.php index 4f11b0fbb503..1ccc17f1e80e 100644 --- a/app/Import/Providers/BaseImport.php +++ b/app/Import/Providers/BaseImport.php @@ -569,8 +569,6 @@ class BaseImport 'company' => $this->company, ]; -nlog($this->company->company_users); - $nmo = new NinjaMailerObject; $nmo->mailable = new ImportCompleted($this->company, $data); $nmo->company = $this->company; diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 5f214de0ce4b..706e5b7045fd 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -159,7 +159,7 @@ class Gateway extends StaticModel break; case 52: return [ - GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']], // GoCardless + GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], // GoCardless GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], GatewayType::SEPA => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], GatewayType::INSTANT_BANK_PAY => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 651737fd8393..51cd2e09a4f3 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -186,7 +186,7 @@ class PaymentRepository extends BaseRepository { TransactionLog::dispatch(TransactionEvent::PAYMENT_MADE, $transaction, $payment->company->db); - return $payment->fresh(); + return $payment->refresh(); } /** diff --git a/app/Services/Invoice/HandleCancellation.php b/app/Services/Invoice/HandleCancellation.php index fb93aca67ac7..9f2a450634a4 100644 --- a/app/Services/Invoice/HandleCancellation.php +++ b/app/Services/Invoice/HandleCancellation.php @@ -52,6 +52,8 @@ class HandleCancellation extends AbstractService //adjust client balance $this->invoice->client->service()->updateBalance($adjustment)->save(); + $this->invoice->service()->workFlow()->save(); + event(new InvoiceWasCancelled($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); $transaction = [ diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index e91ae43aa5b5..622387322253 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -546,6 +546,19 @@ class InvoiceService event(new InvoiceWasArchived($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + } + + if ($this->invoice->status_id == Invoice::STATUS_CANCELLED && $this->invoice->client->getSetting('auto_archive_invoice_cancelled')) { + /* Throws: Payment amount xxx does not match invoice totals. */ + + if ($this->invoice->trashed()) + return $this; + + $this->invoice->delete(); + + event(new InvoiceWasArchived($this->invoice, $this->invoice->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); + + } return $this;