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:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\BillingUnitModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<BillingUnitModel>
|
||||
*/
|
||||
class BillingUnitFactory extends Factory
|
||||
{
|
||||
protected $model = BillingUnitModel::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'customer_id' => CustomerModel::factory(),
|
||||
'name' => fake()->company(),
|
||||
'billing_address' => fake()->streetAddress()."\n".fake()->postcode().' '.fake()->city(),
|
||||
'e_invoice_address' => null,
|
||||
'e_invoice_operator' => null,
|
||||
'reference' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function eInvoice(string $address = '003712345678', string $operator = '003721291126'): static
|
||||
{
|
||||
return $this->state(fn (): array => [
|
||||
'e_invoice_address' => $address,
|
||||
'e_invoice_operator' => $operator,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerContactModel;
|
||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<CustomerContactModel>
|
||||
*/
|
||||
class CustomerContactFactory extends Factory
|
||||
{
|
||||
protected $model = CustomerContactModel::class;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'customer_id' => CustomerModel::factory(),
|
||||
'name' => fake()->name(),
|
||||
'title' => fake()->optional()->jobTitle(),
|
||||
'phone' => fake()->optional()->phoneNumber(),
|
||||
'email' => fake()->optional()->safeEmail(),
|
||||
'note' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('customer_contacts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('customer_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->string('title')->nullable();
|
||||
$table->string('phone', 50)->nullable();
|
||||
$table->string('email')->nullable();
|
||||
$table->text('note')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('customer_contacts');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('billing_units', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('customer_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('name');
|
||||
$table->text('billing_address')->nullable();
|
||||
$table->string('e_invoice_address', 35)->nullable();
|
||||
$table->string('e_invoice_operator', 35)->nullable();
|
||||
$table->string('reference')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('billing_units');
|
||||
}
|
||||
};
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* A consumer's personal identity code, encrypted with the app key, and a
|
||||
* keyed hash of it (blind index) so duplicates can be found without
|
||||
* decrypting every row.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
$table->text('personal_identity_code')->nullable()->after('business_id');
|
||||
$table->char('personal_identity_code_hash', 64)->nullable()->unique()->after('personal_identity_code');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('customers', function (Blueprint $table) {
|
||||
$table->dropUnique(['personal_identity_code_hash']);
|
||||
$table->dropColumn(['personal_identity_code', 'personal_identity_code_hash']);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user