update
This commit is contained in:
@ -72,7 +72,19 @@ export class FacturXDecoder extends CIIBaseDecoder {
|
||||
const totalAmount = this.getNumber('//ram:GrandTotalAmount');
|
||||
|
||||
// Extract notes
|
||||
const notes = this.extractNotes();
|
||||
const allNotes = this.extractNotes();
|
||||
|
||||
// Extract subject and notes separately
|
||||
let subject = `Invoice ${invoiceId}`;
|
||||
let notes = [...allNotes];
|
||||
|
||||
// If the first note doesn't look like a payment term or other standard note,
|
||||
// treat it as the subject
|
||||
if (allNotes.length > 0 && !allNotes[0].toLowerCase().includes('due in') &&
|
||||
!allNotes[0].toLowerCase().includes('payment')) {
|
||||
subject = allNotes[0];
|
||||
notes = allNotes.slice(1); // Remove subject from notes
|
||||
}
|
||||
|
||||
// Check for reverse charge
|
||||
const reverseCharge = this.exists('//ram:SpecifiedTradeAllowanceCharge/ram:ReasonCode[text()="62"]');
|
||||
@ -93,7 +105,7 @@ export class FacturXDecoder extends CIIBaseDecoder {
|
||||
incidenceId: invoiceId,
|
||||
from: seller,
|
||||
to: buyer,
|
||||
subject: `Invoice ${invoiceId}`,
|
||||
subject: subject,
|
||||
items: items,
|
||||
dueInDays: dueInDays,
|
||||
reverseCharge: reverseCharge,
|
||||
|
@ -145,15 +145,22 @@ export class FacturXEncoder extends CIIBaseEncoder {
|
||||
issueDateElement.appendChild(dateStringElement);
|
||||
documentElement.appendChild(issueDateElement);
|
||||
|
||||
// Add notes if present
|
||||
// Add notes - include subject as first note if it exists
|
||||
const allNotes: string[] = [];
|
||||
if (invoice.subject && invoice.subject.trim()) {
|
||||
allNotes.push(invoice.subject);
|
||||
}
|
||||
if (invoice.notes && invoice.notes.length > 0) {
|
||||
for (const note of invoice.notes) {
|
||||
const noteElement = doc.createElement('ram:IncludedNote');
|
||||
const contentElement = doc.createElement('ram:Content');
|
||||
contentElement.textContent = note;
|
||||
noteElement.appendChild(contentElement);
|
||||
documentElement.appendChild(noteElement);
|
||||
}
|
||||
allNotes.push(...invoice.notes);
|
||||
}
|
||||
|
||||
// Write all notes
|
||||
for (const note of allNotes) {
|
||||
const noteElement = doc.createElement('ram:IncludedNote');
|
||||
const contentElement = doc.createElement('ram:Content');
|
||||
contentElement.textContent = note;
|
||||
noteElement.appendChild(contentElement);
|
||||
documentElement.appendChild(noteElement);
|
||||
}
|
||||
|
||||
// Create transaction element if it doesn't exist
|
||||
|
@ -70,7 +70,20 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
|
||||
// const totalAmount = this.getNumber('//ram:GrandTotalAmount');
|
||||
|
||||
// Extract notes
|
||||
const notes = this.extractNotes();
|
||||
const allNotes = this.extractNotes();
|
||||
|
||||
// Extract subject and notes separately
|
||||
// If we have notes, the first one might be the subject
|
||||
let subject = `Invoice ${invoiceId}`;
|
||||
let notes = [...allNotes];
|
||||
|
||||
// If the first note doesn't look like a payment term or other standard note,
|
||||
// treat it as the subject
|
||||
if (allNotes.length > 0 && !allNotes[0].toLowerCase().includes('due in') &&
|
||||
!allNotes[0].toLowerCase().includes('payment')) {
|
||||
subject = allNotes[0];
|
||||
notes = allNotes.slice(1); // Remove subject from notes
|
||||
}
|
||||
|
||||
// Check for reverse charge
|
||||
const reverseCharge = this.exists('//ram:SpecifiedTradeAllowanceCharge/ram:ReasonCode[text()="62"]');
|
||||
@ -91,7 +104,7 @@ export class ZUGFeRDDecoder extends CIIBaseDecoder {
|
||||
incidenceId: invoiceId,
|
||||
from: seller,
|
||||
to: buyer,
|
||||
subject: `Invoice ${invoiceId}`,
|
||||
subject: subject,
|
||||
items: items,
|
||||
dueInDays: dueInDays,
|
||||
reverseCharge: reverseCharge,
|
||||
|
@ -152,15 +152,22 @@ export class ZUGFeRDEncoder extends CIIBaseEncoder {
|
||||
issueDateElement.appendChild(dateStringElement);
|
||||
documentElement.appendChild(issueDateElement);
|
||||
|
||||
// Add notes if available
|
||||
// Add notes - include subject as first note if it exists
|
||||
const allNotes: string[] = [];
|
||||
if (invoice.subject && invoice.subject.trim()) {
|
||||
allNotes.push(invoice.subject);
|
||||
}
|
||||
if (invoice.notes && invoice.notes.length > 0) {
|
||||
for (const note of invoice.notes) {
|
||||
const noteElement = doc.createElement('ram:IncludedNote');
|
||||
const contentElement = doc.createElement('ram:Content');
|
||||
contentElement.textContent = note;
|
||||
noteElement.appendChild(contentElement);
|
||||
documentElement.appendChild(noteElement);
|
||||
}
|
||||
allNotes.push(...invoice.notes);
|
||||
}
|
||||
|
||||
// Write all notes
|
||||
for (const note of allNotes) {
|
||||
const noteElement = doc.createElement('ram:IncludedNote');
|
||||
const contentElement = doc.createElement('ram:Content');
|
||||
contentElement.textContent = note;
|
||||
noteElement.appendChild(contentElement);
|
||||
documentElement.appendChild(noteElement);
|
||||
}
|
||||
|
||||
// Create transaction element if it doesn't exist
|
||||
|
@ -85,7 +85,20 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
|
||||
// const totalAmount = this.getNumber('//ram:GrandTotalAmount');
|
||||
|
||||
// Extract notes
|
||||
const notes = this.extractNotes();
|
||||
const allNotes = this.extractNotes();
|
||||
|
||||
// Extract subject and notes separately
|
||||
// If we have notes, the first one might be the subject
|
||||
let subject = `Invoice ${invoiceId}`;
|
||||
let notes = [...allNotes];
|
||||
|
||||
// If the first note doesn't look like a payment term or other standard note,
|
||||
// treat it as the subject
|
||||
if (allNotes.length > 0 && !allNotes[0].toLowerCase().includes('due in') &&
|
||||
!allNotes[0].toLowerCase().includes('payment')) {
|
||||
subject = allNotes[0];
|
||||
notes = allNotes.slice(1); // Remove subject from notes
|
||||
}
|
||||
|
||||
// Check for reverse charge
|
||||
const reverseCharge = this.exists('//ram:SpecifiedTradeAllowanceCharge/ram:ReasonCode[text()="62"]');
|
||||
@ -106,7 +119,7 @@ export class ZUGFeRDV1Decoder extends CIIBaseDecoder {
|
||||
incidenceId: invoiceId,
|
||||
from: seller,
|
||||
to: buyer,
|
||||
subject: `Invoice ${invoiceId}`,
|
||||
subject: subject,
|
||||
items: items,
|
||||
dueInDays: dueInDays,
|
||||
reverseCharge: reverseCharge,
|
||||
|
@ -82,11 +82,18 @@ export class UBLEncoder extends UBLBaseEncoder {
|
||||
const typeCode = documentType === UBLDocumentType.INVOICE ? '380' : '381';
|
||||
this.appendElement(doc, root, 'cbc:InvoiceTypeCode', typeCode);
|
||||
|
||||
// Notes
|
||||
// Notes - include subject as first note if it exists
|
||||
const allNotes: string[] = [];
|
||||
if (invoice.subject && invoice.subject.trim()) {
|
||||
allNotes.push(invoice.subject);
|
||||
}
|
||||
if (invoice.notes && invoice.notes.length > 0) {
|
||||
for (const note of invoice.notes) {
|
||||
this.appendElement(doc, root, 'cbc:Note', note);
|
||||
}
|
||||
allNotes.push(...invoice.notes);
|
||||
}
|
||||
|
||||
// Write all notes
|
||||
for (const note of allNotes) {
|
||||
this.appendElement(doc, root, 'cbc:Note', note);
|
||||
}
|
||||
|
||||
// Document Currency Code
|
||||
|
@ -164,18 +164,31 @@ export class XRechnungDecoder extends UBLBaseDecoder {
|
||||
const periodEnd = this.getText('//cac:InvoicePeriod/cbc:EndDate', this.doc);
|
||||
const deliveryDate = this.getText('//cac:Delivery/cbc:ActualDeliveryDate', this.doc);
|
||||
|
||||
// Extract notes
|
||||
const notes: string[] = [];
|
||||
const noteNodes = this.select('//cbc:Note', this.doc);
|
||||
// Extract notes (excluding PaymentTerms notes)
|
||||
const allNotes: string[] = [];
|
||||
const noteNodes = this.select('//cbc:Note[not(parent::cac:PaymentTerms)]', this.doc);
|
||||
if (noteNodes && Array.isArray(noteNodes)) {
|
||||
for (let i = 0; i < noteNodes.length; i++) {
|
||||
const noteText = noteNodes[i].textContent || '';
|
||||
if (noteText) {
|
||||
notes.push(noteText);
|
||||
allNotes.push(noteText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract subject and notes separately
|
||||
// If we have notes, the first one might be the subject
|
||||
let subject = `Invoice ${invoiceId}`;
|
||||
let notes = [...allNotes];
|
||||
|
||||
// If the first note doesn't look like a payment term or other standard note,
|
||||
// treat it as the subject
|
||||
if (allNotes.length > 0 && !allNotes[0].toLowerCase().includes('due in') &&
|
||||
!allNotes[0].toLowerCase().includes('payment')) {
|
||||
subject = allNotes[0];
|
||||
notes = allNotes.slice(1); // Remove subject from notes
|
||||
}
|
||||
|
||||
// Extract seller and buyer information
|
||||
const seller = this.extractParty('//cac:AccountingSupplierParty/cac:Party');
|
||||
const buyer = this.extractParty('//cac:AccountingCustomerParty/cac:Party');
|
||||
@ -196,7 +209,7 @@ export class XRechnungDecoder extends UBLBaseDecoder {
|
||||
incidenceId: invoiceId,
|
||||
from: seller,
|
||||
to: buyer,
|
||||
subject: notes.length > 0 ? notes[0] : `Invoice ${invoiceId}`,
|
||||
subject: subject,
|
||||
items: items,
|
||||
dueInDays: dueInDays,
|
||||
reverseCharge: false,
|
||||
|
Reference in New Issue
Block a user