8. November 2023 19:56
void clicked()
{
TextIO io;
Filename filename;
str defaultpath;
str s,s1,s2,s3,s4,s5,s6,s7,s8;
str z1,z2,z3;
str ltaKontakt,kKontakt;
str durchwahl = "-0";
str strMessage = "";
str strTitle = "XRechnung erstellen";
date d = today();
CustTable custTable;
ProjInvoiceItem projInvoiceItem;
ProjInvoiceTable projInvoiceTable;
ProjTable projTable;
EmplTable emplTable;
str directory = @"C:\XRechnung";
;
super();
//Typ Rechnung prüfen + vorhandene Leitweg-ID
if (ProjInvoiceJour.ProjInvoiceType == ProjInvoiceType::Invoice && custTable::find(ProjInvoiceJour.OrderAccount).Leitweg_ID)
{
if (!WinApi::folderExists(directory))
{
WinApi::createDirectory(directory);
}
s = date2Str(d, 123, 2, -1, 2, -1, 4);
defaultpath = "C:\\XRechnung\\";
filename = defaultpath + "XRechnung_" + ProjInvoiceJour.ProjInvoiceId + "_" + s + "_" + int2str(timenow()) + ".xml";
io = new TextIO(filename, 'W', 65001);//Codepage muss 65001, sonst werden Umlaute nicht übergeben
io.outFieldDelimiter('|');
//xml erzeugen
s1 = '<?xml version="1.0" encoding="utf-8"?>';
io.write(s1);
s1 = '<Invoice'
+ ' xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"'
+ ' xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"'
+ ' xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">';
io.write(s1);
s1 = '<cbc:UBLVersionID>2.1</cbc:UBLVersionID>';
io.write(s1);
s1 = '<cbc:CustomizationID>urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.3</cbc:CustomizationID>';
io.write(s1);
//BT-01 Rechnungsnummer
s1 = strfmt('<cbc:ID>%1/%2</cbc:ID>', ProjInvoiceJour.OrderAccount, ProjInvoiceJour.ProjInvoiceId);
io.write(s1);
//BT-02 Rechnungsdatum
s1 = strfmt('<cbc:IssueDate>%1</cbc:IssueDate>', date2str(ProjInvoiceJour.InvoiceDate,321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2,DateSeparator::Hyphen,DateYear::Digits4));
io.write(s1);
//BT-09 Fälligkeitsdatum
s1 = strfmt('<cbc:DueDate>%1</cbc:DueDate>', date2str(ProjInvoiceJour.DueDate,321,DateDay::Digits2,DateSeparator::Hyphen,DateMonth::Digits2,DateSeparator::Hyphen,DateYear::Digits4));
io.write(s1);
//BT-03 Rechnungstyp 380 = Rechnung, Korrigierte Rechnung, Teilrechnung, Gutschrift, Abschlagsrechnung, Teilschlussrechnung, Schlussrechnung
s1 = '<cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>'; //Rechnung
io.write(s1);
//BT-22 Bemerkungen zur Rechnung
z1 = 'Lieferungen erfolgen ausschließlich zu unseren Allg. Geschäftsbedingungen.';
z2 = 'Wir verweisen insbesondere auf unseren einfachen, verlängerten und erweiterten';
z3 = 'Eigentumsvorbehalt.';
s1 = strfmt('<cbc:Note>%1\n%2\n%3</cbc:Note>', z1, z2, z3);
io.write(s1);
s1 = '<cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>';
io.write(s1);
//BT-10 Leitweg-ID des Kunden
s1 = strfmt('<cbc:BuyerReference>%1</cbc:BuyerReference>', custTable::find(ProjInvoiceJour.OrderAccount).Leitweg_ID);
io.write(s1);
//BT-46 Projektvertrag
s1 = '<cac:ContractDocumentReference>';
io.write(s1);
s1 = strfmt('<cbc:ID>%1</cbc:ID>', ProjInvoiceJour.ProjInvoiceProjId);
io.write(s1);
s1 = '</cac:ContractDocumentReference>';
io.write(s1);
//BT-27 eigene Firmendaten
s1 = '<cac:AccountingSupplierParty>';
io.write(s1);
s1 = '<cac:Party>';
io.write(s1);
s1 = '<cac:PostalAddress>';
io.write(s1);
s1 = strfmt('<cbc:StreetName>%1</cbc:StreetName>', CompanyInfo::find().Street);
io.write(s1);
s1 = strfmt('<cbc:CityName>%1</cbc:CityName>', CompanyInfo::find().City);
io.write(s1);
s1 = strfmt('<cbc:PostalZone>%1</cbc:PostalZone>', CompanyInfo::find().ZipCode);
io.write(s1);
s1 = '<cac:Country>';
io.write(s1);
s1 = strfmt('<cbc:IdentificationCode>%1</cbc:IdentificationCode>', CompanyInfo::find().CountryRegionId);
io.write(s1);
s1 = '</cac:Country>';
io.write(s1);
s1 = '</cac:PostalAddress>';
io.write(s1);
//BT-31 eigene Umsatzsteuer-ID
s1 = '<cac:PartyTaxScheme>';
io.write(s1);
s1 = strfmt('<cbc:CompanyID>DE%1</cbc:CompanyID>', CompanyInfo::find().VATNum);
io.write(s1);
s1 = '<cac:TaxScheme>';
io.write(s1);
s1 = '<cbc:ID>VAT</cbc:ID>'; //VAT = Umsatzsteuer-ID
io.write(s1);
s1 = '</cac:TaxScheme>';
io.write(s1);
s1 = '</cac:PartyTaxScheme>';
io.write(s1);
//BT-32 eigene Steuernummer
s1 = '<cac:PartyTaxScheme>';
io.write(s1);
s1 = strfmt('<cbc:CompanyID>%1</cbc:CompanyID>', CompanyInfo::find().CoRegNum);
io.write(s1);
s1 = '<cac:TaxScheme>';
io.write(s1);
s1 = '<cbc:ID>FC</cbc:ID>'; //FC = Steuernummer
io.write(s1);
s1 = '</cac:TaxScheme>';
io.write(s1);
s1 = '</cac:PartyTaxScheme>';
io.write(s1);
s1 = '<cac:PartyLegalEntity>';
io.write(s1);
s1 = strfmt('<cbc:RegistrationName>%1</cbc:RegistrationName>', CompanyInfo::find().Name);
io.write(s1);
s1 = strfmt('<cbc:CompanyID>DE%1</cbc:CompanyID>', CompanyInfo::find().VATNum);
io.write(s1);
s1 = '</cac:PartyLegalEntity>';
io.write(s1);
//eigene Kontaktdaten
s1 = '<cac:Contact>';
io.write(s1);
//BT-41 Name
while select projTable index InvoiceProjectIdx
where projTable.ProjInvoiceProjId == ProjInvoiceJour.ProjInvoiceProjId
{
ltaKontakt = EmplTable::emplId2Name(projTable.ResponsibleSales);
}
s1 = '<cbc:Name>'
+ strfmt('%1', ltaKontakt)
+ '</cbc:Name>';
io.write(s1);
//BT-42 Telephon
while select projTable index InvoiceProjectIdx
where projTable.ProjInvoiceProjId == ProjInvoiceJour.ProjInvoiceProjId
{
if (emplTable::find(projTable.ResponsibleSales).Durchwahl)
{
durchwahl = emplTable::find(projTable.ResponsibleSales).Durchwahl;
}
}
s1 = '<cbc:Telephone>'
+ strfmt('+49(0)38874 50%1', durchwahl)
+ '</cbc:Telephone>';
io.write(s1);
//BT-43 Mail fest eingestellt
s1 = '<cbc:ElectronicMail>rechnung@lta-anlagentechnik.de</cbc:ElectronicMail>';
io.write(s1);
s1 = '</cac:Contact>';
io.write(s1);
s1 = '</cac:Party>';
io.write(s1);
s1 = '</cac:AccountingSupplierParty>';
io.write(s1);
//BT-44 Kundendaten
s1 = '<cac:AccountingCustomerParty>';
io.write(s1);
s1 = '<cac:Party>';
io.write(s1);
//BT-46 Kundennummer
s1 = '<cac:PartyIdentification>';
io.write(s1);
s1 = strfmt('<cbc:ID>%1</cbc:ID>', ProjInvoiceJour.OrderAccount);
io.write(s1);
s1 = '</cac:PartyIdentification>';
io.write(s1);
s1 = '<cac:PostalAddress>';
io.write(s1);
//BT-50 Straße
s1 = strfmt('<cbc:StreetName>%1</cbc:StreetName>', ProjInvoiceJour.DeliveryStreet);
io.write(s1);
//BT-52 Ort
s1 = strfmt('<cbc:CityName>%1</cbc:CityName>', ProjInvoiceJour.DeliveryCity);
io.write(s1);
//BT-53 PLZ
s1 = strfmt('<cbc:PostalZone>%1</cbc:PostalZone>', ProjInvoiceJour.DlvZipCode);
io.write(s1);
s1 = '<cac:Country>';
io.write(s1);
//BT-55 Land
s1 = strfmt('<cbc:IdentificationCode>%1</cbc:IdentificationCode>', ProjInvoiceJour.LanguageId);
io.write(s1);
s1 = '</cac:Country>';
io.write(s1);
s1 = '</cac:PostalAddress>';
io.write(s1);
//BT-48 Umsatzsteuer-ID
s1 = '<cac:PartyTaxScheme>';
io.write(s1);
s1 = strfmt('<cbc:CompanyID>%1</cbc:CompanyID>', ProjInvoiceJour.VATNum); //Umsatzsteuer-ID
io.write(s1);
s1 = '<cac:TaxScheme>';
io.write(s1);
s1 = '<cbc:ID>VAT</cbc:ID>'; //VAT = Umsatzsteuer-ID
io.write(s1);
s1 = '</cac:TaxScheme>';
io.write(s1);
s1 = '</cac:PartyTaxScheme>';
io.write(s1);
s1 = '<cac:PartyLegalEntity>';
io.write(s1);
//BT-44 Firmenname Kunde
s1 = strfmt('<cbc:RegistrationName>%1</cbc:RegistrationName>', strreplace(ProjInvoiceJour.DeliveryName, '&', 'und'));
io.write(s1);
s1 = '</cac:PartyLegalEntity>';
io.write(s1);
//Kontaktdaten Kunde
s1 = '<cac:Contact>';
io.write(s1);
//BT-56 Name
while select projInvoiceTable index ProjInvoiceIdx
where projInvoiceTable.ProjInvoiceProjId == ProjInvoiceJour.ProjInvoiceProjId
{
kKontakt = projInvoiceTable.contactPersonName();
}
s1 = '<cbc:Name>'
+ strfmt('%1', kKontakt)
+ '</cbc:Name>';
io.write(s1);
//BT-57 Telephon
s1 = '<cbc:Telephone></cbc:Telephone>';
io.write(s1);
//BT-58 Mail
s1 = '<cbc:ElectronicMail></cbc:ElectronicMail>';
io.write(s1);
s1 = '</cac:Contact>';
io.write(s1);
s1 = '</cac:Party>';
io.write(s1);
s1 = '</cac:AccountingCustomerParty>';
io.write(s1);
//Zahlung fest auf Commerzbank eingestellt
s1 = '<cac:PaymentMeans>';
io.write(s1);
s1 = '<cbc:PaymentMeansCode>58</cbc:PaymentMeansCode>'; //SEPA Überweisung
io.write(s1);
s1 = '<cbc:InstructionNote>SepaCreditTransfer</cbc:InstructionNote>';
io.write(s1);
s1 = '<cac:PayeeFinancialAccount>';
io.write(s1);
s1 = '<cbc:ID>DE13200400000624267100</cbc:ID>'; //IBAN
io.write(s1);
s1 = '<cbc:Name>Commerzbank</cbc:Name>'; //Bankname
io.write(s1);
s1 = '<cac:FinancialInstitutionBranch>';
io.write(s1);
s1 = '<cbc:ID>COBADEFFXXX</cbc:ID>'; //BIC
io.write(s1);
s1 = '</cac:FinancialInstitutionBranch>';
io.write(s1);
s1 = '</cac:PayeeFinancialAccount>';
io.write(s1);
s1 = '</cac:PaymentMeans>';
io.write(s1);
//Rechnungssummen
s1 = '<cac:TaxTotal>';
io.write(s1);
// Umsatzsteuer
s1 = strfmt('<cbc:TaxAmount currencyID="EUR">%1</cbc:TaxAmount>', num2str(ProjInvoiceJour.SumTax,1,2,1,0));
io.write(s1);
s1 = '<cac:TaxSubtotal>';
io.write(s1);
//BT-109 Netto-Rechnungs-Gesamtbetrag
s1 = strfmt('<cbc:TaxableAmount currencyID="EUR">%1</cbc:TaxableAmount>', num2str(ProjInvoiceJour.SalesOrderbalance,1,2,1,0));
io.write(s1);
//Umsatzsteuer
s1 = strfmt('<cbc:TaxAmount currencyID="EUR">%1</cbc:TaxAmount>', num2str(ProjInvoiceJour.SumTax,1,2,1,0));
io.write(s1);
s1 = '<cac:TaxCategory>';
io.write(s1);
// Steuertyp S = KUI 19% AE = KUI-$13b
s4 = ProjInvoiceJour.TaxGroupId;
if (s4 == 'KUI-§13b')
{
s5 = 'AE';
s6 = '0.00';
}
else
{
s5 = 'S';
s6 = '19.00';
}
s1 = strfmt('<cbc:ID>%1</cbc:ID>', s5);
io.write(s1);
s1 = strfmt('<cbc:Percent>%1</cbc:Percent>', s6);
io.write(s1);
if (s4 == 'KUI-§13b')
{
s1 ='<cbc:TaxExemptionReason>Die Umsatzsteuer nach $ 13b UStG schuldet der Leistungsempfänger.</cbc:TaxExemptionReason>';
io.write(s1);
}
s1 = '<cac:TaxScheme>';
io.write(s1);
s1 = '<cbc:ID>VAT</cbc:ID>';
io.write(s1);
s1 = '</cac:TaxScheme>';
io.write(s1);
s1 = '</cac:TaxCategory>';
io.write(s1);
s1 = '</cac:TaxSubtotal>';
io.write(s1);
s1 = '</cac:TaxTotal>';
io.write(s1);
s1 = '<cac:LegalMonetaryTotal>';
io.write(s1);
//BT-106 Nettobetrag
s1 = strfmt('<cbc:LineExtensionAmount currencyID="EUR">%1</cbc:LineExtensionAmount>', num2str(ProjInvoiceJour.SalesOrderbalance,1,2,1,0));
io.write(s1);
//BT-109 Nettobetrag
s1 = strfmt('<cbc:TaxExclusiveAmount currencyID="EUR">%1</cbc:TaxExclusiveAmount>', num2str(ProjInvoiceJour.SalesOrderbalance,1,2,1,0));
io.write(s1);
//BT-112 Brutto gesammt
s1 = strfmt('<cbc:TaxInclusiveAmount currencyID="EUR">%1</cbc:TaxInclusiveAmount>', num2str(ProjInvoiceJour.InvoiceAmount,1,2,1,0));
io.write(s1);
//BT-107 Summe Nachlässe Dokumentebene
s1 = '<cbc:AllowanceTotalAmount currencyID="EUR">0.00</cbc:AllowanceTotalAmount>';
io.write(s1);
s1 = '<cbc:ChargeTotalAmount currencyID="EUR">0.00</cbc:ChargeTotalAmount>';
io.write(s1);
s1 = '<cbc:PrepaidAmount currencyID="EUR">0.00</cbc:PrepaidAmount>';
io.write(s1);
//BT-114 Rundungsbetrag
s1 = '<cbc:PayableRoundingAmount currencyID="EUR">0.00</cbc:PayableRoundingAmount>';
io.write(s1);
//BT-115 Rechnungsbetrag
s1 = strfmt('<cbc:PayableAmount currencyID="EUR">%1</cbc:PayableAmount>', num2str(ProjInvoiceJour.InvoiceAmount,1,2,1,0));
io.write(s1);
s1 = '</cac:LegalMonetaryTotal>';
io.write(s1);
//Artikel einfügen
while select projInvoiceItem
where ProjInvoiceJour.ProjInvoiceId == projInvoiceItem.ProjInvoiceId
{
s1 = '<cac:InvoiceLine>';
io.write(s1);
//BT-126 Positionsnummer
s1 = strfmt('<cbc:ID>%1</cbc:ID>', projInvoiceItem.ProjId);
io.write(s1);
//BT-129 Menge + BT-130 Einheit uniCode="C62" ist Stück, uniCode="HUR"
s2 = projInvoiceItem.SalesUnit;
if (s2 == 'Std.')
{
s3 = 'HUR';
}
else
{
s3 = 'C62';
}
// Menge auf negativ wenn
if (projInvoiceItem.SalesPrice < 0)
{
projInvoiceItem.SalesPrice =- projInvoiceItem.SalesPrice;
projInvoiceItem.Qty =- projInvoiceItem.Qty;
}
s1 = strfmt('<cbc:InvoicedQuantity unitCode="%1">%2</cbc:InvoicedQuantity>', s3, num2str(projInvoiceItem.Qty,1,2,1,0));
io.write(s1);
//BT-131 Gesamtpreis (Netto)
s1 = strfmt('<cbc:LineExtensionAmount currencyID="EUR">%1</cbc:LineExtensionAmount>', num2str(projInvoiceItem.LineAmount,1,2,1,0));
io.write(s1);
s1 = '<cac:Item>';
io.write(s1);
//BT-154 Beschreibung
s1 = strfmt('<cbc:Description>%1</cbc:Description>', projInvoiceItem.Txt);
io.write(s1);
//BT-153 Bezeichnung
s1 = strfmt('<cbc:Name>%1</cbc:Name>', projInvoiceItem.Txt);
io.write(s1);
s1 = '<cac:SellersItemIdentification>';
io.write(s1);
//BT-155 Artikelnummer
s1 = strfmt('<cbc:ID>%1</cbc:ID>', projInvoiceItem.ItemId);
io.write(s1);
s1 = '</cac:SellersItemIdentification>';
io.write(s1);
//BT-151 Umsatzsteuersatz
s1 = '<cac:ClassifiedTaxCategory>';
io.write(s1);
s4 = projInvoiceItem.TaxGroupId;
if (s4 == 'KUI-§13b')
{
s5 = 'AE';
s6 = '0.00';
}
else
{
s5 = 'S';
s6 = '19.00';
}
s1 = strfmt('<cbc:ID>%1</cbc:ID>', s5);
io.write(s1);
s1 = strfmt('<cbc:Percent>%1</cbc:Percent>', s6);
io.write(s1);
s1 = '<cac:TaxScheme>';
io.write(s1);
s1 = '<cbc:ID>VAT</cbc:ID>';
io.write(s1);
s1 = '</cac:TaxScheme>';
io.write(s1);
s1 = '</cac:ClassifiedTaxCategory>';
io.write(s1);
s1 = '</cac:Item>';
io.write(s1);
s1 = '<cac:Price>';
io.write(s1);
//BT-146 Preis pro Einheit
s1 = strfmt('<cbc:PriceAmount currencyID="EUR">%1</cbc:PriceAmount>', num2str(projInvoiceItem.SalesPrice,1,2,1,0));
io.write(s1);
s1 = '</cac:Price>';
io.write(s1);
s1 = '</cac:InvoiceLine>';
io.write(s1);
}
//bis hier Rechnungsinhalt
s1 = '</Invoice>';
io.write(s1);
io = null;
//xml Erzeugung Ende
strMessage = strfmt("XRechnung: %1 für den Kunden: %2 wurde erzeugt.\nDiese liegt im Ordner: %3.", ProjInvoiceJour.ProjInvoiceId, ProjInvoiceJour.DeliveryName, directory);
}
else
{
strMessage = "Der Kunde hat keine Leitweg-ID hinterlegt \noder es ist eine Akonto-Rechnung!";
}
Box::info(strMessage,strTitle);
}
8. November 2023 21:58
PS. wieso liegt dieses Thema im Klatsch & Tratsch?
9. November 2023 19:44
26. Januar 2024 14:47
26. Januar 2024 14:58
JoSchuh hat geschrieben:Gibt es eingentlich auch ein ZugFerd Modul für den Classic Client ??
9. Februar 2024 09:52