OfficeServer/create-angebot-template.js
dgsoft a01423321b Complete migration from docx-templates to docxtemplater
 Migration completed:
- server.js: Complete rewrite using docxtemplater + pizzip
- server-old.js: Backup of original docx-templates implementation
- package.json: Added docxtemplater and pizzip dependencies
- Removed docx-templates dependency

🚀 New features:
- True dynamic tables with {#array}{field}{/array} syntax
- Unlimited table rows (no more fixed array indices)
- New API endpoints: /analyze, /generate, /demo
- Simplified template creation scripts

🎯 Template improvements:
- Updated template syntax examples
- Added dynamic-template.docx with loop syntax
- Enhanced template analysis functionality

📊 Benefits:
- Real dynamic table generation
- Better template flexibility
- Cleaner API design
- Preserved SSL and WebDAV functionality
2025-10-01 22:14:19 +02:00

132 lines
5.7 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const AdmZip = require('adm-zip');
function createOfferTemplate() {
try {
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 - Angebot 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="32"/></w:rPr><w:t>ANGEBOT</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>Anbieter:</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Interessent:</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>++straße++</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>++kunde_straße++</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:tr>
<w:tc><w:p><w:r><w:t>Ansprechpartner: ++ansprechpartner++</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>Email: ++kunde_email++</w:t></w:r></w:p></w:tc>
</w:tr>
<w:tr>
<w:tc><w:p><w:r><w:t>Email: ++email++</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>Tel: ++kunde_telefon++</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>Angebotsnummer: ++angebotsnummer++</w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Angebotsdatum: ++datum++</w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Gültig bis: ++gültig_bis++</w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Projekt: ++projekt_name++</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>Sehr geehrte Damen und Herren,</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>gerne unterbreiten wir Ihnen folgendes Angebot:</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>Leistung</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>Aufwand</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Preis</w:t></w:r></w:p></w:tc>
</w:tr>
<w:tr>
<w:tc><w:p><w:r><w:t>++leistungen[0].nr++</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>++leistungen[0].titel++</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>++leistungen[0].beschreibung++</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>++leistungen[0].aufwand++</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>++leistungen[0].preis++</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>Gesamtpreis: ++gesamtpreis++</w:t></w:r></w:p>
<w:p><w:r><w:t>Alle Preise verstehen sich zzgl. der gesetzlichen Mehrwertsteuer.</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Projektdauer:</w:t></w:r></w:p>
<w:p><w:r><w:t>Geplanter Projektstart: ++projektstart++</w:t></w:r></w:p>
<w:p><w:r><w:t>Voraussichtliche Fertigstellung: ++projektende++</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:rPr><w:b/></w:rPr><w:t>Zahlungskonditionen:</w:t></w:r></w:p>
<w:p><w:r><w:t>++zahlungskonditionen++</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>Für Rückfragen stehen wir Ihnen gerne zur Verfügung.</w:t></w:r></w:p>
<w:p><w:r><w:t></w:t></w:r></w:p>
<w:p><w:r><w:t>Mit freundlichen Grüßen</w:t></w:r></w:p>
<w:p><w:r><w:t>++ansprechpartner++</w:t></w:r></w:p>
</w:body>
</w:document>`;
// Dateien zum ZIP hinzufügen
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'));
// DOCX speichern
const templatePath = path.join(__dirname, 'templates', 'angebot-template.docx');
fs.writeFileSync(templatePath, zip.toBuffer());
console.log('✅ Angebot-Template erstellt:', templatePath);
} catch (error) {
console.error('❌ Fehler beim Erstellen des Angebot-Templates:', error);
}
}
createOfferTemplate();