UNPKG

@disruptive-learning/cfdi-to-pdf

Version:

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

80 lines (79 loc) 3.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const generic_cfdi_concepto_impuestos_content_1 = __importDefault(require("#src/templates/sections/generic_cfdi_concepto_impuestos_content")); const currency_1 = require("#src/utils/currency"); const genericCfdiConceptosContent = (comprobante, catalogs, primaryColor, bgGrayColor) => { const conceptos = comprobante.searchNodes('cfdi:Conceptos', 'cfdi:Concepto'); const rowsConceptos = []; const headerCells = [ 'No. Identificación', 'Clave Unidad', 'Descripción', 'Valor Unitario', 'Cantidad', { text: 'Importe', alignment: 'center' }, 'Descuento', 'Impuestos', ]; const styledHeaderCells = headerCells.map((cell) => ({ text: cell, style: 'tableHeader', margin: [0, 2, 0, 2], fontSize: 7, })); rowsConceptos.push(styledHeaderCells); for (const concepto of conceptos) { const id = concepto.getAttribute('NoIdentificacion'); const impuestosContent = (0, generic_cfdi_concepto_impuestos_content_1.default)(concepto, catalogs, primaryColor, bgGrayColor); rowsConceptos.push([ { table: { widths: ['7%', '7%', '*', '10%', '7%', '10%', '10%', '10%'], body: [ [ { text: id === '' ? '---' : id, fontSize: 7 }, { text: concepto.getAttribute('ClaveUnidad'), fontSize: 7 }, { text: concepto.getAttribute('Descripcion'), fontSize: 7 }, { text: (0, currency_1.formatCurrency)(concepto.getAttribute('ValorUnitario')), alignment: 'right', fontSize: 7, }, { text: concepto.getAttribute('Cantidad'), alignment: 'center', fontSize: 7 }, { text: (0, currency_1.formatCurrency)(concepto.getAttribute('Importe')), alignment: 'right', fontSize: 7 }, { text: (0, currency_1.formatCurrency)(concepto.getAttribute('Descuento')), alignment: 'right', fontSize: 7, }, { text: impuestosContent.table.body[0][0].text, fontSize: 7, color: '#666666' }, ], ], }, layout: 'conceptosLayout', colSpan: 8, border: [false, false, false, true], }, ]); } return { table: { widths: ['7%', '7%', '*', '10%', '7%', '10%', '10%', '10%'], body: rowsConceptos, dontBreakRows: true, headerRows: 1, }, layout: 'conceptosLayout', }; }; exports.default = genericCfdiConceptosContent;