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
+122 -1
View File
@@ -1,6 +1,8 @@
<?php
use App\Models\User;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\BillingUnitModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerContactModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -51,6 +53,125 @@ it('creates a customer with the keyboard alone', function () {
->assertScript('document.activeElement.getAttribute("wire:model")', 'form.name')
->type('[wire\\:model="form.name"]', 'Mainos Oy')
->keys('[wire\\:model="form.name"]', 'Enter')
->assertPathIs('/customers')
->assertPathBeginsWith('/customers/')
->assertSee('Asiakas Mainos Oy lisätty.');
});
it('has no accessibility issues on the customer page and the contact and billing unit forms', function (string $page, string $device, string $colorScheme) {
$customer = CustomerModel::factory()->company('0737546-2')->create(['name' => 'Mainos Oy']);
$contact = CustomerContactModel::factory()->create([
'customer_id' => $customer->id,
'name' => 'Maija Meikäläinen',
'title' => 'Markkinointipäällikkö',
'phone' => '040 123 4567',
'email' => '[email protected]',
'note' => 'Soita aamupäivisin.',
]);
$billingUnit = BillingUnitModel::factory()->eInvoice()->create(['customer_id' => $customer->id, 'name' => 'Mainos Oy, markkinointi', 'reference' => 'PO-42']);
$url = match ($page) {
'customer page' => route('customers.show', $customer->id),
'new contact' => route('customers.contacts.create', $customer->id),
'edit contact' => route('customers.contacts.edit', [$customer->id, $contact->id]),
'new billing unit' => route('customers.billing-units.create', $customer->id),
'edit billing unit' => route('customers.billing-units.edit', [$customer->id, $billingUnit->id]),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with([
'customer page',
'new contact',
'edit contact',
'new billing unit',
'edit billing unit',
])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('shows billing unit errors without accessibility issues', function (string $colorScheme) {
$customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']);
$page = visit(route('customers.billing-units.create', $customer->id));
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
$page->fill('[wire\:model="form.e_invoice_address"]', '003712345678')
->press('Tallenna')
->assertSee('Anna välittäjätunnus, koska verkkolaskuosoite on annettu.')
->assertNoAccessibilityIssues(level: 2);
})->with(['light', 'dark']);
it('removes a contact with the keyboard, in a dialog that keeps and returns focus', function (string $colorScheme) {
$customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']);
CustomerContactModel::factory()->create(['customer_id' => $customer->id, 'name' => 'Maija']);
CustomerContactModel::factory()->create(['customer_id' => $customer->id, 'name' => 'Pekka']);
$page = visit(route('customers.show', $customer->id));
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
$removeMaija = '[aria-label="Poista yhteyshenkilö Maija"]';
// Cancel: the dialog opens with focus inside it, and Escape returns focus to the button.
$page->keys($removeMaija, 'Enter')
->assertSee('Poistetaanko yhteyshenkilö Maija?')
->assertScript('document.getElementById("remove-dialog").open', true)
->assertScript('document.getElementById("remove-dialog").contains(document.activeElement)', true)
->assertNoAccessibilityIssues(level: 2)
->keys('#remove-dialog', 'Escape')
->assertScript('document.getElementById("remove-dialog").open', false)
->assertScript('document.activeElement.getAttribute("aria-label")', 'Poista yhteyshenkilö Maija');
// Confirm: the row goes away and focus moves to the section heading.
$page->keys($removeMaija, 'Enter')
->click('#remove-dialog button.bg-red-600, #remove-dialog [wire\:click="remove"]')
->assertSee('Yhteyshenkilö Maija poistettu.')
->assertDontSee('Poista yhteyshenkilö Maija')
->assertScript('document.activeElement.id', 'contacts-heading')
->assertSee('Pekka');
})->with(['light', 'dark']);
it('has no accessibility issues with a consumer\'s personal identity code', function (string $page, string $device, string $colorScheme) {
$this->actingAs(User::factory()->management()->create());
$consumer = CustomerModel::factory()->consumer()->create([
'name' => 'Maija Meikäläinen',
'personal_identity_code' => '131052-308T',
'personal_identity_code_hash' => str_repeat('a', 64),
]);
$url = match ($page) {
'customer page' => route('customers.show', $consumer->id),
'edit form' => route('customers.edit', $consumer->id),
};
$visit = visit($url);
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertSee($page === 'customer page' ? '131052-308T' : 'Poista tallennettu henkilötunnus')
->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2);
})->with(['customer page', 'edit form'])->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('shows an invalid personal identity code error without accessibility issues', function (string $colorScheme) {
$page = visit(route('customers.create'));
$page = $colorScheme === 'dark' ? $page->inDarkMode() : $page->inLightMode();
$page->fill('[wire\:model="form.name"]', 'Maija Meikäläinen')
->click('Kuluttaja')
->fill('[wire\:model="form.personal_identity_code"]', '131052-308U')
->press('Tallenna')
->assertSee('Henkilötunnus ei ole kelvollinen.')
->assertNoAccessibilityIssues(level: 2);
})->with(['light', 'dark']);