@plasoft/boletos 1.0.0 → 1.0.1
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.js +21 -6
- package/package.json +11 -3
- package/src/ailos/dtos/IBoleto.ts +28 -0
- package/src/ailos/gerarDadosBoleto.ts +139 -0
- package/src/ailos/gerarPDF.ts +150 -0
- package/src/ailos/gerarRemessa.ts +319 -0
- package/src/ailos/images/ailos.png +0 -0
- package/src/ailos/images/barcode.png +0 -0
- package/src/ailos/images/cut.png +0 -0
- package/src/ailos/index.ts +9 -3
- package/src/ailos/views/boleto.hbs +487 -0
- package/src/lib/Arquivo.ts +19 -0
- package/src/utils/compileHbs.ts +9 -0
- package/src/utils/copy.ts +21 -0
- package/src/utils/maskFormat.ts +39 -0
- package/src/utils/pafLeft.ts +5 -0
- package/build/index.d.mts +0 -5
- package/build/index.d.ts +0 -5
- package/build/index.mjs +0 -13
package/build/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,20 +17,34 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
21
31
|
var src_exports = {};
|
|
22
32
|
__export(src_exports, {
|
|
23
|
-
ailos: () => ailos,
|
|
24
33
|
bradesco: () => bradesco
|
|
25
34
|
});
|
|
26
35
|
module.exports = __toCommonJS(src_exports);
|
|
27
36
|
|
|
28
|
-
// src/ailos/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
// src/ailos/gerarDadosBoleto.ts
|
|
38
|
+
var import_date_fns = require("date-fns");
|
|
39
|
+
|
|
40
|
+
// src/ailos/gerarPDF.ts
|
|
41
|
+
var import_bwip_js = __toESM(require("bwip-js"));
|
|
42
|
+
|
|
43
|
+
// src/utils/compileHbs.ts
|
|
44
|
+
var import_handlebars = __toESM(require("handlebars"));
|
|
45
|
+
|
|
46
|
+
// src/ailos/gerarRemessa.ts
|
|
47
|
+
var import_date_fns2 = require("date-fns");
|
|
32
48
|
|
|
33
49
|
// src/bradesco/index.ts
|
|
34
50
|
function bradesco() {
|
|
@@ -36,6 +52,5 @@ function bradesco() {
|
|
|
36
52
|
}
|
|
37
53
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
54
|
0 && (module.exports = {
|
|
39
|
-
ailos,
|
|
40
55
|
bradesco
|
|
41
56
|
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasoft/boletos",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
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"
|
|
8
|
+
"dev": "tsup src/index.ts --format esm, cjs --dts --out-dir build --watch",
|
|
9
|
+
"publish": "npm run build && npm publish --access=public"
|
|
9
10
|
},
|
|
10
11
|
"devDependencies": {
|
|
12
|
+
"@types/bwip-js": "^3.2.0",
|
|
11
13
|
"tsup": "^7.1.0",
|
|
12
14
|
"typescript": "^5.1.6"
|
|
13
15
|
},
|
|
@@ -36,5 +38,11 @@
|
|
|
36
38
|
"bugs": {
|
|
37
39
|
"url": "https://github.com/plasoft-software/plasoft-firebird/issues"
|
|
38
40
|
},
|
|
39
|
-
"homepage": "https://github.com/plasoft-software/plasoft-firebird#readme"
|
|
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
|
+
}
|
|
40
48
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
}
|