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>
476 lines
16 KiB
C#
476 lines
16 KiB
C#
using Khaemhat.Core.Entities;
|
|
|
|
namespace Khaemhat.Core.Parties;
|
|
|
|
/// <summary>What a party is to the company (SPEC §11.2): the archive and the code mask follow from it.</summary>
|
|
public enum PartyKind
|
|
{
|
|
/// <summary>A customer (it may also be a supplier).</summary>
|
|
Customer = 0,
|
|
|
|
/// <summary>A supplier that is not a customer.</summary>
|
|
Supplier = 1,
|
|
|
|
/// <summary>A qualified potential customer, without fiscal documents.</summary>
|
|
Prospect = 2,
|
|
|
|
/// <summary>A commercial contact still to qualify (CRM).</summary>
|
|
Lead = 3,
|
|
}
|
|
|
|
/// <summary>The kind of subject: it decides the checks and the values proposed (SDI code, split payment, VAT number).</summary>
|
|
public enum SubjectType
|
|
{
|
|
/// <summary>A domestic business.</summary>
|
|
Company = 0,
|
|
|
|
/// <summary>A private person (consumer).</summary>
|
|
Person = 1,
|
|
|
|
/// <summary>A public administration (split payment, office code of 6 characters).</summary>
|
|
PublicAdministration = 2,
|
|
|
|
/// <summary>A business in another EU member state (VIES).</summary>
|
|
EuCompany = 3,
|
|
|
|
/// <summary>A business outside the EU.</summary>
|
|
NonEuCompany = 4,
|
|
|
|
/// <summary>A domestic business under the flat-rate scheme (no VAT charged, stamp duty).</summary>
|
|
FlatRate = 5,
|
|
}
|
|
|
|
/// <summary>The outcome of the last check of the VAT number on VIES, saved on the party.</summary>
|
|
public enum VatCheckStatus
|
|
{
|
|
/// <summary>Not checked.</summary>
|
|
None = 0,
|
|
|
|
/// <summary>Registered for intra-EU operations.</summary>
|
|
Valid = 1,
|
|
|
|
/// <summary>Not registered.</summary>
|
|
Invalid = 2,
|
|
|
|
/// <summary>The service could not answer; to repeat.</summary>
|
|
Unavailable = 3,
|
|
}
|
|
|
|
/// <summary>How the documents are sent to a customer.</summary>
|
|
public enum DocumentDelivery
|
|
{
|
|
/// <summary>Not sent: printed or downloaded.</summary>
|
|
None = 0,
|
|
|
|
/// <summary>By e-mail.</summary>
|
|
Email = 1,
|
|
|
|
/// <summary>By certified e-mail (PEC).</summary>
|
|
Pec = 2,
|
|
}
|
|
|
|
/// <summary>What an address of a party is used for.</summary>
|
|
public enum PartyAddressKind
|
|
{
|
|
/// <summary>Delivery address (destination of delivery notes).</summary>
|
|
Delivery = 0,
|
|
|
|
/// <summary>Address for invoices, when different from the registered office.</summary>
|
|
Billing = 1,
|
|
|
|
/// <summary>A building site or a branch.</summary>
|
|
Site = 2,
|
|
|
|
/// <summary>Another address.</summary>
|
|
Other = 3,
|
|
}
|
|
|
|
/// <summary>
|
|
/// A party (SPEC §11.2, wiki <i>Anagrafiche</i>): customer, supplier, prospect or lead, registered once. The code follows
|
|
/// the mask of its kind (ADR 0027); converting a lead or prospect into a customer gives it a customer code and keeps the
|
|
/// old one in <see cref="PreviousCode"/>.
|
|
/// </summary>
|
|
public sealed class Party : Entity<long>, IDemoMarkable
|
|
{
|
|
/// <summary>The code, unique among the parties.</summary>
|
|
public string Code { get; set; } = string.Empty;
|
|
|
|
/// <summary>The code it had before a conversion.</summary>
|
|
public string? PreviousCode { get; set; }
|
|
|
|
/// <summary>What the party is.</summary>
|
|
public PartyKind Kind { get; set; }
|
|
|
|
/// <summary>A customer that also sells to the company.</summary>
|
|
public bool IsAlsoSupplier { get; set; }
|
|
|
|
/// <summary>The kind of subject.</summary>
|
|
public SubjectType SubjectType { get; set; }
|
|
|
|
/// <summary>The business name, or "last name first name" for a person.</summary>
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
/// <summary>The first name of a person.</summary>
|
|
public string? FirstName { get; set; }
|
|
|
|
/// <summary>The last name of a person.</summary>
|
|
public string? LastName { get; set; }
|
|
|
|
/// <summary>The name on fiscal documents, when different.</summary>
|
|
public string? FiscalName { get; set; }
|
|
|
|
/// <summary>The VAT number, compact, without the country prefix.</summary>
|
|
public string? VatNumber { get; set; }
|
|
|
|
/// <summary>The tax code.</summary>
|
|
public string? TaxCode { get; set; }
|
|
|
|
/// <summary>The registration in the companies register (REA).</summary>
|
|
public string? Rea { get; set; }
|
|
|
|
/// <summary>The category (<c>party_categories</c>).</summary>
|
|
public long? CategoryId { get; set; }
|
|
|
|
/// <summary>Street of the registered office.</summary>
|
|
public string? Address { get; set; }
|
|
|
|
/// <summary>Street number.</summary>
|
|
public string? StreetNumber { get; set; }
|
|
|
|
/// <summary>Postal code.</summary>
|
|
public string? PostalCode { get; set; }
|
|
|
|
/// <summary>Municipality or city.</summary>
|
|
public string? City { get; set; }
|
|
|
|
/// <summary>Province abbreviation (or region abroad).</summary>
|
|
public string? Province { get; set; }
|
|
|
|
/// <summary>Country (ISO 3166-1 alpha-2).</summary>
|
|
public string CountryCode { get; set; } = "IT";
|
|
|
|
/// <summary>Phone.</summary>
|
|
public string? Phone { get; set; }
|
|
|
|
/// <summary>E-mail.</summary>
|
|
public string? Email { get; set; }
|
|
|
|
/// <summary>Certified e-mail (PEC).</summary>
|
|
public string? Pec { get; set; }
|
|
|
|
/// <summary>Web site.</summary>
|
|
public string? Website { get; set; }
|
|
|
|
/// <summary>The salesperson (<c>salespeople</c>).</summary>
|
|
public long? SalespersonId { get; set; }
|
|
|
|
/// <summary>Language of the documents (ISO 639-1).</summary>
|
|
public string Language { get; set; } = "it";
|
|
|
|
/// <summary>Currency of the documents (ISO 4217).</summary>
|
|
public string CurrencyCode { get; set; } = "EUR";
|
|
|
|
/// <summary>Start of the relationship.</summary>
|
|
public DateOnly? Since { get; set; }
|
|
|
|
/// <summary>Privacy notice accepted.</summary>
|
|
public bool PrivacyAccepted { get; set; }
|
|
|
|
/// <summary>Consent to marketing.</summary>
|
|
public bool Marketing { get; set; }
|
|
|
|
/// <summary>Notes.</summary>
|
|
public string? Notes { get; set; }
|
|
|
|
/// <summary>Last VIES outcome.</summary>
|
|
public VatCheckStatus VatCheck { get; set; }
|
|
|
|
/// <summary>When VIES answered (or failed), UTC.</summary>
|
|
public DateTime? VatCheckedAt { get; set; }
|
|
|
|
/// <summary>The customer sub-account of the ledger, created at the first posting (M7).</summary>
|
|
public string? CustomerAccountCode { get; set; }
|
|
|
|
/// <summary>The supplier sub-account of the ledger, created at the first posting (M7).</summary>
|
|
public string? SupplierAccountCode { get; set; }
|
|
|
|
/// <summary>Hidden from new documents and default searches; kept with its documents.</summary>
|
|
public bool Disabled { get; set; }
|
|
|
|
/// <inheritdoc />
|
|
public bool IsDemo { get; set; }
|
|
|
|
/// <summary>Whether the party is a customer (also a supplier that is a customer).</summary>
|
|
public bool IsCustomer => Kind == PartyKind.Customer;
|
|
|
|
/// <summary>Whether the party is a supplier, alone or also a customer.</summary>
|
|
public bool IsSupplier => Kind == PartyKind.Supplier || (Kind == PartyKind.Customer && IsAlsoSupplier);
|
|
}
|
|
|
|
/// <summary>An address of a party besides the registered office.</summary>
|
|
public sealed class PartyAddress : Entity<long>
|
|
{
|
|
/// <summary>The party.</summary>
|
|
public long PartyId { get; set; }
|
|
|
|
/// <summary>What it is used for.</summary>
|
|
public PartyAddressKind Kind { get; set; }
|
|
|
|
/// <summary>The name shown on documents (site, branch).</summary>
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
/// <summary>Street.</summary>
|
|
public string? Address { get; set; }
|
|
|
|
/// <summary>Street number.</summary>
|
|
public string? StreetNumber { get; set; }
|
|
|
|
/// <summary>Postal code.</summary>
|
|
public string? PostalCode { get; set; }
|
|
|
|
/// <summary>City.</summary>
|
|
public string? City { get; set; }
|
|
|
|
/// <summary>Province.</summary>
|
|
public string? Province { get; set; }
|
|
|
|
/// <summary>Country (ISO 3166-1 alpha-2).</summary>
|
|
public string CountryCode { get; set; } = "IT";
|
|
|
|
/// <summary>The address proposed first for its kind.</summary>
|
|
public bool IsDefault { get; set; }
|
|
|
|
/// <summary>Notes (opening hours, how to reach it).</summary>
|
|
public string? Notes { get; set; }
|
|
}
|
|
|
|
/// <summary>A contact person of a party.</summary>
|
|
public sealed class PartyContact : Entity<long>
|
|
{
|
|
/// <summary>The party.</summary>
|
|
public long PartyId { get; set; }
|
|
|
|
/// <summary>Name and surname.</summary>
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
/// <summary>Role (purchasing, administration...).</summary>
|
|
public string? Role { get; set; }
|
|
|
|
/// <summary>Phone.</summary>
|
|
public string? Phone { get; set; }
|
|
|
|
/// <summary>Mobile phone.</summary>
|
|
public string? Mobile { get; set; }
|
|
|
|
/// <summary>E-mail.</summary>
|
|
public string? Email { get; set; }
|
|
|
|
/// <summary>The main contact.</summary>
|
|
public bool IsDefault { get; set; }
|
|
|
|
/// <summary>Notes.</summary>
|
|
public string? Notes { get; set; }
|
|
}
|
|
|
|
/// <summary>A bank account of a party: the bank of its RiBa, or where the company pays it.</summary>
|
|
public sealed class PartyBankAccount : Entity<long>
|
|
{
|
|
/// <summary>The party.</summary>
|
|
public long PartyId { get; set; }
|
|
|
|
/// <summary>The IBAN, compact.</summary>
|
|
public string Iban { get; set; } = string.Empty;
|
|
|
|
/// <summary>The BIC.</summary>
|
|
public string? Bic { get; set; }
|
|
|
|
/// <summary>The bank.</summary>
|
|
public string? BankName { get; set; }
|
|
|
|
/// <summary>The national bank code (ABI), read from the IBAN.</summary>
|
|
public string? BankCode { get; set; }
|
|
|
|
/// <summary>The branch code (CAB), read from the IBAN.</summary>
|
|
public string? BranchCode { get; set; }
|
|
|
|
/// <summary>The account proposed on documents.</summary>
|
|
public bool IsDefault { get; set; }
|
|
}
|
|
|
|
/// <summary>The sales terms of a customer, proposed on its documents (M5).</summary>
|
|
public sealed class PartySalesTerms : Entity<long>
|
|
{
|
|
/// <summary>The party (one row per party).</summary>
|
|
public long PartyId { get; set; }
|
|
|
|
/// <summary>The price list (<c>price_lists</c>).</summary>
|
|
public long? PriceListId { get; set; }
|
|
|
|
/// <summary>First discount, percent.</summary>
|
|
public decimal? Discount1 { get; set; }
|
|
|
|
/// <summary>Second discount, percent.</summary>
|
|
public decimal? Discount2 { get; set; }
|
|
|
|
/// <summary>The payment terms (<c>payment_terms</c>).</summary>
|
|
public long? PaymentTermId { get; set; }
|
|
|
|
/// <summary>The account of the company where the customer pays (<c>bank_accounts</c>).</summary>
|
|
public long? CompanyBankAccountId { get; set; }
|
|
|
|
/// <summary>The carrier (<c>carriers</c>).</summary>
|
|
public long? CarrierId { get; set; }
|
|
|
|
/// <summary>The shipping terms (<c>shipping_terms</c>).</summary>
|
|
public long? ShippingTermId { get; set; }
|
|
|
|
/// <summary>The warehouse goods leave from (<c>warehouses</c>).</summary>
|
|
public long? WarehouseId { get; set; }
|
|
|
|
/// <summary>The credit limit: the most the customer may owe.</summary>
|
|
public decimal? CreditLimit { get; set; }
|
|
|
|
/// <summary>Orders and deliveries are blocked.</summary>
|
|
public bool Blocked { get; set; }
|
|
|
|
/// <summary>Delivery notes are grouped into one deferred invoice.</summary>
|
|
public bool GroupDeliveryNotes { get; set; } = true;
|
|
|
|
/// <summary>The day of the month the deferred invoices are issued, if fixed.</summary>
|
|
public int? InvoiceDay { get; set; }
|
|
|
|
/// <summary>How the documents are sent.</summary>
|
|
public DocumentDelivery SendDocuments { get; set; }
|
|
|
|
/// <summary>Where the documents are sent, when not the main e-mail or PEC.</summary>
|
|
public string? DocumentsEmail { get; set; }
|
|
}
|
|
|
|
/// <summary>The purchase terms of a supplier, proposed on its orders (M6).</summary>
|
|
public sealed class PartyPurchaseTerms : Entity<long>
|
|
{
|
|
/// <summary>The party (one row per party).</summary>
|
|
public long PartyId { get; set; }
|
|
|
|
/// <summary>The payment terms (<c>payment_terms</c>).</summary>
|
|
public long? PaymentTermId { get; set; }
|
|
|
|
/// <summary>Days between order and delivery.</summary>
|
|
public int? LeadTimeDays { get; set; }
|
|
|
|
/// <summary>The smallest order accepted.</summary>
|
|
public decimal? MinimumOrder { get; set; }
|
|
|
|
/// <summary>Discount, percent.</summary>
|
|
public decimal? Discount { get; set; }
|
|
|
|
/// <summary>The shipping terms (<c>shipping_terms</c>).</summary>
|
|
public long? ShippingTermId { get; set; }
|
|
|
|
/// <summary>The VAT register of the purchases (M7).</summary>
|
|
public string? VatRegisterCode { get; set; }
|
|
|
|
/// <summary>The cost account proposed (M7).</summary>
|
|
public string? CostAccountCode { get; set; }
|
|
|
|
/// <summary>The e-mail for the orders.</summary>
|
|
public string? OrdersEmail { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// The fiscal data of a party (mockup 015, 016): e-invoicing, VAT regime, withholding and contributions, the declaration
|
|
/// of intent of a habitual exporter and the identifiers.
|
|
/// </summary>
|
|
public sealed class PartyFiscal : Entity<long>
|
|
{
|
|
/// <summary>The party (one row per party).</summary>
|
|
public long PartyId { get; set; }
|
|
|
|
/// <summary>The SDI recipient code (7 characters, 6 for a public administration).</summary>
|
|
public string? RecipientCode { get; set; }
|
|
|
|
/// <summary>The PEC the e-invoices go to, without a recipient code.</summary>
|
|
public string? RecipientPec { get; set; }
|
|
|
|
/// <summary>The reference of the administration (public administrations).</summary>
|
|
public string? AdministrationReference { get; set; }
|
|
|
|
/// <summary>A courtesy PDF goes with the e-invoice.</summary>
|
|
public bool AttachPdf { get; set; } = true;
|
|
|
|
/// <summary>A copy is sent by e-mail when the invoice is issued.</summary>
|
|
public bool SendCopy { get; set; }
|
|
|
|
/// <summary>Split payment (art. 17-ter DPR 633/72).</summary>
|
|
public bool SplitPayment { get; set; }
|
|
|
|
/// <summary>Reverse charge by default.</summary>
|
|
public bool ReverseCharge { get; set; }
|
|
|
|
/// <summary>The VAT code proposed (<c>tax_codes</c>).</summary>
|
|
public long? TaxCodeId { get; set; }
|
|
|
|
/// <summary>VAT exigibility: <c>I</c> immediate, <c>D</c> deferred, <c>S</c> split payment.</summary>
|
|
public string? Exigibility { get; set; }
|
|
|
|
/// <summary>The stamp duty is charged to the customer.</summary>
|
|
public bool StampDutyCharged { get; set; } = true;
|
|
|
|
/// <summary>Subject to withholding tax (professionals).</summary>
|
|
public bool Withholding { get; set; }
|
|
|
|
/// <summary>Withholding rate, percent.</summary>
|
|
public decimal? WithholdingRate { get; set; }
|
|
|
|
/// <summary>Withholding reason of the e-invoice (A, M, Q...).</summary>
|
|
public string? WithholdingReason { get; set; }
|
|
|
|
/// <summary>Pension fund of the e-invoice (TC01-TC22).</summary>
|
|
public string? PensionFund { get; set; }
|
|
|
|
/// <summary>Pension fund rate, percent.</summary>
|
|
public decimal? PensionFundRate { get; set; }
|
|
|
|
/// <summary>Agent subject to ENASARCO.</summary>
|
|
public bool Enasarco { get; set; }
|
|
|
|
/// <summary>Declaration of intent active.</summary>
|
|
public bool IntentActive { get; set; }
|
|
|
|
/// <summary>Number of the declaration.</summary>
|
|
public string? IntentNumber { get; set; }
|
|
|
|
/// <summary>Date of the declaration.</summary>
|
|
public DateOnly? IntentDate { get; set; }
|
|
|
|
/// <summary>Protocol of the revenue agency.</summary>
|
|
public string? IntentProtocol { get; set; }
|
|
|
|
/// <summary>The non-taxable VAT code used under the declaration (<c>tax_codes</c>, nature N3.5).</summary>
|
|
public long? IntentTaxCodeId { get; set; }
|
|
|
|
/// <summary>The ceiling of the declaration.</summary>
|
|
public decimal? IntentCeiling { get; set; }
|
|
|
|
/// <summary>The amount already invoiced under the declaration (updated by the invoices, M5).</summary>
|
|
public decimal IntentUsed { get; set; }
|
|
|
|
/// <summary>The declaration is valid from.</summary>
|
|
public DateOnly? IntentFrom { get; set; }
|
|
|
|
/// <summary>The declaration is valid until.</summary>
|
|
public DateOnly? IntentTo { get; set; }
|
|
|
|
/// <summary>Global location number.</summary>
|
|
public string? Gln { get; set; }
|
|
|
|
/// <summary>Economic operators registration and identification number (customs).</summary>
|
|
public string? Eori { get; set; }
|
|
|
|
/// <summary>The code of the company at the party.</summary>
|
|
public string? OurCode { get; set; }
|
|
|
|
/// <summary>What remains of the ceiling of the declaration.</summary>
|
|
public decimal? IntentRemaining => IntentCeiling is { } ceiling ? ceiling - IntentUsed : null;
|
|
}
|