@disruptive-learning/cfdi-to-pdf
Version:
Librería para crear un pdf basado en un XML CFDI o Retenciones
122 lines (121 loc) • 4.93 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const catalogs_source_1 = require("#src/catalogs/catalogs_source");
const cfdi_data_1 = __importDefault(require("#src/cfdi_data"));
const retenciones_data_1 = __importDefault(require("#src/retenciones_data"));
const genericTopContent = (data, catalogs, primaryColor) => {
const logo = data.logo();
const tfd = data.timbreFiscalDigital();
const contentWidths = [];
const bodyContent = [];
let title = '';
let sectionLogoMargin = [0, 8, 0, 8];
let sectionLogoFit = [180, 80];
if (data instanceof cfdi_data_1.default) {
contentWidths.push('10%', '*', 'auto', '3%', '42%');
const comprobante = data.comprobante();
const version = comprobante.getAttribute('Version');
const tipoComprobante = comprobante.getAttribute('TipoDeComprobante');
title = `CFDI ${version} de ${(0, catalogs_source_1.getValueOfCatalog)('cfdi40TiposComprobantes', tipoComprobante, catalogs)}`;
bodyContent.push([
{ text: 'Serie', style: ['tableHeader'], color: '#000000', bold: true },
{ text: 'Folio', style: ['tableHeader'], color: '#000000', bold: true },
{ text: 'Lugar de emisión', style: ['tableHeader'], color: '#000000', bold: true },
'',
{ text: 'Fecha y hora de emisión', style: ['tableHeader'], color: '#000000', bold: true },
], [
{ text: comprobante.getAttribute('Serie') },
{ text: comprobante.getAttribute('Folio') },
{ text: comprobante.getAttribute('LugarExpedicion') },
'',
{ text: comprobante.getAttribute('Fecha') },
], [
{ text: 'Folio fiscal', style: ['tableHeader'], color: '#000000', bold: true, colSpan: 3 },
'',
'',
'',
{ text: 'Fecha y hora de certificación', style: ['tableHeader'], color: '#000000', bold: true },
], [
{ text: tfd.getAttribute('UUID'), colSpan: 3 },
'',
'',
'',
{ text: tfd.getAttribute('FechaTimbrado') },
]);
}
else if (data instanceof retenciones_data_1.default) {
contentWidths.push('*', '3%', '42%');
sectionLogoMargin = [0, 10, 0, 10];
sectionLogoFit = [150, 70];
const retenciones = data.retenciones();
const version = retenciones.getAttribute('Version');
const cveRetencion = retenciones.getAttribute('CveRetenc');
title = `CFDI Retenciones e Información de Pagos ${version}`;
bodyContent.push([
{ text: 'Folio Interno', style: ['tableHeader'], color: primaryColor },
'',
{ text: 'Fecha y hora de emisión', style: ['tableHeader'], color: primaryColor },
], [
{ text: retenciones.getAttribute('FolioInt') },
'',
{ text: retenciones.getAttribute('FechaExp') },
], [
{ text: 'Folio fiscal', style: ['tableHeader'], color: primaryColor },
'',
{ text: 'Fecha y hora de certificación', style: ['tableHeader'], color: primaryColor },
], [{ text: tfd.getAttribute('UUID') }, '', { text: tfd.getAttribute('FechaTimbrado') }], [{ text: 'Clave', style: ['tableHeader'], color: primaryColor, colSpan: 3 }, '', ''], [
{
text: (0, catalogs_source_1.getKeyValueOfCatalog)('retenciones20ClavesRetencion', cveRetencion, catalogs),
colSpan: 3,
},
'',
'',
]);
}
const logoSection = logo
? {
rowSpan: 2,
margin: sectionLogoMargin,
image: logo,
fit: sectionLogoFit,
alignment: 'center',
}
: {
rowSpan: 2,
margin: sectionLogoMargin,
text: '',
alignment: 'center',
};
return {
table: {
widths: ['45%', '55%'],
body: [
[
logoSection,
{
text: title,
alignment: 'center',
style: ['header'],
color: primaryColor,
border: [false, false, false, true],
},
],
[
'',
{
table: {
widths: contentWidths,
body: bodyContent,
},
layout: 'tableLayout',
},
],
],
},
layout: 'tableLayout',
};
};
exports.default = genericTopContent;