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.
- package/.eslintrc.json +25 -0
- package/LICENSE +661 -0
- package/README.md +50 -0
- package/examples/gerar-boleto-BancoDoBrasil.js +72 -0
- package/examples/gerar-boleto-bradesco.js +58 -0
- package/examples/gerar-boleto-cecred.js +59 -0
- package/index.d.ts +372 -0
- package/lib/boleto/bancos/banco-do-brasil.js +125 -0
- package/lib/boleto/bancos/bradesco.js +115 -0
- package/lib/boleto/bancos/caixa.js +140 -0
- package/lib/boleto/bancos/cecred.js +117 -0
- package/lib/boleto/bancos/itau.js +124 -0
- package/lib/boleto/bancos/logotipos/ailos.png +0 -0
- package/lib/boleto/bancos/logotipos/banco-do-brasil.png +0 -0
- package/lib/boleto/bancos/logotipos/bradesco.png +0 -0
- package/lib/boleto/bancos/logotipos/caixa-economica-federal.png +0 -0
- package/lib/boleto/bancos/logotipos/itau.png +0 -0
- package/lib/boleto/bancos/logotipos/santander.png +0 -0
- package/lib/boleto/bancos/logotipos/sicoob.png +0 -0
- package/lib/boleto/bancos/logotipos/sicredi.png +0 -0
- package/lib/boleto/bancos/santander.js +118 -0
- package/lib/boleto/bancos/sicoob.js +118 -0
- package/lib/boleto/bancos/sicredi.js +143 -0
- package/lib/boleto/codigo-de-barras-builder.js +38 -0
- package/lib/boleto/fontes/Code25I.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman Bold Italic.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman Bold.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman Italic.ttf +0 -0
- package/lib/boleto/fontes/Times New Roman.ttf +0 -0
- package/lib/boleto/gerador-de-boleto.js +1198 -0
- package/lib/boleto/gerador-de-digito-padrao.js +42 -0
- package/lib/boleto/gerador-de-linha-digitavel.js +26 -0
- package/lib/boleto/imagens/tesoura128.png +0 -0
- package/lib/boleto/valida-codigo-barras.js +12 -0
- package/lib/index.js +14 -0
- package/lib/metodosPublicos/boletoMetodos.js +50 -0
- package/lib/pdf-gerador.js +26 -0
- package/lib/stringify/boletoStringify.js +49 -0
- package/lib/utils/array-utils.js +13 -0
- package/lib/utils/date-utils.js +8 -0
- package/lib/utils/functions/bancosUtils.js +104 -0
- package/lib/utils/functions/boletoUtils.js +895 -0
- package/lib/utils/functions/formatacoesUtils.js +287 -0
- package/lib/utils/functions/validacoesUtils.js +233 -0
- package/lib/utils/math-utils.js +53 -0
- package/lib/utils/object-utils.js +8 -0
- package/lib/utils/stream-utils.js +6 -0
- package/lib/utils/string-utils.js +60 -0
- package/package.json +60 -0
- package/tests/bancos-test.js +116 -0
- package/tests/boleto/bancos/bradesco-test.js +145 -0
- package/tests/boleto/bancos/caixa-test.js +428 -0
- package/tests/boleto/bancos/itau-test.js +342 -0
- package/tests/boleto/bancos/sicoob-test.js +341 -0
- package/tests/boleto/gerador-de-digito-padrao-test.js +22 -0
- package/tests/boleto-test.js +349 -0
- package/tests/brasil-test.js +66 -0
- package/tests/formatacoes-test.js +349 -0
- package/tests/validacoes-test.js +309 -0
- package/tmp/boletos/.gitkeep +0 -0
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
//Este submodulo de boletos é inspirado no Stella-Boletos, da Caelum
|
|
2
|
+
//https://github.com/caelum/caelum-stella
|
|
3
|
+
const formatacoes = require('./formatacoesUtils');
|
|
4
|
+
const validacoes = require('../functions/validacoesUtils');
|
|
5
|
+
const StringUtils = require('../string-utils');
|
|
6
|
+
const moment = require('moment-timezone');
|
|
7
|
+
|
|
8
|
+
moment.tz.setDefault('America/Sao_Paulo');
|
|
9
|
+
|
|
10
|
+
const pad = StringUtils.pad;
|
|
11
|
+
|
|
12
|
+
const Itau = require('../../boleto/bancos/itau');
|
|
13
|
+
const Caixa = require('../../boleto/bancos/caixa');
|
|
14
|
+
const Bradesco = require('../../boleto/bancos/bradesco');
|
|
15
|
+
const BancoBrasil = require('../../boleto/bancos/banco-do-brasil');
|
|
16
|
+
const Cecred = require('../../boleto/bancos/cecred');
|
|
17
|
+
const Sicoob = require('../../boleto/bancos/sicoob');
|
|
18
|
+
const Santander = require('../../boleto/bancos/santander');
|
|
19
|
+
const Sicredi = require('../../boleto/bancos/sicredi');
|
|
20
|
+
|
|
21
|
+
const Gerador = require('../../boleto/gerador-de-boleto');
|
|
22
|
+
const GeradorDeLinhaDigitavel = require('../../boleto/gerador-de-linha-digitavel');
|
|
23
|
+
|
|
24
|
+
module.exports.especiesDeDocumento = {
|
|
25
|
+
//TODO: Ordenar por ordem alfabética
|
|
26
|
+
'DMI': 'Duplicata de Venda Mercantil por Indicação',
|
|
27
|
+
'DM': 'Duplicata de Venda Mercantil',
|
|
28
|
+
'DSI': 'Duplicata de Prestação de Serviços por Indicação de Comprovante',
|
|
29
|
+
'NP': 'Nota Promissória',
|
|
30
|
+
'ME': 'Mensalidade Escolar',
|
|
31
|
+
'DS': 'Duplicata de Prestação de Serviços Original',
|
|
32
|
+
'CT': 'Espécie de Contrato',
|
|
33
|
+
'LC': 'Letra de Câmbio',
|
|
34
|
+
'CPS': 'Conta de Prestação de Serviços de Profissional Liberal ou Declaração do Profissional',
|
|
35
|
+
'EC': 'Encargos Condominiais',
|
|
36
|
+
'DD': 'Documento de Dívida',
|
|
37
|
+
'CCB': 'Cédula de Crédito Bancário',
|
|
38
|
+
'CBI': 'Cédula de Crédito Bancário por Indicação',
|
|
39
|
+
'CH': 'Cheque',
|
|
40
|
+
'CM': 'Contrato de Mútuo',
|
|
41
|
+
'RA': 'Recibo de Aluguel Para Pessoa Jurídica (Contrato Aluguel e Recibo)',
|
|
42
|
+
'CD': 'Confissão de Dívida Apenas Para Falência de Declaração do Devedor',
|
|
43
|
+
'FS': 'Fatura de Serviço',
|
|
44
|
+
'TA': 'Termo de Acordo - Ex. Ação Trabalhista',
|
|
45
|
+
'CC': 'Contrato de Câmbio',
|
|
46
|
+
'DV': 'Diversos',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports.bancos = {
|
|
50
|
+
Itau: Itau,
|
|
51
|
+
'341': Itau,
|
|
52
|
+
|
|
53
|
+
Caixa: Caixa,
|
|
54
|
+
'104': Caixa,
|
|
55
|
+
|
|
56
|
+
Bradesco: Bradesco,
|
|
57
|
+
'237': Bradesco,
|
|
58
|
+
|
|
59
|
+
BancoBrasil: BancoBrasil,
|
|
60
|
+
'001': BancoBrasil,
|
|
61
|
+
|
|
62
|
+
Cecred: Cecred,
|
|
63
|
+
'085': Cecred,
|
|
64
|
+
|
|
65
|
+
Sicoob: Sicoob,
|
|
66
|
+
'756': Sicoob,
|
|
67
|
+
|
|
68
|
+
Santander: Santander,
|
|
69
|
+
'033': Santander,
|
|
70
|
+
|
|
71
|
+
Sicredi: Sicredi,
|
|
72
|
+
'748': Sicredi
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
module.exports.Gerador = Gerador;
|
|
76
|
+
|
|
77
|
+
//Baixar depois:
|
|
78
|
+
//Logotipo HSBC: http://pt.vector.me/browse/29385/hsbc
|
|
79
|
+
//Logotipo UNIBANCO: http://pt.vector.me/browse/27779/unibanco
|
|
80
|
+
|
|
81
|
+
var Pagador = (function () {
|
|
82
|
+
function Pagador() {
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Pagador.prototype.getNome = function () {
|
|
87
|
+
return this._nome;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
Pagador.prototype.comNome = function (_nome) {
|
|
91
|
+
this._nome = _nome;
|
|
92
|
+
return this;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
Pagador.prototype.getIdentificacao = function () {
|
|
96
|
+
var identificacao = this.getNome(),
|
|
97
|
+
tipo = this.temRegistroNacional();
|
|
98
|
+
|
|
99
|
+
// TODO: Inserir novamente o registro nacional depois
|
|
100
|
+
// de implementar mecanismo para o texto não extravassar
|
|
101
|
+
// do campo.
|
|
102
|
+
|
|
103
|
+
if (tipo) {
|
|
104
|
+
identificacao += [
|
|
105
|
+
' (',
|
|
106
|
+
tipo.toUpperCase(),
|
|
107
|
+
': ',
|
|
108
|
+
this.getRegistroNacionalFormatado(),
|
|
109
|
+
')'
|
|
110
|
+
].join('') || '';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return (identificacao || '').toUpperCase();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Pagador.prototype.getRegistroNacional = function () {
|
|
117
|
+
return this._registroNacional;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
Pagador.prototype.getRegistroNacionalFormatado = function () {
|
|
121
|
+
return formatacoes.registroNacional(this._registroNacional);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
Pagador.prototype.temRegistroNacional = function () {
|
|
125
|
+
return validacoes.eRegistroNacional(this._registroNacional);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
Pagador.prototype.comCNPJ = function (_cnpj) {
|
|
129
|
+
this.comRegistroNacional(_cnpj);
|
|
130
|
+
return this;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
Pagador.prototype.comCPF = function (_cpf) {
|
|
134
|
+
this.comRegistroNacional(_cpf);
|
|
135
|
+
return this;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
Pagador.prototype.comRegistroNacional = function (_registroNacional) {
|
|
139
|
+
this._registroNacional = _registroNacional;
|
|
140
|
+
return this;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
Pagador.prototype.getDocumento = function () {
|
|
144
|
+
return this._documento;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
Pagador.prototype.comDocumento = function (_documento) {
|
|
148
|
+
this._documento = _documento;
|
|
149
|
+
return this;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
Pagador.prototype.getEndereco = function () {
|
|
153
|
+
return this._endereco;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
Pagador.prototype.comEndereco = function (_endereco) {
|
|
157
|
+
this._endereco = _endereco;
|
|
158
|
+
return this;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
Pagador.novoPagador = function () {
|
|
162
|
+
return new Pagador().comEndereco(Endereco.novoEndereco());
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return Pagador;
|
|
166
|
+
})();
|
|
167
|
+
|
|
168
|
+
module.exports.Pagador = Pagador;
|
|
169
|
+
|
|
170
|
+
var Beneficiario = (function () {
|
|
171
|
+
function Beneficiario() {
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
Beneficiario.prototype.getIdentificacao = function () {
|
|
176
|
+
var identificacao = this.getNome(),
|
|
177
|
+
tipo = this.temRegistroNacional();
|
|
178
|
+
|
|
179
|
+
if (tipo) {
|
|
180
|
+
identificacao += [
|
|
181
|
+
' (',
|
|
182
|
+
tipo.toUpperCase(),
|
|
183
|
+
': ',
|
|
184
|
+
this.getRegistroNacionalFormatado(),
|
|
185
|
+
')'
|
|
186
|
+
].join('');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return (identificacao || '').toUpperCase();
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
Beneficiario.prototype.getRegistroNacional = function () {
|
|
193
|
+
return this._registroNacional;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
Beneficiario.prototype.getRegistroNacionalFormatado = function () {
|
|
197
|
+
return formatacoes.registroNacional(this._registroNacional);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
Beneficiario.prototype.temRegistroNacional = function () {
|
|
201
|
+
return validacoes.eRegistroNacional(this._registroNacional);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
Beneficiario.prototype.comCNPJ = function (_cnpj) {
|
|
205
|
+
this.comRegistroNacional(_cnpj);
|
|
206
|
+
return this;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
Beneficiario.prototype.comCPF = function (_cpf) {
|
|
210
|
+
this.comRegistroNacional(_cpf);
|
|
211
|
+
return this;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
Beneficiario.prototype.comRegistroNacional = function (_registroNacional) {
|
|
215
|
+
this._registroNacional = _registroNacional;
|
|
216
|
+
return this;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
Beneficiario.prototype.comAgencia = function (_agencia) {
|
|
220
|
+
this._agencia = _agencia;
|
|
221
|
+
return this;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
Beneficiario.prototype.getAgencia = function () {
|
|
225
|
+
return this._agencia;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
Beneficiario.prototype.comCodPosto = function (_posto) {
|
|
230
|
+
this._posto = _posto;
|
|
231
|
+
return this;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
Beneficiario.prototype.getCodposto = function () {
|
|
235
|
+
return this._posto;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
Beneficiario.prototype.getAgenciaFormatada = function () {
|
|
239
|
+
return pad(this._agencia, 4, '0');
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
Beneficiario.prototype.comDigitoAgencia = function (_digitoAgencia) {
|
|
243
|
+
this._digitoAgencia = _digitoAgencia;
|
|
244
|
+
return this;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
Beneficiario.prototype.getDigitoAgencia = function () {
|
|
248
|
+
return this._digitoAgencia;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
Beneficiario.prototype.comCodigoBeneficiario = function (_codigo) {
|
|
252
|
+
this._codigo = _codigo;
|
|
253
|
+
return this;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
Beneficiario.prototype.getCodigoBeneficiario = function () {
|
|
257
|
+
return this._codigo;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
Beneficiario.prototype.getDigitoCodigoBeneficiario = function () {
|
|
261
|
+
return this._digitoCodigoBeneficiario;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
Beneficiario.prototype.comDigitoCodigoBeneficiario = function (_digitoCodigoBeneficiario) {
|
|
265
|
+
this._digitoCodigoBeneficiario = _digitoCodigoBeneficiario;
|
|
266
|
+
return this;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
Beneficiario.prototype.getCarteira = function () {
|
|
270
|
+
return this._carteira;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
Beneficiario.prototype.comCarteira = function (_carteira) {
|
|
274
|
+
this._carteira = _carteira;
|
|
275
|
+
return this;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
Beneficiario.prototype.getNossoNumero = function () {
|
|
279
|
+
return this._nossoNumero;
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
Beneficiario.prototype.comNossoNumero = function (_nossoNumero) {
|
|
283
|
+
this._nossoNumero = _nossoNumero;
|
|
284
|
+
return this;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
Beneficiario.prototype.getDigitoNossoNumero = function () {
|
|
288
|
+
return this._digitoNossoNumero;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
Beneficiario.prototype.comDigitoNossoNumero = function (_digitoNossoNumero) {
|
|
292
|
+
this._digitoNossoNumero = _digitoNossoNumero;
|
|
293
|
+
return this;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
Beneficiario.prototype.getNome = function () {
|
|
297
|
+
return this._nome;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
Beneficiario.prototype.comNome = function (_nomeBeneficiario) {
|
|
301
|
+
this._nome = _nomeBeneficiario;
|
|
302
|
+
return this;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
Beneficiario.prototype.getEndereco = function () {
|
|
306
|
+
return this._endereco;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
Beneficiario.prototype.comEndereco = function (_endereco) {
|
|
310
|
+
this._endereco = _endereco;
|
|
311
|
+
return this;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
Beneficiario.prototype.getNumeroConvenio = function () {
|
|
315
|
+
return this._numeroConvenio;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
Beneficiario.prototype.comNumeroConvenio = function (_numeroConvenio) {
|
|
319
|
+
this._numeroConvenio = _numeroConvenio;
|
|
320
|
+
return this;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
Beneficiario.prototype.getDocumento = function () {
|
|
324
|
+
return this._documento;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
Beneficiario.prototype.comDocumento = function (_documento) {
|
|
328
|
+
this._documento = _documento;
|
|
329
|
+
return this;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
Beneficiario.prototype.novoBeneficiario = function () {
|
|
333
|
+
return new Beneficiario().comEndereco(Endereco.novoEndereco());
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
Beneficiario.novoBeneficiario = function () {
|
|
337
|
+
return new Beneficiario();
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
return Beneficiario;
|
|
341
|
+
})();
|
|
342
|
+
|
|
343
|
+
module.exports.Beneficiario = Beneficiario;
|
|
344
|
+
|
|
345
|
+
var Datas = (function () {
|
|
346
|
+
function removerHoras(data) {
|
|
347
|
+
data.setHours(0);
|
|
348
|
+
data.setMinutes(0);
|
|
349
|
+
data.setSeconds(0);
|
|
350
|
+
data.setMilliseconds(0);
|
|
351
|
+
|
|
352
|
+
return data;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function formatar(data) {
|
|
356
|
+
return [
|
|
357
|
+
pad(data.getDate(), 2, '0'),
|
|
358
|
+
pad(data.getMonth() + 1, 2, '0'),
|
|
359
|
+
data.getFullYear()
|
|
360
|
+
].join('/');
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function validarData(data) {
|
|
364
|
+
var ano = data.getFullYear();
|
|
365
|
+
return ano >= 1997 && ano < 2029;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function Datas() {
|
|
369
|
+
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
Datas.prototype.comDocumento = function (_documento, locate = 'usa') {
|
|
373
|
+
if (locate === 'usa') {
|
|
374
|
+
_documento = new Date(_documento);
|
|
375
|
+
} else if (locate === 'brl') {
|
|
376
|
+
_documento = new Date(moment(new Date(_documento)).format('YYYY-MM-DD'));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
if (!validarData(_documento)) {
|
|
381
|
+
throw new Error('O ano do documento deve ser maior que 1997 e menor que 2029');
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
this._documento = removerHoras(_documento);
|
|
385
|
+
return this;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
Datas.prototype.getDocumento = function () {
|
|
389
|
+
return this._documento;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
Datas.prototype.getDocumentoFormatado = function () {
|
|
393
|
+
return formatar(this.getDocumento());
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
Datas.prototype.comProcessamento = function (_processamento, locate = 'usa') {
|
|
397
|
+
if (locate === 'usa') {
|
|
398
|
+
_processamento = new Date(_processamento);
|
|
399
|
+
} else if (locate === 'brl') {
|
|
400
|
+
_processamento = new Date(moment(new Date(_processamento)).format('YYYY-MM-DD'));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
if (!validarData(_processamento)) {
|
|
405
|
+
throw new Error('O ano do documento deve ser maior que 1997 e menor que 2024');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
this._processamento = removerHoras(_processamento);
|
|
409
|
+
return this;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
Datas.prototype.getProcessamento = function () {
|
|
413
|
+
return this._processamento;
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
Datas.prototype.getProcessamentoFormatado = function () {
|
|
417
|
+
return formatar(this.getProcessamento());
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
Datas.prototype.comVencimento = function (_vencimento, locate = 'usa') {
|
|
421
|
+
if (locate == 'usa') {
|
|
422
|
+
_vencimento = new Date(_vencimento);
|
|
423
|
+
} else if (locate == 'brl') {
|
|
424
|
+
_vencimento = new Date(moment(new Date(_vencimento)).format('YYYY-MM-DD'));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
if (!validarData(_vencimento)) {
|
|
429
|
+
throw new Error('O ano do documento deve ser maior que 1997 e menor que 2024');
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
this._vencimento = removerHoras(_vencimento);
|
|
433
|
+
return this;
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
Datas.prototype.getVencimento = function () {
|
|
437
|
+
return this._vencimento;
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
Datas.prototype.getVencimentoFormatado = function () {
|
|
441
|
+
return formatar(this._vencimento);
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
Datas.novasDatas = function () {
|
|
445
|
+
return new Datas();
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
return Datas;
|
|
449
|
+
})();
|
|
450
|
+
|
|
451
|
+
module.exports.Datas = Datas;
|
|
452
|
+
|
|
453
|
+
var Endereco = (function () {
|
|
454
|
+
function Endereco() {
|
|
455
|
+
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
Endereco.prototype.getLogradouro = function () {
|
|
459
|
+
return this._logradouro || '';
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
Endereco.prototype.comLogradouro = function (_logradouro) {
|
|
463
|
+
this._logradouro = _logradouro;
|
|
464
|
+
return this;
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
Endereco.prototype.getBairro = function () {
|
|
468
|
+
return this._bairro || '';
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
Endereco.prototype.comBairro = function (_bairro) {
|
|
472
|
+
this._bairro = _bairro;
|
|
473
|
+
return this;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
Endereco.prototype.getCep = function () {
|
|
477
|
+
return this._cep || '';
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
Endereco.prototype.getCepFormatado = function () {
|
|
481
|
+
return formatacoes.cep(this.getCep());
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
Endereco.prototype.comCep = function (_cep) {
|
|
485
|
+
this._cep = _cep;
|
|
486
|
+
return this;
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
Endereco.prototype.getCidade = function () {
|
|
490
|
+
return this._cidade || '';
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
Endereco.prototype.comCidade = function (_cidade) {
|
|
494
|
+
this._cidade = _cidade;
|
|
495
|
+
return this;
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
Endereco.prototype.getUf = function () {
|
|
499
|
+
return this._uf || '';
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
Endereco.prototype.comUf = function (_uf) {
|
|
503
|
+
this._uf = _uf;
|
|
504
|
+
return this;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
Endereco.prototype.getPrimeiraLinha = function () {
|
|
508
|
+
var resultado = '';
|
|
509
|
+
|
|
510
|
+
if (this.getLogradouro()) {
|
|
511
|
+
resultado += this.getLogradouro();
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (this.getLogradouro() && this.getBairro()) {
|
|
515
|
+
resultado += ', ';
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (this.getBairro()) {
|
|
519
|
+
resultado += this.getBairro();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return resultado;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
Endereco.prototype.getSegundaLinha = function () {
|
|
526
|
+
var resultado = '';
|
|
527
|
+
|
|
528
|
+
if (this.getCidade()) {
|
|
529
|
+
resultado += this.getCidade();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (this.getCidade() && this.getUf()) {
|
|
533
|
+
resultado += '/';
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (this.getUf()) {
|
|
537
|
+
resultado += this.getUf();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (resultado && this.getCep()) {
|
|
541
|
+
resultado += ' — ';
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (this.getCep()) {
|
|
545
|
+
resultado += this.getCepFormatado();
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
return resultado;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
Endereco.prototype.getEnderecoCompleto = function () {
|
|
552
|
+
var enderecoCompleto = [];
|
|
553
|
+
|
|
554
|
+
this.getLogradouro() && enderecoCompleto.push(this.getLogradouro());
|
|
555
|
+
this.getBairro() && enderecoCompleto.push(this.getBairro());
|
|
556
|
+
this.getCep() && enderecoCompleto.push(this.getCepFormatado());
|
|
557
|
+
this.getCidade() && enderecoCompleto.push(this.getCidade());
|
|
558
|
+
this.getUf() && enderecoCompleto.push(this.getUf());
|
|
559
|
+
|
|
560
|
+
return enderecoCompleto.join(' ');
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
Endereco.novoEndereco = function () {
|
|
564
|
+
return new Endereco();
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
return Endereco;
|
|
568
|
+
})();
|
|
569
|
+
|
|
570
|
+
module.exports.Endereco = Endereco;
|
|
571
|
+
|
|
572
|
+
var Boleto = (function () {
|
|
573
|
+
var DATA_BASE = new Date(1997, 10 - 1, 7);
|
|
574
|
+
|
|
575
|
+
function Boleto() {
|
|
576
|
+
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function formatarValor(valor) {
|
|
580
|
+
var valorArray = valor.toString().split('.'),
|
|
581
|
+
inteiros = valorArray[0],
|
|
582
|
+
decimais = valorArray.length > 1 ? valorArray[1] : '00';
|
|
583
|
+
|
|
584
|
+
decimais = pad(decimais, 2, '0', 'right').substr(0, 2);
|
|
585
|
+
|
|
586
|
+
return pad(inteiros + decimais, 10, '0');
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function formatarBRL(valor) {
|
|
590
|
+
var zeroAEsquerda = true,
|
|
591
|
+
i = -1;
|
|
592
|
+
|
|
593
|
+
return 'R$ ' + (valor.substr(0, 8).split('').reduce(function (acc, cur) {
|
|
594
|
+
if (cur === '0' && zeroAEsquerda) {
|
|
595
|
+
return acc;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
zeroAEsquerda = false;
|
|
599
|
+
return acc + cur;
|
|
600
|
+
}, '').split('').reduceRight(function (acc, cur) {
|
|
601
|
+
i++;
|
|
602
|
+
return cur + (i !== 0 && i % 3 === 0 ? '.' : '') + acc;
|
|
603
|
+
}, '') || 0) + ',' + valor.substr(8, 2);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
Boleto.prototype.getFatorVencimento = function () {
|
|
607
|
+
var vencimento = this.getDatas().getVencimento(),
|
|
608
|
+
diferencaEmDias = (vencimento - DATA_BASE) / (1000 * 60 * 60 * 24);
|
|
609
|
+
|
|
610
|
+
if (diferencaEmDias > 9999) {
|
|
611
|
+
diferencaEmDias = (diferencaEmDias % 10000);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
return Math.floor(diferencaEmDias).toString();
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
Boleto.prototype.comEspecieMoeda = function (_especieMoeda) {
|
|
618
|
+
this._especieMoeda = _especieMoeda;
|
|
619
|
+
return this;
|
|
620
|
+
};
|
|
621
|
+
|
|
622
|
+
Boleto.prototype.getEspecieMoeda = function () {
|
|
623
|
+
return this._especieMoeda;
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
Boleto.prototype.getCodigoEspecieMoeda = function () {
|
|
627
|
+
return this._codigoEspecieMoeda;
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
Boleto.prototype.comCodigoEspecieMoeda = function (_codigoEspecieMoeda) {
|
|
631
|
+
this._codigoEspecieMoeda = _codigoEspecieMoeda.toString();
|
|
632
|
+
return this;
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
Boleto.prototype.getAceite = function () {
|
|
636
|
+
return this._aceite;
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
Boleto.prototype.getAceiteFormatado = function () {
|
|
640
|
+
return this._aceite ? 'S' : 'N';
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
Boleto.prototype.comAceite = function (_aceite) {
|
|
644
|
+
this._aceite = _aceite;
|
|
645
|
+
return this;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
Boleto.prototype.getEspecieDocumento = function () {
|
|
649
|
+
return this._especieDocumento;
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
Boleto.prototype.comEspecieDocumento = function (_especieDocumento) {
|
|
653
|
+
this._especieDocumento = _especieDocumento;
|
|
654
|
+
return this;
|
|
655
|
+
};
|
|
656
|
+
|
|
657
|
+
Boleto.prototype.getDatas = function () {
|
|
658
|
+
return this._datas;
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
Boleto.prototype.comDatas = function (_datas) {
|
|
662
|
+
this._datas = _datas;
|
|
663
|
+
return this;
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
Boleto.prototype.getValorFormatado = function () {
|
|
667
|
+
return formatarValor(this._valorBoleto);
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
Boleto.prototype.getValorFormatadoBRL = function () {
|
|
671
|
+
return formatarBRL(this.getValorFormatado());
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
Boleto.prototype.getValorBoleto = function () {
|
|
675
|
+
return this._valorBoleto;
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
Boleto.prototype.comValorBoleto = function (_valorBoleto) {
|
|
679
|
+
if (_valorBoleto < 0) {
|
|
680
|
+
throw new Error('Valor deve ser maior ou igual a zero');
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
if (_valorBoleto > 99999999.99) {
|
|
684
|
+
throw new Error('Valor deve ser menor do que noventa e nove milhoes');
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
this._valorBoleto = _valorBoleto;
|
|
688
|
+
return this;
|
|
689
|
+
};
|
|
690
|
+
|
|
691
|
+
Boleto.prototype.comValor = function (_valorBoleto) {
|
|
692
|
+
this.comValorBoleto(_valorBoleto);
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
Boleto.prototype.getNumeroDoDocumentoFormatado = function () {
|
|
696
|
+
return pad(this._numeroDoDocumento || '', 4, '0');
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
Boleto.prototype.getNumeroDoDocumento = function () {
|
|
700
|
+
return this._numeroDoDocumento || '';
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
Boleto.prototype.comNumeroDoDocumento = function (_numeroDoDocumento) {
|
|
704
|
+
this._numeroDoDocumento = _numeroDoDocumento;
|
|
705
|
+
return this;
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
Boleto.prototype.getInstrucoes = function () {
|
|
709
|
+
return this._instrucoes || [];
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
Boleto.prototype.comInstrucoes = function (_instrucoes) {
|
|
713
|
+
if (arguments.length > 1) {
|
|
714
|
+
_instrucoes = Array.prototype.slice.call(arguments, 0);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (typeof _instrucoes === 'string') {
|
|
718
|
+
_instrucoes = [_instrucoes];
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
if (_instrucoes.length > 5) {
|
|
722
|
+
throw new Error('Máximo de cinco instruções permitidas');
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
this._instrucoes = _instrucoes;
|
|
726
|
+
return this;
|
|
727
|
+
};
|
|
728
|
+
|
|
729
|
+
Boleto.prototype.getDescricoes = function () {
|
|
730
|
+
return this._descricoes || [];
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
Boleto.prototype.comDescricoes = function (_descricoes) {
|
|
734
|
+
if (arguments.length > 1) {
|
|
735
|
+
_descricoes = Array.prototype.slice.call(arguments, 0);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
if (typeof _descricoes === 'string') {
|
|
739
|
+
_descricoes = [_descricoes];
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
if (_descricoes.length > 5) {
|
|
743
|
+
throw new Error('Máximo de cinco instruções permitidas');
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
this._descricoes = _descricoes;
|
|
747
|
+
return this;
|
|
748
|
+
},
|
|
749
|
+
|
|
750
|
+
Boleto.prototype.getLocaisDePagamento = function () {
|
|
751
|
+
if (this._locaisDePagamento) return this._locaisDePagamento;
|
|
752
|
+
if (this.getBanco().getLocaisDePagamentoPadrao) return this.getBanco().getLocaisDePagamentoPadrao();
|
|
753
|
+
return [];
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
Boleto.prototype.comLocaisDePagamento = function (_locaisDePagamento) {
|
|
757
|
+
if (arguments.length > 1) {
|
|
758
|
+
_locaisDePagamento = Array.prototype.slice.call(arguments, 0);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (typeof _locaisDePagamento === 'string') {
|
|
762
|
+
_locaisDePagamento = [_locaisDePagamento];
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
if (_locaisDePagamento.length > 2) {
|
|
766
|
+
throw new Error('Máximo de dois locais de pagamento permitidos');
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
this._locaisDePagamento = _locaisDePagamento;
|
|
770
|
+
return this;
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
Boleto.prototype.getQuantidadeDeMoeda = function () {
|
|
774
|
+
return this._quantidadeDeMoeda;
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
Boleto.prototype.comQuantidadeDeMoeda = function (_quantidadeDeMoeda) {
|
|
778
|
+
this._quantidadeDeMoeda = _quantidadeDeMoeda;
|
|
779
|
+
return this;
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
Boleto.prototype.getBanco = function () {
|
|
783
|
+
return this._banco;
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
Boleto.prototype.comBanco = function (_banco) {
|
|
787
|
+
this._banco = _banco;
|
|
788
|
+
return this;
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
Boleto.prototype.getPagador = function () {
|
|
792
|
+
return this._pagador;
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
Boleto.prototype.comPagador = function (_pagador) {
|
|
796
|
+
this._pagador = _pagador;
|
|
797
|
+
return this;
|
|
798
|
+
};
|
|
799
|
+
|
|
800
|
+
Boleto.prototype.getBeneficiario = function () {
|
|
801
|
+
return this._beneficiario;
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
Boleto.prototype.comBeneficiario = function (_beneficiario) {
|
|
805
|
+
this._beneficiario = _beneficiario;
|
|
806
|
+
return this;
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
Boleto.prototype.getValorDescontosFormatadoBRL = function () {
|
|
810
|
+
if (!this.getValorDescontos()) {
|
|
811
|
+
return '';
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
return formatarBRL(formatarValor(this.getValorDescontos()));
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
Boleto.prototype.getValorDescontos = function () {
|
|
818
|
+
return this._valorDescontos || 0;
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
Boleto.prototype.comValorDescontos = function (_valorDescontos) {
|
|
822
|
+
this._valorDescontos = _valorDescontos;
|
|
823
|
+
return this;
|
|
824
|
+
};
|
|
825
|
+
|
|
826
|
+
Boleto.prototype.getValorDeducoesFormatadoBRL = function () {
|
|
827
|
+
if (!this.getValorDeducoes()) {
|
|
828
|
+
return '';
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
return formatarBRL(formatarValor(this.getValorDeducoes()));
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
Boleto.prototype.getValorDeducoes = function () {
|
|
835
|
+
return this._valorDeducoes || 0;
|
|
836
|
+
};
|
|
837
|
+
|
|
838
|
+
Boleto.prototype.comValorDeducoes = function (_valorDeducoes) {
|
|
839
|
+
this._valorDeducoes = _valorDeducoes;
|
|
840
|
+
return this;
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
Boleto.prototype.getValorMultaFormatadoBRL = function () {
|
|
844
|
+
return formatarBRL(formatarValor(this.getValorMulta()));
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
Boleto.prototype.getValorMulta = function () {
|
|
848
|
+
return this._valorMulta || 0;
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
Boleto.prototype.comValorMulta = function (_valorMulta) {
|
|
852
|
+
this._valorMulta = _valorMulta;
|
|
853
|
+
return this;
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
Boleto.prototype.getValorAcrescimosFormatadoBRL = function () {
|
|
857
|
+
return formatarBRL(formatarValor(this.getValorAcrescimos()));
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
Boleto.prototype.getValorAcrescimos = function () {
|
|
861
|
+
return this._valorAcrescimos || 0;
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
Boleto.prototype.comValorAcrescimos = function (_valorAcrescimos) {
|
|
865
|
+
this._valorAcrescimos = _valorAcrescimos;
|
|
866
|
+
return this;
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
Boleto.prototype.getLinhaDigitavelFormatado = function () {
|
|
870
|
+
const numeroDocumento = this.getNumeroDoDocumentoFormatado();
|
|
871
|
+
const linha = GeradorDeLinhaDigitavel(this._banco.geraCodigoDeBarrasPara(this), this._banco);
|
|
872
|
+
return {linha, numeroDocumento};
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
Boleto.prototype.comQrCode = function (_qrCode) {
|
|
876
|
+
this._qrCode = _qrCode;
|
|
877
|
+
return this;
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
Boleto.prototype.getQrCode = function () {
|
|
881
|
+
return this._qrCode;
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
Boleto.novoBoleto = function () {
|
|
885
|
+
return new Boleto()
|
|
886
|
+
.comEspecieMoeda('R$')
|
|
887
|
+
.comCodigoEspecieMoeda(9)
|
|
888
|
+
.comAceite(false)
|
|
889
|
+
.comEspecieDocumento('DV');
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
return Boleto;
|
|
893
|
+
})();
|
|
894
|
+
|
|
895
|
+
module.exports.Boleto = Boleto;
|