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]>
59 lines
3.0 KiB
PHP
59 lines
3.0 KiB
PHP
<?php
|
|
|
|
use App\Modules\Customers\Domain\Entities\BillingUnit;
|
|
use App\Modules\Customers\Domain\Entities\CustomerContact;
|
|
use App\Modules\Customers\Domain\Exceptions\EInvoiceOperatorRequired;
|
|
use App\Modules\Customers\Domain\Exceptions\InvalidBillingUnitName;
|
|
use App\Modules\Customers\Domain\Exceptions\InvalidContactName;
|
|
use App\Modules\Customers\Domain\Exceptions\InvalidEInvoiceAddress;
|
|
use App\Modules\Customers\Domain\ValueObjects\BillingUnitName;
|
|
use App\Modules\Customers\Domain\ValueObjects\ContactName;
|
|
use App\Modules\Customers\Domain\ValueObjects\EInvoiceAddress;
|
|
|
|
it('normalises an e-invoice address', function (string $input, string $expected) {
|
|
expect((new EInvoiceAddress($input))->value)->toBe($expected);
|
|
})->with([
|
|
'OVT with spaces' => ['0037 1234 5678', '003712345678'],
|
|
'IBAN in lower case' => ['fi49 5000 9420 0287 30', 'FI4950009420028730'],
|
|
]);
|
|
|
|
it('rejects an e-invoice address that is too short or has other characters', function (string $input) {
|
|
new EInvoiceAddress($input);
|
|
})->throws(InvalidEInvoiceAddress::class)->with(['00371234', '0037-1234-5678', '', str_repeat('1', 36)]);
|
|
|
|
it('rejects an empty or too long contact or billing unit name', function (string $class, string $exception, string $name) {
|
|
expect(fn () => new $class($name))->toThrow($exception);
|
|
})->with([
|
|
'contact, empty' => [ContactName::class, InvalidContactName::class, ' '],
|
|
'contact, too long' => [ContactName::class, InvalidContactName::class, str_repeat('a', 256)],
|
|
'billing unit, empty' => [BillingUnitName::class, InvalidBillingUnitName::class, ''],
|
|
'billing unit, too long' => [BillingUnitName::class, InvalidBillingUnitName::class, str_repeat('a', 256)],
|
|
]);
|
|
|
|
it('stores empty optional contact fields as none', function () {
|
|
$contact = CustomerContact::create(1, new ContactName('Maija Meikäläinen'), ' ', '', null, " Soita aamulla \n");
|
|
|
|
expect($contact->title())->toBeNull()
|
|
->and($contact->phone())->toBeNull()
|
|
->and($contact->note())->toBe('Soita aamulla');
|
|
});
|
|
|
|
it('requires an operator for an e-invoice address', function () {
|
|
BillingUnit::create(1, new BillingUnitName('Mainos Oy'), null, new EInvoiceAddress('003712345678'), ' ');
|
|
})->throws(EInvoiceOperatorRequired::class);
|
|
|
|
it('requires an operator when an e-invoice address is added later', function () {
|
|
$billingUnit = BillingUnit::create(1, new BillingUnitName('Mainos Oy'), "Katu 1\n00100 Helsinki");
|
|
|
|
expect(fn () => $billingUnit->changeDetails(new BillingUnitName('Mainos Oy'), null, new EInvoiceAddress('003712345678'), null, null))
|
|
->toThrow(EInvoiceOperatorRequired::class)
|
|
->and($billingUnit->eInvoiceAddress())->toBeNull()
|
|
->and($billingUnit->billingAddress())->toBe("Katu 1\n00100 Helsinki");
|
|
});
|
|
|
|
it('normalises the operator code', function () {
|
|
$billingUnit = BillingUnit::create(1, new BillingUnitName('Mainos Oy'), null, new EInvoiceAddress('003712345678'), ' ndea fihh ');
|
|
|
|
expect($billingUnit->eInvoiceOperator())->toBe('NDEAFIHH');
|
|
});
|