feat: fiscal pack abstractions and the Italian pack (#37)
The rest of the product needs tax codes, natures, code lists and VAT rules without knowing the country. IFiscalPack exposes the parts every country has (tax code catalog, tax engine, calendar) and optional features by type, so a module can tell a missing feature from a broken one. FiscalPackCatalog finds the pack by country; only the composition root names the Italian pack, as an architecture test now checks. The Italian pack carries the FatturaPA 1.9.1 code lists, VAT natures and base tax codes with their rules, summary rounding on the total per rate, the stamp duty rule, VAT deadlines with the August and holiday shifts, withholding kinds, basic depreciation rules and F24 codes. ADR 0025 records the design. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8079d3da69
commit
49d2bb166b
22 files changed
+1987
-17
No files matched your search
@@ -0,0 +1,198 @@
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>
|
||||
/// The code lists of the FatturaPA technical specifications of the Agenzia delle Entrate (SPEC §11.9). Descriptions
|
||||
/// follow the official tables, shortened where the official text runs to several lines.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <see cref="SpecVersion"/> is the version checked at each release (ADR 0025): 1.9 (in force from 1 April 2025)
|
||||
/// added TD29 and redefined TD20; 1.9.1 (published 31 March 2026, in force from 15 May 2026) changed no code list.
|
||||
/// </remarks>
|
||||
public static class FatturaPaCodeLists
|
||||
{
|
||||
/// <summary>The version of the technical specifications that this pack follows.</summary>
|
||||
public const string SpecVersion = "1.9.1";
|
||||
|
||||
/// <summary>The date from which <see cref="SpecVersion"/> is in force.</summary>
|
||||
public static readonly DateOnly SpecInForceFrom = new(2026, 5, 15);
|
||||
|
||||
/// <summary>Transmission formats (<c>FormatoTrasmissione</c>).</summary>
|
||||
public static CodeList TransmissionFormats { get; } = new("TransmissionFormats",
|
||||
[
|
||||
new("FPA12", "Fattura verso pubbliche amministrazioni"),
|
||||
new("FPR12", "Fattura verso privati"),
|
||||
new("FSM10", "Fattura semplificata"),
|
||||
]);
|
||||
|
||||
/// <summary>Document types (<c>TipoDocumento</c>).</summary>
|
||||
public static CodeList DocumentTypes { get; } = new("DocumentTypes",
|
||||
[
|
||||
new("TD01", "Fattura"),
|
||||
new("TD02", "Acconto/anticipo su fattura"),
|
||||
new("TD03", "Acconto/anticipo su parcella"),
|
||||
new("TD04", "Nota di credito"),
|
||||
new("TD05", "Nota di debito"),
|
||||
new("TD06", "Parcella"),
|
||||
new("TD07", "Fattura semplificata"),
|
||||
new("TD08", "Nota di credito semplificata"),
|
||||
new("TD09", "Nota di debito semplificata"),
|
||||
new("TD16", "Integrazione fattura reverse charge interno"),
|
||||
new("TD17", "Integrazione/autofattura per acquisto servizi dall'estero"),
|
||||
new("TD18", "Integrazione per acquisto di beni intracomunitari"),
|
||||
new("TD19", "Integrazione/autofattura per acquisto di beni ex art. 17 c. 2 DPR 633/72"),
|
||||
new("TD20", "Autofattura per regolarizzazione e integrazione delle fatture (art. 6 c. 8 e 9-bis D.Lgs. 471/97 o art. 46 c. 5 DL 331/93)"),
|
||||
new("TD21", "Autofattura per splafonamento"),
|
||||
new("TD22", "Estrazione beni da deposito IVA"),
|
||||
new("TD23", "Estrazione beni da deposito IVA con versamento dell'IVA"),
|
||||
new("TD24", "Fattura differita di cui all'art. 21 c. 4 lett. a) DPR 633/72"),
|
||||
new("TD25", "Fattura differita di cui all'art. 21 c. 4 terzo periodo lett. b) DPR 633/72"),
|
||||
new("TD26", "Cessione di beni ammortizzabili e per passaggi interni (art. 36 DPR 633/72)"),
|
||||
new("TD27", "Fattura per autoconsumo o per cessioni gratuite senza rivalsa"),
|
||||
new("TD28", "Acquisti da San Marino con IVA (fattura cartacea)"),
|
||||
new("TD29", "Comunicazione per omessa o irregolare fatturazione (art. 6 c. 8 D.Lgs. 471/97)"),
|
||||
]);
|
||||
|
||||
/// <summary>Document types accepted only in the simplified format <c>FSM10</c>.</summary>
|
||||
public static IReadOnlySet<string> SimplifiedDocumentTypes { get; } = new HashSet<string>(StringComparer.Ordinal) { "TD07", "TD08", "TD09" };
|
||||
|
||||
/// <summary>Payment methods (<c>ModalitaPagamento</c>).</summary>
|
||||
public static CodeList PaymentMethods { get; } = new("PaymentMethods",
|
||||
[
|
||||
new("MP01", "Contanti"),
|
||||
new("MP02", "Assegno"),
|
||||
new("MP03", "Assegno circolare"),
|
||||
new("MP04", "Contanti presso Tesoreria"),
|
||||
new("MP05", "Bonifico"),
|
||||
new("MP06", "Vaglia cambiario"),
|
||||
new("MP07", "Bollettino bancario"),
|
||||
new("MP08", "Carta di pagamento"),
|
||||
new("MP09", "RID"),
|
||||
new("MP10", "RID utenze"),
|
||||
new("MP11", "RID veloce"),
|
||||
new("MP12", "RIBA"),
|
||||
new("MP13", "MAV"),
|
||||
new("MP14", "Quietanza erario"),
|
||||
new("MP15", "Giroconto su conti di contabilità speciale"),
|
||||
new("MP16", "Domiciliazione bancaria"),
|
||||
new("MP17", "Domiciliazione postale"),
|
||||
new("MP18", "Bollettino di c/c postale"),
|
||||
new("MP19", "SEPA Direct Debit"),
|
||||
new("MP20", "SEPA Direct Debit CORE"),
|
||||
new("MP21", "SEPA Direct Debit B2B"),
|
||||
new("MP22", "Trattenuta su somme già riscosse"),
|
||||
new("MP23", "PagoPA"),
|
||||
]);
|
||||
|
||||
/// <summary>Payment conditions (<c>CondizioniPagamento</c>).</summary>
|
||||
public static CodeList PaymentConditions { get; } = new("PaymentConditions",
|
||||
[
|
||||
new("TP01", "Pagamento a rate"),
|
||||
new("TP02", "Pagamento completo"),
|
||||
new("TP03", "Anticipo"),
|
||||
]);
|
||||
|
||||
/// <summary>Tax regimes of the seller (<c>RegimeFiscale</c>); RF03 no longer exists.</summary>
|
||||
public static CodeList TaxRegimes { get; } = new("TaxRegimes",
|
||||
[
|
||||
new("RF01", "Ordinario"),
|
||||
new("RF02", "Contribuenti minimi (art. 1 c. 96-117 L. 244/2007)"),
|
||||
new("RF03", "Nuove iniziative produttive (abrogato)", Obsolete: true),
|
||||
new("RF04", "Agricoltura e attività connesse e pesca (artt. 34 e 34-bis DPR 633/72)"),
|
||||
new("RF05", "Vendita sali e tabacchi (art. 74 c. 1 DPR 633/72)"),
|
||||
new("RF06", "Commercio dei fiammiferi (art. 74 c. 1 DPR 633/72)"),
|
||||
new("RF07", "Editoria (art. 74 c. 1 DPR 633/72)"),
|
||||
new("RF08", "Gestione di servizi di telefonia pubblica (art. 74 c. 1 DPR 633/72)"),
|
||||
new("RF09", "Rivendita di documenti di trasporto pubblico e di sosta (art. 74 c. 1 DPR 633/72)"),
|
||||
new("RF10", "Intrattenimenti, giochi e altre attività di cui alla tariffa allegata al DPR 640/72 (art. 74 c. 6 DPR 633/72)"),
|
||||
new("RF11", "Agenzie di viaggi e turismo (art. 74-ter DPR 633/72)"),
|
||||
new("RF12", "Agriturismo (art. 5 c. 2 L. 413/91)"),
|
||||
new("RF13", "Vendite a domicilio (art. 25-bis c. 6 DPR 600/73)"),
|
||||
new("RF14", "Rivendita di beni usati, oggetti d'arte, d'antiquariato o da collezione (art. 36 DL 41/95)"),
|
||||
new("RF15", "Agenzie di vendite all'asta di oggetti d'arte, antiquariato o da collezione (art. 40-bis DL 41/95)"),
|
||||
new("RF16", "IVA per cassa P.A. (art. 6 c. 5 DPR 633/72)"),
|
||||
new("RF17", "IVA per cassa (art. 32-bis DL 83/2012)"),
|
||||
new("RF18", "Altro"),
|
||||
new("RF19", "Regime forfettario (art. 1 c. 54-89 L. 190/2014)"),
|
||||
]);
|
||||
|
||||
/// <summary>Withholding types (<c>TipoRitenuta</c>).</summary>
|
||||
public static CodeList WithholdingTypes { get; } = new("WithholdingTypes",
|
||||
[
|
||||
new("RT01", "Ritenuta persone fisiche"),
|
||||
new("RT02", "Ritenuta persone giuridiche"),
|
||||
new("RT03", "Contributo INPS"),
|
||||
new("RT04", "Contributo ENASARCO"),
|
||||
new("RT05", "Contributo ENPAM"),
|
||||
new("RT06", "Altro contributo previdenziale"),
|
||||
]);
|
||||
|
||||
/// <summary>Payment reasons of the withholding (<c>CausalePagamento</c>, as in the CU form).</summary>
|
||||
public static CodeList WithholdingReasons { get; } = new("WithholdingReasons",
|
||||
[
|
||||
new("A", "Prestazioni di lavoro autonomo rientranti nell'esercizio di arte o professione abituale"),
|
||||
new("B", "Utilizzazione economica, da parte dell'autore o dell'inventore, di opere dell'ingegno"),
|
||||
new("C", "Utili derivanti da contratti di associazione in partecipazione e cointeressenza (solo apporto di lavoro)"),
|
||||
new("D", "Utili spettanti ai soci promotori e ai soci fondatori delle società di capitali"),
|
||||
new("E", "Levata di protesti cambiari da parte dei segretari comunali"),
|
||||
new("G", "Indennità corrisposte per la cessazione di attività sportiva professionale"),
|
||||
new("H", "Indennità corrisposte per la cessazione dei rapporti di agenzia"),
|
||||
new("I", "Indennità corrisposte per la cessazione da funzioni notarili"),
|
||||
new("L", "Utilizzazione economica di opere dell'ingegno da parte di soggetto diverso dall'autore"),
|
||||
new("L1", "Redditi da utilizzazione economica di opere dell'ingegno acquisiti a titolo oneroso"),
|
||||
new("M", "Prestazioni di lavoro autonomo non esercitate abitualmente"),
|
||||
new("M1", "Redditi derivanti dall'assunzione di obblighi di fare, non fare o permettere"),
|
||||
new("M2", "Prestazioni di lavoro autonomo non esercitate abitualmente con obbligo di iscrizione alla Gestione Separata ENPAPI"),
|
||||
new("N", "Indennità di trasferta, rimborsi forfetari, premi e compensi nell'esercizio diretto di attività sportive dilettantistiche"),
|
||||
new("O", "Prestazioni di lavoro autonomo non esercitate abitualmente, senza obbligo di iscrizione alla gestione separata"),
|
||||
new("O1", "Redditi da obblighi di fare, non fare o permettere, senza obbligo di iscrizione alla gestione separata"),
|
||||
new("P", "Compensi a soggetti non residenti privi di stabile organizzazione per l'uso di attrezzature"),
|
||||
new("Q", "Provvigioni ad agente o rappresentante di commercio monomandatario"),
|
||||
new("R", "Provvigioni ad agente o rappresentante di commercio plurimandatario"),
|
||||
new("S", "Provvigioni a commissionario"),
|
||||
new("T", "Provvigioni a mediatore"),
|
||||
new("U", "Provvigioni a procacciatore di affari"),
|
||||
new("V", "Provvigioni a incaricato per le vendite a domicilio o porta a porta"),
|
||||
new("V1", "Redditi derivanti da attività commerciali non esercitate abitualmente"),
|
||||
new("V2", "Prestazioni non esercitate abitualmente rese dagli incaricati alla vendita diretta a domicilio"),
|
||||
new("W", "Corrispettivi per prestazioni relative a contratti d'appalto (art. 25-ter DPR 600/73)"),
|
||||
new("X", "Canoni corrisposti nel 2004 da società o enti residenti (art. 26-quater DPR 600/73)"),
|
||||
new("Y", "Canoni corrisposti dal 2005 da società o enti residenti (art. 26-quater DPR 600/73)"),
|
||||
new("Z", "Titolo diverso dai precedenti (sostituito da ZO)", Obsolete: true),
|
||||
new("ZO", "Titolo diverso dai precedenti"),
|
||||
]);
|
||||
|
||||
/// <summary>Social security funds (<c>TipoCassa</c>).</summary>
|
||||
public static CodeList SocialSecurityFunds { get; } = new("SocialSecurityFunds",
|
||||
[
|
||||
new("TC01", "Cassa nazionale previdenza e assistenza avvocati e procuratori legali"),
|
||||
new("TC02", "Cassa previdenza dottori commercialisti"),
|
||||
new("TC03", "Cassa previdenza e assistenza geometri"),
|
||||
new("TC04", "Cassa nazionale previdenza e assistenza ingegneri e architetti liberi professionisti"),
|
||||
new("TC05", "Cassa nazionale del notariato"),
|
||||
new("TC06", "Cassa nazionale previdenza e assistenza ragionieri e periti commerciali"),
|
||||
new("TC07", "Ente nazionale assistenza agenti e rappresentanti di commercio (ENASARCO)"),
|
||||
new("TC08", "Ente nazionale previdenza e assistenza consulenti del lavoro (ENPACL)"),
|
||||
new("TC09", "Ente nazionale previdenza e assistenza medici (ENPAM)"),
|
||||
new("TC10", "Ente nazionale previdenza e assistenza farmacisti (ENPAF)"),
|
||||
new("TC11", "Ente nazionale previdenza e assistenza veterinari (ENPAV)"),
|
||||
new("TC12", "Ente nazionale previdenza e assistenza impiegati dell'agricoltura (ENPAIA)"),
|
||||
new("TC13", "Fondo previdenza impiegati imprese di spedizione e agenzie marittime"),
|
||||
new("TC14", "Istituto nazionale previdenza giornalisti italiani (INPGI)"),
|
||||
new("TC15", "Opera nazionale assistenza orfani sanitari italiani (ONAOSI)"),
|
||||
new("TC16", "Cassa autonoma assistenza integrativa giornalisti italiani (CASAGIT)"),
|
||||
new("TC17", "Ente previdenza periti industriali e periti industriali laureati (EPPI)"),
|
||||
new("TC18", "Ente previdenza e assistenza pluricategoriale (EPAP)"),
|
||||
new("TC19", "Ente nazionale previdenza e assistenza biologi (ENPAB)"),
|
||||
new("TC20", "Ente nazionale previdenza e assistenza professione infermieristica (ENPAPI)"),
|
||||
new("TC21", "Ente nazionale previdenza e assistenza psicologi (ENPAP)"),
|
||||
new("TC22", "INPS"),
|
||||
]);
|
||||
|
||||
/// <summary>Recipient code for consumers and companies without a channel.</summary>
|
||||
public const string RecipientCodeNone = "0000000";
|
||||
|
||||
/// <summary>Recipient code for foreign customers.</summary>
|
||||
public const string RecipientCodeForeign = "XXXXXXX";
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using Khaemhat.Core.Tax;
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>
|
||||
/// Italian VAT deadlines (wiki <i>Fiscalità italiana</i>, "Scadenze e regole principali"):
|
||||
/// <list type="bullet">
|
||||
/// <item>monthly VAT by the 16th of the next month;</item>
|
||||
/// <item>quarterly VAT by the 16th of the second month after the quarter, with 1% interest; the fourth quarter is paid
|
||||
/// with the annual balance by 16 March;</item>
|
||||
/// <item>payments due from 1 to 20 August move to 20 August (art. 3-quater DL 16/2012);</item>
|
||||
/// <item>a deadline on a Saturday, Sunday or public holiday moves to the next working day (art. 7 DL 70/2011).</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public sealed class ItalianFiscalCalendar : IFiscalCalendar
|
||||
{
|
||||
/// <summary>Interest on quarterly VAT, in percent.</summary>
|
||||
public const decimal QuarterlyInterestRate = 1m;
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateOnly VatPaymentDue(TaxPeriod period)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(period);
|
||||
DateOnly due;
|
||||
if (period.Periodicity == VatPeriodicity.Monthly)
|
||||
{
|
||||
due = new DateOnly(period.Year, period.Number, 16).AddMonths(1);
|
||||
}
|
||||
else if (period.Number == 4)
|
||||
{
|
||||
due = new DateOnly(period.Year + 1, 3, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
due = new DateOnly(period.End.Year, period.End.Month, 16).AddMonths(2);
|
||||
}
|
||||
|
||||
if (due.Month == 8 && due.Day <= 20)
|
||||
{
|
||||
due = new DateOnly(due.Year, 8, 20);
|
||||
}
|
||||
|
||||
return NextWorkingDay(due);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal VatInterestRate(VatPeriodicity periodicity) =>
|
||||
periodicity == VatPeriodicity.Quarterly ? QuarterlyInterestRate : 0m;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsNonWorkingDay(DateOnly day) =>
|
||||
day.DayOfWeek is DayOfWeek.Saturday or DayOfWeek.Sunday || IsPublicHoliday(day);
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateOnly NextWorkingDay(DateOnly day)
|
||||
{
|
||||
while (IsNonWorkingDay(day))
|
||||
{
|
||||
day = day.AddDays(1);
|
||||
}
|
||||
|
||||
return day;
|
||||
}
|
||||
|
||||
/// <summary>Whether a day is an Italian national public holiday.</summary>
|
||||
/// <param name="date">The day.</param>
|
||||
/// <returns><see langword="true"/> for a holiday.</returns>
|
||||
public static bool IsPublicHoliday(DateOnly date)
|
||||
{
|
||||
switch ((date.Month, date.Day))
|
||||
{
|
||||
case (1, 1): // Capodanno
|
||||
case (1, 6): // Epifania
|
||||
case (4, 25): // Liberazione
|
||||
case (5, 1): // Festa del lavoro
|
||||
case (6, 2): // Festa della Repubblica
|
||||
case (8, 15): // Ferragosto
|
||||
case (11, 1): // Ognissanti
|
||||
case (12, 8): // Immacolata
|
||||
case (12, 25): // Natale
|
||||
case (12, 26): // Santo Stefano
|
||||
return true;
|
||||
case (10, 4) when date.Year >= 2026: // San Francesco, national holiday again from 2026
|
||||
return true;
|
||||
default:
|
||||
return date == EasterSunday(date.Year).AddDays(1); // Lunedì dell'Angelo
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Easter Sunday of a year (Gregorian calendar, anonymous algorithm).</summary>
|
||||
/// <param name="year">The year.</param>
|
||||
/// <returns>The date.</returns>
|
||||
public static DateOnly EasterSunday(int year)
|
||||
{
|
||||
var a = year % 19;
|
||||
var b = year / 100;
|
||||
var c = year % 100;
|
||||
var d = b / 4;
|
||||
var e = b % 4;
|
||||
var f = (b + 8) / 25;
|
||||
var g = (b - f + 1) / 3;
|
||||
var h = ((19 * a) + b - d - g + 15) % 30;
|
||||
var i = c / 4;
|
||||
var k = c % 4;
|
||||
var l = (32 + (2 * e) + (2 * i) - h - k) % 7;
|
||||
var m = (a + (11 * h) + (22 * l)) / 451;
|
||||
var month = (h + l - (7 * m) + 114) / 31;
|
||||
var day = ((h + l - (7 * m) + 114) % 31) + 1;
|
||||
return new DateOnly(year, month, day);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using Khaemhat.Core.Tax;
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>The FatturaPA format: version of the specifications and code lists (writer and reader arrive in M9).</summary>
|
||||
public sealed class FatturaPaFormat : IEInvoiceFormat
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string Name => "FatturaPA";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string SpecVersion => FatturaPaCodeLists.SpecVersion;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList TransmissionFormats => FatturaPaCodeLists.TransmissionFormats;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList DocumentTypes => FatturaPaCodeLists.DocumentTypes;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList PaymentMethods => FatturaPaCodeLists.PaymentMethods;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList PaymentConditions => FatturaPaCodeLists.PaymentConditions;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList TaxRegimes => FatturaPaCodeLists.TaxRegimes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Italian withholding taxes: fees of professionals (20% on the whole fee, F24 1040), commissions of agents (23% on 50%,
|
||||
/// or on 20% for agents with employees, F24 1038) and the 4% of condominiums (F24 1019).
|
||||
/// </summary>
|
||||
public sealed class WithholdingRulesIt : IWithholdingRules
|
||||
{
|
||||
private readonly ItalianTaxEngine _engine = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<WithholdingKind> Kinds { get; } =
|
||||
[
|
||||
new("PROF", "Lavoro autonomo professionale", 20m, 100m, "1040", "RT01", "A"),
|
||||
new("OCC", "Lavoro autonomo occasionale", 20m, 100m, "1040", "RT01", "M"),
|
||||
new("AGEN", "Provvigioni ad agenti e rappresentanti", 23m, 50m, "1038", "RT01", "R"),
|
||||
new("AGEND", "Provvigioni ad agenti con dipendenti o terzi", 23m, 20m, "1038", "RT01", "R"),
|
||||
new("COND", "Ritenuta del condominio sugli appalti", 4m, 100m, "1019", "RT01", "W"),
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList InvoiceTypes => FatturaPaCodeLists.WithholdingTypes;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList PaymentReasons => FatturaPaCodeLists.WithholdingReasons;
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList SocialSecurityFunds => FatturaPaCodeLists.SocialSecurityFunds;
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal Compute(decimal amount, WithholdingKind kind)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(kind);
|
||||
return _engine.Round(amount * kind.TaxableBasePercent / 100m * kind.Rate / 100m);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Italian depreciation rules (DM 31/12/1988 coefficients arrive with the asset register, M10).</summary>
|
||||
public sealed class FixedAssetRulesIt : IFixedAssetRules
|
||||
{
|
||||
private readonly ItalianTaxEngine _engine = new();
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal FirstYearFactor => 0.5m;
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal LowValueThreshold => 516.46m;
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal PassengerCarCostLimit => 18_075.99m;
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal YearlyDepreciation(decimal cost, decimal ratePercent, bool firstYear, decimal alreadyDepreciated)
|
||||
{
|
||||
var remaining = Math.Max(0m, cost - alreadyDepreciated);
|
||||
var amount = _engine.Round(cost * ratePercent / 100m * (firstYear ? FirstYearFactor : 1m));
|
||||
return Math.Min(amount, remaining);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The F24 payment codes Khaemhat proposes (the file export arrives with the VAT settlement, M7).</summary>
|
||||
public sealed class F24Exporter : ITaxPaymentFormExporter
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string FormName => "F24";
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<TaxPaymentCode> Codes { get; } = BuildCodes();
|
||||
|
||||
/// <inheritdoc />
|
||||
public string VatCode(TaxPeriod period)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(period);
|
||||
return period.Periodicity == VatPeriodicity.Monthly
|
||||
? (6000 + period.Number).ToString(System.Globalization.CultureInfo.InvariantCulture)
|
||||
: (6030 + period.Number).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string VatAdvanceCode(VatPeriodicity periodicity) => periodicity == VatPeriodicity.Monthly ? "6013" : "6035";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string StampDutyCode(int quarter)
|
||||
{
|
||||
ArgumentOutOfRangeException.ThrowIfLessThan(quarter, 1);
|
||||
ArgumentOutOfRangeException.ThrowIfGreaterThan(quarter, 4);
|
||||
return (2520 + quarter).ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private static List<TaxPaymentCode> BuildCodes()
|
||||
{
|
||||
string[] months = ["gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"];
|
||||
var codes = new List<TaxPaymentCode>();
|
||||
for (var m = 1; m <= 12; m++)
|
||||
{
|
||||
codes.Add(new((6000 + m).ToString(System.Globalization.CultureInfo.InvariantCulture), "Versamento IVA mensile " + months[m - 1]));
|
||||
}
|
||||
|
||||
codes.Add(new("6013", "Versamento acconto IVA mensile"));
|
||||
for (var q = 1; q <= 4; q++)
|
||||
{
|
||||
codes.Add(new((6030 + q).ToString(System.Globalization.CultureInfo.InvariantCulture), $"Versamento IVA trimestrale {q}° trimestre"));
|
||||
}
|
||||
|
||||
codes.Add(new("6035", "Versamento IVA acconto trimestrali"));
|
||||
codes.Add(new("6099", "Versamento IVA sulla base della dichiarazione annuale"));
|
||||
codes.Add(new("1040", "Ritenute su redditi di lavoro autonomo"));
|
||||
codes.Add(new("1038", "Ritenute su provvigioni"));
|
||||
codes.Add(new("1019", "Ritenute del 4% operate dal condominio a titolo di acconto IRPEF"));
|
||||
for (var q = 1; q <= 4; q++)
|
||||
{
|
||||
codes.Add(new((2520 + q).ToString(System.Globalization.CultureInfo.InvariantCulture), $"Imposta di bollo sulle fatture elettroniche, {q}° trimestre"));
|
||||
}
|
||||
|
||||
return codes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using Khaemhat.Core.Tax;
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>The Italian VAT natures, the base tax codes of SPEC §14 and the rules of a tax code (mockup 076).</summary>
|
||||
public sealed class ItalianTaxCodeCatalog : ITaxCodeCatalog
|
||||
{
|
||||
/// <summary>The rates of Italian VAT in percent (ordinary and reduced).</summary>
|
||||
public static IReadOnlySet<decimal> StandardRates { get; } = new HashSet<decimal> { 0m, 4m, 5m, 10m, 22m };
|
||||
|
||||
/// <inheritdoc />
|
||||
public CodeList Natures => VatNatures.All;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<TaxCodeDefinition> BaseCodes { get; } =
|
||||
[
|
||||
new("22", "IVA 22%", 22m),
|
||||
new("10", "IVA 10%", 10m),
|
||||
new("5", "IVA 5%", 5m),
|
||||
new("4", "IVA 4%", 4m),
|
||||
new("22SP", "IVA 22% scissione dei pagamenti", 22m, Exigibility: TaxExigibility.SplitPayment, LegalReference: "Art. 17-ter DPR 633/72"),
|
||||
new("10SP", "IVA 10% scissione dei pagamenti", 10m, Exigibility: TaxExigibility.SplitPayment, LegalReference: "Art. 17-ter DPR 633/72"),
|
||||
new("22I50", "IVA 22% indetraibile al 50%", 22m, NonDeductiblePercent: 50m),
|
||||
new("22I100", "IVA 22% indetraibile", 22m, NonDeductiblePercent: 100m),
|
||||
new("ESC15", "Escluso art. 15", 0m, "N1", LegalReference: "Art. 15 DPR 633/72"),
|
||||
new("FC7", "Non soggetto artt. 7-7 septies", 0m, "N2.1", LegalReference: "Artt. 7-7-septies DPR 633/72"),
|
||||
new("NS", "Non soggetto, altri casi", 0m, "N2.2", LegalReference: "Art. 2 DPR 633/72"),
|
||||
new("FORF", "Operazione in regime forfettario", 0m, "N2.2", LegalReference: "Art. 1 c. 54-89 L. 190/2014"),
|
||||
new("NI8", "Non imponibile art. 8 (esportazioni)", 0m, "N3.1", LegalReference: "Art. 8 c. 1 lett. a) DPR 633/72"),
|
||||
new("NI41", "Non imponibile art. 41 (cessioni intracomunitarie)", 0m, "N3.2", LegalReference: "Art. 41 DL 331/93"),
|
||||
new("NI71", "Non imponibile art. 71 (San Marino)", 0m, "N3.3", LegalReference: "Art. 71 DPR 633/72"),
|
||||
new("NI8C", "Non imponibile art. 8 c. 1 lett. c) (dichiarazione d'intento)", 0m, "N3.5", LegalReference: "Art. 8 c. 1 lett. c) DPR 633/72"),
|
||||
new("ESE10", "Esente art. 10", 0m, "N4", LegalReference: "Art. 10 DPR 633/72"),
|
||||
new("RC74", "Inversione contabile, rottami", 0m, "N6.1", LegalReference: "Art. 74 c. 7 e 8 DPR 633/72"),
|
||||
new("RC17O", "Inversione contabile, oro e argento", 0m, "N6.2", LegalReference: "Art. 17 c. 5 DPR 633/72"),
|
||||
new("RC17A", "Inversione contabile, subappalto edile", 0m, "N6.3", LegalReference: "Art. 17 c. 6 lett. a) DPR 633/72"),
|
||||
new("RC17F", "Inversione contabile, cessione di fabbricati", 0m, "N6.4", LegalReference: "Art. 17 c. 6 lett. a-bis) DPR 633/72"),
|
||||
new("RC17B", "Inversione contabile, telefoni cellulari", 0m, "N6.5", LegalReference: "Art. 17 c. 6 lett. b) DPR 633/72"),
|
||||
new("RC17C", "Inversione contabile, prodotti elettronici", 0m, "N6.6", LegalReference: "Art. 17 c. 6 lett. c) DPR 633/72"),
|
||||
new("RC17E", "Inversione contabile, comparto edile e settori connessi", 0m, "N6.7", LegalReference: "Art. 17 c. 6 lett. a-ter) DPR 633/72"),
|
||||
new("RC17N", "Inversione contabile, settore energetico", 0m, "N6.8", LegalReference: "Art. 17 c. 6 lett. d-bis), d-ter), d-quater) DPR 633/72"),
|
||||
new("RC17", "Inversione contabile, altri casi", 0m, "N6.9", LegalReference: "Art. 17 DPR 633/72"),
|
||||
];
|
||||
|
||||
/// <inheritdoc />
|
||||
public TaxCodeKind KindOf(decimal rate, string? nature) =>
|
||||
string.IsNullOrWhiteSpace(nature) ? TaxCodeKind.Taxable : VatNatures.KindOf(nature);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<FiscalProblem> Validate(TaxCodeDefinition code)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(code);
|
||||
var problems = new List<FiscalProblem>();
|
||||
var nature = string.IsNullOrWhiteSpace(code.Nature) ? null : code.Nature.Trim();
|
||||
|
||||
if (code.Rate is < 0m or > 100m)
|
||||
{
|
||||
problems.Add(new(nameof(code.Rate), "fiscal.tax.rate-range"));
|
||||
}
|
||||
else if (!StandardRates.Contains(code.Rate))
|
||||
{
|
||||
// Compensation rates of the agricultural regime are legal but rare: a warning, not an error.
|
||||
problems.Add(new(nameof(code.Rate), "fiscal.tax.rate-unusual", FiscalProblemSeverity.Warning));
|
||||
}
|
||||
|
||||
if (nature is null)
|
||||
{
|
||||
if (code.Rate == 0m)
|
||||
{
|
||||
problems.Add(new(nameof(code.Nature), "fiscal.tax.nature-required"));
|
||||
}
|
||||
}
|
||||
else if (Natures.Find(nature) is not { } entry)
|
||||
{
|
||||
problems.Add(new(nameof(code.Nature), "fiscal.tax.nature-unknown"));
|
||||
}
|
||||
else if (entry.Obsolete)
|
||||
{
|
||||
problems.Add(new(nameof(code.Nature), "fiscal.tax.nature-obsolete"));
|
||||
}
|
||||
else if (code.Rate != 0m)
|
||||
{
|
||||
problems.Add(new(nameof(code.Nature), "fiscal.tax.nature-with-rate"));
|
||||
}
|
||||
else if (string.IsNullOrWhiteSpace(code.LegalReference))
|
||||
{
|
||||
problems.Add(new(nameof(code.LegalReference), "fiscal.tax.legal-reference-missing", FiscalProblemSeverity.Warning));
|
||||
}
|
||||
|
||||
if (code.Exigibility == TaxExigibility.SplitPayment && code.Rate == 0m)
|
||||
{
|
||||
problems.Add(new(nameof(code.Exigibility), "fiscal.tax.split-needs-rate"));
|
||||
}
|
||||
|
||||
if (code.Exigibility != TaxExigibility.Immediate && VatNatures.IsReverseCharge(nature))
|
||||
{
|
||||
problems.Add(new(nameof(code.Exigibility), "fiscal.tax.reverse-charge-immediate"));
|
||||
}
|
||||
|
||||
if (code.NonDeductiblePercent is < 0m or > 100m)
|
||||
{
|
||||
problems.Add(new(nameof(code.NonDeductiblePercent), "fiscal.tax.non-deductible-range"));
|
||||
}
|
||||
|
||||
return problems;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>
|
||||
/// Italian VAT arithmetic: amounts to the cent, halves away from zero; the tax of the summary is computed on the total
|
||||
/// taxable of each line, as the FatturaPA <c>DatiRiepilogo</c> requires (tolerance of one cent on rows).
|
||||
/// </summary>
|
||||
public sealed class ItalianTaxEngine : ITaxEngine
|
||||
{
|
||||
/// <summary>The stamp duty on invoices without VAT (art. 13 of the tariff of DPR 642/72).</summary>
|
||||
public const decimal StampDutyAmount = 2.00m;
|
||||
|
||||
/// <summary>The amount without VAT above which the stamp duty is due.</summary>
|
||||
public const decimal StampDutyThreshold = 77.47m;
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal Round(decimal amount) => Math.Round(amount, 2, MidpointRounding.AwayFromZero);
|
||||
|
||||
/// <inheritdoc />
|
||||
public decimal ComputeTax(decimal taxable, decimal rate) => Round(taxable * rate / 100m);
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<TaxSummaryLine> Summarize(IEnumerable<TaxableAmount> amounts)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(amounts);
|
||||
return
|
||||
[
|
||||
.. amounts
|
||||
.GroupBy(a => (a.Rate, Nature: Normalize(a.Nature), a.Exigibility, a.NonDeductiblePercent))
|
||||
.Select(g =>
|
||||
{
|
||||
var taxable = Round(g.Sum(a => a.Amount));
|
||||
var tax = ComputeTax(taxable, g.Key.Rate);
|
||||
return new TaxSummaryLine(g.Key.Rate, g.Key.Nature, g.Key.Exigibility, g.Key.NonDeductiblePercent,
|
||||
taxable, tax, Round(tax * g.Key.NonDeductiblePercent / 100m));
|
||||
})
|
||||
.OrderByDescending(l => l.Rate)
|
||||
.ThenBy(l => l.Nature, StringComparer.Ordinal)
|
||||
.ThenBy(l => l.Exigibility)
|
||||
.ThenBy(l => l.NonDeductiblePercent),
|
||||
];
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public StampDutyAssessment AssessStampDuty(IEnumerable<TaxSummaryLine> summary)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(summary);
|
||||
var exempt = Round(summary.Where(l => l.Rate == 0m && VatNatures.CountsForStampDuty(l.Nature)).Sum(l => l.Taxable));
|
||||
var required = exempt > StampDutyThreshold;
|
||||
return new StampDutyAssessment(required, required ? StampDutyAmount : 0m, exempt, StampDutyThreshold);
|
||||
}
|
||||
|
||||
private static string? Normalize(string? nature) =>
|
||||
string.IsNullOrWhiteSpace(nature) ? null : nature.Trim().ToUpperInvariant();
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>
|
||||
/// The Italian fiscal pack (SPEC §1.10, ADR 0007, ADR 0025): chosen for companies whose <c>company_profile.country</c>
|
||||
/// is <c>IT</c>. Registered only by the composition root of <c>Khaemhat.Web</c>.
|
||||
/// </summary>
|
||||
public sealed class ItalyFiscalPack : FiscalPackBase
|
||||
{
|
||||
/// <summary>The version of the Italian base data and code lists.</summary>
|
||||
public const string Version = "IT 2026.2";
|
||||
|
||||
/// <summary>Creates the pack with every feature this version delivers.</summary>
|
||||
public ItalyFiscalPack()
|
||||
{
|
||||
AddFeature<IEInvoiceFormat>(new FatturaPaFormat());
|
||||
AddFeature<IWithholdingRules>(new WithholdingRulesIt());
|
||||
AddFeature<IFixedAssetRules>(new FixedAssetRulesIt());
|
||||
AddFeature<ITaxPaymentFormExporter>(new F24Exporter());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string CountryCode => "IT";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Italia";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string DataVersion => Version;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ITaxCodeCatalog TaxCodes { get; } = new ItalianTaxCodeCatalog();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ITaxEngine TaxEngine { get; } = new ItalianTaxEngine();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IFiscalCalendar Calendar { get; } = new ItalianFiscalCalendar();
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using Khaemhat.Core.Tax;
|
||||
using Khaemhat.Fiscal.Abstractions;
|
||||
|
||||
namespace Khaemhat.Fiscal.Italy;
|
||||
|
||||
/// <summary>
|
||||
/// The VAT natures of the FatturaPA specifications (<c>Natura</c>, N1-N7). Since 2021 the generic codes N2, N3 and N6
|
||||
/// are no longer accepted: only their sub-codes.
|
||||
/// </summary>
|
||||
public static class VatNatures
|
||||
{
|
||||
/// <summary>Every nature, obsolete ones included.</summary>
|
||||
public static CodeList All { get; } = new("VatNatures",
|
||||
[
|
||||
new("N1", "Escluse ex art. 15 DPR 633/72"),
|
||||
new("N2", "Non soggette", Obsolete: true),
|
||||
new("N2.1", "Non soggette ad IVA ai sensi degli artt. da 7 a 7-septies DPR 633/72"),
|
||||
new("N2.2", "Non soggette - altri casi"),
|
||||
new("N3", "Non imponibili", Obsolete: true),
|
||||
new("N3.1", "Non imponibili - esportazioni"),
|
||||
new("N3.2", "Non imponibili - cessioni intracomunitarie"),
|
||||
new("N3.3", "Non imponibili - cessioni verso San Marino"),
|
||||
new("N3.4", "Non imponibili - operazioni assimilate alle cessioni all'esportazione"),
|
||||
new("N3.5", "Non imponibili - a seguito di dichiarazioni d'intento"),
|
||||
new("N3.6", "Non imponibili - altre operazioni che non concorrono alla formazione del plafond"),
|
||||
new("N4", "Esenti"),
|
||||
new("N5", "Regime del margine / IVA non esposta in fattura"),
|
||||
new("N6", "Inversione contabile", Obsolete: true),
|
||||
new("N6.1", "Inversione contabile - cessione di rottami e altri materiali di recupero"),
|
||||
new("N6.2", "Inversione contabile - cessione di oro e argento ai sensi della L. 7/2000 nonché di oreficeria usata ad OPO"),
|
||||
new("N6.3", "Inversione contabile - subappalto nel settore edile"),
|
||||
new("N6.4", "Inversione contabile - cessione di fabbricati"),
|
||||
new("N6.5", "Inversione contabile - cessione di telefoni cellulari"),
|
||||
new("N6.6", "Inversione contabile - cessione di prodotti elettronici"),
|
||||
new("N6.7", "Inversione contabile - prestazioni comparto edile e settori connessi"),
|
||||
new("N6.8", "Inversione contabile - operazioni settore energetico"),
|
||||
new("N6.9", "Inversione contabile - altri casi"),
|
||||
new("N7", "IVA assolta in altro stato UE (art. 7-octies e art. 74-sexies DPR 633/72)"),
|
||||
]);
|
||||
|
||||
// Natures whose amounts count toward the stamp duty threshold: exports (N3.1), intra-EU supplies (N3.2), San Marino
|
||||
// (N3.3), operations assimilated to exports (N3.4), reverse charge (N6.x) and VAT paid in another EU state (N7) are
|
||||
// exempt from stamp duty (art. 15 of the table attached to DPR 642/72 and the Agenzia's guidance).
|
||||
private static readonly HashSet<string> StampDutyNatures = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"N1", "N2.1", "N2.2", "N3.5", "N3.6", "N4", "N5",
|
||||
};
|
||||
|
||||
/// <summary>The kind of operation a nature describes; no nature means a taxable operation.</summary>
|
||||
/// <param name="nature">The nature code.</param>
|
||||
/// <returns>The kind.</returns>
|
||||
public static TaxCodeKind KindOf(string? nature)
|
||||
{
|
||||
var code = nature?.Trim().ToUpperInvariant() ?? string.Empty;
|
||||
return code switch
|
||||
{
|
||||
"" => TaxCodeKind.Taxable,
|
||||
"N1" => TaxCodeKind.Excluded,
|
||||
"N4" => TaxCodeKind.Exempt,
|
||||
"N5" => TaxCodeKind.Margin,
|
||||
"N7" => TaxCodeKind.OtherEuVat,
|
||||
_ when code.StartsWith("N2", StringComparison.Ordinal) => TaxCodeKind.NotSubject,
|
||||
_ when code.StartsWith("N3", StringComparison.Ordinal) => TaxCodeKind.NonTaxable,
|
||||
_ when code.StartsWith("N6", StringComparison.Ordinal) => TaxCodeKind.ReverseCharge,
|
||||
_ => throw new ArgumentException($"Unknown VAT nature '{nature}'.", nameof(nature)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Whether an amount with this nature counts toward the stamp duty threshold.</summary>
|
||||
/// <param name="nature">The nature code.</param>
|
||||
/// <returns><see langword="true"/> when the stamp duty rule counts it.</returns>
|
||||
public static bool CountsForStampDuty(string? nature) => nature is not null && StampDutyNatures.Contains(nature.Trim());
|
||||
|
||||
/// <summary>Whether the nature is a reverse charge one (N6.x).</summary>
|
||||
/// <param name="nature">The nature code.</param>
|
||||
/// <returns><see langword="true"/> for reverse charge.</returns>
|
||||
public static bool IsReverseCharge(string? nature) =>
|
||||
nature is not null && nature.Trim().StartsWith("N6", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
Reference in new issue
Block a user