Files
Khaemhat/src/Khaemhat.Web/Tables/ProfileLayout.cs
T
Alby96andClaude Opus 5.5 9bcf8c1082 feat: company table screens, profile and fiscal years, seed command (#38, #39, #45)
Gives the company tables of the previous commit their screens, so a company
can be configured from the browser, and makes the base data runnable outside
the web server.

- one generic editor for the 26 coded tables (/tabelle/<slug>), described in
  TableScreens: grid with active/disabled filter, detail with errors and
  warnings, disable instead of delete, CSV export and all-or-nothing import,
  "update from base tables"; index page and menu entries
- company profile in tabs with the fiscal pack checks, fiscal years with
  month lock/unlock, exchange rates with manual rates
- PaymentTermService: installments saved together, percentages must sum to 100
- a new profile proposes the registered company name instead of its code
- seed verb in Khaemhat.Web and scripts/seed.sh --base [--company CODE],
  shipped in the image under /app/scripts
- ADR 0026 (base data only adds missing codes; ISTAT and ABI/CAB lists come
  as separate datasets), wiki, CHANGELOG, STATUS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 23:15:09 +01:00

112 lines
5.7 KiB
C#

using Khaemhat.Core.Tables;
using Khaemhat.Fiscal.Abstractions;
namespace Khaemhat.Web.Tables;
/// <summary>A group of fields of a tab of the company profile.</summary>
/// <param name="Key">The text key of the title, under <c>CompanyTables.Profile.Groups</c>.</param>
/// <param name="Icon">The icon.</param>
/// <param name="Fields">The fields.</param>
public sealed record ProfileGroup(string Key, string Icon, IReadOnlyList<TableField> Fields);
/// <summary>A tab of the company profile.</summary>
/// <param name="Id">The id in the address (<c>?scheda=fiscale</c>).</param>
/// <param name="Icon">The icon.</param>
/// <param name="Groups">The groups.</param>
public sealed record ProfileTab(string Id, string Icon, IReadOnlyList<ProfileGroup> Groups);
/// <summary>The tabs of the company profile (SPEC §11.1, mockup 075).</summary>
public static class ProfileLayout
{
/// <summary>The tabs, in order.</summary>
public static IReadOnlyList<ProfileTab> Tabs { get; } =
[
new("societa", "building",
[
new("Company", "building",
[
new(nameof(CompanyProfile.LegalName)) { Required = true, Span = 12, MaxLength = 200 },
new(nameof(CompanyProfile.FiscalName)) { Span = 12, MaxLength = 200 },
new(nameof(CompanyProfile.ReaOffice), TableFieldKind.Code) { MaxLength = 2, Span = 3 },
new(nameof(CompanyProfile.ReaNumber), TableFieldKind.Code) { MaxLength = 20, Span = 3 },
new(nameof(CompanyProfile.ShareCapital), TableFieldKind.Number) { Decimals = 2, Min = 0, Span = 6 },
new(nameof(CompanyProfile.Shareholders), TableFieldKind.Choice) { Values = ["SU", "SM"] },
new(nameof(CompanyProfile.LiquidationStatus), TableFieldKind.Choice) { Values = ["LN", "LS"] },
]),
new("Address", "pin",
[
new(nameof(CompanyProfile.Address)) { Span = 9 },
new(nameof(CompanyProfile.StreetNumber)) { Span = 3, MaxLength = 10 },
new(nameof(CompanyProfile.PostalCode), TableFieldKind.Code) { Span = 3, MaxLength = 10 },
new(nameof(CompanyProfile.City)) { Span = 6 },
new(nameof(CompanyProfile.ProvinceCode), TableFieldKind.Code) { Span = 3, MaxLength = 2 },
new(nameof(CompanyProfile.AddressCountry), TableFieldKind.Lookup) { Lookup = typeof(Country), ByCode = true },
new(nameof(CompanyProfile.Phone)),
new(nameof(CompanyProfile.Email)),
new(nameof(CompanyProfile.Pec)),
new(nameof(CompanyProfile.Website)) { Span = 12 },
]),
]),
new("fiscale", "file-check",
[
new("Tax", "file-check",
[
new(nameof(CompanyProfile.Country), TableFieldKind.Lookup) { Lookup = typeof(Country), ByCode = true, Required = true },
new(nameof(CompanyProfile.CurrencyCode), TableFieldKind.Lookup) { Lookup = typeof(Currency), ByCode = true, Required = true },
new(nameof(CompanyProfile.VatNumber), TableFieldKind.Code) { MaxLength = 30 },
new(nameof(CompanyProfile.TaxCode), TableFieldKind.Code) { MaxLength = 16 },
new(nameof(CompanyProfile.TaxRegime), TableFieldKind.CodeList) { CodeList = TaxRegimes, Required = true, Span = 12 },
new(nameof(CompanyProfile.RecipientCode), TableFieldKind.Code) { MaxLength = 7 },
]),
]),
new("banche", "coins",
[
new("Bank", "coins",
[
new(nameof(CompanyProfile.DefaultBankAccountId), TableFieldKind.Lookup) { Lookup = typeof(BankAccount), Span = 12 },
]),
]),
new("stampa", "printer",
[
new("Print", "printer",
[
new(nameof(CompanyProfile.FooterNotes)) { Span = 12, Rows = 4, MaxLength = 1000 },
]),
]),
new("esercizi", "calendar",
[
new("Vat", "calendar",
[
new(nameof(CompanyProfile.FiscalYearStartMonth), TableFieldKind.Number) { Min = 1, Max = 12, Required = true, Span = 4 },
new(nameof(CompanyProfile.VatPeriodicity), TableFieldKind.Choice) { Span = 4 },
new(nameof(CompanyProfile.ProRataPercent), TableFieldKind.Number) { Decimals = 2, Min = 0, Max = 100, Span = 4 },
new(nameof(CompanyProfile.CashVat), TableFieldKind.Bool) { Span = 12 },
]),
]),
new("trasmittente", "send",
[
new("Transmitter", "send",
[
new(nameof(CompanyProfile.TransmitterCountry), TableFieldKind.Code) { MaxLength = 2, Span = 3 },
new(nameof(CompanyProfile.TransmitterId), TableFieldKind.Code) { MaxLength = 28, Span = 9 },
]),
new("Intermediary", "users",
[
new(nameof(CompanyProfile.IntermediaryName)) { Span = 8 },
new(nameof(CompanyProfile.IntermediaryTaxCode), TableFieldKind.Code) { MaxLength = 16, Span = 4 },
]),
]),
];
/// <summary>Every field, in order.</summary>
public static IEnumerable<TableField> Fields => Tabs.SelectMany(t => t.Groups).SelectMany(g => g.Fields);
/// <summary>The tab of a field, to show the one with an error.</summary>
/// <param name="property">The property.</param>
/// <returns>The tab, or <see langword="null"/>.</returns>
public static ProfileTab? TabOf(string? property) =>
Tabs.FirstOrDefault(t => t.Groups.Any(g => g.Fields.Any(f => f.Property == property)));
private static CodeList? TaxRegimes(IFiscalPack pack) => pack.GetFeature<IEInvoiceFormat>()?.TaxRegimes;
}