@disruptive-learning/cfdi-to-pdf
Version:
Librería para crear un pdf basado en un XML CFDI o Retenciones
65 lines (64 loc) • 2.13 kB
JavaScript
import { getKeyValueOfCatalog } from '#src/catalogs/catalogs_source';
import { toCurrency } from '#src/utils/currency';
const genericCfdiDetailsInfoContent = (comprobante, catalogs, primaryColor) => {
const detailsInfo = [];
const total = comprobante.getAttribute('Total');
const moneda = comprobante.getAttribute('Moneda');
detailsInfo.push([
{
text: ['Importe con letra: ', toCurrency(total === '' ? 0 : Number(total), moneda)],
alignment: 'center',
colSpan: 4,
style: ['tableSubtitleHeader'],
},
'',
'',
'',
]);
const comprobanteInfo = [
{
text: [
{ text: 'Método de Pago: ', color: primaryColor },
{
text: getKeyValueOfCatalog('cfdi40MetodosPago', comprobante.getAttribute('MetodoPago'), catalogs),
},
],
alignment: 'center',
},
{
text: [
{ text: 'Forma de Pago: ', color: primaryColor },
{
text: getKeyValueOfCatalog('cfdi40FormasPago', comprobante.getAttribute('FormaPago'), catalogs),
},
],
alignment: 'center',
},
];
if (moneda === 'MXN') {
comprobanteInfo.push({
text: [{ text: 'Moneda: ', color: primaryColor }, { text: moneda }],
colSpan: 2,
alignment: 'center',
}, '');
}
else {
comprobanteInfo.push({ text: [{ text: 'Moneda: ', color: primaryColor }, { text: moneda }], alignment: 'center' }, {
text: [
{ text: 'Tipo cambio: ', color: primaryColor },
{ text: comprobante.getAttribute('TipoCambio') },
],
alignment: 'center',
});
}
detailsInfo.push(comprobanteInfo);
return {
table: {
widths: ['38%', '38%', '12%', '12%'],
body: detailsInfo,
dontBreakRows: true,
},
layout: 'tableLayout',
};
};
export default genericCfdiDetailsInfoContent;