authorize('customers.manage'); $customer = Customer::query()->where('uuid', $uuid)->firstOrFail(); $this->customerUuid = $uuid; $this->customerName = (string) $customer->name; $this->refusal = WithdrawalRight::for($this->contractOf($customer))->refusal; } public function record(): void { $this->authorize('customers.manage'); $customer = Customer::query()->where('uuid', $this->customerUuid)->firstOrFail(); $contract = $this->contractOf($customer); if ($contract === null) { $this->refusal = __('withdrawal.refusal_no_contract'); return; } try { app(WithdrawContract::class)( $contract, WithdrawContract::CHANNEL_OPERATOR, // Who took it. Part of the evidence that a declaration was made // at all — a refund with nobody's name against it is the one an // auditor asks about. auth('operator')->user(), ); } catch (RuntimeException $e) { $this->refusal = $e->getMessage(); return; } $this->dispatch('notify', message: __('withdrawal.recorded', ['name' => $this->customerName])); $this->closeModal(); } private function contractOf(Customer $customer): ?Subscription { return app(CustomDomainAccess::class)->contractOf($customer); } public function render() { $customer = Customer::query()->where('uuid', $this->customerUuid)->first(); $contract = $customer === null ? null : $this->contractOf($customer); return view('livewire.admin.record-withdrawal', [ 'right' => WithdrawalRight::for($contract), // How long the cloud has been running. Nothing is charged for it — // the refund is the whole amount — but it is the first thing an // operator is asked on the telephone. 'deliveredDays' => $contract === null ? 0 : WithdrawalRight::deliveredDays($contract), 'termDays' => $contract === null ? 0 : WithdrawalRight::termDays($contract), ]); } }