import { UBLBaseEncoder } from '../ubl.encoder.js'; import type { TInvoice, TCreditNote, TDebitNote } from '../../../interfaces/common.js'; import { UBLDocumentType } from '../ubl.types.js'; /** * Encoder for XRechnung (UBL) format * Implements encoding of TInvoice to XRechnung XML */ export class XRechnungEncoder extends UBLBaseEncoder { /** * Encodes a TCreditNote object to XRechnung XML * @param creditNote TCreditNote object to encode * @returns Promise resolving to XML string */ protected async encodeCreditNote(creditNote: TCreditNote): Promise { // For now, we'll just return a simple UBL credit note template // In a real implementation, we would generate a proper UBL credit note return ` urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0 ${creditNote.id} ${this.formatDate(creditNote.date)} 381 ${creditNote.currency} `; } /** * Encodes a TDebitNote object to XRechnung XML * @param debitNote TDebitNote object to encode * @returns Promise resolving to XML string */ protected async encodeDebitNote(debitNote: TDebitNote): Promise { // For now, we'll just return a simple UBL invoice template // In a real implementation, we would generate a proper UBL invoice return ` urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0 ${debitNote.id} ${this.formatDate(debitNote.date)} ${this.formatDate(debitNote.date + debitNote.dueInDays * 24 * 60 * 60 * 1000)} 380 ${debitNote.currency} ${debitNote.from.name} ${debitNote.from.address.streetName || ''} ${debitNote.from.address.houseNumber || ''} ${debitNote.from.address.city || ''} ${debitNote.from.address.postalCode || ''} ${debitNote.from.address.countryCode || ''} ${debitNote.from.registrationDetails?.vatId ? ` ${debitNote.from.registrationDetails.vatId} VAT ` : ''} ${debitNote.from.registrationDetails?.registrationId ? ` ${debitNote.from.registrationDetails.registrationName || debitNote.from.name} ${debitNote.from.registrationDetails.registrationId} ` : ''} ${debitNote.to.name} ${debitNote.to.address.streetName || ''} ${debitNote.to.address.houseNumber || ''} ${debitNote.to.address.city || ''} ${debitNote.to.address.postalCode || ''} ${debitNote.to.address.countryCode || ''} ${debitNote.to.registrationDetails?.vatId ? ` ${debitNote.to.registrationDetails.vatId} VAT ` : ''} Due in ${debitNote.dueInDays} days 0.00 0.00 0.00 0.00 0.00 ${debitNote.items.map((item, index) => ` ${index + 1} ${item.unitQuantity} ${item.unitNetPrice * item.unitQuantity} ${item.name} ${item.articleNumber ? ` ${item.articleNumber} ` : ''} S ${item.vatPercentage} VAT ${item.unitNetPrice} `).join('')} `; } }