UNPKG

@nodecfdi/cfdi-to-pdf

Version:

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

1,571 lines (1,556 loc) 87.4 kB
import { CfdiData, RetencionesData, break_characters_default, formatCurrency, toCurrency, toNumber } from "../chunk-KVWNMCPD.js"; // templates/abstract_generic_translator.ts var AbstractGenericTraslator = class { genericSpace(spaces = 1) { const result = Array.from({ length: spaces }); return { text: result.join("\n") }; } }; // templates/generic_cfdi_translator.ts import { XmlNodes as XmlNodes2 } from "@nodecfdi/cfdi-core"; // templates/complements/donat11_complement.ts var useDonat11Complement = (donat11, currentContent, primaryColor, bgGrayColor) => { currentContent.push({ table: { widths: ["*", "*", "*"], body: [ [ { text: "Donatarias", style: ["tableSubtitleHeader"], color: primaryColor, colSpan: 3 }, "", "" ], [ { fillColor: bgGrayColor, text: [ { text: "Version: ", color: primaryColor, bold: true }, { text: donat11.getAttribute("version") } ] }, { fillColor: bgGrayColor, text: [ { text: "No. Autorizaci\xF3n: ", color: primaryColor, bold: true }, { text: donat11.getAttribute("noAutorizacion") } ], alignment: "center" }, { fillColor: bgGrayColor, text: [ { text: "Fecha Autorizaci\xF3n: ", color: primaryColor, bold: true }, { text: donat11.getAttribute("fechaAutorizacion") } ], alignment: "right" } ], [ { fillColor: bgGrayColor, text: [{ text: "Leyenda: ", color: primaryColor, bold: true }, { text: donat11.getAttribute("leyenda") }], colSpan: 3 }, "", "" ], [ { fillColor: bgGrayColor, text: "", border: [false, false, false, true] }, { fillColor: bgGrayColor, text: "", border: [false, false, false, true] }, { fillColor: bgGrayColor, text: "", border: [false, false, false, true] } ] ] }, layout: "tableLayout" }); }; var donat11_complement_default = useDonat11Complement; // templates/complements/pago10_complement.ts var fillDoctoRelacionados = (doctoRelacionados, primaryColor) => { const rowsDoctoRelacionados = [ [ { text: "Documentos Relacionados", colSpan: 8, style: ["tableSubtitleHeader"], color: primaryColor }, "", "", "", "", "", "", "" ] ]; const headerCells = [ "UUID", "M\xE9todo 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"), formatCurrency(doctoRelacionado.getAttribute("ImpSaldoAnt")), formatCurrency(doctoRelacionado.getAttribute("ImpPagado")), 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" }; }; var 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\xF3n 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: catalogs.cfdi40FormasPago.findAndReturnTexto(pago.getAttribute("FormaDePagoP")), 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: 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" ); } } }; var pago10_complement_default = usePago10Complement; // templates/complements/pago20_complement.ts var generateRelatedDocsContent = (doctoRelacionados, primaryColor) => { const relatedDocsCells = doctoRelacionados.map((doc) => { return [ doc.getAttribute("IdDocumento"), `${doc.getAttribute("Serie")} ${doc.getAttribute("Folio")}`, doc.getAttribute("MonedaDR"), doc.getAttribute("EquivalenciaDR"), doc.getAttribute("NumParcialidad"), { text: formatCurrency(doc.getAttribute("ImpSaldoAnt")), alignment: "right" }, { text: formatCurrency(doc.getAttribute("ImpPagado")), alignment: "right" }, { text: formatCurrency(doc.getAttribute("ImpSaldoInsoluto")), alignment: "right" } ]; }); relatedDocsCells.unshift( [ "UUID", "Serie | Folio", "Moneda", "Tipo de Cambio", "Num. Parcialidad", "Importe Saldo Anterior", "Importe Pagado", "Importe Saldo Insoluto" ].map((cell) => { return { text: cell, border: [false, false, false, true] }; }) ); relatedDocsCells.unshift([ { text: "DOCUMENTOS RELACIONADOS", color: primaryColor, colSpan: 8, alignment: "center", border: [false, false, false, true] }, {}, {}, {}, {}, {}, {}, {} ]); return relatedDocsCells; }; var fillTableTotales = (totales, primaryColor, bgGrayColor) => { return { table: { widths: ["*", "*", "*", "*", "*", "*"], body: [ [{ text: "Totales", color: primaryColor, bold: true, colSpan: 6 }, "", "", "", "", ""], [ { table: { widths: ["*", "*", "*", "*"], body: [ [ { text: "Monto Total Pagos:", color: primaryColor }, { text: formatCurrency(totales.getAttribute("MontoTotalPagos")), alignment: "center" }, { text: "Traslados Base IVA Exento:", color: primaryColor }, { text: formatCurrency(totales.getAttribute("TotalTrasladosBaseIVAExento")), alignment: "center" } ] ], dontBreakRows: true }, layout: "tableLayout", colSpan: 6, fillColor: bgGrayColor }, "", "", "", "", "" ], [ { text: "Traslados Base IVA 16:", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalTrasladosBaseIVA16")), alignment: "center", fillColor: bgGrayColor }, { text: "Traslados Base IVA 8:", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalTrasladosBaseIVA8")), alignment: "center", fillColor: bgGrayColor }, { text: "Traslados Base IVA 0:", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalTrasladosBaseIVA0")), alignment: "center", fillColor: bgGrayColor } ], [ { text: "Traslados IVA 16:", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalTrasladosImpuestoIVA16")), alignment: "center", fillColor: bgGrayColor }, { text: "Traslados IVA 8", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalTrasladosImpuestoIVA8")), alignment: "center", fillColor: bgGrayColor }, { text: "Traslados IVA 0", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalTrasladosImpuestoIVA0")), alignment: "center", fillColor: bgGrayColor } ], [ { text: "Retenciones IVA", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalRetencionesIVA")), alignment: "center", fillColor: bgGrayColor }, { text: "Retenciones ISR", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalRetencionesISR")), alignment: "center", fillColor: bgGrayColor }, { text: "Retenciones IEPS", color: primaryColor, fillColor: bgGrayColor }, { text: formatCurrency(totales.getAttribute("TotalRetencionesIEPS")), alignment: "center", fillColor: bgGrayColor } ] ], dontBreakRows: true }, layout: "tableLayout", border: [false, false, false, true] }; }; var usePago20Complement = (pago20, currentContent, catalogs, primaryColor, bgGrayColor) => { const totales = pago20.searchNode("pago20:Totales"); const pagos = pago20.searchNodes("pago20:Pago"); if (pagos.length > 0 && totales !== void 0) { currentContent.push( { table: { widths: ["*"], body: [ [ { text: "Complemento pago", style: "tableSubtitleHeader", color: primaryColor, border: [false, true, false, false] } ], [ { table: { widths: ["*"], body: pagos.flatMap((pago) => { const doctoRelacionados = pago.searchNodes("pago20:DoctoRelacionado"); const tablePagosBody = []; tablePagosBody.push( [{ text: "", border: [false, true, false, false] }], [ { table: { widths: ["12%", "16%", "12%", "*", "12%", "18%"], body: [ [ { text: "Fecha pago:", color: primaryColor, alignment: "center" }, { text: pago.getAttribute("FechaPago"), alignment: "center" }, { text: "Forma de pago:", color: primaryColor, alignment: "center" }, { text: catalogs.cfdi40FormasPago.findAndReturnTexto(pago.getAttribute("FormaDePagoP")), alignment: "center" }, { text: "Monto:", color: primaryColor, alignment: "center" }, { text: formatCurrency(pago.getAttribute("Monto")), alignment: "center" } ], [ { text: "Moneda:", color: primaryColor, alignment: "center" }, { text: pago.getAttribute("MonedaP"), alignment: "center" }, { text: "Tipo cambio:", color: primaryColor, alignment: "center" }, { text: pago.getAttribute("TipoCambioP"), alignment: "center" }, { text: pago.hasAttribute("NumOperacion") ? "Num. Operaci\xF3n:" : "", color: primaryColor, alignment: "center" }, { text: pago.hasAttribute("NumOperacion") ? pago.getAttribute("NumOperacion") : "", alignment: "center" } ], ...pago.hasAttribute("NomBancoOrdExt") ? [ [ { text: [ { text: "Nombre Banco Ordenante: ", color: primaryColor }, { text: pago.getAttribute("NomBancoOrdExt") } ], alignment: "center", colSpan: 6 }, "", "", "", "", "" ] ] : [], ...pago.hasAttribute("TipoCadPago") ? [ [ { table: { widths: ["*", "*"], body: [ [ { text: [ { text: "Tipo cadena pago: ", color: primaryColor }, { text: catalogs.pagosTiposCadenaPago.findAndReturnTexto( pago.getAttribute("TipoCadPago") ) } ] }, { text: [ { text: "Cadena pago", color: primaryColor }, { text: break_characters_default(pago.getAttribute("CadPago")) } ] } ], [ { text: "Certificado Pago", color: primaryColor }, { text: "Sello Pago", color: primaryColor } ], [ { text: break_characters_default(pago.getAttribute("CertPago")) }, { text: break_characters_default(pago.getAttribute("SelloPago")) } ] ], dontBreaksRows: true }, layout: "tableLayout", colSpan: 6 }, "", "", "", "", "" ] ] : [], [ { style: "tableSmall", table: { widths: ["32%", "8%", "8%", "8%", "8%", "12%", "12%", "12%"], body: generateRelatedDocsContent(doctoRelacionados, primaryColor), dontBreakRows: true }, layout: "conceptosLayout", fillColor: bgGrayColor, colSpan: 6 }, "", "", "", "", "" ] ] }, layout: "tableLayout" } ], [{ text: "", border: [false, false, false, true] }] ); return tablePagosBody; }), dontBreakRows: true }, layout: "conceptosLayout" } ], [fillTableTotales(totales, primaryColor, bgGrayColor)] ] }, layout: "tableLayout" }, "\n", "\n" ); } }; var pago20_complement_default = usePago20Complement; // templates/sections/generic_cfdi_concepto_impuestos_content.ts var generateImpuestosContentTable = (traslados, retenciones, catalogs, primaryColor, bgGrayColor) => { const impuestosTableBody = []; for (const traslado of traslados) { const baseCells = []; baseCells.push( { text: "Traslado:", color: primaryColor, bold: true }, { text: catalogs.cfdi40Impuestos.findAndReturnTexto(traslado.getAttribute("Impuesto")) }, { text: "Base:", color: primaryColor, bold: true }, { text: formatCurrency(traslado.getAttribute("Base")), alignment: "right" } ); const factor = traslado.getAttribute("TipoFactor"); if (factor === "Exento") { baseCells.push({ text: "Factor:", color: primaryColor, bold: true }, { text: factor }, "", ""); } else { const importe = traslado.getAttribute("Importe"); baseCells.push( { text: "Tasa:", color: primaryColor, bold: true }, { text: traslado.getAttribute("TasaOCuota") }, { text: "Importe:", color: primaryColor, bold: true }, { text: formatCurrency(importe === "" ? "0" : importe) } ); } impuestosTableBody.push(baseCells); } for (const retencion of retenciones) { const baseCells = []; baseCells.push( { text: "Retenci\xF3n:", color: primaryColor, bold: true }, { text: catalogs.cfdi40Impuestos.findAndReturnTexto(retencion.getAttribute("Impuesto")) }, { text: "Base:", color: primaryColor, bold: true }, { text: formatCurrency(retencion.getAttribute("Base")), alignment: "right" } ); const factor = retencion.getAttribute("TipoFactor"); if (factor === "Exento") { baseCells.push({ text: "Factor:", color: primaryColor, bold: true }, { text: factor }, "", ""); } else { const importe = retencion.getAttribute("Importe"); baseCells.push( { text: "Tasa:", color: primaryColor, bold: true }, { text: retencion.getAttribute("TasaOCuota") }, { text: "Importe:", color: primaryColor, bold: true }, { text: formatCurrency(importe === "" ? "0" : importe) } ); impuestosTableBody.push(baseCells); } } return { table: { widths: ["auto", "auto", "auto", "auto", "auto", "auto", "auto", "auto"], body: impuestosTableBody }, fillColor: bgGrayColor, layout: "conceptosLayout" }; }; var genericCfdiConceptoImpuestosContent = (concepto, catalogs, primaryColor, bgGrayColor) => { const impuestoConceptoTable = []; const predial = concepto.searchNode("cfdi:CuentaPredial"); const codigoSat = concepto.getAttribute("ClaveProdServ"); const objetoImp = concepto.getAttribute("ObjetoImp"); const extraDetails = [ "", { text: [ { text: "Clave Producto/Servicio: ", color: primaryColor, bold: true }, { text: codigoSat } ] }, { text: objetoImp === "" ? "" : [ { text: "Objeto Impuesto: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40ObjetosImpuestos.findAndReturnTexto(objetoImp) } ] }, { text: predial === void 0 ? "" : [{ text: "Cuenta Predial: ", color: primaryColor, bold: true }, { text: predial.getAttribute("Numero") }] } ]; impuestoConceptoTable.push(extraDetails); const traslados = concepto.searchNodes("cfdi:Impuestos", "cfdi:Traslados", "cfdi:Traslado"); const retenciones = concepto.searchNodes("cfdi:Impuestos", "cfdi:Retenciones", "cfdi:Retencion"); if (traslados.length > 0 || retenciones.length > 0) { impuestoConceptoTable.push([ { ...generateImpuestosContentTable(traslados, retenciones, catalogs, primaryColor, bgGrayColor), colSpan: 4 }, "", "", "" ]); } return { table: { widths: ["*", "auto", "auto", "*"], body: impuestoConceptoTable }, layout: "conceptosLayout" }; }; var generic_cfdi_concepto_impuestos_content_default = genericCfdiConceptoImpuestosContent; // templates/sections/generic_cfdi_conceptos_contents.ts var genericCfdiConceptosContent = (comprobante, catalogs, primaryColor, bgGrayColor) => { const conceptos = comprobante.searchNodes("cfdi:Conceptos", "cfdi:Concepto"); const rowsConceptos = []; const headerCells = [ "No. Identificaci\xF3n", "Clave Unidad", "Descripci\xF3n", "Valor Unitario", "Cantidad", { text: "Importe", alignment: "center" }, "Descuento" ]; const styledHeaderCells = headerCells.map((cell) => ({ text: cell, style: "tableHeader", fillColor: primaryColor, margin: [0, 3, 0, 3] })); rowsConceptos.push(styledHeaderCells); for (const concepto of conceptos) { const id = concepto.getAttribute("NoIdentificacion"); rowsConceptos.push([ { table: { widths: ["11%", "10%", "*", "11%", "11%", "11%", "11%"], body: [ [ { text: id === "" ? "---" : id }, { text: concepto.getAttribute("ClaveUnidad") }, { text: concepto.getAttribute("Descripcion") }, { text: formatCurrency(concepto.getAttribute("ValorUnitario")), alignment: "right" }, { text: concepto.getAttribute("Cantidad"), alignment: "center" }, { text: formatCurrency(concepto.getAttribute("Importe")), alignment: "right" }, { text: formatCurrency(concepto.getAttribute("Descuento")), alignment: "right" } ], [ { ...generic_cfdi_concepto_impuestos_content_default(concepto, catalogs, primaryColor, bgGrayColor), colSpan: 7 } ] ] }, layout: "conceptosLayout", colSpan: 7, border: [false, false, false, true] } ]); } return { table: { widths: ["11%", "10%", "*", "11%", "11%", "11%", "11%"], body: rowsConceptos, dontBreakRows: true, headerRows: 1 }, layout: "conceptosLayout" }; }; var generic_cfdi_conceptos_contents_default = genericCfdiConceptosContent; // templates/sections/generic_cfdi_details_info_content.ts var 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\xE9todo de Pago: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40MetodosPago.findAndReturnEtiqueta(comprobante.getAttribute("MetodoPago")) } ], alignment: "center" }, { text: [ { text: "Forma de Pago: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40FormasPago.findAndReturnEtiqueta(comprobante.getAttribute("FormaPago")) } ], alignment: "center" } ]; if (moneda === "MXN") { comprobanteInfo.push( { text: [{ text: "Moneda: ", color: primaryColor, bold: true }, { text: moneda }], colSpan: 2, alignment: "center" }, "" ); } else { comprobanteInfo.push( { text: [{ text: "Moneda: ", color: primaryColor, bold: true }, { text: moneda }], alignment: "center" }, { text: [ { text: "Tipo cambio: ", color: primaryColor, bold: true }, { text: comprobante.getAttribute("TipoCambio") } ], alignment: "center" } ); } detailsInfo.push(comprobanteInfo); return { table: { widths: ["38%", "38%", "12%", "12%"], body: detailsInfo, dontBreakRows: true }, layout: "tableLayout" }; }; var generic_cfdi_details_info_content_default = genericCfdiDetailsInfoContent; // templates/sections/generic_cfdi_informacion_global_content.ts var genericCfdiInformacionGlobalContent = (informacionGlobal, catalogs, primaryColor, bgGrayColor) => { return { table: { widths: ["*", "*", "*"], body: [ [ { text: "Informaci\xF3n Global", style: ["tableSubtitleHeader"], color: primaryColor, colSpan: 3 }, "", "" ], [ { fillColor: bgGrayColor, text: [ { text: "Periodicidad: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40Periodicidades.findAndReturnEtiqueta( informacionGlobal.getAttribute("Periodicidad") ) } ] }, { fillColor: bgGrayColor, text: [ { text: "Meses: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40Meses.findAndReturnEtiqueta(informacionGlobal.getAttribute("Meses")) } ] }, { fillColor: bgGrayColor, text: [{ text: "A\xF1o: ", color: primaryColor, bold: true }, { text: informacionGlobal.getAttribute("A\xF1o") }] } ], [ { fillColor: bgGrayColor, text: "", border: [false, false, false, true] }, { fillColor: bgGrayColor, text: "", border: [false, false, false, true] }, { fillColor: bgGrayColor, text: "", border: [false, false, false, true] } ] ] }, layout: "tableLayout" }; }; var generic_cfdi_informacion_global_content_default = genericCfdiInformacionGlobalContent; // templates/sections/generic_cfdi_relacionados_content.ts import { XmlNodes } from "@nodecfdi/cfdi-core"; var genericCfdiRelacionadosContent = (relacionados, catalogs, primaryColor, bgGrayColor) => { const relatedInfoAndImport = []; const pushElementFromRelatedNode = (relatedNode) => { const uuidsArray = relatedNode.searchNodes("cfdi:CfdiRelacionado").map((relacionado) => { return relacionado.getAttribute("UUID"); }); const tipoRelacion = catalogs.cfdi40TiposRelaciones.findAndReturnEtiqueta(relatedNode.getAttribute("TipoRelacion")); relatedInfoAndImport.push({ tipoRelacion, uuids: uuidsArray }); }; if (relacionados instanceof XmlNodes) { for (const relacionadosNode of relacionados) { pushElementFromRelatedNode(relacionadosNode); } } else { pushElementFromRelatedNode(relacionados); } return { table: { widths: ["auto", "5%", "*"], body: [ [ { text: "CFDI relacionados", colSpan: 3, alignment: "left", color: primaryColor, style: "tableSubtitleHeader" }, "", "" ], [ { text: "Tipo de relaci\xF3n", alignment: "left", fillColor: bgGrayColor, color: primaryColor, bold: true }, { text: "", fillColor: bgGrayColor }, { text: "UUID", alignment: "left", fillColor: bgGrayColor, color: primaryColor, bold: true } ], ...relatedInfoAndImport.map((related) => { return [ { text: related.tipoRelacion, alignment: "left", fillColor: bgGrayColor }, { text: "", fillColor: bgGrayColor }, { text: related.uuids.join(" | "), alignment: "left", fillColor: bgGrayColor } ]; }), [ { text: "", colSpan: 3, border: [false, true, false, false] }, "", "" ] ] }, layout: "tableLayout" }; }; var generic_cfdi_relacionados_content_default = genericCfdiRelacionadosContent; // templates/complements/implocal10_complement.ts var useImplocal10Complement = (impLocal10, primaryColor, bgGrayColor, tableTotales, totalesContent) => { const totalesSubContent = []; const totalRetencionesLocales = impLocal10.getAttribute("TotaldeRetenciones"); const totalTrasladosLocales = impLocal10.getAttribute("TotaldeTraslados"); if (toNumber(totalTrasladosLocales) > 0) { tableTotales.push([ { text: "Traslados Locales", alignment: "right" }, { text: "$", color: primaryColor, alignment: "center" }, { text: formatCurrency(totalTrasladosLocales, "code"), alignment: "right" } ]); } if (toNumber(totalRetencionesLocales) > 0) { tableTotales.push([ { text: "Retenciones Locales", alignment: "right" }, { text: "$", color: primaryColor, alignment: "center" }, { text: `- ${formatCurrency(totalRetencionesLocales, "code")}`, alignment: "right" } ]); } const trasladosLocales = impLocal10.searchNodes("implocal:TrasladosLocales"); const retencionesLocales = impLocal10.searchNodes("implocal:RetencionesLocales"); const retencionesLocalesTable = { table: { widths: ["40%", "20%", "auto"], body: [ [ { text: "Impuestos Locales Retenidos", style: ["tableSubtitleHeader"], color: primaryColor, colSpan: 3 }, "", "" ], ...retencionesLocales.map((retencionLocal) => { return [ { text: retencionLocal.getAttribute("ImpLocRetenido"), fillColor: bgGrayColor }, { text: [ { text: "Tasa: " }, { text: `${(Number(retencionLocal.getAttribute("TasadeRetencion")) * 1).toString()} %` } ], fillColor: bgGrayColor }, { text: [{ text: "Importe: " }, { text: formatCurrency(retencionLocal.getAttribute("Importe")) }], alignment: "right", fillColor: bgGrayColor } ]; }) ], dontBreakRows: true }, layout: "tableLayout" }; const trasladosLocalesTable = { table: { widths: ["40%", "20%", "auto"], body: [ [ { text: "Impuestos Locales Trasladados", style: ["tableSubtitleHeader"], color: primaryColor, colSpan: 3 }, "", "" ], ...trasladosLocales.map((trasladoLocal) => { return [ { text: trasladoLocal.getAttribute("ImpLocTrasladado"), fillColor: bgGrayColor }, { text: [ { text: "Tasa: " }, { text: `${(Number(trasladoLocal.getAttribute("TasadeTraslado")) * 1).toString()} %` } ], fillColor: bgGrayColor }, { text: [{ text: "Importe: " }, { text: formatCurrency(trasladoLocal.getAttribute("Importe")) }], alignment: "right", fillColor: bgGrayColor } ]; }) ], dontBreakRows: true }, layout: "tableLayout" }; if (trasladosLocales.length === 0 && retencionesLocales.length === 0) { totalesSubContent.push("", ""); } if (trasladosLocales.length === 0 && retencionesLocales.length > 0) { totalesSubContent.push( { ...retencionesLocalesTable, colSpan: 2 }, "" ); } if (trasladosLocales.length > 0 && retencionesLocales.length === 0) { totalesSubContent.push( { ...trasladosLocalesTable, colSpan: 2 }, "" ); } if (trasladosLocales.length > 0 && retencionesLocales.length > 0) { totalesSubContent.push(trasladosLocalesTable, retencionesLocalesTable); } totalesSubContent.push({ table: { widths: ["*", "10%", "auto"], body: tableTotales, dontBreakRows: true }, layout: "tableLayout" }); totalesContent.push(totalesSubContent); }; var implocal10_complement_default = useImplocal10Complement; // templates/sections/generic_cfdi_totales_content.ts var fillCfdiImpuestos = (comprobante, catalogs, primaryColor, bgGrayColor, totalesSubContent) => { const elementImpuestos = "cfdi:Impuestos"; const traslados = comprobante.searchNodes(elementImpuestos, "cfdi:Traslados", "cfdi:Traslado").filter((value) => value.getAttribute("TipoFactor") !== "Exento" && toNumber(value.getAttribute("TasaOCuota")) > 0); const retenciones = comprobante.searchNodes(elementImpuestos, "cfdi:Retenciones", "cfdi:Retencion"); const retencionesTable = { table: { widths: ["40%", "auto"], body: [ [ { text: "Impuestos Retenidos", style: ["tableSubtitleHeader"], color: primaryColor, colSpan: 2 }, "" ], ...retenciones.map((retencion) => { return [ { text: catalogs.cfdi40Impuestos.findAndReturnTexto(retencion.getAttribute("Impuesto")), fillColor: bgGrayColor }, { text: [{ text: "Importe: " }, { text: formatCurrency(retencion.getAttribute("Importe")) }], alignment: "right", fillColor: bgGrayColor } ]; }) ], dontBreakRows: true }, layout: "tableLayout" }; const trasladosTable = { table: { widths: ["10%", "15%", "20%", "18%", "auto"], body: [ [ { text: "Impuestos Trasladados", style: ["tableSubtitleHeader"], color: primaryColor, colSpan: 5 }, "", "", "", "" ], ...traslados.map((traslado) => { const isTasa = traslado.getAttribute("TipoFactor") === "Tasa"; const tasaOCuota = traslado.getAttribute("TasaOCuota"); return [ { text: catalogs.cfdi40Impuestos.findAndReturnTexto(traslado.getAttribute("Impuesto")), fillColor: bgGrayColor }, { text: traslado.getAttribute("TipoFactor"), alignment: "center", fillColor: bgGrayColor }, { text: isTasa ? `${(Number(tasaOCuota) * 100).toString()} %` : tasaOCuota, alignment: "center", fillColor: bgGrayColor }, { text: "Importe: ", alignment: "left", fillColor: bgGrayColor }, { text: formatCurrency(traslado.getAttribute("Importe")), alignment: "right", fillColor: bgGrayColor } ]; }) ], dontBreakRows: true }, layout: "tableLayout" }; if (traslados.length === 0 && retenciones.length === 0) { totalesSubContent.push("", ""); } if (traslados.length === 0 && retenciones.length > 0) { totalesSubContent.push( { ...retencionesTable, colSpan: 2 }, "" ); } if (traslados.length > 0 && retenciones.length === 0) { totalesSubContent.push( { ...trasladosTable, colSpan: 2 }, "" ); } if (traslados.length > 0 && retenciones.length > 0) { totalesSubContent.push(trasladosTable, retencionesTable); } }; var genericCfdiTotalesContent = (comprobante, catalogs, primaryColor, bgGrayColor) => { const elementImpuestos = "cfdi:Impuestos"; const totalesContent = []; const totalImpuestosTrasladados = comprobante.searchAttribute(elementImpuestos, "TotalImpuestosTrasladados"); const totalImpuestosRetenidos = comprobante.searchAttribute(elementImpuestos, "TotalImpuestosRetenidos"); const totalesSubContent = []; fillCfdiImpuestos(comprobante, catalogs, primaryColor, bgGrayColor, totalesSubContent); const tableTotales = [ [ { text: "Subtotal", alignment: "right" }, { text: "$", color: primaryColor, alignment: "center", bold: true }, { text: formatCurrency(comprobante.getAttribute("SubTotal"), "code"), alignment: "right" } ], [ { text: "Descuento", alignment: "right" }, { text: "$", color: primaryColor, alignment: "center", bold: true }, { text: `- ${formatCurrency(comprobante.getAttribute("Descuento"), "code")}`, alignment: "right" } ], [ { text: "Traslados", alignment: "right" }, { text: "$", color: primaryColor, alignment: "center", bold: true }, { text: formatCurrency(totalImpuestosTrasladados, "code"), alignment: "right" } ], [ { text: "Retenciones", alignment: "right" }, { text: "$", color: primaryColor, alignment: "center", bold: true }, { text: `- ${formatCurrency(totalImpuestosRetenidos, "code")}`, alignment: "right" } ] ]; const impLocal10 = comprobante.searchNode("cfdi:Complemento", "implocal:ImpuestosLocales"); if (impLocal10) { totalesSubContent.push(""); totalesContent.push(totalesSubContent); implocal10_complement_default(impLocal10, primaryColor, bgGrayColor, tableTotales, totalesContent); } else { totalesSubContent.push({ table: { widths: ["*", "10%", "auto"], body: tableTotales, dontBreakRows: true }, layout: "tableLayout" }); totalesContent.push(totalesSubContent); } totalesContent.push([ "", { style: "tableHeader", text: `Total ${comprobante.getAttribute("Moneda")} ${formatCurrency(comprobante.getAttribute("Total"))}`, alignment: "right", margin: [2, 5, 2, 2], fillColor: primaryColor, fontSize: 14, colSpan: 2 }, "" ]); return { table: { widths: ["38%", "28%", "34%"], body: totalesContent, dontBreakRows: true }, layout: "tableLayout" }; }; var generic_cfdi_totales_content_default = genericCfdiTotalesContent; // templates/sections/generic_emisor_content.ts var genericEmisorContent = (data, catalogs, primaryColor, bgGrayColor) => { const emisor = data.emisor(); const additionalEmisorData = []; let razonSocial = ""; let rfc = ""; let numCertificado = ""; let regimenFiscal = ""; let curp; if (data instanceof CfdiData) { razonSocial = emisor.getAttribute("Nombre"); rfc = emisor.getAttribute("Rfc"); numCertificado = data.comprobante().getAttribute("NoCertificado"); regimenFiscal = emisor.getAttribute("RegimenFiscal"); } else if (data instanceof RetencionesData) { const retVersion = data.retenciones().getAttribute("Version"); razonSocial = emisor.getAttribute("NomDenRazSocE"); rfc = emisor.getAttribute(retVersion === "1.0" ? "RFCEmisor" : "RfcE"); numCertificado = data.retenciones().getAttribute("NumCert"); regimenFiscal = emisor.getAttribute("RegimenFiscalE"); curp = emisor.getAttribute("CURPE"); } if (regimenFiscal !== "") { additionalEmisorData.push([ { text: [ { text: "Regimen Fiscal: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40RegimenesFiscales.findAndReturnEtiqueta(regimenFiscal) } ] } ]); } additionalEmisorData.push([ { text: [{ text: "N\xFAmero de certificado: ", color: primaryColor, bold: true }, { text: numCertificado }] } ]); if (curp && curp !== "") { additionalEmisorData.push([ { text: [{ text: "CURP: ", color: primaryColor, bold: true }, { text: curp }] } ]); } return { table: { widths: ["49.5%", "*", "49.5%"], body: [ [ { text: "Datos del emisor", style: ["tableSubtitleHeader"], color: primaryColor }, "", { text: "Datos adicionales emisor", style: ["tableSubtitleHeader"], color: primaryColor } ], [ { fillColor: bgGrayColor, table: { widths: ["*"], body: [ [{ text: razonSocial, style: ["subHeader"], color: primaryColor }], [{ text: [{ text: "RFC: ", color: primaryColor, bold: true }, { text: rfc }] }] ] }, layout: "tableLayout", border: [false, false, false, true] }, "", { fillColor: bgGrayColor, table: { widths: ["*"], body: additionalEmisorData }, layout: "tableLayout", border: [false, false, false, true] } ] ] }, layout: "tableLayout" }; }; var generic_emisor_content_default = genericEmisorContent; // templates/sections/generic_footer.ts var genericFooter = (currentPage, pageCount, data) => { const uuid = data.timbreFiscalDigital().getAttribute("UUID"); let version = ""; if (data instanceof CfdiData) { version = data.comprobante().getAttribute("Version"); } else if (data instanceof RetencionesData) { version = data.retenciones().getAttribute("Version"); } return [ { text: data.legendFooter().replace("{version}", version), style: { fontSize: 7 }, alignment: "center" }, { text: `UUID: ${uuid} - P\xE1gina ${currentPage} de ${pageCount}`, style: { fontSize: 7 }, alignment: "center" } ]; }; var generic_footer_default = genericFooter; // templates/sections/generic_receptor_content.ts var genericCfdiReceptorContent = (data, primaryColor, catalogs, receptorData, additionalReceptorData) => { const receptor = data.receptor(); receptorData.push( [{ text: receptor.getAttribute("Nombre"), style: ["subHeader"], color: primaryColor }], [ { text: [{ text: "RFC: ", color: primaryColor, bold: true }, { text: receptor.getAttribute("Rfc") }] } ] ); if (receptor.hasAttribute("RegimenFiscalReceptor")) { receptorData.push([ { text: [ { text: "R\xE9gimen fiscal: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40RegimenesFiscales.findAndReturnEtiqueta( receptor.getAttribute("RegimenFiscalReceptor") ) } ] } ]); } if (receptor.hasAttribute("DomicilioFiscalReceptor")) { receptorData.push([ { text: [ { text: "Domicilio fiscal: ", color: primaryColor, bold: true }, { text: receptor.getAttribute("DomicilioFiscalReceptor") } ] } ]); } additionalReceptorData.push([ { text: [ { text: "Uso del CFDI: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40UsosCfdi.findAndReturnTexto(receptor.getAttribute("UsoCFDI")) } ] } ]); if (data.comprobante().hasAttribute("Exportacion")) { additionalReceptorData.push([ { text: [ { text: "Exportaci\xF3n: ", color: primaryColor, bold: true }, { text: catalogs.cfdi40Exportaciones.findAndReturnTexto(data.comprobante().getAttribute("Exportacion")) } ] } ]); } if (receptor.hasAttribute("ResidenciaFiscal")) { additionalReceptorData.push([ { text: [ { text: "Residencia Fiscal: ", color: primaryColor, bold: true }, { text: receptor.getAttribute("ResidenciaFiscal") } ] } ]); } if (receptor.hasAttribute("NumRegIdTrib")) { additionalReceptorData.push([ { text: [ { text: "N\xFAmero Id Trib.: ", color: primaryColor, bold: true }, { text: receptor.getAttribute("NumRegIdTrib") } ] } ]); } }; var genericRetencionesReceptorContent = (data, primaryColor, receptorData, additionalReceptorData) => { const receptor = data.receptor(); const version