From a2e94bb27ef763743401a36ddfcf062b0e1af633 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 9 Dec 2022 08:31:22 +1100 Subject: [PATCH] Disable auto billing on recurring invoices and generated invoices if disabled in client portal --- app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php b/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php index 8170fbf12d66..548521dddfc6 100644 --- a/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php +++ b/app/Http/Livewire/RecurringInvoices/UpdateAutoBilling.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire\RecurringInvoices; +use App\Models\Invoice; use Livewire\Component; class UpdateAutoBilling extends Component @@ -24,6 +25,12 @@ class UpdateAutoBilling extends Component if ($this->invoice->auto_bill == 'optin' || $this->invoice->auto_bill == 'optout') { $this->invoice->auto_bill_enabled = ! $this->invoice->auto_bill_enabled; $this->invoice->saveQuietly(); + + Invoice::where('recurring_id', $this->invoice->id) + ->whereIn('status_id', [2,3]) + ->where('is_deleted',0) + ->where('balance', '>', 0) + ->update(['auto_bill_enabled' => $this->invoice->auto_bill_enabled]); } }