@plasoft/boletos 1.0.4 → 1.0.6
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/package.json +9 -8
- package/src/ailos/dtos/IBoleto.ts +0 -28
- package/src/ailos/gerarDadosBoleto.ts +0 -139
- package/src/ailos/gerarPDF.ts +0 -150
- package/src/ailos/gerarRemessa.ts +0 -319
- 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 +0 -9
- package/src/ailos/views/boleto.hbs +0 -487
- package/src/bradesco/index.ts +0 -3
- package/src/index.ts +0 -2
- package/src/lib/Arquivo.ts +0 -19
- package/src/utils/compileHbs.ts +0 -9
- package/src/utils/copy.ts +0 -21
- package/src/utils/maskFormat.ts +0 -39
- package/src/utils/pafLeft.ts +0 -5
- package/tsconfig.json +0 -109
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasoft/boletos",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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
8
|
"dev": "tsup src/index.ts --format esm, cjs --dts --out-dir build --watch"
|
|
9
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"
|
|
15
|
+
},
|
|
10
16
|
"devDependencies": {
|
|
11
17
|
"@types/bwip-js": "^3.2.0",
|
|
12
18
|
"tsup": "^7.1.0",
|
|
13
19
|
"typescript": "^5.1.6"
|
|
14
20
|
},
|
|
21
|
+
"files": ["build"],
|
|
15
22
|
"repository": {
|
|
16
23
|
"type": "git",
|
|
17
24
|
"url": "git+https://github.com/plasoft-software/plasoft-firebird.git"
|
|
@@ -37,11 +44,5 @@
|
|
|
37
44
|
"bugs": {
|
|
38
45
|
"url": "https://github.com/plasoft-software/plasoft-firebird/issues"
|
|
39
46
|
},
|
|
40
|
-
"homepage": "https://github.com/plasoft-software/plasoft-firebird#readme"
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"bwip-js": "^3.4.3",
|
|
43
|
-
"date-fns": "^2.30.0",
|
|
44
|
-
"handlebars": "^4.7.7",
|
|
45
|
-
"puppeteer-core": "^20.9.0"
|
|
46
|
-
}
|
|
47
|
+
"homepage": "https://github.com/plasoft-software/plasoft-firebird#readme"
|
|
47
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
|
-
}
|
package/src/ailos/gerarPDF.ts
DELETED
|
@@ -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
|
-
}
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { addDays, format } from 'date-fns';
|
|
2
|
-
import { Arquivo } from '../lib/Arquivo';
|
|
3
|
-
|
|
4
|
-
interface IDadosRemessa {
|
|
5
|
-
pagador: {
|
|
6
|
-
nome: string;
|
|
7
|
-
pessoa: 'F' | 'J';
|
|
8
|
-
cpfCnpj: string;
|
|
9
|
-
endereco: {
|
|
10
|
-
logradouro: string;
|
|
11
|
-
numero: string;
|
|
12
|
-
bairro: string;
|
|
13
|
-
cep: string;
|
|
14
|
-
municipio: string;
|
|
15
|
-
uf: string;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
beneficiario: {
|
|
19
|
-
nome: string;
|
|
20
|
-
cnpj: string;
|
|
21
|
-
endereco: {
|
|
22
|
-
logradouro: string;
|
|
23
|
-
numero: string;
|
|
24
|
-
bairro: string;
|
|
25
|
-
cep: string;
|
|
26
|
-
municipio: string;
|
|
27
|
-
uf: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
dadosBancario: {
|
|
31
|
-
carteira: string;
|
|
32
|
-
convenio: string;
|
|
33
|
-
agencia: string;
|
|
34
|
-
agenciaDigito: string;
|
|
35
|
-
conta: string;
|
|
36
|
-
contaDigito: string;
|
|
37
|
-
numeroRemessa: string;
|
|
38
|
-
jurosMes: number;
|
|
39
|
-
multaAtraso: number;
|
|
40
|
-
descontoPagamento: number;
|
|
41
|
-
diasProtesto: number;
|
|
42
|
-
};
|
|
43
|
-
boletos: {
|
|
44
|
-
identificacaoTitulo: string;
|
|
45
|
-
vencimento: string | Date;
|
|
46
|
-
valor: number | string;
|
|
47
|
-
nossoNumero: string;
|
|
48
|
-
numeroDocumento: string;
|
|
49
|
-
parcela: number | string;
|
|
50
|
-
}[];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function gerarRemessa(dados: IDadosRemessa) {
|
|
54
|
-
try {
|
|
55
|
-
const { dadosBancario, beneficiario, boletos, pagador } = dados;
|
|
56
|
-
|
|
57
|
-
const arquivo = new Arquivo();
|
|
58
|
-
const dataAtual = new Date();
|
|
59
|
-
const data = format(dataAtual, 'ddMMyyyy');
|
|
60
|
-
const hora = format(dataAtual, 'HHmmss');
|
|
61
|
-
|
|
62
|
-
const convenio = dadosBancario.convenio.padStart(7, '0');
|
|
63
|
-
const numero =
|
|
64
|
-
dadosBancario.conta.padStart(7, '0') + dadosBancario.contaDigito;
|
|
65
|
-
|
|
66
|
-
const remessa = `REM${convenio}-${numero}-${data}.REM`;
|
|
67
|
-
|
|
68
|
-
// Header do arquivo
|
|
69
|
-
arquivo.add('085');
|
|
70
|
-
arquivo.add('0000');
|
|
71
|
-
arquivo.add('0');
|
|
72
|
-
arquivo.add(' ');
|
|
73
|
-
arquivo.add('2');
|
|
74
|
-
arquivo.add(beneficiario.cnpj);
|
|
75
|
-
arquivo.add(dadosBancario.convenio.padEnd(20, ' '));
|
|
76
|
-
arquivo.add(dadosBancario.agencia.padStart(5, '0'));
|
|
77
|
-
arquivo.add(dadosBancario.agencia);
|
|
78
|
-
arquivo.add(dadosBancario.conta.padStart(12, '0'));
|
|
79
|
-
arquivo.add(dadosBancario.contaDigito);
|
|
80
|
-
arquivo.add(' ');
|
|
81
|
-
arquivo.add(beneficiario.nome.substring(0, 30).padEnd(30, ' '));
|
|
82
|
-
arquivo.add('AILOS'.padEnd(30, ' '));
|
|
83
|
-
arquivo.add(' ');
|
|
84
|
-
arquivo.add('1');
|
|
85
|
-
arquivo.add(data);
|
|
86
|
-
arquivo.add(hora);
|
|
87
|
-
arquivo.add(dadosBancario.numeroRemessa.padStart(6, '0'));
|
|
88
|
-
arquivo.add('087');
|
|
89
|
-
arquivo.add('00000');
|
|
90
|
-
arquivo.add(' '.padEnd(20, ' '));
|
|
91
|
-
arquivo.add(' '.padEnd(20, ' '));
|
|
92
|
-
arquivo.add(' '.padEnd(29, ' '));
|
|
93
|
-
|
|
94
|
-
arquivo.addLine();
|
|
95
|
-
|
|
96
|
-
// Header do lote
|
|
97
|
-
arquivo.add('085');
|
|
98
|
-
arquivo.add('0001');
|
|
99
|
-
arquivo.add('1');
|
|
100
|
-
arquivo.add('R');
|
|
101
|
-
arquivo.add('01');
|
|
102
|
-
arquivo.add(' ');
|
|
103
|
-
arquivo.add('045');
|
|
104
|
-
arquivo.add(' ');
|
|
105
|
-
arquivo.add('2');
|
|
106
|
-
arquivo.add(beneficiario.cnpj.padStart(15, '0'));
|
|
107
|
-
arquivo.add(dadosBancario.convenio.padEnd(20, ' '));
|
|
108
|
-
arquivo.add(dadosBancario.agencia.padStart(5, '0'));
|
|
109
|
-
arquivo.add(dadosBancario.agenciaDigito);
|
|
110
|
-
arquivo.add(dadosBancario.conta.padStart(12, '0'));
|
|
111
|
-
arquivo.add(dadosBancario.contaDigito);
|
|
112
|
-
arquivo.add(' ');
|
|
113
|
-
arquivo.add(pagador.nome.substring(0, 30).padEnd(30, ' '));
|
|
114
|
-
arquivo.add(' '.padEnd(40, ' '));
|
|
115
|
-
arquivo.add(' '.padEnd(40, ' '));
|
|
116
|
-
arquivo.add(dadosBancario.numeroRemessa.padStart(8, '0'));
|
|
117
|
-
arquivo.add(data);
|
|
118
|
-
arquivo.add('00000000');
|
|
119
|
-
arquivo.add(' '.padEnd(33, ' '));
|
|
120
|
-
|
|
121
|
-
arquivo.addLine();
|
|
122
|
-
|
|
123
|
-
let sequencia = 1;
|
|
124
|
-
let quantidadeRegistro = 1;
|
|
125
|
-
let total = 0;
|
|
126
|
-
|
|
127
|
-
// Registro Detalhe – Segmento P
|
|
128
|
-
for (const boleto of boletos) {
|
|
129
|
-
const vencimento = format(new Date(boleto.vencimento), 'ddMMyyyy');
|
|
130
|
-
total += Number(boleto.valor);
|
|
131
|
-
|
|
132
|
-
// Cálculos de juros
|
|
133
|
-
const codigoJuro = dadosBancario.jurosMes > 0 ? '2' : '3';
|
|
134
|
-
const juros =
|
|
135
|
-
dadosBancario.jurosMes > 0
|
|
136
|
-
? dadosBancario.jurosMes.toFixed(2)
|
|
137
|
-
: '000000000000000';
|
|
138
|
-
|
|
139
|
-
// Cálculos de desconto
|
|
140
|
-
const jurosVencimento = format(
|
|
141
|
-
addDays(new Date(boleto.vencimento), 1),
|
|
142
|
-
'ddMMyyyy',
|
|
143
|
-
);
|
|
144
|
-
const codigoDesconto = dadosBancario.descontoPagamento > 0 ? '2' : '0';
|
|
145
|
-
const desconto =
|
|
146
|
-
dadosBancario.descontoPagamento > 0
|
|
147
|
-
? dadosBancario.descontoPagamento.toFixed(2)
|
|
148
|
-
: '000000000000000';
|
|
149
|
-
|
|
150
|
-
const protesto = dadosBancario.diasProtesto > 0 ? '1' : '3';
|
|
151
|
-
const diasProtesto =
|
|
152
|
-
protesto === '1' ? dadosBancario.diasProtesto.toString() : '00';
|
|
153
|
-
|
|
154
|
-
arquivo.add('085');
|
|
155
|
-
arquivo.add('0001');
|
|
156
|
-
arquivo.add('3');
|
|
157
|
-
arquivo.add(sequencia.toString().padStart(5, '0'));
|
|
158
|
-
arquivo.add('P');
|
|
159
|
-
arquivo.add(' ');
|
|
160
|
-
arquivo.add('01');
|
|
161
|
-
arquivo.add(dadosBancario.agencia.padStart(5, '0'));
|
|
162
|
-
arquivo.add(dadosBancario.agenciaDigito);
|
|
163
|
-
arquivo.add(dadosBancario.conta.padStart(12, '0'));
|
|
164
|
-
arquivo.add(dadosBancario.contaDigito);
|
|
165
|
-
arquivo.add(' ');
|
|
166
|
-
arquivo.add(boleto.nossoNumero.padEnd(20, ' '));
|
|
167
|
-
arquivo.add('1');
|
|
168
|
-
arquivo.add('1');
|
|
169
|
-
arquivo.add('1');
|
|
170
|
-
arquivo.add('2');
|
|
171
|
-
arquivo.add('2');
|
|
172
|
-
arquivo.add(`${boleto.numeroDocumento}/${boleto.parcela}`.padEnd(15, ' '));
|
|
173
|
-
arquivo.add(vencimento);
|
|
174
|
-
arquivo.add(
|
|
175
|
-
Number(boleto.valor).toFixed(2).replace('.', '').padStart(15, '0'),
|
|
176
|
-
);
|
|
177
|
-
arquivo.add(dadosBancario.agencia.padStart(5, '0'));
|
|
178
|
-
arquivo.add(dadosBancario.agenciaDigito);
|
|
179
|
-
arquivo.add('02'); // Mandar fixo ou criar parâmetro na forma de pagamento
|
|
180
|
-
arquivo.add('A');
|
|
181
|
-
arquivo.add(data);
|
|
182
|
-
arquivo.add(codigoJuro);
|
|
183
|
-
arquivo.add(jurosVencimento);
|
|
184
|
-
arquivo.add(juros.replace('.', '').padStart(15, '0'));
|
|
185
|
-
arquivo.add(codigoDesconto);
|
|
186
|
-
arquivo.add(vencimento);
|
|
187
|
-
arquivo.add(desconto.replace('.', '').padStart(15, '0'));
|
|
188
|
-
arquivo.add('000000000000000');
|
|
189
|
-
arquivo.add('000000000000000');
|
|
190
|
-
arquivo.add(boleto.identificacaoTitulo.padEnd(25, ' ')); // Identificação de título, usar depois
|
|
191
|
-
arquivo.add(protesto);
|
|
192
|
-
arquivo.add(diasProtesto.padStart(1, '0'));
|
|
193
|
-
arquivo.add('2');
|
|
194
|
-
arquivo.add(' ');
|
|
195
|
-
arquivo.add('09');
|
|
196
|
-
arquivo.add('0000000000');
|
|
197
|
-
arquivo.add(' ');
|
|
198
|
-
|
|
199
|
-
sequencia++;
|
|
200
|
-
|
|
201
|
-
arquivo.addLine();
|
|
202
|
-
|
|
203
|
-
// Registro Detalhe – Segmento Q
|
|
204
|
-
let tipoInscricao = '1';
|
|
205
|
-
|
|
206
|
-
if (pagador.pessoa === 'F') {
|
|
207
|
-
tipoInscricao = '1';
|
|
208
|
-
} else {
|
|
209
|
-
tipoInscricao = '2';
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
pagador.endereco.logradouro = `${pagador.endereco.logradouro
|
|
213
|
-
.substring(0, 32)
|
|
214
|
-
.padEnd(32, ' ')}${pagador.endereco.numero.padEnd(8, ' ')}`;
|
|
215
|
-
|
|
216
|
-
arquivo.add('085');
|
|
217
|
-
arquivo.add('0001');
|
|
218
|
-
arquivo.add('3');
|
|
219
|
-
arquivo.add(sequencia.toString().padStart(5, '0'));
|
|
220
|
-
arquivo.add('Q');
|
|
221
|
-
arquivo.add(' ');
|
|
222
|
-
arquivo.add('01');
|
|
223
|
-
arquivo.add(tipoInscricao);
|
|
224
|
-
arquivo.add(pagador.cpfCnpj.padStart(15, '0'));
|
|
225
|
-
arquivo.add(pagador.nome.substring(0, 40).padEnd(40, ' '));
|
|
226
|
-
arquivo.add(pagador.endereco.logradouro.substring(0, 40).padEnd(40, ' '));
|
|
227
|
-
arquivo.add(pagador.endereco.bairro.substring(0, 15).padEnd(15, ' '));
|
|
228
|
-
arquivo.add(pagador.endereco.cep.substring(0, 5).padStart(5, '0'));
|
|
229
|
-
arquivo.add(pagador.endereco.cep.substring(5, 7).padStart(3, '0'));
|
|
230
|
-
arquivo.add(pagador.endereco.municipio.substring(0, 15).padEnd(15, ' '));
|
|
231
|
-
arquivo.add(pagador.endereco.uf.padEnd(2, ' '));
|
|
232
|
-
arquivo.add('0');
|
|
233
|
-
arquivo.add('000000000000000');
|
|
234
|
-
arquivo.add(' '.padEnd(40, ' '));
|
|
235
|
-
arquivo.add('000');
|
|
236
|
-
arquivo.add(' '.padEnd(20, ' '));
|
|
237
|
-
arquivo.add(' '.padEnd(8, ' '));
|
|
238
|
-
|
|
239
|
-
dadosBancario.multaAtraso = Number(dadosBancario.multaAtraso || 0);
|
|
240
|
-
if (dadosBancario.multaAtraso > 0) {
|
|
241
|
-
arquivo.addLine();
|
|
242
|
-
const multa = dadosBancario.multaAtraso.toFixed(2);
|
|
243
|
-
|
|
244
|
-
sequencia++;
|
|
245
|
-
|
|
246
|
-
// Registro Detalhe – Segmento R
|
|
247
|
-
arquivo.add('085');
|
|
248
|
-
arquivo.add('0001');
|
|
249
|
-
arquivo.add('3');
|
|
250
|
-
arquivo.add(sequencia.toString().padStart(5, '0'));
|
|
251
|
-
arquivo.add('R');
|
|
252
|
-
arquivo.add(' ');
|
|
253
|
-
arquivo.add('01');
|
|
254
|
-
arquivo.add('0');
|
|
255
|
-
arquivo.add('00000000');
|
|
256
|
-
arquivo.add('000000000000000');
|
|
257
|
-
arquivo.add('0');
|
|
258
|
-
arquivo.add('00000000');
|
|
259
|
-
arquivo.add('000000000000000');
|
|
260
|
-
arquivo.add('2');
|
|
261
|
-
arquivo.add(vencimento);
|
|
262
|
-
arquivo.add(multa.replace('.', '').padStart(15, '0'));
|
|
263
|
-
arquivo.add(' '.padEnd(10, ' '));
|
|
264
|
-
arquivo.add(' '.padEnd(40, ' '));
|
|
265
|
-
arquivo.add(' '.padEnd(40, ' '));
|
|
266
|
-
arquivo.add(' '.padEnd(20, ' '));
|
|
267
|
-
arquivo.add('00000000');
|
|
268
|
-
arquivo.add('000');
|
|
269
|
-
arquivo.add('00000');
|
|
270
|
-
arquivo.add(' ');
|
|
271
|
-
arquivo.add('000000000000');
|
|
272
|
-
arquivo.add(' ');
|
|
273
|
-
arquivo.add(' ');
|
|
274
|
-
arquivo.add('0');
|
|
275
|
-
arquivo.add('000000000');
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
arquivo.addLine();
|
|
279
|
-
quantidadeRegistro++;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Registro trailer do lote
|
|
283
|
-
arquivo.add('085');
|
|
284
|
-
arquivo.add('0001');
|
|
285
|
-
arquivo.add('5');
|
|
286
|
-
arquivo.add(' '.padEnd(9, ' '));
|
|
287
|
-
arquivo.add((sequencia + 3).toString().padStart(6, '0'));
|
|
288
|
-
arquivo.add(quantidadeRegistro.toString().padStart(6, '0'));
|
|
289
|
-
arquivo.add(total.toFixed(2).replace('.', '').padStart(17, '0'));
|
|
290
|
-
arquivo.add('0'.padStart(6, '0'));
|
|
291
|
-
arquivo.add('0'.padStart(17, '0'));
|
|
292
|
-
arquivo.add('0'.padStart(6, '0'));
|
|
293
|
-
arquivo.add('0'.padStart(17, '0'));
|
|
294
|
-
arquivo.add('0'.padStart(6, '0'));
|
|
295
|
-
arquivo.add('0'.padStart(17, '0'));
|
|
296
|
-
arquivo.add(' '.padStart(8, ' '));
|
|
297
|
-
arquivo.add(' '.padStart(117, ' '));
|
|
298
|
-
|
|
299
|
-
arquivo.addLine();
|
|
300
|
-
|
|
301
|
-
// Registro Trailer de Arquivo
|
|
302
|
-
arquivo.add('085');
|
|
303
|
-
arquivo.add('9999');
|
|
304
|
-
arquivo.add('9');
|
|
305
|
-
arquivo.add(' '.padEnd(9, ' '));
|
|
306
|
-
arquivo.add('000001');
|
|
307
|
-
arquivo.add((sequencia + 4).toString().padStart(6, '0'));
|
|
308
|
-
arquivo.add('000000');
|
|
309
|
-
arquivo.add(' '.padEnd(205, ' '));
|
|
310
|
-
|
|
311
|
-
return {
|
|
312
|
-
download: remessa,
|
|
313
|
-
arquivo: arquivo.getArquivo(),
|
|
314
|
-
};
|
|
315
|
-
} catch (error) {
|
|
316
|
-
console.log(error);
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
Binary file
|
|
Binary file
|
package/src/ailos/images/cut.png
DELETED
|
Binary file
|