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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user