@treeunfe/danfe 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/NFCEGerarDanfe/NFCEGerarDanfe.d.ts +58 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/NFCEGerarDanfe/NFCEGerarDanfe.js +495 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/NFCEGerarDanfe/NFCEGerarDanfe.js.map +1 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/NFEGerarDanfe/NFEGerarDanfe.d.ts +39 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/NFEGerarDanfe/NFEGerarDanfe.js +1097 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/NFEGerarDanfe/NFEGerarDanfe.js.map +1 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/index.d.ts +2 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/index.js +19 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/src/index.js.map +1 -0
- package/.rollup.cache/home/runner/work/treeunfe-dfe/treeunfe-dfe/packages/danfe/dist/tsconfig.tsbuildinfo +1 -0
- package/.turbo/turbo-build.log +15 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +27 -0
- package/LICENSE.txt +221 -0
- package/dist/index.cjs +1591 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +1587 -0
- package/dist/index.mjs.map +1 -0
- package/dist/src/NFCEGerarDanfe/NFCEGerarDanfe.d.ts +58 -0
- package/dist/src/NFEGerarDanfe/NFEGerarDanfe.d.ts +39 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +63 -0
- package/rollup.config.js +94 -0
- package/src/NFCEGerarDanfe/NFCEGerarDanfe.ts +598 -0
- package/src/NFEGerarDanfe/NFEGerarDanfe.ts +1223 -0
- package/src/bwip-js.d.ts +16 -0
- package/src/index.ts +19 -0
- package/tsconfig.json +16 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1587 @@
|
|
|
1
|
+
import { ValidaCPFCNPJ, getDesTipoPag } from '@treeunfe/shared';
|
|
2
|
+
import bwipjs from 'bwip-js';
|
|
3
|
+
import { format, parseISO } from 'date-fns';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import PDFDocument from 'pdfkit';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import QRCode from 'qrcode';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* This file is part of Treeunfe DFe.
|
|
12
|
+
*
|
|
13
|
+
* Treeunfe DFe is free software: you can redistribute it and/or modify
|
|
14
|
+
* it under the terms of the GNU General Public License as published by
|
|
15
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
16
|
+
* (at your option) any later version.
|
|
17
|
+
*
|
|
18
|
+
* Treeunfe DFe is distributed in the hope that it will be useful,
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21
|
+
* GNU General Public License for more details.
|
|
22
|
+
*
|
|
23
|
+
* You should have received a copy of the GNU General Public License
|
|
24
|
+
* along with Treeunfe DFe. If not, see <https://www.gnu.org/licenses/>.
|
|
25
|
+
*/
|
|
26
|
+
class NFEGerarDanfe {
|
|
27
|
+
constructor(props) {
|
|
28
|
+
this.barcodeBuffer = null;
|
|
29
|
+
const { data, chave, outputPath } = props;
|
|
30
|
+
this.data = data;
|
|
31
|
+
this.chave = chave.trim();
|
|
32
|
+
this.outputPath = outputPath;
|
|
33
|
+
this.enviada = false;
|
|
34
|
+
this.documento = new ValidaCPFCNPJ();
|
|
35
|
+
this.protNFe = data.protNFe;
|
|
36
|
+
const nfeData = Array.isArray(data.NFe) ? data.NFe[0] : data.NFe;
|
|
37
|
+
const { det, ide, emit, dest, total, transp, infAdic } = nfeData.infNFe;
|
|
38
|
+
this.det = det;
|
|
39
|
+
this.ide = ide;
|
|
40
|
+
this.emit = emit;
|
|
41
|
+
this.total = total;
|
|
42
|
+
this.transp = transp;
|
|
43
|
+
this.infAdic = infAdic;
|
|
44
|
+
if (dest)
|
|
45
|
+
this.dest = dest;
|
|
46
|
+
if (this.protNFe?.infProt.nProt) {
|
|
47
|
+
this.enviada = true;
|
|
48
|
+
}
|
|
49
|
+
// Área útil ignorando margem à direita (22.68) e esquerda (5.67) = 566.93
|
|
50
|
+
this.doc = new PDFDocument({
|
|
51
|
+
margins: { top: 22, right: 22.68, bottom: 12, left: 5.67 },
|
|
52
|
+
size: 'a4', // 595.28 * 841.89
|
|
53
|
+
bufferPages: true,
|
|
54
|
+
layout: 'portrait',
|
|
55
|
+
font: 'Times-Roman',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
async generateBarcode(data) {
|
|
59
|
+
try {
|
|
60
|
+
const pngBuffer = await bwipjs.toBuffer({
|
|
61
|
+
bcid: 'code128',
|
|
62
|
+
text: data,
|
|
63
|
+
scaleX: 4,
|
|
64
|
+
height: 14,
|
|
65
|
+
includetext: false,
|
|
66
|
+
});
|
|
67
|
+
this.barcodeBuffer = pngBuffer; // Armazena o buffer na instância
|
|
68
|
+
return pngBuffer; // Retorna o buffer
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
console.error('Erro ao gerar código de barras:', err);
|
|
72
|
+
this.barcodeBuffer = null;
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
setLineStyle(lineWidth, strokeColor) {
|
|
77
|
+
this.doc.lineWidth(lineWidth).strokeColor(strokeColor).fill('black');
|
|
78
|
+
}
|
|
79
|
+
drawHeader(isFirstPage) {
|
|
80
|
+
if (isFirstPage) {
|
|
81
|
+
this._buildGuia();
|
|
82
|
+
this._buildSeparator();
|
|
83
|
+
this._buildHeader(52);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this._buildHeader(0);
|
|
87
|
+
}
|
|
88
|
+
// this.doc.moveDown();
|
|
89
|
+
}
|
|
90
|
+
drawFooter() {
|
|
91
|
+
this._buildFooter();
|
|
92
|
+
}
|
|
93
|
+
_buildGuia() {
|
|
94
|
+
const { top, left } = this.doc.page.margins;
|
|
95
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
96
|
+
/** TOP LEFT */
|
|
97
|
+
this.doc.rect(left, top, 470, 21).stroke();
|
|
98
|
+
this.doc.fontSize(5).text(`RECEBEMOS DE ${this.emit.xNome} OS PRODUTOS / SERVIÇOS CONSTANTES DA NOTA FISCAL INDICADO AO LADO`, 10, 26, {
|
|
99
|
+
characterSpacing: 0.5
|
|
100
|
+
});
|
|
101
|
+
this.doc.fontSize(6).text(`EMISSÃO: ${format(new Date(this.ide.dhEmi), 'dd-MM-yyyy')} - DEST. / REM.: ${this.dest?.xNome || ''} - VALOR TOTAL: R$ ${parseFloat(String(this.total.ICMSTot.vNF)).toFixed(2)}`, 10, 33.5, {
|
|
102
|
+
characterSpacing: 0.5
|
|
103
|
+
});
|
|
104
|
+
/** RIGHT */
|
|
105
|
+
this.doc.rect(left + 470, top, 96.93, 42).stroke();
|
|
106
|
+
this.doc.fontSize(11).text(`NF-e`, 480, 27, {
|
|
107
|
+
characterSpacing: 1.5,
|
|
108
|
+
align: 'center'
|
|
109
|
+
});
|
|
110
|
+
this.doc.fontSize(8.8).font('Times-Bold').text(`Nº ${String(this.ide.nNF).padStart(2, '0')}`, 480, 40.5, {
|
|
111
|
+
characterSpacing: 1.5,
|
|
112
|
+
align: 'center',
|
|
113
|
+
});
|
|
114
|
+
this.doc.fontSize(8.5).font('Times-Roman').text(`SÉRIE ${this.ide.serie.padStart(3, '0')}`, 480, 53, {
|
|
115
|
+
characterSpacing: 1.5,
|
|
116
|
+
align: 'center',
|
|
117
|
+
});
|
|
118
|
+
/** BOTTON LEFT */
|
|
119
|
+
this.doc.rect(left, top + 21, 75, 21).stroke();
|
|
120
|
+
this.doc.fontSize(5).text(`DATA DE RECEBIMENTO`, 10, 46.5, {
|
|
121
|
+
characterSpacing: 0.5,
|
|
122
|
+
});
|
|
123
|
+
/** BOTTON RIGHT */
|
|
124
|
+
this.doc.rect(left + 75, top + 21, 395, 21).stroke();
|
|
125
|
+
this.doc.fontSize(5).text(`IDENTIFICAÇÃO E ASSINATURA DO RECEBEDOR`, 75 + 10, 46.5, {
|
|
126
|
+
characterSpacing: 0.5
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
_buildSeparator() {
|
|
130
|
+
const { left, right } = this.doc.page.margins;
|
|
131
|
+
const pageWidth = 595.28; // Largura da página A4 em pontos
|
|
132
|
+
// Calcule a largura da linha, considerando as margens esquerda e direita
|
|
133
|
+
const lineWidth = pageWidth - left - right;
|
|
134
|
+
// Desenhe a linha
|
|
135
|
+
this.doc.moveTo(left, 69) // Início da linha
|
|
136
|
+
.lineTo(left + lineWidth, 69) // Fim da linha
|
|
137
|
+
.lineWidth(1) // Espessura da linha
|
|
138
|
+
.dash(1.5, { space: 1.5 }) // Estilo pontilhado
|
|
139
|
+
.strokeColor('black') // Cor da linha
|
|
140
|
+
.stroke(); // Desenhar a linha
|
|
141
|
+
this.doc.undash();
|
|
142
|
+
}
|
|
143
|
+
_buildHeader(pos) {
|
|
144
|
+
const { top, left } = this.doc.page.margins;
|
|
145
|
+
const page = this.doc.bufferedPageRange();
|
|
146
|
+
const CNPJCPF = this.emit.CNPJCPF?.toString();
|
|
147
|
+
const CNPJ = this.emit.CNPJ?.toString();
|
|
148
|
+
const CPF = this.emit.CPF?.toString();
|
|
149
|
+
const documento = this.documento.mascaraCnpjCpf(CNPJCPF || CNPJ || CPF || '');
|
|
150
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
151
|
+
const topIdentificacao_1 = top + pos;
|
|
152
|
+
const identificationJoined = `\nCEP: ${this.emit.enderEmit.CEP} - ${this.emit.enderEmit.xBairro} - ${this.emit.enderEmit.UF}\nTEL: ${this.emit.enderEmit.fone} - FAX: ${this.emit.enderEmit.fone}`;
|
|
153
|
+
/** IDENTIFICACAO EMITENTE */
|
|
154
|
+
const _buildIdentificacaoEmit = () => {
|
|
155
|
+
this.doc.rect(left, topIdentificacao_1, 197.5, 98).stroke();
|
|
156
|
+
this.doc.fontSize(5).text(`IDENTIFICAÇÃO DO EMITENTE`, 10, topIdentificacao_1 + 3.5, {
|
|
157
|
+
characterSpacing: 0.5,
|
|
158
|
+
});
|
|
159
|
+
this.doc.fontSize(8).font('Times-Bold').text(this.emit.xNome, 35, topIdentificacao_1 + 14, {
|
|
160
|
+
characterSpacing: 1,
|
|
161
|
+
width: 170,
|
|
162
|
+
lineBreak: true,
|
|
163
|
+
lineGap: 4
|
|
164
|
+
});
|
|
165
|
+
this.doc.fontSize(7).font('Times-Roman').text(`${this.emit.enderEmit.xLgr}, ${this.emit.enderEmit.nro} ${this.emit.xFant ? `- ${this.emit.xFant}` : ''}`, 10, topIdentificacao_1 + 44, {
|
|
166
|
+
characterSpacing: 1,
|
|
167
|
+
width: 181,
|
|
168
|
+
lineBreak: true,
|
|
169
|
+
lineGap: 2,
|
|
170
|
+
continued: true
|
|
171
|
+
}).text(identificationJoined);
|
|
172
|
+
};
|
|
173
|
+
/** IDENTIFICACAO NFe */
|
|
174
|
+
const _buildIdentificacaoDanfe = () => {
|
|
175
|
+
this.doc.rect(left + 197.5, topIdentificacao_1, 112.7, 98).stroke();
|
|
176
|
+
this.doc.fontSize(12).font('Times-Bold').text(`DANFE`, 203, topIdentificacao_1 + 8, {
|
|
177
|
+
characterSpacing: 1.5,
|
|
178
|
+
width: 112.7,
|
|
179
|
+
align: 'center'
|
|
180
|
+
});
|
|
181
|
+
this.doc.fontSize(6).text(`DOCUMENTO AUXILIAR DA NOTA FISCAL ELETRÔNICA`, 215, topIdentificacao_1 + 20, {
|
|
182
|
+
characterSpacing: 0.5,
|
|
183
|
+
width: 95,
|
|
184
|
+
align: 'left',
|
|
185
|
+
lineGap: 2,
|
|
186
|
+
});
|
|
187
|
+
this.doc.fontSize(8).font('Times-Roman').text(`0 - ENTRADA`, 217, topIdentificacao_1 + 40, {
|
|
188
|
+
characterSpacing: 0.5,
|
|
189
|
+
align: 'left',
|
|
190
|
+
});
|
|
191
|
+
this.doc.fontSize(8).text(`1 - SAÍDA`, 217, topIdentificacao_1 + 50, {
|
|
192
|
+
characterSpacing: 0.5,
|
|
193
|
+
align: 'left',
|
|
194
|
+
});
|
|
195
|
+
this.doc.rect(left + 275, topIdentificacao_1 + 38, 18, 18).stroke();
|
|
196
|
+
this.doc.fontSize(14).font('Times-Bold').text(String(this.ide.tpNF), left + 280, topIdentificacao_1 + 42.5);
|
|
197
|
+
this.doc.fontSize(8.8).text(`Nº ${String(this.ide.nNF).padStart(2, '0')}`, 208, topIdentificacao_1 + 65, {
|
|
198
|
+
characterSpacing: 1,
|
|
199
|
+
});
|
|
200
|
+
this.doc.fontSize(10).font('Times-Roman').text(`fl. ${page.start + 1}/${page.count}`, 240, topIdentificacao_1 + 65, {
|
|
201
|
+
characterSpacing: 1.5,
|
|
202
|
+
width: 112.7,
|
|
203
|
+
align: 'center'
|
|
204
|
+
});
|
|
205
|
+
this.doc.fontSize(8.8).text(`SÉRIE ${this.ide.serie.padStart(3, '0')}`, 208, topIdentificacao_1 + 78, {
|
|
206
|
+
characterSpacing: 1.5,
|
|
207
|
+
width: 112.7,
|
|
208
|
+
align: 'center'
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
/** IDENTIFICACAO NFe (Barcode e Chave) */
|
|
212
|
+
const _buildIdentificacaoNFe = () => {
|
|
213
|
+
this.doc.rect(left + 310.2, topIdentificacao_1, 256.73, 35).stroke();
|
|
214
|
+
if (this.barcodeBuffer) { // Verifica se o buffer do barcode existe
|
|
215
|
+
this.doc.image(this.barcodeBuffer, left + 323.5, topIdentificacao_1 + 3, { width: 230, height: 30 });
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
this.doc.fontSize(8).fillColor('red').text('Erro ao carregar barcode', left + 316, topIdentificacao_1 + 12, {
|
|
219
|
+
width: 256.73, align: 'center'
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
if (Number(this.ide.tpAmb) !== 2 && !this.enviada && !this.data.forceTransmitida) {
|
|
223
|
+
this.doc.fontSize(14).font('Times-Bold').fillColor('red').text('NF-E NÃO ENVIADA PARA SEFAZ', left + 316, topIdentificacao_1 + 12, {
|
|
224
|
+
characterSpacing: 1,
|
|
225
|
+
width: 256.73,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
229
|
+
this.doc.rect(left + 310.2, topIdentificacao_1 + 35, 256.73, 23).stroke();
|
|
230
|
+
this.doc.fontSize(5).font('Times-Roman').text(`CHAVE DE ACESSO`, left + 314, topIdentificacao_1 + 38, {
|
|
231
|
+
characterSpacing: 0.5,
|
|
232
|
+
});
|
|
233
|
+
this.doc.fontSize(6).text(this.chave, left + 310.2, topIdentificacao_1 + 47, {
|
|
234
|
+
characterSpacing: 1,
|
|
235
|
+
width: 256.73,
|
|
236
|
+
align: 'center'
|
|
237
|
+
});
|
|
238
|
+
this.doc.rect(left + 310.2, topIdentificacao_1 + 58, 256.73, 40).stroke();
|
|
239
|
+
if (Number(this.ide.tpAmb) === 2 || this.enviada) {
|
|
240
|
+
this.doc.fontSize(6.5).text('Consulta de autenticidade no portal nacional da NF-e', left + 310.2, topIdentificacao_1 + 65, {
|
|
241
|
+
characterSpacing: 0.5,
|
|
242
|
+
width: 256.73,
|
|
243
|
+
align: 'center'
|
|
244
|
+
});
|
|
245
|
+
this.doc.fontSize(6.5).text('www.nfe.fazenda.gov.br/portal', left + 310.2, topIdentificacao_1 + 75, {
|
|
246
|
+
characterSpacing: 0.5,
|
|
247
|
+
width: 256.73,
|
|
248
|
+
align: 'center'
|
|
249
|
+
});
|
|
250
|
+
this.doc.fontSize(6.5).text('ou no site da Sefaz Autorizadora', left + 310.2, topIdentificacao_1 + 85, {
|
|
251
|
+
characterSpacing: 0.5,
|
|
252
|
+
width: 256.73,
|
|
253
|
+
align: 'center'
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
this.doc.rect(left, topIdentificacao_1 + 98, 310.2, 23).stroke();
|
|
257
|
+
this.doc.fontSize(5).text('NATUREZA DE OPERAÇÃO', left + 4, topIdentificacao_1 + 102, {
|
|
258
|
+
characterSpacing: 0.5,
|
|
259
|
+
});
|
|
260
|
+
this.doc.fontSize(8).text(this.ide.natOp, left + 4, topIdentificacao_1 + 112, {
|
|
261
|
+
characterSpacing: 1,
|
|
262
|
+
});
|
|
263
|
+
this.doc.rect(left + 310.2, topIdentificacao_1 + 98, 256.73, 23).stroke();
|
|
264
|
+
if (Number(this.ide.tpAmb) === 2 || this.enviada) {
|
|
265
|
+
let dhRecbto = '';
|
|
266
|
+
if (this.protNFe?.infProt.dhRecbto) {
|
|
267
|
+
dhRecbto = format(new Date(this.protNFe?.infProt.dhRecbto), 'dd/MM/yyyy HH:mm:ss');
|
|
268
|
+
}
|
|
269
|
+
const xProtNfe = `${String(this.protNFe?.infProt.nProt || '')} ${dhRecbto}`;
|
|
270
|
+
this.doc.fontSize(5).text('PROTOCOLO DE AUTORIZAÇÃO DE USO', left + 314.2, topIdentificacao_1 + 102, {
|
|
271
|
+
characterSpacing: 0.5,
|
|
272
|
+
});
|
|
273
|
+
this.doc.fontSize(8).text(xProtNfe, left + 314.2, topIdentificacao_1 + 112, {
|
|
274
|
+
characterSpacing: 1,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
/** IDENTIFICACAO PESSOA */
|
|
279
|
+
const _buildIdentificacaoPessoa = () => {
|
|
280
|
+
this.doc.rect(left, topIdentificacao_1 + 121, 189.5, 23).stroke();
|
|
281
|
+
this.doc.fontSize(5).text('INSCRIÇÃO ESTADUAL', left + 4, topIdentificacao_1 + 125, {
|
|
282
|
+
characterSpacing: 0.5,
|
|
283
|
+
});
|
|
284
|
+
this.doc.fontSize(8).text(this.emit.IE, left + 5, topIdentificacao_1 + 135, {
|
|
285
|
+
characterSpacing: 1,
|
|
286
|
+
});
|
|
287
|
+
this.doc.rect(left + 189.5, topIdentificacao_1 + 121, 187.93, 23).stroke();
|
|
288
|
+
this.doc.fontSize(5).text('INSCRIÇÃO ESTADUAL DO SUBST. TRIB.', left + 193.5, topIdentificacao_1 + 125, {
|
|
289
|
+
characterSpacing: 0.5,
|
|
290
|
+
});
|
|
291
|
+
this.doc.fontSize(8).text(String(this.emit.IEST || ''), left + 194.5, topIdentificacao_1 + 135, {
|
|
292
|
+
characterSpacing: 1,
|
|
293
|
+
});
|
|
294
|
+
this.doc.rect(left + 377.43, topIdentificacao_1 + 121, 189.5, 23).stroke();
|
|
295
|
+
this.doc.fontSize(5).text('CNPJ / CPF', left + 381.43, topIdentificacao_1 + 125, {
|
|
296
|
+
characterSpacing: 0.5,
|
|
297
|
+
});
|
|
298
|
+
this.doc.fontSize(8).text(documento, left + 386.43, topIdentificacao_1 + 135, {
|
|
299
|
+
characterSpacing: 1,
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
_buildIdentificacaoEmit();
|
|
303
|
+
_buildIdentificacaoDanfe();
|
|
304
|
+
_buildIdentificacaoNFe();
|
|
305
|
+
_buildIdentificacaoPessoa();
|
|
306
|
+
}
|
|
307
|
+
_buildDestinatario() {
|
|
308
|
+
const { top, left } = this.doc.page.margins;
|
|
309
|
+
const docDest = this.documento.mascaraCnpjCpf(this.dest?.CNPJCPF || this.dest?.CNPJ || this.dest?.CPF || '');
|
|
310
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
311
|
+
const topDestinatario = top + 90;
|
|
312
|
+
const _buildDestPessoa = () => {
|
|
313
|
+
this.doc.rect(left, topDestinatario + 120, 398, 23).stroke();
|
|
314
|
+
let xNome = 'NF-E EMITIDA EM AMBIENTE DE HOMOLOGACAO - SEM VALOR FISCAL';
|
|
315
|
+
if (Number(this.ide.tpAmb) !== 2) {
|
|
316
|
+
xNome = String(this.dest?.xNome || '');
|
|
317
|
+
}
|
|
318
|
+
this.doc.fontSize(5).font('Times-Roman').text('NOME / RAZÃO SOCIAL', left + 4, topDestinatario + 125, {
|
|
319
|
+
characterSpacing: 0.5,
|
|
320
|
+
});
|
|
321
|
+
this.doc.fontSize(8).text(xNome, left + 5, topDestinatario + 135, {
|
|
322
|
+
characterSpacing: 1,
|
|
323
|
+
});
|
|
324
|
+
this.doc.rect(left + 398, topDestinatario + 120, 94, 23).stroke();
|
|
325
|
+
this.doc.fontSize(5).text('CNPJ / CPF', left + 402, topDestinatario + 125, {
|
|
326
|
+
characterSpacing: 0.5,
|
|
327
|
+
});
|
|
328
|
+
this.doc.fontSize(8).text(docDest, left + 403, topDestinatario + 135, {
|
|
329
|
+
characterSpacing: 1,
|
|
330
|
+
});
|
|
331
|
+
this.doc.rect(left + 492, topDestinatario + 120, 74.3, 23).stroke();
|
|
332
|
+
this.doc.fontSize(5).text('DATA DA EMISSÃO', left + 496, topDestinatario + 125, {
|
|
333
|
+
characterSpacing: 0.5,
|
|
334
|
+
});
|
|
335
|
+
this.doc.fontSize(8).text(format(new Date(this.ide.dhEmi), 'dd-MM-yyyy'), left + 497, topDestinatario + 135, {
|
|
336
|
+
characterSpacing: 1,
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
const _buildDestLogradouro = () => {
|
|
340
|
+
this.doc.rect(left, topDestinatario + 143, 320, 23).stroke();
|
|
341
|
+
this.doc.fontSize(5).text('ENDEREÇO', left + 4, topDestinatario + 148, {
|
|
342
|
+
characterSpacing: 0.5,
|
|
343
|
+
});
|
|
344
|
+
this.doc.fontSize(8).text(`${this.dest?.enderDest?.xLgr || ''}, ${this.dest?.enderDest?.nro || ''}`, left + 5, topDestinatario + 158, {
|
|
345
|
+
characterSpacing: 1,
|
|
346
|
+
});
|
|
347
|
+
this.doc.rect(left + 320, topDestinatario + 143, 118.5, 23).stroke();
|
|
348
|
+
this.doc.fontSize(5).text('BAIRRO / DISTRITO', left + 324, topDestinatario + 148, {
|
|
349
|
+
characterSpacing: 0.5,
|
|
350
|
+
});
|
|
351
|
+
const bairroText = String(this.dest?.enderDest?.xBairro || '');
|
|
352
|
+
const bairroCharLimit = 22;
|
|
353
|
+
const bairroMaxWidthForText = 110; // Largura útil para o texto dentro da célula
|
|
354
|
+
const defaultBairroFontSize = 8;
|
|
355
|
+
const reducedBairroFontSize = 5.5;
|
|
356
|
+
const defaultBairroCharSpacing = 1;
|
|
357
|
+
const reducedBairroCharSpacing = 0.25;
|
|
358
|
+
let fontSizeToUse = defaultBairroFontSize;
|
|
359
|
+
let charSpacingToUse = defaultBairroCharSpacing;
|
|
360
|
+
if (bairroText.length > bairroCharLimit) {
|
|
361
|
+
fontSizeToUse = reducedBairroFontSize;
|
|
362
|
+
charSpacingToUse = reducedBairroCharSpacing;
|
|
363
|
+
}
|
|
364
|
+
// Cálculo de Y para tentar alinhar (pode precisar de ajuste fino)
|
|
365
|
+
const textLineHeight = this.doc.currentLineHeight(); // Altura da linha com fontSizeToUse
|
|
366
|
+
const cellContentYBase = topDestinatario + 158; // Linha de base original
|
|
367
|
+
const cellHeightForText = 23 - 5 - 5; // Altura da célula - padding label - padding inferior
|
|
368
|
+
let yPosForBairro = cellContentYBase;
|
|
369
|
+
// Ajuste simples para tentar centralizar um pouco se a linha for mais baixa que o espaço
|
|
370
|
+
if (textLineHeight < cellHeightForText) {
|
|
371
|
+
yPosForBairro = cellContentYBase - ((cellHeightForText - textLineHeight) / 2) + (textLineHeight * 0.3); // ajuste
|
|
372
|
+
}
|
|
373
|
+
// Ajuste fino para alinhar com os outros campos na mesma linha Y
|
|
374
|
+
yPosForBairro = topDestinatario + 158; // Reset para a mesma linha Y dos outros campos
|
|
375
|
+
this.doc.font('Times-Roman').fontSize(fontSizeToUse);
|
|
376
|
+
this.doc.text(bairroText, left + 320 + 3, yPosForBairro, {
|
|
377
|
+
characterSpacing: charSpacingToUse,
|
|
378
|
+
width: bairroMaxWidthForText,
|
|
379
|
+
lineBreak: false,
|
|
380
|
+
ellipsis: true,
|
|
381
|
+
});
|
|
382
|
+
this.doc.font('Times-Roman').fontSize(8);
|
|
383
|
+
this.doc.rect(left + 438.5, topDestinatario + 143, 53.5, 23).stroke();
|
|
384
|
+
this.doc.fontSize(5).text('CEP', left + 442.5, topDestinatario + 148, {
|
|
385
|
+
characterSpacing: 0.5,
|
|
386
|
+
});
|
|
387
|
+
this.doc.fontSize(8).text(String(this.dest?.enderDest?.CEP || ''), left + 443.5, topDestinatario + 158, {
|
|
388
|
+
characterSpacing: 1,
|
|
389
|
+
});
|
|
390
|
+
this.doc.rect(left + 492, topDestinatario + 143, 74.3, 23).stroke();
|
|
391
|
+
this.doc.fontSize(5).text('DATA SAÍDA / ENTRADA', left + 496, topDestinatario + 148, {
|
|
392
|
+
characterSpacing: 0.5,
|
|
393
|
+
});
|
|
394
|
+
this.doc.fontSize(8).text(format(new Date(), 'dd-MM-yyyy'), left + 497, topDestinatario + 158, {
|
|
395
|
+
characterSpacing: 1,
|
|
396
|
+
});
|
|
397
|
+
};
|
|
398
|
+
const _buildDestEndereco = () => {
|
|
399
|
+
this.doc.rect(left, topDestinatario + 166, 246.5, 23).stroke();
|
|
400
|
+
this.doc.fontSize(5).text('MUNICÍPIO', left + 4, topDestinatario + 171, {
|
|
401
|
+
characterSpacing: 0.5,
|
|
402
|
+
});
|
|
403
|
+
this.doc.fontSize(8).text(String(this.dest?.enderDest?.xMun || ''), left + 5, topDestinatario + 181, {
|
|
404
|
+
characterSpacing: 1,
|
|
405
|
+
});
|
|
406
|
+
this.doc.rect(left + 246.5, topDestinatario + 166, 113, 23).stroke();
|
|
407
|
+
this.doc.fontSize(5).text('FONE / FAX', left + 250.5, topDestinatario + 171, {
|
|
408
|
+
characterSpacing: 0.5,
|
|
409
|
+
});
|
|
410
|
+
this.doc.fontSize(8).text(this.dest?.enderDest?.fone || '', left + 250.5, topDestinatario + 181, {
|
|
411
|
+
characterSpacing: 1,
|
|
412
|
+
});
|
|
413
|
+
this.doc.rect(left + 359.5, topDestinatario + 166, 40, 23).stroke();
|
|
414
|
+
this.doc.fontSize(5).text('UF', left + 363.5, topDestinatario + 171, {
|
|
415
|
+
characterSpacing: 0.5,
|
|
416
|
+
});
|
|
417
|
+
this.doc.fontSize(8).text(String(this.dest?.enderDest?.UF || ''), left + 363.5, topDestinatario + 181, {
|
|
418
|
+
characterSpacing: 1,
|
|
419
|
+
});
|
|
420
|
+
this.doc.rect(left + 399.5, topDestinatario + 166, 92.5, 23).stroke();
|
|
421
|
+
this.doc.fontSize(5).text('INSCRIÇÃO ESTADUAL', left + 403.5, topDestinatario + 171, {
|
|
422
|
+
characterSpacing: 0.5,
|
|
423
|
+
});
|
|
424
|
+
this.doc.fontSize(8).text(String(this.dest?.indIEDest || ''), left + 403.5, topDestinatario + 181, {
|
|
425
|
+
characterSpacing: 1,
|
|
426
|
+
});
|
|
427
|
+
this.doc.rect(left + 492, topDestinatario + 166, 74.3, 23).stroke();
|
|
428
|
+
this.doc.fontSize(5).text('HORA DA SAÍDA', left + 496, topDestinatario + 171, {
|
|
429
|
+
characterSpacing: 0.5,
|
|
430
|
+
});
|
|
431
|
+
this.doc.fontSize(8).text(format(new Date(), 'HH:mm'), left + 497, topDestinatario + 181, {
|
|
432
|
+
characterSpacing: 1,
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
this.doc.fontSize(6).font('Times-Bold').text('DESTINATÁRIO / REMETENTE', left, topDestinatario + 114, {
|
|
436
|
+
characterSpacing: 0.5,
|
|
437
|
+
});
|
|
438
|
+
_buildDestPessoa();
|
|
439
|
+
_buildDestLogradouro();
|
|
440
|
+
_buildDestEndereco();
|
|
441
|
+
}
|
|
442
|
+
_builCalculoImposto() {
|
|
443
|
+
const { top, left } = this.doc.page.margins;
|
|
444
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
445
|
+
const topDestinatario = top + 173;
|
|
446
|
+
const _buildCalcImposto = () => {
|
|
447
|
+
/** LINHA 1 */
|
|
448
|
+
this.doc.rect(left, topDestinatario + 120, 86, 23).stroke();
|
|
449
|
+
this.doc.fontSize(5).font('Times-Roman').text('BASE DE CÁLCULO DO ICMS', left + 4, topDestinatario + 125, {
|
|
450
|
+
characterSpacing: 0.5,
|
|
451
|
+
});
|
|
452
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vBC)).toFixed(2), left - 8, topDestinatario + 135, {
|
|
453
|
+
characterSpacing: 1,
|
|
454
|
+
align: 'right',
|
|
455
|
+
width: 86
|
|
456
|
+
});
|
|
457
|
+
this.doc.rect(left + 86, topDestinatario + 120, 79, 23).stroke();
|
|
458
|
+
this.doc.fontSize(5).text('VALOR DO ICMS', left + 90, topDestinatario + 125, {
|
|
459
|
+
characterSpacing: 0.5,
|
|
460
|
+
});
|
|
461
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vICMS)).toFixed(2), left + 86 - 16, topDestinatario + 135, {
|
|
462
|
+
characterSpacing: 1,
|
|
463
|
+
align: 'right',
|
|
464
|
+
width: 86
|
|
465
|
+
});
|
|
466
|
+
this.doc.rect(left + 165, topDestinatario + 120, 79, 23).stroke();
|
|
467
|
+
this.doc.fontSize(5).text('BASE CÁLC. ICMS SUBST', left + 169, topDestinatario + 125, {
|
|
468
|
+
characterSpacing: 0.5,
|
|
469
|
+
});
|
|
470
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vBCST)).toFixed(2), left + 165 - 16, topDestinatario + 135, {
|
|
471
|
+
characterSpacing: 1,
|
|
472
|
+
align: 'right',
|
|
473
|
+
width: 86
|
|
474
|
+
});
|
|
475
|
+
this.doc.rect(left + 244, topDestinatario + 120, 79, 23).stroke();
|
|
476
|
+
this.doc.fontSize(5).text('VALOR DO ICMS SUBST.', left + 248, topDestinatario + 125, {
|
|
477
|
+
characterSpacing: 0.5,
|
|
478
|
+
});
|
|
479
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vST)).toFixed(2), left + 244 - 16, topDestinatario + 135, {
|
|
480
|
+
characterSpacing: 1,
|
|
481
|
+
align: 'right',
|
|
482
|
+
width: 86
|
|
483
|
+
});
|
|
484
|
+
this.doc.rect(left + 323, topDestinatario + 120, 91, 23).stroke();
|
|
485
|
+
this.doc.fontSize(5).text('VALOR APROX. DOS TRIBUTOS', left + 327, topDestinatario + 125, {
|
|
486
|
+
characterSpacing: 0.5,
|
|
487
|
+
});
|
|
488
|
+
this.doc.fontSize(8).text(parseFloat(this.total.ICMSTot.vTotTrib || '0').toFixed(2), left + 323 - 6, topDestinatario + 135, {
|
|
489
|
+
characterSpacing: 1,
|
|
490
|
+
align: 'right',
|
|
491
|
+
width: 86
|
|
492
|
+
});
|
|
493
|
+
this.doc.rect(left + 414, topDestinatario + 120, 152.93, 23).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
494
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
495
|
+
this.doc.fontSize(5).text('VALOR TOTAL DOS PRODUTOS', left + 418, topDestinatario + 125, {
|
|
496
|
+
characterSpacing: 0.5,
|
|
497
|
+
});
|
|
498
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vProd)).toFixed(2), left + 480 - 8, topDestinatario + 135, {
|
|
499
|
+
characterSpacing: 1,
|
|
500
|
+
align: 'right',
|
|
501
|
+
width: 86
|
|
502
|
+
});
|
|
503
|
+
/** LINHA 2 */
|
|
504
|
+
this.doc.rect(left, topDestinatario + 143, 86, 23).stroke();
|
|
505
|
+
this.doc.fontSize(5).text('VALOR DO FRETE', left + 4, topDestinatario + 148, {
|
|
506
|
+
characterSpacing: 0.5,
|
|
507
|
+
});
|
|
508
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vFrete)).toFixed(2), left - 8, topDestinatario + 158, {
|
|
509
|
+
characterSpacing: 1,
|
|
510
|
+
align: 'right',
|
|
511
|
+
width: 86
|
|
512
|
+
});
|
|
513
|
+
this.doc.rect(left + 86, topDestinatario + 143, 79, 23).stroke();
|
|
514
|
+
this.doc.fontSize(5).text('VALOR DO SEGURO', left + 90, topDestinatario + 148, {
|
|
515
|
+
characterSpacing: 0.5,
|
|
516
|
+
});
|
|
517
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vSeg)).toFixed(2), left + 86 - 16, topDestinatario + 158, {
|
|
518
|
+
characterSpacing: 1,
|
|
519
|
+
align: 'right',
|
|
520
|
+
width: 86
|
|
521
|
+
});
|
|
522
|
+
this.doc.rect(left + 165, topDestinatario + 143, 79, 23).stroke();
|
|
523
|
+
this.doc.fontSize(5).text('DESCONTO', left + 169, topDestinatario + 148, {
|
|
524
|
+
characterSpacing: 0.5,
|
|
525
|
+
});
|
|
526
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vDesc)).toFixed(2), left + 165 - 16, topDestinatario + 158, {
|
|
527
|
+
characterSpacing: 1,
|
|
528
|
+
align: 'right',
|
|
529
|
+
width: 86
|
|
530
|
+
});
|
|
531
|
+
this.doc.rect(left + 244, topDestinatario + 143, 79, 23).stroke();
|
|
532
|
+
this.doc.fontSize(5).text('OUTRAS DESP. ACESS.', left + 248, topDestinatario + 148, {
|
|
533
|
+
characterSpacing: 0.5,
|
|
534
|
+
});
|
|
535
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vOutro)).toFixed(2), left + 244 - 16, topDestinatario + 158, {
|
|
536
|
+
characterSpacing: 1,
|
|
537
|
+
align: 'right',
|
|
538
|
+
width: 86
|
|
539
|
+
});
|
|
540
|
+
this.doc.rect(left + 323, topDestinatario + 143, 91, 23).stroke();
|
|
541
|
+
this.doc.fontSize(5).text('VALOR DO IPI', left + 327, topDestinatario + 148, {
|
|
542
|
+
characterSpacing: 0.5,
|
|
543
|
+
});
|
|
544
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vIPI)).toFixed(2), left + 323 - 6, topDestinatario + 158, {
|
|
545
|
+
characterSpacing: 1,
|
|
546
|
+
align: 'right',
|
|
547
|
+
width: 86
|
|
548
|
+
});
|
|
549
|
+
this.doc.rect(left + 414, topDestinatario + 143, 152.93, 23).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
550
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
551
|
+
this.doc.fontSize(5).text('VALOR TOTAL DA NOTA', left + 418, topDestinatario + 148, {
|
|
552
|
+
characterSpacing: 0.5,
|
|
553
|
+
});
|
|
554
|
+
this.doc.fontSize(8).text(parseFloat(String(this.total.ICMSTot.vNF)).toFixed(2), left + 480 - 8, topDestinatario + 158, {
|
|
555
|
+
characterSpacing: 1,
|
|
556
|
+
align: 'right',
|
|
557
|
+
width: 86
|
|
558
|
+
});
|
|
559
|
+
};
|
|
560
|
+
this.doc.fontSize(6).font('Times-Bold').text('CÁLCULO DO IMPOSTO', left, topDestinatario + 114, {
|
|
561
|
+
characterSpacing: 0.5,
|
|
562
|
+
});
|
|
563
|
+
_buildCalcImposto();
|
|
564
|
+
}
|
|
565
|
+
_builTransporte() {
|
|
566
|
+
const { top, left } = this.doc.page.margins;
|
|
567
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
568
|
+
const topDestinatario = top + 233;
|
|
569
|
+
const getModFrete = () => {
|
|
570
|
+
// * 0=Contratação do Frete por conta do Remetente (CIF)
|
|
571
|
+
// * 1=Contratação do Frete por conta do Destinatário (FOB)
|
|
572
|
+
// * 2=Contratação do Frete por conta de Terceiros
|
|
573
|
+
// * 3=Transporte Próprio por conta do Remetente
|
|
574
|
+
// * 4=Transporte Próprio por conta do Destinatário
|
|
575
|
+
// * 9=Sem Ocorrência de Transporte. (Atualizado na NT 2016/002)
|
|
576
|
+
const modFrete = parseInt(String(this.transp.modFrete));
|
|
577
|
+
switch (modFrete) {
|
|
578
|
+
case 0:
|
|
579
|
+
return `${modFrete} - REMETENTE`;
|
|
580
|
+
case 1:
|
|
581
|
+
return `${modFrete} - DESTINATÁRIO`;
|
|
582
|
+
case 2:
|
|
583
|
+
return `${modFrete} - TERCEIROS`;
|
|
584
|
+
case 3:
|
|
585
|
+
return `${modFrete} - REMETENTE`;
|
|
586
|
+
case 4:
|
|
587
|
+
return `${modFrete} - DESTINATÁRIO`;
|
|
588
|
+
case 9:
|
|
589
|
+
return `${modFrete} - SEM FRETE`;
|
|
590
|
+
default:
|
|
591
|
+
return '';
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
const _buildVolumeTransporte = () => {
|
|
595
|
+
if (this.transp.vol) {
|
|
596
|
+
/** Posição da primeira linha */
|
|
597
|
+
let topTrnasport = topDestinatario + 166;
|
|
598
|
+
let topTrnasportTitle = topDestinatario + 171;
|
|
599
|
+
let topTrnasportValue = topDestinatario + 181;
|
|
600
|
+
const createVolume = (vol) => {
|
|
601
|
+
this.doc.rect(left, topTrnasport, 68.5, 23).stroke();
|
|
602
|
+
this.doc.fontSize(5).text('QUANTIDADE', left + 4, topTrnasportTitle, {
|
|
603
|
+
characterSpacing: 0.5,
|
|
604
|
+
});
|
|
605
|
+
this.doc.fontSize(8).text(String(vol?.qVol || ''), left - 8, topTrnasportValue, {
|
|
606
|
+
characterSpacing: 1,
|
|
607
|
+
align: 'right',
|
|
608
|
+
width: 68.5
|
|
609
|
+
});
|
|
610
|
+
this.doc.rect(left + 68.5, topTrnasport, 100.5, 23).stroke();
|
|
611
|
+
this.doc.fontSize(5).text('ESPÉCIE', left + 72.5, topTrnasportTitle, {
|
|
612
|
+
characterSpacing: 0.5,
|
|
613
|
+
});
|
|
614
|
+
this.doc.fontSize(8).text(String(vol?.esp || ''), left + 73.5, topTrnasportValue, {
|
|
615
|
+
characterSpacing: 1,
|
|
616
|
+
});
|
|
617
|
+
this.doc.rect(left + 169, topTrnasport, 100.5, 23).stroke();
|
|
618
|
+
this.doc.fontSize(5).text('MARCA', left + 173, topTrnasportTitle, {
|
|
619
|
+
characterSpacing: 0.5,
|
|
620
|
+
});
|
|
621
|
+
this.doc.fontSize(8).text(String(vol?.marca || ''), left + 174, topTrnasportValue, {
|
|
622
|
+
characterSpacing: 1,
|
|
623
|
+
});
|
|
624
|
+
this.doc.rect(left + 269.5, topTrnasport, 100.5, 23).stroke();
|
|
625
|
+
this.doc.fontSize(5).text('NUMERAÇÃO', left + 273.5, topTrnasportTitle, {
|
|
626
|
+
characterSpacing: 0.5,
|
|
627
|
+
});
|
|
628
|
+
this.doc.fontSize(8).text(String(vol?.nVol || ''), left + 274.5, topTrnasportValue, {
|
|
629
|
+
characterSpacing: 1,
|
|
630
|
+
});
|
|
631
|
+
this.doc.rect(left + 370, topTrnasport, 102.6, 23).stroke();
|
|
632
|
+
this.doc.fontSize(5).text('PESO BRUTO', left + 374, topTrnasportTitle, {
|
|
633
|
+
characterSpacing: 0.5,
|
|
634
|
+
});
|
|
635
|
+
this.doc.fontSize(8).text(String(vol?.nVol || ''), left + 375, topTrnasportValue, {
|
|
636
|
+
characterSpacing: 1,
|
|
637
|
+
});
|
|
638
|
+
//96,43
|
|
639
|
+
this.doc.rect(left + 472.5, topTrnasport, 94.43, 23).stroke();
|
|
640
|
+
this.doc.fontSize(5).text('PESO LÍQUIDO', left + 474.5, topTrnasportTitle, {
|
|
641
|
+
characterSpacing: 0.5,
|
|
642
|
+
});
|
|
643
|
+
this.doc.fontSize(8).text(String(vol?.nVol || ''), left + 475.5, topTrnasportValue, {
|
|
644
|
+
characterSpacing: 1,
|
|
645
|
+
});
|
|
646
|
+
/** Define posição da nova linha */
|
|
647
|
+
topTrnasport = topTrnasport + 23;
|
|
648
|
+
topTrnasportTitle = topTrnasportTitle + 23;
|
|
649
|
+
topTrnasportValue = topTrnasportValue + 23;
|
|
650
|
+
};
|
|
651
|
+
if (this.transp.vol instanceof Array) {
|
|
652
|
+
for (let vol of this.transp.vol) {
|
|
653
|
+
createVolume(vol);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
657
|
+
createVolume(this.transp.vol);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
const _buildCalcImposto = () => {
|
|
662
|
+
const documento = this.documento.mascaraCnpjCpf(this.transp.transporta?.CNPJCPF || this.transp.transporta?.CNPJ || this.transp.transporta?.CPF || '');
|
|
663
|
+
/** LINHA 1 */
|
|
664
|
+
this.doc.rect(left, topDestinatario + 120, 248.5, 23).stroke();
|
|
665
|
+
this.doc.fontSize(5).font('Times-Roman').text('RAZÃO SOCIAL', left + 4, topDestinatario + 125, {
|
|
666
|
+
characterSpacing: 0.5,
|
|
667
|
+
});
|
|
668
|
+
this.doc.fontSize(8).text(this.transp.transporta?.xNome || '', left + 5, topDestinatario + 135, {
|
|
669
|
+
characterSpacing: 1,
|
|
670
|
+
width: 246
|
|
671
|
+
});
|
|
672
|
+
this.doc.rect(left + 248.5, topDestinatario + 120, 90, 23).stroke();
|
|
673
|
+
this.doc.fontSize(5).text('FRETE POR CONTA', left + 252.5, topDestinatario + 125, {
|
|
674
|
+
characterSpacing: 0.5,
|
|
675
|
+
});
|
|
676
|
+
this.doc.fontSize(8).text(getModFrete(), left + 253.5, topDestinatario + 135, {
|
|
677
|
+
characterSpacing: 1,
|
|
678
|
+
});
|
|
679
|
+
this.doc.rect(left + 338.5, topDestinatario + 120, 50, 23).stroke();
|
|
680
|
+
this.doc.fontSize(5).text('CÓDIGO ANTT', left + 342.5, topDestinatario + 125, {
|
|
681
|
+
characterSpacing: 0.5,
|
|
682
|
+
});
|
|
683
|
+
this.doc.fontSize(8).text(this.transp?.veicTransp?.RNTC || '', left + 343.5, topDestinatario + 135, {
|
|
684
|
+
characterSpacing: 1,
|
|
685
|
+
});
|
|
686
|
+
this.doc.rect(left + 388.5, topDestinatario + 120, 62, 23).stroke();
|
|
687
|
+
this.doc.fontSize(5).text('PLACA DO VEÍCULO', left + 391.5, topDestinatario + 125, {
|
|
688
|
+
characterSpacing: 0.5,
|
|
689
|
+
});
|
|
690
|
+
this.doc.fontSize(8).text(this.transp?.veicTransp?.placa || '', left + 393.5, topDestinatario + 135, {
|
|
691
|
+
characterSpacing: 1,
|
|
692
|
+
});
|
|
693
|
+
this.doc.rect(left + 450.5, topDestinatario + 120, 22, 23).stroke();
|
|
694
|
+
this.doc.fontSize(5).text('UF', left + 454.5, topDestinatario + 125, {
|
|
695
|
+
characterSpacing: 0.5,
|
|
696
|
+
});
|
|
697
|
+
this.doc.fontSize(8).text(this.transp?.transporta?.UF || '', left + 455.5, topDestinatario + 135, {
|
|
698
|
+
characterSpacing: 1,
|
|
699
|
+
});
|
|
700
|
+
this.doc.rect(left + 472.5, topDestinatario + 120, 94.43, 23).stroke();
|
|
701
|
+
this.doc.fontSize(5).text('CNPJ / CPF', left + 476.5, topDestinatario + 125, {
|
|
702
|
+
characterSpacing: 0.5,
|
|
703
|
+
});
|
|
704
|
+
this.doc.fontSize(8).text(documento, left + 477.5, topDestinatario + 135, {
|
|
705
|
+
characterSpacing: 1,
|
|
706
|
+
});
|
|
707
|
+
/** LINHA 2 */
|
|
708
|
+
this.doc.rect(left, topDestinatario + 143, 338.5, 23).stroke();
|
|
709
|
+
this.doc.fontSize(5).text('ENDEREÇO', left + 4, topDestinatario + 148, {
|
|
710
|
+
characterSpacing: 0.5,
|
|
711
|
+
});
|
|
712
|
+
this.doc.fontSize(8).text(this.transp.transporta?.xEnder || '', left + 4, topDestinatario + 158, {
|
|
713
|
+
characterSpacing: 1,
|
|
714
|
+
});
|
|
715
|
+
this.doc.rect(left + 338.5, topDestinatario + 143, 112, 23).stroke();
|
|
716
|
+
this.doc.fontSize(5).text('MUNICÍPIO', left + 342.5, topDestinatario + 148, {
|
|
717
|
+
characterSpacing: 0.5,
|
|
718
|
+
});
|
|
719
|
+
this.doc.fontSize(8).text(this.transp.transporta?.xMun || '', left + 343.5, topDestinatario + 158, {
|
|
720
|
+
characterSpacing: 1,
|
|
721
|
+
});
|
|
722
|
+
this.doc.rect(left + 450.5, topDestinatario + 143, 22, 23).stroke();
|
|
723
|
+
this.doc.fontSize(5).text('UF', left + 454.5, topDestinatario + 148, {
|
|
724
|
+
characterSpacing: 0.5,
|
|
725
|
+
});
|
|
726
|
+
this.doc.fontSize(8).text(this.transp?.transporta?.UF || '', left + 455.5, topDestinatario + 158, {
|
|
727
|
+
characterSpacing: 1,
|
|
728
|
+
});
|
|
729
|
+
this.doc.rect(left + 472.5, topDestinatario + 143, 94.43, 23).stroke();
|
|
730
|
+
this.doc.fontSize(5).text('INSCRIÇÃO ESTADUAL', left + 476.5, topDestinatario + 148, {
|
|
731
|
+
characterSpacing: 0.5,
|
|
732
|
+
});
|
|
733
|
+
this.doc.fontSize(8).text(this.transp?.transporta?.IE || '', left + 476.5, topDestinatario + 158, {
|
|
734
|
+
characterSpacing: 1,
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
this.doc.fontSize(6).font('Times-Bold').text('TRANSPORTADOR / VOLUMES TRANSPORTADOS', left, topDestinatario + 114, {
|
|
738
|
+
characterSpacing: 0.5,
|
|
739
|
+
});
|
|
740
|
+
_buildCalcImposto();
|
|
741
|
+
_buildVolumeTransporte();
|
|
742
|
+
}
|
|
743
|
+
_buildProdutos() {
|
|
744
|
+
const { left } = this.doc.page.margins;
|
|
745
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
746
|
+
this.doc.fontSize(6).font('Times-Bold').fillColor('black').text('DADOS DO PRODUTO / SERVIÇOS', left, 452, {
|
|
747
|
+
characterSpacing: 0.5,
|
|
748
|
+
});
|
|
749
|
+
const tableTop = 458;
|
|
750
|
+
const defaultItemHeight = 15;
|
|
751
|
+
let y = tableTop;
|
|
752
|
+
let currentPage = 0;
|
|
753
|
+
const header = (top) => {
|
|
754
|
+
this.doc.rect(left, top, 40, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
755
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
756
|
+
this.doc.font('Times-Roman').fontSize(5.7).text('CÓDIGO DO PROD. / SERV', left, top + 2.8, {
|
|
757
|
+
width: 40,
|
|
758
|
+
align: 'center',
|
|
759
|
+
});
|
|
760
|
+
this.doc.rect(left + 40, top, 138, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
761
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
762
|
+
this.doc.text('DESCRIÇÃO DO PRODUTO / SERVIÇO', left + 40, top + 5.9, {
|
|
763
|
+
width: 138,
|
|
764
|
+
align: 'center'
|
|
765
|
+
});
|
|
766
|
+
this.doc.rect(left + 178, top, 30, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
767
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
768
|
+
this.doc.text('NCM / SH', left + 178, top + 5.9, {
|
|
769
|
+
width: 30,
|
|
770
|
+
align: 'center'
|
|
771
|
+
});
|
|
772
|
+
this.doc.rect(left + 208, top, 17, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
773
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
774
|
+
this.doc.text('CST', left + 208, top + 5.9, {
|
|
775
|
+
width: 17,
|
|
776
|
+
align: 'center'
|
|
777
|
+
});
|
|
778
|
+
this.doc.rect(left + 225, top, 28, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
779
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
780
|
+
this.doc.text('CFOP', left + 225, top + 5.9, {
|
|
781
|
+
width: 28,
|
|
782
|
+
align: 'center'
|
|
783
|
+
});
|
|
784
|
+
this.doc.rect(left + 253, top, 23, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
785
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
786
|
+
this.doc.text('UNID.', left + 253, top + 5.9, {
|
|
787
|
+
width: 23,
|
|
788
|
+
align: 'center'
|
|
789
|
+
});
|
|
790
|
+
this.doc.rect(left + 276, top, 25, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
791
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
792
|
+
this.doc.text('QUANT.', left + 276, top + 5.9, {
|
|
793
|
+
width: 25,
|
|
794
|
+
align: 'center'
|
|
795
|
+
});
|
|
796
|
+
this.doc.rect(left + 301, top, 37.23, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
797
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
798
|
+
this.doc.text('VALOR UNITÁRIO', left + 301, top + 2.9, {
|
|
799
|
+
width: 37.23,
|
|
800
|
+
align: 'center'
|
|
801
|
+
});
|
|
802
|
+
this.doc.rect(left + 338.23, top, 39.23, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
803
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
804
|
+
this.doc.text('VALOR DESCONTO', left + 338.23, top + 2.9, {
|
|
805
|
+
width: 39.23,
|
|
806
|
+
align: 'center'
|
|
807
|
+
});
|
|
808
|
+
this.doc.rect(left + 377.46, top, 33.23, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
809
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
810
|
+
this.doc.text('VALOR LIQUIDO', left + 377.46, top + 2.9, {
|
|
811
|
+
width: 33.23,
|
|
812
|
+
align: 'center'
|
|
813
|
+
});
|
|
814
|
+
this.doc.rect(left + 410.69, top, 38, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
815
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
816
|
+
this.doc.text('BASE CÁLC. ICMS', left + 413.8, top + 2.9, {
|
|
817
|
+
width: 32,
|
|
818
|
+
align: 'center'
|
|
819
|
+
});
|
|
820
|
+
this.doc.rect(left + 448.69, top, 35, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
821
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
822
|
+
this.doc.text('VALOR I.C.M.S.', left + 448.69, top + 2.9, {
|
|
823
|
+
width: 35,
|
|
824
|
+
align: 'center'
|
|
825
|
+
});
|
|
826
|
+
this.doc.rect(left + 483.69, top, 38, defaultItemHeight).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
827
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
828
|
+
this.doc.text('VALOR I.P.I.', left + 490.69, top + 2.9, {
|
|
829
|
+
width: 25,
|
|
830
|
+
align: 'center'
|
|
831
|
+
});
|
|
832
|
+
this.doc.rect(left + 521.69, top, 45.2, 7.5).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
833
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
834
|
+
this.doc.text('ALÍQUOTAS', left + 521.69, top + 2, {
|
|
835
|
+
width: 45,
|
|
836
|
+
align: 'center'
|
|
837
|
+
});
|
|
838
|
+
this.doc.rect(left + 521.69, top + 7.5, 22.5, 7.5).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
839
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
840
|
+
this.doc.text('ICMS', left + 521.69, top + 9.5, {
|
|
841
|
+
width: 22.5,
|
|
842
|
+
align: 'center'
|
|
843
|
+
});
|
|
844
|
+
this.doc.rect(left + 544.19, top + 7.5, 22.75, 7.5).fillAndStroke('#DDDDDD', '#1c1c1c');
|
|
845
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
846
|
+
this.doc.text('IPI', left + 544.19, top + 9.5, {
|
|
847
|
+
width: 22.5,
|
|
848
|
+
align: 'center'
|
|
849
|
+
});
|
|
850
|
+
};
|
|
851
|
+
const row = (top, item) => {
|
|
852
|
+
function getCST(ICMS) {
|
|
853
|
+
const chavesICMS = Object.keys(ICMS);
|
|
854
|
+
const listaIcmsSemCST = [
|
|
855
|
+
'ICMSSN101',
|
|
856
|
+
'ICMSSN102',
|
|
857
|
+
'ICMSSN201',
|
|
858
|
+
'ICMSSN202',
|
|
859
|
+
'ICMSSN500',
|
|
860
|
+
'ICMSSN900'
|
|
861
|
+
];
|
|
862
|
+
const icmsSemCST = listaIcmsSemCST.includes(chavesICMS[0]);
|
|
863
|
+
let CST = '';
|
|
864
|
+
if (chavesICMS.length > 0) {
|
|
865
|
+
const tipoICMS = chavesICMS[0];
|
|
866
|
+
if (!icmsSemCST) {
|
|
867
|
+
CST = ICMS[tipoICMS].CST;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
return CST;
|
|
871
|
+
}
|
|
872
|
+
function getValoresItem(ICMS) {
|
|
873
|
+
const chavesICMS = Object.keys(ICMS);
|
|
874
|
+
const listaIcmsSemvBC = [
|
|
875
|
+
'ICMS02',
|
|
876
|
+
'ICMS15',
|
|
877
|
+
'ICMS30',
|
|
878
|
+
'ICMS40',
|
|
879
|
+
'ICMS53',
|
|
880
|
+
'ICMS60',
|
|
881
|
+
'ICMS61',
|
|
882
|
+
'ICMSST',
|
|
883
|
+
'ICMSSN101',
|
|
884
|
+
'ICMSSN102',
|
|
885
|
+
'ICMSSN201',
|
|
886
|
+
'ICMSSN202',
|
|
887
|
+
'ICMSSN500'
|
|
888
|
+
];
|
|
889
|
+
const icmsSemvBC = listaIcmsSemvBC.includes(chavesICMS[0]);
|
|
890
|
+
let vBC = '0,00';
|
|
891
|
+
let vICMS = '0,00';
|
|
892
|
+
let pICMS = '0,00';
|
|
893
|
+
if (chavesICMS.length > 0) {
|
|
894
|
+
const tipoICMS = chavesICMS[0];
|
|
895
|
+
if (!icmsSemvBC) {
|
|
896
|
+
vBC = ICMS[tipoICMS].vBC;
|
|
897
|
+
vICMS = ICMS[tipoICMS].vICMS;
|
|
898
|
+
pICMS = ICMS[tipoICMS].pICMS;
|
|
899
|
+
return {
|
|
900
|
+
vBC: parseFloat(vBC).toFixed(2),
|
|
901
|
+
vICMS: parseFloat(vBC).toFixed(2),
|
|
902
|
+
pICMS: parseFloat(pICMS).toFixed(2)
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return { vBC, vICMS, pICMS };
|
|
907
|
+
}
|
|
908
|
+
function getValoresIPI(IPI) {
|
|
909
|
+
if (!IPI) {
|
|
910
|
+
return {
|
|
911
|
+
vIPI: '0,00',
|
|
912
|
+
pIPI: '0,00'
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
let vIPI = parseFloat(String(IPI.IPITrib.vIPI)).toFixed(2);
|
|
916
|
+
let pIPI = parseFloat(String(IPI.IPITrib.pIPI)).toFixed(2);
|
|
917
|
+
return { vIPI, pIPI };
|
|
918
|
+
}
|
|
919
|
+
const CST = getCST(item.imposto.ICMS);
|
|
920
|
+
const { vIPI, pIPI } = getValoresIPI(item.imposto.IPI);
|
|
921
|
+
const { vBC, vICMS, pICMS } = getValoresItem(item.imposto.ICMS);
|
|
922
|
+
const text = item.infAdProd ? `${item.prod.xProd || ''}\n${item.infAdProd}` : item.prod.xProd || '';
|
|
923
|
+
const textHeight = this.doc.heightOfString(text, {
|
|
924
|
+
width: 138,
|
|
925
|
+
align: 'center'
|
|
926
|
+
});
|
|
927
|
+
const itemHeight = Math.max(defaultItemHeight, textHeight + 10); // 10 is padding
|
|
928
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
929
|
+
this.doc.rect(left, top, 40, itemHeight).stroke();
|
|
930
|
+
this.doc.font('Times-Roman').fontSize(6).text(item.prod.cProd || '', left + 2, top + 3, {
|
|
931
|
+
width: 40,
|
|
932
|
+
});
|
|
933
|
+
this.doc.rect(left + 40, top, 138, itemHeight).stroke();
|
|
934
|
+
this.doc.text(text, left + 43, top + 4, {
|
|
935
|
+
width: 137,
|
|
936
|
+
});
|
|
937
|
+
this.doc.rect(left + 178, top, 30, itemHeight).stroke();
|
|
938
|
+
this.doc.text(String(item.prod.NCM) || '', left + 178, top + 5.9, {
|
|
939
|
+
width: 30,
|
|
940
|
+
align: 'center'
|
|
941
|
+
});
|
|
942
|
+
this.doc.rect(left + 208, top, 17, itemHeight).stroke();
|
|
943
|
+
this.doc.text(CST, left + 208, top + 5.9, {
|
|
944
|
+
width: 17,
|
|
945
|
+
align: 'center'
|
|
946
|
+
});
|
|
947
|
+
this.doc.rect(left + 225, top, 28, itemHeight).stroke();
|
|
948
|
+
this.doc.text(String(item.prod.CFOP || ''), left + 225, top + 5.9, {
|
|
949
|
+
width: 28,
|
|
950
|
+
align: 'center'
|
|
951
|
+
});
|
|
952
|
+
this.doc.rect(left + 253, top, 23, itemHeight).stroke();
|
|
953
|
+
this.doc.text(item.prod.uCom || item.prod.uTrib || '', left + 256, top + 5.9, {
|
|
954
|
+
width: 23,
|
|
955
|
+
});
|
|
956
|
+
const quant = parseFloat(String(item.prod.qCom || item.prod.qTrib)).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
957
|
+
this.doc.rect(left + 276, top, 25, itemHeight).stroke();
|
|
958
|
+
this.doc.text(String(quant || ''), left + 274.5, top + 5.9, {
|
|
959
|
+
width: 25,
|
|
960
|
+
align: 'right'
|
|
961
|
+
});
|
|
962
|
+
const valUnit = parseFloat(String(item.prod.vUnCom || item.prod.vUnTrib || '0')).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
963
|
+
this.doc.rect(left + 301, top, 37.23, itemHeight).stroke();
|
|
964
|
+
this.doc.text(valUnit, left + 299.5, top + 5.9, {
|
|
965
|
+
width: 37.23,
|
|
966
|
+
align: 'right'
|
|
967
|
+
});
|
|
968
|
+
const valDesc = parseFloat(String(item.prod.vDesc || '0')).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
969
|
+
this.doc.rect(left + 338.23, top, 39.23, itemHeight).stroke();
|
|
970
|
+
this.doc.text(valDesc, left + 336.73, top + 5.9, {
|
|
971
|
+
width: 39.23,
|
|
972
|
+
align: 'right'
|
|
973
|
+
});
|
|
974
|
+
const valLiq = parseFloat(String(item.prod.vProd || '0')).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
975
|
+
this.doc.rect(left + 377.46, top, 33.23, itemHeight).stroke();
|
|
976
|
+
this.doc.text(valLiq, left + 375.96, top + 5.9, {
|
|
977
|
+
width: 33.23,
|
|
978
|
+
align: 'right'
|
|
979
|
+
});
|
|
980
|
+
this.doc.rect(left + 410.69, top, 38, itemHeight).stroke();
|
|
981
|
+
this.doc.text(vBC, left + 409.19, top + 5.9, {
|
|
982
|
+
width: 38,
|
|
983
|
+
align: 'right'
|
|
984
|
+
});
|
|
985
|
+
this.doc.rect(left + 448.69, top, 35, itemHeight).stroke();
|
|
986
|
+
this.doc.text(vICMS, left + 447.19, top + 5.9, {
|
|
987
|
+
width: 35,
|
|
988
|
+
align: 'right'
|
|
989
|
+
});
|
|
990
|
+
this.doc.rect(left + 483.69, top, 38, itemHeight).stroke();
|
|
991
|
+
this.doc.text(vIPI, left + 482.19, top + 5.9, {
|
|
992
|
+
width: 38,
|
|
993
|
+
align: 'right'
|
|
994
|
+
});
|
|
995
|
+
this.doc.rect(left + 521.69, top, 22.5, itemHeight).stroke();
|
|
996
|
+
this.doc.text(pICMS, left + 520.19, top + 5.9, {
|
|
997
|
+
width: 22.5,
|
|
998
|
+
align: 'right'
|
|
999
|
+
});
|
|
1000
|
+
this.doc.rect(left + 544.19, top, 22.75, itemHeight).stroke();
|
|
1001
|
+
this.doc.text(pIPI, left + 542.69, top + 5.9, {
|
|
1002
|
+
width: 22.5,
|
|
1003
|
+
align: 'right'
|
|
1004
|
+
});
|
|
1005
|
+
return itemHeight;
|
|
1006
|
+
};
|
|
1007
|
+
header(458);
|
|
1008
|
+
const createTable = (prod) => {
|
|
1009
|
+
if (y + defaultItemHeight > this.doc.page.height - 160) {
|
|
1010
|
+
this.doc.addPage();
|
|
1011
|
+
currentPage++;
|
|
1012
|
+
if (currentPage > 0) {
|
|
1013
|
+
y = 185;
|
|
1014
|
+
this.doc.fontSize(6).font('Times-Bold').fillColor('black').text('DADOS DO PRODUTO / SERVIÇOS', left, 175, {
|
|
1015
|
+
characterSpacing: 0.5,
|
|
1016
|
+
});
|
|
1017
|
+
header(185);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
const itemHeight = row(y + 15, prod);
|
|
1021
|
+
y += itemHeight;
|
|
1022
|
+
};
|
|
1023
|
+
// Adicionando itens da tabela
|
|
1024
|
+
if (this.det instanceof Array) {
|
|
1025
|
+
for (let i = 0; i < this.det.length; i++) {
|
|
1026
|
+
const prod = this.det[i];
|
|
1027
|
+
createTable(prod);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
else {
|
|
1031
|
+
createTable(this.det);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
_buildFooter() {
|
|
1035
|
+
const { left } = this.doc.page.margins;
|
|
1036
|
+
this.setLineStyle(0.75, '#1c1c1c');
|
|
1037
|
+
const topDestinatario = 820.45 - 88.5;
|
|
1038
|
+
this.doc.fontSize(6).font('Times-Bold').text('DADOS ADICIONAIS', left, topDestinatario - 5, {
|
|
1039
|
+
characterSpacing: 0.5,
|
|
1040
|
+
});
|
|
1041
|
+
this.doc.rect(left, topDestinatario, 408, 95).stroke();
|
|
1042
|
+
this.doc.fontSize(5).font('Times-Roman').text('INFORMAÇÕES COMPLEMENTARES', 10, topDestinatario + 4.5, {
|
|
1043
|
+
characterSpacing: 0.5
|
|
1044
|
+
});
|
|
1045
|
+
this.doc.fontSize(8).text(this.infAdic?.infCpl || '', 13, topDestinatario + 13, {
|
|
1046
|
+
characterSpacing: 1,
|
|
1047
|
+
width: 400,
|
|
1048
|
+
});
|
|
1049
|
+
this.doc.rect(left + 408, topDestinatario, 158.93, 95).stroke();
|
|
1050
|
+
this.doc.fontSize(5).text('RESERVADO AO FISCO', 408 + 10, topDestinatario + 4.5, {
|
|
1051
|
+
characterSpacing: 0.5
|
|
1052
|
+
});
|
|
1053
|
+
this.doc.fontSize(8).text(String(this.infAdic?.infAdFisco || ''), 13, topDestinatario + 13, {
|
|
1054
|
+
characterSpacing: 1,
|
|
1055
|
+
width: 400,
|
|
1056
|
+
});
|
|
1057
|
+
if (this.exibirMarcaDaguaDanfe) {
|
|
1058
|
+
const topPosition = Number(Number(this.ide.tpAmb)) !== 2 ? topDestinatario + 38 : topDestinatario + 58;
|
|
1059
|
+
const leftPosition = Number(Number(this.ide.tpAmb)) !== 2 ? left + 150 : left + 100;
|
|
1060
|
+
this.doc.fontSize(26).font('Times-Bold').fillColor('#c7c7c7').text('Treeunfe DFe', leftPosition, topPosition, {
|
|
1061
|
+
characterSpacing: 0.5,
|
|
1062
|
+
});
|
|
1063
|
+
}
|
|
1064
|
+
if (Number(Number(this.ide.tpAmb)) === 2) {
|
|
1065
|
+
this.doc.fontSize(14).font('Times-Bold').fillColor('grey').text('AMBIENTE DE HOMOLOGAÇÃO - NF-E SEM VALOR FISCAL', left + 100, topDestinatario + 45, {
|
|
1066
|
+
characterSpacing: 1
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
// .rotate(45, { origin: [0, 0] })
|
|
1070
|
+
}
|
|
1071
|
+
async generatePDF(exibirMarcaDaguaDanfe) {
|
|
1072
|
+
try {
|
|
1073
|
+
this.exibirMarcaDaguaDanfe = exibirMarcaDaguaDanfe ?? true;
|
|
1074
|
+
const chave = this.chave;
|
|
1075
|
+
await this.generateBarcode(chave);
|
|
1076
|
+
this.doc.pipe(fs.createWriteStream(this.outputPath));
|
|
1077
|
+
this.drawHeader(true);
|
|
1078
|
+
this._buildDestinatario();
|
|
1079
|
+
this._builCalculoImposto();
|
|
1080
|
+
this._builTransporte();
|
|
1081
|
+
this.doc.on('pageAdded', () => {
|
|
1082
|
+
this.drawHeader(false);
|
|
1083
|
+
});
|
|
1084
|
+
this.drawFooter();
|
|
1085
|
+
this.doc.on('pageAdded', () => {
|
|
1086
|
+
this.drawFooter();
|
|
1087
|
+
});
|
|
1088
|
+
this._buildProdutos();
|
|
1089
|
+
this.doc.end();
|
|
1090
|
+
return {
|
|
1091
|
+
message: ` DANFE Gerada em '${this.outputPath}'`,
|
|
1092
|
+
success: true,
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
catch (error) {
|
|
1096
|
+
throw new Error(`Erro ao gerar DANFE: ${error.message}`);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* @description :
|
|
1103
|
+
* @author : Marco Aurélio Silva Lima
|
|
1104
|
+
* @group :
|
|
1105
|
+
* @created :
|
|
1106
|
+
*
|
|
1107
|
+
* MODIFICATION LOG
|
|
1108
|
+
* - Version : 1.0.0
|
|
1109
|
+
* - Date : 3/7/2025
|
|
1110
|
+
* - Author : Cassio Seffrin
|
|
1111
|
+
* - Modification :
|
|
1112
|
+
**/
|
|
1113
|
+
/*
|
|
1114
|
+
* This file is part of Treeunfe DFe.
|
|
1115
|
+
*
|
|
1116
|
+
* Treeunfe DFe is free software: you can redistribute it and/or modify
|
|
1117
|
+
* it under the terms of the GNU General Public License as published by
|
|
1118
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
1119
|
+
* (at your option) any later version.
|
|
1120
|
+
*
|
|
1121
|
+
* Treeunfe DFe is distributed in the hope that it will be useful,
|
|
1122
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
1123
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
1124
|
+
* GNU General Public License for more details.
|
|
1125
|
+
*
|
|
1126
|
+
* You should have received a copy of the GNU General Public License
|
|
1127
|
+
* along with Treeunfe DFe. If not, see <https://www.gnu.org/licenses/>.
|
|
1128
|
+
*/
|
|
1129
|
+
const baseDir = path.dirname(fileURLToPath(import.meta.url));
|
|
1130
|
+
const fontDir = process.env.NODE_ENV === 'production' ? '../resources/fonts/ARIAL.TTF' : '../../../../resources/fonts/ARIAL.TTF';
|
|
1131
|
+
const fontDirBold = process.env.NODE_ENV === 'production' ? '../resources/fonts/ARIALBD.TTF' : '../../../../resources/fonts/ARIALBD.TTF';
|
|
1132
|
+
class NFCEGerarDanfe {
|
|
1133
|
+
constructor(props) {
|
|
1134
|
+
this.saveQRCode = async (text) => {
|
|
1135
|
+
const filePath = path.resolve(baseDir, this.qrcodePath);
|
|
1136
|
+
try {
|
|
1137
|
+
await QRCode.toFile(`${filePath}/qrcode.png`, text, {
|
|
1138
|
+
color: {
|
|
1139
|
+
dark: '#000000', // Cor do código
|
|
1140
|
+
light: '#FFFFFF', // Cor de fundo
|
|
1141
|
+
},
|
|
1142
|
+
width: 300, // Largura da imagem
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
catch (error) {
|
|
1146
|
+
console.error('Erro ao gerar o QR code:', error);
|
|
1147
|
+
console.error(error.stack);
|
|
1148
|
+
}
|
|
1149
|
+
};
|
|
1150
|
+
this.getQRCodeBuffer = async (text) => {
|
|
1151
|
+
try {
|
|
1152
|
+
const buffer = await QRCode.toBuffer(text, {
|
|
1153
|
+
color: {
|
|
1154
|
+
dark: '#000000', // Cor do código
|
|
1155
|
+
light: '#FFFFFF', // Cor de fundo
|
|
1156
|
+
},
|
|
1157
|
+
width: 300, // Largura da imagem
|
|
1158
|
+
});
|
|
1159
|
+
return buffer;
|
|
1160
|
+
}
|
|
1161
|
+
catch (error) {
|
|
1162
|
+
console.error('Erro ao gerar o QR code:', error);
|
|
1163
|
+
console.error(error.stack);
|
|
1164
|
+
throw new Error(`Erro ao gerar o QR code: ${error.message}`);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
const { data, chave, outputPath, pageWidth } = props;
|
|
1168
|
+
this.data = data;
|
|
1169
|
+
this.chave = chave.trim();
|
|
1170
|
+
this.outputPath = outputPath;
|
|
1171
|
+
this.enviada = false; // Valor padrão
|
|
1172
|
+
this.qrcodePath = outputPath; // Caminho padrão
|
|
1173
|
+
this.documento = new ValidaCPFCNPJ(); // Inicialização correta
|
|
1174
|
+
this.protNFe = data.protNFe;
|
|
1175
|
+
const nfeData = Array.isArray(data.NFe) ? data.NFe[0] : data.NFe;
|
|
1176
|
+
const { det, ide, emit, dest, total, transp, pag, infAdic } = nfeData.infNFe;
|
|
1177
|
+
const infNFeSupl = nfeData.infNFeSupl;
|
|
1178
|
+
this.det = det;
|
|
1179
|
+
this.ide = ide;
|
|
1180
|
+
this.emit = emit;
|
|
1181
|
+
this.total = total;
|
|
1182
|
+
this.transp = transp;
|
|
1183
|
+
this.pag = pag;
|
|
1184
|
+
this.infAdic = infAdic;
|
|
1185
|
+
this.infNFeSupl = infNFeSupl;
|
|
1186
|
+
if (dest)
|
|
1187
|
+
this.dest = dest;
|
|
1188
|
+
if (this.protNFe?.infProt.nProt) {
|
|
1189
|
+
this.enviada = true;
|
|
1190
|
+
}
|
|
1191
|
+
function calculateHeight(itemsLength, itemHeight) {
|
|
1192
|
+
const headerHeight = 34.22975675056; // Altura do cabeçalho
|
|
1193
|
+
const footerHeight = 170; // Altura do rodapé -> 34.22975675056
|
|
1194
|
+
// Altura total é a soma das alturas dos itens + cabeçalho + rodapé
|
|
1195
|
+
return headerHeight + footerHeight + (itemsLength * itemHeight) + 5;
|
|
1196
|
+
}
|
|
1197
|
+
function calculateFontSize(width) {
|
|
1198
|
+
// Aqui você pode ajustar a fórmula para atender às suas necessidades
|
|
1199
|
+
return Math.min(width) * 0.02646;
|
|
1200
|
+
}
|
|
1201
|
+
this.larguraPadrao = 226.772;
|
|
1202
|
+
this.documentWidth = pageWidth || 226.772; // 158.74
|
|
1203
|
+
// const pageHeight = 300;
|
|
1204
|
+
let itensLength = 1;
|
|
1205
|
+
if (this.det instanceof Array) {
|
|
1206
|
+
itensLength = this.det.length;
|
|
1207
|
+
}
|
|
1208
|
+
const fontSize = calculateFontSize(this.documentWidth);
|
|
1209
|
+
this.fontSize = fontSize;
|
|
1210
|
+
this.itemHeight = fontSize * 1.116;
|
|
1211
|
+
const pageHeight = calculateHeight(itensLength, this.itemHeight);
|
|
1212
|
+
const fontPath = path.resolve(baseDir, fontDir);
|
|
1213
|
+
const fontPathBold = path.resolve(baseDir, fontDirBold);
|
|
1214
|
+
this.doc = new PDFDocument({
|
|
1215
|
+
margins: { top: 5.67, right: 5.67, bottom: 5.67, left: 5.67 },
|
|
1216
|
+
size: [this.documentWidth, pageHeight],
|
|
1217
|
+
bufferPages: true,
|
|
1218
|
+
layout: 'portrait',
|
|
1219
|
+
});
|
|
1220
|
+
this.doc.registerFont('Arial', fontPath);
|
|
1221
|
+
this.doc.registerFont('Arial-bold', fontPathBold);
|
|
1222
|
+
}
|
|
1223
|
+
createDir(path) {
|
|
1224
|
+
if (!fs.existsSync(path)) {
|
|
1225
|
+
fs.mkdirSync(path, { recursive: true });
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
async generateBarcode(data) {
|
|
1229
|
+
try {
|
|
1230
|
+
const png = await bwipjs.toBuffer({
|
|
1231
|
+
bcid: 'code128', // Tipo de código de barras
|
|
1232
|
+
text: data, // Dado a ser codificado
|
|
1233
|
+
scaleX: 4, // Fator de escala
|
|
1234
|
+
height: 14, // Altura da barra
|
|
1235
|
+
includetext: false, // Incluir texto
|
|
1236
|
+
});
|
|
1237
|
+
const barcode = png.toString('base64');
|
|
1238
|
+
const buffer = Buffer.from(barcode, 'base64');
|
|
1239
|
+
const barcodeDir = this.qrcodePath;
|
|
1240
|
+
const barcodeFilePath = path.join(barcodeDir, 'barcode.png');
|
|
1241
|
+
// this.createDir(barcodeDir);
|
|
1242
|
+
fs.writeFileSync(barcodeFilePath, buffer);
|
|
1243
|
+
return buffer;
|
|
1244
|
+
}
|
|
1245
|
+
catch (err) {
|
|
1246
|
+
console.error('Erro ao gerar código de barras:', err);
|
|
1247
|
+
return null;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
centeredPos(texto) {
|
|
1251
|
+
const larguraPagina = this.doc.page.width;
|
|
1252
|
+
const larguraTexto = this.doc.fontSize(this.fontSize).widthOfString(texto);
|
|
1253
|
+
const posicaoX = (larguraPagina - larguraTexto) / 2;
|
|
1254
|
+
return posicaoX;
|
|
1255
|
+
}
|
|
1256
|
+
ajustarPosicao(posicaoOriginal, novaLargura) {
|
|
1257
|
+
return posicaoOriginal * (novaLargura / this.larguraPadrao);
|
|
1258
|
+
}
|
|
1259
|
+
calculaPosicao(text) {
|
|
1260
|
+
const { right, left } = this.doc.page.margins;
|
|
1261
|
+
const [pageWidth] = this.doc.page.size;
|
|
1262
|
+
const textWidth = this.doc.widthOfString(text);
|
|
1263
|
+
return Number(pageWidth) - textWidth - right - left;
|
|
1264
|
+
}
|
|
1265
|
+
drawHeader(_isFirstPage) {
|
|
1266
|
+
this._buildHeader();
|
|
1267
|
+
}
|
|
1268
|
+
drawFooter(qrCodeBuffer) {
|
|
1269
|
+
this._buildFooter(qrCodeBuffer);
|
|
1270
|
+
}
|
|
1271
|
+
_buildHeader() {
|
|
1272
|
+
const CNPJCPF = this.emit.CNPJCPF?.toString();
|
|
1273
|
+
const CNPJ = this.emit.CNPJ?.toString();
|
|
1274
|
+
const CPF = this.emit.CPF?.toString();
|
|
1275
|
+
const documento = this.documento.mascaraCnpjCpf(CNPJCPF || CNPJ || CPF || '');
|
|
1276
|
+
const identificationJoined = `${this.emit.enderEmit.xLgr}, ${this.emit.enderEmit.nro}, ${this.emit.enderEmit.xBairro}, ${this.emit.enderEmit.UF}`;
|
|
1277
|
+
/** IDENTIFICACAO EMITENTE */
|
|
1278
|
+
const _buildIdentificacaoEmit = () => {
|
|
1279
|
+
const centeredPosEmit = this.centeredPos(`CNPJ: ${documento} ${this.emit.xNome}`);
|
|
1280
|
+
const centeredPosEnd = this.centeredPos(identificationJoined);
|
|
1281
|
+
const centeredPosText = this.centeredPos('Documento Auxiliar da Nota Fiscal de Consumidor Eletrônica');
|
|
1282
|
+
this.doc.font('Arial').fontSize(this.fontSize).text(`CNPJ: ${documento} `, centeredPosEmit, 2, {
|
|
1283
|
+
lineBreak: false,
|
|
1284
|
+
})
|
|
1285
|
+
.font('Arial-bold').text(this.emit.xNome)
|
|
1286
|
+
.fontSize(this.fontSize)
|
|
1287
|
+
.font('Arial')
|
|
1288
|
+
.text(identificationJoined, centeredPosEnd)
|
|
1289
|
+
.text('Documento Auxiliar da Nota Fiscal de Consumidor Eletrônica', centeredPosText);
|
|
1290
|
+
};
|
|
1291
|
+
_buildIdentificacaoEmit();
|
|
1292
|
+
}
|
|
1293
|
+
_buildProdutos() {
|
|
1294
|
+
const { right, left, top } = this.doc.page.margins;
|
|
1295
|
+
const tableWidth = this.documentWidth - left - right;
|
|
1296
|
+
const startX = left;
|
|
1297
|
+
const tableTop = this.doc.y + top;
|
|
1298
|
+
const columnRatios = {
|
|
1299
|
+
codigo: 0.15,
|
|
1300
|
+
descricao: 0.40,
|
|
1301
|
+
qtdeUn: 0.15,
|
|
1302
|
+
unit: 0.15,
|
|
1303
|
+
total: 0.15
|
|
1304
|
+
};
|
|
1305
|
+
const columnSpacing = 0;
|
|
1306
|
+
const columnWidths = {
|
|
1307
|
+
codigo: tableWidth * columnRatios.codigo,
|
|
1308
|
+
descricao: tableWidth * columnRatios.descricao,
|
|
1309
|
+
qtdeUn: tableWidth * columnRatios.qtdeUn,
|
|
1310
|
+
unit: tableWidth * columnRatios.unit,
|
|
1311
|
+
total: tableWidth * columnRatios.total
|
|
1312
|
+
};
|
|
1313
|
+
const header = (top) => {
|
|
1314
|
+
let x = startX;
|
|
1315
|
+
this.doc.font('Arial-bold').fontSize(this.fontSize).text('Código', x, top, { width: columnWidths.codigo });
|
|
1316
|
+
x += columnWidths.codigo + columnSpacing;
|
|
1317
|
+
this.doc.text('Descrição', x, top, { width: columnWidths.descricao });
|
|
1318
|
+
x += columnWidths.descricao + columnSpacing;
|
|
1319
|
+
this.doc.text('Qtde', x, top, { width: columnWidths.qtdeUn, align: 'right' });
|
|
1320
|
+
x += columnWidths.qtdeUn + columnSpacing;
|
|
1321
|
+
this.doc.text('Unit', x, top, { width: columnWidths.unit, align: 'right' });
|
|
1322
|
+
x += columnWidths.unit + columnSpacing;
|
|
1323
|
+
this.doc.text('Total', x, top, { width: columnWidths.total, align: 'right' });
|
|
1324
|
+
};
|
|
1325
|
+
const row = (top, item) => {
|
|
1326
|
+
const quant = parseFloat(String(item.prod.qCom || item.prod.qTrib)).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1327
|
+
const valUnit = parseFloat(String(item.prod.vUnCom || item.prod.vUnTrib || '0')).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
1328
|
+
const valLiq = parseFloat(String(item.prod.vProd || '0')).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
1329
|
+
let x = startX;
|
|
1330
|
+
this.doc.font('Arial').fontSize(this.fontSize).text(item.prod.cProd, x, top, {
|
|
1331
|
+
width: columnWidths.codigo,
|
|
1332
|
+
align: 'left'
|
|
1333
|
+
});
|
|
1334
|
+
x += columnWidths.codigo + columnSpacing;
|
|
1335
|
+
const descricao = item.prod.xProd.slice(0, 120); // Limite de 120 caracteres
|
|
1336
|
+
const textWidth = this.doc.widthOfString(descricao);
|
|
1337
|
+
const lineCount = Math.ceil(textWidth / columnWidths.descricao);
|
|
1338
|
+
const descricaoOptions = {
|
|
1339
|
+
width: columnWidths.descricao,
|
|
1340
|
+
align: 'left',
|
|
1341
|
+
height: this.itemHeight * lineCount
|
|
1342
|
+
};
|
|
1343
|
+
this.doc.text(descricao, x, top, descricaoOptions);
|
|
1344
|
+
x += columnWidths.descricao + columnSpacing;
|
|
1345
|
+
this.doc.text(`${quant} ${item.prod.uCom}`, x, top, {
|
|
1346
|
+
width: columnWidths.qtdeUn,
|
|
1347
|
+
align: 'right'
|
|
1348
|
+
});
|
|
1349
|
+
x += columnWidths.qtdeUn + columnSpacing;
|
|
1350
|
+
this.doc.text(valUnit, x, top, {
|
|
1351
|
+
width: columnWidths.unit,
|
|
1352
|
+
align: 'right'
|
|
1353
|
+
});
|
|
1354
|
+
x += columnWidths.unit + columnSpacing;
|
|
1355
|
+
this.doc.text(valLiq, x, top, {
|
|
1356
|
+
width: columnWidths.total,
|
|
1357
|
+
align: 'right'
|
|
1358
|
+
});
|
|
1359
|
+
return descricaoOptions.height;
|
|
1360
|
+
};
|
|
1361
|
+
header(tableTop);
|
|
1362
|
+
let y = tableTop + this.itemHeight;
|
|
1363
|
+
if (this.det instanceof Array) {
|
|
1364
|
+
this.det.forEach((prod) => {
|
|
1365
|
+
row(y, prod);
|
|
1366
|
+
y += this.itemHeight;
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
else {
|
|
1370
|
+
row(y, this.det);
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
_buildTotais() {
|
|
1374
|
+
let tableTop = this.doc.y + 5;
|
|
1375
|
+
const quantidadeTotalDeItens = Array.isArray(this.det) ? this.det.length : 1;
|
|
1376
|
+
let valTotal = 0;
|
|
1377
|
+
let acrescimo = 0;
|
|
1378
|
+
let desconto = 0;
|
|
1379
|
+
if (Array.isArray(this.det)) {
|
|
1380
|
+
// Calcula o valor total dos produtos
|
|
1381
|
+
valTotal = this.det.reduce((sum, item) => sum + parseFloat(item.prod.vProd), 0);
|
|
1382
|
+
// Calcula o total dos acréscimos
|
|
1383
|
+
acrescimo = this.det.reduce((sum, item) => sum + (parseFloat(item.prod.vFrete || '0') + parseFloat(item.prod.vSeg || '0') + parseFloat(item.prod.vOutro || '0')), 0);
|
|
1384
|
+
// Calcula o total dos descontos
|
|
1385
|
+
desconto = this.det.reduce((sum, item) => sum + parseFloat(item.prod.vDesc || '0'), 0);
|
|
1386
|
+
}
|
|
1387
|
+
else {
|
|
1388
|
+
// Calcula o valor total do produto, os acréscimos, e desconto caso não seja um array
|
|
1389
|
+
valTotal = parseFloat(this.det.prod.vProd);
|
|
1390
|
+
acrescimo = parseFloat(this.det.prod.vFrete || '0') + parseFloat(this.det.prod.vSeg || '0') + parseFloat(this.det.prod.vOutro || '0');
|
|
1391
|
+
desconto = parseFloat(this.det.prod.vDesc || '0');
|
|
1392
|
+
}
|
|
1393
|
+
const valorTotal = valTotal.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1394
|
+
const acrescimoTotal = acrescimo.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1395
|
+
const descontoTotal = desconto.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1396
|
+
this.doc.text('Qtd. total de itens', 2, tableTop);
|
|
1397
|
+
this.doc.text(String(quantidadeTotalDeItens), this.calculaPosicao(String(quantidadeTotalDeItens)), tableTop, {
|
|
1398
|
+
align: 'right',
|
|
1399
|
+
});
|
|
1400
|
+
tableTop += this.itemHeight;
|
|
1401
|
+
this.doc.text('Valor total R$', 2, tableTop);
|
|
1402
|
+
this.doc.text(valorTotal, this.calculaPosicao(valorTotal), tableTop, {
|
|
1403
|
+
align: 'right',
|
|
1404
|
+
});
|
|
1405
|
+
tableTop += this.itemHeight;
|
|
1406
|
+
if (desconto > 0) {
|
|
1407
|
+
this.doc.text('Desconto R$', 2, tableTop);
|
|
1408
|
+
this.doc.text(descontoTotal, this.calculaPosicao(descontoTotal), tableTop, {
|
|
1409
|
+
align: 'right',
|
|
1410
|
+
});
|
|
1411
|
+
tableTop += this.itemHeight;
|
|
1412
|
+
}
|
|
1413
|
+
if (acrescimo > 0) {
|
|
1414
|
+
this.doc.text('Acréscimo R$', 2, tableTop);
|
|
1415
|
+
this.doc.text(acrescimoTotal, this.calculaPosicao(acrescimoTotal), tableTop, {
|
|
1416
|
+
align: 'right',
|
|
1417
|
+
});
|
|
1418
|
+
tableTop += this.itemHeight;
|
|
1419
|
+
}
|
|
1420
|
+
if (desconto > 0 || acrescimo > 0) {
|
|
1421
|
+
const totalPagar = parseFloat(String(valTotal + acrescimo - desconto)).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1422
|
+
this.doc.font('Arial-bold').text('Valor a Pagar R$', 2, tableTop);
|
|
1423
|
+
this.doc.text(totalPagar, this.calculaPosicao(totalPagar), tableTop, {
|
|
1424
|
+
align: 'right',
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
tableTop += this.itemHeight + 2;
|
|
1428
|
+
this.doc.font('Arial').text('FORMA PAGAMENTO', 2, tableTop);
|
|
1429
|
+
// Tipos
|
|
1430
|
+
let topTiposPag = tableTop;
|
|
1431
|
+
if (Array.isArray(this.pag.detPag)) {
|
|
1432
|
+
for (let pagto of this.pag.detPag) {
|
|
1433
|
+
if (!pagto.xPag)
|
|
1434
|
+
pagto.xPag = getDesTipoPag(pagto.tPag);
|
|
1435
|
+
this.doc.text(pagto.xPag || 'Não informado', 2, topTiposPag + this.itemHeight);
|
|
1436
|
+
topTiposPag += this.itemHeight;
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
else {
|
|
1440
|
+
if (!this.pag.detPag.xPag)
|
|
1441
|
+
this.pag.detPag.xPag = getDesTipoPag(this.pag.detPag.tPag);
|
|
1442
|
+
this.doc.text(this.pag.detPag.xPag || 'Não informado', 2, topTiposPag + this.itemHeight);
|
|
1443
|
+
}
|
|
1444
|
+
this.doc.text('VALOR PAGO R$', this.calculaPosicao('VALOR PAGO R$'), tableTop, {
|
|
1445
|
+
align: 'right',
|
|
1446
|
+
});
|
|
1447
|
+
// Valores
|
|
1448
|
+
let topValPags = tableTop;
|
|
1449
|
+
if (Array.isArray(this.pag.detPag)) {
|
|
1450
|
+
for (let pagto of this.pag.detPag) {
|
|
1451
|
+
const val = parseFloat(pagto.vPag).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1452
|
+
this.doc.text(val, this.calculaPosicao(val), topValPags + this.itemHeight, {
|
|
1453
|
+
align: 'right',
|
|
1454
|
+
});
|
|
1455
|
+
topValPags += this.itemHeight;
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
else {
|
|
1459
|
+
const val = parseFloat(this.pag.detPag.vPag).toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1460
|
+
this.doc.text(val, this.calculaPosicao(val), topValPags + this.itemHeight, {
|
|
1461
|
+
align: 'right',
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
tableTop = topValPags;
|
|
1465
|
+
tableTop += 2 * this.itemHeight;
|
|
1466
|
+
let valTroco = 0;
|
|
1467
|
+
if (Array.isArray(this.pag.detPag)) {
|
|
1468
|
+
valTroco = this.pag.detPag.reduce((sum, item) => sum + parseFloat(item.vTroco || '0'), 0);
|
|
1469
|
+
}
|
|
1470
|
+
else {
|
|
1471
|
+
valTroco = parseFloat(this.pag.detPag.vTroco || '0');
|
|
1472
|
+
}
|
|
1473
|
+
const troco = valTroco.toLocaleString('pt-BR', { minimumFractionDigits: 2, maximumFractionDigits: 3 });
|
|
1474
|
+
this.doc.text('Troco R$', 2, tableTop);
|
|
1475
|
+
this.doc.text(troco, this.calculaPosicao(troco), tableTop, {
|
|
1476
|
+
align: 'right',
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
_buildFooter(qrCodeBuffer) {
|
|
1480
|
+
let tableTop = this.doc.y + 5;
|
|
1481
|
+
this.doc.font('Arial-bold').text('Consulte pela Chave de Acesso em', 0, tableTop, {
|
|
1482
|
+
align: 'center'
|
|
1483
|
+
});
|
|
1484
|
+
tableTop += this.itemHeight;
|
|
1485
|
+
this.doc.font('Arial').text(this.infNFeSupl?.urlChave || '', 0, tableTop, {
|
|
1486
|
+
align: 'center'
|
|
1487
|
+
});
|
|
1488
|
+
tableTop += this.itemHeight;
|
|
1489
|
+
this.doc.text(this.protNFe?.infProt.chNFe || '', 0, tableTop, {
|
|
1490
|
+
align: 'center'
|
|
1491
|
+
});
|
|
1492
|
+
tableTop += this.itemHeight;
|
|
1493
|
+
// const filePath = path.resolve(baseDir, this.qrcodePath);
|
|
1494
|
+
// this.doc.image(`${filePath}/qrcode.png`, 2, tableTop, { width: 70.87, height: 70.87 });
|
|
1495
|
+
this.doc.image(qrCodeBuffer, 2, tableTop, { width: 70.87, height: 70.87 });
|
|
1496
|
+
tableTop += 4;
|
|
1497
|
+
let topBeforeQrCode = tableTop;
|
|
1498
|
+
const CNPJCPF = this.documento.mascaraCnpjCpf(this.dest?.CNPJCPF || this.dest?.CNPJ || this.dest?.CPF || this.dest?.idEstrangeiro || '');
|
|
1499
|
+
const xNome = this.dest?.xNome ?? 'Sem cliente identificado';
|
|
1500
|
+
const xLgr = this.dest?.enderDest?.xLgr ?? '';
|
|
1501
|
+
const nro = this.dest?.enderDest?.nro ?? '';
|
|
1502
|
+
const xBairro = this.dest?.enderDest?.xBairro ?? null;
|
|
1503
|
+
const xMun = this.dest?.enderDest?.xMun ?? '';
|
|
1504
|
+
const UF = this.dest?.enderDest?.UF ?? '';
|
|
1505
|
+
const enderecoPartes = [
|
|
1506
|
+
xLgr && `${xLgr}`,
|
|
1507
|
+
nro && `${nro}`,
|
|
1508
|
+
xBairro && `bairro: ${xBairro}`,
|
|
1509
|
+
xMun && `${xMun}`,
|
|
1510
|
+
UF && `${UF}`
|
|
1511
|
+
].filter(Boolean);
|
|
1512
|
+
const enderecoStr = enderecoPartes.join(', ');
|
|
1513
|
+
if (CNPJCPF && CNPJCPF !== '') {
|
|
1514
|
+
this.doc.font('Arial-bold')
|
|
1515
|
+
.text(`CONSUMIDOR - DOC ${CNPJCPF}`, 75, tableTop, {
|
|
1516
|
+
align: 'left',
|
|
1517
|
+
lineGap: 1
|
|
1518
|
+
})
|
|
1519
|
+
.font('Arial')
|
|
1520
|
+
.text(` - ${xNome}`, {
|
|
1521
|
+
lineGap: 1
|
|
1522
|
+
});
|
|
1523
|
+
tableTop = this.doc.y + 4;
|
|
1524
|
+
this.doc.text(enderecoStr, 75, tableTop);
|
|
1525
|
+
tableTop = this.doc.y + 8;
|
|
1526
|
+
}
|
|
1527
|
+
else {
|
|
1528
|
+
this.doc.text('CONSUMIDOR NÃO IDENTIFICADO', 75, tableTop, {
|
|
1529
|
+
align: 'left',
|
|
1530
|
+
});
|
|
1531
|
+
tableTop = this.doc.y + 8;
|
|
1532
|
+
}
|
|
1533
|
+
const data = parseISO(this.ide.dhEmi);
|
|
1534
|
+
const dtaEmi = format(data, 'dd/MM/yyyy HH:mm:ss');
|
|
1535
|
+
let dtaAut = format(new Date(), 'dd/MM/yyyy HH:mm:ss');
|
|
1536
|
+
if (this.protNFe?.infProt.dhRecbto) {
|
|
1537
|
+
const dataAut = parseISO(this.protNFe?.infProt.dhRecbto);
|
|
1538
|
+
dtaAut = format(dataAut, 'dd/MM/yyyy HH:mm:ss');
|
|
1539
|
+
}
|
|
1540
|
+
this.doc.font('Arial-bold')
|
|
1541
|
+
.text(`NFC-e nº ${this.ide.nNF} Série ${this.ide.serie} ${dtaEmi}`, 75, tableTop, {
|
|
1542
|
+
align: 'left',
|
|
1543
|
+
lineGap: 1
|
|
1544
|
+
})
|
|
1545
|
+
.text('Protocolo de autorização: ', {
|
|
1546
|
+
continued: true,
|
|
1547
|
+
lineGap: 1,
|
|
1548
|
+
})
|
|
1549
|
+
.font('Arial')
|
|
1550
|
+
.text(this.protNFe?.infProt.nProt || '123')
|
|
1551
|
+
.font('Arial-bold')
|
|
1552
|
+
.text('Data de autorização ', {
|
|
1553
|
+
continued: true,
|
|
1554
|
+
lineGap: 1,
|
|
1555
|
+
})
|
|
1556
|
+
.font('Arial')
|
|
1557
|
+
.text(dtaAut);
|
|
1558
|
+
tableTop = this.doc.y + 20;
|
|
1559
|
+
topBeforeQrCode += 70.87;
|
|
1560
|
+
this.doc.text(`Tributos Totais Incidentes (Lei Federal 12.741/2012): R$ ${parseFloat(this.total.ICMSTot.vTotTrib || '0').toFixed(2)}`, 0, topBeforeQrCode, {
|
|
1561
|
+
align: 'center'
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
async generatePDF(exibirMarcaDaguaDanfe) {
|
|
1565
|
+
try {
|
|
1566
|
+
this.exibirMarcaDaguaDanfe = exibirMarcaDaguaDanfe || true;
|
|
1567
|
+
// await this.saveQRCode(this.infNFeSupl?.qrCode || '')
|
|
1568
|
+
const qrCodeBuffer = await this.getQRCodeBuffer(this.infNFeSupl?.qrCode || '');
|
|
1569
|
+
this.doc.pipe(fs.createWriteStream(this.outputPath));
|
|
1570
|
+
this.drawHeader(true);
|
|
1571
|
+
this._buildProdutos();
|
|
1572
|
+
this._buildTotais();
|
|
1573
|
+
this.drawFooter(qrCodeBuffer);
|
|
1574
|
+
this.doc.end();
|
|
1575
|
+
return {
|
|
1576
|
+
message: ` DANFE Gerada em '${this.outputPath}'`,
|
|
1577
|
+
success: true,
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
catch (error) {
|
|
1581
|
+
throw new Error(`Erro ao gerar DANFE: ${error.message}`);
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
export { NFCEGerarDanfe, NFEGerarDanfe };
|
|
1587
|
+
//# sourceMappingURL=index.mjs.map
|