@plasoft/boletos 1.0.7 → 1.0.8

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/build/index.d.mts CHANGED
@@ -43,13 +43,17 @@ interface IDadosPDF$1 {
43
43
  beneficiario: {
44
44
  nome: string;
45
45
  cnpj: string;
46
- dadosBancarios: {
46
+ dadosBancario: {
47
47
  carteira: string;
48
48
  convenio: string;
49
49
  agencia: string;
50
50
  agenciaDigito: string;
51
51
  conta: string;
52
52
  contaDigito: string;
53
+ juros?: number;
54
+ multa?: number;
55
+ desconto?: number;
56
+ protesto?: number;
53
57
  };
54
58
  endereco: {
55
59
  logradouro: string;
@@ -80,10 +84,12 @@ interface IDadosPDF$1 {
80
84
  usoDoBanco?: string;
81
85
  cip?: string;
82
86
  codigoBarra: string;
87
+ linhaDigitavel: string;
83
88
  codigoBarraImage?: string;
84
89
  instrucao1?: string;
85
90
  instrucao2?: string;
86
91
  instrucao3?: string;
92
+ instrucao4?: string;
87
93
  };
88
94
  }
89
95
  interface IGerarRemessaAilos {
@@ -315,6 +321,7 @@ declare enum Banco {
315
321
  }
316
322
 
317
323
  declare function gerar({ banco, dados }: IGerarBoleto): {
324
+ linhaDigitavel: string;
318
325
  fatorVencimento: string;
319
326
  valor: string;
320
327
  convenio: string;
@@ -323,15 +330,6 @@ declare function gerar({ banco, dados }: IGerarBoleto): {
323
330
  digitoGeral: string;
324
331
  codigoBarra: string;
325
332
  numeroDocumento: string;
326
- campo1: string;
327
- campo2: string;
328
- campo3: string;
329
- campo4: string;
330
- campo5: string;
331
- digito1: string;
332
- digito2: string;
333
- digito3: string;
334
- digito4: string;
335
333
  } | null | undefined;
336
334
 
337
335
  declare function pdf({ banco, dados }: IGerarPDF): Promise<{
@@ -357,7 +355,6 @@ interface IConfig {
357
355
  url?: string;
358
356
  authorization?: string;
359
357
  };
360
- printer?: boolean;
361
358
  }
362
359
  declare function defineConfig({ apiClient }: IConfig): void;
363
360
 
package/build/index.d.ts CHANGED
@@ -43,13 +43,17 @@ interface IDadosPDF$1 {
43
43
  beneficiario: {
44
44
  nome: string;
45
45
  cnpj: string;
46
- dadosBancarios: {
46
+ dadosBancario: {
47
47
  carteira: string;
48
48
  convenio: string;
49
49
  agencia: string;
50
50
  agenciaDigito: string;
51
51
  conta: string;
52
52
  contaDigito: string;
53
+ juros?: number;
54
+ multa?: number;
55
+ desconto?: number;
56
+ protesto?: number;
53
57
  };
54
58
  endereco: {
55
59
  logradouro: string;
@@ -80,10 +84,12 @@ interface IDadosPDF$1 {
80
84
  usoDoBanco?: string;
81
85
  cip?: string;
82
86
  codigoBarra: string;
87
+ linhaDigitavel: string;
83
88
  codigoBarraImage?: string;
84
89
  instrucao1?: string;
85
90
  instrucao2?: string;
86
91
  instrucao3?: string;
92
+ instrucao4?: string;
87
93
  };
88
94
  }
89
95
  interface IGerarRemessaAilos {
@@ -315,6 +321,7 @@ declare enum Banco {
315
321
  }
316
322
 
317
323
  declare function gerar({ banco, dados }: IGerarBoleto): {
324
+ linhaDigitavel: string;
318
325
  fatorVencimento: string;
319
326
  valor: string;
320
327
  convenio: string;
@@ -323,15 +330,6 @@ declare function gerar({ banco, dados }: IGerarBoleto): {
323
330
  digitoGeral: string;
324
331
  codigoBarra: string;
325
332
  numeroDocumento: string;
326
- campo1: string;
327
- campo2: string;
328
- campo3: string;
329
- campo4: string;
330
- campo5: string;
331
- digito1: string;
332
- digito2: string;
333
- digito3: string;
334
- digito4: string;
335
333
  } | null | undefined;
336
334
 
337
335
  declare function pdf({ banco, dados }: IGerarPDF): Promise<{
@@ -357,7 +355,6 @@ interface IConfig {
357
355
  url?: string;
358
356
  authorization?: string;
359
357
  };
360
- printer?: boolean;
361
358
  }
362
359
  declare function defineConfig({ apiClient }: IConfig): void;
363
360
 
package/build/index.js CHANGED
@@ -113,7 +113,9 @@ function gerarDadosBoleto({ dados }) {
113
113
  const digito2 = getDigito(campo2);
114
114
  const digito3 = getDigito(campo3);
115
115
  const digito4 = getDigito(campo4);
116
+ const linhaDigitavel = campo1 + digito1 + campo2 + digito2 + campo3 + digito3 + campo4 + digito4 + campo5;
116
117
  const dadosBoleto = {
118
+ linhaDigitavel,
117
119
  fatorVencimento,
118
120
  valor,
119
121
  convenio,
@@ -121,16 +123,7 @@ function gerarDadosBoleto({ dados }) {
121
123
  campoLivre,
122
124
  digitoGeral,
123
125
  codigoBarra: codigoBarra2,
124
- numeroDocumento,
125
- campo1,
126
- campo2,
127
- campo3,
128
- campo4,
129
- campo5,
130
- digito1,
131
- digito2,
132
- digito3,
133
- digito4
126
+ numeroDocumento
134
127
  };
135
128
  return dadosBoleto;
136
129
  } catch (error) {
@@ -203,11 +196,18 @@ function compileHbs(templatePath, data) {
203
196
  }
204
197
 
205
198
  // src/utils/maskFormat.ts
199
+ var import_string_mask = __toESM(require("string-mask"));
206
200
  function retornaCpfCnpjFormatado(cpfCnpj) {
207
- return cpfCnpj;
201
+ if ((cpfCnpj == null ? void 0 : cpfCnpj.length) <= 11) {
202
+ const formatter2 = new import_string_mask.default("000.000.000-00");
203
+ return formatter2.apply(cpfCnpj);
204
+ }
205
+ const formatter = new import_string_mask.default("00.000.000/0000-00");
206
+ return formatter.apply(cpfCnpj);
208
207
  }
209
208
  function retornaCEPFormatado(cep) {
210
- return cep;
209
+ const formatter = new import_string_mask.default("00000-000");
210
+ return formatter.apply(cep);
211
211
  }
212
212
  function numberToReal(numero) {
213
213
  numero = typeof numero === "string" ? parseFloat(numero) : numero;
@@ -216,7 +216,8 @@ function numberToReal(numero) {
216
216
  return numero.join(",");
217
217
  }
218
218
  function codigoBarra(codigo) {
219
- return codigo;
219
+ const formatter = new import_string_mask.default("00000.00000 00000.000000 00000.000000 0 000000000000000");
220
+ return formatter.apply(codigo);
220
221
  }
221
222
  var maskFormat_default = {
222
223
  numberToReal,
@@ -244,6 +245,7 @@ function getPathTemplates(template) {
244
245
  // src/ailos/gerarPDF.ts
245
246
  function gerarPDF(_0) {
246
247
  return __async(this, arguments, function* ({ dados }) {
248
+ var _a, _b, _c, _d;
247
249
  try {
248
250
  const { generatePDF, dadosPDF } = dados;
249
251
  const codigoBarra2 = yield import_bwip_js.default.toBuffer({
@@ -251,9 +253,9 @@ function gerarPDF(_0) {
251
253
  text: dadosPDF.boleto.codigoBarra,
252
254
  height: 20
253
255
  });
254
- dadosPDF.beneficiario.dadosBancarios.agencia = dadosPDF.beneficiario.dadosBancarios.agencia.padStart(4, "0");
255
- dadosPDF.beneficiario.dadosBancarios.conta = dadosPDF.beneficiario.dadosBancarios.conta.padStart(7, "0");
256
- dadosPDF.boleto.codigoBarra = maskFormat_default.codigoBarra(dadosPDF.boleto.codigoBarra);
256
+ dadosPDF.beneficiario.dadosBancario.agencia = dadosPDF.beneficiario.dadosBancario.agencia.padStart(4, "0");
257
+ dadosPDF.beneficiario.dadosBancario.conta = dadosPDF.beneficiario.dadosBancario.conta.padStart(7, "0");
258
+ dadosPDF.boleto.linhaDigitavel = maskFormat_default.codigoBarra(dadosPDF.boleto.linhaDigitavel);
257
259
  dadosPDF.boleto.codigoBarraImage = codigoBarra2.toString("base64");
258
260
  dadosPDF.beneficiario.cnpj = maskFormat_default.retornaCpfCnpjFormatado(
259
261
  dadosPDF.beneficiario.cnpj
@@ -283,6 +285,24 @@ function gerarPDF(_0) {
283
285
  if (dadosPDF.boleto.quantidade) {
284
286
  dadosPDF.boleto.quantidade = maskFormat_default.numberToReal(dadosPDF.boleto.quantidade);
285
287
  }
288
+ const jurosMes = Number(((_a = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _a.juros) || 0);
289
+ if (jurosMes > 0) {
290
+ const juros = Number(dadosPDF.boleto.valor) * jurosMes / 100 / 30;
291
+ dadosPDF.boleto.instrucao1 = `AP\xD3S O VENCIMENTO, COBRAR JUROS DE R$ ${numberToReal(juros)} POR DIA DE ATRASO`;
292
+ }
293
+ const descontoVencimento = Number(((_b = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _b.desconto) || 0);
294
+ if (descontoVencimento > 0) {
295
+ const desconto = Number(dadosPDF.boleto.valor) / 100 * descontoVencimento;
296
+ dadosPDF.boleto.instrucao2 = `AT\xC9 O VENCIMENTO, CONCEDER DESCONTO DE R$ ${numberToReal(desconto)}`;
297
+ }
298
+ const multaAtraso = Number(((_c = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _c.multa) || 0);
299
+ if (multaAtraso > 0) {
300
+ dadosPDF.boleto.instrucao3 = `MULTA DE ${numberToReal(multaAtraso)} %`;
301
+ }
302
+ const protestoDias = Number(((_d = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _d.protesto) || 0);
303
+ if (protestoDias > 0) {
304
+ dadosPDF.boleto.instrucao4 = `PROTESTAR AP\xD3S ${protestoDias} DIAS CORRIDOS DO VENCIMENTO`;
305
+ }
286
306
  dadosPDF.boleto.valor = maskFormat_default.numberToReal(dadosPDF.boleto.valor);
287
307
  const content = compileHbs(getPathTemplates("ailos-boleto.hbs"), dadosPDF);
288
308
  const config = {
@@ -648,7 +668,9 @@ function gerarDadosBoleto2({ dados }) {
648
668
  const digito2 = getDigito2(campo2);
649
669
  const digito3 = getDigito2(campo3);
650
670
  const digito4 = getDigito2(campo4);
671
+ const linhaDigitavel = campo1 + digito1 + campo2 + digito2 + campo3 + digito3 + campo4 + digito4 + campo5;
651
672
  const dadosBoleto = {
673
+ linhaDigitavel,
652
674
  fatorVencimento,
653
675
  valor,
654
676
  convenio,
@@ -656,16 +678,7 @@ function gerarDadosBoleto2({ dados }) {
656
678
  campoLivre,
657
679
  digitoGeral,
658
680
  codigoBarra: codigoBarra2,
659
- numeroDocumento,
660
- campo1,
661
- campo2,
662
- campo3,
663
- campo4,
664
- campo5,
665
- digito1,
666
- digito2,
667
- digito3,
668
- digito4
681
+ numeroDocumento
669
682
  };
670
683
  return dadosBoleto;
671
684
  } catch (error) {
package/build/index.mjs CHANGED
@@ -76,7 +76,9 @@ function gerarDadosBoleto({ dados }) {
76
76
  const digito2 = getDigito(campo2);
77
77
  const digito3 = getDigito(campo3);
78
78
  const digito4 = getDigito(campo4);
79
+ const linhaDigitavel = campo1 + digito1 + campo2 + digito2 + campo3 + digito3 + campo4 + digito4 + campo5;
79
80
  const dadosBoleto = {
81
+ linhaDigitavel,
80
82
  fatorVencimento,
81
83
  valor,
82
84
  convenio,
@@ -84,16 +86,7 @@ function gerarDadosBoleto({ dados }) {
84
86
  campoLivre,
85
87
  digitoGeral,
86
88
  codigoBarra: codigoBarra2,
87
- numeroDocumento,
88
- campo1,
89
- campo2,
90
- campo3,
91
- campo4,
92
- campo5,
93
- digito1,
94
- digito2,
95
- digito3,
96
- digito4
89
+ numeroDocumento
97
90
  };
98
91
  return dadosBoleto;
99
92
  } catch (error) {
@@ -166,11 +159,18 @@ function compileHbs(templatePath, data) {
166
159
  }
167
160
 
168
161
  // src/utils/maskFormat.ts
162
+ import StringMask from "string-mask";
169
163
  function retornaCpfCnpjFormatado(cpfCnpj) {
170
- return cpfCnpj;
164
+ if ((cpfCnpj == null ? void 0 : cpfCnpj.length) <= 11) {
165
+ const formatter2 = new StringMask("000.000.000-00");
166
+ return formatter2.apply(cpfCnpj);
167
+ }
168
+ const formatter = new StringMask("00.000.000/0000-00");
169
+ return formatter.apply(cpfCnpj);
171
170
  }
172
171
  function retornaCEPFormatado(cep) {
173
- return cep;
172
+ const formatter = new StringMask("00000-000");
173
+ return formatter.apply(cep);
174
174
  }
175
175
  function numberToReal(numero) {
176
176
  numero = typeof numero === "string" ? parseFloat(numero) : numero;
@@ -179,7 +179,8 @@ function numberToReal(numero) {
179
179
  return numero.join(",");
180
180
  }
181
181
  function codigoBarra(codigo) {
182
- return codigo;
182
+ const formatter = new StringMask("00000.00000 00000.000000 00000.000000 0 000000000000000");
183
+ return formatter.apply(codigo);
183
184
  }
184
185
  var maskFormat_default = {
185
186
  numberToReal,
@@ -207,6 +208,7 @@ function getPathTemplates(template) {
207
208
  // src/ailos/gerarPDF.ts
208
209
  function gerarPDF(_0) {
209
210
  return __async(this, arguments, function* ({ dados }) {
211
+ var _a, _b, _c, _d;
210
212
  try {
211
213
  const { generatePDF, dadosPDF } = dados;
212
214
  const codigoBarra2 = yield BwipJs.toBuffer({
@@ -214,9 +216,9 @@ function gerarPDF(_0) {
214
216
  text: dadosPDF.boleto.codigoBarra,
215
217
  height: 20
216
218
  });
217
- dadosPDF.beneficiario.dadosBancarios.agencia = dadosPDF.beneficiario.dadosBancarios.agencia.padStart(4, "0");
218
- dadosPDF.beneficiario.dadosBancarios.conta = dadosPDF.beneficiario.dadosBancarios.conta.padStart(7, "0");
219
- dadosPDF.boleto.codigoBarra = maskFormat_default.codigoBarra(dadosPDF.boleto.codigoBarra);
219
+ dadosPDF.beneficiario.dadosBancario.agencia = dadosPDF.beneficiario.dadosBancario.agencia.padStart(4, "0");
220
+ dadosPDF.beneficiario.dadosBancario.conta = dadosPDF.beneficiario.dadosBancario.conta.padStart(7, "0");
221
+ dadosPDF.boleto.linhaDigitavel = maskFormat_default.codigoBarra(dadosPDF.boleto.linhaDigitavel);
220
222
  dadosPDF.boleto.codigoBarraImage = codigoBarra2.toString("base64");
221
223
  dadosPDF.beneficiario.cnpj = maskFormat_default.retornaCpfCnpjFormatado(
222
224
  dadosPDF.beneficiario.cnpj
@@ -246,6 +248,24 @@ function gerarPDF(_0) {
246
248
  if (dadosPDF.boleto.quantidade) {
247
249
  dadosPDF.boleto.quantidade = maskFormat_default.numberToReal(dadosPDF.boleto.quantidade);
248
250
  }
251
+ const jurosMes = Number(((_a = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _a.juros) || 0);
252
+ if (jurosMes > 0) {
253
+ const juros = Number(dadosPDF.boleto.valor) * jurosMes / 100 / 30;
254
+ dadosPDF.boleto.instrucao1 = `AP\xD3S O VENCIMENTO, COBRAR JUROS DE R$ ${numberToReal(juros)} POR DIA DE ATRASO`;
255
+ }
256
+ const descontoVencimento = Number(((_b = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _b.desconto) || 0);
257
+ if (descontoVencimento > 0) {
258
+ const desconto = Number(dadosPDF.boleto.valor) / 100 * descontoVencimento;
259
+ dadosPDF.boleto.instrucao2 = `AT\xC9 O VENCIMENTO, CONCEDER DESCONTO DE R$ ${numberToReal(desconto)}`;
260
+ }
261
+ const multaAtraso = Number(((_c = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _c.multa) || 0);
262
+ if (multaAtraso > 0) {
263
+ dadosPDF.boleto.instrucao3 = `MULTA DE ${numberToReal(multaAtraso)} %`;
264
+ }
265
+ const protestoDias = Number(((_d = dadosPDF.beneficiario.dadosBancario) == null ? void 0 : _d.protesto) || 0);
266
+ if (protestoDias > 0) {
267
+ dadosPDF.boleto.instrucao4 = `PROTESTAR AP\xD3S ${protestoDias} DIAS CORRIDOS DO VENCIMENTO`;
268
+ }
249
269
  dadosPDF.boleto.valor = maskFormat_default.numberToReal(dadosPDF.boleto.valor);
250
270
  const content = compileHbs(getPathTemplates("ailos-boleto.hbs"), dadosPDF);
251
271
  const config = {
@@ -611,7 +631,9 @@ function gerarDadosBoleto2({ dados }) {
611
631
  const digito2 = getDigito2(campo2);
612
632
  const digito3 = getDigito2(campo3);
613
633
  const digito4 = getDigito2(campo4);
634
+ const linhaDigitavel = campo1 + digito1 + campo2 + digito2 + campo3 + digito3 + campo4 + digito4 + campo5;
614
635
  const dadosBoleto = {
636
+ linhaDigitavel,
615
637
  fatorVencimento,
616
638
  valor,
617
639
  convenio,
@@ -619,16 +641,7 @@ function gerarDadosBoleto2({ dados }) {
619
641
  campoLivre,
620
642
  digitoGeral,
621
643
  codigoBarra: codigoBarra2,
622
- numeroDocumento,
623
- campo1,
624
- campo2,
625
- campo3,
626
- campo4,
627
- campo5,
628
- digito1,
629
- digito2,
630
- digito3,
631
- digito4
644
+ numeroDocumento
632
645
  };
633
646
  return dadosBoleto;
634
647
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasoft/boletos",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "build",
5
5
  "license": "ISC",
6
6
  "scripts": {
@@ -14,7 +14,8 @@
14
14
  "date-fns": "^2.30.0",
15
15
  "dotenv": "^16.3.1",
16
16
  "handlebars": "^4.7.7",
17
- "puppeteer-core": "^20.9.0"
17
+ "puppeteer-core": "^20.9.0",
18
+ "string-mask": "^0.3.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@types/bwip-js": "^3.2.0",