UNPKG

@disruptive-learning/cfdi-to-pdf

Version:

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

75 lines (74 loc) 3.08 kB
import genericCfdiConceptoImpuestosContent from '#src/templates/sections/generic_cfdi_concepto_impuestos_content'; import { formatCurrency } from '#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 = genericCfdiConceptoImpuestosContent(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: formatCurrency(concepto.getAttribute('ValorUnitario')), alignment: 'right', fontSize: 7, }, { text: concepto.getAttribute('Cantidad'), alignment: 'center', fontSize: 7 }, { text: formatCurrency(concepto.getAttribute('Importe')), alignment: 'right', fontSize: 7 }, { text: 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', }; }; export default genericCfdiConceptosContent;