Skip to content

Commit

Permalink
Refactoring enum mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanstapel committed Feb 16, 2025
1 parent 5be106d commit d7d722c
Show file tree
Hide file tree
Showing 30 changed files with 650 additions and 669 deletions.
99 changes: 89 additions & 10 deletions ZUGFeRD.Test/ZUGFeRD22Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void TestLineStatusCode()
Assert.AreEqual(loadedInvoice.TradeLineItems[1].AssociatedDocument.LineStatusReasonCode, null);
Assert.AreEqual(loadedInvoice.TradeLineItems[2].AssociatedDocument.LineStatusCode, LineStatusCodes.DocumentationClaim);
Assert.AreEqual(loadedInvoice.TradeLineItems[2].AssociatedDocument.LineStatusReasonCode, LineStatusReasonCodes.INFORMATION);
}
} // !TestLineStatusCode()


[TestMethod]
public void TestExtendedInvoiceWithIncludedItems()
Expand Down Expand Up @@ -137,7 +138,8 @@ public void TestExtendedInvoiceWithIncludedItems()
Assert.AreEqual(loadedInvoice.TradeLineItems[0].IncludedReferencedProducts[1].Name, "Test2");
Assert.AreEqual(loadedInvoice.TradeLineItems[0].IncludedReferencedProducts[1].UnitQuantity.HasValue, false);
Assert.AreEqual(loadedInvoice.TradeLineItems[0].IncludedReferencedProducts[1].UnitCode, null);
}
} // !TestExtendedInvoiceWithIncludedItems()


[TestMethod]
public void TestReferenceEReportingFacturXInvoice()
Expand All @@ -156,7 +158,8 @@ public void TestReferenceEReportingFacturXInvoice()
Assert.IsNull(desc.LineTotalAmount); // not present in file
Assert.AreEqual(desc.TaxBasisAmount, 198.0m);
Assert.AreEqual(desc.IsTest, false); // not present in file
}
} // !TestReferenceEReportingFacturXInvoice()


[TestMethod]
public void TestReferenceBasicFacturXInvoice()
Expand Down Expand Up @@ -867,7 +870,8 @@ public void TestWriteTradeLineBillingPeriod()
Assert.AreEqual(new DateTime(2021, 1, 1), secondTradeLineItem.BillingPeriodStart);
Assert.AreEqual(new DateTime(2022, 1, 1), secondTradeLineItem.BillingPeriodEnd);
}
}
} // !TestWriteTradeLineBillingPeriod()


[TestMethod]
public void TestWriteTradeLineBilledQuantity()
Expand All @@ -883,7 +887,7 @@ public void TestWriteTradeLineBilledQuantity()
// Modifiy trade line settlement data
originalInvoiceDescriptor.AddTradeLineItem(
name: String.Empty,
billedQuantity: 10,
billedQuantity: 10,
netUnitPrice: 1);

originalInvoiceDescriptor.IsTest = false;
Expand All @@ -897,7 +901,8 @@ public void TestWriteTradeLineBilledQuantity()
var invoiceDescriptor = InvoiceDescriptor.Load(memoryStream);
Assert.AreEqual(10, invoiceDescriptor.TradeLineItems[0].BilledQuantity);
}
}
} // !TestWriteTradeLineBilledQuantity()


[TestMethod]
public void TestWriteTradeLineChargeFreePackage()
Expand Down Expand Up @@ -925,9 +930,13 @@ public void TestWriteTradeLineChargeFreePackage()
// Load Invoice and compare to expected
var invoiceDescriptor = InvoiceDescriptor.Load(memoryStream);
Assert.AreEqual(10, invoiceDescriptor.TradeLineItems[0].ChargeFreeQuantity);
Assert.AreEqual(QuantityCodes.C62, invoiceDescriptor.TradeLineItems[0].ChargeFreeUnitCode);
Assert.AreEqual(20, invoiceDescriptor.TradeLineItems[0].PackageQuantity);
Assert.AreEqual(QuantityCodes.C62, invoiceDescriptor.TradeLineItems[0].PackageUnitCode);
}
}
} // !TestWriteTradeLineChargeFreePackage()


[TestMethod]
public void TestWriteTradeLineNetUnitPrice()
{
Expand All @@ -953,7 +962,8 @@ public void TestWriteTradeLineNetUnitPrice()
var invoiceDescriptor = InvoiceDescriptor.Load(memoryStream);
Assert.AreEqual(25, invoiceDescriptor.TradeLineItems[0].NetUnitPrice);
}
}
} // !TestWriteTradeLineNetUnitPrice()


[TestMethod]
public void TestWriteTradeLineLineID()
Expand Down Expand Up @@ -1002,6 +1012,7 @@ public void TestLoadingSepaPreNotification()

Assert.AreEqual("DE98ZZZ09999999999", invoiceDescriptor.PaymentMeans.SEPACreditorIdentifier);
Assert.AreEqual("REF A-123", invoiceDescriptor.PaymentMeans.SEPAMandateReference);
Assert.AreEqual(PaymentMeansTypeCodes.SEPADirectDebit, invoiceDescriptor.PaymentMeans.TypeCode);
Assert.AreEqual(1, invoiceDescriptor.DebitorBankAccounts.Count);
Assert.AreEqual("DE21860000000086001055", invoiceDescriptor.DebitorBankAccounts[0].IBAN);

Expand Down Expand Up @@ -1108,12 +1119,13 @@ public void TestStoringSepaPreNotification()
stream.Seek(0, SeekOrigin.Begin);

var d2 = InvoiceDescriptor.Load(stream);
Assert.AreEqual(d2.Currency, CurrencyCodes.EUR);
Assert.AreEqual("DE98ZZZ09999999999", d2.PaymentMeans.SEPACreditorIdentifier);
Assert.AreEqual("REF A-123", d2.PaymentMeans.SEPAMandateReference);
Assert.AreEqual(1, d2.DebitorBankAccounts.Count);
Assert.AreEqual("DE21860000000086001055", d2.DebitorBankAccounts[0].IBAN);
Assert.IsTrue(d.Seller.SpecifiedLegalOrganization.ID.SchemeID.HasValue);
Assert.AreEqual("0088", d.Seller.SpecifiedLegalOrganization.ID.SchemeID.Value.EnumToString());
Assert.AreEqual(GlobalIDSchemeIdentifiers.GLN, d.Seller.SpecifiedLegalOrganization.ID.SchemeID.Value);
Assert.AreEqual("4000001123452", d.Seller.SpecifiedLegalOrganization.ID.ID);
Assert.AreEqual("Lieferant GmbH", d.Seller.SpecifiedLegalOrganization.TradingBusinessName);
}
Expand Down Expand Up @@ -2252,10 +2264,13 @@ public void TestAltteilSteuer()
MemoryStream ms = new MemoryStream();

desc.Save(ms, ZUGFeRDVersion.Version23, Profile.XRechnung);
desc.Save("e:\\output.xml", ZUGFeRDVersion.Version23, Profile.XRechnung);
ms.Seek(0, SeekOrigin.Begin);

InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
Assert.AreEqual(loadedInvoice.Invoicee, null);
Assert.AreEqual(loadedInvoice.GetNotes().First().SubjectCode, SubjectCodes.ADU);
Assert.AreEqual(loadedInvoice.GetNotes().First().ContentCode, ContentCodes.Unknown);
} // !TestAltteilSteuer()

[TestMethod]
Expand Down Expand Up @@ -3178,6 +3193,7 @@ public void TestInvoiceExemptions()

} // !TestInvoiceExemptions()


[TestMethod]
public void TestOriginTradeCountry()
{
Expand All @@ -3193,7 +3209,70 @@ public void TestOriginTradeCountry()
InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
List<TradeLineItem> items = loadedInvoice.GetTradeLineItems();

Assert.AreEqual(items[0].OriginTradeCountry.ToString(), "DE");
Assert.IsNotNull(items[0].OriginTradeCountry);
Assert.AreEqual(items[0].OriginTradeCountry, CountryCodes.DE);
} // !TestOriginTradeCountry()


[TestMethod]
public void TestLoadingCurrency()
{
string path = @"..\..\..\..\demodata\zugferd21\zugferd_2p1_EXTENDED_Warenrechnung-factur-x.xml";
path = _makeSurePathIsCrossPlatformCompatible(path);

Stream s = File.Open(path, FileMode.Open);
InvoiceDescriptor desc = InvoiceDescriptor.Load(s);
s.Close();

Assert.AreEqual(desc.Currency, CurrencyCodes.EUR);
Assert.AreEqual(desc.TaxCurrency, null);
} // !TestLoadingCurrency()


[TestMethod]
public void TestLoadingSellerCountry()
{
string path = @"..\..\..\..\demodata\zugferd21\zugferd_2p1_EXTENDED_Warenrechnung-factur-x.xml";
path = _makeSurePathIsCrossPlatformCompatible(path);

Stream s = File.Open(path, FileMode.Open);
InvoiceDescriptor desc = InvoiceDescriptor.Load(s);
s.Close();

Assert.AreEqual(desc.Seller.Country, CountryCodes.DE);
} // !TestLoadingSellerCountry()


[TestMethod]
public void TestLoadingBuyerCountry()
{
string path = @"..\..\..\..\demodata\zugferd21\zugferd_2p1_EXTENDED_Warenrechnung-factur-x.xml";
path = _makeSurePathIsCrossPlatformCompatible(path);

Stream s = File.Open(path, FileMode.Open);
InvoiceDescriptor desc = InvoiceDescriptor.Load(s);
s.Close();

Assert.AreEqual(desc.Buyer.Country, CountryCodes.DE);
} // !TestLoadingSellerCountry()


[TestMethod]
public void TestLoadingInvoiceType()
{
// load standrd invoice
string path = @"..\..\..\..\demodata\zugferd21\zugferd_2p1_EXTENDED_Warenrechnung-factur-x.xml";
path = _makeSurePathIsCrossPlatformCompatible(path);
InvoiceDescriptor desc = InvoiceDescriptor.Load(path);

Assert.AreEqual(desc.Type, InvoiceType.Invoice);

// load correction
path = @"..\..\..\..\documentation\zugferd23en\Examples\4. EXTENDED\EXTENDED_Rechnungskorrektur\factur-x.xml";
path = _makeSurePathIsCrossPlatformCompatible(path);
desc = InvoiceDescriptor.Load(path);

Assert.AreEqual(desc.Type, InvoiceType.Correction);
} // !TestLoadingInvoiceType()
}
}
104 changes: 104 additions & 0 deletions ZUGFeRD.Test/ZUGFeRDCrossVersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,110 @@ public void TestAutomaticLineIds()
} // !TestAutomaticLineIds()


[TestMethod]
[DataRow(ZUGFeRDVersion.Version1, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version20, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version23, Profile.Extended)]
public void TestNoteContentCodes(ZUGFeRDVersion version, Profile profile)
{
InvoiceDescriptor desc = this._InvoiceProvider.CreateInvoice();
desc.Notes.Clear();
desc.AddNote("EEV", SubjectCodes.Unknown, ContentCodes.EEV);
desc.AddNote("WEV", SubjectCodes.Unknown, ContentCodes.WEV);
desc.AddNote("ST1", SubjectCodes.Unknown, ContentCodes.ST1);
desc.AddNote("ST2", SubjectCodes.Unknown, ContentCodes.ST2);
desc.AddNote("ST3", SubjectCodes.Unknown, ContentCodes.ST3);
desc.AddNote("VEV", SubjectCodes.Unknown, ContentCodes.VEV);

using MemoryStream ms = new();
desc.Save(ms, version, profile);
ms.Seek(0, SeekOrigin.Begin);

InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);

List<Note> notes = loadedInvoice.GetNotes();
Assert.AreEqual(notes[0].ContentCode, ContentCodes.EEV);
Assert.AreEqual(notes[1].ContentCode, ContentCodes.WEV);
Assert.AreEqual(notes[2].ContentCode, ContentCodes.ST1);
Assert.AreEqual(notes[3].ContentCode, ContentCodes.ST2);
Assert.AreEqual(notes[4].ContentCode, ContentCodes.ST3);
Assert.AreEqual(notes[5].ContentCode, ContentCodes.VEV);
} // !TestNoteContentCodes()


[TestMethod]
[DataRow(ZUGFeRDVersion.Version1, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version20, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version23, Profile.Extended)]
public void TestNoteSubjectCodes(ZUGFeRDVersion version, Profile profile)
{
InvoiceDescriptor desc = this._InvoiceProvider.CreateInvoice();
desc.Notes.Clear();
desc.AddNote("ACB", SubjectCodes.ACB, ContentCodes.Unknown);
desc.AddNote("AAI", SubjectCodes.AAI, ContentCodes.Unknown);
desc.AddNote("PRF", SubjectCodes.PRF, ContentCodes.Unknown);
desc.AddNote("REG", SubjectCodes.REG, ContentCodes.Unknown);
desc.AddNote("SUR", SubjectCodes.SUR, ContentCodes.Unknown);
desc.AddNote("TXD", SubjectCodes.TXD, ContentCodes.Unknown);

using MemoryStream ms = new();
desc.Save(ms, version, profile);
ms.Seek(0, SeekOrigin.Begin);

InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);

List<Note> notes = loadedInvoice.GetNotes();
Assert.AreEqual(notes[0].SubjectCode, SubjectCodes.ACB);
Assert.AreEqual(notes[1].SubjectCode, SubjectCodes.AAI);
Assert.AreEqual(notes[2].SubjectCode, SubjectCodes.PRF);
Assert.AreEqual(notes[3].SubjectCode, SubjectCodes.REG);
Assert.AreEqual(notes[4].SubjectCode, SubjectCodes.SUR);
Assert.AreEqual(notes[5].SubjectCode, SubjectCodes.TXD);
} // !TestNoteSubjectCodes()


[TestMethod]
[DataRow(ZUGFeRDVersion.Version1, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version20, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version23, Profile.Extended)]
public void TestKosovoCountryCode(ZUGFeRDVersion version, Profile profile)
{
InvoiceDescriptor desc = this._InvoiceProvider.CreateInvoice();
desc.Seller = new Party()
{
Country = CountryCodes._1A,
};

using MemoryStream ms = new();
desc.Save(ms, version, profile);
ms.Seek(0, SeekOrigin.Begin);

InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
Assert.AreEqual(loadedInvoice.Seller.Country, CountryCodes._1A);
} // !TestKosovoCountryCode()



[TestMethod]
[DataRow(ZUGFeRDVersion.Version1, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version20, Profile.Extended)]
[DataRow(ZUGFeRDVersion.Version23, Profile.Extended)]
public void TestStandardCountryCode(ZUGFeRDVersion version, Profile profile)
{
InvoiceDescriptor desc = this._InvoiceProvider.CreateInvoice();
desc.Seller = new Party()
{
Country = CountryCodes.US,
};

using MemoryStream ms = new();
desc.Save(ms, version, profile);
ms.Seek(0, SeekOrigin.Begin);

InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms);
Assert.AreEqual(loadedInvoice.Seller.Country, CountryCodes.US);
} // !TestStandardCountryCode()


[TestMethod]
public void TestManualLineIds()
Expand Down
28 changes: 13 additions & 15 deletions ZUGFeRD/AccountingAccountTypeCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,43 @@ public enum AccountingAccountTypeCodes
/// <summary>
/// The code indicates a financial account
/// </summary>
[EnumStringValue("1")]
Financial = 1,

/// <summary>
/// The code indicates a subsidiary account
/// </summary>
[EnumStringValue("2")]
Subsidiary = 2,

/// <summary>
/// The code indicates a budget account
/// </summary>
[EnumStringValue("3")]
Budget = 3,

/// <summary>
/// The code indicates a cost accounting account
/// </summary>
[EnumStringValue("4")]
Cost_Accounting = 4,

/// <summary>
/// The code indicates a receivable account
/// </summary>
[EnumStringValue("5")]
Receivable = 5,

/// <summary>
/// The code indicates a payable account
/// </summary>
[EnumStringValue("6")]
Payable = 6,

/// <summary>
/// The code indicates a job cost accounting
/// </summary>
[EnumStringValue("7")]
Job_Cost_Accounting = 7
}


internal static class AccountingAccountTypeCodesExtensions
{
public static AccountingAccountTypeCodes FromString(this AccountingAccountTypeCodes _, string s)
{
return EnumExtensions.StringToEnum<AccountingAccountTypeCodes>(s);
} // !FromString()


public static string EnumToString(this AccountingAccountTypeCodes c)
{
return EnumExtensions.EnumToString<AccountingAccountTypeCodes>(c);
} // !ToString()
}
}
Loading

0 comments on commit d7d722c

Please sign in to comment.