feat: treasury data model, rules and migration (#69 #70 #71 #72)

Open items gain their schedule state; payments, remittances, mandates, bank
statements, match rules and dunning get their tables. Pure rules for aging,
allocation, payment posting, late interest, bank matching, dunning levels and
cash flow periods. The Italian pack adds the treasury accounts, templates and
the late payment rates of D.Lgs. 231/2002.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-13 08:42:48 +01:00
1 parent 88a0c8ce9c
commit b12dc79317
10 files changed
+1869

No files matched your search

@@ -206,6 +206,7 @@ codice;descrizione;natura;tipo;voce_cee;partitario;iva
28.01.002;Interessi passivi su mutui;C;;C.17;;
28.01.003;Interessi sulla liquidazione IVA trimestrale;C;;C.17;;
28.01.004;Oneri finanziari diversi;C;;C.17;;
28.01.005;Perdite su cambi;C;;C.17-bis;;
29;Imposte sul reddito;C;;20;;
29.01;Imposte sul reddito dell'esercizio;C;;20;;
29.01.001;IRES dell'esercizio;C;;20;;
@@ -231,6 +232,8 @@ codice;descrizione;natura;tipo;voce_cee;partitario;iva
32.01;Proventi finanziari;R;;C.16;;
32.01.001;Interessi attivi bancari;R;;C.16;;
32.01.002;Altri proventi finanziari;R;;C.16;;
32.01.003;Utili su cambi;R;;C.17-bis;;
32.01.004;Interessi di mora attivi;R;;C.16;;
90;Conti di apertura e chiusura;O;;;;
90.01;Conti di apertura e chiusura;O;;;;
90.01.001;Stato patrimoniale di apertura;O;;;;
1 codice descrizione natura tipo voce_cee partitario iva
206 28.01.002 Interessi passivi su mutui C C.17
207 28.01.003 Interessi sulla liquidazione IVA trimestrale C C.17
208 28.01.004 Oneri finanziari diversi C C.17
209 28.01.005 Perdite su cambi C C.17-bis
210 29 Imposte sul reddito C 20
211 29.01 Imposte sul reddito dell'esercizio C 20
212 29.01.001 IRES dell'esercizio C 20
232 32.01 Proventi finanziari R C.16
233 32.01.001 Interessi attivi bancari R C.16
234 32.01.002 Altri proventi finanziari R C.16
235 32.01.003 Utili su cambi R C.17-bis
236 32.01.004 Interessi di mora attivi R C.16
237 90 Conti di apertura e chiusura O
238 90.01 Conti di apertura e chiusura O
239 90.01.001 Stato patrimoniale di apertura O
@@ -60,6 +60,27 @@ public sealed class ItalianLedgerTemplate : ILedgerTemplate
/// <summary>The interest of quarterly VAT payers.</summary>
public const string VatInterest = "28.01.003";
/// <summary>Allowances received.</summary>
public const string AllowanceIncome = "31.01.004";
/// <summary>Bank fees.</summary>
public const string BankCharges = "21.03.011";
/// <summary>Effects and direct debits presented for collection.</summary>
public const string BillsForCollection = "05.02.001";
/// <summary>Advances of the bank on effects.</summary>
public const string BankAdvances = "13.01.001";
/// <summary>Exchange gains.</summary>
public const string ExchangeGain = "32.01.003";
/// <summary>Exchange losses.</summary>
public const string ExchangeLoss = "28.01.005";
/// <summary>Late payment interest charged to customers.</summary>
public const string LateInterest = "32.01.004";
private readonly Lazy<IReadOnlyList<AccountTemplate>> _accounts = new(ReadAccounts);
/// <inheritdoc />
@@ -101,6 +122,13 @@ public sealed class ItalianLedgerTemplate : ILedgerTemplate
PostingRole.StampDuty => StampDutyCost,
PostingRole.Rounding => Rounding,
PostingRole.VatSettlement => VatSettlement,
PostingRole.AllowanceIncome => AllowanceIncome,
PostingRole.BankCharges => BankCharges,
PostingRole.BillsForCollection => BillsForCollection,
PostingRole.BankAdvances => BankAdvances,
PostingRole.ExchangeGain => ExchangeGain,
PostingRole.ExchangeLoss => ExchangeLoss,
PostingRole.LateInterest => LateInterest,
_ => null,
};
@@ -157,11 +185,39 @@ public sealed class ItalianLedgerTemplate : ILedgerTemplate
[
L(PostingRole.Bank, AccountSide.Debit, Bank),
L(PostingRole.Customer, AccountSide.Credit, Customers),
L(PostingRole.Rounding, AccountSide.Debit, Rounding, "Abbuono passivo"),
L(PostingRole.ExchangeLoss, AccountSide.Debit, ExchangeLoss, "Differenza cambio"),
L(PostingRole.BankCharges, AccountSide.Debit, BankCharges, "Spese bancarie"),
]),
new("PAG", "Pagamento a fornitore", JournalArea.Treasury, null, OpensItems: false, Reverses: false,
[
L(PostingRole.Supplier, AccountSide.Debit, Suppliers),
L(PostingRole.Bank, AccountSide.Credit, Bank),
L(PostingRole.AllowanceIncome, AccountSide.Credit, AllowanceIncome, "Abbuono attivo"),
L(PostingRole.ExchangeGain, AccountSide.Credit, ExchangeGain, "Differenza cambio"),
L(PostingRole.BankCharges, AccountSide.Debit, BankCharges, "Spese bancarie"),
]),
new("DIST", "Presentazione effetti e addebiti SEPA", JournalArea.Treasury, null, OpensItems: false, Reverses: false,
[
L(PostingRole.BillsForCollection, AccountSide.Debit, BillsForCollection),
L(PostingRole.Customer, AccountSide.Credit, Customers),
]),
new("ANT", "Anticipo salvo buon fine", JournalArea.Treasury, null, OpensItems: false, Reverses: false,
[
L(PostingRole.Bank, AccountSide.Debit, Bank),
L(PostingRole.BankAdvances, AccountSide.Credit, BankAdvances),
]),
new("ACCR", "Accredito effetti a scadenza", JournalArea.Treasury, null, OpensItems: false, Reverses: false,
[
L(PostingRole.Bank, AccountSide.Debit, Bank),
L(PostingRole.BankAdvances, AccountSide.Debit, BankAdvances),
L(PostingRole.BillsForCollection, AccountSide.Credit, BillsForCollection),
]),
new("INS", "Effetto insoluto", JournalArea.Treasury, null, OpensItems: false, Reverses: false,
[
L(PostingRole.Customer, AccountSide.Debit, Customers),
L(PostingRole.Bank, AccountSide.Credit, Bank),
L(PostingRole.BillsForCollection, AccountSide.Credit, BillsForCollection),
]),
new("RIT", "Ritenuta d'acconto operata", JournalArea.Taxes, null, OpensItems: false, Reverses: false,
[
@@ -15,6 +15,7 @@ public sealed class ItalyFiscalPack : FiscalPackBase
public ItalyFiscalPack()
{
AddFeature<IEInvoiceFormat>(new FatturaPaFormat());
AddFeature<ILatePaymentRules>(new LatePaymentRulesIt());
AddFeature<IIncomingInvoiceReader>(new FatturaPaReader());
AddFeature<IIncomingInvoiceRules>(new IncomingInvoiceRulesIt());
AddFeature<ISelfInvoiceRules>(new SelfInvoiceRulesIt());
@@ -0,0 +1,56 @@
using Khaemhat.Fiscal.Abstractions;
namespace Khaemhat.Fiscal.Italy;
/// <summary>
/// Late payment interest between companies (D.Lgs. 9 ottobre 2002, n. 231, art. 5): the reference rate is the rate of
/// the main refinancing operations of the European Central Bank on the first calendar day of the half-year, published
/// by the Ministry of Economy in the Gazzetta Ufficiale, plus eight points. The table below must get a row every
/// half-year (ADR 0038); after its last row the last rate applies.
/// </summary>
public sealed class LatePaymentRulesIt : ILatePaymentRules
{
/// <summary>The points added to the reference rate.</summary>
public const decimal Margin = 8m;
/// <summary>The ECB main refinancing rate on the first day of each half-year, in percent.</summary>
private static readonly (DateOnly From, decimal Rate)[] ReferenceRates =
[
(new DateOnly(2022, 1, 1), 0.00m),
(new DateOnly(2022, 7, 1), 0.00m),
(new DateOnly(2023, 1, 1), 2.50m),
(new DateOnly(2023, 7, 1), 4.00m),
(new DateOnly(2024, 1, 1), 4.50m),
(new DateOnly(2024, 7, 1), 4.25m),
(new DateOnly(2025, 1, 1), 3.15m),
(new DateOnly(2025, 7, 1), 2.15m),
(new DateOnly(2026, 1, 1), 2.15m),
(new DateOnly(2026, 7, 1), 2.15m),
];
/// <inheritdoc />
public string LegalReference => "D.Lgs. 231/2002";
/// <inheritdoc />
public decimal RecoveryCompensation => 40m;
/// <summary>The reference rate of the half-year of a day, without the margin.</summary>
/// <param name="day">A day.</param>
/// <returns>The rate in percent.</returns>
public static decimal ReferenceRateOn(DateOnly day)
{
var rate = ReferenceRates[0].Rate;
foreach (var (from, value) in ReferenceRates)
{
if (from <= day)
{
rate = value;
}
}
return rate;
}
/// <inheritdoc />
public decimal RateOn(DateOnly day) => ReferenceRateOn(day) + Margin;
}