@plasoft/boletos 1.0.19 → 1.0.21

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.mjs CHANGED
@@ -19,9 +19,6 @@ var __async = (__this, __arguments, generator) => {
19
19
  });
20
20
  };
21
21
 
22
- // src/banks/ailos/gerarDadosBoleto.ts
23
- import { differenceInDays } from "date-fns";
24
-
25
22
  // src/utils/pafLeft.ts
26
23
  function padLeft(numero, tamanho) {
27
24
  numero = String(numero);
@@ -49,6 +46,17 @@ function copy(texto, startPosition, endPosition) {
49
46
  return retorno2;
50
47
  }
51
48
 
49
+ // src/utils/getFatorVencimento.ts
50
+ import { differenceInDays } from "date-fns";
51
+ function getFatorVencimento(vencimento) {
52
+ vencimento = new Date(vencimento);
53
+ if (vencimento >= new Date(2025, 1, 22)) {
54
+ return differenceInDays(new Date(vencimento), new Date(2022, 4, 29)).toString();
55
+ } else {
56
+ return differenceInDays(new Date(vencimento), new Date(1997, 9, 7)).toString();
57
+ }
58
+ }
59
+
52
60
  // src/banks/ailos/gerarDadosBoleto.ts
53
61
  function gerarDadosBoleto({ dados }) {
54
62
  try {
@@ -88,10 +96,6 @@ function gerarDadosBoleto({ dados }) {
88
96
  return null;
89
97
  }
90
98
  }
91
- function getFatorVencimento(vencimento) {
92
- const data = new Date(1997, 9, 7);
93
- return differenceInDays(new Date(vencimento), data).toString();
94
- }
95
99
  function getValor(valor) {
96
100
  const valorFormatado = valor.toFixed(2).replace(/\D/g, "");
97
101
  return padLeft(valorFormatado, 10);
@@ -199,6 +203,19 @@ var api = axios.create({
199
203
  baseURL: process.env.API_URL
200
204
  });
201
205
 
206
+ // src/utils/zip.ts
207
+ import * as zlib from "zlib";
208
+ function decompress(input) {
209
+ return new Promise((resolve, reject) => {
210
+ zlib.gunzip(input, (error, result) => {
211
+ if (error) {
212
+ return reject(error);
213
+ }
214
+ resolve(result.toString());
215
+ });
216
+ });
217
+ }
218
+
202
219
  // src/banks/ailos/gerarPDF.ts
203
220
  function gerarPDF(_0) {
204
221
  return __async(this, arguments, function* ({ dados }) {
@@ -275,7 +292,8 @@ function gerarPDF(_0) {
275
292
  throw new Error("BaseURL api not found");
276
293
  }
277
294
  const response = yield api.post("/", { content, config });
278
- pdfBase64 = response.data;
295
+ const buffer = Buffer.from(response.data.pdf);
296
+ pdfBase64 = yield decompress(buffer);
279
297
  }
280
298
  return {
281
299
  erro: false,
@@ -285,7 +303,7 @@ function gerarPDF(_0) {
285
303
  console.log(error);
286
304
  return {
287
305
  erro: true,
288
- dados: error
306
+ dados: null
289
307
  };
290
308
  }
291
309
  });
@@ -616,12 +634,11 @@ var Banco = /* @__PURE__ */ ((Banco2) => {
616
634
  })(Banco || {});
617
635
 
618
636
  // src/banks/bradesco/gerarDadosBoleto.ts
619
- import { differenceInDays as differenceInDays2 } from "date-fns";
620
637
  function gerarDadosBoleto2({ dados }) {
621
638
  try {
622
639
  const { bancario, parcela } = dados;
623
640
  parcela.valor = Number(parcela.valor);
624
- const fatorVencimento = getFatorVencimento2(parcela.vencimento);
641
+ const fatorVencimento = getFatorVencimento(parcela.vencimento);
625
642
  const valor = getValor2(parcela.valor);
626
643
  const convenio = padLeft(bancario.convenio, 6);
627
644
  const numeroDocumento = padLeft(`${parcela.id_boleto}`, 9);
@@ -656,10 +673,6 @@ function gerarDadosBoleto2({ dados }) {
656
673
  return null;
657
674
  }
658
675
  }
659
- function getFatorVencimento2(vencimento) {
660
- const data = new Date(1997, 9, 7);
661
- return differenceInDays2(new Date(vencimento), data).toString();
662
- }
663
676
  function getValor2(valor) {
664
677
  const valorFormatado = valor.toFixed(2).replace(/\D/g, "");
665
678
  return padLeft(valorFormatado, 10);
@@ -767,7 +780,8 @@ function gerarPDF2(_0) {
767
780
  throw new Error("BaseURL api not found");
768
781
  }
769
782
  const response = yield api.post("/", { content, config });
770
- pdfBase64 = response.data;
783
+ const buffer = Buffer.from(response.data.pdf);
784
+ pdfBase64 = yield decompress(buffer);
771
785
  }
772
786
  return {
773
787
  erro: false,
@@ -1076,12 +1090,11 @@ var bradesco = {
1076
1090
  };
1077
1091
 
1078
1092
  // src/banks/sicredi/gerarDadosBoleto.ts
1079
- import { differenceInDays as differenceInDays3 } from "date-fns";
1080
1093
  function gerarDadosBoleto3({ dados }) {
1081
1094
  try {
1082
1095
  const { bancario, parcela } = dados;
1083
1096
  parcela.valor = Number(parcela.valor);
1084
- const fatorVencimento = getFatorVencimento3(parcela.vencimento);
1097
+ const fatorVencimento = getFatorVencimento(parcela.vencimento);
1085
1098
  const valor = getValor3(parcela.valor);
1086
1099
  const nossoNumero = getNossoNumero(
1087
1100
  parcela.numeroUnico,
@@ -1139,10 +1152,6 @@ function getNossoNumero(id, agencia, posto, codigoCedente) {
1139
1152
  digito = 0;
1140
1153
  return id.padStart(8, "0") + digito.toString();
1141
1154
  }
1142
- function getFatorVencimento3(vencimento) {
1143
- const data = new Date(1997, 9, 7);
1144
- return differenceInDays3(new Date(vencimento), data).toString();
1145
- }
1146
1155
  function getValor3(valor) {
1147
1156
  const valorFormatado = valor.toFixed(2).replace(/\D/g, "");
1148
1157
  return valorFormatado.padStart(10, "0");
@@ -1285,7 +1294,8 @@ function gerarPDF3(_0) {
1285
1294
  throw new Error("BaseURL api not found");
1286
1295
  }
1287
1296
  const response = yield api.post("/", { content, config });
1288
- pdfBase64 = response.data;
1297
+ const buffer = Buffer.from(response.data.pdf);
1298
+ pdfBase64 = yield decompress(buffer);
1289
1299
  }
1290
1300
  return {
1291
1301
  erro: false,
@@ -1295,7 +1305,7 @@ function gerarPDF3(_0) {
1295
1305
  console.log(error);
1296
1306
  return {
1297
1307
  erro: true,
1298
- dados: error
1308
+ dados: null
1299
1309
  };
1300
1310
  }
1301
1311
  });
@@ -1307,15 +1317,12 @@ function gerarRemessa3({ dados }) {
1307
1317
  try {
1308
1318
  const { dadosBancario, beneficiario, boletos } = dados.remessa;
1309
1319
  const arquivo = new Arquivo();
1310
- const dataAtual = format3(/* @__PURE__ */ new Date(), "ddMMyyyy");
1311
- const dia = copy(dataAtual, 1, 2);
1312
- const mes = copy(dataAtual, 2, 4);
1320
+ const data = /* @__PURE__ */ new Date();
1313
1321
  let protestar = "00";
1314
1322
  let negativar = "0000";
1315
1323
  if (dadosBancario.diasProtesto > 0) {
1316
1324
  protestar = "06";
1317
1325
  }
1318
- const remessa2 = `${dadosBancario.codigo_cedente}`;
1319
1326
  arquivo.add("01REMESSA");
1320
1327
  arquivo.add("01");
1321
1328
  arquivo.add("COBRANCA".padEnd(15, " "));
@@ -1324,7 +1331,7 @@ function gerarRemessa3({ dados }) {
1324
1331
  arquivo.add(" ".padEnd(31, " "));
1325
1332
  arquivo.add("748");
1326
1333
  arquivo.add("SICREDI".padEnd(15, " "));
1327
- arquivo.add(format3(/* @__PURE__ */ new Date(), "yyyyMMdd"));
1334
+ arquivo.add(format3(data, "yyyyMMdd"));
1328
1335
  arquivo.add(" ".padEnd(8, " "));
1329
1336
  arquivo.add(dadosBancario.numeroRemessa.padStart(7, "0"));
1330
1337
  arquivo.add(" ".padEnd(273, " "));
@@ -1336,11 +1343,13 @@ function gerarRemessa3({ dados }) {
1336
1343
  for (const boleto of boletos) {
1337
1344
  const { pagador } = boleto;
1338
1345
  total += Number(boleto.valor);
1339
- console.log(pagador);
1340
- let nossoNumero = "100010001";
1341
- let tipoInscricao = pagador.pessoa === "F" ? "1" : "";
1342
- const desconto = dadosBancario.descontoPagamento > 0 ? dadosBancario.descontoPagamento.toFixed(2) : "0";
1343
- const dataDesconto = format3(new Date(boleto.vencimento), "ddMMyy");
1346
+ let tipoInscricao = pagador.pessoa === "F" ? "1" : "2";
1347
+ let desconto = "0000000000000";
1348
+ let dataDesconto = "000000";
1349
+ if (dadosBancario.descontoPagamento) {
1350
+ desconto = dadosBancario.descontoPagamento.toFixed(2).replace(".", "").padStart(13, "0");
1351
+ dataDesconto = format3(new Date(boleto.vencimento), "ddMMyy");
1352
+ }
1344
1353
  let valorJurosDias = Number(boleto.valor) + Number(dadosBancario.jurosMes) / 100 / 30;
1345
1354
  let multaAtraso = String(dadosBancario.multaAtraso * 100);
1346
1355
  arquivo.add("1");
@@ -1348,7 +1357,7 @@ function gerarRemessa3({ dados }) {
1348
1357
  arquivo.add(" ".padEnd(12, " "));
1349
1358
  arquivo.add("AAA");
1350
1359
  arquivo.add(" ".padEnd(28, " "));
1351
- arquivo.add(nossoNumero.padEnd(9, " "));
1360
+ arquivo.add(boleto.nossoNumero.padEnd(9, " "));
1352
1361
  arquivo.add(" ".padEnd(6, " "));
1353
1362
  arquivo.add(format3(new Date(boleto.emissao), "yyyyMMdd"));
1354
1363
  arquivo.add(" ");
@@ -1361,7 +1370,7 @@ function gerarRemessa3({ dados }) {
1361
1370
  arquivo.add(multaAtraso.padStart(4, "0"));
1362
1371
  arquivo.add(" ".padEnd(12, " "));
1363
1372
  arquivo.add("01");
1364
- arquivo.add(boleto.identificacaoTitulo.padEnd(10, " "));
1373
+ arquivo.add((boleto.numeroDocumento + "/" + boleto.parcela).padEnd(10, " "));
1365
1374
  arquivo.add(format3(new Date(boleto.vencimento), "ddMMyy"));
1366
1375
  arquivo.add(Number(boleto.valor).toFixed(2).replace(".", "").padStart(13, "0"));
1367
1376
  arquivo.add(" ".padEnd(9, " "));
@@ -1371,7 +1380,7 @@ function gerarRemessa3({ dados }) {
1371
1380
  arquivo.add(String(dadosBancario.diasProtesto).padStart(2, "0"));
1372
1381
  arquivo.add(Number(valorJurosDias).toFixed(2).replace(".", "").padStart(13, "0"));
1373
1382
  arquivo.add(dataDesconto);
1374
- arquivo.add(Number(desconto).toFixed(2).replace(".", "").padStart(13, "0"));
1383
+ arquivo.add(desconto);
1375
1384
  arquivo.add(negativar);
1376
1385
  arquivo.add("0".padEnd(22, "0"));
1377
1386
  arquivo.add(tipoInscricao);
@@ -1392,8 +1401,9 @@ function gerarRemessa3({ dados }) {
1392
1401
  arquivo.add(dadosBancario.codigo_cedente);
1393
1402
  arquivo.add(" ".padEnd(384, " "));
1394
1403
  arquivo.add(String(sequencia).padStart(6, "0"));
1404
+ arquivo.addLine();
1395
1405
  return {
1396
- download: "teste.rem",
1406
+ download: `${dadosBancario.codigo_cedente}${retornaMes(data)}${format3(data, "dd")}.crm`,
1397
1407
  arquivo: arquivo.getArquivo()
1398
1408
  };
1399
1409
  } catch (error) {
@@ -1401,6 +1411,19 @@ function gerarRemessa3({ dados }) {
1401
1411
  return null;
1402
1412
  }
1403
1413
  }
1414
+ function retornaMes(data) {
1415
+ const mes = data.getMonth() + 1;
1416
+ switch (mes) {
1417
+ case 10:
1418
+ return "O";
1419
+ case 11:
1420
+ return "N";
1421
+ case 12:
1422
+ return "D";
1423
+ default:
1424
+ return mes.toString();
1425
+ }
1426
+ }
1404
1427
 
1405
1428
  // src/banks/sicredi/index.ts
1406
1429
  var sicredi = {
@@ -1410,7 +1433,6 @@ var sicredi = {
1410
1433
  };
1411
1434
 
1412
1435
  // src/banks/sicoob/gerarDadosBoleto.ts
1413
- import { differenceInDays as differenceInDays4 } from "date-fns";
1414
1436
  function gerarDadosBoleto4({ dados }) {
1415
1437
  try {
1416
1438
  const { bancario, parcela } = dados;
@@ -1419,7 +1441,7 @@ function gerarDadosBoleto4({ dados }) {
1419
1441
  }
1420
1442
  bancario.modalidade = padLeft(bancario.modalidade, 2);
1421
1443
  const nossoNumero = getNossoNumero2(bancario.agencia, bancario.codigo_cliente, parcela.id_boleto);
1422
- const fatorVencimento = getFatorVencimento4(parcela.vencimento);
1444
+ const fatorVencimento = getFatorVencimento(parcela.vencimento);
1423
1445
  const valor = getValor4(Number(parcela.valor));
1424
1446
  const campoLivre = "1" + padLeft(copy(bancario.agencia, 1, 4), 4) + bancario.modalidade + padLeft(bancario.codigo_cliente, 7) + nossoNumero + padLeft(parcela.parcela, 3);
1425
1447
  const digitoGeral = getDigitoGeral4(`7569${fatorVencimento}${valor}${campoLivre}`);
@@ -1448,10 +1470,6 @@ function gerarDadosBoleto4({ dados }) {
1448
1470
  return null;
1449
1471
  }
1450
1472
  }
1451
- function getFatorVencimento4(vencimento) {
1452
- const data = new Date(1997, 9, 7);
1453
- return differenceInDays4(new Date(vencimento), data).toString().padStart(4, "0");
1454
- }
1455
1473
  function getNossoNumero2(numero_cooperativa, codigo_cliente, id_boleto) {
1456
1474
  const constante_calculo = "3197";
1457
1475
  numero_cooperativa = padLeft(copy(numero_cooperativa, 1, 4), 4);
@@ -1837,7 +1855,8 @@ function gerarPDF4(_0) {
1837
1855
  throw new Error("BaseURL api not found");
1838
1856
  }
1839
1857
  const response = yield api.post("/", { content, config });
1840
- pdfBase64 = response.data;
1858
+ const buffer = Buffer.from(response.data.pdf);
1859
+ pdfBase64 = yield decompress(buffer);
1841
1860
  }
1842
1861
  return {
1843
1862
  erro: false,