UNPKG

@disruptive-learning/cfdi-to-pdf

Version:

Librería para crear un pdf basado en un XML CFDI o Retenciones

161 lines (160 loc) 6.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const catalogs_source_1 = require("#src/catalogs/catalogs_source"); const currency_1 = require("#src/utils/currency"); const fillDoctoRelacionados = (doctoRelacionados, primaryColor) => { const rowsDoctoRelacionados = [ [ { text: 'Documentos Relacionados', colSpan: 8, style: ['tableSubtitleHeader'], color: primaryColor, }, '', '', '', '', '', '', '', ], ]; const headerCells = [ 'UUID', 'Método de Pago', 'Moneda', 'Tipo de Cambio', 'Num. Parcialidad', 'Importe Saldo Anterior', 'Importe Pagado', 'Importe Saldo Insoluto', ]; const styledHeaderCells = headerCells.map((cell) => ({ text: cell, style: 'tableHeader', fillColor: primaryColor, margin: [0, 3, 0, 3], })); rowsDoctoRelacionados.push(styledHeaderCells); for (const doctoRelacionado of doctoRelacionados) { const values = [ doctoRelacionado.getAttribute('IdDocumento'), doctoRelacionado.getAttribute('MetodoDePagoDR'), doctoRelacionado.getAttribute('MonedaDR'), doctoRelacionado.getAttribute('TipoCambioDR'), doctoRelacionado.getAttribute('NumParcialidad'), (0, currency_1.formatCurrency)(doctoRelacionado.getAttribute('ImpSaldoAnt')), (0, currency_1.formatCurrency)(doctoRelacionado.getAttribute('ImpPagado')), (0, currency_1.formatCurrency)(doctoRelacionado.getAttribute('ImpSaldoInsoluto')), ]; rowsDoctoRelacionados.push(values.map((cell) => { return { style: 'tableSmall', text: cell, alignment: 'center', border: [false, false, false, true], }; })); } return { table: { widths: ['30%', 'auto', '10%', '10%', '10%', 'auto', 'auto', 'auto'], body: rowsDoctoRelacionados, dontBreakRows: true, }, layout: 'conceptosLayout', }; }; const usePago10Complement = (pago10, currentContent, catalogs, primaryColor, bgGrayColor) => { const pagos = pago10.searchNodes('pago10:Pago'); if (pagos.length > 0) { for (const pago of pagos) { const doctoRelacionados = pago.searchNodes('pago10:DoctoRelacionado'); currentContent.push({ table: { widths: ['10%', '*', '10%', '*'], body: [ [ { text: 'Información de Pago', style: ['tableSubtitleHeader'], color: primaryColor, colSpan: 4, }, '', '', '', ], [ { style: 'tableSmall', text: 'Fecha:', color: primaryColor, fillColor: bgGrayColor, }, { style: 'tableSmall', text: pago.getAttribute('FechaPago'), fillColor: bgGrayColor, }, { style: 'tableSmall', text: 'Forma Pago:', color: primaryColor, fillColor: bgGrayColor, }, { style: 'tableSmall', text: (0, catalogs_source_1.getValueOfCatalog)('cfdi40FormasPago', pago.getAttribute('FormaDePagoP'), catalogs), fillColor: bgGrayColor, }, ], [ { style: 'tableSmall', text: 'Moneda:', color: primaryColor, fillColor: bgGrayColor, }, { style: 'tableSmall', text: pago.getAttribute('MonedaP'), fillColor: bgGrayColor }, { style: 'tableSmall', text: 'Monto:', color: primaryColor, fillColor: bgGrayColor, }, { style: 'tableSmall', text: (0, currency_1.formatCurrency)(pago.getAttribute('Monto')), fillColor: bgGrayColor, }, ], ...(pago.hasAttribute('TipoCambioP') ? [ [ { style: 'tableSmall', text: 'Tipo de Cambio:', color: primaryColor, fillColor: bgGrayColor, }, { style: 'tableSmall', text: pago.getAttribute('TipoCambioP'), fillColor: bgGrayColor, }, { style: 'tableSmall', text: '', fillColor: bgGrayColor }, { style: 'tableSmall', text: '', fillColor: bgGrayColor }, ], ] : []), ], dontBreakRows: true, }, layout: 'tableLayout', }, '\n', fillDoctoRelacionados(doctoRelacionados, primaryColor), '\n', '\n'); } } }; exports.default = usePago10Complement;