@credithub/harlan-components 1.53.5 → 1.55.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.
@@ -2,8 +2,9 @@ import React from 'react';
2
2
  export declare const ProtestoItem: React.MemoExoticComponent<({ protesto }: {
3
3
  protesto: Node;
4
4
  }) => React.JSX.Element>;
5
- export declare const Instrumento: ({ nm_chave }: {
5
+ export declare const Instrumento: ({ nm_chave, cpfCnpj }: {
6
6
  nm_chave?: string;
7
+ cpfCnpj?: string;
7
8
  }) => React.JSX.Element | null;
8
9
  export declare const ProtestosList: React.FC<{
9
10
  protestos: Node[];
@@ -42,6 +42,7 @@ import AddItemField from '../common/addItem';
42
42
  import Button from '../common/button';
43
43
  import { ResultContent } from '../interface/result';
44
44
  import { WebService } from '../webservice';
45
+ import { openFormThenRedirect } from '../../utils/protestosp';
45
46
  export var ProtestoItem = memo(function (_a) {
46
47
  var protesto = _a.protesto;
47
48
  var getField = function (path, formatter) {
@@ -59,10 +60,10 @@ export var ProtestoItem = memo(function (_a) {
59
60
  React.createElement(AddItemField, { name: "Possui Anu\u00EAncia / Protesto Pago", value: formatBooleanField(getField('./temAnuencia')) }),
60
61
  React.createElement(AddItemField, { name: "Valor Do Protesto", value: formatMoney(getField('./valor')) }),
61
62
  getField('./vl_custas') && (React.createElement(AddItemField, { name: "Custas de Cart\u00F3rio para Baixa", value: formatMoney(getField('./vl_custas')) })),
62
- React.createElement(Instrumento, { nm_chave: getField('./nm_chave') })));
63
+ React.createElement(Instrumento, { nm_chave: getField('./nm_chave'), cpfCnpj: getField('//consulta/@documento') })));
63
64
  });
64
65
  export var Instrumento = function (_a) {
65
- var nm_chave = _a.nm_chave;
66
+ var nm_chave = _a.nm_chave, cpfCnpj = _a.cpfCnpj;
66
67
  var client = useContext(WebService);
67
68
  var _b = React.useState(), error = _b[0], setError = _b[1];
68
69
  var _c = React.useState(false), isLoading = _c[0], setIsLoading = _c[1];
@@ -88,6 +89,11 @@ export var Instrumento = function (_a) {
88
89
  return [3 /*break*/, 6];
89
90
  case 4:
90
91
  e_1 = _a.sent();
92
+ if (/^35/.test(nm_chave)) {
93
+ /* Instrumento de SP */
94
+ openFormThenRedirect(nm_chave, cpfCnpj);
95
+ return [2 /*return*/];
96
+ }
91
97
  console.error(e_1);
92
98
  setError(true);
93
99
  return [3 /*break*/, 6];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Opens a new window with a form that auto-submits via POST to the target URL.
3
+ * The new window then closes (after 2 seconds), and once closed,
4
+ * the "imprimir" page is opened in a new window.
5
+ *
6
+ * @param {string} chaveUnica - The ChaveUnica value.
7
+ * @param {string} devedorPrincipal - A CPF (11 digits) or CNPJ (14 digits).
8
+ */
9
+ export declare function openFormThenRedirect(chaveUnica: string, devedorPrincipal: string): void;
@@ -0,0 +1,67 @@
1
+ // Helper to strip non-digit characters.
2
+ function getDigits(str) {
3
+ return str.replace(/\D/g, '');
4
+ }
5
+ // Format CPF (11 digits) as XXX.XXX.XXX-XX.
6
+ function formatCPF(cpf) {
7
+ var digits = getDigits(cpf);
8
+ if (digits.length !== 11)
9
+ return cpf;
10
+ return digits.replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, '$1.$2.$3-$4');
11
+ }
12
+ // Format CNPJ (14 digits) as XX.XXX.XXX/XXXX-XX.
13
+ function formatCNPJ(cnpj) {
14
+ var digits = getDigits(cnpj);
15
+ if (digits.length !== 14)
16
+ return cnpj;
17
+ return digits.replace(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '$1.$2.$3/$4-$5');
18
+ }
19
+ // Format ChaveUnica if it has 23 digits into a dash-separated pattern.
20
+ function formatChaveUnica(chave) {
21
+ var digits = getDigits(chave);
22
+ if (digits.length !== 23)
23
+ return chave;
24
+ return digits.replace(/(\d{3})(\d{4})(\d{4})(\d{4})(\d{4})(\d{4})/, '$1-$2-$3-$4-$5-$6');
25
+ }
26
+ /**
27
+ * Opens a new window with a form that auto-submits via POST to the target URL.
28
+ * The new window then closes (after 2 seconds), and once closed,
29
+ * the "imprimir" page is opened in a new window.
30
+ *
31
+ * @param {string} chaveUnica - The ChaveUnica value.
32
+ * @param {string} devedorPrincipal - A CPF (11 digits) or CNPJ (14 digits).
33
+ */
34
+ export function openFormThenRedirect(chaveUnica, devedorPrincipal) {
35
+ // Format the ChaveUnica.
36
+ var formattedChaveUnica = formatChaveUnica(chaveUnica);
37
+ // Determine whether devedorPrincipal is CPF or CNPJ.
38
+ var devedorDigits = getDigits(devedorPrincipal);
39
+ var formattedDevedorPrincipal, devedorPrincipalTipo;
40
+ if (devedorDigits.length === 11) {
41
+ formattedDevedorPrincipal = formatCPF(devedorPrincipal);
42
+ devedorPrincipalTipo = '1';
43
+ }
44
+ else if (devedorDigits.length === 14) {
45
+ formattedDevedorPrincipal = formatCNPJ(devedorPrincipal);
46
+ devedorPrincipalTipo = '2';
47
+ }
48
+ else {
49
+ // If not recognized, use the provided value and default type.
50
+ formattedDevedorPrincipal = devedorPrincipal;
51
+ devedorPrincipalTipo = '1';
52
+ }
53
+ // Open a new window.
54
+ var newWindow = window.open('', '_blank');
55
+ if (!newWindow) {
56
+ alert('Please allow popups for this site.');
57
+ return;
58
+ }
59
+ // Build the HTML document for the new window with the form.
60
+ var html = "\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title>Instrumento de S\u00E3o Paulo</title>\n </head>\n <body>\n <form id=\"submissionForm\" method=\"POST\" action=\"https://protestosp.com.br/Validacoes/Consultar\">\n <input type=\"hidden\" name=\"vTipoDocumento\" value=\"1\">\n <input type=\"hidden\" name=\"ChaveUnica\" value=\"".concat(formattedChaveUnica, "\">\n <input type=\"hidden\" name=\"DevedorPrincipalTipo\" value=\"").concat(devedorPrincipalTipo, "\">\n <input type=\"hidden\" name=\"DevedorPrincipal\" value=\"").concat(formattedDevedorPrincipal, "\">\n <input type=\"hidden\" name=\"ChaveValidacao\" value=\"P35-5030-8000-\">\n <input type=\"hidden\" name=\"PesquisadoDocumentoTipo\" value=\"0\">\n <input type=\"hidden\" name=\"PesquisadoDocumento\" value=\"\">\n <input type=\"hidden\" name=\"X-Requested-With\" value=\"XMLHttpRequest\">\n </form>\n <script>\n // Auto-submit the form.\n document.getElementById('submissionForm').submit();\n // After 2 seconds, close this window.\n </script>\n </body>\n </html>\n ");
61
+ newWindow.document.open();
62
+ newWindow.document.write(html);
63
+ setTimeout(function () {
64
+ newWindow.location.href = "https://protestosp.com.br/Validacoes/ImprimirDocumento";
65
+ }, 3000);
66
+ }
67
+ // openFormThenRedirect("35503080001809805230314", "37554311816");