@plasoft/boletos 1.0.56 → 1.0.57

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
@@ -287,7 +287,7 @@ function gerarPDF(_0) {
287
287
  if (jurosDia > 0) {
288
288
  dadosPDF.boleto.instrucao1 = `COBRAR JUROS DE R$${maskFormat_default.numberToReal(jurosDia)} AO DIA, AP\xD3S O VENCIMENTO`;
289
289
  }
290
- const descontoVencimento = dadosPDF.beneficiario.dadosBancario.desconto || 0;
290
+ const descontoVencimento = dadosPDF.boleto.desconto > 0 ? dadosPDF.boleto.desconto : dadosPDF.beneficiario.dadosBancario.desconto > 0 ? dadosPDF.beneficiario.dadosBancario.desconto : 0;
291
291
  if (descontoVencimento > 0) {
292
292
  dadosPDF.boleto.instrucao2 = `AT\xC9 O VENCIMENTO, CONCEDER DESCONTO DE ${descontoVencimento}%`;
293
293
  }
@@ -454,7 +454,7 @@ function gerarRemessa({ dados }) {
454
454
  "ddMMyyyy"
455
455
  );
456
456
  const codigoDesconto = dadosBancario.descontoPagamento > 0 ? "2" : "0";
457
- const desconto = dadosBancario.descontoPagamento > 0 ? dadosBancario.descontoPagamento.toFixed(2) : "000000000000000";
457
+ const desconto = boleto.desconto > 0 ? boleto.desconto.toFixed(2) : dadosBancario.descontoPagamento > 0 ? dadosBancario.descontoPagamento.toFixed(2) : "000000000000000";
458
458
  let diasProtesto = "00";
459
459
  let protesto = "3";
460
460
  switch (dadosBancario.tipo_protesto) {
@@ -1291,9 +1291,15 @@ function gerarPDF3(_0) {
1291
1291
  if (!dadosPDF.pagador.cpfcnpj) {
1292
1292
  throw new Error("CPF/CNPJ do pagador na\u0303o informado!");
1293
1293
  }
1294
+ const codigoBarraText = dadosPDF.boleto.codigoBarra.replace(/\D/g, "");
1295
+ if (!/^\d+$/.test(codigoBarraText)) {
1296
+ throw new Error("C\xF3digo de barras cont\xE9m caracteres inv\xE1lidos. Apenas d\xEDgitos s\xE3o permitidos.");
1297
+ }
1298
+ console.log(dadosPDF.boleto.codigoBarra);
1299
+ console.log(codigoBarraText);
1294
1300
  const codigoBarra2 = yield BwipJs3.toBuffer({
1295
1301
  bcid: "interleaved2of5",
1296
- text: dadosPDF.boleto.codigoBarra,
1302
+ text: codigoBarraText,
1297
1303
  height: 20
1298
1304
  });
1299
1305
  dadosPDF.beneficiario.dadosBancario.agencia = dadosPDF.beneficiario.dadosBancario.agencia.padStart(4, "0");
@@ -1334,7 +1340,7 @@ function gerarPDF3(_0) {
1334
1340
  if (jurosDia > 0) {
1335
1341
  dadosPDF.boleto.instrucao1 = `COBRAR JUROS DE R$${maskFormat_default.numberToReal(jurosDia)} AO DIA, AP\xD3S O VENCIMENTO`;
1336
1342
  }
1337
- const descontoVencimento = dadosPDF.beneficiario.dadosBancario.desconto || 0;
1343
+ const descontoVencimento = dadosPDF.boleto.desconto > 0 ? dadosPDF.boleto.desconto : dadosPDF.beneficiario.dadosBancario.desconto > 0 ? dadosPDF.beneficiario.dadosBancario.desconto : 0;
1338
1344
  if (descontoVencimento > 0) {
1339
1345
  dadosPDF.boleto.instrucao2 = `AT\xC9 O VENCIMENTO, CONCEDER DESCONTO DE ${descontoVencimento}%`;
1340
1346
  }
@@ -1436,7 +1442,11 @@ function gerarRemessa3({ dados }) {
1436
1442
  let tipoInscricao = pagador.pessoa === "F" ? "1" : "2";
1437
1443
  let desconto = "0000000000000";
1438
1444
  let dataDesconto = "000000";
1439
- if (dadosBancario.descontoPagamento) {
1445
+ if (boleto.desconto) {
1446
+ desconto = boleto.desconto.toFixed(2).replace(".", "").padStart(13, "0");
1447
+ dataDesconto = format3(new Date(boleto.vencimento), "ddMMyy");
1448
+ }
1449
+ if (!boleto.desconto && dadosBancario.descontoPagamento) {
1440
1450
  desconto = dadosBancario.descontoPagamento.toFixed(2).replace(".", "").padStart(13, "0");
1441
1451
  dataDesconto = format3(new Date(boleto.vencimento), "ddMMyy");
1442
1452
  }
@@ -2282,7 +2292,7 @@ function gerarPDF5(_0) {
2282
2292
  if (jurosDia > 0) {
2283
2293
  dadosPDF.boleto.instrucao1 = `COBRAR JUROS DE R$${jurosDia} AO DIA, AP\xD3S O VENCIMENTO`;
2284
2294
  }
2285
- const descontoVencimento = dadosPDF.beneficiario.dadosBancario.desconto || 0;
2295
+ const descontoVencimento = dadosPDF.boleto.desconto > 0 ? dadosPDF.boleto.desconto : dadosPDF.beneficiario.dadosBancario.desconto > 0 ? dadosPDF.beneficiario.dadosBancario.desconto : 0;
2286
2296
  if (descontoVencimento > 0) {
2287
2297
  dadosPDF.boleto.instrucao2 = `AT\xC9 O VENCIMENTO, CONCEDER DESCONTO DE ${descontoVencimento}%`;
2288
2298
  }
@@ -2444,6 +2454,8 @@ function gerarRemessa5({ dados }) {
2444
2454
  const tipoInscricao = pagador.pessoa === "F" ? "1" : "2";
2445
2455
  const vencimento = format5(new Date(boleto.vencimento), "ddMMyyyy");
2446
2456
  total += Number(boleto.valor);
2457
+ const codigoDesconto = dadosBancario.descontoPagamento > 0 ? "2" : "0";
2458
+ const desconto = boleto.desconto > 0 ? boleto.desconto.toFixed(2) : dadosBancario.descontoPagamento > 0 ? dadosBancario.descontoPagamento.toFixed(2) : "000000000000000";
2447
2459
  let protesto = "3";
2448
2460
  let diasProtesto = "00";
2449
2461
  let baixarDevolver = "1";
@@ -2501,9 +2513,9 @@ function gerarRemessa5({ dados }) {
2501
2513
  arquivo.add("1");
2502
2514
  arquivo.add("00000000");
2503
2515
  arquivo.add(valorJurosDia.toFixed(2).replace(".", "").padStart(15, "0"));
2504
- arquivo.add("0");
2505
- arquivo.add("00000000");
2506
- arquivo.add("000000000000000");
2516
+ arquivo.add(codigoDesconto);
2517
+ arquivo.add(vencimento);
2518
+ arquivo.add(desconto.replace(".", "").padStart(15, "0"));
2507
2519
  arquivo.add("000000000000000");
2508
2520
  arquivo.add("000000000000000");
2509
2521
  arquivo.add(boleto.identificacaoTitulo.padEnd(25, " "));