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
@@ -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'),
];
}
}