feat: parties with radar, record, checks, VIES and demo data (#41)

Customers, suppliers, prospects and leads live in one parties archive
with a kind and a subject type (ADR 0029). A customer that also supplies
carries is_also_supplier, so it shows in both radars with one code.

- Three radars (/anagrafiche/clienti, /fornitori, /contatti) with search,
  quick filters and bulk disable/enable; the record has eight tabs
  (main data, addresses, contacts, terms, fiscal and SDI, banks, notes and
  attachments, history) on the MasterDataPage base.
- PartyService saves the whole record in one transaction, checks it with
  the fiscal pack (VAT number, tax code, recipient code, country), treats
  a duplicate VAT number or a consumer without tax code as warnings, fills
  the default recipient code, runs VIES after commit for EU companies, and
  converts prospects/leads (new customer code, old one kept as
  previous_code) and suppliers (become customers that also supply).
- Delete falls back to disable when the party is referenced.
- DemoPartiesSeeder adds 3 salespeople and 21 parties with fictitious but
  formally valid identifiers; SeedAsync now runs demo seeders when asked.
- Test host accepts service overrides so VIES can be stubbed.

Docs: ADR 0029, wiki Anagrafiche and demo data pages, regenerated data
model, CHANGELOG and STATUS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-12 10:06:33 +01:00
1 parent a9eda510f2
commit 3401271483
28 files changed
+4600 -85

No files matched your search

@@ -0,0 +1,203 @@
using Khaemhat.Data.Migrations;
using Khaemhat.Data.Schema;
namespace Khaemhat.Data.CompanyDatabase.Migrations;
/// <summary>
/// Parties and their details (SPEC §11.2, issue #41): addresses, contacts, bank accounts, sales and purchase terms and
/// fiscal data. The details go with the party; the company tables they point to cannot be deleted while used.
/// </summary>
[Migration(20261112_001, "create_parties")]
public sealed class M20261112_001_CreateParties : IMigration
{
/// <inheritdoc />
public void Up(ISchemaBuilder schema)
{
ArgumentNullException.ThrowIfNull(schema);
schema.CreateTable("parties", t =>
{
t.Id();
t.String("code", 30).NotNull();
t.String("previous_code", 30);
t.String("kind", 40).NotNull();
t.Bool("is_also_supplier").NotNull().Default(false);
t.String("subject_type", 40).NotNull();
t.String("name", 200).NotNull();
t.String("first_name", 80);
t.String("last_name", 80);
t.String("fiscal_name", 200);
t.String("vat_number", 30);
t.String("tax_code", 30);
t.String("rea", 20);
t.Int64("category_id");
t.String("address", 200);
t.String("street_number", 20);
t.String("postal_code", 10);
t.String("city", 100);
t.String("province", 10);
t.String("country_code", 2).NotNull();
t.String("phone", 40);
t.String("email", 200);
t.String("pec", 200);
t.String("website", 200);
t.Int64("salesperson_id");
t.String("language", 5).NotNull();
t.String("currency_code", 3).NotNull();
t.Date("since");
t.Bool("privacy_accepted").NotNull().Default(false);
t.Bool("marketing").NotNull().Default(false);
t.Text("notes");
t.String("vat_check", 40).NotNull();
t.DateTimeUtc("vat_checked_at");
t.String("customer_account_code", 20);
t.String("supplier_account_code", 20);
t.Bool("disabled").NotNull().Default(false);
t.DemoColumn();
t.AuditColumns();
t.Unique("ux_parties_code", "code");
t.Index("ix_parties_name", "name");
t.Index("ix_parties_vat_number", "vat_number");
t.Index("ix_parties_tax_code", "tax_code");
t.Index("ix_parties_kind", "kind");
t.ForeignKey("fk_parties_category", "category_id", "party_categories", ReferentialAction.Restrict);
t.ForeignKey("fk_parties_salesperson", "salesperson_id", "salespeople", ReferentialAction.Restrict);
});
schema.CreateTable("party_addresses", t =>
{
t.Id();
t.Int64("party_id").NotNull();
t.String("kind", 40).NotNull();
t.String("name", 200).NotNull();
t.String("address", 200);
t.String("street_number", 20);
t.String("postal_code", 10);
t.String("city", 100);
t.String("province", 10);
t.String("country_code", 2).NotNull();
t.Bool("is_default").NotNull().Default(false);
t.Text("notes");
t.AuditColumns();
t.Index("ix_party_addresses_party", "party_id");
t.ForeignKey("fk_party_addresses_party", "party_id", "parties", ReferentialAction.Cascade);
});
schema.CreateTable("party_contacts", t =>
{
t.Id();
t.Int64("party_id").NotNull();
t.String("name", 120).NotNull();
t.String("role", 80);
t.String("phone", 40);
t.String("mobile", 40);
t.String("email", 200);
t.Bool("is_default").NotNull().Default(false);
t.Text("notes");
t.AuditColumns();
t.Index("ix_party_contacts_party", "party_id");
t.ForeignKey("fk_party_contacts_party", "party_id", "parties", ReferentialAction.Cascade);
});
schema.CreateTable("party_bank_accounts", t =>
{
t.Id();
t.Int64("party_id").NotNull();
t.String("iban", 34).NotNull();
t.String("bic", 11);
t.String("bank_name", 100);
t.String("bank_code", 10);
t.String("branch_code", 10);
t.Bool("is_default").NotNull().Default(false);
t.AuditColumns();
t.Index("ix_party_bank_accounts_party", "party_id");
t.ForeignKey("fk_party_bank_accounts_party", "party_id", "parties", ReferentialAction.Cascade);
});
schema.CreateTable("party_sales_terms", t =>
{
t.Id();
t.Int64("party_id").NotNull();
t.Int64("price_list_id");
t.Decimal("discount1");
t.Decimal("discount2");
t.Int64("payment_term_id");
t.Int64("company_bank_account_id");
t.Int64("carrier_id");
t.Int64("shipping_term_id");
t.Int64("warehouse_id");
t.Decimal("credit_limit");
t.Bool("blocked").NotNull().Default(false);
t.Bool("group_delivery_notes").NotNull().Default(true);
t.Int32("invoice_day");
t.String("send_documents", 40).NotNull();
t.String("documents_email", 200);
t.AuditColumns();
t.Unique("ux_party_sales_terms_party", "party_id");
t.ForeignKey("fk_party_sales_terms_party", "party_id", "parties", ReferentialAction.Cascade);
t.ForeignKey("fk_party_sales_terms_price_list", "price_list_id", "price_lists", ReferentialAction.Restrict);
t.ForeignKey("fk_party_sales_terms_payment_term", "payment_term_id", "payment_terms", ReferentialAction.Restrict);
t.ForeignKey("fk_party_sales_terms_bank_account", "company_bank_account_id", "bank_accounts", ReferentialAction.Restrict);
t.ForeignKey("fk_party_sales_terms_carrier", "carrier_id", "carriers", ReferentialAction.Restrict);
t.ForeignKey("fk_party_sales_terms_shipping_term", "shipping_term_id", "shipping_terms", ReferentialAction.Restrict);
t.ForeignKey("fk_party_sales_terms_warehouse", "warehouse_id", "warehouses", ReferentialAction.Restrict);
});
schema.CreateTable("party_purchase_terms", t =>
{
t.Id();
t.Int64("party_id").NotNull();
t.Int64("payment_term_id");
t.Int32("lead_time_days");
t.Decimal("minimum_order");
t.Decimal("discount");
t.Int64("shipping_term_id");
t.String("vat_register_code", 10);
t.String("cost_account_code", 20);
t.String("orders_email", 200);
t.AuditColumns();
t.Unique("ux_party_purchase_terms_party", "party_id");
t.ForeignKey("fk_party_purchase_terms_party", "party_id", "parties", ReferentialAction.Cascade);
t.ForeignKey("fk_party_purchase_terms_payment_term", "payment_term_id", "payment_terms", ReferentialAction.Restrict);
t.ForeignKey("fk_party_purchase_terms_shipping_term", "shipping_term_id", "shipping_terms", ReferentialAction.Restrict);
});
schema.CreateTable("party_fiscal", t =>
{
t.Id();
t.Int64("party_id").NotNull();
t.String("recipient_code", 7);
t.String("recipient_pec", 200);
t.String("administration_reference", 20);
t.Bool("attach_pdf").NotNull().Default(true);
t.Bool("send_copy").NotNull().Default(false);
t.Bool("split_payment").NotNull().Default(false);
t.Bool("reverse_charge").NotNull().Default(false);
t.Int64("tax_code_id");
t.String("exigibility", 1);
t.Bool("stamp_duty_charged").NotNull().Default(true);
t.Bool("withholding").NotNull().Default(false);
t.Decimal("withholding_rate");
t.String("withholding_reason", 4);
t.String("pension_fund", 4);
t.Decimal("pension_fund_rate");
t.Bool("enasarco").NotNull().Default(false);
t.Bool("intent_active").NotNull().Default(false);
t.String("intent_number", 40);
t.Date("intent_date");
t.String("intent_protocol", 40);
t.Int64("intent_tax_code_id");
t.Decimal("intent_ceiling");
t.Decimal("intent_used").NotNull().Default(0m);
t.Date("intent_from");
t.Date("intent_to");
t.String("gln", 13);
t.String("eori", 17);
t.String("our_code", 40);
t.AuditColumns();
t.Unique("ux_party_fiscal_party", "party_id");
t.ForeignKey("fk_party_fiscal_party", "party_id", "parties", ReferentialAction.Cascade);
t.ForeignKey("fk_party_fiscal_tax_code", "tax_code_id", "tax_codes", ReferentialAction.Restrict);
t.ForeignKey("fk_party_fiscal_intent_tax_code", "intent_tax_code_id", "tax_codes", ReferentialAction.Restrict);
});
}
}
@@ -0,0 +1,129 @@
using Khaemhat.Core.Parties;
using Khaemhat.Data.Mapping;
namespace Khaemhat.Data.CompanyDatabase;
/// <summary>Map of <see cref="Party"/> to <c>parties</c>.</summary>
public sealed class PartyMap : EntityMap<Party>
{
/// <summary>Creates the map.</summary>
public PartyMap()
{
ToTable("parties");
Map(x => x.Code).MaxLength(30);
Map(x => x.PreviousCode).MaxLength(30);
Map(x => x.Name).MaxLength(200);
Map(x => x.FirstName).MaxLength(80);
Map(x => x.LastName).MaxLength(80);
Map(x => x.FiscalName).MaxLength(200);
Map(x => x.VatNumber).MaxLength(30);
Map(x => x.TaxCode).MaxLength(30);
Map(x => x.Rea).MaxLength(20);
Map(x => x.Address).MaxLength(200);
Map(x => x.StreetNumber).MaxLength(20);
Map(x => x.PostalCode).MaxLength(10);
Map(x => x.City).MaxLength(100);
Map(x => x.Province).MaxLength(10);
Map(x => x.CountryCode).MaxLength(2);
Map(x => x.Phone).MaxLength(40);
Map(x => x.Email).MaxLength(200);
Map(x => x.Pec).MaxLength(200);
Map(x => x.Website).MaxLength(200);
Map(x => x.Language).MaxLength(5);
Map(x => x.CurrencyCode).MaxLength(3);
Map(x => x.CustomerAccountCode).MaxLength(20);
Map(x => x.SupplierAccountCode).MaxLength(20);
}
}
/// <summary>Map of <see cref="PartyAddress"/> to <c>party_addresses</c>.</summary>
public sealed class PartyAddressMap : EntityMap<PartyAddress>
{
/// <summary>Creates the map.</summary>
public PartyAddressMap()
{
ToTable("party_addresses");
Map(x => x.Name).MaxLength(200);
Map(x => x.Address).MaxLength(200);
Map(x => x.StreetNumber).MaxLength(20);
Map(x => x.PostalCode).MaxLength(10);
Map(x => x.City).MaxLength(100);
Map(x => x.Province).MaxLength(10);
Map(x => x.CountryCode).MaxLength(2);
}
}
/// <summary>Map of <see cref="PartyContact"/> to <c>party_contacts</c>.</summary>
public sealed class PartyContactMap : EntityMap<PartyContact>
{
/// <summary>Creates the map.</summary>
public PartyContactMap()
{
ToTable("party_contacts");
Map(x => x.Name).MaxLength(120);
Map(x => x.Role).MaxLength(80);
Map(x => x.Phone).MaxLength(40);
Map(x => x.Mobile).MaxLength(40);
Map(x => x.Email).MaxLength(200);
}
}
/// <summary>Map of <see cref="PartyBankAccount"/> to <c>party_bank_accounts</c>.</summary>
public sealed class PartyBankAccountMap : EntityMap<PartyBankAccount>
{
/// <summary>Creates the map.</summary>
public PartyBankAccountMap()
{
ToTable("party_bank_accounts");
Map(x => x.Iban).MaxLength(34);
Map(x => x.Bic).MaxLength(11);
Map(x => x.BankName).MaxLength(100);
Map(x => x.BankCode).MaxLength(10);
Map(x => x.BranchCode).MaxLength(10);
}
}
/// <summary>Map of <see cref="PartySalesTerms"/> to <c>party_sales_terms</c>.</summary>
public sealed class PartySalesTermsMap : EntityMap<PartySalesTerms>
{
/// <summary>Creates the map.</summary>
public PartySalesTermsMap()
{
ToTable("party_sales_terms");
Map(x => x.DocumentsEmail).MaxLength(200);
}
}
/// <summary>Map of <see cref="PartyPurchaseTerms"/> to <c>party_purchase_terms</c>.</summary>
public sealed class PartyPurchaseTermsMap : EntityMap<PartyPurchaseTerms>
{
/// <summary>Creates the map.</summary>
public PartyPurchaseTermsMap()
{
ToTable("party_purchase_terms");
Map(x => x.VatRegisterCode).MaxLength(10);
Map(x => x.CostAccountCode).MaxLength(20);
Map(x => x.OrdersEmail).MaxLength(200);
}
}
/// <summary>Map of <see cref="PartyFiscal"/> to <c>party_fiscal</c>.</summary>
public sealed class PartyFiscalMap : EntityMap<PartyFiscal>
{
/// <summary>Creates the map.</summary>
public PartyFiscalMap()
{
ToTable("party_fiscal");
Map(x => x.RecipientCode).MaxLength(7);
Map(x => x.RecipientPec).MaxLength(200);
Map(x => x.AdministrationReference).MaxLength(20);
Map(x => x.Exigibility).MaxLength(1);
Map(x => x.WithholdingReason).MaxLength(4);
Map(x => x.PensionFund).MaxLength(4);
Map(x => x.IntentNumber).MaxLength(40);
Map(x => x.IntentProtocol).MaxLength(40);
Map(x => x.Gln).MaxLength(13);
Map(x => x.Eori).MaxLength(17);
Map(x => x.OurCode).MaxLength(40);
}
}