@plasoft/boletos 1.0.46 → 1.0.48

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
@@ -1,3 +1,22 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
1
20
  var __async = (__this, __arguments, generator) => {
2
21
  return new Promise((resolve, reject) => {
3
22
  var fulfilled = (value) => {
@@ -200,7 +219,7 @@ function getPathTemplates(template) {
200
219
  import "dotenv/config";
201
220
  import axios from "axios";
202
221
  var api = axios.create({
203
- baseURL: process.env.API_URL
222
+ baseURL: process.env.API_URL || "https://23136fv876.execute-api.sa-east-1.amazonaws.com/dev/create-report"
204
223
  });
205
224
 
206
225
  // src/utils/zip.ts
@@ -642,6 +661,7 @@ var Banco = /* @__PURE__ */ ((Banco2) => {
642
661
  Banco2["SICREDI"] = "748";
643
662
  Banco2["SICOOB"] = "756";
644
663
  Banco2["BANCO_BRASIL"] = "001";
664
+ Banco2["ITAU"] = "341";
645
665
  return Banco2;
646
666
  })(Banco || {});
647
667
 
@@ -2568,6 +2588,111 @@ function gerar({ banco, dados }) {
2568
2588
  }
2569
2589
  }
2570
2590
 
2591
+ // src/banks/itau/gerarPDF.ts
2592
+ import BwipJs6 from "bwip-js";
2593
+ function gerarPDF6(_0) {
2594
+ return __async(this, arguments, function* ({ dados }) {
2595
+ try {
2596
+ const { dadosPDF } = dados;
2597
+ if (!dadosPDF.pagador.cnpj) {
2598
+ throw new Error("CPF/CNPJ do pagador na\u0303o informado!");
2599
+ }
2600
+ const codigoBarra2 = yield BwipJs6.toBuffer({
2601
+ bcid: "interleaved2of5",
2602
+ text: dadosPDF.boleto.codigoBarra,
2603
+ height: 20
2604
+ });
2605
+ dadosPDF.beneficiario.dadosBancario.agencia = dadosPDF.beneficiario.dadosBancario.agencia.padStart(4, "0");
2606
+ dadosPDF.boleto.linhaDigitavel = maskFormat_default.codigoBarra(dadosPDF.boleto.linhaDigitavel);
2607
+ dadosPDF.beneficiario.cnpj = maskFormat_default.retornaCpfCnpjFormatado(
2608
+ dadosPDF.beneficiario.cnpj
2609
+ );
2610
+ dadosPDF.beneficiario.endereco.cep = maskFormat_default.retornaCEPFormatado(
2611
+ dadosPDF.beneficiario.endereco.cep
2612
+ );
2613
+ dadosPDF.pagador.endereco.cep = maskFormat_default.retornaCEPFormatado(
2614
+ dadosPDF.pagador.endereco.cep
2615
+ );
2616
+ dadosPDF.pagador.cnpj = maskFormat_default.retornaCpfCnpjFormatado(dadosPDF.pagador.cnpj);
2617
+ const valorDocumento = Number(dadosPDF.boleto.valorDocumento);
2618
+ dadosPDF.boleto.valorDocumento = maskFormat_default.numberToReal(
2619
+ dadosPDF.boleto.valorDocumento
2620
+ );
2621
+ const jurosMes = dadosPDF.beneficiario.dadosBancario.juros;
2622
+ const jurosDia = jurosMes / 100 / 30 * valorDocumento;
2623
+ if (jurosDia > 0) {
2624
+ dadosPDF.boleto.instrucoes = [`AP\xD3S O VENCIMENTO, COBRAR JUROS DE R$${maskFormat_default.numberToReal(jurosDia)} AO DIA`, ...dadosPDF.boleto.instrucoes];
2625
+ }
2626
+ const descontoVencimento = dadosPDF.beneficiario.dadosBancario.desconto || 0;
2627
+ if (descontoVencimento > 0) {
2628
+ dadosPDF.boleto.instrucoes = [`AT\xC9 O VENCIMENTO, CONCEDER DESCONTO DE ${descontoVencimento}%`, ...dadosPDF.boleto.instrucoes];
2629
+ }
2630
+ const multaAtraso = dadosPDF.beneficiario.dadosBancario.multa || 0;
2631
+ if (multaAtraso > 0) {
2632
+ dadosPDF.boleto.instrucoes = [`MULTA DE ${multaAtraso}%`, ...dadosPDF.boleto.instrucoes];
2633
+ }
2634
+ const protestoDias = dadosPDF.beneficiario.dadosBancario.protesto || 0;
2635
+ if (protestoDias > 0) {
2636
+ dadosPDF.boleto.instrucoes = [`PROTESTAR AP\xD3S ${protestoDias} DIAS CORRIDOS DO VENCIMENTO`, ...dadosPDF.boleto.instrucoes];
2637
+ }
2638
+ const content = compileHbs(getPathTemplates("itau-boleto.hbs"), __spreadProps(__spreadValues({}, dadosPDF), {
2639
+ boleto: __spreadProps(__spreadValues({}, dadosPDF.boleto), {
2640
+ codigoBarraImage: codigoBarra2.toString("base64"),
2641
+ nossoNumeroDigito: getDigito6(`${dadosPDF.beneficiario.dadosBancario.agencia}${dadosPDF.beneficiario.dadosBancario.conta}${dadosPDF.beneficiario.dadosBancario.codigoCarteira}${dadosPDF.boleto.nossoNumero}`)
2642
+ })
2643
+ }));
2644
+ const config = {
2645
+ displayHeaderFooter: false,
2646
+ path: "./boleto.pdf",
2647
+ format: "a4",
2648
+ printBackground: true
2649
+ };
2650
+ const response = yield api.post("/", { content, config });
2651
+ const buffer = Buffer.from(response.data.pdf);
2652
+ const pdfBase64 = yield decompress(buffer);
2653
+ return {
2654
+ erro: false,
2655
+ dados: pdfBase64
2656
+ };
2657
+ } catch (error) {
2658
+ console.log(error);
2659
+ return {
2660
+ erro: true,
2661
+ dados: "Falha ao gerar impress\xE3o do boleto"
2662
+ };
2663
+ }
2664
+ });
2665
+ }
2666
+ function getDigito6(texto) {
2667
+ let i = texto.length;
2668
+ let j = 1;
2669
+ let total = 0;
2670
+ let soma = 0;
2671
+ let digito = 0;
2672
+ while (i >= 1) {
2673
+ j = j === 1 ? 2 : 1;
2674
+ let valor = Number(copy(texto, i, i));
2675
+ total = valor * j;
2676
+ if (total >= 10) {
2677
+ valor = Number(copy(total, 1, 1)) + Number(copy(total, 2, 2));
2678
+ } else {
2679
+ valor = total;
2680
+ }
2681
+ soma += valor;
2682
+ i--;
2683
+ }
2684
+ const uni = Number(copy(soma, String(soma).length, String(soma).length));
2685
+ digito = 10 - uni;
2686
+ if (digito === 10)
2687
+ digito = 0;
2688
+ return String(digito);
2689
+ }
2690
+
2691
+ // src/banks/itau/index.ts
2692
+ var itau = {
2693
+ gerarPDF: gerarPDF6
2694
+ };
2695
+
2571
2696
  // src/pdf.ts
2572
2697
  function pdf({ banco, dados }) {
2573
2698
  if (banco === "085" /* AILOS */) {
@@ -2585,6 +2710,9 @@ function pdf({ banco, dados }) {
2585
2710
  if (banco === "001" /* BANCO_BRASIL */) {
2586
2711
  return bancoBrasil.gerarPDF({ banco, dados });
2587
2712
  }
2713
+ if (banco === "341" /* ITAU */) {
2714
+ return itau.gerarPDF({ banco, dados });
2715
+ }
2588
2716
  }
2589
2717
 
2590
2718
  // src/remessa.ts
@@ -2648,3 +2776,4 @@ export {
2648
2776
  src_default as default,
2649
2777
  defineConfig
2650
2778
  };
2779
+ //# sourceMappingURL=index.mjs.map