Skip to content

Commit

Permalink
added better payment term handling zu ZUGFeRD 1.0 (reader)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanstapel committed Jan 10, 2025
1 parent 92844da commit e9aa607
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
27 changes: 27 additions & 0 deletions ZUGFeRD.Test/ZUGFeRD10Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,32 @@ public void TestMissingPropertiesAreNull()
Assert.IsTrue(invoiceDescriptor.TradeLineItems.TrueForAll(x => x.BillingPeriodStart == null));
Assert.IsTrue(invoiceDescriptor.TradeLineItems.TrueForAll(x => x.BillingPeriodEnd == null));
} // !TestMissingPropertiesAreNull()


[TestMethod]
public void TestSpecifiedTradePaymentTermsDescription()
{
string path = @"..\..\..\..\demodata\zugferd10\ZUGFeRD_1p0_EXTENDED_Warenrechnung.xml";
path = _makeSurePathIsCrossPlatformCompatible(path);

InvoiceDescriptor desc = InvoiceDescriptor.Load(path);
Assert.IsNotNull(desc.GetTradePaymentTerms().First().Description);
Assert.AreEqual("Bei Zahlung innerhalb 14 Tagen gewähren wir 2,0% Skonto.", desc.GetTradePaymentTerms().First().Description);
} // !TestSpecifiedTradePaymentTermsDescription()


[TestMethod]
public void TestSpecifiedTradePaymentTermsCalculationPercent()
{
string path = @"..\..\..\..\demodata\zugferd10\ZUGFeRD_1p0_EXTENDED_Warenrechnung.xml";
path = _makeSurePathIsCrossPlatformCompatible(path);

InvoiceDescriptor desc = InvoiceDescriptor.Load(path);

var x = desc.GetTradePaymentTerms();

Assert.IsNotNull(desc.GetTradePaymentTerms().First().Percentage);
Assert.AreEqual(2m, desc.GetTradePaymentTerms().First().Percentage);
} // !TestSpecifiedTradePaymentTermsCalculationPercent()
}
}
2 changes: 1 addition & 1 deletion ZUGFeRD.Test/ZUGFeRD22Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2957,6 +2957,6 @@ public void TestSpecifiedTradePaymentTermsCalculationPercent()
InvoiceDescriptor desc = InvoiceDescriptor.Load(path);
Assert.IsNotNull(desc.GetTradePaymentTerms().First().Percentage);
Assert.AreEqual(2m, desc.GetTradePaymentTerms().First().Percentage);
} // !TestSpecifiedTradePaymentTermsDescription()
} // !TestSpecifiedTradePaymentTermsCalculationPercent()
}
}
16 changes: 15 additions & 1 deletion ZUGFeRD/InvoiceDescriptor1Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,22 @@ public override InvoiceDescriptor Load(Stream stream)

foreach (XmlNode node in doc.SelectNodes("//ram:SpecifiedTradePaymentTerms", nsmgr))
{
decimal? discountPercent = XmlUtils.NodeAsDecimal(node, ".//ram:ApplicableTradePaymentDiscountTerms/ram:CalculationPercent", nsmgr, null);
int? discountDueDays = null; // XmlUtils.NodeAsInt(node, ".//ram:ApplicableTradePaymentDiscountTerms/ram:BasisPeriodMeasure", nsmgr);
decimal? discountBaseAmount = XmlUtils.NodeAsDecimal(node, ".//ram:ApplicableTradePaymentDiscountTerms/ram:BasisAmount", nsmgr, null);
decimal? penaltyPercent = XmlUtils.NodeAsDecimal(node, ".//ram:ApplicableTradePaymentPenaltyTerms/ram:CalculationPercent", nsmgr, null);
int? penaltyDueDays = null; // XmlUtils.NodeAsInt(node, ".//ram:ApplicableTradePaymentPenaltyTerms/ram:BasisPeriodMeasure", nsmgr);
decimal? penaltyBaseAmount = XmlUtils.NodeAsDecimal(node, ".//ram:ApplicableTradePaymentPenaltyTerms/ram:BasisAmount", nsmgr, null);
PaymentTermsType? paymentTermsType = discountPercent.HasValue ? PaymentTermsType.Skonto :
penaltyPercent.HasValue ? PaymentTermsType.Verzug :
(PaymentTermsType?)null;

retval.AddTradePaymentTerms(XmlUtils.NodeAsString(node, ".//ram:Description", nsmgr),
XmlUtils.NodeAsDateTime(node, ".//ram:DueDateDateTime", nsmgr));
XmlUtils.NodeAsDateTime(node, ".//ram:DueDateDateTime/udt:DateTimeString", nsmgr),
paymentTermsType,
discountDueDays ?? penaltyDueDays,
discountPercent ?? penaltyPercent,
discountBaseAmount ?? penaltyBaseAmount);
}

retval.LineTotalAmount = XmlUtils.NodeAsDecimal(doc.DocumentElement, "//ram:SpecifiedTradeSettlementMonetarySummation/ram:LineTotalAmount", nsmgr, 0).Value;
Expand Down

0 comments on commit e9aa607

Please sign in to comment.