From e0b8f4970fc1fb06da60a9c1acfaed562fe729e3 Mon Sep 17 00:00:00 2001 From: Petri Saarinen Date: Mon, 23 Nov 2026 18:11:06 +0200 Subject: [PATCH] Add customer contacts, billing units and consumer personal identity codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. - (native ) replaces , 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 --- CLAUDE.md | 5 +- .../Application/Contracts/CustomerQueries.php | 32 ++ .../Application/DTOs/BillingUnitData.php | 35 ++ .../Application/DTOs/BillingUnitSummary.php | 21 + .../Application/DTOs/ContactData.php | 35 ++ .../Application/DTOs/ContactSummary.php | 21 + .../Application/DTOs/CustomerDetailsData.php | 10 +- .../Application/DTOs/CustomerSummary.php | 10 + .../Application/UseCases/AddBillingUnit.php | 50 +++ .../Application/UseCases/AddContact.php | 48 +++ .../Application/UseCases/RegisterCustomer.php | 12 +- .../UseCases/RemoveBillingUnit.php | 34 ++ .../Application/UseCases/RemoveContact.php | 34 ++ .../UseCases/UpdateBillingUnit.php | 40 ++ .../Application/UseCases/UpdateContact.php | 38 ++ .../Application/UseCases/UpdateCustomer.php | 20 +- .../Contracts/BillingUnitRepository.php | 23 ++ .../Contracts/CustomerContactRepository.php | 23 ++ .../Domain/Contracts/CustomerRepository.php | 3 + .../Customers/Domain/Entities/BillingUnit.php | 139 +++++++ .../Customers/Domain/Entities/Customer.php | 65 ++- .../Domain/Entities/CustomerContact.php | 98 +++++ .../Domain/Entities/OptionalText.php | 20 + .../Domain/Exceptions/BillingUnitNotFound.php | 18 + .../CompanyCannotHavePersonalIdentityCode.php | 15 + .../Domain/Exceptions/ContactNotFound.php | 18 + .../Exceptions/EInvoiceOperatorRequired.php | 15 + .../Exceptions/InvalidBillingUnitName.php | 15 + .../Domain/Exceptions/InvalidContactName.php | 15 + .../Exceptions/InvalidEInvoiceAddress.php | 15 + .../InvalidPersonalIdentityCode.php | 18 + .../PersonalIdentityCodeAlreadyInUse.php | 18 + .../Domain/ValueObjects/BillingUnitName.php | 28 ++ .../Domain/ValueObjects/ContactName.php | 28 ++ .../Domain/ValueObjects/EInvoiceAddress.php | 27 ++ .../ValueObjects/PersonalIdentityCode.php | 65 +++ .../Persistence/Eloquent/BillingUnitModel.php | 31 ++ .../Eloquent/CustomerContactModel.php | 31 ++ .../Persistence/Eloquent/CustomerModel.php | 7 +- .../PersonalIdentityCodeHasher.php | 28 ++ .../EloquentBillingUnitRepository.php | 55 +++ .../EloquentCustomerContactRepository.php | 55 +++ .../Repositories/EloquentCustomerQueries.php | 72 +++- .../EloquentCustomerRepository.php | 15 + .../Providers/CustomersServiceProvider.php | 13 + .../Livewire/Forms/BillingUnitForm.php | 93 +++++ .../Livewire/Forms/ContactForm.php | 92 +++++ .../Livewire/Forms/CustomerForm.php | 19 + .../Livewire/⚡billing-unit-form.blade.php | 117 ++++++ .../Livewire/⚡contact-form.blade.php | 114 ++++++ .../Presentation/Livewire/⚡form.blade.php | 46 ++- .../Presentation/Livewire/⚡index.blade.php | 2 +- .../Presentation/Livewire/⚡show.blade.php | 357 +++++++++++++++++ .../Customers/Presentation/Routes/web.php | 15 + .../Domain/Exceptions/InvalidEmailAddress.php | 4 +- .../Domain/ValueObjects/EmailAddress.php | 8 +- .../Contracts/PasswordLinkSender.php | 2 +- .../UseCases/CreateUserAccount.php | 2 +- .../UseCases/RequestPasswordReset.php | 2 +- .../UseCases/UpdateUserAccount.php | 2 +- .../Contracts/UserAccountRepository.php | 2 +- .../Users/Domain/Entities/UserAccount.php | 2 +- .../Auth/LaravelPasswordLinkSender.php | 2 +- .../EloquentUserAccountRepository.php | 2 +- .../Presentation/Livewire/Forms/UserForm.php | 2 +- .../Livewire/⚡forgot-password.blade.php | 2 +- .../TallStackUi/Colors/NormalButtonColors.php | 377 ++++++++++++++++++ database/factories/BillingUnitFactory.php | 38 ++ database/factories/CustomerContactFactory.php | 30 ++ ..._155038_create_customer_contacts_table.php | 33 ++ ...1_23_155039_create_billing_units_table.php | 33 ++ ...sonal_identity_code_to_customers_table.php | 32 ++ docs/architecture.md | 3 +- docs/maarittely.md | 20 +- lang/fi/customers.php | 74 +++- lang/fi/layout.php | 1 + .../views/components/confirm-dialog.blade.php | 41 ++ tests/Browser/CustomersAccessibilityTest.php | 123 +++++- tests/Fakes/FakePasswordLinkSender.php | 2 +- tests/Fakes/InMemoryBillingUnitRepository.php | 46 +++ .../InMemoryCustomerContactRepository.php | 46 +++ tests/Fakes/InMemoryCustomerRepository.php | 14 +- tests/Fakes/InMemoryUserAccountRepository.php | 2 +- .../Customers/ContactsAndBillingUnitsTest.php | 186 +++++++++ .../Modules/Customers/CustomerPagesTest.php | 4 +- .../Customers/PersonalIdentityCodeTest.php | 146 +++++++ .../ContactAndBillingUnitUseCasesTest.php | 104 +++++ .../PersonalIdentityCodeUseCasesTest.php | 50 +++ .../Domain/ContactAndBillingUnitTest.php | 58 +++ .../Domain/PersonalIdentityCodeTest.php | 59 +++ .../Application/UserAccountUseCasesTest.php | 2 +- .../Modules/Users/Domain/UserAccountTest.php | 2 +- .../Modules/Users/Domain/ValueObjectsTest.php | 4 +- 93 files changed, 3777 insertions(+), 58 deletions(-) create mode 100644 app/Modules/Customers/Application/DTOs/BillingUnitData.php create mode 100644 app/Modules/Customers/Application/DTOs/BillingUnitSummary.php create mode 100644 app/Modules/Customers/Application/DTOs/ContactData.php create mode 100644 app/Modules/Customers/Application/DTOs/ContactSummary.php create mode 100644 app/Modules/Customers/Application/UseCases/AddBillingUnit.php create mode 100644 app/Modules/Customers/Application/UseCases/AddContact.php create mode 100644 app/Modules/Customers/Application/UseCases/RemoveBillingUnit.php create mode 100644 app/Modules/Customers/Application/UseCases/RemoveContact.php create mode 100644 app/Modules/Customers/Application/UseCases/UpdateBillingUnit.php create mode 100644 app/Modules/Customers/Application/UseCases/UpdateContact.php create mode 100644 app/Modules/Customers/Domain/Contracts/BillingUnitRepository.php create mode 100644 app/Modules/Customers/Domain/Contracts/CustomerContactRepository.php create mode 100644 app/Modules/Customers/Domain/Entities/BillingUnit.php create mode 100644 app/Modules/Customers/Domain/Entities/CustomerContact.php create mode 100644 app/Modules/Customers/Domain/Entities/OptionalText.php create mode 100644 app/Modules/Customers/Domain/Exceptions/BillingUnitNotFound.php create mode 100644 app/Modules/Customers/Domain/Exceptions/CompanyCannotHavePersonalIdentityCode.php create mode 100644 app/Modules/Customers/Domain/Exceptions/ContactNotFound.php create mode 100644 app/Modules/Customers/Domain/Exceptions/EInvoiceOperatorRequired.php create mode 100644 app/Modules/Customers/Domain/Exceptions/InvalidBillingUnitName.php create mode 100644 app/Modules/Customers/Domain/Exceptions/InvalidContactName.php create mode 100644 app/Modules/Customers/Domain/Exceptions/InvalidEInvoiceAddress.php create mode 100644 app/Modules/Customers/Domain/Exceptions/InvalidPersonalIdentityCode.php create mode 100644 app/Modules/Customers/Domain/Exceptions/PersonalIdentityCodeAlreadyInUse.php create mode 100644 app/Modules/Customers/Domain/ValueObjects/BillingUnitName.php create mode 100644 app/Modules/Customers/Domain/ValueObjects/ContactName.php create mode 100644 app/Modules/Customers/Domain/ValueObjects/EInvoiceAddress.php create mode 100644 app/Modules/Customers/Domain/ValueObjects/PersonalIdentityCode.php create mode 100644 app/Modules/Customers/Infrastructure/Persistence/Eloquent/BillingUnitModel.php create mode 100644 app/Modules/Customers/Infrastructure/Persistence/Eloquent/CustomerContactModel.php create mode 100644 app/Modules/Customers/Infrastructure/Persistence/PersonalIdentityCodeHasher.php create mode 100644 app/Modules/Customers/Infrastructure/Persistence/Repositories/EloquentBillingUnitRepository.php create mode 100644 app/Modules/Customers/Infrastructure/Persistence/Repositories/EloquentCustomerContactRepository.php create mode 100644 app/Modules/Customers/Presentation/Livewire/Forms/BillingUnitForm.php create mode 100644 app/Modules/Customers/Presentation/Livewire/Forms/ContactForm.php create mode 100644 app/Modules/Customers/Presentation/Livewire/⚡billing-unit-form.blade.php create mode 100644 app/Modules/Customers/Presentation/Livewire/⚡contact-form.blade.php create mode 100644 app/Modules/Customers/Presentation/Livewire/⚡show.blade.php rename app/Modules/{Users => Shared}/Domain/Exceptions/InvalidEmailAddress.php (65%) rename app/Modules/{Users => Shared}/Domain/ValueObjects/EmailAddress.php (69%) create mode 100644 app/View/Components/TallStackUi/Colors/NormalButtonColors.php create mode 100644 database/factories/BillingUnitFactory.php create mode 100644 database/factories/CustomerContactFactory.php create mode 100644 database/migrations/2026_11_23_155038_create_customer_contacts_table.php create mode 100644 database/migrations/2026_11_23_155039_create_billing_units_table.php create mode 100644 database/migrations/2026_11_23_160551_add_personal_identity_code_to_customers_table.php create mode 100644 resources/views/components/confirm-dialog.blade.php create mode 100644 tests/Fakes/InMemoryBillingUnitRepository.php create mode 100644 tests/Fakes/InMemoryCustomerContactRepository.php create mode 100644 tests/Feature/Modules/Customers/ContactsAndBillingUnitsTest.php create mode 100644 tests/Feature/Modules/Customers/PersonalIdentityCodeTest.php create mode 100644 tests/Unit/Modules/Customers/Application/ContactAndBillingUnitUseCasesTest.php create mode 100644 tests/Unit/Modules/Customers/Application/PersonalIdentityCodeUseCasesTest.php create mode 100644 tests/Unit/Modules/Customers/Domain/ContactAndBillingUnitTest.php create mode 100644 tests/Unit/Modules/Customers/Domain/PersonalIdentityCodeTest.php diff --git a/CLAUDE.md b/CLAUDE.md index 8ebf5ba..bdaf1db 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -38,12 +38,15 @@ Accessibility is a contractual acceptance criterion. It covers the whole UI: nav - ``: unnamed `role="switch"`. Use `resources/views/partials/theme-toggle.blade.php`, which drives `tallstackui_darkTheme({ default: 'system' })` on `` (localStorage `dark-theme`; an inline script in the layout applies it before paint). - ``: root-relative asset URLs that 404 in a subfolder (local XAMPP). The layout includes `resources/views/partials/tallstackui-script.blade.php` instead. - ``: the label is not tied to the control, so also pass `:aria-label` with the same text. + - ``: `aria-labelledby` points at an id its title lacks, the close button has no name, and focus neither moves in nor returns. Use `` (`resources/views/components/confirm-dialog.blade.php`, native `` + `showModal()`), opened from Livewire with `$this->js("document.getElementById('').showModal()")`; see `customers::show`. + - Solid `color="red"` buttons: white on red-500 is 3.5:1, so the solid red is red-700 in the published `NormalButtonColors`. - `` without `wire:model` (e.g. a read-only value): pass an explicit `id`, or the label is not tied to it. `` has an unlabelled input and a button whose name changes; build copy fields from `` + `` + a `role="status"` message instead (see `users::form`). - Contrast: the primary palette is one step darker (`resources/css/app.css`); error text, label error and asterisk, and input/select error colours are changed by soft customization in `App\Providers\AppServiceProvider`; light alert and link text colours are in published colour classes `app/View/Components/TallStackUi/Colors/`. `flat` and `outline` buttons have no dark-mode text colour: use `subtle color="black"` for neutral buttons. - Finnish strings for TallStackUI's own components are in `lang/vendor/ts-ui/fi/messages.php`. +- **Personal identity codes** (*henkilötunnus*, consumer customers) are sensitive personal data: stored encrypted (`encrypted` cast, `$hidden`) with an HMAC blind index for duplicates, never in `CustomerSummary`, search, logs, exception messages or Livewire public properties, and shown in full only behind `customers.view-personal-identity-code` (admin, management) via `CustomerQueries::personalIdentityCodeOf()`; everyone else sees `masked()`. - Never convey meaning by colour alone. Statuses, priorities (e.g. *kiire* = red), errors and warnings always also have visible text or an icon with text. - Announce dynamic changes: put status text in `role="status"` / `aria-live="polite"` (errors: `role="alert"`), or a TallStackUI toast (`` must then be added to the layout). Keep button names stable instead of putting changing state in them. -- Make everything work with the keyboard alone, with a visible focus indicator and no focus traps. Use `` for dialogs and check that focus moves in and returns. +- Make everything work with the keyboard alone, with a visible focus indicator and no focus traps. Use `` for dialogs (not ``, see above) and check that focus moves in and returns. - The layout (`resources/views/layouts/app.blade.php`) provides a skip link and a `
` landmark. Keep them, and add `