OfficeServer/create-rechnung-fixed.js
dgsoft 5371d5e479 Add WebDAV integration and template improvements
 Frontend-Verbesserungen:
- WebDAV-Integration für direktes Template-Bearbeiten
- 'In Word öffnen' Button für ms-word: URLs
- Verbesserte Template-Karten mit Tag-Informationen
- WebDAV-Info-Sektion mit Anleitungen
- Korrigierte API-Endpunkte für docxtemplater

🔧 Template-Updates:
- Alle Templates auf docxtemplater-Syntax aktualisiert
- create-*-fixed.js Scripts für korrekte {tag} Syntax
- Entfernt alte ++tag++ und ++INS++ Syntax
- Neue create-new-table-template.js für echte Loops

🌐 WebDAV-Features:
- Direkter Template-Download über /webdav/templates/
- Template-Bearbeitung in Word möglich
- Automatische Speicherung über WebDAV
- Fallback auf Download bei Word-Problemen

📊 Template-Syntax-Migration:
- {variable} statt ++variable++
- {#array}{field}{/array} statt ++INS array++
- Echte dynamische Tabellen ohne fixe Indizes
- Verbesserte Tag-Erkennung und Analyse
2025-10-01 22:27:29 +02:00

104 lines
4.4 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const AdmZip = require('adm-zip');
function createRechnungTemplate() {
const zip = new AdmZip();
// [Content_Types].xml
const contentTypes = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>`;
// _rels/.rels
const rels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
</Relationships>`;
// word/document.xml - Rechnungs Template
const document = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:pPr><w:jc w:val="center"/></w:pPr>
<w:r><w:rPr><w:b/><w:sz w:val="36"/></w:rPr><w:t>RECHNUNG</w:t></w:r>
</w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:tbl>
<w:tblPr><w:tblW w:w="0" w:type="auto"/></w:tblPr>
<w:tr>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Rechnungssteller</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Kunde</w:t></w:r></w:p></w:tc>
</w:tr>
<w:tr>
<w:tc><w:p><w:r><w:t>{firma}</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>{kunde_name}</w:t></w:r></w:p></w:tc>
</w:tr>
<w:tr>
<w:tc><w:p><w:r><w:t>{strasse}</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>{kunde_strasse}</w:t></w:r></w:p></w:tc>
</w:tr>
<w:tr>
<w:tc><w:p><w:r><w:t>{plz} {stadt}</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>{kunde_plz} {kunde_stadt}</w:t></w:r></w:p></w:tc>
</w:tr>
</w:tbl>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Rechnungsnummer: {rechnungsnummer}</w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Rechnungsdatum: {datum}</w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Leistungszeitraum: {leistungszeitraum}</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:tbl>
<w:tblPr><w:tblW w:w="0" w:type="auto"/></w:tblPr>
<w:tr>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Pos.</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Beschreibung</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Menge</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Einzelpreis (€)</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Gesamtpreis (€)</w:t></w:r></w:p></w:tc>
</w:tr>
<w:tr>
<w:tc><w:p><w:r><w:t>{#positionen}{nr}</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>{beschreibung}</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>{menge}</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>{einzelpreis}</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>{gesamtpreis}{/positionen}</w:t></w:r></w:p></w:tc>
</w:tr>
</w:tbl>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Nettobetrag: {nettobetrag}€</w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Mehrwertsteuer (19%): {mwst}€</w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/><w:sz w:val="24"/></w:rPr><w:t>Gesamtbetrag: {gesamtbetrag}€</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>Zahlbar bis: {zahlbar_bis}</w:t></w:r></w:p>
<w:p><w:r><w:t>Verwendungszweck: {rechnungsnummer}</w:t></w:r></w:p>
</w:body>
</w:document>`;
// Füge Dateien zum ZIP hinzu
zip.addFile('[Content_Types].xml', Buffer.from(contentTypes, 'utf8'));
zip.addFile('_rels/.rels', Buffer.from(rels, 'utf8'));
zip.addFile('word/document.xml', Buffer.from(document, 'utf8'));
// Speichere die Datei
const outputPath = path.join(__dirname, 'templates', 'rechnung-template.docx');
zip.writeZip(outputPath);
console.log('✅ Rechnungs-Template mit docxtemplater-Syntax erstellt:', outputPath);
}
createRechnungTemplate();