easy-e-invoice
Version:
Easy invoice XRechnung is a standardized electronic invoice format developed to comply with the European Directive 2014/55/EU
147 lines (146 loc) • 5.87 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.simpleConvertEInvoiceToCII = void 0;
function simpleConvertEInvoiceToCII(inv) {
var _a, _b, _c;
// 1. Context
var ctx = {
businessProcessSpecifiedDocumentContextParameter: {
id: 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0',
},
guidelineSpecifiedDocumentContextParameter: {
id: 'urn:cen.eu:en16931:2017#compliant',
},
};
// 2. Document
var doc = {
id: inv.id,
typeCode: '380',
issueDateTime: { format: '102', value: inv.issueDate },
includedNotes: (inv.notes || []).map(function (n) { return ({ content: n, subjectCode: 'NOTE' }); }),
};
// 3. Line items
var lines = inv.lineItems.map(function (item) { return ({
associatedDocumentLineDocument: { lineID: item.id },
specifiedTradeProduct: {
sellerAssignedID: item.id,
buyerAssignedID: item.id,
name: item.name,
description: item.description,
},
specifiedLineTradeAgreement: {
buyerOrderReferencedDocument: { lineID: '' },
netPriceProductTradePrice: {
chargeAmount: (item.unitPrice *
(1 - inv.taxTotal.taxPercentage)).toString(),
},
},
specifiedLineTradeDelivery: {
billedQuantity: {
unitCode: 'C62',
value: item.quantity.toString(),
},
},
specifiedLineTradeSettlement: {
applicableTradeTax: {
typeCode: 'VAT',
categoryCode: 'S',
rateApplicablePercent: inv.taxTotal.taxPercentage.toString(),
},
billingSpecifiedPeriod: {
endDateTime: {
format: '102',
value: inv.dueDate || inv.issueDate,
},
},
specifiedTradeSettlementLineMonetarySummation: {
lineTotalAmount: item.lineTotal.toString(),
},
additionalReferencedDocument: {
issuerAssignedID: '',
typeCode: '',
},
},
}); });
// 4. Parties helper
var makeParty = function (name, country, street, postal, city, taxNo) {
if (street === void 0) { street = ''; }
if (postal === void 0) { postal = ''; }
if (city === void 0) { city = ''; }
return ({
name: name,
postalTradeAddress: {
postcodeCode: postal,
lineOne: street,
cityName: city,
countryID: country,
},
specifiedTaxRegistrations: taxNo ? [{ id: taxNo, schemeID: 'VA' }] : [],
});
};
var seller = makeParty(inv.supplier.name, inv.supplier.country, inv.supplier.street || '', inv.supplier.postalCode || '', inv.supplier.city || '', inv.supplier.taxNumber);
var buyer = makeParty(inv.customer.name, inv.customer.country, inv.customer.street || '', inv.customer.postalCode || '', inv.customer.city || '', inv.customer.taxNumber);
// 5. Header agreement, delivery, settlement
var agreement = {
buyerReference: inv.customer.name,
sellerTradeParty: seller,
buyerTradeParty: buyer,
sellerOrderReferencedDocument: { issuerAssignedID: '' },
buyerOrderReferencedDocument: { issuerAssignedID: '' },
contractReferencedDocument: { issuerAssignedID: '' },
additionalReferencedDocument: { issuerAssignedID: '', typeCode: '' },
};
var delivery = {
shipToTradeParty: buyer,
};
var payMeans = {
typeCode: ((_a = inv.paymentDetails) === null || _a === void 0 ? void 0 : _a.paymentMeansCode) || '31',
payeePartyCreditorFinancialAccount: {
iBANID: ((_b = inv.paymentDetails) === null || _b === void 0 ? void 0 : _b.bankDetails.iban) || '',
},
payeeSpecifiedCreditorFinancialInstitution: {
bICID: ((_c = inv.paymentDetails) === null || _c === void 0 ? void 0 : _c.bankDetails.bic) || '',
},
};
var settlement = {
paymentReference: inv.id,
invoiceCurrencyCode: inv.currency,
specifiedTradeSettlementPaymentMeans: payMeans,
applicableTradeTax: {
typeCode: 'VAT',
categoryCode: 'S',
rateApplicablePercent: inv.taxTotal.taxPercentage.toString(),
calculatedAmount: inv.taxTotal.taxAmount.toString(),
basisAmount: inv.totalNetPrice.toString(),
},
billingSpecifiedPeriod: {
startDateTime: { format: '102', value: inv.issueDate },
endDateTime: { format: '102', value: inv.dueDate || inv.issueDate },
},
specifiedTradePaymentTerms: {
description: 'Due upon receipt',
},
specifiedTradeSettlementHeaderMonetarySummation: {
lineTotalAmount: inv.totalNetPrice.toString(),
taxBasisTotalAmount: inv.totalNetPrice.toString(),
taxTotalAmount: inv.taxTotal.taxAmount.toString(),
taxTotalCurrencyID: inv.currency || 'EUR',
grandTotalAmount: (inv.totalNetPrice + inv.taxTotal.taxAmount).toString(),
duePayableAmount: (inv.totalNetPrice + inv.taxTotal.taxAmount).toString(),
},
};
// 6. Assemble
var supply = {
includedSupplyChainTradeLineItems: lines,
applicableHeaderTradeAgreement: agreement,
applicableHeaderTradeDelivery: delivery,
applicableHeaderTradeSettlement: settlement,
};
var cii = {
exchangedDocumentContext: ctx,
exchangedDocument: doc,
supplyChainTradeTransaction: supply,
};
return cii;
}
exports.simpleConvertEInvoiceToCII = simpleConvertEInvoiceToCII;