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,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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user