UNPKG

@disruptive-learning/cfdi-to-pdf

Version:

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

197 lines (196 loc) 7.64 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 genericRetencionTotalesContent = (totales, isVersionOne, catalogs, primaryColor, bgGrayColor) => { const retencionTotalesContent = []; const tableTotalesBody = [ [ { text: 'Totales (montos)', style: ['tableSubtitleHeader'], color: primaryColor, colSpan: 4, }, '', '', '', ], [ { text: [ { text: 'Total operación: ', color: primaryColor }, { text: (0, currency_1.formatCurrency)(totales.getAttribute(isVersionOne ? 'montoTotOperacion' : 'MontoTotOperacion')), }, ], alignment: 'center', fillColor: bgGrayColor, }, { text: [ { text: 'Total gravado: ', color: primaryColor }, { text: (0, currency_1.formatCurrency)(totales.getAttribute(isVersionOne ? 'montoTotGrav' : 'MontoTotGrav')), }, ], alignment: 'center', fillColor: bgGrayColor, }, { text: [ { text: 'Total exento: ', color: primaryColor }, { text: (0, currency_1.formatCurrency)(totales.getAttribute(isVersionOne ? 'montoTotExent' : 'MontoTotExent')), }, ], alignment: 'center', fillColor: bgGrayColor, }, { text: [ { text: 'Total retenido: ', color: primaryColor }, { text: (0, currency_1.formatCurrency)(totales.getAttribute(isVersionOne ? 'montoTotRet' : 'MontoTotRet')), }, ], alignment: 'center', fillColor: bgGrayColor, }, ], ]; const utilidadBimestral = totales.getAttribute('UtilidadBimestral'); const isrCorrespondiente = totales.getAttribute('ISRCorrespondiente'); if (!isVersionOne && (utilidadBimestral !== '' || isrCorrespondiente !== '')) { tableTotalesBody.push([ { text: [ { text: 'Utilidad Bimestral: ', color: primaryColor }, { text: (0, currency_1.formatCurrency)(totales.getAttribute('UtilidadBimestral')), }, ], alignment: 'center', fillColor: bgGrayColor, }, { text: [ { text: 'ISR Correspondiente: ', color: primaryColor }, { text: (0, currency_1.formatCurrency)(totales.getAttribute('ISRCorrespondiente')), }, ], alignment: 'center', fillColor: bgGrayColor, }, '', '', ]); } tableTotalesBody.push([ { text: '', color: primaryColor, colSpan: 4, border: [false, true, false, false], }, '', '', '', ]); retencionTotalesContent.push({ table: { widths: ['*', '*', '*', '*'], body: tableTotalesBody, dontBreakRows: true, }, layout: 'tableLayout', }); const impuestosRetenidos = totales.searchNodes('retenciones:ImpRetenidos'); if (impuestosRetenidos.length > 0) { retencionTotalesContent.push({ text: '\n' }, { table: { widths: ['20%', '20%', '*', '*'], body: [ [ { text: 'Impuestos Retenidos', style: ['tableSubtitleHeader'], color: primaryColor, colSpan: 4, }, '', '', '', ], [ { text: 'Impuesto', style: 'tableHeader', alignment: 'center', fillColor: primaryColor, margin: [0, 3, 0, 3], }, { text: 'Base', style: 'tableHeader', alignment: 'center', fillColor: primaryColor, margin: [0, 3, 0, 3], }, { text: 'Tipo Pago', style: 'tableHeader', alignment: 'center', fillColor: primaryColor, margin: [0, 3, 0, 3], }, { text: 'Monto', style: 'tableHeader', alignment: 'center', fillColor: primaryColor, margin: [0, 3, 0, 3], }, ], ...impuestosRetenidos.map((impRetenido) => { const baseRet = impRetenido.getAttribute('BaseRet'); let impuesto = impRetenido.getAttribute(isVersionOne ? 'Impuesto' : 'ImpuestoRet'); const tipoPago = impRetenido.getAttribute('TipoPagoRet'); const monto = impRetenido.getAttribute(isVersionOne ? 'montoRet' : 'MontoRet'); if (isVersionOne && impuesto.length < 3) { impuesto = `0${impuesto}`; } return [ { text: impuesto === '' ? '---' : (0, catalogs_source_1.getValueOfCatalog)('cfdi40Impuestos', impuesto, catalogs), alignment: 'center', }, { text: baseRet === '' ? '---' : (0, currency_1.formatCurrency)(baseRet), alignment: 'center', }, { text: isVersionOne ? tipoPago : (0, catalogs_source_1.getValueOfCatalog)('retenciones20TiposPago', tipoPago, catalogs), alignment: 'center', }, { text: (0, currency_1.formatCurrency)(monto), alignment: 'center', }, ]; }), ], dontBreakRows: true, headerRows: 1, }, layout: 'conceptosLayout', }); } return retencionTotalesContent; }; exports.default = genericRetencionTotalesContent;