using Khaemhat.Core.Tax; namespace Khaemhat.Fiscal.Abstractions; /// /// The fiscal content of a tax code (SPEC §11.1, mockup 076): the parts the country's rules check. The table /// tax_codes adds validity, accounts and the other company data. /// /// The company's code, such as 22 or NI8. /// The description shown on documents. /// The rate in percent, such as 22. /// The country's nature code for zero-rate operations (Italy: N1...N7). /// When the tax becomes due. /// Share of the purchase tax that cannot be deducted, 0-100. /// The law the operation is based on, printed on the invoice. public sealed record TaxCodeDefinition( string Code, string Description, decimal Rate, string? Nature = null, TaxExigibility Exigibility = TaxExigibility.Immediate, decimal NonDeductiblePercent = 0m, string? LegalReference = null); /// The country's tax natures and base tax codes, and the rules a tax code must follow. public interface ITaxCodeCatalog { /// The nature codes for operations without tax. CodeList Natures { get; } /// The tax codes loaded by the base data (SPEC §14). IReadOnlyList BaseCodes { get; } /// The kind of operation a rate and nature describe. /// The rate in percent. /// The nature code, if any. /// The kind. TaxCodeKind KindOf(decimal rate, string? nature); /// The rules a tax code breaks; empty when it is valid. /// The tax code. /// Errors and warnings. IReadOnlyList Validate(TaxCodeDefinition code); } /// An amount of a document subject to one tax code. /// The taxable amount, already net of discounts. /// The rate in percent. /// The nature code for zero-rate operations. /// When the tax becomes due. /// Share of the tax that cannot be deducted (purchases). public sealed record TaxableAmount( decimal Amount, decimal Rate, string? Nature = null, TaxExigibility Exigibility = TaxExigibility.Immediate, decimal NonDeductiblePercent = 0m); /// One line of the tax summary of a document (castelletto IVA). /// The rate in percent. /// The nature code, if any. /// When the tax becomes due. /// Share of the tax that cannot be deducted. /// The sum of the taxable amounts. /// The tax, rounded to the cent. /// The part of that cannot be deducted. public sealed record TaxSummaryLine( decimal Rate, string? Nature, TaxExigibility Exigibility, decimal NonDeductiblePercent, decimal Taxable, decimal Tax, decimal NonDeductibleTax); /// Whether a document needs stamp duty, and how much. /// The document must carry the duty. /// The duty, zero when not required. /// The sum of the amounts without tax that the rule counts. /// The amount above which the duty is due. public sealed record StampDutyAssessment(bool Required, decimal Amount, decimal ExemptTotal, decimal Threshold); /// Tax computation with the country's rounding rules. public interface ITaxEngine { /// Rounds an amount of money as the country's tax rules require. /// The amount. /// The amount rounded to the cent. decimal Round(decimal amount); /// The tax on a taxable amount. /// The taxable amount. /// The rate in percent. /// The tax, rounded. decimal ComputeTax(decimal taxable, decimal rate); /// /// The tax summary of a document: one line per rate, nature, exigibility and non-deductible share, with the tax /// computed on the total of the line (not summed from the rows). /// /// The taxable amounts of the document rows. /// The summary lines, by rate (highest first) and then by nature. IReadOnlyList Summarize(IEnumerable amounts); /// Whether the document needs stamp duty. /// The tax summary of the document. /// The assessment. StampDutyAssessment AssessStampDuty(IEnumerable summary); }