Add customer contacts, billing units and consumer personal identity codes

Customer page and contacts/billing units (phase 1, item 2):
- New customer page (customers.show) with details, contacts and billing
  units; add and edit on their own pages, delete after confirmation.
  Creating or editing a customer now leads to this page.
- Contacts: name, title, phone, email, note. Billing units: name,
  billing address, e-invoice address (12-35 letters/digits), operator
  (required with an e-invoice address) and reference.
- Use cases check that the row belongs to the customer, so ids in the
  URL can't reach another customer's rows.
- EmailAddress moves from Users to Shared so both modules can use it.
- <x-confirm-dialog> (native <dialog>) replaces <x-modal>, whose title,
  close button and focus handling are not accessible; solid red buttons
  use red-700 via published NormalButtonColors for 4.5:1 contrast.

Personal identity code (henkilötunnus) for consumers who are invoiced:
- Validated (date, century sign, check character), stored encrypted
  with an HMAC blind index for duplicate checks; never in
  CustomerSummary, search, logs or Livewire state.
- Admins and management see it in full and may remove it; others enter
  it and see only the masked form. The form never shows the stored code.

Spec, architecture doc and CLAUDE.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-23 18:11:06 +02:00
co-authored by Claude Opus 5.5
parent 8dfc02c4e5
commit e0b8f4970f
93 changed files with 3777 additions and 58 deletions
@@ -0,0 +1,93 @@
<?php
namespace App\Modules\Customers\Presentation\Livewire\Forms;
use App\Modules\Customers\Application\DTOs\BillingUnitData;
use App\Modules\Customers\Application\DTOs\BillingUnitSummary;
use App\Modules\Customers\Domain\Exceptions\EInvoiceOperatorRequired;
use App\Modules\Customers\Domain\Exceptions\InvalidBillingUnitName;
use App\Modules\Customers\Domain\Exceptions\InvalidEInvoiceAddress;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use Livewire\Form;
/**
* Billing unit form shared by the add and edit pages.
*/
class BillingUnitForm extends Form
{
public string $name = '';
public string $billing_address = '';
public string $e_invoice_address = '';
public string $e_invoice_operator = '';
public string $reference = '';
public function fillFromSummary(BillingUnitSummary $billingUnit): void
{
$this->name = $billingUnit->name;
$this->billing_address = $billingUnit->billingAddress ?? '';
$this->e_invoice_address = $billingUnit->eInvoiceAddress ?? '';
$this->e_invoice_operator = $billingUnit->eInvoiceOperator ?? '';
$this->reference = $billingUnit->reference ?? '';
}
public function toData(): BillingUnitData
{
$this->validate();
return BillingUnitData::fromArray([
'name' => $this->name,
'billing_address' => $this->billing_address,
'e_invoice_address' => $this->e_invoice_address,
'e_invoice_operator' => $this->e_invoice_operator,
'reference' => $this->reference,
]);
}
/**
* Shows a broken business rule as an error on the field it concerns.
*/
public function showDomainError(DomainException $exception): void
{
[$field, $key] = match ($exception::class) {
InvalidBillingUnitName::class => ['name', 'customers.errors.invalid_billing_unit_name'],
InvalidEInvoiceAddress::class => ['e_invoice_address', 'customers.errors.invalid_e_invoice_address'],
EInvoiceOperatorRequired::class => ['e_invoice_operator', 'customers.errors.e_invoice_operator_required'],
default => throw $exception,
};
$this->addError($field, __($key));
}
/**
* @return array<string, array<int, mixed>>
*/
protected function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'billing_address' => ['nullable', 'string', 'max:1000'],
'e_invoice_address' => ['nullable', 'string', 'max:50'],
'e_invoice_operator' => ['nullable', 'string', 'max:35'],
'reference' => ['nullable', 'string', 'max:255'],
];
}
/**
* @return array<string, string>
*/
protected function messages(): array
{
return [
'name.required' => __('customers.errors.billing_unit_name_required'),
'name.max' => __('customers.errors.invalid_billing_unit_name'),
'billing_address.max' => __('customers.errors.too_long', ['max' => 1000]),
'e_invoice_address.max' => __('customers.errors.invalid_e_invoice_address'),
'e_invoice_operator.max' => __('customers.errors.too_long', ['max' => 35]),
'reference.max' => __('customers.errors.too_long', ['max' => 255]),
];
}
}
@@ -0,0 +1,92 @@
<?php
namespace App\Modules\Customers\Presentation\Livewire\Forms;
use App\Modules\Customers\Application\DTOs\ContactData;
use App\Modules\Customers\Application\DTOs\ContactSummary;
use App\Modules\Customers\Domain\Exceptions\InvalidContactName;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\Shared\Domain\Exceptions\InvalidEmailAddress;
use Livewire\Form;
/**
* Contact person form shared by the add and edit pages.
*/
class ContactForm extends Form
{
public string $name = '';
public string $title = '';
public string $phone = '';
public string $email = '';
public string $note = '';
public function fillFromSummary(ContactSummary $contact): void
{
$this->name = $contact->name;
$this->title = $contact->title ?? '';
$this->phone = $contact->phone ?? '';
$this->email = $contact->email ?? '';
$this->note = $contact->note ?? '';
}
public function toData(): ContactData
{
$this->validate();
return ContactData::fromArray([
'name' => $this->name,
'title' => $this->title,
'phone' => $this->phone,
'email' => $this->email,
'note' => $this->note,
]);
}
/**
* Shows a broken business rule as an error on the field it concerns.
*/
public function showDomainError(DomainException $exception): void
{
[$field, $key] = match ($exception::class) {
InvalidContactName::class => ['name', 'customers.errors.invalid_contact_name'],
InvalidEmailAddress::class => ['email', 'customers.errors.invalid_email'],
default => throw $exception,
};
$this->addError($field, __($key));
}
/**
* @return array<string, array<int, mixed>>
*/
protected function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'title' => ['nullable', 'string', 'max:255'],
'phone' => ['nullable', 'string', 'max:50'],
'email' => ['nullable', 'string', 'email', 'max:255'],
'note' => ['nullable', 'string', 'max:2000'],
];
}
/**
* @return array<string, string>
*/
protected function messages(): array
{
return [
'name.required' => __('customers.errors.contact_name_required'),
'name.max' => __('customers.errors.invalid_contact_name'),
'title.max' => __('customers.errors.too_long', ['max' => 255]),
'phone.max' => __('customers.errors.too_long', ['max' => 50]),
'email.email' => __('customers.errors.invalid_email'),
'email.max' => __('customers.errors.invalid_email'),
'note.max' => __('customers.errors.too_long', ['max' => 2000]),
];
}
}
@@ -6,9 +6,12 @@ use App\Modules\Customers\Application\DTOs\CustomerDetailsData;
use App\Modules\Customers\Application\DTOs\CustomerSummary;
use App\Modules\Customers\Domain\Enums\CustomerType;
use App\Modules\Customers\Domain\Exceptions\BusinessIdAlreadyInUse;
use App\Modules\Customers\Domain\Exceptions\CompanyCannotHavePersonalIdentityCode;
use App\Modules\Customers\Domain\Exceptions\ConsumerCannotHaveBusinessId;
use App\Modules\Customers\Domain\Exceptions\InvalidBusinessId;
use App\Modules\Customers\Domain\Exceptions\InvalidCustomerName;
use App\Modules\Customers\Domain\Exceptions\InvalidPersonalIdentityCode;
use App\Modules\Customers\Domain\Exceptions\PersonalIdentityCodeAlreadyInUse;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use Illuminate\Validation\Rule;
use Livewire\Form;
@@ -28,6 +31,14 @@ class CustomerForm extends Form
public string $business_id = '';
/**
* A new personal identity code. Never filled from the stored code: empty
* keeps the stored one.
*/
public string $personal_identity_code = '';
public bool $remove_personal_identity_code = false;
public function fillFromSummary(CustomerSummary $customer): void
{
$this->name = $customer->name;
@@ -43,6 +54,8 @@ class CustomerForm extends Form
'name' => $this->name,
'type' => $this->type,
'business_id' => $this->type === CustomerType::Consumer->value ? null : $this->business_id,
'personal_identity_code' => $this->type === CustomerType::Consumer->value ? $this->personal_identity_code : null,
'remove_personal_identity_code' => $this->remove_personal_identity_code,
]);
}
@@ -56,6 +69,9 @@ class CustomerForm extends Form
InvalidBusinessId::class => ['business_id', 'customers.errors.invalid_business_id'],
ConsumerCannotHaveBusinessId::class => ['business_id', 'customers.errors.consumer_business_id'],
BusinessIdAlreadyInUse::class => ['business_id', 'customers.errors.business_id_taken'],
InvalidPersonalIdentityCode::class => ['personal_identity_code', 'customers.errors.invalid_personal_identity_code'],
CompanyCannotHavePersonalIdentityCode::class => ['personal_identity_code', 'customers.errors.company_personal_identity_code'],
PersonalIdentityCodeAlreadyInUse::class => ['personal_identity_code', 'customers.errors.personal_identity_code_taken'],
default => throw $exception,
};
@@ -71,6 +87,8 @@ class CustomerForm extends Form
'name' => ['required', 'string', 'max:255'],
'type' => ['required', Rule::enum(CustomerType::class)],
'business_id' => ['nullable', 'string', 'max:20'],
'personal_identity_code' => ['nullable', 'string', 'max:20'],
'remove_personal_identity_code' => ['boolean'],
];
}
@@ -85,6 +103,7 @@ class CustomerForm extends Form
'type.required' => __('customers.errors.type_required'),
'type.enum' => __('customers.errors.type_required'),
'business_id.max' => __('customers.errors.invalid_business_id'),
'personal_identity_code.max' => __('customers.errors.invalid_personal_identity_code'),
];
}
}
@@ -0,0 +1,117 @@
<?php
use App\Modules\Customers\Application\Contracts\CustomerQueries;
use App\Modules\Customers\Application\UseCases\AddBillingUnit;
use App\Modules\Customers\Application\UseCases\UpdateBillingUnit;
use App\Modules\Customers\Domain\Exceptions\BillingUnitNotFound;
use App\Modules\Customers\Domain\Exceptions\CustomerNotFound;
use App\Modules\Customers\Presentation\Livewire\Forms\BillingUnitForm;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Add page (no {billingUnit}) and edit page (with {billingUnit}) of a customer's billing unit.
*/
new class extends Component
{
#[Locked]
public int $customerId;
#[Locked]
public ?int $billingUnitId = null;
#[Locked]
public string $customerName = '';
public BillingUnitForm $form;
public function mount(CustomerQueries $customerQueries, int $customer, ?int $billingUnit = null): void
{
$this->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');
}
};
?>
<div class="mx-auto max-w-2xl space-y-6 p-4 sm:p-6">
<div class="space-y-1">
<h1 class="text-2xl font-semibold">{{ $this->heading() }}</h1>
<p class="text-sm text-zinc-600 dark:text-zinc-300">
{{ __('customers.customer_label') }}:
<x-link :href="route('customers.show', $customerId)" navigate>{{ $customerName }}</x-link>
</p>
</div>
<form wire:submit="save" class="space-y-6" novalidate>
<x-input wire:model="form.name" :label="__('customers.billing_units.fields.name')" :hint="__('customers.billing_units.fields.name_description')" autocomplete="off" required />
<x-textarea wire:model="form.billing_address" :label="__('customers.billing_units.fields.billing_address')" :hint="__('customers.billing_units.fields.billing_address_description')" resize-auto />
<x-input wire:model="form.e_invoice_address" :label="__('customers.billing_units.fields.e_invoice_address')" :hint="__('customers.billing_units.fields.e_invoice_address_description')" autocomplete="off" />
<x-input wire:model="form.e_invoice_operator" :label="__('customers.billing_units.fields.e_invoice_operator')" :hint="__('customers.billing_units.fields.e_invoice_operator_description')" autocomplete="off" />
<x-input wire:model="form.reference" :label="__('customers.billing_units.fields.reference')" :hint="__('customers.billing_units.fields.reference_description')" autocomplete="off" />
<div class="flex flex-wrap gap-3">
<x-button submit :text="__('customers.save')" />
<x-button :href="route('customers.show', $customerId)" wire:navigate subtle color="black" :text="__('customers.cancel')" />
</div>
</form>
</div>
@@ -0,0 +1,114 @@
<?php
use App\Modules\Customers\Application\Contracts\CustomerQueries;
use App\Modules\Customers\Application\UseCases\AddContact;
use App\Modules\Customers\Application\UseCases\UpdateContact;
use App\Modules\Customers\Domain\Exceptions\ContactNotFound;
use App\Modules\Customers\Domain\Exceptions\CustomerNotFound;
use App\Modules\Customers\Presentation\Livewire\Forms\ContactForm;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Add page (no {contact}) and edit page (with {contact}) of a customer's contact.
*/
new class extends Component
{
#[Locked]
public int $customerId;
#[Locked]
public ?int $contactId = null;
#[Locked]
public string $customerName = '';
public ContactForm $form;
public function mount(CustomerQueries $customerQueries, int $customer, ?int $contact = null): void
{
$this->authorize('customers.use');
$summary = $customerQueries->findSummary($customer);
abort_if($summary === null, 404);
$this->customerId = $summary->id;
$this->customerName = $summary->name;
if ($contact === null) {
return;
}
$contactSummary = $customerQueries->findContact($customer, $contact);
abort_if($contactSummary === null, 404);
$this->contactId = $contactSummary->id;
$this->form->fillFromSummary($contactSummary);
}
public function save(AddContact $addContact, UpdateContact $updateContact): void
{
$this->authorize('customers.use');
$data = $this->form->toData();
try {
if ($this->contactId === null) {
$addContact->execute($this->customerId, $data);
session()->flash('status', __('customers.contacts.created', ['name' => $data->name]));
} else {
$updateContact->execute($this->customerId, $this->contactId, $data);
session()->flash('status', __('customers.contacts.updated', ['name' => $data->name]));
}
} catch (CustomerNotFound|ContactNotFound) {
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->contactId === null ? 'customers.contacts.create_title' : 'customers.contacts.edit_title');
}
};
?>
<div class="mx-auto max-w-2xl space-y-6 p-4 sm:p-6">
<div class="space-y-1">
<h1 class="text-2xl font-semibold">{{ $this->heading() }}</h1>
<p class="text-sm text-zinc-600 dark:text-zinc-300">
{{ __('customers.customer_label') }}:
<x-link :href="route('customers.show', $customerId)" navigate>{{ $customerName }}</x-link>
</p>
</div>
<form wire:submit="save" class="space-y-6" novalidate>
<x-input wire:model="form.name" :label="__('customers.contacts.fields.name')" autocomplete="off" required />
<x-input wire:model="form.title" :label="__('customers.contacts.fields.title')" :hint="__('customers.contacts.fields.title_description')" autocomplete="off" />
<x-input wire:model="form.phone" type="tel" :label="__('customers.contacts.fields.phone')" autocomplete="off" />
<x-input wire:model="form.email" type="email" :label="__('customers.contacts.fields.email')" autocomplete="off" />
<x-textarea wire:model="form.note" :label="__('customers.contacts.fields.note')" resize-auto />
<div class="flex flex-wrap gap-3">
<x-button submit :text="__('customers.save')" />
<x-button :href="route('customers.show', $customerId)" wire:navigate subtle color="black" :text="__('customers.cancel')" />
</div>
</form>
</div>
@@ -20,6 +20,13 @@ new class extends Component
public CustomerForm $form;
/**
* The stored personal identity code, masked (e.g. ••••••-308T). The
* full code never reaches the form.
*/
#[Locked]
public ?string $storedPersonalIdentityCode = null;
public function mount(CustomerQueries $customerQueries, ?int $customer = null): void
{
$this->authorize('customers.use');
@@ -33,6 +40,7 @@ new class extends Component
abort_if($summary === null, 404);
$this->customerId = $summary->id;
$this->storedPersonalIdentityCode = $summary->personalIdentityCodeMasked;
$this->form->fillFromSummary($summary);
}
@@ -40,14 +48,19 @@ new class extends Component
{
$this->authorize('customers.use');
if ($this->form->remove_personal_identity_code) {
$this->authorize('customers.view-personal-identity-code');
}
$data = $this->form->toData();
try {
if ($this->customerId === null) {
$registerCustomer->execute($data);
$customerId = $registerCustomer->execute($data);
session()->flash('status', __('customers.created', ['name' => $data->name]));
} else {
$updateCustomer->execute($this->customerId, $data);
$customerId = $this->customerId;
session()->flash('status', __('customers.updated', ['name' => $data->name]));
}
} catch (CustomerNotFound) {
@@ -58,7 +71,8 @@ new class extends Component
return;
}
$this->redirectRoute('customers.index', navigate: true);
// The customer's page, where contacts and billing units are added.
$this->redirectRoute('customers.show', $customerId, navigate: true);
}
public function render(): mixed
@@ -95,11 +109,37 @@ new class extends Component
:hint="__('customers.fields.business_id_description')"
autocomplete="off"
/>
@else
{{-- Never filled from the stored code; type="text" because the code has letters. --}}
<x-input
wire:model="form.personal_identity_code"
:label="__('customers.fields.personal_identity_code')"
:hint="$storedPersonalIdentityCode === null
? __('customers.fields.personal_identity_code_description')
: __('customers.fields.personal_identity_code_stored', ['code' => $storedPersonalIdentityCode])"
autocomplete="off"
spellcheck="false"
/>
@if ($storedPersonalIdentityCode !== null)
@can('customers.view-personal-identity-code')
<x-checkbox
wire:model="form.remove_personal_identity_code"
:label="__('customers.fields.remove_personal_identity_code')"
/>
@endcan
@endif
@endif
<div class="flex flex-wrap gap-3">
<x-button submit :text="__('customers.save')" />
<x-button :href="route('customers.index')" wire:navigate subtle color="black" :text="__('customers.cancel')" />
<x-button
:href="$customerId === null ? route('customers.index') : route('customers.show', $customerId)"
wire:navigate
subtle
color="black"
:text="__('customers.cancel')"
/>
</div>
</form>
</div>
@@ -89,7 +89,7 @@ new class extends Component
@else
<x-table :headers="$this->headers()" :rows="$this->customers" paginate>
@interact('column_name', $customer)
<span class="font-medium">{{ $customer->name }}</span>
<x-link :href="route('customers.show', $customer->id)" navigate class="font-medium">{{ $customer->name }}</x-link>
@endinteract
@interact('column_type', $customer)
@@ -0,0 +1,357 @@
<?php
use App\Modules\Customers\Application\Contracts\CustomerQueries;
use App\Modules\Customers\Application\DTOs\BillingUnitSummary;
use App\Modules\Customers\Application\DTOs\ContactSummary;
use App\Modules\Customers\Application\DTOs\CustomerSummary;
use App\Modules\Customers\Application\UseCases\RemoveBillingUnit;
use App\Modules\Customers\Application\UseCases\RemoveContact;
use App\Modules\Customers\Domain\Exceptions\BillingUnitNotFound;
use App\Modules\Customers\Domain\Exceptions\ContactNotFound;
use App\Modules\Customers\Domain\Enums\CustomerType;
use Illuminate\Support\Facades\Gate;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* A customer's page: details, contacts and billing units.
*/
new class extends Component
{
public const string REMOVE_DIALOG = 'remove-dialog';
#[Locked]
public int $customerId;
/**
* The row the remove dialog asks about: 'contact' or 'billing_unit'.
*/
#[Locked]
public ?string $removalType = null;
#[Locked]
public ?int $removalId = null;
#[Locked]
public string $removalName = '';
public string $statusMessage = '';
protected CustomerQueries $customerQueries;
public function boot(CustomerQueries $customerQueries): void
{
$this->customerQueries = $customerQueries;
}
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;
}
/**
* @return list<ContactSummary>
*/
#[Computed]
public function contacts(): array
{
return $this->customerQueries->contactsOf($this->customerId);
}
/**
* @return list<BillingUnitSummary>
*/
#[Computed]
public function billingUnits(): array
{
return $this->customerQueries->billingUnitsOf($this->customerId);
}
/**
* Opens the remove dialog for a contact or a billing unit of this customer.
*/
public function confirmRemoval(string $type, int $id): void
{
$this->authorize('customers.use');
$name = match ($type) {
'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): void
{
$this->authorize('customers.use');
if ($this->removalType === null || $this->removalId === null) {
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');
}
// 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');
}
public function render(): mixed
{
return $this->view()->title($this->customer->name);
}
};
?>
<div class="mx-auto max-w-5xl space-y-8 p-4 sm:p-6">
<div class="space-y-4">
<div class="flex flex-wrap items-center justify-between gap-4">
<h1 class="text-2xl font-semibold break-words">{{ $this->customer->name }}</h1>
<x-button
:href="route('customers.edit', $customerId)"
wire:navigate
subtle
color="black"
icon="pencil"
:text="__('customers.edit_details')"
/>
</div>
@if (session('status'))
<x-alert role="status" color="green" light icon="check-circle" :text="session('status')" />
@endif
<dl class="grid gap-x-6 gap-y-2 text-sm sm:grid-cols-[max-content_1fr]">
<dt class="font-medium">{{ __('customers.fields.type') }}</dt>
<dd>{{ __('customers.types.'.$this->customer->type->value) }}</dd>
@if ($this->customer->businessId !== null)
<dt class="font-medium">{{ __('customers.fields.business_id') }}</dt>
<dd>{{ $this->customer->businessId }}</dd>
@endif
@if ($this->customer->type === CustomerType::Consumer)
<dt class="font-medium">{{ __('customers.fields.personal_identity_code') }}</dt>
<dd>
@if ($this->personalIdentityCode !== null)
{{ $this->personalIdentityCode }}
@else
<span class="inline-flex items-center gap-1">
<x-icon name="exclamation-triangle" class="size-4 shrink-0" aria-hidden="true" />
{{ __('customers.fields.personal_identity_code_missing') }}
</span>
@endif
</dd>
@endif
</dl>
<p role="status" aria-live="polite" class="text-sm">{{ $statusMessage }}</p>
</div>
<section aria-labelledby="contacts-heading" class="space-y-4">
<div class="flex flex-wrap items-center justify-between gap-4">
<h2 id="contacts-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">
{{ __('customers.contacts.title') }}
</h2>
<x-button
:href="route('customers.contacts.create', $customerId)"
wire:navigate
icon="plus"
:text="__('customers.contacts.new')"
/>
</div>
@if ($this->contacts === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('customers.contacts.empty') }}</p>
@else
<ul class="divide-y divide-zinc-200 rounded-lg border border-zinc-200 dark:divide-zinc-700 dark:border-zinc-700">
@foreach ($this->contacts as $contact)
<li wire:key="contact-{{ $contact->id }}" class="flex flex-wrap items-start justify-between gap-4 p-4">
<div class="min-w-0 space-y-1 text-sm">
<h3 class="text-base font-medium break-words">{{ $contact->name }}</h3>
@if ($contact->title !== null)
<p>{{ $contact->title }}</p>
@endif
@if ($contact->phone !== null)
<p>
<span class="sr-only">{{ __('customers.contacts.fields.phone') }}:</span>
<x-link :href="'tel:'.preg_replace('/[^\d+]/', '', $contact->phone)">{{ $contact->phone }}</x-link>
</p>
@endif
@if ($contact->email !== null)
<p class="break-all">
<span class="sr-only">{{ __('customers.contacts.fields.email') }}:</span>
<x-link :href="'mailto:'.$contact->email">{{ $contact->email }}</x-link>
</p>
@endif
@if ($contact->note !== null)
<p class="whitespace-pre-line text-zinc-600 dark:text-zinc-300">{{ $contact->note }}</p>
@endif
</div>
<div class="flex flex-wrap gap-2">
<x-button
:href="route('customers.contacts.edit', [$customerId, $contact->id])"
wire:navigate
subtle
color="black"
sm
icon="pencil"
:text="__('customers.edit')"
:aria-label="__('customers.contacts.edit_named', ['name' => $contact->name])"
/>
<x-button
wire:click="confirmRemoval('contact', {{ $contact->id }})"
subtle
color="black"
sm
icon="trash"
:text="__('customers.remove')"
:aria-label="__('customers.contacts.remove_named', ['name' => $contact->name])"
/>
</div>
</li>
@endforeach
</ul>
@endif
</section>
<section aria-labelledby="billing-units-heading" class="space-y-4">
<div class="flex flex-wrap items-center justify-between gap-4">
<h2 id="billing-units-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">
{{ __('customers.billing_units.title') }}
</h2>
<x-button
:href="route('customers.billing-units.create', $customerId)"
wire:navigate
icon="plus"
:text="__('customers.billing_units.new')"
/>
</div>
@if ($this->billingUnits === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('customers.billing_units.empty') }}</p>
@else
<ul class="divide-y divide-zinc-200 rounded-lg border border-zinc-200 dark:divide-zinc-700 dark:border-zinc-700">
@foreach ($this->billingUnits as $billingUnit)
<li wire:key="billing-unit-{{ $billingUnit->id }}" class="flex flex-wrap items-start justify-between gap-4 p-4">
<div class="min-w-0 space-y-1 text-sm">
<h3 class="text-base font-medium break-words">{{ $billingUnit->name }}</h3>
<dl class="grid gap-x-4 gap-y-1 sm:grid-cols-[max-content_1fr]">
@if ($billingUnit->billingAddress !== null)
<dt class="font-medium">{{ __('customers.billing_units.fields.billing_address') }}</dt>
<dd class="whitespace-pre-line">{{ $billingUnit->billingAddress }}</dd>
@endif
@if ($billingUnit->eInvoiceAddress !== null)
<dt class="font-medium">{{ __('customers.billing_units.fields.e_invoice_address') }}</dt>
<dd class="break-all">{{ $billingUnit->eInvoiceAddress }}</dd>
<dt class="font-medium">{{ __('customers.billing_units.fields.e_invoice_operator') }}</dt>
<dd class="break-all">{{ $billingUnit->eInvoiceOperator }}</dd>
@endif
@if ($billingUnit->reference !== null)
<dt class="font-medium">{{ __('customers.billing_units.fields.reference') }}</dt>
<dd class="break-words">{{ $billingUnit->reference }}</dd>
@endif
</dl>
</div>
<div class="flex flex-wrap gap-2">
<x-button
:href="route('customers.billing-units.edit', [$customerId, $billingUnit->id])"
wire:navigate
subtle
color="black"
sm
icon="pencil"
:text="__('customers.edit')"
:aria-label="__('customers.billing_units.edit_named', ['name' => $billingUnit->name])"
/>
<x-button
wire:click="confirmRemoval('billing_unit', {{ $billingUnit->id }})"
subtle
color="black"
sm
icon="trash"
:text="__('customers.remove')"
:aria-label="__('customers.billing_units.remove_named', ['name' => $billingUnit->name])"
/>
</div>
</li>
@endforeach
</ul>
@endif
</section>
<x-confirm-dialog id="remove-dialog" :title="__('customers.removal.title')">
<p>
@if ($removalType !== null)
{{ __('customers.removal.question_'.$removalType, ['name' => $removalName]) }}
@endif
</p>
<x-slot:actions>
<x-button wire:click="remove" color="red" icon="trash" :text="__('customers.remove')" />
</x-slot:actions>
</x-confirm-dialog>
</div>
@@ -8,5 +8,20 @@ Route::middleware(['web', 'auth', 'can:customers.use'])
->group(function () {
Route::livewire('/', 'customers::index')->name('index');
Route::livewire('/create', 'customers::form')->name('create');
Route::livewire('/{customer}', 'customers::show')->whereNumber('customer')->name('show');
Route::livewire('/{customer}/edit', 'customers::form')->whereNumber('customer')->name('edit');
Route::livewire('/{customer}/contacts/create', 'customers::contact-form')
->whereNumber('customer')
->name('contacts.create');
Route::livewire('/{customer}/contacts/{contact}/edit', 'customers::contact-form')
->whereNumber(['customer', 'contact'])
->name('contacts.edit');
Route::livewire('/{customer}/billing-units/create', 'customers::billing-unit-form')
->whereNumber('customer')
->name('billing-units.create');
Route::livewire('/{customer}/billing-units/{billingUnit}/edit', 'customers::billing-unit-form')
->whereNumber(['customer', 'billingUnit'])
->name('billing-units.edit');
});