@plasoft/boletos 1.0.3 → 1.0.5

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
@@ -159,6 +159,12 @@ declare function gerarRemessa(dados: IDadosRemessa): Promise<{
159
159
  arquivo: string;
160
160
  } | null>;
161
161
 
162
+ declare const ailos: {
163
+ gerarDadosBoleto: typeof gerarDadosBoleto;
164
+ gerarPDF: typeof gerarPDF;
165
+ gerarRemessa: typeof gerarRemessa;
166
+ };
167
+
162
168
  declare function bradesco(): void;
163
169
 
164
- export { bradesco, gerarDadosBoleto, gerarPDF, gerarRemessa };
170
+ export { ailos, bradesco };
package/build/index.d.ts CHANGED
@@ -159,6 +159,12 @@ declare function gerarRemessa(dados: IDadosRemessa): Promise<{
159
159
  arquivo: string;
160
160
  } | null>;
161
161
 
162
+ declare const ailos: {
163
+ gerarDadosBoleto: typeof gerarDadosBoleto;
164
+ gerarPDF: typeof gerarPDF;
165
+ gerarRemessa: typeof gerarRemessa;
166
+ };
167
+
162
168
  declare function bradesco(): void;
163
169
 
164
- export { bradesco, gerarDadosBoleto, gerarPDF, gerarRemessa };
170
+ export { ailos, bradesco };
package/build/index.js CHANGED
@@ -50,10 +50,8 @@ var __async = (__this, __arguments, generator) => {
50
50
  // src/index.ts
51
51
  var src_exports = {};
52
52
  __export(src_exports, {
53
- bradesco: () => bradesco,
54
- gerarDadosBoleto: () => gerarDadosBoleto,
55
- gerarPDF: () => gerarPDF,
56
- gerarRemessa: () => gerarRemessa
53
+ ailos: () => ailos,
54
+ bradesco: () => bradesco
57
55
  });
58
56
  module.exports = __toCommonJS(src_exports);
59
57
 
@@ -529,14 +527,19 @@ function gerarRemessa(dados) {
529
527
  });
530
528
  }
531
529
 
530
+ // src/ailos/index.ts
531
+ var ailos = {
532
+ gerarDadosBoleto,
533
+ gerarPDF,
534
+ gerarRemessa
535
+ };
536
+
532
537
  // src/bradesco/index.ts
533
538
  function bradesco() {
534
539
  console.log("bradesco");
535
540
  }
536
541
  // Annotate the CommonJS export names for ESM import in node:
537
542
  0 && (module.exports = {
538
- bradesco,
539
- gerarDadosBoleto,
540
- gerarPDF,
541
- gerarRemessa
543
+ ailos,
544
+ bradesco
542
545
  });
package/build/index.mjs CHANGED
@@ -491,13 +491,18 @@ function gerarRemessa(dados) {
491
491
  });
492
492
  }
493
493
 
494
+ // src/ailos/index.ts
495
+ var ailos = {
496
+ gerarDadosBoleto,
497
+ gerarPDF,
498
+ gerarRemessa
499
+ };
500
+
494
501
  // src/bradesco/index.ts
495
502
  function bradesco() {
496
503
  console.log("bradesco");
497
504
  }
498
505
  export {
499
- bradesco,
500
- gerarDadosBoleto,
501
- gerarPDF,
502
- gerarRemessa
506
+ ailos,
507
+ bradesco
503
508
  };
package/package.json CHANGED
@@ -1,18 +1,24 @@
1
1
  {
2
2
  "name": "@plasoft/boletos",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "build/index.js",
5
5
  "license": "ISC",
6
6
  "scripts": {
7
7
  "build": "tsup src/index.ts --format esm, cjs --dts --out-dir build",
8
- "dev": "tsup src/index.ts --format esm, cjs --dts --out-dir build --watch",
9
- "deploy": "npm run build && npm publish --access=public"
8
+ "dev": "tsup src/index.ts --format esm, cjs --dts --out-dir build --watch"
9
+ },
10
+ "dependencies": {
11
+ "bwip-js": "^3.4.3",
12
+ "date-fns": "^2.30.0",
13
+ "handlebars": "^4.7.7",
14
+ "puppeteer-core": "^20.9.0"
10
15
  },
11
16
  "devDependencies": {
12
17
  "@types/bwip-js": "^3.2.0",
13
18
  "tsup": "^7.1.0",
14
19
  "typescript": "^5.1.6"
15
20
  },
21
+ "files": ["build"],
16
22
  "repository": {
17
23
  "type": "git",
18
24
  "url": "git+https://github.com/plasoft-software/plasoft-firebird.git"
@@ -38,11 +44,5 @@
38
44
  "bugs": {
39
45
  "url": "https://github.com/plasoft-software/plasoft-firebird/issues"
40
46
  },
41
- "homepage": "https://github.com/plasoft-software/plasoft-firebird#readme",
42
- "dependencies": {
43
- "bwip-js": "^3.4.3",
44
- "date-fns": "^2.30.0",
45
- "handlebars": "^4.7.7",
46
- "puppeteer-core": "^20.9.0"
47
- }
47
+ "homepage": "https://github.com/plasoft-software/plasoft-firebird#readme"
48
48
  }
@@ -1,28 +0,0 @@
1
- export interface IParcelaGerarBoleto {
2
- id_boleto: number;
3
- parcela: number;
4
- vencimento: string | Date;
5
- valor: number | string;
6
- pago: number | string;
7
- data_emissao: string | Date;
8
- }
9
-
10
- export interface IDadosBoleto {
11
- fatorVencimento: string;
12
- valor: string;
13
- convenio: string;
14
- nossoNumero: string;
15
- campoLivre: string;
16
- digitoGeral: string;
17
- codigoBarra: string;
18
- numeroDocumento: string;
19
- campo1: string;
20
- campo2: string;
21
- campo3: string;
22
- campo4: string;
23
- campo5: string;
24
- digito1: string;
25
- digito2: string;
26
- digito3: string;
27
- digito4: string;
28
- }
@@ -1,139 +0,0 @@
1
- import { IParcelaGerarBoleto } from './dtos/IBoleto';
2
- import { differenceInDays } from 'date-fns';
3
- import { copy } from '../utils/copy';
4
- import { padLeft } from '../utils/pafLeft';
5
-
6
- type IParcela = IParcelaGerarBoleto;
7
-
8
- interface ICedente {
9
- numero: string;
10
- numero_dv: string;
11
- convenio: string;
12
- msg_local: string;
13
- msg_1: string;
14
- msg_2: string;
15
- msg_3: string;
16
- nome: string;
17
- cnpj: string;
18
- carteira: string;
19
- }
20
-
21
- export async function gerarDadosBoleto(
22
- cedente: ICedente,
23
- parcela: IParcela,
24
- ) {
25
- try {
26
- parcela.valor = Number(parcela.valor);
27
-
28
- const fatorVencimento = getFatorVencimento(parcela.vencimento);
29
- const valor = getValor(parcela.valor);
30
- const convenio = padLeft(cedente.convenio, 6); // 110004
31
- const numeroDocumento = padLeft(`${parcela.id_boleto}`, 9);
32
- const nossoNumero =
33
- padLeft(cedente.numero + cedente.numero_dv, 8) + numeroDocumento; // 8290 1136 + 2
34
-
35
- const campoLivre = convenio + nossoNumero + padLeft(cedente.carteira, 2);
36
- const digitoGeral = getDigitoGeral(`0859${fatorVencimento}${valor}${campoLivre}`);
37
- const codigoBarra = `0859${digitoGeral}${fatorVencimento}${valor}${campoLivre}`;
38
-
39
- const campo1 = copy(codigoBarra, 1, 3) + copy(codigoBarra, 4, 4) + copy(codigoBarra, 20, 24);
40
- const campo2 = copy(codigoBarra, 25, 34);
41
- const campo3 = copy(codigoBarra, 35, 44);
42
- const campo4 = copy(codigoBarra, 5, 5);
43
- const campo5 = copy(codigoBarra, 6, 9) + copy(codigoBarra, 10, 19);
44
-
45
- const digito1 = getDigito(campo1);
46
- const digito2 = getDigito(campo2);
47
- const digito3 = getDigito(campo3);
48
- const digito4 = getDigito(campo4);
49
-
50
- const dados = {
51
- fatorVencimento,
52
- valor,
53
- convenio,
54
- nossoNumero,
55
- campoLivre,
56
- digitoGeral,
57
- codigoBarra,
58
- numeroDocumento,
59
- campo1,
60
- campo2,
61
- campo3,
62
- campo4,
63
- campo5,
64
- digito1,
65
- digito2,
66
- digito3,
67
- digito4,
68
- };
69
-
70
- return dados;
71
- } catch (error) {
72
- console.log('Falha ao gerar dados do boleto', error);
73
- return null;
74
- }
75
- }
76
-
77
- function getFatorVencimento(vencimento: string | Date) {
78
- const data = new Date(1997, 9, 7);
79
- return differenceInDays(new Date(vencimento), data).toString();
80
- }
81
-
82
- function getValor(valor: number) {
83
- const valorFormatado = valor.toFixed(2).replace(/\D/g, '');
84
- return padLeft(valorFormatado, 10);
85
- }
86
-
87
- function getDigitoGeral(texto: string) {
88
- let i = 43;
89
- let j = 1;
90
- let soma = 0;
91
- let digito = 0;
92
-
93
- while (i >= 1) {
94
- j++;
95
-
96
- if (j === 10) j = 2;
97
-
98
- const valor = Number(copy(texto, i, i));
99
- soma += j * valor;
100
-
101
- i--;
102
- }
103
-
104
- const restoDivisao = soma % 11;
105
- digito = 11 - restoDivisao;
106
-
107
- if (digito === 0 || digito === 1 || digito > 9) digito = 1;
108
-
109
- return String(digito);
110
- }
111
-
112
- function getDigito(texto: string) {
113
- let i = texto.length;
114
- let j = 1;
115
- let total = 0;
116
- let soma = 0;
117
- let digito = 0;
118
-
119
- while (i >= 1) {
120
- j = j === 1 ? 2 : 1;
121
-
122
- let valor = Number(copy(texto, i, i));
123
- total = valor * j;
124
-
125
- if (total >= 10) {
126
- valor = Number(copy(total, 1, 1)) + Number(copy(total, 2, 2));
127
- } else {
128
- valor = total;
129
- }
130
-
131
- soma += valor;
132
- i--;
133
- }
134
-
135
- const uni = Number(copy(soma, String(soma).length, String(soma).length));
136
- digito = 10 - uni;
137
- if (digito === 10) digito = 0;
138
- return String(digito);
139
- }
@@ -1,150 +0,0 @@
1
- import { PDFOptions } from 'puppeteer-core';
2
- import path from 'path';
3
- import BwipJs from 'bwip-js';
4
- import { compileHbs } from '../utils/compileHbs';
5
- import maskFormat from '../utils/maskFormat';
6
-
7
- interface IDadosBoleto {
8
- pagador: {
9
- nome: string;
10
- endereco: {
11
- logradouro: string;
12
- numero: string;
13
- bairro: string;
14
- cep: string;
15
- municipio: string;
16
- uf: string;
17
- };
18
- };
19
- beneficiario: {
20
- nome: string;
21
- cnpj: string;
22
- dadosBancarios: {
23
- carteira: string;
24
- convenio: string;
25
- agencia: string;
26
- agenciaDigito: string;
27
- conta: string;
28
- contaDigito: string;
29
- };
30
- endereco: {
31
- logradouro: string;
32
- numero: string;
33
- bairro: string;
34
- cep: string;
35
- municipio: string;
36
- uf: string;
37
- };
38
- };
39
- boleto: {
40
- dataVencimento: string;
41
- dataProcessamento: string;
42
- dataDocumento: string;
43
-
44
- valorCobrado: number | string;
45
- valorDocumento: number | string;
46
- valorDescontoAbatimento: number | string;
47
- valorOutrasDeducoes: number | string;
48
- valorMulta: number | string;
49
- valorAcrescimo: number | string;
50
- quantidade?: number | string;
51
- valor?: number | string;
52
-
53
- numeroDocumento: string;
54
- nossoNumero: string;
55
- especieDocumento: string;
56
- aceite: 'S' | 'N';
57
- moeda: string;
58
- usoDoBanco?: string;
59
- cip?: string;
60
- codigoBarra: string;
61
- codigoBarraImage?: string;
62
-
63
- instrucao1?: string;
64
- instrucao2?: string;
65
- instrucao3?: string;
66
- };
67
- }
68
-
69
- export async function gerarPDF(dados: IDadosBoleto) {
70
- try {
71
- const codigoBarra = await BwipJs.toBuffer({
72
- bcid: 'interleaved2of5',
73
- text: dados.boleto.codigoBarra,
74
- height: 20,
75
- });
76
-
77
- dados.beneficiario.dadosBancarios.agencia =
78
- dados.beneficiario.dadosBancarios.agencia.padStart(4, '0');
79
- dados.beneficiario.dadosBancarios.conta =
80
- dados.beneficiario.dadosBancarios.conta.padStart(7, '0');
81
-
82
- dados.boleto.codigoBarra = maskFormat.codigoBarra(dados.boleto.codigoBarra);
83
- dados.boleto.codigoBarraImage = codigoBarra.toString('base64');
84
- dados.beneficiario.cnpj = maskFormat.retornaCpfCnpjFormatado(
85
- dados.beneficiario.cnpj,
86
- );
87
- dados.beneficiario.endereco.cep = maskFormat.retornaCEPFormatado(
88
- dados.beneficiario.endereco.cep,
89
- );
90
- dados.pagador.endereco.cep = maskFormat.retornaCEPFormatado(
91
- dados.pagador.endereco.cep,
92
- );
93
-
94
- dados.boleto.valorAcrescimo = maskFormat.numberToReal(
95
- dados.boleto.valorAcrescimo,
96
- );
97
- dados.boleto.valorCobrado = maskFormat.numberToReal(
98
- dados.boleto.valorCobrado,
99
- );
100
- dados.boleto.valorDescontoAbatimento = maskFormat.numberToReal(
101
- dados.boleto.valorDescontoAbatimento,
102
- );
103
- dados.boleto.valorDocumento = maskFormat.numberToReal(
104
- dados.boleto.valorDocumento,
105
- );
106
- dados.boleto.valorMulta = maskFormat.numberToReal(dados.boleto.valorMulta);
107
- dados.boleto.valorOutrasDeducoes = maskFormat.numberToReal(
108
- dados.boleto.valorOutrasDeducoes,
109
- );
110
-
111
- if (dados.boleto.quantidade) {
112
- dados.boleto.quantidade = maskFormat.numberToReal(dados.boleto.quantidade);
113
- }
114
-
115
- dados.boleto.valor = maskFormat.numberToReal(dados.boleto.valor);
116
-
117
- const filePath = path.join(__dirname, 'views', 'boleto.hbs');
118
- const content = compileHbs(filePath, dados);
119
-
120
- const config: PDFOptions = {
121
- displayHeaderFooter: false,
122
- path: './boleto.pdf',
123
- format: 'a4',
124
- printBackground: true,
125
- };
126
-
127
- // const response = await axios.post(
128
- // `http://vm.relatorios.plasoft.com.br:3333/impressao`,
129
- // {
130
- // content,
131
- // config,
132
- // },
133
- // {
134
- // headers: {
135
- // Authorization: 'ee5175ed61daebe395ad19440996af86f778e26e69ebf32b636e65fb17304fb6654b616e7294c66c106aa095b74a66962e4530d2029ace68215b7af23071da70',
136
- // },
137
- // },
138
- // );
139
-
140
- return {
141
- erro: false,
142
- // dados: response.data,
143
- };
144
- } catch (error) {
145
- return {
146
- erro: true,
147
- dados: null,
148
- };
149
- }
150
- }