SUB SaveZUGFeRD( )		'oForm AS OBJECT, stXRechnungDatei AS STRING, arSources())
	DIM oConnection AS OBJECT, oSQL_Statement AS OBJECT, oResult AS OBJECT, oUcb AS OBJECT, oOutputStream AS OBJECT, oFile AS OBJECT
	DIM stID AS STRING, stSql AS STRING, stNetto AS STRING, stSteuer AS STRING, stBrutto AS STRING
	DIM stBuyerID AS STRING, stBuyerIcDCode AS STRING
	DIM stRStellFirma AS STRING, stRStellStr AS STRING, stRStellPlz AS STRING, stRStellStadt AS STRING, stRStellEMail AS STRING, stRStellTel AS STRING, stRStellUST_IdNr AS STRING
	DIM stRStellAbwHandelsname AS STRING, stZahlungIBAN AS STRING, stZahlungBIC AS STRING, stZahlungEmpfaenger AS STRING, stZahlungNotiz AS STRING, stRStellHRAEintragID AS STRING
	DIM stRStellHRAEintragForm AS STRING, stRStellKonName AS STRING, stRStellKonEMail AS STRING, stRStellKonTel AS STRING, stKaufID AS STRING, stKaufName AS STRING, stKaufStr AS STRING
	DIM stKaufPlz AS STRING, stKaufStadt AS STRING, stKaufLandCode AS STRING, stKaufEMail AS STRING, stRDatum AS STRING, stRZahlungBisDatum AS STRING, stRKaufRef AS STRING, stRNummer AS STRING
	DIM stInvoiceTypeCode AS STRING, stDocumentCurrencyCode AS STRING, stCountryIdentificationCode AS STRING, stPaymentMeansCode AS STRING
	DIM stFileUrl AS STRING, stString AS STRING, stDataAmountTotal AS STRING, stAllowanceTotalAmount AS STRING, stChargeTotalAmount AS STRING, stKaufCompID AS STRING
	DIM stLDatum AS STRING, stLFirma AS STRING, stLStr AS STRING, stLPlz AS STRING, stLStadt AS STRING, stLLandCode AS STRING, stLAddress AS STRING, stDelivery AS STRING
	DIM stGlaeubID AS STRING, stIBANEmpfaenger AS STRING, stMandatID AS STRING, stSteuerfreiheit AS STRING, stRStellSteuerNr AS STRING
	DIM stTenderID AS STRING, stObjectID AS STRING, stAccounting AS STRING, stSellerID AS STRING, stSellerID2 AS STRING, stSellerICDCode AS STRING
	DIM inTab AS INTEGER, inI AS INTEGER, i AS INTEGER, inAttach AS INTEGER
	DIM doBrutto AS DOUBLE, doDataAmountTotal AS DOUBLE, doAllowanceTotalAmount AS DOUBLE, doChargeTotalAmount AS DOUBLE
	DIM ar(), arDataID(1), arDataDescription(1), arDataName(1), arDataQuantity(1), arDataPrice(1), arDataRabatt(1), arDataAmount(1), arDataTax(1), arDataTaxID (1), arDataQuantityUnitCode(1), arDataSellID(1)
	DIM arDataStartDate(1), arDataEndDate(1), arDataRow(1), arDataKonto(1), arDataRabattIndicator(1)
	DIM arAllowReason(1), arAllowAmount(1), arAllowTax(1), arAllowIndicator(1), arTaxPercent(1), arTaxNetto(1), arTaxTax(1), arTaxID(1)
	DIM arAttachFilename(), arAttachDescription(), arAttachMimeCode(), arAttachFile(), arVor(), arDocRefID(), arDocRefDate()

	DIM arAllowTaxID(3)
	DIM stPrepaidAmount as STRING
	DIM stPayableAmount as STRING
	DIM stRAnmerkung AS STRING
	DIM stSalesID As String, stPurchaseID As String, stContractID As String
	DIM stProjectID	As String
	DIM stDir As String, stDatum As String
	DIM stDummy1 As String, stDummy2 As String, stDummy3 As String		'zum Zusammensetzen von Variablen
	stSalesID = ""
	stPurchaseID = ""
	stContractID = ""
	stTenderID = ""
	stObjectID = ""
	stProjectID = ""

		rem aus dem Buch  AndrewMacro.odt
		  Dim oDoc As Object, oSheet As Object, oCell As Object
		  oDoc=ThisComponent
		  oSheet=oDoc.Sheets.getByName("Tabelle1")
		  oCell=oSheet.getCellByposition(3,18) 				'D19
		  Rem a cell's contents can have one of the three following types:
		  XXX = oCell.getValue()
		  YYY =  oCell.getString()
		rem das bis hier ist nur ein Beispiel ... DIMt aber bereits die Variablen!!
		
	  oCell=oSheet.getCellByposition(1,14) 				'B15
	stRNummer = oCell.getString()
	IF Instr(stRNummer," ") THEN
		arDummy = Split(stRNummer, " ")
		stRNummer = arDummy(1)
	ELSE
		arDummy = Split(stRNummer, ".")
		stRNummer = arDummy(1)
	END IF		
	stInvoiceTypeCode = "380"
	  oCell=oSheet.getCellByposition(7,10) 				'H11
	stDatum = oCell.getString()									' stDatum = 31.01.26
	stRDatum = CDateToISO(stDatum)		' stRDatum = 20260131
	stDatum = CDateFromISO(stRDatum)
	
	stDir = ArchivPfad(stDatum,"Archiv",TRUE)		' stDir ist mit \ am Ende
		IF FileExists( stDir & "A" & stRNummer ) = false THEN mkDir( stDir & "A" & stRNummer )
 	stXRechnungDatei = ConvertToUrl( stDir & "A" & stRNummer & "\R" & stRNummer & "_zug.xml" )
	rem in stRechFile ist der Name der .ods-Rechnung im Archiv:
 	stRechFile = Replace(stXRechnungDatei,"_zug.xml",".ods")			' stRechFile wird ganz hinten nach xRech_ZugPDF() weitergelinkt
	rem bis hier ist die Lage der im Folgenden erzeugten Dateien festgelegt
	
	stLDatum = stRDatum
	  oCell=oSheet.getCellByposition(1,32) 				'B33 & " " & B34
	stDummy1 = oCell.getString()
	  oCell=oSheet.getCellByposition(1,33) 				'B33 & " " & B34
	stDummy2 = oCell.getString()
	stRAnmerkung = stDummy1 & " " & stDummy2
	arDataID = Array("1","2")
	arDataRow = Array("Main","Main")
	arDataSellID = Array("0","1")
	
	  oCell=oSheet.getCellByposition(1,25) 				'B26 & ": " & C26 & " / " & E26
	stDummy1 = oCell.getString()
	  oCell=oSheet.getCellByposition(2,25) 				'B26 & ": " & C26 & " / " & E26
	stDummy2 = oCell.getString()
	  oCell=oSheet.getCellByposition(4,25) 				'B26 & ": " & C26 & " / " & E26
	stDummy3 = oCell.getString()
	arDataName(0) = stDummy1 & ": " & stDummy2 & " / " & stDummy3
	
	  oCell=oSheet.getCellByposition(1,26) 				'B27 & ": " & C27 & " / " & E27
	stDummy1 = oCell.getString()
	  oCell=oSheet.getCellByposition(2,26) 				'B27 & ": " & C27 & " / " & E27
	stDummy2 = oCell.getString()
	  oCell=oSheet.getCellByposition(4,26) 				'B27 & ": " & C27 & " / " & E27
	stDummy3 = oCell.getString()
	arDataName(1) = stDummy1 & ": " & stDummy2 & " / " & stDummy3

	arDataDescription(0) = arDataName(0)
	arDataDescription(1) = arDataName(1)
	
		  oCell=oSheet.getCellByposition(7,25) 				'H26		berfhrung: 85,00 ?
	arDataPrice(0) = oCell.getString()
	arDataPrice(0) = Replace(arDataPrice(0),"?","",1,-1)
	arDataPrice(0) = Replace(arDataPrice(0),".","",1,-1)
	arDataPrice(0) = Replace(arDataPrice(0),",",".",1,-1)
	  oCell=oSheet.getCellByposition(7,26) 				'H27
	stDummy1= oCell.getString()
	stDummy1 = Replace(stDummy1,"?","",1,-1)
	stDummy1 = Replace(stDummy1,".","",1,-1)
	stDummy1 = Replace(stDummy1,",",".",1,-1)
	  oCell=oSheet.getCellByposition(5,26) 				'F27
	stDummy2 = oCell.getString()
	arDataPrice(1) = Str(CDec(stDummy1) / CDec(stDummy2))
	
	arDataQuantityUnitCode = Array("XPP","XPP")
	
	arDataQuantity(0) = "1"
	  oCell=oSheet.getCellByposition(5,26) 				'F27
	arDataQuantity(1) = oCell.getString()
	
	arDataTaxID = Array("S","S")
	
	arDataTax = Array("19.00","19.00")
	
	  oCell=oSheet.getCellByposition(7,25) 				'H26
	arDataAmount(0) = oCell.getString()
	arDataAmount(0) = Replace(arDataAmount(0),"?","",1,-1)
	arDataAmount(0) = Replace(arDataAmount(0),".","",1,-1)
	arDataAmount(0) = Replace(arDataAmount(0),",",".",1,-1)
	  oCell=oSheet.getCellByposition(7,26) 				'H27
	arDataAmount(1) = oCell.getString()
	arDataAmount(1) = Replace(arDataAmount(1),"?","",1,-1)
	arDataAmount(1) = Replace(arDataAmount(1),".","",1,-1)
	arDataAmount(1) = Replace(arDataAmount(1),",",".",1,-1)
	
	arDataRabatt = Array(0,0)

	arDataStartDate = Array(stRDatum,stRDatum)
	arDataEndDate = Array(stRDatum,stRDatum)
	stRStartDate = stRDatum
	stREndDate = stRDatum
	stAccounting = ""
	stVorRechnungenID = ""
	arDataKonto = Array("","")
	
	stRKaufRef = "10011"								' Schumacher
	stRStellAbwHandelsname  = "Anton Kirchner"
	stRStellHRAEintragsForm  = "Anton Kirchner"
	stRStellHRAEintragID  = "H.R.64928"
	stRStellFirma  = "Anton Kirchner"
	stRStellKonName  = "Anton Kirchner"
	stRStellKonTel  = "01714664967"
	stRStellEMail  = "ifge@skynet.be"
	stRStellPLZ  = "B-4700"
	stRStellStr  = "Hufengasse 22"
	stRStellStadt  = "Eupen"
	stRStellLandCode = "BE"
	stRStellKonEMail  = "AntonKirchner@gmx.de"
	stRStellUST_IdNr = "BE0650492391"
	stRStellSteuerNr = "BE0650492391"
	stCountryIdentificationCode = "BE"

	stKaufID = "10011"								' Schumacher
	stKaufName = "Beerdigungsinstitut Karl Schumacher e.K."
	stKaufAnsprechP = "Karl-Markus Schumacher"
	stKaufAnsprechPTel = "0208690480"
	stKaufAnsprechPEMail = "buchhaltung@karl-schumacher.de"
	stKaufPlz = "46117"
	stKaufStr = "Vestische Strae 146"
	stKaufStrAdd = ""
	stKaufStadt = "Oberhausen"
	stKaufLandCode = "DE"
	stKaufEMail = "zentrale@karl-schumacher.de"
	stKaufUST_IdNr = "DE120633201"

	stDocumentCurrencyCode = "EUR"
	stPaymentMeansCode = "58"
	stZahlungIBAN = "BE81 1290 0709 2424"
	stZahlungEmpfaenger = "Anton Kirchner"
	stZahlungBIC = "CTBKBEBX"
	
	arTaxTax = Array(0.00,0.00)
	arTaxNetto(0) = arDataAmount(0)
	arTaxNetto(1) = arDataAmount(1) 
	arTaxID = Array("S","S")
	arTaxPercent = Array("19.00","19.00")

	  oCell=oSheet.getCellByposition(1,32) 				'B33
	stDummy1 = oCell.getString()
	  oCell=oSheet.getCellByposition(1,33) 				'B34
	stDummy2 = oCell.getString()
	stZahlungnotiz = stDummy1 & " " & stDummy2

	  oCell=oSheet.getCellByposition(7,27) 				'H28
	stDataAmountTotal = oCell.getString()
	stDataAmountTotal = Replace(stDataAmountTotal,"?","",1,-1)
	stDataAmountTotal = Replace(stDataAmountTotal,".","",1,-1)
	stDataAmountTotal = Replace(stDataAmountTotal,",",".",1,-1)
	stNetto = stDataAmountTotal
	  oCell=oSheet.getCellByposition(7,28) 				'H29
	stSteuer = oCell.getString()
	stSteuer = Replace(stSteuer,"?","",1,-1)
	stSteuer = Replace(stSteuer,".","",1,-1)
	stSteuer = Replace(stSteuer,",",".",1,-1)
	  oCell=oSheet.getCellByposition(7,29) 				'H30
	stBrutto = oCell.getString()
	stBrutto = Replace(stBrutto,"?","",1,-1)
	stBrutto = Replace(stBrutto,".","",1,-1)
	stBrutto = Replace(stBrutto,",",".",1,-1)

	stPayableAmount = stBrutto
	
	arAllowTaxID = Array("S","S")
	
