Erstellung einer ZUGFeRD/X-Rechnung XML Datei via COM Schnittstelle (VB6 / VBA) with Late Binding

Um den Einstieg in die Nutzung unseres SDK zu erleichtern, haben wir ein neues Beispiel entwickelt, das demonstriert, wie eine vollständige ZUGFeRD XML-Datei erstellt wird. Für die Erstellung dieses Beispiels wurde die Version 9.0.0.15 der ZUGFeRD-Bibliothek verwendet. Bitte stellen Sie sicher, dass Sie mindestens diese Version installiert haben.

Das erstellte Beispiel wurde erfolgreich mit verschiedenen freien Kosit/ZUGFeRD/X-Rechnung Validatoren geprüft. Je nach Validator kann es trotzdem zu Warnungen kommen, beispielsweise wegen einer ungültigen IBAN-Nummer, da wir bewusst keine gültigen Daten verwendet haben.

Angesichts der anhaltenden Beliebtheit von VB6 und MS Access in unternehmensinternen Buchhaltungsanwendungen, die auch für VBA gilt, nutzt dieses Beispiel die COM-APIs, die ebenfalls in .NET verwendet werden können. Dies gewährleistet eine breite Kompatibilität und Flexibilität in verschiedenen Entwicklungs­umgebungen.

Sollten Sie Interesse an unserem VB6 Beispielprojekt haben kontaktieren Sie uns bitte damit wir Ihnen die Sourcen schicken.

Das Ergebnis des Beispielcodes finden sie hier:

Fuer VB.NET koennen Sie auch ein komplettes Demo Projekt laden:
https://www.aloaha.com/download/ZUGFeRDSample.zip

Dim LicenseKey As String
Dim InvoiceCurrency As String
Dim InvoiceID As String
Dim InvoiceDate As String
Dim InvoiceDate_Format As String
Dim InvoiceNote As String
Dim Bestellnummer As String
Dim BookingReference As String
Dim BookingReferenceTypeocde As String
Dim LeitWegID As String
Dim IssuerAssignedID As String                  'BT-17, BT-18, BT-122
Dim URIID As String                             'BT-124
Dim TypeCode As String                          'BT-17-0, BT-18-0, BT-122-0
Dim docdescription As String                    'BT-123
Dim PaymentTermsDescription As String
Dim DueDate As String                           'BT-9
Dim DirectDebitMandateID As String              'BG-19/ BT-89
Dim position0 As Integer
Dim position1 As Integer
Dim StartDate As String                         'BT-73
Dim EndDate As String                           'BT-74
Dim ItemStartDate As String
Dim ItemEndDate As String
    
Dim CalculatedAmount As String
Dim BasisAmount As String
Dim TaxTypeCode As String
Dim CategoryCode As String
Dim ApplicablePercent As String
Dim TaxPointDate As String          'BT-7
Dim DueDateTypeCode As String       'BT-8
Dim ExemptionReason As String

'Late Binding, please note that sometimes Early Binding is better!   
Dim alo As Object
Set alo = CreateObject("Aloaha_ZUGFeRD.XML")
 
'if error then call regasm Aloaha_ZUGFeRD.dll /codebase
'make sure you use the 32 Bit Regasm
    
LicenseKey = "Sxxxxxxxxxx4"
InvoiceCurrency = "EUR"                         'BT-5
InvoiceID = "47110815"                          'BT-1
InvoiceDate = "20240531"                        'BT-2
InvoiceDate_Format = "102"
     
Bestellnummer = "Bestellnummer"                 'BT-13
InvoiceNote = "Rechnung gemäß Bestellung."      'BT-22, BG-1
BookingReference = "Buchungsreferenz"           'BT-19
BookingReferenceTypeocde = "" 
    
If alo.Licensed(LicenseKey) = False Then
    MsgBox ("Not Licensed")
Else
    MsgBox ("Licensed OK")
    alo.LicenseKey = LicenseKey
    alo.ZUGFeRD_Profile = 1
    alo.ZUGfeRDStandard = 2
    alo.isKOSIT = True
    If alo.CreateNewInvoice(InvoiceID, InvoiceNote, InvoiceDate, InvoiceDate_Format, "", "", InvoiceCurrency) = True Then
        alo.Document_Type = 380                     'BT-3 (Invoice)
        
         alo.InvoiceCurrencyCode = InvoiceCurrency   'BT-5
         alo.Document_ID = InvoiceID                 'BT-1
        
         'BT-23
         alo.BusinessProcessSpecifiedDocumentContextParameter = "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0"
            
        alo.AddBuyerAssignedID (Bestellnummer)      'BT-13
            
        Call alo.AddReceivableSpecifiedTradeAccountingAccount(BookingReference, BookingReferenceTypeocde) 'BT-19
            
            
        IssuerAssignedID = "111111114"         'BT-17, BT-18, BT-122
        URIID = ""                             'BT-124
        TypeCode = "916"                       'BT-17-0, BT-18-0, BT-122-0
        docdescription = "doc description"     'BT-123
        Call alo.Add_AdditionalReferencedDocument(IssuerAssignedID, URIID, TypeCode, docdescription)
            
            
        LeitWegID = "N999-11111-22"            'BT-10
        Call alo.WriteBuyer("Muster GmbH", "49479", "Ibbenbüren", "Bahnhofstraße 1", "", "DE", "kundennummer", "DE000000", LeitWegID)
        alo.LeitWegID = LeitWegID
        alo.BuyerReference = LeitWegID
             
        alo.BuyerCountry = "DE"
        alo.BuyerPostCode = "49479"
        alo.BuyerID = "KundenNummer"
        'Call alo.AddBuyerGlobalID(alo.BuyerID, "0021")

        Call alo.WriteBuyerContactPerson("John Doe", "Einkauf", "stefan@aloaha.com", "+4900000")
        alo.BuyerCity = "Ibbenbüren"
        alo.BuyerAddressLine1 = "Bahnhofstraße 1"
        alo.BuyerAddressLine2 = "Wohnung 2"
        alo.BuyerPersonalName = "Karl Mustermann"
        alo.BuyerDepartment = "Einkauf"
        alo.BuyerEmail = "stefan@aloaha.com"
            
        'BT-34, BT-49
         Call alo.set_URIUniversalCommunication("test@toplevel.tld", "EM", False)
        
        alo.BuyerTelephone = "+490000"
        'Call alo.AddBuyerOrderReferencedDocument("47110815", "20130608", "102", "", "1")
        'Call alo.AddBuyerOrderReferencedDocument("234234243", "20130608", "102", "", "2")
            
        'alo.CreditorReferenceID = "CreditorReferenceID"   'BG19 / BT-90
            
            
        Call alo.WriteSeller("Aloaha Limited", "PBK1131", "Pembroke", "Helgoland", "45, Triq Gio Felice Inglott", "MT", "MT000000000")
        alo.SellerDepartment = "Sales"
        alo.SellerName = "Aloaha Limited"
        alo.SellerCity = "Pembroke"
        alo.SellerAddressLine1 = "Helgoland"
        alo.SellerAddressLine2 = "Triq Gio Felice Inglott"
        alo.SellerCountry = "MT"
        alo.SellerPostCode = "PBK1131"
        alo.SellerID = "4711"
        'Call alo.AddSellerGlobalID(alo.SellerID, "0021")
        Call alo.AddPaymentMeans_2("58", "Ãœberweisung", "DE12 3456 7890 1234 5678 90", "", "", "XXXXX21YYY", "", "Sparkasse", False, "", "")
        Call alo.WriteSellerContactPerson("John Doe", "Verkauf", "stefan@aloaha.com", "+49 1111111")
        alo.SellerPersonalName = "John Doe"              'BT-41
        alo.SellerDepartment = "Sales Department"
        alo.SellerEmail = "stefan@aloaha.com"            'BT-43
        'alo.SellerFAX = "+49000000"
        alo.SellerTelephone = "+490000"
    
        'BT-34, BT-49, PEPPOL-EN16931-R020
        Call alo.set_URIUniversalCommunication("1234567890128", "0088", True)
        
        PaymentTermsDescription = "#SKONTO#TAGE=14#PROZENT=2.00#BASISBETRAG=396.00#"    'BT-20
        DueDate = alo.TodayDate.Document_Date                      'BT-9
        DirectDebitMandateID = ""                                  'BG-19/ BT-89
        Call alo.AddTradePaymentTerms(PaymentTermsDescription, DueDate, "102", DirectDebitMandateID)

        'Call alo.SetDespatchAdviceReferencedDocument("Lieferavisreferenz")              'BT-16
            
            
        Dim useBillingPeriod As Boolean
        useBillingPeriod = False
        If useBillingPeriod = True Then
            StartDate = "20120108"                                 'BT-73
            EndDate = "20120708"                                   'BT-74
            Call alo.WriteBillingPeriod(StartDate, EndDate, "102")
        End If
            
        Dim DeliveryDate As String
        Dim DeliveryDateFormat As String
        DeliveryDate = "20120608"                                  'BT-72
        DeliveryDateFormat = "102"                                 'BT-72-0
        Call alo.Set_Actual_DeliveryDate(DeliveryDate, DeliveryDateFormat)
            
    End If
        
    'Call alo.AddDeliveryNote("324544", "20150608", "102")
    'Call alo.AddDeliveryNote("dfadfafaf", "20150608", "102", "1")

    'ItemStartDate = "20120108"
    'ItemEndDate = "20120708"
     position0 = alo.AddProduct_Comfort_2("1", "nicht rabattierfähig", "TB100A4", "20.0000", "H87", "Trennblätter", "A4", "11.781", InvoiceCurrency, "", "", False, "", "", "", "9,9", InvoiceCurrency, "", "", "vat", "s", "19.00", "", "198.00", InvoiceCurrency, "globalid", "0160")
    'Call alo.ItemWriteBillingPeriod(position0, ItemStartDate, ItemEndDate, "102")
        
    position1 = alo.AddProduct_Comfort_2("2", "nicht rabattierfähig", "TB100A4", "20.0000", "H87", "Trennstreifen", "A4", "11.781", InvoiceCurrency, "", "", False, "", "", "", "9,9", InvoiceCurrency, "", "", "vat", "s", "19.00", "", "198.00", InvoiceCurrency, "globalid", "0160")
        
      
    CalculatedAmount = "75.24"
    BasisAmount = "396.00"
    TaxTypeCode = "VAT"
    CategoryCode = "S"
    ApplicablePercent = "19.00"
    TaxPointDate = ""              'BT-7
    DueDateTypeCode = ""           'BT-8
    ExemptionReason = ""
    Call alo.AddTradeTax(CalculatedAmount, InvoiceCurrency, BasisAmount, InvoiceCurrency, TaxTypeCode, CategoryCode, ApplicablePercent, ExemptionReason, TaxPointDate, "", DueDateTypeCode)
        
    Call alo.WriteTotals("396.00", "471.24", "471.24", "396.00", "75.24", "00,00", "0.00", "0.00")


    alo.UseASIIOnSave = False
    alo.SaveWithoutUTF8Header = False
        
    alo.SaveXML ("o:\temp\test1.xml")

    Call alo.MergeXMLIntoPDF("o:\temp\test1.xml", "o:\pdf\plain.pdf", "o:\temp\test1.pdf", True, "", LicenseKey)

End If