boletos-ademitech 1.0.0

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.
Files changed (60) hide show
  1. package/.eslintrc.json +25 -0
  2. package/LICENSE +661 -0
  3. package/README.md +50 -0
  4. package/examples/gerar-boleto-BancoDoBrasil.js +72 -0
  5. package/examples/gerar-boleto-bradesco.js +58 -0
  6. package/examples/gerar-boleto-cecred.js +59 -0
  7. package/index.d.ts +372 -0
  8. package/lib/boleto/bancos/banco-do-brasil.js +125 -0
  9. package/lib/boleto/bancos/bradesco.js +115 -0
  10. package/lib/boleto/bancos/caixa.js +140 -0
  11. package/lib/boleto/bancos/cecred.js +117 -0
  12. package/lib/boleto/bancos/itau.js +124 -0
  13. package/lib/boleto/bancos/logotipos/ailos.png +0 -0
  14. package/lib/boleto/bancos/logotipos/banco-do-brasil.png +0 -0
  15. package/lib/boleto/bancos/logotipos/bradesco.png +0 -0
  16. package/lib/boleto/bancos/logotipos/caixa-economica-federal.png +0 -0
  17. package/lib/boleto/bancos/logotipos/itau.png +0 -0
  18. package/lib/boleto/bancos/logotipos/santander.png +0 -0
  19. package/lib/boleto/bancos/logotipos/sicoob.png +0 -0
  20. package/lib/boleto/bancos/logotipos/sicredi.png +0 -0
  21. package/lib/boleto/bancos/santander.js +118 -0
  22. package/lib/boleto/bancos/sicoob.js +118 -0
  23. package/lib/boleto/bancos/sicredi.js +143 -0
  24. package/lib/boleto/codigo-de-barras-builder.js +38 -0
  25. package/lib/boleto/fontes/Code25I.ttf +0 -0
  26. package/lib/boleto/fontes/Times New Roman Bold Italic.ttf +0 -0
  27. package/lib/boleto/fontes/Times New Roman Bold.ttf +0 -0
  28. package/lib/boleto/fontes/Times New Roman Italic.ttf +0 -0
  29. package/lib/boleto/fontes/Times New Roman.ttf +0 -0
  30. package/lib/boleto/gerador-de-boleto.js +1198 -0
  31. package/lib/boleto/gerador-de-digito-padrao.js +42 -0
  32. package/lib/boleto/gerador-de-linha-digitavel.js +26 -0
  33. package/lib/boleto/imagens/tesoura128.png +0 -0
  34. package/lib/boleto/valida-codigo-barras.js +12 -0
  35. package/lib/index.js +14 -0
  36. package/lib/metodosPublicos/boletoMetodos.js +50 -0
  37. package/lib/pdf-gerador.js +26 -0
  38. package/lib/stringify/boletoStringify.js +49 -0
  39. package/lib/utils/array-utils.js +13 -0
  40. package/lib/utils/date-utils.js +8 -0
  41. package/lib/utils/functions/bancosUtils.js +104 -0
  42. package/lib/utils/functions/boletoUtils.js +895 -0
  43. package/lib/utils/functions/formatacoesUtils.js +287 -0
  44. package/lib/utils/functions/validacoesUtils.js +233 -0
  45. package/lib/utils/math-utils.js +53 -0
  46. package/lib/utils/object-utils.js +8 -0
  47. package/lib/utils/stream-utils.js +6 -0
  48. package/lib/utils/string-utils.js +60 -0
  49. package/package.json +60 -0
  50. package/tests/bancos-test.js +116 -0
  51. package/tests/boleto/bancos/bradesco-test.js +145 -0
  52. package/tests/boleto/bancos/caixa-test.js +428 -0
  53. package/tests/boleto/bancos/itau-test.js +342 -0
  54. package/tests/boleto/bancos/sicoob-test.js +341 -0
  55. package/tests/boleto/gerador-de-digito-padrao-test.js +22 -0
  56. package/tests/boleto-test.js +349 -0
  57. package/tests/brasil-test.js +66 -0
  58. package/tests/formatacoes-test.js +349 -0
  59. package/tests/validacoes-test.js +309 -0
  60. package/tmp/boletos/.gitkeep +0 -0
@@ -0,0 +1,118 @@
1
+ const path = require('path');
2
+ const StringUtils = require('../../utils/string-utils');
3
+ const pad = StringUtils.pad;
4
+
5
+ const CodigoDeBarrasBuilder = require('../codigo-de-barras-builder');
6
+
7
+ var Santander = (function () {
8
+ var NUMERO_SANTANDER = '033',
9
+ DIGITO_SANTANDER = '7';
10
+
11
+ function Santander() {
12
+
13
+ }
14
+
15
+ Santander.prototype.getTitulos = function () {
16
+ return {
17
+ instrucoes: 'Informações de responsabilidade do beneficiário',
18
+ nomeDoPagador: 'Nome do Pagador',
19
+ especie: 'Moeda',
20
+ quantidade: 'Quantidade',
21
+ valor: 'Valor',
22
+ moraMulta: '(+) Juros / Multa'
23
+ };
24
+ };
25
+
26
+ Santander.prototype.exibirReciboDoPagadorCompleto = function () {
27
+ return true;
28
+ };
29
+
30
+ Santander.prototype.exibirCampoCip = function () {
31
+ return false;
32
+ };
33
+
34
+ Santander.prototype.geraCodigoDeBarrasPara = function (boleto) {
35
+ var beneficiario = boleto.getBeneficiario(),
36
+ campoLivre = [];
37
+
38
+ campoLivre.push('9');
39
+ campoLivre.push(beneficiario.getCodigoBeneficiario().substring(0, 4));
40
+ campoLivre.push(beneficiario.getCodigoBeneficiario().substring(4));
41
+ campoLivre.push(this.getNossoNumeroFormatado(beneficiario).substring(0, 7));
42
+ campoLivre.push(this.getNossoNumeroFormatado(beneficiario).substring(7));
43
+ campoLivre.push(beneficiario.getDigitoNossoNumero());
44
+ campoLivre.push('0');
45
+ campoLivre.push(this.getCarteiraFormatado(beneficiario));
46
+
47
+ return new CodigoDeBarrasBuilder(boleto).comCampoLivre(campoLivre);
48
+ };
49
+
50
+ Santander.prototype.getNumeroFormatadoComDigito = function () {
51
+ return [
52
+ NUMERO_SANTANDER,
53
+ DIGITO_SANTANDER
54
+ ].join('-');
55
+ };
56
+
57
+ Santander.prototype.getNumeroFormatado = function () {
58
+ return NUMERO_SANTANDER;
59
+ };
60
+
61
+ Santander.prototype.getCarteiraFormatado = function (beneficiario) {
62
+ return pad(beneficiario.getCarteira(), 2, '0');
63
+ };
64
+
65
+ Santander.prototype.getCarteiraTexto = function (beneficiario) {
66
+ return pad(beneficiario.getCarteira(), 2, '0');
67
+ };
68
+
69
+ Santander.prototype.getCodigoFormatado = function (beneficiario) {
70
+ return pad(beneficiario.getCodigoBeneficiario(), 7, '0');
71
+ };
72
+
73
+ Santander.prototype.getImagem = function () {
74
+ return path.join(__dirname, 'logotipos/santander.png');
75
+ };
76
+
77
+ Santander.prototype.getNossoNumeroFormatado = function (beneficiario) {
78
+ return pad(beneficiario.getNossoNumero(), 12, '0');
79
+ };
80
+
81
+ Santander.prototype.getNossoNumeroECodigoDocumento = function (boleto) {
82
+ var beneficiario = boleto.getBeneficiario();
83
+
84
+ return [
85
+ this.getNossoNumeroFormatado(beneficiario),
86
+ beneficiario.getDigitoNossoNumero()
87
+ ].join('-');
88
+ };
89
+
90
+ Santander.prototype.getNome = function () {
91
+ return 'Banco Santander S.A.';
92
+ };
93
+
94
+ Santander.prototype.getImprimirNome = function () {
95
+ return false;
96
+ };
97
+
98
+ Santander.prototype.getAgenciaECodigoBeneficiario = function (boleto) {
99
+ var beneficiario = boleto.getBeneficiario(),
100
+
101
+ codigo = this.getCodigoFormatado(beneficiario),
102
+ digitoCodigo = beneficiario.getDigitoCodigoBeneficiario();
103
+
104
+ if (digitoCodigo) {
105
+ codigo += '-' + digitoCodigo;
106
+ }
107
+
108
+ return beneficiario.getAgenciaFormatada() + '/' + codigo;
109
+ };
110
+
111
+ Santander.novoSantander = function () {
112
+ return new Santander();
113
+ };
114
+
115
+ return Santander;
116
+ })();
117
+
118
+ module.exports = Santander;
@@ -0,0 +1,118 @@
1
+ const path = require('path');
2
+ const StringUtils = require('../../utils/string-utils');
3
+ const pad = StringUtils.pad;
4
+
5
+ const CodigoDeBarrasBuilder = require('../codigo-de-barras-builder');
6
+
7
+
8
+ var Sicoob = (function () {
9
+ var NUMERO_SICOOB = '756',
10
+ DIGITO_SICOOB = '0';
11
+
12
+ function Sicoob() {
13
+
14
+ }
15
+
16
+ Sicoob.prototype.getTitulos = function () {
17
+ return {
18
+ localDoPagamento: 'Local de Pagamento',
19
+ especieDoDocumento: 'Espécie',
20
+ instrucoes: 'Instruções (texto de responsabilidade do beneficiário)',
21
+ agenciaECodigoDoBeneficiario: 'Coop. contratante/Cód. Beneficiário',
22
+ valorDoDocumento: 'Valor Documento',
23
+ igualDoValorDoDocumento: '',
24
+ nomeDoPagador: 'Nome do Pagador'
25
+ };
26
+ };
27
+
28
+ Sicoob.prototype.exibirReciboDoPagadorCompleto = function () {
29
+ return false;
30
+ };
31
+
32
+ Sicoob.prototype.exibirCampoCip = function () {
33
+ return false;
34
+ };
35
+
36
+ Sicoob.prototype.geraCodigoDeBarrasPara = function (boleto) {
37
+ var beneficiario = boleto.getBeneficiario(),
38
+ campoLivre = [];
39
+
40
+ campoLivre.push(this.getCarteiraFormatado(beneficiario));
41
+ campoLivre.push(beneficiario.getAgenciaFormatada());
42
+ campoLivre.push(pad(beneficiario.getCarteira(), 2, '0'));
43
+ campoLivre.push(this.getCodigoFormatado(beneficiario));
44
+ campoLivre.push(this.getNossoNumeroFormatado(beneficiario));
45
+ campoLivre.push(beneficiario.getDigitoNossoNumero());
46
+ campoLivre.push('001');
47
+
48
+ campoLivre = campoLivre.join('');
49
+
50
+ return new CodigoDeBarrasBuilder(boleto).comCampoLivre(campoLivre);
51
+ };
52
+
53
+ Sicoob.prototype.getNumeroFormatadoComDigito = function () {
54
+ return [NUMERO_SICOOB, DIGITO_SICOOB].join('-');
55
+ };
56
+
57
+ Sicoob.prototype.getCarteiraFormatado = function (beneficiario) {
58
+ return pad(beneficiario.getCarteira(), 1, '0');
59
+ };
60
+
61
+ Sicoob.prototype.getCarteiraTexto = function (beneficiario) {
62
+ return this.getCarteiraFormatado(beneficiario);
63
+ };
64
+
65
+ Sicoob.prototype.getCodigoFormatado = function (beneficiario) {
66
+ return pad(beneficiario.getCodigoBeneficiario(), 7, '0');
67
+ };
68
+
69
+ Sicoob.prototype.getImagem = function () {
70
+ return path.join(__dirname, 'logotipos/sicoob.png');
71
+ };
72
+
73
+ Sicoob.prototype.getNossoNumeroFormatado = function (beneficiario) {
74
+ return pad(beneficiario.getNossoNumero(), 7, '0');
75
+ };
76
+
77
+ Sicoob.prototype.getNossoNumeroECodigoDocumento = function (boleto) {
78
+ var beneficiario = boleto.getBeneficiario();
79
+
80
+ return pad(beneficiario.getCarteira(), 2, '0') + '/' + [
81
+ this.getNossoNumeroFormatado(beneficiario),
82
+ beneficiario.getDigitoNossoNumero()
83
+ ].join('-');
84
+ };
85
+
86
+ Sicoob.prototype.getNumeroFormatado = function () {
87
+ return NUMERO_SICOOB;
88
+ };
89
+
90
+ Sicoob.prototype.getNome = function () {
91
+ return '';
92
+ };
93
+
94
+ Sicoob.prototype.getImprimirNome = function () {
95
+ return true;
96
+ };
97
+
98
+ Sicoob.prototype.getAgenciaECodigoBeneficiario = function (boleto) {
99
+ var beneficiario = boleto.getBeneficiario(),
100
+
101
+ codigo = this.getCodigoFormatado(beneficiario),
102
+ digitoCodigo = beneficiario.getDigitoCodigoBeneficiario();
103
+
104
+ if (digitoCodigo) {
105
+ codigo += '-' + digitoCodigo;
106
+ }
107
+
108
+ return beneficiario.getAgenciaFormatada() + '/' + codigo;
109
+ };
110
+
111
+ Sicoob.novoSicoob = function () {
112
+ return new Sicoob();
113
+ };
114
+
115
+ return Sicoob;
116
+ })();
117
+
118
+ module.exports = Sicoob;
@@ -0,0 +1,143 @@
1
+ const path = require('path');
2
+ const StringUtils = require('../../utils/string-utils');
3
+ const pad = StringUtils.pad;
4
+
5
+ const CodigoDeBarrasBuilder = require('../codigo-de-barras-builder');
6
+
7
+ var Sicredi = (function () {
8
+ var NUMERO_SICREDI = '748',
9
+ DIGITO_SICREDI = 'X';
10
+
11
+ function Sicredi() {
12
+
13
+ }
14
+
15
+ Sicredi.prototype.getTitulos = function () {
16
+ return {
17
+ instrucoes: 'Informações de responsabilidade do beneficiário',
18
+ nomeDoPagador: 'Nome do Pagador',
19
+ especie: 'Moeda',
20
+ quantidade: 'Quantidade',
21
+ valor: 'Valor',
22
+ moraMulta: '(+) Juros / Multa'
23
+ };
24
+ };
25
+
26
+ Sicredi.prototype.exibirReciboDoPagadorCompleto = function () {
27
+ return true;
28
+ };
29
+
30
+ Sicredi.prototype.exibirCampoCip = function () {
31
+ return false;
32
+ };
33
+
34
+ Sicredi.prototype.geraCodigoDeBarrasPara = function (boleto) {
35
+ var beneficiario = boleto.getBeneficiario(),
36
+ campoLivre = [];
37
+
38
+ var arrayDigitoCampoLivre = ('1'
39
+ + beneficiario.getCarteira()
40
+ + beneficiario.getNossoNumero()
41
+ + beneficiario.getDigitoNossoNumero()
42
+ + beneficiario.getAgenciaFormatada()
43
+ + beneficiario.getCodposto()
44
+ + beneficiario.getCodigoBeneficiario()
45
+ + '10').split('');
46
+ var pesos = [9, 8, 7, 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
47
+
48
+ var soma = 0;
49
+
50
+ for (let i = 0; i < arrayDigitoCampoLivre.length; i++) {
51
+ soma += pesos[i] * parseInt(arrayDigitoCampoLivre[i], 10);
52
+ }
53
+ var digCampoLivre = soma % 11;
54
+ if (digCampoLivre === 1 || digCampoLivre === 0) {
55
+ digCampoLivre = 0;
56
+ } else {
57
+ digCampoLivre = 11 - digCampoLivre;
58
+ }
59
+
60
+ campoLivre.push('1');
61
+ campoLivre.push(this.getCarteiraFormatado(beneficiario));
62
+ campoLivre.push(beneficiario.getNossoNumero().substring(0, 3));
63
+ campoLivre.push(beneficiario.getNossoNumero().substring(3, 8));
64
+ campoLivre.push(beneficiario.getDigitoNossoNumero());
65
+ campoLivre.push(beneficiario.getAgenciaFormatada());
66
+ campoLivre.push(beneficiario.getCodposto());
67
+ campoLivre.push(beneficiario.getCodigoBeneficiario());
68
+ campoLivre.push('1');
69
+ campoLivre.push('0');
70
+ campoLivre.push(digCampoLivre);
71
+
72
+ return new CodigoDeBarrasBuilder(boleto).comCampoLivre(campoLivre);
73
+ };
74
+
75
+ Sicredi.prototype.getNumeroFormatadoComDigito = function () {
76
+ return [
77
+ NUMERO_SICREDI,
78
+ DIGITO_SICREDI
79
+ ].join('-');
80
+ };
81
+
82
+ Sicredi.prototype.getNumeroFormatado = function () {
83
+ return NUMERO_SICREDI;
84
+ };
85
+
86
+ Sicredi.prototype.getCarteiraFormatado = function (beneficiario) {
87
+ return pad(beneficiario.getCarteira(), 1, '0');
88
+ };
89
+
90
+ Sicredi.prototype.getCarteiraTexto = function (beneficiario) {
91
+ return pad(beneficiario.getCarteira(), 2, '0');
92
+ };
93
+
94
+ Sicredi.prototype.getCodigoFormatado = function (beneficiario) {
95
+ return pad(beneficiario.getCodigoBeneficiario(), 7, '0');
96
+ };
97
+
98
+ Sicredi.prototype.getImagem = function () {
99
+ return path.join(__dirname, 'logotipos/sicredi.png');
100
+ };
101
+
102
+ Sicredi.prototype.getNossoNumeroFormatado = function (beneficiario) {
103
+ return pad(beneficiario.getNossoNumero(), 8, '0');
104
+ };
105
+
106
+ Sicredi.prototype.getNossoNumeroECodigoDocumento = function (boleto) {
107
+ var beneficiario = boleto.getBeneficiario();
108
+
109
+ return this.getNossoNumeroFormatado(beneficiario).substring(0, 2) + '/' + [
110
+ this.getNossoNumeroFormatado(beneficiario).substring(2),
111
+ beneficiario.getDigitoNossoNumero()
112
+ ].join('-');
113
+ };
114
+
115
+ Sicredi.prototype.getNome = function () {
116
+ return 'Sicredi';
117
+ };
118
+
119
+ Sicredi.prototype.getImprimirNome = function () {
120
+ return false;
121
+ };
122
+
123
+ Sicredi.prototype.getAgenciaECodigoBeneficiario = function (boleto) {
124
+ var beneficiario = boleto.getBeneficiario(),
125
+
126
+ codigo = beneficiario.getCodposto() + '.' + beneficiario.getCodigoBeneficiario(),
127
+ digitoCodigo = beneficiario.getDigitoCodigoBeneficiario();
128
+
129
+ if (digitoCodigo) {
130
+ codigo += '-' + digitoCodigo;
131
+ }
132
+
133
+ return beneficiario.getAgenciaFormatada() + '.' + codigo;
134
+ };
135
+
136
+ Sicredi.novoSicredi = function () {
137
+ return new Sicredi();
138
+ };
139
+
140
+ return Sicredi;
141
+ })();
142
+
143
+ module.exports = Sicredi;
@@ -0,0 +1,38 @@
1
+ const ValidaCodigoBarras = require('./valida-codigo-barras');
2
+ const GeradorDeDigitoPadrao = require('./gerador-de-digito-padrao');
3
+ const StringUtils = require('../utils/string-utils');
4
+ const insert = StringUtils.insert;
5
+
6
+ module.exports = (function () {
7
+ function CodigoDeBarrasBuilder(boleto) {
8
+ const codigoDeBarras = [];
9
+ const banco = boleto.getBanco();
10
+
11
+ codigoDeBarras.push(banco.getNumeroFormatado());
12
+ codigoDeBarras.push(boleto.getCodigoEspecieMoeda());
13
+ codigoDeBarras.push(boleto.getFatorVencimento());
14
+ codigoDeBarras.push(boleto.getValorFormatado());
15
+
16
+ this._banco = banco;
17
+ this._codigoDeBarras = codigoDeBarras.join('');
18
+ }
19
+
20
+ CodigoDeBarrasBuilder.prototype.comCampoLivre = function (campoLivre) {
21
+ let codigoDeBarras = this._codigoDeBarras;
22
+
23
+ if (Array.isArray(campoLivre)) campoLivre = campoLivre.join('');
24
+
25
+ if (!campoLivre.length) throw new Error('Campo livre está vazio');
26
+
27
+ codigoDeBarras += campoLivre;
28
+
29
+ let digito = GeradorDeDigitoPadrao.mod11(codigoDeBarras);
30
+ codigoDeBarras = insert(codigoDeBarras, 4, digito);
31
+
32
+ ValidaCodigoBarras.validar(codigoDeBarras);
33
+
34
+ return codigoDeBarras;
35
+ };
36
+
37
+ return CodigoDeBarrasBuilder;
38
+ })();
Binary file