expires_at || $service->expires_at->isPast()) { $service->update(['status' => 'cancelled', 'cancelled_at' => now(), 'auto_renew' => false]); return self::IMMEDIATE; } $service->update(['cancel_at_expiry' => true, 'auto_renew' => false]); return self::SCHEDULED; } public static function finalize(Service $service): void { $service->update(['status' => 'cancelled', 'cancelled_at' => now()]); if ($service->vm_id) { dispatch(new VMJobs((int) $service->vm_id, 'PowerOff', false)); } } private static function voidOpenRenewalInvoices(Service $service): void { $orderId = $service->orderItem?->order_id; if (! $orderId) { return; } Invoice::where('order_id', $orderId) ->where('invoice_type', 2) ->whereIn('status', [InvoiceStatus::UNPAID->value, InvoiceStatus::OVERDUE->value]) ->where(fn ($query) => $query->whereNull('amount_paid')->orWhere('amount_paid', 0)) ->get() ->each(fn (Invoice $invoice) => $invoice->update(['status' => InvoiceStatus::CANCELLED->value])); } }