Skip to content

Commit 10f0389

Browse files
committed
Backport and cleanup for TaxPointDate
1 parent 876f2e4 commit 10f0389

File tree

7 files changed

+49
-20
lines changed

7 files changed

+49
-20
lines changed

ZUGFeRD/DateTypeCodes.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ namespace s2industries.ZUGFeRD
2727
{
2828
public enum DateTypeCodes
2929
{
30-
/// <summary>
31-
/// Unknown means, we have a problem ...
32-
/// </summary>
33-
[EnumStringValue("")]
34-
Unknown = 0,
35-
3630
/// <summary>
3731
/// Date of invoice
3832
/// </summary>

ZUGFeRD/InvoiceDescriptor.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,19 +1258,15 @@ public void SetTotals(decimal? lineTotalAmount = null, decimal? chargeTotalAmoun
12581258
/// <param name="exemptionReasonCode">Tax exemption reason code</param>
12591259
/// <param name="exemptionReason">Tax exemption reason text</param>
12601260
/// <param name="lineTotalBasisAmount">Line total base amount for tax calculation</param>
1261-
/// <param name="taxPointDate">Value added tax point date</param>
1262-
/// <param name="dueDateTypeCode">Value added tax point date code</param>
1263-
public void AddApplicableTradeTax(decimal basisAmount,
1261+
public Tax AddApplicableTradeTax(decimal basisAmount,
12641262
decimal percent,
12651263
decimal taxAmount,
12661264
TaxTypes typeCode,
12671265
TaxCategoryCodes? categoryCode = null,
12681266
decimal? allowanceChargeBasisAmount = null,
12691267
TaxExemptionReasonCodes? exemptionReasonCode = null,
12701268
string exemptionReason = null,
1271-
decimal? lineTotalBasisAmount = null,
1272-
DateTime? taxPointDate = null,
1273-
DateTypeCodes? dueDateTypeCode = null)
1269+
decimal? lineTotalBasisAmount = null)
12741270
{
12751271
Tax tax = new Tax()
12761272
{
@@ -1281,9 +1277,7 @@ public void AddApplicableTradeTax(decimal basisAmount,
12811277
AllowanceChargeBasisAmount = allowanceChargeBasisAmount,
12821278
LineTotalBasisAmount = lineTotalBasisAmount,
12831279
ExemptionReasonCode = exemptionReasonCode,
1284-
ExemptionReason = exemptionReason,
1285-
TaxPointDate = taxPointDate,
1286-
DueDateTypeCode = dueDateTypeCode
1280+
ExemptionReason = exemptionReason
12871281
};
12881282

12891283
if ((categoryCode != null) && (categoryCode.Value != TaxCategoryCodes.Unknown))
@@ -1292,6 +1286,7 @@ public void AddApplicableTradeTax(decimal basisAmount,
12921286
}
12931287

12941288
this.Taxes.Add(tax);
1289+
return tax;
12951290
} // !AddApplicableTradeTax()
12961291

12971292

ZUGFeRD/InvoiceDescriptor20Reader.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ public override InvoiceDescriptor Load(Stream stream)
241241
XmlUtils.NodeAsDecimal(node, ".//ram:AllowanceChargeBasisAmount", nsmgr),
242242
EnumExtensions.StringToNullableEnum<TaxExemptionReasonCodes>(XmlUtils.NodeAsString(node, ".//ram:ExemptionReasonCode", nsmgr)),
243243
XmlUtils.NodeAsString(node, ".//ram:ExemptionReason", nsmgr),
244-
lineTotalBasisAmount: XmlUtils.NodeAsDecimal(node, ".//ram:LineTotalBasisAmount", nsmgr));
244+
lineTotalBasisAmount: XmlUtils.NodeAsDecimal(node, ".//ram:LineTotalBasisAmount", nsmgr))
245+
.SetTaxPointDate(XmlUtils.NodeAsDateTime(node, ".//ram:TaxPointDate/udt:DateString", nsmgr),
246+
EnumExtensions.StringToNullableEnum<DateTypeCodes>(XmlUtils.NodeAsString(node, ".//ram:DueDateTypeCode", nsmgr)));
245247
}
246248

247249
foreach (XmlNode node in doc.SelectNodes("//ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge", nsmgr))

ZUGFeRD/InvoiceDescriptor20Writer.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,20 @@ private void _writeOptionalTaxes(ProfileAwareXmlTextWriter writer)
10281028
writer.WriteElementString("ram", "ExemptionReasonCode", tax.ExemptionReasonCode?.EnumToString());
10291029
}
10301030

1031+
if (tax.TaxPointDate.HasValue)
1032+
{
1033+
Writer.WriteStartElement("ram", "TaxPointDate");
1034+
Writer.WriteStartElement("udt", "DateString");
1035+
Writer.WriteAttributeString("format", "102");
1036+
Writer.WriteValue(_formatDate(tax.TaxPointDate.Value));
1037+
Writer.WriteEndElement(); // !udt:DateString
1038+
Writer.WriteEndElement(); // !TaxPointDate
1039+
}
1040+
if (tax.TaxPointDate.HasValue)
1041+
{
1042+
Writer.WriteElementString("ram", "DueDateTypeCode", tax.DueDateTypeCode?.EnumToString());
1043+
}
1044+
10311045
writer.WriteElementString("ram", "RateApplicablePercent", _formatDecimal(tax.Percent));
10321046
writer.WriteEndElement(); // !ApplicableTradeTax
10331047
}

ZUGFeRD/InvoiceDescriptor23CIIReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ public override InvoiceDescriptor Load(Stream stream)
312312
XmlUtils.NodeAsDecimal(node, ".//ram:AllowanceChargeBasisAmount", nsmgr),
313313
EnumExtensions.StringToNullableEnum<TaxExemptionReasonCodes>(XmlUtils.NodeAsString(node, ".//ram:ExemptionReasonCode", nsmgr)),
314314
XmlUtils.NodeAsString(node, ".//ram:ExemptionReason", nsmgr),
315-
XmlUtils.NodeAsDecimal(node, ".//ram:LineTotalBasisAmount", nsmgr),
316-
XmlUtils.NodeAsDateTime(node, ".//ram:TaxPointDate/udt:DateString", nsmgr),
317-
EnumExtensions.StringToNullableEnum<DateTypeCodes>(XmlUtils.NodeAsString(node, ".//ram:DueDateTypeCode", nsmgr)));
315+
XmlUtils.NodeAsDecimal(node, ".//ram:LineTotalBasisAmount", nsmgr))
316+
.SetTaxPointDate(XmlUtils.NodeAsDateTime(node, ".//ram:TaxPointDate/udt:DateString", nsmgr),
317+
EnumExtensions.StringToNullableEnum<DateTypeCodes>(XmlUtils.NodeAsString(node, ".//ram:DueDateTypeCode", nsmgr)));
318318
}
319319

320320
foreach (XmlNode node in doc.SelectNodes("//ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradeAllowanceCharge", nsmgr))

ZUGFeRD/InvoiceDescriptor23CIIWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ private void _writeOptionalTaxes(ProfileAwareXmlTextWriter writer)
14931493
}
14941494

14951495
writer.WriteElementString("ram", "RateApplicablePercent", _formatDecimal(tax.Percent));
1496-
writer.WriteEndElement(); // !RateApplicablePercent
1496+
writer.WriteEndElement(); // !ApplicableTradeTax
14971497
});
14981498
} // !_writeOptionalTaxes()
14991499

ZUGFeRD/Tax.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
* under the License.
1818
*/
1919
using System;
20+
using System.ComponentModel;
21+
using System.Drawing;
22+
using System.Text.RegularExpressions;
23+
using System.Xml.Linq;
2024

2125
namespace s2industries.ZUGFeRD
2226
{
@@ -87,5 +91,25 @@ public class Tax
8791
/// </summary>
8892
public DateTypeCodes? DueDateTypeCode { get; set; }
8993

94+
95+
/// <summary>
96+
/// The tax point is usually the date goods were supplied or services completed (the 'basic tax point'). There are
97+
/// some variations.Please refer to Article 226 (7) of the Council Directive 2006/112/EC[2] for more information.
98+
/// This element is required if the Value added tax point date is different from the Invoice issue date.
99+
/// Both Buyer and Seller should use the Tax Point Date when provided by the Seller.The use of BT-7 and BT-8 is
100+
/// mutually exclusive.
101+
///
102+
/// BT-7
103+
///
104+
/// Use: The date when the VAT becomes accountable for the Seller and for the Buyer in so far as that date can be
105+
/// determined and differs from the date of issue of the invoice, according to the VAT directive.
106+
/// </summary>
107+
/// <param name="taxPointDate">Value added tax point date</param>
108+
/// <param name="dueDateTypeCode">Value added tax point date code</param>
109+
public void SetTaxPointDate(DateTime? taxPointDate = null, DateTypeCodes? dueDateTypeCode = null)
110+
{
111+
TaxPointDate = taxPointDate;
112+
DueDateTypeCode = dueDateTypeCode;
113+
} // !SetTaxPointDate()
90114
}
91115
}

0 commit comments

Comments
 (0)