diff --git a/ZUGFeRD-Test/Application.cs b/ZUGFeRD-Test/Application.cs deleted file mode 100644 index ae3f197c..00000000 --- a/ZUGFeRD-Test/Application.cs +++ /dev/null @@ -1,460 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -using s2industries.ZUGFeRD; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; - -namespace ZUGFeRD_Test -{ - class Application - { - internal void Run() - { - InvoiceDescriptor desc = _createInvoice(); - desc.Save("xrechnung.xml", ZUGFeRDVersion.Version21, Profile.XRechnung); - - // --- ZUGFeRD 2.0x tests --- - - // load demo data - //_loadZUGFeRD2EinfachInvoice(); - //_loadZUGFeRD2ExtendedInvoice(); - - _loadZUGFeRD21BasicInvoice(); - //_loadZUGFeRD21BasicWLInvoice(); - //_loadZUGFeRD21ExtendedInvoice(); - //_loadZUGFeRD21MinimumInvoice(); - - //_loadXRechnungCII(); - - _loadSaveLoadZUGFeRD21BasicInvoice(); - - // --- ZUGFeRD 1.x tests --- - ZugFerd1ComfortEinfachGenerator generator = new ZugFerd1ComfortEinfachGenerator(); - generator.generate(); - generator.read(); - - ZugFerd1ExtendedWarenrechnungGenerator generator2 = new ZugFerd1ExtendedWarenrechnungGenerator(); - generator2.generate(); - generator2.read(); - - _loadZUGFeRD1EinfachOriginalInvoice(); - _loadZUGFeRD1ComfortRabatteInvoice(); - - _saveAndLoadZUGFeRD1Invoice(); - _saveAndLoadZUGFeRD1InvoiceViaStream(); - - _createAndSaveXRechnungWithAttachment(); - } // !run() - - - private void _loadZUGFeRD21BasicInvoice() - { - string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_BASIC_Einfach-factur-x.xml"; - - Stream s = File.Open(path, FileMode.Open); - InvoiceDescriptor desc = InvoiceDescriptor.Load(s); - s.Close(); - - Assert.AreEqual(desc.Profile, Profile.Basic); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "471102"); - Assert.AreEqual(desc.TradeLineItems.Count, 1); - Assert.AreEqual(desc.LineTotalAmount, 198.0m); - } // !_loadZUGFeRD21BasicInvoice() - - - private void _loadSaveLoadZUGFeRD21BasicInvoice() - { - string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_BASIC_Einfach-factur-x.xml"; - - Stream s = File.Open(path, FileMode.Open); - InvoiceDescriptor originalDesc = InvoiceDescriptor.Load(s); - s.Close(); - - Assert.AreEqual(originalDesc.Profile, Profile.Basic); - Assert.AreEqual(originalDesc.Type, InvoiceType.Invoice); - Assert.AreEqual(originalDesc.InvoiceNo, "471102"); - Assert.AreEqual(originalDesc.TradeLineItems.Count, 1); - Assert.AreEqual(originalDesc.LineTotalAmount, 198.0m); - Assert.AreEqual(originalDesc.Taxes[0].TaxAmount, 37.62m); - Assert.AreEqual(originalDesc.Taxes[0].Percent, 19.0m); - originalDesc.IsTest = false; - - Stream ms = new MemoryStream(); - originalDesc.Save(ms, ZUGFeRDVersion.Version21, Profile.Basic); - originalDesc.Save(@"zugferd_2p1_BASIC_Einfach-factur-x_Result.xml", ZUGFeRDVersion.Version21); - - InvoiceDescriptor desc = InvoiceDescriptor.Load(ms); - - Assert.AreEqual(desc.Profile, Profile.Basic); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "471102"); - Assert.AreEqual(desc.TradeLineItems.Count, 1); - Assert.AreEqual(desc.LineTotalAmount, 198.0m); - Assert.AreEqual(desc.Taxes[0].TaxAmount, 37.62m); - Assert.AreEqual(desc.Taxes[0].Percent, 19.0m); - } // !_loadZUGFeRD21BasicInvoice() - - - private void _loadZUGFeRD21BasicWLInvoice() - { - - string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_BASIC-WL_Einfach-factur-x.xml"; - - Stream s = File.Open(path, FileMode.Open); - InvoiceDescriptor desc = InvoiceDescriptor.Load(s); - s.Close(); - - Assert.AreEqual(desc.Profile, Profile.BasicWL); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "471102"); - Assert.AreEqual(desc.TradeLineItems.Count, 0); - Assert.AreEqual(desc.LineTotalAmount, 624.90m); - } // !_loadZUGFeRD21BasicWLInvoice() - - - private void _loadZUGFeRD21ExtendedInvoice() - { - string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_EXTENDED_Warenrechnung-factur-x.xml"; - - Stream s = File.Open(path, FileMode.Open); - InvoiceDescriptor desc = InvoiceDescriptor.Load(s); - s.Close(); - - Assert.AreEqual(desc.Profile, Profile.Extended); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "R87654321012345"); - Assert.AreEqual(desc.TradeLineItems.Count, 6); - Assert.AreEqual(desc.LineTotalAmount, 457.20m); - } // !_loadZUGFeRD21ExtendedInvoice() - - - private void _loadZUGFeRD21MinimumInvoice() - { - string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_MINIMUM_Rechnung-factur-x.xml"; - - Stream s = File.Open(path, FileMode.Open); - InvoiceDescriptor desc = InvoiceDescriptor.Load(s); - s.Close(); - - Assert.AreEqual(desc.Profile, Profile.Minimum); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "471102"); - Assert.AreEqual(desc.TradeLineItems.Count, 0); - Assert.AreEqual(desc.LineTotalAmount, 0.0m); // not present in file - Assert.AreEqual(desc.TaxBasisAmount, 198.0m); - } // !_loadZUGFeRD21MinimumInvoice() - - - private void _loadXRechnungCII() - { - string path = @"..\..\..\demodata\xRechnung\xRechnung CII.xml"; - InvoiceDescriptor desc = InvoiceDescriptor.Load(path); - - Assert.AreEqual(desc.Profile, Profile.XRechnung); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "0815-99-1-a"); - Assert.AreEqual(desc.TradeLineItems.Count, 2); - Assert.AreEqual(desc.LineTotalAmount, 1445.98m); - } // !_loadZUGFeRD1EinfachOriginalInvoice() - - - private void _loadZUGFeRD2EinfachInvoice() - { - string path = @"..\..\..\demodata\zugferd20\zugferd_2p0_BASIC_Einfach.xml"; - - Stream s = File.Open(path, FileMode.Open); - InvoiceDescriptor desc = InvoiceDescriptor.Load(s); - s.Close(); - - Assert.AreEqual(desc.Profile, Profile.Basic); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "471102"); - Assert.AreEqual(desc.TradeLineItems.Count, 1); - Assert.AreEqual(desc.LineTotalAmount, 198.0m); - } // !_loadZUGFeRD2EinfachInvoice() - - - private void _loadZUGFeRD2ExtendedInvoice() - { - string path = @"..\..\..\demodata\zugferd20\zugferd_2p0_EXTENDED_Warenrechnung.xml"; - - Stream s = File.Open(path, FileMode.Open); - InvoiceDescriptor desc = InvoiceDescriptor.Load(s); - s.Close(); - - Assert.AreEqual(desc.Profile, Profile.Extended); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.InvoiceNo, "R87654321012345"); - Assert.AreEqual(desc.TradeLineItems.Count, 6); - Assert.AreEqual(desc.LineTotalAmount, 457.20m); - } // !_loadZUGFeRD2ExtendedInvoice() - - - private void _loadZUGFeRD1EinfachOriginalInvoice() - { - string path = @"..\..\..\demodata\zugferd10\ZUGFeRD_1p0_COMFORT_Einfach.xml"; - InvoiceDescriptor desc = InvoiceDescriptor.Load(path); - - Assert.AreEqual(desc.Profile, Profile.Comfort); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - } // !_loadZUGFeRD1EinfachOriginalInvoice() - - - private void _loadZUGFeRD1ComfortRabatteInvoice() - { - string path = @"..\..\..\demodata\zugferd10\ZUGFeRD_1p0_COMFORT_Rabatte.xml"; - InvoiceDescriptor desc = InvoiceDescriptor.Load(path); - - desc.Save("test.xml", ZUGFeRDVersion.Version1, Profile.Comfort); - - Assert.AreEqual(desc.Profile, Profile.Comfort); - Assert.AreEqual(desc.Type, InvoiceType.Invoice); - Assert.AreEqual(desc.CreditorBankAccounts[0].BankName, "Hausbank München"); - } // !_loadZUGFeRDComfortRabatteInvoice() - - - private void _saveAndLoadZUGFeRD1Invoice() - { - string path = "output.xml"; - InvoiceDescriptor desc = _createInvoice(); - desc.Save(path, ZUGFeRDVersion.Version1, Profile.Comfort); - - InvoiceDescriptor desc2 = InvoiceDescriptor.Load(path); - } // !_saveAndLoadZUGFeRD1Invoice() - - - private void _saveAndLoadZUGFeRD1InvoiceViaStream() - { - InvoiceDescriptor desc = _createInvoice(); - - string path = "output_stream.xml"; - FileStream saveStream = new FileStream(path, FileMode.Create); - desc.Save(saveStream, ZUGFeRDVersion.Version1, Profile.Comfort); - saveStream.Close(); - - FileStream loadStream = new FileStream(path, FileMode.Open); - InvoiceDescriptor desc2 = InvoiceDescriptor.Load(loadStream); - loadStream.Close(); - - Assert.AreEqual(desc2.Profile, Profile.Comfort); - Assert.AreEqual(desc2.Type, InvoiceType.Invoice); - - - // try again with a memory stream - MemoryStream ms = new MemoryStream(); - desc.Save(ms, ZUGFeRDVersion.Version1, Profile.Comfort); - - byte[] data = ms.ToArray(); - string s = System.Text.Encoding.Default.GetString(data); - } // !_saveAndLoadZUGFeRD1InvoiceViaStream() - - - private void _createAndSaveXRechnungWithAttachment() - { - InvoiceDescriptor desc = _createInvoice(); - byte[] data = System.IO.File.ReadAllBytes("ZUGFeRD-Test.exe"); - desc.AddAdditionalReferencedDocument( - issuerAssignedID: "My-File", - typeCode: AdditionalReferencedDocumentTypeCode.ReferenceDocument, - name: "Ausführbare Datei", - attachmentBinaryObject: data, - filename: "ZUGFeRD-Test.exe"); - - - string filename = "xrechnung-with-attachment.xml"; - desc.Save(filename, ZUGFeRDVersion.Version21, Profile.XRechnung); - InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(filename); - } // !_createAndSaveXRechnungWithAttachment() - - - - private InvoiceDescriptor _createInvoice() - { - InvoiceDescriptor desc = InvoiceDescriptor.CreateInvoice("471102", new DateTime(2018, 03, 05), CurrencyCodes.EUR); - desc.AddNote("Rechnung gemäß Bestellung vom 01.03.2018."); - desc.AddNote(note: "Lieferant GmbH\r\nLieferantenstraße 20\r\n80333 München\r\nDeutschland\r\nGeschäftsführer: Hans Muster\r\nHandelsregisternummer: H A 123\r\n", - subjectCode: SubjectCodes.REG - ); - - desc.AddTradeLineItem(name: "Trennblätter A4", - unitCode: QuantityCodes.H87, - sellerAssignedID: "TB100A4", - id: new GlobalID("0160", "4012345001235"), - grossUnitPrice: 9.9m, - netUnitPrice: 9.9m, - billedQuantity: 20m, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent:19m - ); - - desc.AddTradeLineItem(name: "Joghurt Banane", - unitCode: QuantityCodes.H87, - sellerAssignedID: "ARNR2", - id: new GlobalID("0160", "4000050986428"), - grossUnitPrice: 5.5m, - netUnitPrice: 5.5m, - billedQuantity: 50, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 7 - ); - - desc.ReferenceOrderNo = "04011000-12345-34"; - desc.SetSeller(name: "Lieferant GmbH", - postcode: "80333", - city: "München", - street: "Lieferantenstraße 20", - country: CountryCodes.DE, - id: "", - globalID: new GlobalID("0088", "4000001123452") - ); - desc.SetSellerContact(name: "Max Mustermann", - orgunit: "Muster-Einkauf", - emailAddress: "Max@Mustermann.de", - phoneno: "+49891234567" - ); - desc.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC); - desc.AddSellerTaxRegistration("DE123456789", TaxRegistrationSchemeID.VA); - - desc.SetBuyer(name: "Kunden AG Mitte", - postcode: "69876", - city: "Frankfurt", - street: "Kundenstraße 15", - country: CountryCodes.DE, - id: "GE2020211" - ); - - desc.ActualDeliveryDate = new DateTime(2018, 03, 05); - desc.SetPaymentMeans(PaymentMeansTypeCodes.SEPACreditTransfer, "Zahlung per SEPA Überweisung."); - desc.AddCreditorFinancialAccount(iban: "DE02120300000000202051", bic: "BYLADEM1001", name: "Kunden AG"); - - desc.AddApplicableTradeTax(basisAmount: 275.0m, - percent: 7m, - typeCode: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S - ); - - desc.AddApplicableTradeTax(basisAmount: 198.0m, - percent: 19m, - typeCode: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S - ); - - desc.SetTradePaymentTerms("Zahlbar innerhalb 30 Tagen netto bis 04.04.2018, 3% Skonto innerhalb 10 Tagen bis 15.03.2018"); - desc.SetTotals(lineTotalAmount: 473.0m, - chargeTotalAmount: 0.0m, - allowanceTotalAmount: 0.0m, - taxBasisAmount: 473.0m, - taxTotalAmount: 56.87m, - grandTotalAmount: 529.87m, - totalPrepaidAmount: 0.0m, - duePayableAmount: 529.87m - ); - - return desc; - } // !_createInvoice() - - - private InvoiceDescriptor _createInvoiceOld() - { - InvoiceDescriptor desc = InvoiceDescriptor.CreateInvoice("471102", new DateTime(2013, 6, 5), CurrencyCodes.EUR, "GE2020211-471102"); - desc.ReferenceOrderNo = "AB-312"; - desc.AddNote("Rechnung gemäß Bestellung Nr. 2013-471331 vom 01.03.2013."); - desc.AddNote("Es bestehen Rabatt- und Bonusvereinbarungen.", SubjectCodes.AAK); - desc.SetBuyer("Kunden Mitte AG", "69876", "Frankfurt", "Kundenstraße 15", CountryCodes.DE, "GE2020211", new GlobalID(GlobalID.SchemeID_GLN, "4000001987658")); - desc.AddBuyerTaxRegistration("DE234567890", TaxRegistrationSchemeID.VA); - desc.SetBuyerContact("Hans Muster"); - desc.SetSeller("Lieferant GmbH", "80333", "München", "Lieferantenstraße 20", CountryCodes.DE, "", new GlobalID(GlobalID.SchemeID_GLN, "4000001123452")); - desc.SetSellerContact("Frau Mustermann", "Vertrieb", "mustermann@lieferant.internal", "0049-89-12345678"); - desc.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC); - desc.AddSellerTaxRegistration("DE123456789", TaxRegistrationSchemeID.VA); - desc.SetBuyerOrderReferenceDocument("2013-471331", new DateTime(2013, 03, 01)); - desc.SetDeliveryNoteReferenceDocument("2013-51111", new DateTime(2013, 6, 3)); - desc.ActualDeliveryDate = new DateTime(2013, 6, 3); - desc.SetTotals(lineTotalAmount: 147.30m, - chargeTotalAmount: 0m, - allowanceTotalAmount: 14.73m, - taxBasisAmount: 132.57m, - taxTotalAmount: 10.36m, - grandTotalAmount: 142.93m, - totalPrepaidAmount: 50m, - duePayableAmount: 92.93m); - desc.AddApplicableTradeTax(123.57m, 7m, TaxTypes.VAT, TaxCategoryCodes.S); - desc.AddApplicableTradeTax(9m, 19m, TaxTypes.VAT, TaxCategoryCodes.S); - desc.AddLogisticsServiceCharge(5.80m, "Versandkosten", TaxTypes.VAT, TaxCategoryCodes.S, 7m); - desc.AddTradeAllowanceCharge(true, 10m, CurrencyCodes.EUR, 1m, "Sondernachlass", TaxTypes.VAT, TaxCategoryCodes.S, 19); - desc.AddTradeAllowanceCharge(true, 137.7m, CurrencyCodes.EUR, 13.73m, "Sondernachlass", TaxTypes.VAT, TaxCategoryCodes.S, 7); - desc.SetTradePaymentTerms("Zahlbar innerhalb 30 Tagen netto bis 04.07.2013, 3% Skonto innerhalb 10 Tagen bis 15.06.2013", new DateTime(2013, 07, 04)); - - desc.SetPaymentMeans(PaymentMeansTypeCodes.PaymentToBankAccount, "Überweisung"); - desc.AddCreditorFinancialAccount("DE08700901001234567890", "GENODEF1M04", "1234567890", "70090100", "Hausbank München"); - - desc.AddTradeLineCommentItem("Wir erlauben uns Ihnen folgende Positionen aus der Lieferung Nr. 2013-51112 in Rechnung zu stellen:"); - desc.AddTradeLineItem(name: "Kunstrasen grün 3m breit", - description: "300cm x 100 cm", - unitCode: QuantityCodes.MTK, - unitQuantity: 1, - grossUnitPrice: 4.00m, - netUnitPrice: 3.3333m, - billedQuantity: 3, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 19, - id: new GlobalID(GlobalID.SchemeID_EAN, "4012345001235"), - sellerAssignedID: "KR3M", - buyerAssignedID: "55T01"); - - desc.AddTradeLineItem(name: "Schweinesteak", - description: "aus Deutschland", - unitCode: QuantityCodes.KGM, - unitQuantity: 1, - grossUnitPrice: 5.50m, - netUnitPrice: 5.50m, - billedQuantity: 5, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 7, - id: new GlobalID(GlobalID.SchemeID_EAN, "4000050986428"), - sellerAssignedID: "SFK5", - buyerAssignedID: "55T02"); - - - desc.AddTradeLineItem(name: "Mineralwasser Medium 12 x 1,0l PET", - description: "", - unitCode: QuantityCodes.C62, - unitQuantity: 1, - grossUnitPrice: 5.49m, - netUnitPrice: 5.49m, - billedQuantity: 20, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 7, - id: new GlobalID(GlobalID.SchemeID_EAN, "4000001234561"), - sellerAssignedID: "GTRWA5", - buyerAssignedID: "55T03", - buyerOrderID: "123"); - return desc; - } // _createInvoiceOld() - } -} diff --git a/ZUGFeRD-Test/Assert.cs b/ZUGFeRD-Test/Assert.cs deleted file mode 100644 index ef82f80b..00000000 --- a/ZUGFeRD-Test/Assert.cs +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ZUGFeRD_Test -{ - public class Assert - { - public static bool AreEqual(object o1, object o2) - { - if (!o1.Equals(o2)) - { - throw new Exception(); - } - return true; - } - - - public static bool AreEqual(decimal d1, decimal d2) - { - if (d1 != d2) - { - throw new Exception(); - } - return true; - } - } -} diff --git a/ZUGFeRD-Test/BasicTests.cs b/ZUGFeRD-Test/BasicTests.cs new file mode 100644 index 00000000..5d5322cd --- /dev/null +++ b/ZUGFeRD-Test/BasicTests.cs @@ -0,0 +1,42 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using s2industries.ZUGFeRD; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ZUGFeRD_Test +{ + [TestClass] + public class BasicTests + { + InvoiceProvider InvoiceProvider = new InvoiceProvider(); + + + [TestMethod] + public void TestAutomaticLineIds() + { + InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); + desc.TradeLineItems.Clear(); + + desc.AddTradeLineItem("Item1"); + desc.AddTradeLineItem("Item2"); + + Assert.AreEqual(desc.TradeLineItems[0].AssociatedDocument.LineID, "1"); + Assert.AreEqual(desc.TradeLineItems[1].AssociatedDocument.LineID, "2"); + } // !TestAutomaticLineIds() + + + + [TestMethod] + void TestManualLineIds() + { + InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); + desc.TradeLineItems.Clear(); + desc.AddTradeLineItem(lineID: "item-01", "Item1"); + desc.AddTradeLineItem(lineID: "item-02", "Item2"); + + Assert.AreEqual(desc.TradeLineItems[0].AssociatedDocument.LineID, "item-01"); + Assert.AreEqual(desc.TradeLineItems[1].AssociatedDocument.LineID, "item-02"); + } // !TestManualLineIds() + } +} diff --git a/ZUGFeRD-Test/InvoiceProvider.cs b/ZUGFeRD-Test/InvoiceProvider.cs new file mode 100644 index 00000000..cfe653af --- /dev/null +++ b/ZUGFeRD-Test/InvoiceProvider.cs @@ -0,0 +1,99 @@ +using s2industries.ZUGFeRD; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZUGFeRD_Test +{ + internal class InvoiceProvider + { + internal InvoiceDescriptor CreateInvoice() + { + InvoiceDescriptor desc = InvoiceDescriptor.CreateInvoice("471102", new DateTime(2018, 03, 05), CurrencyCodes.EUR); + desc.AddNote("Rechnung gemäß Bestellung vom 01.03.2018."); + desc.AddNote(note: "Lieferant GmbH\r\nLieferantenstraße 20\r\n80333 München\r\nDeutschland\r\nGeschäftsführer: Hans Muster\r\nHandelsregisternummer: H A 123\r\n", + subjectCode: SubjectCodes.REG + ); + + desc.AddTradeLineItem(name: "Trennblätter A4", + unitCode: QuantityCodes.H87, + sellerAssignedID: "TB100A4", + id: new GlobalID("0160", "4012345001235"), + grossUnitPrice: 9.9m, + netUnitPrice: 9.9m, + billedQuantity: 20m, + taxType: TaxTypes.VAT, + categoryCode: TaxCategoryCodes.S, + taxPercent: 19m + ); + + desc.AddTradeLineItem(name: "Joghurt Banane", + unitCode: QuantityCodes.H87, + sellerAssignedID: "ARNR2", + id: new GlobalID("0160", "4000050986428"), + grossUnitPrice: 5.5m, + netUnitPrice: 5.5m, + billedQuantity: 50, + taxType: TaxTypes.VAT, + categoryCode: TaxCategoryCodes.S, + taxPercent: 7 + ); + + desc.ReferenceOrderNo = "04011000-12345-34"; + desc.SetSeller(name: "Lieferant GmbH", + postcode: "80333", + city: "München", + street: "Lieferantenstraße 20", + country: CountryCodes.DE, + id: "", + globalID: new GlobalID("0088", "4000001123452") + ); + desc.SetSellerContact(name: "Max Mustermann", + orgunit: "Muster-Einkauf", + emailAddress: "Max@Mustermann.de", + phoneno: "+49891234567" + ); + desc.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC); + desc.AddSellerTaxRegistration("DE123456789", TaxRegistrationSchemeID.VA); + + desc.SetBuyer(name: "Kunden AG Mitte", + postcode: "69876", + city: "Frankfurt", + street: "Kundenstraße 15", + country: CountryCodes.DE, + id: "GE2020211" + ); + + desc.ActualDeliveryDate = new DateTime(2018, 03, 05); + desc.SetPaymentMeans(PaymentMeansTypeCodes.SEPACreditTransfer, "Zahlung per SEPA Überweisung."); + desc.AddCreditorFinancialAccount(iban: "DE02120300000000202051", bic: "BYLADEM1001", name: "Kunden AG"); + + desc.AddApplicableTradeTax(basisAmount: 275.0m, + percent: 7m, + typeCode: TaxTypes.VAT, + categoryCode: TaxCategoryCodes.S + ); + + desc.AddApplicableTradeTax(basisAmount: 198.0m, + percent: 19m, + typeCode: TaxTypes.VAT, + categoryCode: TaxCategoryCodes.S + ); + + desc.SetTradePaymentTerms("Zahlbar innerhalb 30 Tagen netto bis 04.04.2018, 3% Skonto innerhalb 10 Tagen bis 15.03.2018"); + desc.SetTotals(lineTotalAmount: 473.0m, + chargeTotalAmount: 0.0m, + allowanceTotalAmount: 0.0m, + taxBasisAmount: 473.0m, + taxTotalAmount: 56.87m, + grandTotalAmount: 529.87m, + totalPrepaidAmount: 0.0m, + duePayableAmount: 529.87m + ); + + return desc; + } // !CreateInvoice() + } +} diff --git a/ZUGFeRD-Test/Program.cs b/ZUGFeRD-Test/Program.cs deleted file mode 100644 index 63e474ab..00000000 --- a/ZUGFeRD-Test/Program.cs +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace ZUGFeRD_Test -{ - class Program - { - static void Main(string[] args) - { - Application app = new Application(); - app.Run(); - } - } -} diff --git a/ZUGFeRD-Test/Properties/AssemblyInfo.cs b/ZUGFeRD-Test/Properties/AssemblyInfo.cs index cae57393..9a1de553 100644 --- a/ZUGFeRD-Test/Properties/AssemblyInfo.cs +++ b/ZUGFeRD-Test/Properties/AssemblyInfo.cs @@ -1,54 +1,20 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. [assembly: AssemblyTitle("ZUGFeRD-Test")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ZUGFeRD-Test")] -[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyCopyright("Copyright © 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("25ab730b-71ae-49ab-b727-5ee63e6f49ff")] +[assembly: Guid("83a81f31-508c-4e35-bbac-fb095704d9b6")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ZUGFeRD-Test/ZUGFeRD-Test.csproj b/ZUGFeRD-Test/ZUGFeRD-Test.csproj index 4f8cd63c..ac8643d7 100644 --- a/ZUGFeRD-Test/ZUGFeRD-Test.csproj +++ b/ZUGFeRD-Test/ZUGFeRD-Test.csproj @@ -1,23 +1,27 @@  - + + + Debug - x86 - 8.0.30703 - 2.0 - {1FF5A300-0D7A-4C87-9785-D9C5483DB301} - Exe + AnyCPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6} + Library Properties ZUGFeRD_Test ZUGFeRD-Test v4.7.2 - - 512 - true + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 15.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + - - AnyCPU + true full false @@ -25,40 +29,37 @@ DEBUG;TRACE prompt 4 - false - true - - x86 + pdbonly true bin\Release\ TRACE prompt 4 - false - true + + packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + True + + + packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + True + - - - - - - - - + + - - - + + + - + @@ -66,12 +67,14 @@ ZUGFeRD + - + \ No newline at end of file diff --git a/ZUGFeRD-Test/ZUGFeRD-Test.sln b/ZUGFeRD-Test/ZUGFeRD-Test.sln index 432a6e2f..7e3c92ed 100644 --- a/ZUGFeRD-Test/ZUGFeRD-Test.sln +++ b/ZUGFeRD-Test/ZUGFeRD-Test.sln @@ -3,10 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30128.36 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZUGFeRD-Test", "ZUGFeRD-Test.csproj", "{1FF5A300-0D7A-4C87-9785-D9C5483DB301}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZUGFeRD", "..\ZUGFeRD\ZUGFeRD.csproj", "{B9550547-0A5C-445D-88C7-DD481881E62F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZUGFeRD-Test", "ZUGFeRD-Test.csproj", "{83A81F31-508C-4E35-BBAC-FB095704D9B6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,13 +15,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1FF5A300-0D7A-4C87-9785-D9C5483DB301}.Debug|Any CPU.ActiveCfg = Debug|x86 - {1FF5A300-0D7A-4C87-9785-D9C5483DB301}.Debug|Any CPU.Build.0 = Debug|x86 - {1FF5A300-0D7A-4C87-9785-D9C5483DB301}.Debug|x86.ActiveCfg = Debug|x86 - {1FF5A300-0D7A-4C87-9785-D9C5483DB301}.Debug|x86.Build.0 = Debug|x86 - {1FF5A300-0D7A-4C87-9785-D9C5483DB301}.Release|Any CPU.ActiveCfg = Release|x86 - {1FF5A300-0D7A-4C87-9785-D9C5483DB301}.Release|x86.ActiveCfg = Release|x86 - {1FF5A300-0D7A-4C87-9785-D9C5483DB301}.Release|x86.Build.0 = Release|x86 {B9550547-0A5C-445D-88C7-DD481881E62F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B9550547-0A5C-445D-88C7-DD481881E62F}.Debug|Any CPU.Build.0 = Debug|Any CPU {B9550547-0A5C-445D-88C7-DD481881E62F}.Debug|x86.ActiveCfg = Debug|Any CPU @@ -30,6 +23,14 @@ Global {B9550547-0A5C-445D-88C7-DD481881E62F}.Release|Any CPU.Build.0 = Release|Any CPU {B9550547-0A5C-445D-88C7-DD481881E62F}.Release|x86.ActiveCfg = Release|Any CPU {B9550547-0A5C-445D-88C7-DD481881E62F}.Release|x86.Build.0 = Release|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Debug|x86.ActiveCfg = Debug|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Debug|x86.Build.0 = Debug|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Release|Any CPU.Build.0 = Release|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Release|x86.ActiveCfg = Release|Any CPU + {83A81F31-508C-4E35-BBAC-FB095704D9B6}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ZUGFeRD-Test/ZUGFeRD10Tests.cs b/ZUGFeRD-Test/ZUGFeRD10Tests.cs new file mode 100644 index 00000000..729da372 --- /dev/null +++ b/ZUGFeRD-Test/ZUGFeRD10Tests.cs @@ -0,0 +1,78 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using s2industries.ZUGFeRD; +using System; +using System.IO; + +namespace ZUGFeRD_Test +{ + [TestClass] + public class ZUGFeRD10Tests + { + InvoiceProvider InvoiceProvider = new InvoiceProvider(); + + + [TestMethod] + public void TestReferenceComfortInvoice() + { + string path = @"..\..\..\demodata\zugferd10\ZUGFeRD_1p0_COMFORT_Einfach.xml"; + InvoiceDescriptor desc = InvoiceDescriptor.Load(path); + + Assert.AreEqual(desc.Profile, Profile.Comfort); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + } // !TestReferenceComfortInvoice() + + + [TestMethod] + public void TestReferenceComfortInvoiceRabattiert() + { + string path = @"..\..\..\demodata\zugferd10\ZUGFeRD_1p0_COMFORT_Rabatte.xml"; + InvoiceDescriptor desc = InvoiceDescriptor.Load(path); + + desc.Save("test.xml", ZUGFeRDVersion.Version1, Profile.Comfort); + + Assert.AreEqual(desc.Profile, Profile.Comfort); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.CreditorBankAccounts[0].BankName, "Hausbank München"); + } // !TestReferenceComfortInvoiceRabattiert() + + + [TestMethod] + public void TestStoringInvoiceViaFile() + { + string path = "output.xml"; + InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); + desc.Save(path, ZUGFeRDVersion.Version1, Profile.Comfort); + + InvoiceDescriptor desc2 = InvoiceDescriptor.Load(path); + // TODO: Add more asserts + } // !TestStoringInvoiceViaFile() + + + [TestMethod] + public void TestStoringInvoiceViaStreams() + { + InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); + + string path = "output_stream.xml"; + FileStream saveStream = new FileStream(path, FileMode.Create); + desc.Save(saveStream, ZUGFeRDVersion.Version1, Profile.Comfort); + saveStream.Close(); + + FileStream loadStream = new FileStream(path, FileMode.Open); + InvoiceDescriptor desc2 = InvoiceDescriptor.Load(loadStream); + loadStream.Close(); + + Assert.AreEqual(desc2.Profile, Profile.Comfort); + Assert.AreEqual(desc2.Type, InvoiceType.Invoice); + + + // try again with a memory stream + MemoryStream ms = new MemoryStream(); + desc.Save(ms, ZUGFeRDVersion.Version1, Profile.Comfort); + + byte[] data = ms.ToArray(); + string s = System.Text.Encoding.Default.GetString(data); + // TODO: Add more asserts + } // !TestStoringInvoiceViaStream() + } +} diff --git a/ZUGFeRD-Test/ZUGFeRD20Tests.cs b/ZUGFeRD-Test/ZUGFeRD20Tests.cs new file mode 100644 index 00000000..67cd6d08 --- /dev/null +++ b/ZUGFeRD-Test/ZUGFeRD20Tests.cs @@ -0,0 +1,44 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using s2industries.ZUGFeRD; +using System; +using System.IO; + +namespace ZUGFeRD_Test +{ + [TestClass] + public class ZUGFeRD20Tests + { + [TestMethod] + public void TestReferenceBasicInvoice() + { + string path = @"..\..\..\demodata\zugferd20\zugferd_2p0_BASIC_Einfach.xml"; + + Stream s = File.Open(path, FileMode.Open); + InvoiceDescriptor desc = InvoiceDescriptor.Load(s); + s.Close(); + + Assert.AreEqual(desc.Profile, Profile.Basic); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "471102"); + Assert.AreEqual(desc.TradeLineItems.Count, 1); + Assert.AreEqual(desc.LineTotalAmount, 198.0m); + } // !TestReferenceBasicInvoice() + + + [TestMethod] + public void TestReferenceExtendedInvoice() + { + string path = @"..\..\..\demodata\zugferd20\zugferd_2p0_EXTENDED_Warenrechnung.xml"; + + Stream s = File.Open(path, FileMode.Open); + InvoiceDescriptor desc = InvoiceDescriptor.Load(s); + s.Close(); + + Assert.AreEqual(desc.Profile, Profile.Extended); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "R87654321012345"); + Assert.AreEqual(desc.TradeLineItems.Count, 6); + Assert.AreEqual(desc.LineTotalAmount, 457.20m); + } // !TestReferenceExtendedInvoice() + } +} diff --git a/ZUGFeRD-Test/ZUGFeRD21Tests.cs b/ZUGFeRD-Test/ZUGFeRD21Tests.cs new file mode 100644 index 00000000..fe37f3e2 --- /dev/null +++ b/ZUGFeRD-Test/ZUGFeRD21Tests.cs @@ -0,0 +1,168 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using s2industries.ZUGFeRD; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZUGFeRD_Test +{ + [TestClass] + public class ZUGFeRD21Tests + { + InvoiceProvider InvoiceProvider = new InvoiceProvider(); + + + [TestMethod] + public void TestReferenceBasicFacturXInvoice() + { + string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_BASIC_Einfach-factur-x.xml"; + + Stream s = File.Open(path, FileMode.Open); + InvoiceDescriptor desc = InvoiceDescriptor.Load(s); + s.Close(); + + Assert.AreEqual(desc.Profile, Profile.Basic); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "471102"); + Assert.AreEqual(desc.TradeLineItems.Count, 1); + Assert.AreEqual(desc.LineTotalAmount, 198.0m); + } // !TestReferenceBasicFacturXInvoice() + + + [TestMethod] + public void TestStoringReferenceBasicFacturXInvoice() + { + string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_BASIC_Einfach-factur-x.xml"; + + Stream s = File.Open(path, FileMode.Open); + InvoiceDescriptor originalDesc = InvoiceDescriptor.Load(s); + s.Close(); + + Assert.AreEqual(originalDesc.Profile, Profile.Basic); + Assert.AreEqual(originalDesc.Type, InvoiceType.Invoice); + Assert.AreEqual(originalDesc.InvoiceNo, "471102"); + Assert.AreEqual(originalDesc.TradeLineItems.Count, 1); + Assert.AreEqual(originalDesc.LineTotalAmount, 198.0m); + Assert.AreEqual(originalDesc.Taxes[0].TaxAmount, 37.62m); + Assert.AreEqual(originalDesc.Taxes[0].Percent, 19.0m); + originalDesc.IsTest = false; + + Stream ms = new MemoryStream(); + originalDesc.Save(ms, ZUGFeRDVersion.Version21, Profile.Basic); + originalDesc.Save(@"zugferd_2p1_BASIC_Einfach-factur-x_Result.xml", ZUGFeRDVersion.Version21); + + InvoiceDescriptor desc = InvoiceDescriptor.Load(ms); + + Assert.AreEqual(desc.Profile, Profile.Basic); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "471102"); + Assert.AreEqual(desc.TradeLineItems.Count, 1); + Assert.AreEqual(desc.LineTotalAmount, 198.0m); + Assert.AreEqual(desc.Taxes[0].TaxAmount, 37.62m); + Assert.AreEqual(desc.Taxes[0].Percent, 19.0m); + } // !TestStoringReferenceBasicFacturXInvoice() + + + [TestMethod] + public void TestReferenceBasicWLInvoice() + { + string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_BASIC-WL_Einfach-factur-x.xml"; + + Stream s = File.Open(path, FileMode.Open); + InvoiceDescriptor desc = InvoiceDescriptor.Load(s); + s.Close(); + + Assert.AreEqual(desc.Profile, Profile.BasicWL); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "471102"); + Assert.AreEqual(desc.TradeLineItems.Count, 0); + Assert.AreEqual(desc.LineTotalAmount, 624.90m); + } // !TestReferenceBasicWLInvoice() + + + [TestMethod] + public void TestReferenceExtendedInvoice() + { + string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_EXTENDED_Warenrechnung-factur-x.xml"; + + Stream s = File.Open(path, FileMode.Open); + InvoiceDescriptor desc = InvoiceDescriptor.Load(s); + s.Close(); + + Assert.AreEqual(desc.Profile, Profile.Extended); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "R87654321012345"); + Assert.AreEqual(desc.TradeLineItems.Count, 6); + Assert.AreEqual(desc.LineTotalAmount, 457.20m); + } // !TestReferenceExtendedInvoice() + + + [TestMethod] + public void TestReferenceMinimumInvoice() + { + string path = @"..\..\..\demodata\zugferd21\zugferd_2p1_MINIMUM_Rechnung-factur-x.xml"; + + Stream s = File.Open(path, FileMode.Open); + InvoiceDescriptor desc = InvoiceDescriptor.Load(s); + s.Close(); + + Assert.AreEqual(desc.Profile, Profile.Minimum); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "471102"); + Assert.AreEqual(desc.TradeLineItems.Count, 0); + Assert.AreEqual(desc.LineTotalAmount, 0.0m); // not present in file + Assert.AreEqual(desc.TaxBasisAmount, 198.0m); + } // !TestReferenceMinimumInvoice() + + + [TestMethod] + public void TestReferenceXRechnungCII() + { + string path = @"..\..\..\demodata\xRechnung\xRechnung CII.xml"; + InvoiceDescriptor desc = InvoiceDescriptor.Load(path); + + Assert.AreEqual(desc.Profile, Profile.XRechnung); + Assert.AreEqual(desc.Type, InvoiceType.Invoice); + Assert.AreEqual(desc.InvoiceNo, "0815-99-1-a"); + Assert.AreEqual(desc.TradeLineItems.Count, 2); + Assert.AreEqual(desc.LineTotalAmount, 1445.98m); + } // !TestReferenceXRechnungCII() + + + [TestMethod] + public void TestInvoiceWithAttachment() + { + InvoiceDescriptor desc = this.InvoiceProvider.CreateInvoice(); + string filename = "myrandomdata.bin"; + byte[] data = new byte[32768]; + new Random().NextBytes(data); + + desc.AddAdditionalReferencedDocument( + issuerAssignedID: "My-File", + typeCode: AdditionalReferencedDocumentTypeCode.ReferenceDocument, + name: "Ausführbare Datei", + attachmentBinaryObject: data, + filename: filename); + + MemoryStream ms = new MemoryStream(); + + desc.Save(ms, ZUGFeRDVersion.Version21, Profile.XRechnung); + ms.Seek(0, SeekOrigin.Begin); + + InvoiceDescriptor loadedInvoice = InvoiceDescriptor.Load(ms); + + foreach(AdditionalReferencedDocument document in loadedInvoice.AdditionalReferencedDocuments) + { + if (document.IssuerAssignedID == "My-File") + { + CollectionAssert.AreEqual(document.AttachmentBinaryObject, data); + Assert.AreEqual(document.Filename, filename); + break; + } + } + } + } +} diff --git a/ZUGFeRD-Test/ZugFerd1BasicGenerator.cs b/ZUGFeRD-Test/ZugFerd1BasicGenerator.cs deleted file mode 100644 index b06b63be..00000000 --- a/ZUGFeRD-Test/ZugFerd1BasicGenerator.cs +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -using s2industries.ZUGFeRD; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace ZUGFeRD_Test -{ - class ZugFerd1BasicGenerator - { - public void generate() - { - string filename = "ZUGFeRD_1p0_BASIC.xml"; - - InvoiceDescriptor desc = _generateDescriptor(); - desc.Save(filename); - } // !generate() - - - private InvoiceDescriptor _generateDescriptor() - { - InvoiceDescriptor desc = InvoiceDescriptor.CreateInvoice("471102", new DateTime(2013, 3, 5), CurrencyCodes.EUR, "2013-471102"); - desc.AddNote("Rechnung gemäß Bestellung vom 01.03.2013."); - - StringBuilder lieferantNote = new StringBuilder(); - lieferantNote.AppendLine("Lieferant GmbH"); - lieferantNote.AppendLine("Lieferantenstraße 20"); - lieferantNote.AppendLine("80333 München"); - lieferantNote.AppendLine("Deutschland"); - lieferantNote.AppendLine("Geschäftsführer: Hans Muster"); - lieferantNote.AppendLine("Handelsregisternummer: H A 123"); - desc.AddNote(lieferantNote.ToString()); - - StringBuilder gln = new StringBuilder(); - gln.AppendLine("Unsere GLN: 4000001123452"); - gln.AppendLine("Ihre GLN: 4000001987658"); - gln.AppendLine("Ihre Kundennummer: GE2020211"); - gln.AppendLine(""); - gln.AppendLine(""); - gln.AppendLine("Zahlbar innerhalb 30 Tagen netto bis 04.04.2013, 3% Skonto innerhalb 10 Tagen bis 15.03.2013."); - desc.AddNote(gln.ToString()); - - desc.SetSeller("Lieferant GmbH", - "80333", - "München", - "Lieferantenstraße 20", - CountryCodes.DE, - ""); - desc.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC); - desc.AddSellerTaxRegistration("DE123456789", TaxRegistrationSchemeID.VA); - - desc.SetBuyer(name: "Kunden AG Mitte", - postcode: "69876", - receiver: "Hans Muster", - city: "Frankfurt", - street: "Kundenstraße 15", - country: CountryCodes.DE, - id: null); - - desc.ActualDeliveryDate = new DateTime(2013, 03, 05); - desc.AddCreditorFinancialAccount("DE08700901001234567890", "GENODEF1M04"); - desc.AddApplicableTradeTax(275.0m, 7.0m, TaxTypes.VAT); - desc.AddApplicableTradeTax(198.00m, 19.0m, TaxTypes.VAT); - - desc.SetTotals(lineTotalAmount: 473.00m, - chargeTotalAmount: 0.00m, - allowanceTotalAmount: 0.00m, - taxBasisAmount: 473.00m, - taxTotalAmount: 56.87m, - grandTotalAmount: 529.87m); - desc.AddTradeLineItem(name: $"GTIN: 4012345001235{Environment.NewLine}Unsere Art.-Nr.: TB100A4{Environment.NewLine}Trennblätter A4", - unitCode: QuantityCodes.C62, - grossUnitPrice: 9.90m, - netUnitPrice: 9.90m, - billedQuantity: 20m, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 19.00m, - id: new GlobalID(GlobalID.SchemeID_EAN, "4012345001235"), - sellerAssignedID: "TB100A4"); - - desc.AddTradeLineItem(name: $"GTIN: 4000050986428{Environment.NewLine}Unsere Art.-Nr.: ARNR2{Environment.NewLine}Joghurt Banane", - unitCode: QuantityCodes.C62, - grossUnitPrice: 5.50m, - netUnitPrice: 5.50m, - billedQuantity: 50m, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 7.00m, - id: new GlobalID(GlobalID.SchemeID_EAN, "4000050986428"), - sellerAssignedID: "ARNR2"); - - return desc; - } // !_generateDescriptor() - - - public void read() - { - InvoiceDescriptor tempDesc = _generateDescriptor(); - MemoryStream ms = new MemoryStream(); - tempDesc.Save(ms, ZUGFeRDVersion.Version1, Profile.Basic); - string s = Encoding.ASCII.GetString(ms.ToArray()); - InvoiceDescriptor desc = InvoiceDescriptor.Load(ms); - - bool equals = tempDesc.Equals(desc); - } // !read() - } - -} diff --git a/ZUGFeRD-Test/ZugFerd1ComfortEinfachGenerator.cs b/ZUGFeRD-Test/ZugFerd1ComfortEinfachGenerator.cs deleted file mode 100644 index 1cd3bbf1..00000000 --- a/ZUGFeRD-Test/ZugFerd1ComfortEinfachGenerator.cs +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -using s2industries.ZUGFeRD; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace ZUGFeRD_Test -{ - internal class ZugFerd1ComfortEinfachGenerator - { - public void generate() - { - string filename = "ZUGFeRD_1p0_COMFORT_Einfach.xml"; - - InvoiceDescriptor desc = _generateDescriptor(); - desc.Save(filename, ZUGFeRDVersion.Version1, Profile.Comfort); - } // !generate() - - - private InvoiceDescriptor _generateDescriptor() - { - InvoiceDescriptor desc = InvoiceDescriptor.CreateInvoice("471102", new DateTime(2013, 6, 5), CurrencyCodes.EUR, "2013-471102"); - desc.AddNote("Rechnung gemäß Bestellung vom 01.03.2013."); - - StringBuilder lieferantNote = new StringBuilder(); - lieferantNote.AppendLine("Lieferant GmbH"); - lieferantNote.AppendLine("Lieferantenstraße 20"); - lieferantNote.AppendLine("80333 München"); - lieferantNote.AppendLine("Deutschland"); - lieferantNote.AppendLine("Geschäftsführer: Hans Muster"); - lieferantNote.AppendLine("Handelsregisternummer: H A 123"); - desc.AddNote(lieferantNote.ToString(), SubjectCodes.REG); - - desc.SetSeller("Lieferant GmbH", - "80333", - "München", - "Lieferantenstraße 20", - CountryCodes.DE, - "", - new GlobalID(GlobalID.SchemeID_GLN, "4000001123452")); - desc.AddSellerTaxRegistration("201/113/40209", TaxRegistrationSchemeID.FC); - desc.AddSellerTaxRegistration("DE123456789", TaxRegistrationSchemeID.VA); - - desc.SetBuyer("Kunden AG Mitte", - "69876", - "Frankfurt", - "Kundenstraße 15", - CountryCodes.DE, - "GE2020211", - new GlobalID(GlobalID.SchemeID_GLN, "4000001987658")); - desc.SetBuyerContact("Hans Muster"); - - desc.ActualDeliveryDate = new DateTime(2013, 03, 05); - desc.SetPaymentMeans(PaymentMeansTypeCodes.DebitTransfer, "Überweisung"); - desc.AddCreditorFinancialAccount("DE08700901001234567890", "GENODEF1M04"); - desc.AddApplicableTradeTax(275.0m, 7.0m, TaxTypes.VAT, TaxCategoryCodes.S); - desc.AddApplicableTradeTax(198.00m, 19.0m, TaxTypes.VAT, TaxCategoryCodes.S); - desc.SetTradePaymentTerms("Zahlbar innerhalb 30 Tagen netto bis 04.04.2013, 3% Skonto innerhalb 10 Tagen bis 15.03.2013", - new DateTime(2013, 4, 4)); - desc.SetTotals(473.00m, - 0.00m, - 0.00m, - 473.00m, - 56.87m, - 529.87m, - 0.00m, - 529.87m); - desc.AddTradeLineItem(name: "Trennblätter A4", - unitCode: QuantityCodes.C62, - grossUnitPrice: 9.90m, - netUnitPrice: 9.90m, - billedQuantity: 20m, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 19.00m, - id: new GlobalID(GlobalID.SchemeID_EAN, "4012345001235"), - sellerAssignedID: "TB100A4"); - - desc.AddTradeLineItem(name: "Joghurt Banane", - unitCode: QuantityCodes.C62, - grossUnitPrice: 5.50m, - netUnitPrice: 5.50m, - billedQuantity: 50m, - taxType: TaxTypes.VAT, - categoryCode: TaxCategoryCodes.S, - taxPercent: 7.00m, - id: new GlobalID(GlobalID.SchemeID_EAN, "4000050986428"), - sellerAssignedID: "ARNR2"); - - return desc; - } // !_generateDescriptor() - - - public void read() - { - InvoiceDescriptor tempDesc = _generateDescriptor(); - MemoryStream ms = new MemoryStream(); - tempDesc.Save(ms, ZUGFeRDVersion.Version1, Profile.Comfort); - string s = Encoding.ASCII.GetString(ms.ToArray()); - InvoiceDescriptor desc = InvoiceDescriptor.Load(ms); - - bool equals = tempDesc.Equals(desc); - } // !read() - } -} diff --git a/ZUGFeRD-Test/ZugFerd1ExtendedWarenrechnungGenerator.cs b/ZUGFeRD-Test/ZugFerd1ExtendedWarenrechnungGenerator.cs deleted file mode 100644 index 969a9154..00000000 --- a/ZUGFeRD-Test/ZugFerd1ExtendedWarenrechnungGenerator.cs +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -using s2industries.ZUGFeRD; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace ZUGFeRD_Test -{ - class ZugFerd1ExtendedWarenrechnungGenerator - { - public void generate() - { - InvoiceDescriptor desc = _generateDescriptor(); - desc.Save("ZUGFeRD_1p0_EXTENDED_Warenrechnung.xml", ZUGFeRDVersion.Version1, Profile.Extended); - } // !generate() - - - private InvoiceDescriptor _generateDescriptor() - { - InvoiceDescriptor desc = InvoiceDescriptor.CreateInvoice("R87654321012345", new DateTime(2013, 8, 6), CurrencyCodes.EUR); - desc.IsTest = true; - - desc.AddNote("Es bestehen Rabatt- oder Bonusvereinbarungen.", SubjectCodes.AAK, ContentCodes.ST3); - desc.AddNote("Der Verkäufer bleibt Eigentümer der Waren bis zu vollständigen Erfüllung der Kaufpreisforderung.", SubjectCodes.AAJ, ContentCodes.EEV); - desc.AddNote("MUSTERLIEFERANT GMBH BAHNHOFSTRASSE 99 99199 MUSTERHAUSEN Geschäftsführung: Max Mustermann USt-IdNr: DE123456789 Telefon: +49 932 431 0 www.musterlieferant.de HRB Nr. 372876 Amtsgericht Musterstadt GLN 4304171000002 WEEE-Reg-Nr.: DE87654321", - SubjectCodes.REG); - desc.AddNote("Leergutwert: 46,50"); - - desc.SetSeller("MUSTERLIEFERANT GMBH", - "99199", - "MUSTERHAUSEN", - "BAHNHOFSTRASSE 99", - CountryCodes.DE, - "549910", - new GlobalID(GlobalID.SchemeID_GLN, "4333741000005")); - desc.SetSellerContact("", emailAddress: "max.mustermann@musterlieferant.de", phoneno: "+49 932 431 500"); - desc.AddSellerTaxRegistration("DE123456789", TaxRegistrationSchemeID.VA); - - desc.SetBuyer("MUSTER-KUNDE GMBH", - "40235", - "DUESSELDORF", - "KUNDENWEG 88", - CountryCodes.DE, - "009420", - new GlobalID(GlobalID.SchemeID_GLN, "4304171000002")); - desc.SetBuyerOrderReferenceDocument("B123456789", new DateTime(2013, 08, 01)); - - desc.AddAdditionalReferencedDocument(issuerAssignedID: "A456123", issueDateTime: new DateTime(2013, 08, 02), referenceTypeCode: ReferenceTypeCodes.VN); - - /// TODO: ApplicableSupplyChainTradeDelivery - /// - - desc.AddTradeLineCommentItem("Wichtige Information: Bei Bestellungen bis zum 19.12. ist die Auslieferung bis spätestens 23.12. garantiert."); - TradeLineItem item = desc.AddTradeLineItem("Zitronensäure 100ml", - null, - QuantityCodes.C62, - null, - 1, - 1, - 100, - TaxTypes.VAT, - TaxCategoryCodes.S, - 19, - null, - new GlobalID("0088", "4123456000014"), - "ZS997", - "", - "", - null, - "", - null); - - item = desc.AddTradeLineItem("Gelierzucker Extra 250g", - null, - QuantityCodes.C62, - null, - 1.5m, - 1.45m, - 50, - TaxTypes.VAT, - TaxCategoryCodes.S, - 7, - null, - new GlobalID("0088", "4123456000021"), - "GZ250", - "", - "", - null, - "", - null); - item.AddTradeAllowanceCharge(true, - CurrencyCodes.EUR, - 1.5m, - 0.03m, - "Artikelrabatt 1"); - item.AddTradeAllowanceCharge(true, - CurrencyCodes.EUR, - 1m, - 0.02m, - "Artikelrabatt 2"); - - return desc; - } // !_generateDescriptor() - - - public void read() - { - InvoiceDescriptor tempDesc = _generateDescriptor(); - MemoryStream ms = new MemoryStream(); - tempDesc.Save(ms, ZUGFeRDVersion.Version1, Profile.Extended); - string s = Encoding.ASCII.GetString(ms.ToArray()); - InvoiceDescriptor desc = InvoiceDescriptor.Load(ms); - - bool equals = tempDesc.Equals(desc); - } // !read() - } -} diff --git a/ZUGFeRD-Test/app.config b/ZUGFeRD-Test/app.config deleted file mode 100644 index 312bb3f2..00000000 --- a/ZUGFeRD-Test/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/ZUGFeRD-Test/packages.config b/ZUGFeRD-Test/packages.config new file mode 100644 index 00000000..f84cb106 --- /dev/null +++ b/ZUGFeRD-Test/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/packages.config b/packages.config new file mode 100644 index 00000000..a041b8e1 --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file