authorize('customers.use'); $summary = $customerQueries->findSummary($customer); abort_if($summary === null, 404); $this->customerId = $summary->id; $this->customerName = $summary->name; if ($billingUnit === null) { // A new billing unit is usually named after the customer. $this->form->name = $summary->name; return; } $billingUnitSummary = $customerQueries->findBillingUnit($customer, $billingUnit); abort_if($billingUnitSummary === null, 404); $this->billingUnitId = $billingUnitSummary->id; $this->form->fillFromSummary($billingUnitSummary); } public function save(AddBillingUnit $addBillingUnit, UpdateBillingUnit $updateBillingUnit): void { $this->authorize('customers.use'); $data = $this->form->toData(); try { if ($this->billingUnitId === null) { $addBillingUnit->execute($this->customerId, $data); session()->flash('status', __('customers.billing_units.created', ['name' => $data->name])); } else { $updateBillingUnit->execute($this->customerId, $this->billingUnitId, $data); session()->flash('status', __('customers.billing_units.updated', ['name' => $data->name])); } } catch (CustomerNotFound|BillingUnitNotFound) { abort(404); } catch (DomainException $exception) { $this->form->showDomainError($exception); return; } $this->redirectRoute('customers.show', $this->customerId, navigate: true); } public function render(): mixed { return $this->view()->title($this->heading().' – '.$this->customerName); } public function heading(): string { return __($this->billingUnitId === null ? 'customers.billing_units.create_title' : 'customers.billing_units.edit_title'); } }; ?>
{{ __('customers.customer_label') }}: