customerQueries = $customerQueries; $this->customerRemoval = $customerRemoval; } public function mount(int $customer): void { $this->authorize('customers.use'); abort_if($this->customerQueries->findSummary($customer) === null, 404); $this->customerId = $customer; } #[Computed] public function customer(): CustomerSummary { return $this->customerQueries->findSummary($this->customerId) ?? abort(404); } /** * The personal identity code as this user may see it: in full for admins * and management, masked for others. Computed, so the full code is never * kept in the component state sent to the browser. */ #[Computed] public function personalIdentityCode(): ?string { if (Gate::allows('customers.view-personal-identity-code')) { return $this->customerQueries->personalIdentityCodeOf($this->customerId); } return $this->customer->personalIdentityCodeMasked; } /** * Whether nothing is linked to this customer, so the remove button is shown. */ #[Computed] public function canBeRemoved(): bool { return $this->customerRemoval->canRemove($this->customerId); } /** * @return list */ #[Computed] public function contacts(): array { return $this->customerQueries->contactsOf($this->customerId); } /** * @return list */ #[Computed] public function billingUnits(): array { return $this->customerQueries->billingUnitsOf($this->customerId); } /** * Opens the remove dialog for this customer, or for one of its contacts * or billing units. */ public function confirmRemoval(string $type, int $id): void { $this->authorize('customers.use'); $name = match ($type) { 'customer' => $id === $this->customerId ? $this->customerQueries->findSummary($id)?->name : null, 'contact' => $this->customerQueries->findContact($this->customerId, $id)?->name, 'billing_unit' => $this->customerQueries->findBillingUnit($this->customerId, $id)?->name, default => null, }; if ($name === null) { $this->statusMessage = __('customers.removal.already_removed'); return; } $this->removalType = $type; $this->removalId = $id; $this->removalName = $name; $this->statusMessage = ''; $this->js("document.getElementById('".self::REMOVE_DIALOG."').showModal()"); } public function remove(RemoveContact $removeContact, RemoveBillingUnit $removeBillingUnit, RemoveCustomer $removeCustomer): void { $this->authorize('customers.use'); if ($this->removalType === null || $this->removalId === null) { return; } if ($this->removalType === 'customer') { $this->removeCustomer($removeCustomer); return; } try { match ($this->removalType) { 'contact' => $removeContact->execute($this->customerId, $this->removalId), 'billing_unit' => $removeBillingUnit->execute($this->customerId, $this->removalId), }; $this->statusMessage = __('customers.removal.removed_'.$this->removalType, ['name' => $this->removalName]); } catch (ContactNotFound|BillingUnitNotFound) { $this->statusMessage = __('customers.removal.already_removed'); } catch (ContactInUse|BillingUnitInUse) { $this->statusMessage = __('customers.removal.in_use_'.$this->removalType, ['name' => $this->removalName]); } // The removed row's button is gone, so focus moves to its section heading. $heading = $this->removalType === 'contact' ? 'contacts-heading' : 'billing-units-heading'; $this->js("document.getElementById('".self::REMOVE_DIALOG."').close(); document.getElementById('{$heading}').focus()"); $this->reset('removalType', 'removalId', 'removalName'); } /** * Removes this customer and returns to the customer list, or tells why * it was kept and moves focus back to the page heading. */ private function removeCustomer(RemoveCustomer $removeCustomer): void { try { $removeCustomer->execute($this->customerId); session()->flash('status', __('customers.removal.removed_customer', ['name' => $this->removalName])); $this->redirectRoute('customers.index', navigate: true); return; } catch (CustomerNotFound) { $this->statusMessage = __('customers.removal.already_removed'); } catch (InternalCustomerCannotBeRemoved) { $this->statusMessage = __('customers.removal.internal_customer'); } catch (CustomerInUse) { $this->statusMessage = __('customers.removal.in_use_customer', ['name' => $this->removalName]); } $this->js("document.getElementById('".self::REMOVE_DIALOG."').close(); document.getElementById('customer-heading').focus()"); $this->reset('removalType', 'removalId', 'removalName'); } public function render(): mixed { return $this->view()->title($this->customer->name); } }; ?>
{{ $this->customer->name }}
@if ($this->canBeRemoved) @endif
@if (session('status')) @endif
{{ __('customers.fields.type') }}
{{ __('customers.types.'.$this->customer->type->value) }} @if ($this->customer->isInternal) – {{ __('customers.internal') }}. {{ __('customers.internal_description') }} @endif
@if ($this->customer->businessId !== null)
{{ __('customers.fields.business_id') }}
{{ $this->customer->businessId }}
@endif @if ($this->customer->type === CustomerType::Consumer)
{{ __('customers.fields.personal_identity_code') }}
@if ($this->personalIdentityCode !== null) {{ $this->personalIdentityCode }} @else @endif
@endif

{{ $statusMessage }}

{{ __('customers.contacts.title') }}

@if ($this->contacts === []) {{ __('customers.contacts.empty') }} @else
    @foreach ($this->contacts as $contact)
  • {{ $contact->name }}

    @if ($contact->title !== null)

    {{ $contact->title }}

    @endif @if ($contact->phone !== null)

    {{ __('customers.contacts.fields.phone') }}: {{ $contact->phone }}

    @endif @if ($contact->email !== null)

    {{ __('customers.contacts.fields.email') }}: {{ $contact->email }}

    @endif @if ($contact->note !== null)

    {{ $contact->note }}

    @endif
  • @endforeach
@endif

{{ __('customers.billing_units.title') }}

@if ($this->billingUnits === []) {{ __('customers.billing_units.empty') }} @else
    @foreach ($this->billingUnits as $billingUnit)
  • {{ $billingUnit->name }}

    @if ($billingUnit->billingAddress !== null)
    {{ __('customers.billing_units.fields.billing_address') }}
    {{ $billingUnit->billingAddress }}
    @endif @if ($billingUnit->eInvoiceAddress !== null)
    {{ __('customers.billing_units.fields.e_invoice_address') }}
    {{ $billingUnit->eInvoiceAddress }}
    {{ __('customers.billing_units.fields.e_invoice_operator') }}
    {{ $billingUnit->eInvoiceOperator }}
    @endif @if ($billingUnit->reference !== null)
    {{ __('customers.billing_units.fields.reference') }}
    {{ $billingUnit->reference }}
    @endif
  • @endforeach
@endif

@if ($removalType !== null) {{ __('customers.removal.question_'.$removalType, ['name' => $removalName]) }} @endif