❤️ Helfen Sie noch heute, unser LibreOffice Forum zu erhalten! ❤️
Unterstützen Sie das LibreOffice-Forum und helfen Sie uns, unser Ziel für 2025 zu erreichen!

🍀 Jeder Beitrag zählt – vielen Dank für Ihre Unterstützung!🍀
Mit Ihrer Spende sichern Sie den Fortbestand, den Ausbau und die laufenden Kosten dieses Forums. 🌱


❤️ DANKE >> << DANKE ❤️

>> Dank Ihrer Unterstützung -> Keine Werbung für alle registrierten LibreOffice-Forum User! <<
🤗 Als Dankeschön werden Sie im Forum als LO-SUPPORTER gekennzeichnet. 🤗

XRechnung und ZUGFeRD Rechnungen als DOM-Dokument-Objekt einlesen/erzeugen

Alles zur Programmierung im LibreOffice.
Antworten
aladin
Beiträge: 39
Registriert: Di 30. Jul 2019, 15:49
Kontaktdaten:

XRechnung und ZUGFeRD Rechnungen als DOM-Dokument-Objekt einlesen/erzeugen

Beitrag von aladin » Di 16. Sep 2025, 18:15

@RobertG hat ja schon hervorragende Arbeit geleistet, was das Thema XRechnung und ZUGFeRD angeht.
Ich wollte nun mal probieren, wie man das mittels einem DOM-Objekt mit Libreoffice-Basic umsetzen kann.

Beim Erzeugen der XML-Files habe ich das Problem, dass zwischen den einzelnen Tags keine Zeilenumbrüche eingefügt werden. Auch die Einrückung passt nicht. Allerdings, wenn man ein XML-Dokument als DOM-Objekt einliest und direkt wieder in eine Datei schreibt, sind Zeilenumbrüche und Einrückungen vorhanden.
Weiß jemand wie man das steuern kann? Geht aber ausschließlich um DOM-Objekte. Dass man das mit Outputstream realisieren kann, ist mir bekannt.

Aber das Importieren der XML-Files klappt schon mal ganz gut.
Hier etwas Code, mit dem man E-Rechnungen in UBL und CII einlesen kann.
Die Daten werden in Variablen und Arrays gespeichert.
Auch ist Beispiel-Code dabei, wie die Daten weiterverarbeitet werden können.
In dem Fall wird ein Calc-Dokument mit den Daten gefüllt.
Ich hoffe, ich habe alle relvanten Daten erwischt.

Falls es jemand gebrauchen kann, hier der Code:

Code: Alles auswählen


REM  *****  BASIC  *****

Option Explicit

Global Const BILLING_REFERENCE_ID=0, BILLING_REFERENCE_ISSUE_DATE=1
Global Const CHARGE_INDICATOR=0, ALLOWANCE_CHARGE_REASON_CODE=1, ALLOWANCE_CHARGE_REASON=2
Global Const MULTIPLIER_FACTOR_NUMERIC=5, AMOUNT=6, BASE_AMOUNT=7
Global Const TAXABLE_AMOUNT=0, TAX_AMOUNT=1, TAX_EXEMPTION_REASON=2, TAX_CATEGORY_ID=3, TAX_PERCENT=4
Global Const INVOICE_LINE_LEVEL=0, INVOICE_LINE_ID=1, PARENT_INVOICE_LINE_ID=2
Global Const INVOICE_LINE_NOTE=5, INVOICED_QUANTITY=6, QUANTITY_UNIT_CODE=7
Global Const INVOICE_LINE_ITEM_NAME=8, INVOICE_LINE_ITEM_DESCRIPTION=9
Global Const INVOICE_LINE_ITEM_BUYERS_IDENTIFICATION_ID=10, INVOICE_LINE_ITEM_SELLER_IDENTIFICATION_ID=11
Global Const INVOICE_LINE_EXTENSION_AMOUNT=12, INVOICE_LINE_PRICE_AMOUNT=13

Type structInvoice
	sInvoiceID As String
	sIssueDate As String
	sDueDate As String
	sInvoiceTypCode As String
	sDocumentCurrencyCode As String
	sBuyerReference As String
	sSellerEMail As String
	sSellerName As String
	sSellerDescription As String
	sSellerStreetName As String
	sSellerCityName As String
	sSellerPLZ As String
	sSellerCountryCode As String
	sSellerTaxCompanyID As String
	sSellerContactName As String
	sSellerContactTelephone As String
	sSellerContactElectronicMail As String
	sActualDeliveryDate As String
	sPaymentMeansCode As String
	sPayeeFinancialAccountID As String
	sPayeeFinancialAccountName As String
	sPayeeFinancialInstitutionBranchID As String
	sPaymentTerms As String
	sTaxTotalAmount As String
	sLineExtensionAmount As String
	sTaxExclusiveAmount As String
	sTaxInclusiveAmount As String
	sAllowanceTotalAmount As String
	sChargeTotalAmount As String 
	sPrepaidAmount As String
	sPayableRoundingAmount As String
	sPayableAmount As String
End Type

Dim Invoice As New structInvoice
Dim arrInvoiceNote As Variant, arrBillingReference As Variant, arrAllowanceCharge As Variant, arrTaxSubtotal As Variant, arrInvoiceLines As Variant

Sub readInvoice
	Dim oDocBuilder, oDOM, sURL As String, a%, bInvoiceFound As Boolean
	Dim oFilePicker As Object, oSettings As Object, oFileAccess As Object
 
	oSettings = CreateUnoService("com.sun.star.util.PathSettings")
	sURL = oSettings.Work
 	oFilePicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
	oFilePicker.AppendFilter("XML-Dateien (*.xml)", "*.xml")
	oFilePicker.SetCurrentFilter("XML-Dateien (*.xml)")
	oFilePicker.MultiSelectionMode=False
	
	oFileAccess = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
	If oFileAccess.exists(sURL) Then
		oFilePicker.setDisplayDirectory(sURL)
	End If

	If oFilePicker.execute() Then
		sURL=oFilePicker.Files(0)
	End If
    	
	oDocBuilder = CreateUnoService("com.sun.star.xml.dom.DocumentBuilder")
	oDOM = oDocBuilder.parseURI(ConvertFromURL(sURL))
	oDOM.normalize()

	For a = 0 To oDOM.ChildNodes.getLength - 1
		Select Case oDOM.ChildNodes.item(a).NodeName
			Case "Invoice"
				bInvoiceFound=True
				readXRechnung(oDOM) 
			Case "CrossIndustryInvoice"
				bInvoiceFound=True
				readZUGFeRD(oDOM)
		End Select
	Next 
	
	If Not bInvoiceFound Then
		Print "Keine Rechnungsstruktur erkannt"
	End if
End Sub

Sub readXRechnung(oDOM As Object)
	Dim oElem As Object, oElemList As Object, oSubElemList As Object
	Dim a% , b% , c% , d% , e% , f% , g% , h% , i% , j% , k% , l%, x%
		
	oElemList=oDOM.getElementsByTagName("Invoice").item(0).getChildNodes()
	With Invoice
		For a = 0 To oElemList.getLength() - 1
				Select Case oElemList.item(a).NodeName
					Case "ID"
						.sInvoiceID=oElemList.item(a).FirstChild.NodeValue '[BT-1]
					Case "IssueDate"
						.sIssueDate=oElemList.item(a).FirstChild.NodeValue '[BT-2]
					Case "DueDate"
						.sDueDate=oElemList.item(a).FirstChild.NodeValue	'[BT-9]
					Case "InvoiceTypeCode"
						.sInvoiceTypCode=oElemList.item(a).FirstChild.NodeValue '[BT-3]
					Case "Note"
						ReDim Preserve arrInvoiceNote(b)
						arrInvoiceNote(b)=oElemList.item(a).FirstChild.NodeValue '[BT-22]
						b=b+1
					Case "DocumentCurrencyCode"
						.sDocumentCurrencyCode=oElemList.item(a).FirstChild.NodeValue '[BT-5]
					Case "BuyerReference"
						.sBuyerReference=oElemList.item(a).FirstChild.NodeValue '[BT-10]
					Case "BillingReference" '[BG-3]
						ReDim Preserve arrBillingReference(c,2)
						arrBillingReference(c,BILLING_REFERENCE_ID)=getValue(oElemList.item(a),Array("ID")) '[BT-25]
						arrBillingReference(c,BILLING_REFERENCE_ISSUE_DATE)=getValue(oElemList.item(a),Array("IssueDate")) '[BT-26]
						c=c+1
					Case "AccountingSupplierParty"
						.sSellerEMail=getValue(oElemList.item(a),Array("Party","EndpointID"),"schemeID","EM") '[BT-34]
						.sSellerName=getValue(oElemList.item(a),Array("Party","PartyName","Name")) '[BT-28]
						.sSellerStreetName=getValue(oElemList.item(a),Array("Party","PostalAddress","StreetName")) '[BT-35]
						.sSellerCityName=getValue(oElemList.item(a),Array("Party","PostalAddress","CityName")) '[BT-37]
						.sSellerPLZ=getValue(oElemList.item(a),Array("Party","PostalAddress","PostalZone")) '[BT-38]
						.sSellerCountryCode=getValue(oElemList.item(a),Array("Party","PostalAddress","Country","IdentificationCode")) '[BT-40]
						.sSellerTaxCompanyID=getValue(oElemList.item(a),Array("Party","PartyTaxScheme","CompanyID")) '[BT-31] [BT-32]
						.sSellerContactName=getValue(oElemList.item(a),Array("Party","Contact","Name")) '[BT-41]
						.sSellerContactTelephone=getValue(oElemList.item(a),Array("Party","Contact","Telephone")) '[BT-42]
						.sSellerContactElectronicMail=getValue(oElemList.item(a),Array("Party","Contact","ElectronicMail")) '[BT-43]
					Case "Delivery"
						.sActualDeliveryDate=getValue(oElemList.item(a),Array("ActualDeliveryDate")) '[BT-72]
					Case "PaymentMeans"
						.sPaymentMeansCode=getValue(oElemList.item(a),Array("PaymentMeansCode")) '[BT-81]
						.sPayeeFinancialAccountID=getValue(oElemList.item(a),Array("PayeeFinancialAccount","ID")) '[BT-84]
						.sPayeeFinancialAccountName=getValue(oElemList.item(a),Array("PayeeFinancialAccount","Name")) '[BT-85]
						.sPayeeFinancialInstitutionBranchID=getValue(oElemList.item(a),Array("PayeeFinancialAccount","FinancialInstitutionBranch","ID")) '[BT-86]
					Case "PaymentTerms"
						.sPaymentTerms=getValue(oElemList.item(a),Array("Note")) '[BT-20]
					Case "AllowanceCharge"
						ReDim Preserve arrAllowanceCharge(d,8)
						arrAllowanceCharge(d,CHARGE_INDICATOR)=getValue(oElemList.item(a),Array("ChargeIndicator")) '[Use “true” when informing about Charges and “false” when informing about Allowances.]
						arrAllowanceCharge(d,ALLOWANCE_CHARGE_REASON_CODE)=getValue(oElemList.item(a),Array("AllowanceChargeReasonCode")) '[BT-98] [BT-105]
						arrAllowanceCharge(d,ALLOWANCE_CHARGE_REASON)=getValue(oElemList.item(a),Array("AllowanceChargeReason")) '[BT-97] [BT-104]
						arrAllowanceCharge(d,MULTIPLIER_FACTOR_NUMERIC)=getValue(oElemList.item(a),Array("MultiplierFactorNumeric")) '[BT-94] [BT-101]
						arrAllowanceCharge(d,AMOUNT)=getValue(oElemList.item(a),Array("Amount")) '[BT-92] [BT-99]
						arrAllowanceCharge(d,BASE_AMOUNT)=getValue(oElemList.item(a),Array("BaseAmount")) '[BT-93] [BT-100]
						arrAllowanceCharge(d,TAX_CATEGORY_ID)=getValue(oElemList.item(a),Array("TaxCategory","ID")) '[BT-95] [BT-102]
						arrAllowanceCharge(d,TAX_PERCENT)=getValue(oElemList.item(a),Array("TaxCategory","Percent")) '[BT-96] [BT-103]
						d=d+1
					Case "TaxTotal"
						.sTaxTotalAmount=getValue(oElemList.item(a),Array("TaxAmount")) '[BT-110] [BT-111]
						oSubElemList=oElemList.item(a).getElementsByTagName("TaxSubtotal")
						For e = 0 To oSubElemList.getLength() - 1
							ReDim Preserve arrTaxSubtotal(e,5)
							arrTaxSubtotal(e,TAXABLE_AMOUNT)=getValue(oSubElemList.item(e),Array("TaxableAmount")) '[BT-116]
							arrTaxSubtotal(e,TAX_AMOUNT)=getValue(oSubElemList.item(e),Array("TaxAmount")) '[BT-117]
							arrTaxSubtotal(e,TAX_CATEGORY_ID)=getValue(oSubElemList.item(e),Array("TaxCategory","ID")) '[BT-118]
							arrTaxSubtotal(e,TAX_PERCENT)=getValue(oSubElemList.item(e),Array("TaxCategory","Percent")) '[BT-119]
							arrTaxSubtotal(e,TAX_EXEMPTION_REASON)=getValue(oSubElemList.item(e),Array("TaxCategory","TaxExemptionReason")) '[BT-120]
						Next
					Case "LegalMonetaryTotal"
						.sLineExtensionAmount=getValue(oElemList.item(a),Array("LineExtensionAmount")) '[BT-106]
						.sTaxExclusiveAmount=getValue(oElemList.item(a),Array("TaxExclusiveAmount")) '[BT-109]
						.sTaxInclusiveAmount=getValue(oElemList.item(a),Array("TaxInclusiveAmount")) '[BT-112]
						.sAllowanceTotalAmount=getValue(oElemList.item(a),Array("AllowanceTotalAmount")) '[BT-107]
						.sChargeTotalAmount=getValue(oElemList.item(a),Array("ChargeTotalAmount")) '[BT-108]
						.sPrepaidAmount=getValue(oElemList.item(a),Array("PrepaidAmount")) '[BT-113]
						.sPayableRoundingAmount=getValue(oElemList.item(a),Array("PayableRoundingAmount")) '[BT-114]
						.sPayableAmount=getValue(oElemList.item(a),Array("PayableAmount")) '[BT-115]
					Case "InvoiceLine"
						arrInvoiceLines=getInvoiceLines(oElemList.item(a),arrInvoiceLines)
				End Select
		Next
	End With
	CreateSheet
'	PrintValues
End Sub

Sub readZUGFeRD(oDOM As Object)
	Dim oElem As Object, oElemList As Object, oSubElemList As Object, oSubSubElemList As Object
	Dim a% , b% , c% , d% , e% , f% , g% , h% , i% , j% , k% , l%, x%
		
	oElemList=oDOM.getElementsByTagName("CrossIndustryInvoice").item(0).getChildNodes()
	With Invoice
		For a = 0 To oElemList.getLength() - 1
			Select Case oElemList.item(a).NodeName
				Case "ExchangedDocument"
					.sInvoiceID=getValue(oElemList.item(a),Array("ID")) '[BT-1]
					.sIssueDate=getValue(oElemList.item(a),Array("IssueDateTime","DateTimeString")) '[BT-2]
					.sInvoiceTypCode=getValue(oElemList.item(a),Array("TypeCode")) '[BT-3]
					oSubElemList=oElemList.item(a).getElementsByTagName("IncludedNote")
					For i = 0 To oSubElemList.getLength() - 1
						ReDim Preserve arrInvoiceNote(i)
						arrInvoiceNote(i)=getValue(oSubElemList.item(i),Array("Content")) '[BT-22]
					Next
				Case "SupplyChainTradeTransaction"
					oSubElemList=oElemList.item(a).getChildNodes()
					For b = 0 To oSubElemList.getLength() - 1
						Select Case oSubElemList.item(b).NodeName
							Case "IncludedSupplyChainTradeLineItem"
								ReDim Preserve arrInvoiceLines(b,13)
								arrInvoiceLines(b,INVOICE_LINE_ID)=getValue(oSubElemList.item(b),Array("AssociatedDocumentLineDocument","LineID")) '[BT-126]
								arrInvoiceLines(b,PARENT_INVOICE_LINE_ID)=getValue(oSubElemList.item(b),Array("AssociatedDocumentLineDocument","ParentLineID")) '[BT-X-304]
								arrInvoiceLines(b,INVOICE_LINE_NOTE)=getValue(oSubElemList.item(b),Array("AssociatedDocumentLineDocument","IncludedNote")) '[BT-127]
								arrInvoiceLines(b,INVOICE_LINE_ITEM_BUYERS_IDENTIFICATION_ID)=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","BuyerAssignedID")) '[BT-156]
								arrInvoiceLines(b,INVOICE_LINE_ITEM_SELLER_IDENTIFICATION_ID)=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","SellerAssignedID")) '[BT-155]
								arrInvoiceLines(b,INVOICE_LINE_ITEM_NAME)=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","Name")) '[BT-153]
								arrInvoiceLines(b,INVOICE_LINE_ITEM_DESCRIPTION)=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","Description")) '[BT-154]
								arrInvoiceLines(b,INVOICE_LINE_PRICE_AMOUNT)=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeAgreement","NetPriceProductTradePrice","ChargeAmount")) '[BT-146]
								arrInvoiceLines(b,INVOICED_QUANTITY)=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeDelivery","BilledQuantity")) '[BT-129]
								arrInvoiceLines(b,QUANTITY_UNIT_CODE)=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeDelivery","BilledQuantity"),"unitCode","",True) '[BT-130]
								arrInvoiceLines(b,TAX_CATEGORY_ID)=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","ApplicableTradeTax","CategoryCode")) '[BT-151]
								arrInvoiceLines(b,TAX_PERCENT)=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","ApplicableTradeTax","RateApplicablePercent")) '[BT-152]
								arrInvoiceLines(b,INVOICE_LINE_EXTENSION_AMOUNT)=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeSettlementLineMonetarySummation","LineTotalAmount")) '[BT-131]
							Case "ApplicableHeaderTradeAgreement"
								.sBuyerReference=getValue(oSubElemList.item(b),Array("BuyerReference")) '[BT-10]
								.sSellerName=getValue(oSubElemList.item(b),Array("SellerTradeParty","Name")) '[BT-27]
								.sSellerDescription=getValue(oSubElemList.item(b),Array("SellerTradeParty","Description")) '[BT-33]
								.sSellerPLZ=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","PostcodeCode")) '[BT-38]
								.sSellerStreetName=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","LineOne")) '[BT-35]
								.sSellerCityName=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","CityName")) '[BT-37]
								.sSellerCountryCode=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","CountryID")) '[BT-40]
								.sSellerEMail=getValue(oSubElemList.item(b),Array("SellerTradeParty","URIUniversalCommunication","URIID"),"schemeID","EM") '[BT-34]
								.sSellerTaxCompanyID=getValue(oSubElemList.item(b),Array("SellerTradeParty","SpecifiedTaxRegistration","ID")) '[BT-31] [BT-32]
								.sSellerContactName=getValue(oSubElemList.item(b),Array("SellerTradeParty","DefinedTradeContact","PersonName")) '[BT-41]
								.sSellerContactTelephone=getValue(oSubElemList.item(b),Array("SellerTradeParty","DefinedTradeContact","TelephoneUniversalCommunication","CompleteNumber")) '[BT-42]
								.sSellerContactElectronicMail=getValue(oSubElemList.item(b),Array("SellerTradeParty","DefinedTradeContact","EmailURIUniversalCommunication","URIID")) '[BT-43]
							Case "ApplicableHeaderTradeDelivery"
								.sActualDeliveryDate=getValue(oSubElemList.item(b),Array("ActualDeliverySupplyChainEvent","OccurrenceDateTime","DateTimeString")) '[BT-72]
							Case "ApplicableHeaderTradeSettlement"
								.sDocumentCurrencyCode=getValue(oSubElemList.item(b),Array("InvoiceCurrencyCode")) '[BT-5]
								.sPaymentMeansCode=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","TypeCode")) '[BT-81]
								.sPayeeFinancialAccountID=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","PayeePartyCreditorFinancialAccount","IBANID")) '[BT-84]
								.sPayeeFinancialAccountName=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","PayeePartyCreditorFinancialAccount","AccountName")) '[BT-85]
								.sPayeeFinancialInstitutionBranchID=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","PayeeSpecifiedCreditorFinancialInstitution","BICID")) '[BT-86]
								oSubSubElemList=oSubElemList.item(b).getElementsByTagName("ApplicableTradeTax")
								For c = 0 To oSubSubElemList.getLength() - 1
									ReDim Preserve arrTaxSubtotal(c,5)
									arrTaxSubtotal(c,TAX_AMOUNT)=getValue(oSubSubElemList.item(c),Array("CalculatedAmount")) '[BT-117]
									arrTaxSubtotal(c,TAX_EXEMPTION_REASON)=getValue(oSubSubElemList.item(c),Array("ExemptionReason")) '[BT-120]
									arrTaxSubtotal(c,TAXABLE_AMOUNT)=getValue(oSubSubElemList.item(c),Array("BasisAmount")) '[BT-116]
									arrTaxSubtotal(c,TAX_CATEGORY_ID)=getValue(oSubSubElemList.item(c),Array("CategoryCode")) '[BT-118]
									arrTaxSubtotal(c,TAX_PERCENT)=getValue(oSubSubElemList.item(c),Array("RateApplicablePercent")) '[BT-119]
								Next
								oSubSubElemList=oSubElemList.item(b).getElementsByTagName("SpecifiedTradeAllowanceCharge")
								For d = 0 To oSubSubElemList.getLength() - 1
									ReDim Preserve arrAllowanceCharge(d,8)
									arrAllowanceCharge(d,CHARGE_INDICATOR)=getValue(oSubSubElemList.item(d),Array("ChargeIndicator","Indicator")) '[Use “true” when informing about Charges and “false” when informing about Allowances.]
									arrAllowanceCharge(d,ALLOWANCE_CHARGE_REASON_CODE)=getValue(oSubSubElemList.item(d),Array("ReasonCode")) '[BT-98] [BT-105]
									arrAllowanceCharge(d,ALLOWANCE_CHARGE_REASON)=getValue(oSubSubElemList.item(d),Array("Reason")) '[BT-97] [BT-104]
									arrAllowanceCharge(d,MULTIPLIER_FACTOR_NUMERIC)=getValue(oSubSubElemList.item(d),Array("CalculationPercent")) '[BT-94] [BT-101]
									arrAllowanceCharge(d,AMOUNT)=getValue(oSubSubElemList.item(d),Array("ActualAmount")) '[BT-92] [BT-99]
									arrAllowanceCharge(d,BASE_AMOUNT)=getValue(oSubSubElemList.item(d),Array("BasisAmount")) '[BT-93] [BT-100]
									arrAllowanceCharge(d,TAX_CATEGORY_ID)=getValue(oSubSubElemList.item(d),Array("CategoryTradeTax","CategoryCode")) '[BT-95] [BT-102]
									arrAllowanceCharge(d,TAX_PERCENT)=getValue(oSubSubElemList.item(d),Array("CategoryTradeTax","RateApplicablePercent")) '[BT-96] [BT-103]
								Next
								.sPaymentTerms=getValue(oSubElemList.item(b),Array("SpecifiedTradePaymentTerms","Description")) '[BT-20]
								.sDueDate=getValue(oSubElemList.item(b),Array("SpecifiedTradePaymentTerms","DueDateDateTime","DateTimeString")) '[BT-9]
								.sLineExtensionAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","LineTotalAmount")) '[BT-106]
								.sChargeTotalAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","ChargeTotalAmount")) '[BT-108]
								.sAllowanceTotalAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","AllowanceTotalAmount")) '[BT-107]
								.sTaxExclusiveAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","TaxBasisTotalAmount")) '[BT-109]
								.sTaxTotalAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","TaxTotalAmount")) '[BT-110] [BT-111]
								.sTaxInclusiveAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","GrandTotalAmount")) '[BT-112]
								.sPrepaidAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","TotalPrepaidAmount")) '[BT-113]
								.sPayableAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","DuePayableAmount")) '[BT-115]
								.sPayableRoundingAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","RoundingAmount")) '[BT-114]
								oSubSubElemList=oSubElemList.item(b).getElementsByTagName("InvoiceReferencedDocument")
								For e = 0 To oSubSubElemList.getLength() - 1
									ReDim Preserve arrBillingReference(e,2)
									arrBillingReference(e,BILLING_REFERENCE_ID)=getValue(oSubSubElemList.item(e),Array("IssuerAssignedID")) '[BT-25]
									arrBillingReference(e,BILLING_REFERENCE_ISSUE_DATE)=getValue(oSubSubElemList.item(e),Array("FormattedIssueDateTime","DateTimeString")) '[BT-26]
								Next
						End Select
					Next
			End Select
		Next
	End With
	CreateSheet
End Sub

Function getInvoiceLines(oEntry As Object, arrInvoiceLines) As Variant
	Dim a%, b%, c%, i%, oElement As Object
	Dim iNumberSubInvoiceLines As Integer, iLevel As Integer, sParentID As String
	Dim arrInvoiceLineIDs() As String
	
On Error Goto Catch	
	
	If Not IsArray(arrInvoiceLines) Then 
		ReDim arrInvoiceLines(0,13)
	Else
		ReDim Preserve arrInvoiceLines(UBound(arrInvoiceLines)+1,13)
	End If
	
	a=UBound(arrInvoiceLines)
	arrInvoiceLines(a,INVOICE_LINE_LEVEL)=0
	arrInvoiceLines(a,INVOICE_LINE_ID)=getValue(oEntry,Array("ID")) '[BT-126]
	arrInvoiceLines(a,INVOICE_LINE_NOTE)=getValue(oEntry,Array("Note")) '[BT-127]
	arrInvoiceLines(a,INVOICED_QUANTITY)=getValue(oEntry,Array("InvoicedQuantity")) '[BT-129]
	arrInvoiceLines(a,QUANTITY_UNIT_CODE)=getValue(oEntry,Array("InvoicedQuantity"),"unitCode","",True) '[BT-130]
	arrInvoiceLines(a,INVOICE_LINE_EXTENSION_AMOUNT)=getValue(oEntry,Array("LineExtensionAmount")) '[BT-131]
	arrInvoiceLines(a,INVOICE_LINE_ITEM_DESCRIPTION)=getValue(oEntry,Array("Item","Description")) '[BT-154]
	arrInvoiceLines(a,INVOICE_LINE_ITEM_NAME)=getValue(oEntry,Array("Item","Name")) '[BT-153]
	arrInvoiceLines(a,INVOICE_LINE_ITEM_BUYERS_IDENTIFICATION_ID)=getValue(oEntry,Array("Item","BuyersItemIdentification","ID")) '[BT-156]
	arrInvoiceLines(a,INVOICE_LINE_ITEM_SELLER_IDENTIFICATION_ID)=getValue(oEntry,Array("Item","SellersItemIdentification","ID")) '[BT-155]
	arrInvoiceLines(a,TAX_CATEGORY_ID)=getValue(oEntry,Array("Item","ClassifiedTaxCategory","ID")) '[BT-151]
	arrInvoiceLines(a,TAX_PERCENT)=getValue(oEntry,Array("Item","ClassifiedTaxCategory","Percent")) '[BT-152]
	arrInvoiceLines(a,INVOICE_LINE_PRICE_AMOUNT)=getValue(oEntry,Array("Price","PriceAmount")) '[BT-146]

	sParentID=arrInvoiceLines(a,INVOICE_LINE_ID)
	
	iNumberSubInvoiceLines=oEntry.getElementsByTagName("SubInvoiceLine").getLength
	
	If iNumberSubInvoiceLines > 0 Then
		ReDim arrInvoiceLineIDs(iNumberSubInvoiceLines)
		ReDim Preserve arrInvoiceLines(UBound(arrInvoiceLines)+iNumberSubInvoiceLines,13)

		oElement=oEntry

		For i = (a+1) To iNumberSubInvoiceLines + a - 1
			Do While True
				For b = 0 To oElement.getChildNodes.getLength - 1
					If oElement.getChildNodes.item(b).NodeName = "SubInvoiceLine" Then
						For c = 0 To oElement.getChildNodes.item(b).getChildNodes.getLength - 1
							If oElement.getChildNodes.item(b).getChildNodes.item(c).NodeName = "ID" Then
								If Not bFieldInArray(arrInvoiceLineIDs,oElement.getChildNodes.item(b).getChildNodes.item(c).FirstChild.NodeValue) Then
									iLevel=iLevel+1
									sParentID=getValue(oElement,Array("ID"))
									oElement=oElement.getChildNodes.item(b)
									Exit Do
								End If
							End If 
						Next
					End If
				Next
				iLevel=iLevel-1
				oElement=oElement.getParentNode
				sParentID=getValue(oElement,Array("ID"))
			Loop 
			arrInvoiceLines(i,INVOICE_LINE_LEVEL)=iLevel
			arrInvoiceLines(i,PARENT_INVOICE_LINE_ID)=sParentID
			arrInvoiceLines(i,INVOICE_LINE_ID)=getValue(oElement,Array("ID")) '[BT-126]
			arrInvoiceLines(i,INVOICED_QUANTITY)=getValue(oElement,Array("InvoicedQuantity")) '[BT-129]
			arrInvoiceLines(i,QUANTITY_UNIT_CODE)=getValue(oElement,Array("InvoicedQuantity"),"unitCode","",True) '[BT-130]
			arrInvoiceLines(i,INVOICE_LINE_EXTENSION_AMOUNT)=getValue(oElement,Array("LineExtensionAmount")) '[BT-131]
			arrInvoiceLines(i,INVOICE_LINE_ITEM_DESCRIPTION)=getValue(oElement,Array("Item","Description")) '[BT-154]
			arrInvoiceLines(i,INVOICE_LINE_ITEM_NAME)=getValue(oElement,Array("Item","Name")) '[BT-153]
			arrInvoiceLines(i,INVOICE_LINE_ITEM_BUYERS_IDENTIFICATION_ID)=getValue(oElement,Array("Item","BuyersItemIdentification","ID")) '[BT-156]
			arrInvoiceLines(i,INVOICE_LINE_ITEM_SELLER_IDENTIFICATION_ID)=getValue(oElement,Array("Item","SellersItemIdentification","ID")) '[BT-155]
			arrInvoiceLines(i,TAX_CATEGORY_ID)=getValue(oElement,Array("Item","ClassifiedTaxCategory","ID")) '[BT-151]
			arrInvoiceLines(i,TAX_PERCENT)=getValue(oElement,Array("Item","ClassifiedTaxCategory","Percent")) '[BT-152]
			arrInvoiceLines(i,INVOICE_LINE_PRICE_AMOUNT)=getValue(oElement,Array("Price","PriceAmount")) '[BT-146]	
			arrInvoiceLineIDs(i-a-1)=arrInvoiceLines(i,INVOICE_LINE_ID)
		Next
	End If 
	getInvoiceLines=arrInvoiceLines
	Exit Function
	
Catch:
	MsgBox "Fehler beim Import der XML-Daten " & Chr$(10) & Chr$(10) & Error$ & " " & Chr$(10) & " ", 16, "XML-Import"	
End Function

Function bFieldInArray(arrArray(), sEntry as String) As Boolean
	Dim i%
	For i = LBound(arrArray()) to UBound(arrArray())
		If arrArray(i) = sEntry Then
			bFieldInArray = True
			Exit Function
		End if
	Next
	bFieldInArray = False
End Function

REM Function getValue #####################################################################################################################################
REM Parameter:
REM oEntry Element, welches untersucht werden soll
REM arrNodePath() ein Array mit Elementen die rekursiv durchlaufen werden sollen, aus dem letzten Eintrag im Array wird der Wert gelesen, es muss die Reihenfolge beachtet werden,
REM sAttributName Der Name das Atrributes, welches untersucht oder ausgegeben werden soll
REM sAttribut der Wert des letzten Elements wird nur ausgelesen, wenn dessen Attribut dem Parameter entspricht 
REM bGetAttribut Wenn True wird Atrribut.NodeValue ausgegeben, Wenn False wird nur verglichen ob das Attribunt mit dem Parameter übereinstimmt und dann NodeValue vom Element ausgegeben
Function getValue(oEntry As Object, arrNodePath(), Optional sAttributName As String, Optional sAttribut As String, Optional bGetAttribut As Boolean) As String
	Dim a%, oElement As Object
	If IsMissing(bGetAttribut) Then bGetAttribut=False
	oElement=oEntry
	getValue=""
	For a = 0 To UBound(arrNodePath())
		If oElement.getElementsByTagName(arrNodePath(a)).getLength > 0 And a < UBound(arrNodePath()) Then
			If oElement.getElementsByTagName(arrNodePath(a)).item(0).NodeName = arrNodePath(a) Then
				oElement=oElement.getElementsByTagName(arrNodePath(a)).item(0)
			End If
		ElseIf oElement.getElementsByTagName(arrNodePath(a)).getLength > 0 And a = UBound(arrNodePath()) Then
			If oElement.getElementsByTagName(arrNodePath(a)).item(0).NodeName = arrNodePath(a) Then
				If Not IsMissing(sAttributName) Then
					If oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.getLength > 0 Then
						If oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.item(0).NodeName = sAttributName Then
							If bGetAttribut Then
								getValue=oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.item(0).NodeValue
							Else
								If oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.item(0).NodeValue = sAttribut Then
									If oElement.getElementsByTagName(arrNodePath(a)).item(0).hasChildNodes Then _
										getValue=oElement.getElementsByTagName(arrNodePath(a)).item(0).FirstChild.NodeValue
								End If
							End If
						End If
					End If
					Exit Function
				Else
					If oElement.getElementsByTagName(arrNodePath(a)).item(0).hasChildNodes Then _
						getValue=oElement.getElementsByTagName(arrNodePath(a)).item(0).FirstChild.NodeValue
					Exit Function
				End If
			End If
		Else
			Exit Function
		End If
	Next
End Function

Sub PrintValues
	Dim bDebug As Boolean
	Dim a% , b% , c% , d% , e% , f% , g% , h% , i% , j% , k% , l%, x%
	
	bDebug = True
'	bDebug = False

	With Invoice
		If bDebug Then MsgBox "ID: " & .sInvoiceID & Chr$(10) &_
			"IssueDate: " & .sIssueDate & Chr$(10) &_
			"DueDate: " & .sDueDate & Chr$(10) &_
			"InvoiceTypeCode: " & .sInvoiceTypCode

		If IsArray(arrInvoiceNote) Then
			For f = 0 To UBound(arrInvoiceNote())
				If bDebug Then MsgBox  f+1 & ". Note -->" & Chr$(10) & arrInvoiceNote(f)
			Next
		End If
		
		If bDebug Then MsgBox "DocumentCurrencyCode: " & .sDocumentCurrencyCode
		If bDebug Then MsgBox "BuyerReference: " & .sBuyerReference

		If IsArray(arrBillingReference) Then
			For g = 0 To UBound(arrBillingReference())
				If bDebug Then MsgBox g+1 & ". ID: " & arrBillingReference(g,BILLING_REFERENCE_ID) & " IssueDate: " & arrBillingReference(g,BILLING_REFERENCE_ISSUE_DATE)
			Next
		End If
		
		If bDebug Then MsgBox "Supplier Party -->" &Chr$(10) & .sSellerName & Chr$(10) & .sSellerStreetName & Chr$(10) &_
				 .sSellerCountryCode & " " & .sSellerPLZ & " " & .sSellerCityName & Chr$(10) & .sSellerEMail
		If bDebug Then MsgBox  "SupplierTaxCompanyID: " & .sSellerTaxCompanyID
		If bDebug Then MsgBox "Supplier Contact -->" & Chr$(10) & .sSellerContactName & Chr$(10) &_
											"Telephone: " & .sSellerContactTelephone & Chr$(10) &_
											"ElectronicMail: " & .sSellerContactElectronicMail
		If bDebug Then MsgBox  "ActualDeliveryDate: " & .sActualDeliveryDate
		If bDebug Then MsgBox  "PaymentMeans -->" & Chr$(10) &_
											"PaymentMeansCode: " & .sPaymentMeansCode & Chr$(10) &_
											"IBAN: " & .sPayeeFinancialAccountID & Chr$(10) &_
											"AccountName: " & .sPayeeFinancialAccountName & Chr$(10) &_
											"BIC: " & .sPayeeFinancialInstitutionBranchID
		If bDebug Then MsgBox  "PaymentTerms:" & Chr$(10) & .sPaymentTerms
		
		If IsArray(arrAllowanceCharge) Then 
			For h = 0 To UBound(arrAllowanceCharge())
				If bDebug Then MsgBox h+1 & ". AllowanceCharge -->" & Chr$(10) &_
					"ChargeIndicator: " & arrAllowanceCharge(h,CHARGE_INDICATOR) & Chr$(10) &_
					"AllowanceChargeReasonCode: " & arrAllowanceCharge(h,ALLOWANCE_CHARGE_REASON_CODE) & Chr$(10) &_
					"AllowanceChargeReason: " & arrAllowanceCharge(h,ALLOWANCE_CHARGE_REASON) & Chr$(10) &_
					"MultiplierFactorNumeric: " & arrAllowanceCharge(h,MULTIPLIER_FACTOR_NUMERIC) & Chr$(10) &_
					"Amount: " & arrAllowanceCharge(h,AMOUNT) & Chr$(10) &_
					"BaseAmount: " & arrAllowanceCharge(h,BASE_AMOUNT) & Chr$(10) &_
					"TaxCategoryID: " & arrAllowanceCharge(h,TAX_CATEGORY_ID) & Chr$(10) &_
					"TaxCategoryPercent: " & arrAllowanceCharge(h,TAX_PERCENT) 
			Next
		End If
		
		If bDebug Then MsgBox "TaxTotalAmount: " & .sTaxTotalAmount
		
		For i = 0 To UBound(arrTaxSubtotal())
			If bDebug Then MsgBox i+1 & ". TaxSubtotal -->" & Chr$(10) &_
				"TaxableAmount: " & arrTaxSubtotal(i,TAXABLE_AMOUNT) & Chr$(10) &_
				"TaxAmount: " & arrTaxSubtotal(i,TAX_AMOUNT) & Chr$(10) &_
				"TaxCategoryID: " & arrTaxSubtotal(i,TAX_CATEGORY_ID) & Chr$(10) &_
				"TaxPercent: " & arrTaxSubtotal(i,TAX_PERCENT) & Chr$(10) &_
				"TaxExemptionReason: " & arrTaxSubtotal(i,TAX_EXEMPTION_REASON)
		Next
		
		If bDebug Then MsgBox "LegalMonetaryTotal -->" & Chr$(10) &_
			"LineExtensionAmount: " & .sLineExtensionAmount & Chr$(10) &_
			"TaxExclusiveAmount: " & .sTaxExclusiveAmount & Chr$(10) &_
			"TaxInclusiveAmount: " & .sTaxInclusiveAmount & Chr$(10) &_
			"AllowanceTotalAmount: " & .sAllowanceTotalAmount & Chr$(10) &_
			"PrepaidAmount: " & .sPrepaidAmount & Chr$(10) &_
			"PayableRoundingAmount: " & .sPayableRoundingAmount & Chr$(10) &_
			"PayableAmount: " & .sPayableAmount

		For j = 0 To UBound(arrInvoiceLines())
			If bDebug Then MsgBox(j+1 & ". InvoiceLine -->" & Chr$(10) &_
				"Level: " & arrInvoiceLines(j,INVOICE_LINE_LEVEL) & Chr$(10) &_
				"Parent ID: " & arrInvoiceLines(j,PARENT_INVOICE_LINE_ID) & Chr$(10) &_
				"ID: " & arrInvoiceLines(j,INVOICE_LINE_ID) & Chr$(10) &_
				"Note: " & arrInvoiceLines(j,INVOICE_LINE_NOTE) & Chr$(10) &_
				"Quantity: " & arrInvoiceLines(j,INVOICED_QUANTITY) & Chr$(10) &_
				"UnitCode: " & arrInvoiceLines(j,QUANTITY_UNIT_CODE) & Chr$(10) &_
				"ExtensionAmount: " & arrInvoiceLines(j,INVOICE_LINE_EXTENSION_AMOUNT) & Chr$(10) &_
				"Description: " & arrInvoiceLines(j,INVOICE_LINE_ITEM_DESCRIPTION) & Chr$(10) &_
				"Name: " & arrInvoiceLines(j,INVOICE_LINE_ITEM_NAME) & Chr$(10) &_
				"Buyer IdentID: " & arrInvoiceLines(j,INVOICE_LINE_ITEM_BUYERS_IDENTIFICATION_ID) & Chr$(10) &_
				"Sellers IdentID: " & arrInvoiceLines(j,INVOICE_LINE_ITEM_SELLER_IDENTIFICATION_ID) & Chr$(10) &_
				"TaxCategory: " & arrInvoiceLines(j,TAX_CATEGORY_ID) & Chr$(10) &_
				"TaxPercent: " & arrInvoiceLines(j,TAX_PERCENT) & Chr$(10) &_
				"PriceAmount: " & arrInvoiceLines(j,INVOICE_LINE_PRICE_AMOUNT))
		Next
	End With 
End Sub

Sub CreateSheet
	Dim oCalcDoc As Object, oSheet As Object, oPathSettings As Object
	Dim iRow As Integer
	oPathSettings = CreateUnoService("com.sun.star.util.PathSettings")
	oCalcDoc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, Array())
	oSheet = oCalcDoc.Sheets(0)  
	
	Dim a% , b% , c% , d% , e% , f% , g% , h% , i% , j% , k% , l%, x%
 	With Invoice
		
		iRow=1
		fillSheet(oSheet,"A" & iRow,"Invoice ID",True)
		fillSheet(oSheet,"B" & iRow,"IssueDate",True)
		fillSheet(oSheet,"C" & iRow,"DueDate",True)
		fillSheet(oSheet,"D" & iRow,"ActualDeliveryDate",True)
		fillSheet(oSheet,"E" & iRow,"InvoiceTypeCode",True)
		fillSheet(oSheet,"F" & iRow,"DocumentCurrencyCode",True)
		fillSheet(oSheet,"G" & iRow,"BuyerReference",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sInvoiceID,False)
		fillSheet(oSheet,"B" & iRow,.sIssueDate,False)
		fillSheet(oSheet,"C" & iRow,.sDueDate,False)
		fillSheet(oSheet,"D" & iRow,.sActualDeliveryDate,False)
		fillSheet(oSheet,"E" & iRow,.sInvoiceTypCode,False)
		fillSheet(oSheet,"F" & iRow,.sDocumentCurrencyCode,False)
		fillSheet(oSheet,"G" & iRow,.sBuyerReference,False)
		iRow=iRow+1
		
		If IsArray(arrInvoiceNote) Then
			fillSheet(oSheet,"A" & iRow & ":D" & iRow,"Invoice Notes",True)
			iRow=iRow+1
			For a = 0 To UBound(arrInvoiceNote())
				fillSheet(oSheet,"A" & iRow+a & ":D" & iRow+a,arrInvoiceNote(a),False)				
			Next
			iRow=iRow+a+1
		End If
	
		If IsArray(arrBillingReference) Then
			fillSheet(oSheet,"A" & iRow,"BillingReference ID",True)
			fillSheet(oSheet,"B" & iRow,"IssueDate",True)
			iRow=iRow+1
			For b = 0 To UBound(arrBillingReference())
				fillSheet(oSheet,"A" & iRow+b,arrBillingReference(b,BILLING_REFERENCE_ID),False)				
				fillSheet(oSheet,"B" & iRow+b,arrBillingReference(b,BILLING_REFERENCE_ISSUE_DATE),False)				
			Next
			iRow=iRow+b+1
		End If

		fillSheet(oSheet,"A" & iRow,"Seller Party -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"SellerName",True)
		fillSheet(oSheet,"B" & iRow,"SellerStreetName",True)
		fillSheet(oSheet,"C" & iRow,"SellerCountryCode",True)
		fillSheet(oSheet,"D" & iRow,"SellerPLZ",True)
		fillSheet(oSheet,"E" & iRow,"SellerCityName",True)
		fillSheet(oSheet,"F" & iRow,"SellerEMail",True)
		fillSheet(oSheet,"G" & iRow,"Seller TaxCompanyID",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sSellerName,False)
		fillSheet(oSheet,"B" & iRow,.sSellerStreetName,False)
		fillSheet(oSheet,"C" & iRow,.sSellerCountryCode,False)
		fillSheet(oSheet,"D" & iRow,.sSellerPLZ,False)
		fillSheet(oSheet,"E" & iRow,.sSellerCityName,False)
		fillSheet(oSheet,"F" & iRow,.sSellerEMail,False)
		fillSheet(oSheet,"G" & iRow,.sSellerTaxCompanyID,False)
		iRow=iRow+2

		fillSheet(oSheet,"A" & iRow,"Seller Contact -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"ContactName",True)
		fillSheet(oSheet,"B" & iRow,"Telephone",True)
		fillSheet(oSheet,"C" & iRow,"ElectronicMail",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sSellerContactName,False)
		fillSheet(oSheet,"B" & iRow,.sSellerContactTelephone,False)
		fillSheet(oSheet,"C" & iRow,.sSellerContactElectronicMail,False)
		iRow=iRow+2
	
		fillSheet(oSheet,"A" & iRow,"PaymentMeans -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"AccountName",True)
		fillSheet(oSheet,"B" & iRow,"IBAN",True)
		fillSheet(oSheet,"C" & iRow,"BIC",True)
		fillSheet(oSheet,"D" & iRow,"PaymentMeansCode",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sPayeeFinancialAccountName,False)
		fillSheet(oSheet,"B" & iRow,.sPayeeFinancialAccountID,False)
		fillSheet(oSheet,"C" & iRow,.sPayeeFinancialInstitutionBranchID,False)
		fillSheet(oSheet,"D" & iRow,.sPaymentMeansCode,False)
		iRow=iRow+2
	
		fillSheet(oSheet,"A" & iRow & ":D" & iRow,"PaymentTerms",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow & ":D" & iRow,.sPaymentTerms,False)
		iRow=iRow+2

		If IsArray(arrAllowanceCharge) Then
			fillSheet(oSheet,"A" & iRow,"AllowanceCharge -->",False)
			iRow=iRow+1
			fillSheet(oSheet,"A" & iRow,"ChargeIndicator",True)
			fillSheet(oSheet,"B" & iRow,"MultiplierFactorNumeric",True)
			fillSheet(oSheet,"C" & iRow,"Amount",True)
			fillSheet(oSheet,"D" & iRow,"BaseAmount",True)
			fillSheet(oSheet,"E" & iRow,"TaxCategoryID",True)
			fillSheet(oSheet,"F" & iRow,"TaxCategoryPercent",True)
			fillSheet(oSheet,"G" & iRow,"AllowanceChargeReasonCode",True)
			fillSheet(oSheet,"H" & iRow,"AllowanceChargeReason",True)
			iRow=iRow+1
			For c = 0 To UBound(arrAllowanceCharge())
				fillSheet(oSheet,"A" & iRow+c,arrAllowanceCharge(c,CHARGE_INDICATOR),False)				
				fillSheet(oSheet,"B" & iRow+c,arrAllowanceCharge(c,MULTIPLIER_FACTOR_NUMERIC),False)				
				fillSheet(oSheet,"C" & iRow+c,arrAllowanceCharge(c,AMOUNT),False)				
				fillSheet(oSheet,"D" & iRow+c,arrAllowanceCharge(c,BASE_AMOUNT),False)				
				fillSheet(oSheet,"E" & iRow+c,arrAllowanceCharge(c,TAX_CATEGORY_ID),False)				
				fillSheet(oSheet,"F" & iRow+c,arrAllowanceCharge(c,TAX_PERCENT),False)				
				fillSheet(oSheet,"G" & iRow+c,arrAllowanceCharge(c,ALLOWANCE_CHARGE_REASON_CODE),False)				
				fillSheet(oSheet,"H" & iRow+c,arrAllowanceCharge(c,ALLOWANCE_CHARGE_REASON),False)				
			Next
			iRow=iRow+c+1
		End If

		fillSheet(oSheet,"A" & iRow,"TaxTotalAmount:",True)
		fillSheet(oSheet,"B" & iRow,.sTaxTotalAmount,False)
		iRow=iRow+2

		If IsArray(arrTaxSubtotal) Then
			fillSheet(oSheet,"A" & iRow,"TaxSubtotal -->",False)
			iRow=iRow+1
			fillSheet(oSheet,"A" & iRow,"TaxableAmount",True)
			fillSheet(oSheet,"B" & iRow,"TaxAmount",True)
			fillSheet(oSheet,"C" & iRow,"TaxCategoryID",True)
			fillSheet(oSheet,"D" & iRow,"TaxPercent",True)
			fillSheet(oSheet,"E" & iRow,"",True)
			fillSheet(oSheet,"F" & iRow,"",True)
			fillSheet(oSheet,"G" & iRow,"",True)
			fillSheet(oSheet,"H" & iRow,"TaxExemptionReason",True)
			iRow=iRow+1
			For d = 0 To UBound(arrTaxSubtotal())
				fillSheet(oSheet,"A" & iRow+d,arrTaxSubtotal(d,TAXABLE_AMOUNT),False)				
				fillSheet(oSheet,"B" & iRow+d,arrTaxSubtotal(d,TAX_AMOUNT),False)				
				fillSheet(oSheet,"C" & iRow+d,arrTaxSubtotal(d,TAX_CATEGORY_ID),False)				
				fillSheet(oSheet,"D" & iRow+d,arrTaxSubtotal(d,TAX_PERCENT),False)				
				fillSheet(oSheet,"H" & iRow+d,arrTaxSubtotal(d,TAX_EXEMPTION_REASON),False)				
			Next
			iRow=iRow+d+1
		End If

		fillSheet(oSheet,"A" & iRow,"LegalMonetaryTotal -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"LineExtensionAmount",True)
		fillSheet(oSheet,"B" & iRow,"TaxExclusiveAmount",True)
		fillSheet(oSheet,"C" & iRow,"TaxInclusiveAmount",True)
		fillSheet(oSheet,"D" & iRow,"AllowanceTotalAmount",True)
		fillSheet(oSheet,"E" & iRow,"PrepaidAmount",True)
		fillSheet(oSheet,"F" & iRow,"PayableRoundingAmount",True)
		fillSheet(oSheet,"G" & iRow,"PayableAmount",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sLineExtensionAmount,False)
		fillSheet(oSheet,"B" & iRow,.sTaxExclusiveAmount,False)
		fillSheet(oSheet,"C" & iRow,.sTaxInclusiveAmount,False)
		fillSheet(oSheet,"D" & iRow,.sAllowanceTotalAmount,False)
		fillSheet(oSheet,"E" & iRow,.sPrepaidAmount,False)
		fillSheet(oSheet,"F" & iRow,.sPayableRoundingAmount,False)
		fillSheet(oSheet,"G" & iRow,.sPayableAmount,False)
		iRow=iRow+2

		If IsArray(arrInvoiceLines) Then
			fillSheet(oSheet,"A" & iRow,"InvoiceLine -->",False)
			iRow=iRow+1
			fillSheet(oSheet,"A" & iRow,"Level",True)
			fillSheet(oSheet,"B" & iRow,"Parent ID",True)
			fillSheet(oSheet,"C" & iRow,"InvoiceLine ID",True)
			fillSheet(oSheet,"D" & iRow,"Quantity",True)
			fillSheet(oSheet,"E" & iRow,"UnitCode",True)
			fillSheet(oSheet,"F" & iRow,"Buyer IdentID",True)
			fillSheet(oSheet,"G" & iRow,"Sellers IdentID",True)
			fillSheet(oSheet,"H" & iRow,"Name",True)
			fillSheet(oSheet,"I" & iRow,"TaxCategory",True)
			fillSheet(oSheet,"J" & iRow,"TaxPercent",True)
			fillSheet(oSheet,"K" & iRow,"ExtensionAmount" & Chr$(10) & "LineTotalAmount",True)
			fillSheet(oSheet,"L" & iRow,"PriceAmount" & Chr$(10) & "ChargeAmount",True)
			fillSheet(oSheet,"M" & iRow,"Description",True)
			iRow=iRow+1
			For e = 0 To UBound(arrInvoiceLines())
				fillSheet(oSheet,"A" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_LEVEL),False)				
				fillSheet(oSheet,"B" & iRow+e,arrInvoiceLines(e,PARENT_INVOICE_LINE_ID),False)				
				fillSheet(oSheet,"C" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_ID),False)				
				fillSheet(oSheet,"D" & iRow+e,arrInvoiceLines(e,INVOICED_QUANTITY),False)				
				fillSheet(oSheet,"E" & iRow+e,arrInvoiceLines(e,QUANTITY_UNIT_CODE),False)				
				fillSheet(oSheet,"F" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_ITEM_BUYERS_IDENTIFICATION_ID),False)				
				fillSheet(oSheet,"G" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_ITEM_SELLER_IDENTIFICATION_ID),False)				
				fillSheet(oSheet,"H" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_ITEM_NAME),False)				
				fillSheet(oSheet,"I" & iRow+e,arrInvoiceLines(e,TAX_CATEGORY_ID),False)				
				fillSheet(oSheet,"J" & iRow+e,arrInvoiceLines(e,TAX_PERCENT),False)				
				fillSheet(oSheet,"K" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_EXTENSION_AMOUNT),False)				
				fillSheet(oSheet,"L" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_PRICE_AMOUNT),False)				
				fillSheet(oSheet,"M" & iRow+e,arrInvoiceLines(e,INVOICE_LINE_ITEM_DESCRIPTION),False)				
			Next
			iRow=iRow+e+1
		End If
		
 	End With
 	oSheet.getColumns().OptimalWidth = True
 	oSheet.getRows().OptimalHeight = True
End Sub

Sub fillSheet(oSheet, sRange As String, sValue As String, bBottomLine As Boolean)
	Dim oBorder As Object, oCell As Object, oRange As Object
	Dim bLO As Boolean
	
	oBorder = CreateUnoStruct("com.sun.star.table.BorderLine2")
	bLO = True
	
	If IsNull(oBorder) Then
		bLO = False
		oBorder = CreateUnoStruct("com.sun.star.table.BorderLine")
	End If

	oBorder.OuterLineWidth = 40
	If InStr(sRange,":") > 0 Then
		oRange=oSheet.getCellRangeByName(sRange)
		oRange.merge(True)
		oCell=oSheet.getCellRangeByName(Split(sRange,":")(0))
	Else
		oCell=oSheet.getCellRangeByName(sRange)
	End If
	If bBottomLine Then
		If bLO Then
			oBorder.LineStyle = com.sun.star.table.BorderLineStyle.SOLID
			oBorder.LineWidth = 40
			oCell.BottomBorder2 = oBorder
		Else
			oCell.BottomBorder = oBorder
		End If
	End If
	oCell.VertJustify = com.sun.star.table.CellVertJustify.TOP
	oCell.String = sValue
End Sub

Angebots- und Rechnungsverwaltung mit Kunden- und Lieferantenstamm, OP-Buchhaltung, Nachkalkulation und Vielem mehr... für LibreOffice/OpenOffice

https://github.com/heifisch/aladin

aladin
Beiträge: 39
Registriert: Di 30. Jul 2019, 15:49
Kontaktdaten:

Re: XRechnung und ZUGFeRD Rechnungen als DOM-Dokument-Objekt einlesen/erzeugen

Beitrag von aladin » Di 30. Sep 2025, 20:37

Hier eine Weiterentwicklung das Codes..
Damit werden (denke ich) alle relevanten Daten aus den Rechnungen extrahiert.
Die Daten werden als Rückgabe einer Funktion in ein Array aus Type-Strukturen und Type-Struktur-Arrays gespeichert.
Mit der Routine CreateSheet() werden die Daten in ein Calc-Dokument eingefügt.

Falls es jemand gebrauchen kann, hier der Code:

Code: Alles auswählen

REM  *****  BASIC  *****

Option Explicit

REM Konstanten für die Adressierung des Array, welches die Funktion readInvoice zurück gibt
REM Array(Invoice,InvoiceNotes,BillingReferences,AllowanceCharges,TaxSubtotale,InvoiceLines)

Global Const INVOICE=0	' Struct
Global Const INVOICE_NOTES=1 ' Struct Array
Global Const BILLING_REFERENCES=2 ' Struct Array
Global Const ALLOWANCE_CHARGES=3 ' Struct Array
Global Const TAX_SUBTOTALE=4 ' Struct Array
Global Const INVOICE_LINES=5 ' Struct Array

Type structInvoice
	sInvoiceID As String '[BT-1]
	sIssueDate As String '[BT-2]
	sInvoiceTypCode As String '[BT-3]
	sDocumentCurrencyCode As String '[BT-5]
	sDueDate As String '[BT-9]
	sBuyerReference As String '[BT-10]
	sPaymentTerms As String '[BT-20]
	sSellerName As String '[BT-28]
	sSellerTaxCompanyID As String '[BT-31] [BT-32]
	sSellerDescription As String '[BT-33]
	sSellerEMail As String '[BT-34]
	sSellerStreetName As String '[BT-35]
	sSellerCityName As String '[BT-37]
	sSellerPLZ As String '[BT-38]
	sSellerCountryCode As String '[BT-40]
	sSellerContactName As String '[BT-41]
	sSellerContactTelephone As String '[BT-42]
	sSellerContactElectronicMail As String '[BT-43]
	sBuyerName As String '[BT-44]
	sBuyerIdentifier As String '[BT-46]
	sBuyerTaxCompanyID As String '[BT-48]
	sBuyerEMail As String '[BT-49]
	sBuyerStreetName As String '[BT-50]
	sBuyerCityName As String '[BT-52]
	sBuyerPLZ As String '[BT-53]
	sBuyerCountryCode As String '[BT-55]
	sBuyerContactName As String '[BT-56]
	sBuyerContactTelephone As String '[BT-57]
	sBuyerContactElectronicMail As String '[BT-58]
	sActualDeliveryDate As String '[BT-72]
	sPaymentMeansCode As String '[BT-81]
	sPayeeFinancialAccountID As String '[BT-84]
	sPayeeFinancialAccountName As String '[BT-85]
	sPayeeFinancialInstitutionBranchID As String '[BT-86]
	sLineExtensionAmount As String '[BT-106]
	sAllowanceTotalAmount As String '[BT-107]
	sChargeTotalAmount As String '[BT-108]
	sTaxExclusiveAmount As String '[BT-109]
	sTaxTotalAmount As String '[BT-110] [BT-111]
	sTaxInclusiveAmount As String '[BT-112]
	sPrepaidAmount As String '[BT-113]
	sPayableRoundingAmount As String '[BT-114]
	sPayableAmount As String '[BT-115]
End Type

Type structBillingReference
	sID As String '[BT-25]
	sIssueDate As String '[BT-26]
End Type

Type structAllowanceCharge
	sIndicator As String  '[Use “true” when informing about Charges and “false” when informing about Allowances.]
	sAmount As String '[BT-92] [BT-99]
	sBaseAmount As String '[BT-93] [BT-100]
	sPercent As String '[BT-94] [BT-101]
	sTaxCategoryID As String '[BT-95] [BT-102]
	sTaxPercent As String '[BT-96] [BT-103]
	sReason As String '[BT-97] [BT-104]
	sReasonCode As String '[BT-98] [BT-105]
End Type

Type structTaxSubtotal
	sTaxableAmount As String '[BT-116]
	sTaxAmount As String '[BT-117]
	sTaxCategoryID As String '[BT-118]
	sTaxPercent As String '[BT-119]
	sTaxExemptionReason As String '[BT-120]
End Type

Type structInvoiceLine
	sLevel As String 'Level SubInvoiceLines
	sParentID As String '[BT-X-304] 'SubInvoiceLines
	sID As String '[BT-126]
	sNote As String '[BT-127]
	sQuantity As String '[BT-129]
	sUnitCode As String '[BT-130]
	sNetAmount As String '[BT-131]
	sPeriodStartDate As String '[BT-134]
	sPeriodEndDate As String '[BT-135]
	sAllowanceChargeIndicator As String  '[Use “true” when informing about Charges and “false” when informing about Allowances.]
	sAllowanceChargeAmount As String '[BT-136] [BT-141]
	sAllowanceChargeBaseAmount As String '[BT-137] [BT-142]
	sAllowanceChargePercent As String '[BT-138] [BT-143]
	sAllowanceChargeReason As String '[BT-139] [BT-144]
	sAllowanceChargeReasonCode As String '[BT-140] [BT-145]
	sItemNetPrice As String  '[BT-146]
	sTaxCategoryID As String '[BT-151]
	sTaxPercent As String '[BT-152]
	sItemName As String '[BT-153]
	sItemDescription As String '[BT-154]
	sSellerAssignedID As String '[BT-155]
	sBuyerAssignedID As String '[BT-156]
End Type

Type structInvoiceNote
	sSubjectCode As String '[BT-21]
	sNote As String '[BT-22]
End Type

REM Funktion readInvoice #########################################################################################
REM Mit der Funktion readInvoice kann eine E-Rechnung im XRechnung- oder ZUGFeRD-Format eingelesen werden.
REM Nach der Dateiauswahl werden die Daten als Funktions-Rückgabe in einem Array aus Type-Struktur und Type-Struktur-Arrays
REM zurückgegeben. Das Array kann mit obigen Konstanten Adressiert werden.
REM Aufgerufen in einer Subroutine kann die Funktion folgendermaßen werden:
REM
REM Sub Test()
REM		Dim InvoiceData As Variant, b%
REM		InvoiceData=readInvoice
REM		With InvoiceData(INVOICE)
REM			Print .sInvoiceID
REM		End With
REM		
REM		For b = 0 To UBound(InvoiceData(BILLING_REFERENCES))
REM			With InvoiceData(BILLING_REFERENCES)(b)
REM				Print .sID				
REM				Print .sIssueDate		
REM			End With		
REM		Next
REM ...
REM End Sub
REM
REM Ein vollständiges Beispiel, wie auf die Daten zugegriffen werden kann, ist in der Routine CreateSheet() zu sehen.
REM Mit dieser, werden die Daten aus der Rechnung in eine Calc-Tabelle eingefügt.

Function readInvoice As Variant
	Dim oDocBuilder, oDOM, sURL As String, a%, bInvoiceFound As Boolean
	Dim oFilePicker As Object, oSettings As Object, oFileAccess As Object
 
	oSettings = CreateUnoService("com.sun.star.util.PathSettings")
	sURL = oSettings.Work
 	oFilePicker = CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
	oFilePicker.AppendFilter("XML-Dateien (*.xml)", "*.xml")
	oFilePicker.SetCurrentFilter("XML-Dateien (*.xml)")
	oFilePicker.MultiSelectionMode=False
	
	oFileAccess = CreateUnoService("com.sun.star.ucb.SimpleFileAccess")
	If oFileAccess.exists(sURL) Then
		oFilePicker.setDisplayDirectory(sURL)
	End If

	If oFilePicker.execute() Then
		sURL=oFilePicker.Files(0)
	End If
    	
	oDocBuilder = CreateUnoService("com.sun.star.xml.dom.DocumentBuilder")
	oDOM = oDocBuilder.parseURI(ConvertFromURL(sURL))
	oDOM.normalize()

	For a = 0 To oDOM.ChildNodes.getLength - 1
		Select Case oDOM.ChildNodes.item(a).NodeName
			Case "Invoice"
				bInvoiceFound=True
					readInvoice=readXRechnung(oDOM) 
			Case "CrossIndustryInvoice"
				bInvoiceFound=True
					readInvoice=readZUGFeRD(oDOM)
		End Select
	Next 
	
	If Not bInvoiceFound Then
		Print "Keine Rechnungsstruktur erkannt"
	End If
End Function

Function readXRechnung(oDOM As Object) As Variant
	Dim oElem As Object, oElemList As Object, oSubElemList As Object
	Dim Invoice As New structInvoice, InvoiceNotes() As New structInvoiceNote, BillingReferences() As New structBillingReference
	Dim AllowanceCharges() As New structAllowanceCharge, TaxSubtotale() As New structTaxSubtotal, InvoiceLinesFirst() As New structInvoiceLine
	Dim InvoiceLines As Variant
	
	Dim a% , b% , c% , d% , e% , f% , g% , h% , i% , j% , k% , l%, x%
		
	oElemList=oDOM.getElementsByTagName("Invoice").item(0).getChildNodes()
	With Invoice
		For a = 0 To oElemList.getLength() - 1
				Select Case oElemList.item(a).NodeName
					Case "ID"
						.sInvoiceID=oElemList.item(a).FirstChild.NodeValue '[BT-1]
					Case "IssueDate"
						.sIssueDate=oElemList.item(a).FirstChild.NodeValue '[BT-2]
					Case "DueDate"
						.sDueDate=oElemList.item(a).FirstChild.NodeValue	'[BT-9]
					Case "InvoiceTypeCode"
						.sInvoiceTypCode=oElemList.item(a).FirstChild.NodeValue '[BT-3]
					Case "Note"
						ReDim Preserve InvoiceNotes(b)
						With InvoiceNotes(b)
							If InStr(oElemList.item(a).FirstChild.NodeValue,"#") > 0 Then
								.sSubjectCode=oElemList.item(a).FirstChild.NodeValue '[BT-21]
								.sNote=oElemList.item(a).FirstChild.NodeValue '[BT-22]
							Else
								.sNote=oElemList.item(a).FirstChild.NodeValue '[BT-22]
							End If
						End With 
						b=b+1
					Case "DocumentCurrencyCode"
						.sDocumentCurrencyCode=oElemList.item(a).FirstChild.NodeValue '[BT-5]
					Case "BuyerReference"
						.sBuyerReference=oElemList.item(a).FirstChild.NodeValue '[BT-10]
					Case "BillingReference" '[BG-3]
						ReDim Preserve BillingReferences(c)
						With BillingReferences(c)
							.sID=getValue(oElemList.item(a),Array("ID")) '[BT-25]
							.sIssueDate=getValue(oElemList.item(a),Array("IssueDate")) '[BT-26]
						End With
						c=c+1
					Case "AccountingSupplierParty"
						.sSellerEMail=getValue(oElemList.item(a),Array("Party","EndpointID"),"schemeID","EM") '[BT-34]
						.sSellerName=getValue(oElemList.item(a),Array("Party","PartyName","Name")) '[BT-28]
						.sSellerStreetName=getValue(oElemList.item(a),Array("Party","PostalAddress","StreetName")) '[BT-35]
						.sSellerCityName=getValue(oElemList.item(a),Array("Party","PostalAddress","CityName")) '[BT-37]
						.sSellerPLZ=getValue(oElemList.item(a),Array("Party","PostalAddress","PostalZone")) '[BT-38]
						.sSellerCountryCode=getValue(oElemList.item(a),Array("Party","PostalAddress","Country","IdentificationCode")) '[BT-40]
						.sSellerTaxCompanyID=getValue(oElemList.item(a),Array("Party","PartyTaxScheme","CompanyID")) '[BT-31] [BT-32]
						.sSellerContactName=getValue(oElemList.item(a),Array("Party","Contact","Name")) '[BT-41]
						.sSellerContactTelephone=getValue(oElemList.item(a),Array("Party","Contact","Telephone")) '[BT-42]
						.sSellerContactElectronicMail=getValue(oElemList.item(a),Array("Party","Contact","ElectronicMail")) '[BT-43]
					Case "AccountingCustomerParty"
						.sBuyerEMail=getValue(oElemList.item(a),Array("Party","EndpointID"),"schemeID","EM") '[BT-49]
						.sBuyerName=getValue(oElemList.item(a),Array("Party","PartyName","Name")) '[BT-44]
						.sBuyerStreetName=getValue(oElemList.item(a),Array("Party","PostalAddress","StreetName")) '[BT-50]
						.sBuyerCityName=getValue(oElemList.item(a),Array("Party","PostalAddress","CityName")) '[BT-52]
						.sBuyerPLZ=getValue(oElemList.item(a),Array("Party","PostalAddress","PostalZone")) '[BT-53]
						.sBuyerCountryCode=getValue(oElemList.item(a),Array("Party","PostalAddress","Country","IdentificationCode")) '[BT-55]
						.sBuyerTaxCompanyID=getValue(oElemList.item(a),Array("Party","PartyTaxScheme","CompanyID")) '[BT-48]
						.sBuyerContactName=getValue(oElemList.item(a),Array("Party","Contact","Name")) '[BT-56]
						.sBuyerContactTelephone=getValue(oElemList.item(a),Array("Party","Contact","Telephone")) '[BT-57]
						.sBuyerContactElectronicMail=getValue(oElemList.item(a),Array("Party","Contact","ElectronicMail")) '[BT-58]
					Case "Delivery"
						.sActualDeliveryDate=getValue(oElemList.item(a),Array("ActualDeliveryDate")) '[BT-72]
					Case "PaymentMeans"
						.sPaymentMeansCode=getValue(oElemList.item(a),Array("PaymentMeansCode")) '[BT-81]
						.sPayeeFinancialAccountID=getValue(oElemList.item(a),Array("PayeeFinancialAccount","ID")) '[BT-84]
						.sPayeeFinancialAccountName=getValue(oElemList.item(a),Array("PayeeFinancialAccount","Name")) '[BT-85]
						.sPayeeFinancialInstitutionBranchID=getValue(oElemList.item(a),Array("PayeeFinancialAccount","FinancialInstitutionBranch","ID")) '[BT-86]
					Case "PaymentTerms"
						.sPaymentTerms=getValue(oElemList.item(a),Array("Note")) '[BT-20]
					Case "AllowanceCharge"
						ReDim Preserve AllowanceCharges(d)
						With AllowanceCharges(d)
							.sIndicator=getValue(oElemList.item(a),Array("ChargeIndicator")) '[Use “true” when informing about Charges and “false” when informing about Allowances.]
							.sAmount=getValue(oElemList.item(a),Array("Amount")) '[BT-92] [BT-99]
							.sBaseAmount=getValue(oElemList.item(a),Array("BaseAmount")) '[BT-93] [BT-100]
							.sPercent=getValue(oElemList.item(a),Array("MultiplierFactorNumeric")) '[BT-94] [BT-101]
							.sTaxCategoryID=getValue(oElemList.item(a),Array("TaxCategory","ID")) '[BT-95] [BT-102]
							.sTaxPercent=getValue(oElemList.item(a),Array("TaxCategory","Percent")) '[BT-96] [BT-103]
							.sReason=getValue(oElemList.item(a),Array("AllowanceChargeReason")) '[BT-97] [BT-104]
							.sReasonCode=getValue(oElemList.item(a),Array("AllowanceChargeReasonCode")) '[BT-98] [BT-105]
						End With
						d=d+1
					Case "TaxTotal"
						.sTaxTotalAmount=getValue(oElemList.item(a),Array("TaxAmount")) '[BT-110] [BT-111]
						oSubElemList=oElemList.item(a).getElementsByTagName("TaxSubtotal")
						For e = 0 To oSubElemList.getLength() - 1
							ReDim Preserve TaxSubtotale(e)
							With TaxSubtotale(e)
								.sTaxableAmount=getValue(oSubElemList.item(e),Array("TaxableAmount")) '[BT-116]
								.sTaxAmount=getValue(oSubElemList.item(e),Array("TaxAmount")) '[BT-117]
								.sTaxCategoryID=getValue(oSubElemList.item(e),Array("TaxCategory","ID")) '[BT-118]
								.sTaxPercent=getValue(oSubElemList.item(e),Array("TaxCategory","Percent")) '[BT-119]
								.sTaxExemptionReason=getValue(oSubElemList.item(e),Array("TaxCategory","TaxExemptionReason")) '[BT-120]
							End With
						Next
					Case "LegalMonetaryTotal"
						.sLineExtensionAmount=getValue(oElemList.item(a),Array("LineExtensionAmount")) '[BT-106]
						.sTaxExclusiveAmount=getValue(oElemList.item(a),Array("TaxExclusiveAmount")) '[BT-109]
						.sTaxInclusiveAmount=getValue(oElemList.item(a),Array("TaxInclusiveAmount")) '[BT-112]
						.sAllowanceTotalAmount=getValue(oElemList.item(a),Array("AllowanceTotalAmount")) '[BT-107]
						.sChargeTotalAmount=getValue(oElemList.item(a),Array("ChargeTotalAmount")) '[BT-108]
						.sPrepaidAmount=getValue(oElemList.item(a),Array("PrepaidAmount")) '[BT-113]
						.sPayableRoundingAmount=getValue(oElemList.item(a),Array("PayableRoundingAmount")) '[BT-114]
						.sPayableAmount=getValue(oElemList.item(a),Array("PayableAmount")) '[BT-115]
					Case "InvoiceLine"
						If IsArray(InvoiceLines) Then 
							InvoiceLines=getInvoiceLines(oElemList.item(a),InvoiceLines)
						Else 
							InvoiceLines=getInvoiceLines(oElemList.item(a),InvoiceLinesFirst)
						End If
				End Select
		Next
	End With
	readXRechnung=Array(Invoice,InvoiceNotes,BillingReferences,AllowanceCharges,TaxSubtotale,InvoiceLines)
End Function

Function getInvoiceLines(oEntry As Object, InvoiceLines As structInvoiceLine) As Variant
	Dim a%, b%, c%, i%, oElement As Object, x%
	Dim iNumberSubInvoiceLines As Integer, iLevel As Integer, sParentID As String
	Dim arrInvoiceLineIDs() As String

On Error Goto Catch	

	a=UBound(InvoiceLines)+1
	ReDim Preserve InvoiceLines(a)

	With InvoiceLines(a)
		.sLevel=0 'Level SubInvoiceLines
		.sParentID="" '[BT-X-304] 'SubInvoiceLines
		.sID=getValue(oEntry,Array("ID")) '[BT-126]
		.sNote=getValue(oEntry,Array("Note")) '[BT-127]
		.sQuantity=getValue(oEntry,Array("InvoicedQuantity")) '[BT-129]
		.sUnitCode=getValue(oEntry,Array("InvoicedQuantity"),"unitCode","",True) '[BT-130]
		.sNetAmount=getValue(oEntry,Array("LineExtensionAmount")) '[BT-131]
		.sPeriodStartDate=getValue(oEntry,Array("InvoicePeriod","StartDate")) '[BT-134]
		.sPeriodEndDate=getValue(oEntry,Array("InvoicePeriod","EndDate")) '[BT-135]
		.sAllowanceChargeIndicator=getValue(oEntry,Array("AllowanceCharge","ChargeIndicator")) '[Use “true” when informing about Charges and “false” when informing about Allowances.]
		.sAllowanceChargeAmount=getValue(oEntry,Array("AllowanceCharge","Amount")) '[BT-136] [BT-141]
		.sAllowanceChargeBaseAmount=getValue(oEntry,Array("AllowanceCharge","BaseAmount")) '[BT-137] [BT-142]
		.sAllowanceChargePercent=getValue(oEntry,Array("AllowanceCharge","MultiplierFactorNumeric")) '[BT-138] [BT-143]
		.sAllowanceChargeReason=getValue(oEntry,Array("AllowanceCharge","AllowanceChargeReason")) '[BT-139] [BT-144]
		.sAllowanceChargeReasonCode=getValue(oEntry,Array("AllowanceCharge","AllowanceChargeReasonCode")) '[BT-140] [BT-145]
		.sItemNetPrice=getValue(oEntry,Array("Price","PriceAmount")) '[BT-146] 
		.sTaxCategoryID=getValue(oEntry,Array("Item","ClassifiedTaxCategory","ID")) '[BT-151]
		.sTaxPercent=getValue(oEntry,Array("Item","ClassifiedTaxCategory","Percent")) '[BT-152]
		.sItemName=getValue(oEntry,Array("Item","Name")) '[BT-153]
		.sItemDescription=getValue(oEntry,Array("Item","Description")) '[BT-154]
		.sSellerAssignedID=getValue(oEntry,Array("Item","SellersItemIdentification","ID")) '[BT-155]
		.sBuyerAssignedID=getValue(oEntry,Array("Item","BuyersItemIdentification","ID")) '[BT-156]
		sParentID=.sID
	End With 
	
	iNumberSubInvoiceLines=oEntry.getElementsByTagName("SubInvoiceLine").getLength
	
	If iNumberSubInvoiceLines > 0 Then
		ReDim arrInvoiceLineIDs(iNumberSubInvoiceLines)
		ReDim Preserve InvoiceLines(UBound(InvoiceLines)+iNumberSubInvoiceLines)
		
		oElement=oEntry

		For i = (a+1) To iNumberSubInvoiceLines + a - 1
			Do While True
				For b = 0 To oElement.getChildNodes.getLength - 1
					If oElement.getChildNodes.item(b).NodeName = "SubInvoiceLine" Then
						For c = 0 To oElement.getChildNodes.item(b).getChildNodes.getLength - 1
							If oElement.getChildNodes.item(b).getChildNodes.item(c).NodeName = "ID" Then
								If Not bFieldInArray(arrInvoiceLineIDs,oElement.getChildNodes.item(b).getChildNodes.item(c).FirstChild.NodeValue) Then
									iLevel=iLevel+1
									sParentID=getValue(oElement,Array("ID"))
									oElement=oElement.getChildNodes.item(b)
									Exit Do
								End If
							End If 
						Next
					End If
				Next
				iLevel=iLevel-1
				oElement=oElement.getParentNode
				sParentID=getValue(oElement,Array("ID"))
			Loop
			With InvoiceLines(i)
				.sLevel=iLevel 'Level SubInvoiceLines
				.sParentID=sParentID '[BT-X-304] 'SubInvoiceLines
				.sID=getValue(oElement,Array("ID")) '[BT-126]
				.sNote=getValue(oElement,Array("Note")) '[BT-127]
				.sQuantity=getValue(oElement,Array("InvoicedQuantity")) '[BT-129]
				.sUnitCode=getValue(oElement,Array("InvoicedQuantity"),"unitCode","",True) '[BT-130]
				.sNetAmount=getValue(oElement,Array("LineExtensionAmount")) '[BT-131]
				.sPeriodStartDate=getValue(oElement,Array("InvoicePeriod","StartDate")) '[BT-134]
				.sPeriodEndDate=getValue(oElement,Array("InvoicePeriod","EndDate")) '[BT-135]
				.sAllowanceChargeIndicator=getValue(oElement,Array("AllowanceCharge","ChargeIndicator")) '[Use “true” when informing about Charges and “false” when informing about Allowances.]
				.sAllowanceChargeAmount=getValue(oElement,Array("AllowanceCharge","Amount")) '[BT-136] [BT-141]
				.sAllowanceChargeBaseAmount=getValue(oElement,Array("AllowanceCharge","BaseAmount")) '[BT-137] [BT-142]
				.sAllowanceChargePercent=getValue(oElement,Array("AllowanceCharge","MultiplierFactorNumeric")) '[BT-138] [BT-143]
				.sAllowanceChargeReason=getValue(oElement,Array("AllowanceCharge","AllowanceChargeReason")) '[BT-139] [BT-144]
				.sAllowanceChargeReasonCode=getValue(oElement,Array("AllowanceCharge","AllowanceChargeReasonCode")) '[BT-140] [BT-145]
				.sItemNetPrice=getValue(oElement,Array("Price","PriceAmount")) '[BT-146] 
				.sTaxCategoryID=getValue(oElement,Array("Item","ClassifiedTaxCategory","ID")) '[BT-151]
				.sTaxPercent=getValue(oElement,Array("Item","ClassifiedTaxCategory","Percent")) '[BT-152]
				.sItemName=getValue(oElement,Array("Item","Name")) '[BT-153]
				.sItemDescription=getValue(oElement,Array("Item","Description")) '[BT-154]
				.sSellerAssignedID=getValue(oElement,Array("Item","SellersItemIdentification","ID")) '[BT-155]
				.sBuyerAssignedID=getValue(oElement,Array("Item","BuyersItemIdentification","ID")) '[BT-156]
				arrInvoiceLineIDs(i-a-1)=.sID
			End With 		
		Next
	End If 
	getInvoiceLines=InvoiceLines
	Exit Function
	
Catch:
	MsgBox "Fehler beim Import der XML-Daten " & Chr$(10) & Chr$(10) & Error$ & " " & Chr$(10) & " ", 16, "XML-Import"	
End Function

Function readZUGFeRD(oDOM As Object) As Variant
	Dim oElem As Object, oElemList As Object, oSubElemList As Object, oSubSubElemList As Object
	Dim a% , b% , c% , d% , e% , f% , g% , h% , i% , j% , k% , l%, x%
	Dim Invoice As New structInvoice, InvoiceNotes() As New structInvoiceNote, BillingReferences() As New structBillingReference
	Dim AllowanceCharges() As New structAllowanceCharge, TaxSubtotale() As New structTaxSubtotal, InvoiceLines() As New structInvoiceLine
		
	oElemList=oDOM.getElementsByTagName("CrossIndustryInvoice").item(0).getChildNodes()
	With Invoice
		For a = 0 To oElemList.getLength() - 1
			Select Case oElemList.item(a).NodeName
				Case "ExchangedDocument"
					.sInvoiceID=getValue(oElemList.item(a),Array("ID")) '[BT-1]
					.sIssueDate=getValue(oElemList.item(a),Array("IssueDateTime","DateTimeString")) '[BT-2]
					.sInvoiceTypCode=getValue(oElemList.item(a),Array("TypeCode")) '[BT-3]
					oSubElemList=oElemList.item(a).getElementsByTagName("IncludedNote")
					For i = 0 To oSubElemList.getLength() - 1
						ReDim Preserve InvoiceNotes(i)
						With InvoiceNotes(i)
							.sSubjectCode=getValue(oSubElemList.item(i),Array("SubjectCode")) '[BT-21]
							.sNote=getValue(oSubElemList.item(i),Array("Content")) '[BT-22]
						End With 
					Next
				Case "SupplyChainTradeTransaction"
					oSubElemList=oElemList.item(a).getChildNodes()
					For b = 0 To oSubElemList.getLength() - 1
						Select Case oSubElemList.item(b).NodeName
							Case "IncludedSupplyChainTradeLineItem"
								ReDim Preserve InvoiceLines(j)
								With InvoiceLines(j)
									.sParentID=getValue(oSubElemList.item(b),Array("AssociatedDocumentLineDocument","ParentLineID")) '[BT-X-304]
									.sID=getValue(oSubElemList.item(b),Array("AssociatedDocumentLineDocument","LineID")) '[BT-126]
									.sNote=getValue(oSubElemList.item(b),Array("AssociatedDocumentLineDocument","IncludedNote")) '[BT-127]
									.sQuantity=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeDelivery","BilledQuantity")) '[BT-129]
									.sUnitCode=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeDelivery","BilledQuantity"),"unitCode","",True) '[BT-130]
									.sNetAmount=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeSettlementLineMonetarySummation","LineTotalAmount")) '[BT-131]
									.sPeriodStartDate=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","BillingSpecifiedPeriod","StartDateTime","DateTimeString")) '[BT-134]
									.sPeriodEndDate=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","BillingSpecifiedPeriod","EndDateTime","DateTimeString")) '[BT-135]
									.sAllowanceChargeIndicator=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeAllowanceCharge","ChargeIndicator","Indicator")) '[Use “true” when informing about Charges and “false” when informing about Allowances.]
									.sAllowanceChargeAmount=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeAllowanceCharge","ActualAmount")) '[BT-136] [BT-141]
									.sAllowanceChargeBaseAmount=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeAllowanceCharge","BasisAmount")) '[BT-137] [BT-142]
									.sAllowanceChargePercent=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeAllowanceCharge","CalculationPercent")) '[BT-138] [BT-143]
									.sAllowanceChargeReason=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeAllowanceCharge","Reason")) '[BT-139] [BT-144]
									.sAllowanceChargeReasonCode=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","SpecifiedTradeAllowanceCharge","ReasonCode")) '[BT-140] [BT-145]
									.sItemNetPrice=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeAgreement","NetPriceProductTradePrice","ChargeAmount")) '[BT-146]
									.sTaxCategoryID=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","ApplicableTradeTax","CategoryCode")) '[BT-151]
									.sTaxPercent=getValue(oSubElemList.item(b),Array("SpecifiedLineTradeSettlement","ApplicableTradeTax","RateApplicablePercent")) '[BT-152]
									.sItemName=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","Name")) '[BT-153]
									.sItemDescription=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","Description")) '[BT-154]
									.sSellerAssignedID=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","SellerAssignedID")) '[BT-155]
									.sBuyerAssignedID=getValue(oSubElemList.item(b),Array("SpecifiedTradeProduct","BuyerAssignedID")) '[BT-156]
									j=j+1
								End With								
							Case "ApplicableHeaderTradeAgreement"
								.sBuyerReference=getValue(oSubElemList.item(b),Array("BuyerReference")) '[BT-10]
								.sSellerName=getValue(oSubElemList.item(b),Array("SellerTradeParty","Name")) '[BT-27]
								.sSellerDescription=getValue(oSubElemList.item(b),Array("SellerTradeParty","Description")) '[BT-33]
								.sSellerPLZ=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","PostcodeCode")) '[BT-38]
								.sSellerStreetName=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","LineOne")) '[BT-35]
								.sSellerCityName=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","CityName")) '[BT-37]
								.sSellerCountryCode=getValue(oSubElemList.item(b),Array("SellerTradeParty","PostalTradeAddress","CountryID")) '[BT-40]
								.sSellerEMail=getValue(oSubElemList.item(b),Array("SellerTradeParty","URIUniversalCommunication","URIID"),"schemeID","EM") '[BT-34]
								.sSellerTaxCompanyID=getValue(oSubElemList.item(b),Array("SellerTradeParty","SpecifiedTaxRegistration","ID")) '[BT-31] [BT-32]
								.sSellerContactName=getValue(oSubElemList.item(b),Array("SellerTradeParty","DefinedTradeContact","PersonName")) '[BT-41]
								.sSellerContactTelephone=getValue(oSubElemList.item(b),Array("SellerTradeParty","DefinedTradeContact","TelephoneUniversalCommunication","CompleteNumber")) '[BT-42]
								.sSellerContactElectronicMail=getValue(oSubElemList.item(b),Array("SellerTradeParty","DefinedTradeContact","EmailURIUniversalCommunication","URIID")) '[BT-43]
								.sBuyerName=getValue(oSubElemList.item(b),Array("BuyerTradeParty","Name")) '[BT-44]
								.sBuyerIdentifier=getValue(oSubElemList.item(b),Array("BuyerTradeParty","ID")) '[BT-46]
								.sBuyerPLZ=getValue(oSubElemList.item(b),Array("BuyerTradeParty","PostalTradeAddress","PostcodeCode")) '[BT-53]
								.sBuyerStreetName=getValue(oSubElemList.item(b),Array("BuyerTradeParty","PostalTradeAddress","LineOne")) '[BT-50]
								.sBuyerCityName=getValue(oSubElemList.item(b),Array("BuyerTradeParty","PostalTradeAddress","CityName")) '[BT-52]
								.sBuyerCountryCode=getValue(oSubElemList.item(b),Array("BuyerTradeParty","PostalTradeAddress","CountryID")) '[BT-55]
								.sBuyerEMail=getValue(oSubElemList.item(b),Array("BuyerTradeParty","URIUniversalCommunication","URIID"),"schemeID","EM") '[BT-49]
								.sBuyerTaxCompanyID=getValue(oSubElemList.item(b),Array("BuyerTradeParty","SpecifiedTaxRegistration","ID")) '[BT-48]
								.sBuyerContactName=getValue(oSubElemList.item(b),Array("BuyerTradeParty","DefinedTradeContact","PersonName")) '[BT-56]
								.sBuyerContactTelephone=getValue(oSubElemList.item(b),Array("BuyerTradeParty","DefinedTradeContact","TelephoneUniversalCommunication","CompleteNumber")) '[BT-57]
								.sBuyerContactElectronicMail=getValue(oSubElemList.item(b),Array("BuyerTradeParty","DefinedTradeContact","EmailURIUniversalCommunication","URIID")) '[BT-58]
							Case "ApplicableHeaderTradeDelivery"
								.sActualDeliveryDate=getValue(oSubElemList.item(b),Array("ActualDeliverySupplyChainEvent","OccurrenceDateTime","DateTimeString")) '[BT-72]
							Case "ApplicableHeaderTradeSettlement"
								.sDocumentCurrencyCode=getValue(oSubElemList.item(b),Array("InvoiceCurrencyCode")) '[BT-5]
								.sPaymentMeansCode=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","TypeCode")) '[BT-81]
								.sPayeeFinancialAccountID=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","PayeePartyCreditorFinancialAccount","IBANID")) '[BT-84]
								.sPayeeFinancialAccountName=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","PayeePartyCreditorFinancialAccount","AccountName")) '[BT-85]
								.sPayeeFinancialInstitutionBranchID=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementPaymentMeans","PayeeSpecifiedCreditorFinancialInstitution","BICID")) '[BT-86]
								oSubSubElemList=oSubElemList.item(b).getElementsByTagName("ApplicableTradeTax")
								For c = 0 To oSubSubElemList.getLength() - 1
									ReDim Preserve TaxSubtotale(c)
									With TaxSubtotale(c)
										.sTaxableAmount=getValue(oSubSubElemList.item(c),Array("BasisAmount")) '[BT-116]
										.sTaxAmount=getValue(oSubSubElemList.item(c),Array("CalculatedAmount")) '[BT-117]
										.sTaxCategoryID=getValue(oSubSubElemList.item(c),Array("CategoryCode")) '[BT-118]
										.sTaxPercent=getValue(oSubSubElemList.item(c),Array("RateApplicablePercent")) '[BT-119]
										.sTaxExemptionReason=getValue(oSubSubElemList.item(c),Array("ExemptionReason")) '[BT-120]
									End With								
								Next
								oSubSubElemList=oSubElemList.item(b).getElementsByTagName("SpecifiedTradeAllowanceCharge")
								For d = 0 To oSubSubElemList.getLength() - 1
			 						ReDim Preserve AllowanceCharges(d)
									With AllowanceCharges(d)
										.sIndicator=getValue(oSubSubElemList.item(d),Array("ChargeIndicator","Indicator")) '[Use “true” when informing about Charges and “false” when informing about Allowances.]
										.sAmount=getValue(oSubSubElemList.item(d),Array("ActualAmount")) '[BT-92] [BT-99]
										.sBaseAmount=getValue(oSubSubElemList.item(d),Array("BasisAmount")) '[BT-93] [BT-100]
										.sPercent=getValue(oSubSubElemList.item(d),Array("CalculationPercent")) '[BT-94] [BT-101]
										.sTaxCategoryID=getValue(oSubSubElemList.item(d),Array("CategoryTradeTax","CategoryCode")) '[BT-95] [BT-102]
										.sTaxPercent=getValue(oSubSubElemList.item(d),Array("CategoryTradeTax","RateApplicablePercent")) '[BT-96] [BT-103]
										.sReason=getValue(oSubSubElemList.item(d),Array("Reason")) '[BT-97] [BT-104]
										.sReasonCode=getValue(oSubSubElemList.item(d),Array("ReasonCode")) '[BT-98] [BT-105]
									End With
								Next
								.sPaymentTerms=getValue(oSubElemList.item(b),Array("SpecifiedTradePaymentTerms","Description")) '[BT-20]
								.sDueDate=getValue(oSubElemList.item(b),Array("SpecifiedTradePaymentTerms","DueDateDateTime","DateTimeString")) '[BT-9]
								.sLineExtensionAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","LineTotalAmount")) '[BT-106]
								.sChargeTotalAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","ChargeTotalAmount")) '[BT-108]
								.sAllowanceTotalAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","AllowanceTotalAmount")) '[BT-107]
								.sTaxExclusiveAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","TaxBasisTotalAmount")) '[BT-109]
								.sTaxTotalAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","TaxTotalAmount")) '[BT-110] [BT-111]
								.sTaxInclusiveAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","GrandTotalAmount")) '[BT-112]
								.sPrepaidAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","TotalPrepaidAmount")) '[BT-113]
								.sPayableAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","DuePayableAmount")) '[BT-115]
								.sPayableRoundingAmount=getValue(oSubElemList.item(b),Array("SpecifiedTradeSettlementHeaderMonetarySummation","RoundingAmount")) '[BT-114]
								oSubSubElemList=oSubElemList.item(b).getElementsByTagName("InvoiceReferencedDocument")
								For e = 0 To oSubSubElemList.getLength() - 1
									ReDim Preserve BillingReferences(e)
									With BillingReferences(e)
										.sID=getValue(oSubSubElemList.item(e),Array("IssuerAssignedID")) '[BT-25]
										.sIssueDate=getValue(oSubSubElemList.item(e),Array("FormattedIssueDateTime","DateTimeString")) '[BT-26]
									End With
								Next
						End Select
					Next
			End Select
		Next
	End With
	readZUGFeRD=Array(Invoice,InvoiceNotes,BillingReferences,AllowanceCharges,TaxSubtotale,InvoiceLines)
End Function

Function bFieldInArray(arrArray(), sEntry as String) As Boolean
	Dim i%
	For i = LBound(arrArray()) to UBound(arrArray())
		If arrArray(i) = sEntry Then
			bFieldInArray = True
			Exit Function
		End if
	Next
	bFieldInArray = False
End Function

REM Function getValue #####################################################################################################################################
REM Parameter:
REM oEntry Element, welches untersucht werden soll
REM arrNodePath() ein Array mit Elementen die rekursiv durchlaufen werden sollen, aus dem letzten Eintrag im Array wird der Wert gelesen, es muss die Reihenfolge beachtet werden,
REM sAttributName Der Name das Atrributes, welches untersucht oder ausgegeben werden soll
REM sAttribut der Wert des letzten Elements wird nur ausgelesen, wenn dessen Attribut dem Parameter entspricht 
REM bGetAttribut Wenn True wird Atrribut.NodeValue ausgegeben, Wenn False wird nur verglichen ob das Attribunt mit dem Parameter übereinstimmt und dann NodeValue vom Element ausgegeben
Function getValue(oEntry As Object, arrNodePath(), Optional sAttributName As String, Optional sAttribut As String, Optional bGetAttribut As Boolean) As String
	Dim a%, oElement As Object
	If IsMissing(bGetAttribut) Then bGetAttribut=False
	oElement=oEntry
	getValue=""
	For a = 0 To UBound(arrNodePath())
		If oElement.getElementsByTagName(arrNodePath(a)).getLength > 0 And a < UBound(arrNodePath()) Then
			If oElement.getElementsByTagName(arrNodePath(a)).item(0).NodeName = arrNodePath(a) Then
				oElement=oElement.getElementsByTagName(arrNodePath(a)).item(0)
			End If
		ElseIf oElement.getElementsByTagName(arrNodePath(a)).getLength > 0 And a = UBound(arrNodePath()) Then
			If oElement.getElementsByTagName(arrNodePath(a)).item(0).NodeName = arrNodePath(a) Then
				If Not IsMissing(sAttributName) Then
					If oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.getLength > 0 Then
						If oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.item(0).NodeName = sAttributName Then
							If bGetAttribut Then
								getValue=oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.item(0).NodeValue
							Else
								If oElement.getElementsByTagName(arrNodePath(a)).item(0).Attributes.item(0).NodeValue = sAttribut Then
									If oElement.getElementsByTagName(arrNodePath(a)).item(0).hasChildNodes Then _
										getValue=oElement.getElementsByTagName(arrNodePath(a)).item(0).FirstChild.NodeValue
								End If
							End If
						End If
					End If
					Exit Function
				Else
					If oElement.getElementsByTagName(arrNodePath(a)).item(0).hasChildNodes Then _
						getValue=oElement.getElementsByTagName(arrNodePath(a)).item(0).FirstChild.NodeValue
					Exit Function
				End If
			End If
		Else
			Exit Function
		End If
	Next
End Function

Sub CreateSheet()
	Dim oCalcDoc As Object, oSheet As Object, oPathSettings As Object
	Dim iRow As Integer
	Dim InvoiceData As Variant
	
	InvoiceData=readInvoice

	oPathSettings = CreateUnoService("com.sun.star.util.PathSettings")
	oCalcDoc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, Array())
	oSheet = oCalcDoc.Sheets(0)  
	Dim a% , b% , c% , d% , e% , f% , g% , h% , i% , j% , k% , l%, x%

 	With InvoiceData(INVOICE)
		iRow=1
		fillSheet(oSheet,"A" & iRow,"Invoice ID [BT-1]",True)
		fillSheet(oSheet,"B" & iRow,"Issue Date [BT-2]",True)
		fillSheet(oSheet,"C" & iRow,"Due Date [BT-9]",True)
		fillSheet(oSheet,"D" & iRow,"Actual Delivery Date [BT-72]",True)
		fillSheet(oSheet,"E" & iRow,"Invoice Type Code [BT-3]",True)
		fillSheet(oSheet,"F" & iRow,"DocumentCurrencyCode [BT-5]",True)
		fillSheet(oSheet,"G" & iRow,"BuyerReference [BT-10]",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sInvoiceID,False)
		fillSheet(oSheet,"B" & iRow,.sIssueDate,False)
		fillSheet(oSheet,"C" & iRow,.sDueDate,False)
		fillSheet(oSheet,"D" & iRow,.sActualDeliveryDate,False)
		fillSheet(oSheet,"E" & iRow,.sInvoiceTypCode,False)
		fillSheet(oSheet,"F" & iRow,.sDocumentCurrencyCode,False)
		fillSheet(oSheet,"G" & iRow,.sBuyerReference,False)
		iRow=iRow+1
		
		If IsArray(InvoiceData(INVOICE_NOTES)) Then
			fillSheet(oSheet,"A" & iRow & ":D" & iRow,"Invoice Notes [BT-22]",True)
			fillSheet(oSheet,"E" & iRow,"Subject Codes [BT-21]",True)
			iRow=iRow+1
			For a = 0 To UBound(InvoiceData(INVOICE_NOTES))
				With InvoiceData(INVOICE_NOTES)(a)
					fillSheet(oSheet,"A" & iRow+a & ":D" & iRow+a,.sNote,False)				
					fillSheet(oSheet,"E" & iRow+a,.sSubjectCode,False)				
				End With
			Next
			iRow=iRow+a+1
		End If
	
		If IsArray(InvoiceData(BILLING_REFERENCES)) Then
			fillSheet(oSheet,"A" & iRow,"Billing Reference ID [BT-25]",True)
			fillSheet(oSheet,"B" & iRow,"IssueDate [BT-26]",True)
			iRow=iRow+1
			For b = 0 To UBound(InvoiceData(BILLING_REFERENCES))
				With InvoiceData(BILLING_REFERENCES)(b)
					fillSheet(oSheet,"A" & iRow+b,.sID,False)				
					fillSheet(oSheet,"B" & iRow+b,.sIssueDate,False)		
				End With		
			Next
			iRow=iRow+b+1
		End If

		fillSheet(oSheet,"A" & iRow,"Seller Party -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"Seller Name [BT-28]",True)
		fillSheet(oSheet,"B" & iRow,"Seller StreetName [BT-35]",True)
		fillSheet(oSheet,"C" & iRow,"Seller Country Code [BT-40]",True)
		fillSheet(oSheet,"D" & iRow,"Seller PLZ [BT-38]",True)
		fillSheet(oSheet,"E" & iRow,"Seller City Name [BT-37]",True)
		fillSheet(oSheet,"F" & iRow,"Seller EMail [BT-34]",True)
		fillSheet(oSheet,"G" & iRow,"Seller TaxCompanyID [BT-31] [BT-32]",True)
		fillSheet(oSheet,"H" & iRow,"Seller Description [BT-33]",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sSellerName,False)
		fillSheet(oSheet,"B" & iRow,.sSellerStreetName,False)
		fillSheet(oSheet,"C" & iRow,.sSellerCountryCode,False)
		fillSheet(oSheet,"D" & iRow,.sSellerPLZ,False)
		fillSheet(oSheet,"E" & iRow,.sSellerCityName,False)
		fillSheet(oSheet,"F" & iRow,.sSellerEMail,False)
		fillSheet(oSheet,"G" & iRow,.sSellerTaxCompanyID,False)
		fillSheet(oSheet,"H" & iRow,.sSellerDescription,False)
		iRow=iRow+2
		
		fillSheet(oSheet,"A" & iRow,"Buyer Party -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"Buyer Name [BT-44]",True)
		fillSheet(oSheet,"B" & iRow,"Buyer StreetName [BT-50]",True)
		fillSheet(oSheet,"C" & iRow,"Buyer Country Code [BT-55]",True)
		fillSheet(oSheet,"D" & iRow,"Buyer PLZ [BT-53]",True)
		fillSheet(oSheet,"E" & iRow,"Buyer City Name [BT-52]",True)
		fillSheet(oSheet,"F" & iRow,"Buyer EMail [BT-49]",True)
		fillSheet(oSheet,"G" & iRow,"Buyer TaxCompanyID [BT-48]",True)
		fillSheet(oSheet,"H" & iRow,"Buyer Identifier [BT-46]",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sBuyerName,False)
		fillSheet(oSheet,"B" & iRow,.sBuyerStreetName,False)
		fillSheet(oSheet,"C" & iRow,.sBuyerCountryCode,False)
		fillSheet(oSheet,"D" & iRow,.sBuyerPLZ,False)
		fillSheet(oSheet,"E" & iRow,.sBuyerCityName,False)
		fillSheet(oSheet,"F" & iRow,.sBuyerEMail,False)
		fillSheet(oSheet,"G" & iRow,.sBuyerTaxCompanyID,False)
		fillSheet(oSheet,"H" & iRow,.sBuyerIdentifier,False)
		iRow=iRow+2

		fillSheet(oSheet,"A" & iRow,"Seller Contact -->",False)
		fillSheet(oSheet,"E" & iRow,"Buyer Contact -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"Seller Contact Name [BT-41]",True)
		fillSheet(oSheet,"B" & iRow,"Seller Telephone [BT-42]",True)
		fillSheet(oSheet,"C" & iRow,"Seller ElectronicMail [BT-43]",True)
		fillSheet(oSheet,"E" & iRow,"Buyer Contact Name [BT-56]",True)
		fillSheet(oSheet,"F" & iRow,"Buyer Telephone [BT-57]",True)
		fillSheet(oSheet,"G" & iRow,"Buyer ElectronicMail [BT-58]",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sSellerContactName,False)
		fillSheet(oSheet,"B" & iRow,.sSellerContactTelephone,False)
		fillSheet(oSheet,"C" & iRow,.sSellerContactElectronicMail,False)
		fillSheet(oSheet,"E" & iRow,.sBuyerContactName,False)
		fillSheet(oSheet,"F" & iRow,.sBuyerContactTelephone,False)
		fillSheet(oSheet,"G" & iRow,.sBuyerContactElectronicMail,False)
		iRow=iRow+2
	
		fillSheet(oSheet,"A" & iRow,"PaymentMeans -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"AccountName [BT-85]",True)
		fillSheet(oSheet,"B" & iRow,"IBAN [BT-84]",True)
		fillSheet(oSheet,"C" & iRow,"BIC [BT-86]",True)
		fillSheet(oSheet,"D" & iRow,"PaymentMeansCode [BT-81]",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sPayeeFinancialAccountName,False)
		fillSheet(oSheet,"B" & iRow,.sPayeeFinancialAccountID,False)
		fillSheet(oSheet,"C" & iRow,.sPayeeFinancialInstitutionBranchID,False)
		fillSheet(oSheet,"D" & iRow,.sPaymentMeansCode,False)
		iRow=iRow+2
	
		fillSheet(oSheet,"A" & iRow & ":D" & iRow,"PaymentTerms [BT-20]",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow & ":D" & iRow,.sPaymentTerms,False)
		iRow=iRow+2

		If IsArray(InvoiceData(ALLOWANCE_CHARGES)) Then
			fillSheet(oSheet,"A" & iRow,"AllowanceCharge -->",False)
			iRow=iRow+1
			fillSheet(oSheet,"A" & iRow,"Allowance Charge Indicator",True)
			fillSheet(oSheet,"B" & iRow,"sPercent [BT-94] [BT-101]",True)
			fillSheet(oSheet,"C" & iRow,"Amount [BT-92] [BT-99]",True)
			fillSheet(oSheet,"D" & iRow,"BaseAmount [BT-93] [BT-100]",True)
			fillSheet(oSheet,"E" & iRow,"TaxCategoryID [BT-95] [BT-102]",True)
			fillSheet(oSheet,"F" & iRow,"TaxPercent [BT-96] [BT-103]",True)
			fillSheet(oSheet,"G" & iRow,"ReasonCode [BT-98] [BT-105]",True)
			fillSheet(oSheet,"H" & iRow,"Reason [BT-97] [BT-104]",True)
			iRow=iRow+1
			For c = 0 To UBound(InvoiceData(ALLOWANCE_CHARGES))
				With InvoiceData(ALLOWANCE_CHARGES)(c)
					fillSheet(oSheet,"A" & iRow+c,.sIndicator,False)				
					fillSheet(oSheet,"B" & iRow+c,.sPercent,False)				
					fillSheet(oSheet,"C" & iRow+c,.sAmount,False)				
					fillSheet(oSheet,"D" & iRow+c,.sBaseAmount,False)				
					fillSheet(oSheet,"E" & iRow+c,.sTaxCategoryID,False)				
					fillSheet(oSheet,"F" & iRow+c,.sTaxPercent,False)				
					fillSheet(oSheet,"G" & iRow+c,.sReasonCode,False)				
					fillSheet(oSheet,"H" & iRow+c,.sReason,False)			
				End With	
			Next
			iRow=iRow+c+1
		End If

		fillSheet(oSheet,"A" & iRow,"TaxTotalAmount:",True)
		fillSheet(oSheet,"B" & iRow,.sTaxTotalAmount,False)
		iRow=iRow+2

		If IsArray(InvoiceData(TAX_SUBTOTALE)) Then
			fillSheet(oSheet,"A" & iRow,"TaxSubtotal -->",False)
			iRow=iRow+1
			fillSheet(oSheet,"A" & iRow,"Taxable Amount [BT-116]",True)
			fillSheet(oSheet,"B" & iRow,"Tax Amount [BT-117]",True)
			fillSheet(oSheet,"C" & iRow,"Tax CategoryID [BT-118]",True)
			fillSheet(oSheet,"D" & iRow,"Tax Percent [BT-119]",True)
			fillSheet(oSheet,"E" & iRow,"",True)
			fillSheet(oSheet,"F" & iRow,"",True)
			fillSheet(oSheet,"G" & iRow,"",True)
			fillSheet(oSheet,"H" & iRow,"Tax Exemption Reason [BT-120]",True)
			iRow=iRow+1
			For d = 0 To UBound(InvoiceData(TAX_SUBTOTALE))
				With InvoiceData(TAX_SUBTOTALE)(d)
					fillSheet(oSheet,"A" & iRow+d,.sTaxableAmount,False)
					fillSheet(oSheet,"B" & iRow+d,.sTaxAmount,False)	
					fillSheet(oSheet,"C" & iRow+d,.sTaxCategoryID,False)
					fillSheet(oSheet,"D" & iRow+d,.sTaxPercent,False)
					fillSheet(oSheet,"H" & iRow+d,.sTaxExemptionReason,False)
				End With
			Next
			iRow=iRow+d+1
		End If

		fillSheet(oSheet,"A" & iRow,"LegalMonetaryTotal -->",False)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,"Line Extension Amount [BT-106]",True)
		fillSheet(oSheet,"B" & iRow,"Tax Exclusive Amount [BT-109]",True)
		fillSheet(oSheet,"C" & iRow,"Tax Inclusive Amount [BT-112]",True)
		fillSheet(oSheet,"D" & iRow,"Allowance Total Amount [BT-107]",True)
		fillSheet(oSheet,"E" & iRow,"Charge Total Amount [BT-108]",True)
		fillSheet(oSheet,"F" & iRow,"Prepaid Amount [BT-113]",True)
		fillSheet(oSheet,"G" & iRow,"Payable Rounding Amount [BT-114]",True)
		fillSheet(oSheet,"H" & iRow,"Payable Amount [BT-115]",True)
		iRow=iRow+1
		fillSheet(oSheet,"A" & iRow,.sLineExtensionAmount,False)
		fillSheet(oSheet,"B" & iRow,.sTaxExclusiveAmount,False)
		fillSheet(oSheet,"C" & iRow,.sTaxInclusiveAmount,False)
		fillSheet(oSheet,"D" & iRow,.sAllowanceTotalAmount,False)
		fillSheet(oSheet,"E" & iRow,.sChargeTotalAmount,False)
		fillSheet(oSheet,"F" & iRow,.sPrepaidAmount,False)
		fillSheet(oSheet,"G" & iRow,.sPayableRoundingAmount,False)
		fillSheet(oSheet,"H" & iRow,.sPayableAmount,False)
		iRow=iRow+2

		If IsArray(InvoiceData(INVOICE_LINES)) Then
			fillSheet(oSheet,"A" & iRow,"InvoiceLine -->",False)
			iRow=iRow+1
			fillSheet(oSheet,"A" & iRow,"Level",True)
			fillSheet(oSheet,"B" & iRow,"Parent ID [BT-X-304]",True)
			fillSheet(oSheet,"C" & iRow,"Invoice Line ID [BT-126]",True)
			fillSheet(oSheet,"D" & iRow,"Invoice Line Note [BT-127]",True)
			fillSheet(oSheet,"E" & iRow,"Quantity [BT-129]",True)
			fillSheet(oSheet,"F" & iRow,"Unit Code [BT-130]",True)
			fillSheet(oSheet,"G" & iRow,"Sellers Assigned [BT-155]",True)
			fillSheet(oSheet,"H" & iRow,"Buyer Assigned [BT-156]",True)
			fillSheet(oSheet,"I" & iRow,"Item Name [BT-153]",True)
			fillSheet(oSheet,"J" & iRow,"Allowance Charge " & Chr$(10) & "Indicator",True)
			fillSheet(oSheet,"K" & iRow,"Allowance Charge " & Chr$(10) & "Amount [BT-136] [BT-141]",True)
			fillSheet(oSheet,"L" & iRow,"Allowance Charge " & Chr$(10) & "Base Amount [BT-137] [BT-142]",True)
			fillSheet(oSheet,"M" & iRow,"Allowance Charge " & Chr$(10) & "Percent [BT-138] [BT-143]",True)
			fillSheet(oSheet,"N" & iRow,"Allowance Charge " & Chr$(10) & "Reason [BT-139] [BT-144]",True)
			fillSheet(oSheet,"O" & iRow,"Allowance Charge " & Chr$(10) & "Reason Code [BT-140] [BT-145]",True)
			fillSheet(oSheet,"P" & iRow,"Tax Category ID [BT-151]",True)
			fillSheet(oSheet,"Q" & iRow,"Tax Percent [BT-152]",True)
			fillSheet(oSheet,"R" & iRow,"Netto Amount [BT-131]",True)
			fillSheet(oSheet,"S" & iRow,"Item Netto Price [BT-146]",True)
			fillSheet(oSheet,"T" & iRow,"Description [BT-154]",True)
			iRow=iRow+1
			For e = 0 To UBound(InvoiceData(INVOICE_LINES))
				With InvoiceData(INVOICE_LINES)(e)
					fillSheet(oSheet,"A" & iRow+e,.sLevel,False)
					fillSheet(oSheet,"B" & iRow+e,.sParentID,False)	
					fillSheet(oSheet,"C" & iRow+e,.sID,False)
					fillSheet(oSheet,"D" & iRow+e,.sNote,False)
					fillSheet(oSheet,"E" & iRow+e,.sQuantity,False)
					fillSheet(oSheet,"F" & iRow+e,.sUnitCode,False)
					fillSheet(oSheet,"G" & iRow+e,.sSellerAssignedID,False)
					fillSheet(oSheet,"H" & iRow+e,.sBuyerAssignedID,False)
					fillSheet(oSheet,"I" & iRow+e,.sItemName,False)
					fillSheet(oSheet,"J" & iRow+e,.sAllowanceChargeIndicator,False)
					fillSheet(oSheet,"K" & iRow+e,.sAllowanceChargeAmount,False)
					fillSheet(oSheet,"L" & iRow+e,.sAllowanceChargeBaseAmount,False)
					fillSheet(oSheet,"M" & iRow+e,.sAllowanceChargePercent,False)
					fillSheet(oSheet,"N" & iRow+e,.sAllowanceChargeReason,False)
					fillSheet(oSheet,"O" & iRow+e,.sAllowanceChargeReasonCode,False)
					fillSheet(oSheet,"P" & iRow+e,.sTaxCategoryID,False)
					fillSheet(oSheet,"Q" & iRow+e,.sTaxPercent,False)
					fillSheet(oSheet,"R" & iRow+e,.sNetAmount,False)
					fillSheet(oSheet,"S" & iRow+e,.sItemNetPrice,False)
					fillSheet(oSheet,"T" & iRow+e,.sItemDescription,False)
				End With
			Next
			iRow=iRow+e+1
		End If
 	End With
 	oSheet.getColumns().OptimalWidth = True
 	oSheet.getRows().OptimalHeight = True
End Sub

Sub fillSheet(oSheet, sRange As String, sValue As String, bBottomLine As Boolean)
	Dim oBorder As Object, oCell As Object, oRange As Object
	Dim bLO As Boolean
	
	oBorder = CreateUnoStruct("com.sun.star.table.BorderLine2")
	bLO = True
	
	If IsNull(oBorder) Then
		bLO = False
		oBorder = CreateUnoStruct("com.sun.star.table.BorderLine")
	End If

	oBorder.OuterLineWidth = 40
	If InStr(sRange,":") > 0 Then
		oRange=oSheet.getCellRangeByName(sRange)
		oRange.merge(True)
		oCell=oSheet.getCellRangeByName(Split(sRange,":")(0))
	Else
		oCell=oSheet.getCellRangeByName(sRange)
	End If
	If bBottomLine Then
		If bLO Then
			oBorder.LineStyle = com.sun.star.table.BorderLineStyle.SOLID
			oBorder.LineWidth = 40
			oCell.BottomBorder2 = oBorder
		Else
			oCell.BottomBorder = oBorder
		End If
	End If
	oCell.VertJustify = com.sun.star.table.CellVertJustify.TOP
	oCell.String = sValue
End Sub


Angebots- und Rechnungsverwaltung mit Kunden- und Lieferantenstamm, OP-Buchhaltung, Nachkalkulation und Vielem mehr... für LibreOffice/OpenOffice

https://github.com/heifisch/aladin


An alle, die das LibreOffice-Forum gern nutzen und unterstützen wollen:


Bitte helfen Sie uns mit 7 Euro pro Monat.
Durch Ihren Beitrag tragen Sie dazu bei, unsere laufenden Kosten für die kommenden Monate zu decken.
Unkompliziert per Kreditkarte oder PayPal.
Als ein kleines Dankeschön werden Sie im LO-Forum als SUPPORTER gekennzeichnet.



Antworten