|
| 1 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 2 | + |
| 3 | +namespace s2industries.ZUGFeRD.Test; |
| 4 | + |
| 5 | +[TestClass] |
| 6 | +public class TestTaxes |
| 7 | +{ |
| 8 | + [TestMethod] |
| 9 | + public void SavingThenReadingAppliedTradeTaxesShouldWork() |
| 10 | + { |
| 11 | + InvoiceDescriptor expected = InvoiceDescriptor.CreateInvoice("471102", new DateTime(2013, 6, 5), CurrencyCodes.EUR, "GE2020211-471102"); |
| 12 | + expected.BusinessProcess = string.Empty; |
| 13 | + expected.Name = string.Empty; |
| 14 | + expected.ReferenceOrderNo = string.Empty; |
| 15 | + var lineItem = expected.AddTradeLineItem(name: "Something", |
| 16 | + grossUnitPrice: 9.9m, |
| 17 | + netUnitPrice: 9.9m, |
| 18 | + billedQuantity: 20m, |
| 19 | + taxType: TaxTypes.VAT, |
| 20 | + categoryCode: TaxCategoryCodes.S, |
| 21 | + taxPercent: 19m |
| 22 | + ); |
| 23 | + lineItem.LineTotalAmount = 198m; // 20 * 9.9 |
| 24 | + expected.AddApplicableTradeTax( |
| 25 | + basisAmount: lineItem.LineTotalAmount!.Value, |
| 26 | + percent: 19m, |
| 27 | + taxAmount: 29.82m, // 19% of 198 |
| 28 | + typeCode: TaxTypes.VAT, |
| 29 | + categoryCode: TaxCategoryCodes.S, |
| 30 | + allowanceChargeBasisAmount: -5m |
| 31 | + ); |
| 32 | + expected.LineTotalAmount = 198m; |
| 33 | + expected.TaxBasisAmount = 198m; |
| 34 | + expected.TaxTotalAmount = 29.82m; |
| 35 | + expected.GrandTotalAmount = 198m + 29.82m; |
| 36 | + expected.DuePayableAmount = expected.GrandTotalAmount; |
| 37 | + |
| 38 | + using MemoryStream ms = new(); |
| 39 | + expected.Save(ms); |
| 40 | + ms.Seek(0, SeekOrigin.Begin); |
| 41 | + |
| 42 | + InvoiceDescriptor actual = InvoiceDescriptor.Load(ms); |
| 43 | + |
| 44 | + Assert.AreEqual(expected.Taxes.Count, actual.Taxes.Count); |
| 45 | + Assert.AreEqual(1, actual.Taxes.Count); |
| 46 | + Tax actualTax = actual.Taxes[0]; |
| 47 | + Assert.AreEqual(198m, actualTax.BasisAmount); |
| 48 | + Assert.AreEqual(19m, actualTax.Percent); |
| 49 | + Assert.AreEqual(29.82m, actualTax.TaxAmount); |
| 50 | + Assert.AreEqual(TaxTypes.VAT, actualTax.TypeCode); |
| 51 | + Assert.AreEqual(TaxCategoryCodes.S, actualTax.CategoryCode); |
| 52 | + Assert.AreEqual(-5m, actualTax.AllowanceChargeBasisAmount); |
| 53 | + } |
| 54 | +} |
0 commit comments