feat: company tables, profile, fiscal years and base data (#38, #39, #45)

Adds the company tables of SPEC 11.1 behind one generic service so that every
table gets the same rules, history, cache and CSV import/export, plus the
company profile, fiscal years with monthly lock and the base-data seeder.

- 26 coded tables, exchange rates, company profile, fiscal years and periods:
  entities, maps and migrations 010-014
- TableService + TableCatalog: unique codes, per-table rules (VAT codes are
  checked by the fiscal pack), delete or disable when in use, single default,
  CSV export/import all-or-nothing, cache with cross-instance invalidation
- CompanyProfileService (Italian identifiers through the pack),
  FiscalYearService with the date check used by every dated record
- EcbRatesClient and the ECB rates system task; CsvReader
- ISeeder/SeedRunner with the data version in company settings; base tables
  from the pack (IBaseTablesTemplate) and an embedded ISO country list

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 22:33:37 +01:00
1 parent 25f8a7ad30
commit 34e196424f
33 files changed
+6049 -3

No files matched your search

+180
View File
@@ -0,0 +1,180 @@
using Khaemhat.Core.Entities;
using Khaemhat.Core.Tax;
namespace Khaemhat.Core.Tables;
/// <summary>The data of the company itself, one row per company database (SPEC §11.1, mockup 075).</summary>
public sealed class CompanyProfile : Entity<long>
{
/// <summary>The company name.</summary>
public string LegalName { get; set; } = string.Empty;
/// <summary>The name written on fiscal documents, when different.</summary>
public string? FiscalName { get; set; }
/// <summary>The VAT number, without the country prefix.</summary>
public string? VatNumber { get; set; }
/// <summary>The tax code.</summary>
public string? TaxCode { get; set; }
/// <summary>The province of the business register (REA).</summary>
public string? ReaOffice { get; set; }
/// <summary>The number in the business register (REA).</summary>
public string? ReaNumber { get; set; }
/// <summary>The share capital.</summary>
public decimal? ShareCapital { get; set; }
/// <summary>Sole shareholder: <c>SU</c> one, <c>SM</c> more; empty when it does not apply.</summary>
public string? Shareholders { get; set; }
/// <summary>Liquidation: <c>LN</c> not in liquidation, <c>LS</c> in liquidation.</summary>
public string? LiquidationStatus { get; set; }
/// <summary>The street.</summary>
public string? Address { get; set; }
/// <summary>The street number.</summary>
public string? StreetNumber { get; set; }
/// <summary>The postal code.</summary>
public string? PostalCode { get; set; }
/// <summary>The town.</summary>
public string? City { get; set; }
/// <summary>The province abbreviation.</summary>
public string? ProvinceCode { get; set; }
/// <summary>The country of the address (ISO 3166-1).</summary>
public string? AddressCountry { get; set; }
/// <summary>The phone.</summary>
public string? Phone { get; set; }
/// <summary>The e-mail address.</summary>
public string? Email { get; set; }
/// <summary>The certified e-mail address.</summary>
public string? Pec { get; set; }
/// <summary>The web site.</summary>
public string? Website { get; set; }
/// <summary>The tax regime, such as <c>RF01</c>.</summary>
public string TaxRegime { get; set; } = "RF01";
/// <summary>The company's own recipient code for incoming e-invoices.</summary>
public string? RecipientCode { get; set; }
/// <summary>The logo (an attachment of entity <c>company_profile</c>).</summary>
public long? LogoAttachmentId { get; set; }
/// <summary>The bank account proposed on documents.</summary>
public long? DefaultBankAccountId { get; set; }
/// <summary>The accounting currency (ISO 4217).</summary>
public string CurrencyCode { get; set; } = "EUR";
/// <summary>The country whose fiscal pack applies (ISO 3166-1), from <c>KHAEMHAT_COUNTRY</c> at creation.</summary>
public string Country { get; set; } = "IT";
/// <summary>The VAT settlement periodicity.</summary>
public VatPeriodicity VatPeriodicity { get; set; }
/// <summary>The deductible share for companies with exempt operations (pro-rata), in percent; 100 when it does not apply.</summary>
public decimal ProRataPercent { get; set; } = 100m;
/// <summary>VAT on cash basis (art. 32-bis DL 83/2012).</summary>
public bool CashVat { get; set; }
/// <summary>The first month of the fiscal year (1 for calendar years).</summary>
public int FiscalYearStartMonth { get; set; } = 1;
/// <summary>The transmitter of e-invoices, when not the company: country.</summary>
public string? TransmitterCountry { get; set; }
/// <summary>The transmitter of e-invoices: tax identifier.</summary>
public string? TransmitterId { get; set; }
/// <summary>The intermediary that sends the returns (LIPE, F24): name.</summary>
public string? IntermediaryName { get; set; }
/// <summary>The intermediary: tax code.</summary>
public string? IntermediaryTaxCode { get; set; }
/// <summary>The text printed at the bottom of documents.</summary>
public string? FooterNotes { get; set; }
}
/// <summary>The state of a fiscal year (SPEC §11.1, mockup 052).</summary>
public enum FiscalYearStatus
{
/// <summary>Entries allowed.</summary>
Open = 0,
/// <summary>Closing entries in progress: only closing entries.</summary>
Closing = 1,
/// <summary>Read only.</summary>
Closed = 2,
}
/// <summary>A fiscal year.</summary>
public sealed class FiscalYear : Entity<long>
{
/// <summary>The code, such as <c>2026</c> or <c>2026/27</c>.</summary>
public string Code { get; set; } = string.Empty;
/// <summary>The first day.</summary>
public DateOnly StartDate { get; set; }
/// <summary>The last day.</summary>
public DateOnly EndDate { get; set; }
/// <summary>The state.</summary>
public FiscalYearStatus Status { get; set; }
/// <summary>The first page number of the journal printed for this year.</summary>
public int JournalFirstPage { get; set; } = 1;
/// <summary>The number of the last final journal entry.</summary>
public long LastFinalEntryNumber { get; set; }
/// <summary>The date of the last final journal entry.</summary>
public DateOnly? LastFinalEntryDate { get; set; }
}
/// <summary>The state of a fiscal period.</summary>
public enum FiscalPeriodStatus
{
/// <summary>Documents and entries allowed.</summary>
Open = 0,
/// <summary>The VAT of the period was settled: no new entries with VAT.</summary>
Settled = 1,
/// <summary>Locked: no new documents or entries dated in the period.</summary>
Locked = 2,
}
/// <summary>A month of a fiscal year.</summary>
public sealed class FiscalPeriod : Entity<long>
{
/// <summary>The fiscal year.</summary>
public long FiscalYearId { get; set; }
/// <summary>The number in the year, from 1.</summary>
public int Number { get; set; }
/// <summary>The first day.</summary>
public DateOnly StartDate { get; set; }
/// <summary>The last day.</summary>
public DateOnly EndDate { get; set; }
/// <summary>The state.</summary>
public FiscalPeriodStatus Status { get; set; }
}