@credithub/harlan-components 1.91.1 → 1.91.3

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.
@@ -11,6 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { classifyProtestos } from '../../../hooks/useProtestosClassification';
13
13
  import { converterParaFormatoValido, formatDatePtBrToDate } from '../../../utils/date';
14
+ import { parseProtesto } from '../../../utils/parseProtesto';
14
15
  import XPathUtils from '../../../utils/xpath';
15
16
  import { groupBy, sortBy, unique } from 'underscore';
16
17
  /**
@@ -108,14 +109,15 @@ export var processData = function (data, quantidadeProcessosJuridicos) {
108
109
  return __assign(__assign({}, data), { protestos: data.protestos, ccfs: data.ccfs, boaVista: data.boaVista, serasa: data.serasa, dividasPublicasGrafico: data.dividasPublicasGrafico, pieChartTotalConfig: __assign(__assign({}, data.pieChartTotalConfig), { processosJuridicos: quantidadeProcessosJuridicos }) });
109
110
  };
110
111
  export function processProtestData(document, iaOverrides) {
111
- var _a = classifyProtestos(document, iaOverrides), protestosDeCredito = _a.protestosDeCredito, protestosDeImposto = _a.protestosDeImposto, protestosGerais = _a.protestosGerais;
112
+ // Converte Node[] para Protesto[]
113
+ var protestos = XPathUtils.selectArray('//body//protesto', document).map(parseProtesto);
114
+ var _a = classifyProtestos(protestos, iaOverrides), protestosDeCredito = _a.protestosDeCredito, protestosDeImposto = _a.protestosDeImposto, protestosGerais = _a.protestosGerais;
112
115
  var obterUltimaData = function (protestos) {
113
116
  if (!protestos.length)
114
117
  return null;
115
118
  var datas = protestos
116
119
  .map(function (p) {
117
- var data = XPathUtils.select('string(./dataProtesto)', p);
118
- return new Date(converterParaFormatoValido(data)).getTime();
120
+ return new Date(converterParaFormatoValido(p.dataProtesto)).getTime();
119
121
  })
120
122
  .filter(function (d) { return !isNaN(d); });
121
123
  return datas.length
@@ -1,4 +1,7 @@
1
1
  import React from 'react';
2
+ /** ------------------------------------------------------------------
3
+ * Componente principal ---------------------------------------------
4
+ * ------------------------------------------------------------------*/
2
5
  declare const Falencia: React.FC<{
3
6
  documento: string;
4
7
  }>;
@@ -12,54 +12,72 @@ var __assign = (this && this.__assign) || function () {
12
12
  import React, { useEffect, useMemo, useState } from 'react';
13
13
  import FalenciaIcon from '../../assets/icones/falenciaIcon';
14
14
  import { useGlobalData } from '../../contexts/globalDataContext';
15
+ import AddItemField from '../common/addItem';
16
+ import { Result, ResultContent } from '../interface/result';
15
17
  import Section from '../section';
16
18
  import { RequestStatus, useQuery } from '../webservice';
17
- function parseFalencia(document) {
18
- var _a;
19
- if (!document)
20
- return [];
21
- if (Array.isArray(document)) {
22
- return document;
23
- }
24
- try {
25
- var raw = (_a = document.textContent) === null || _a === void 0 ? void 0 : _a.trim();
26
- if (raw) {
27
- var json = JSON.parse(raw);
28
- if (Array.isArray(json))
29
- return json;
30
- }
31
- }
32
- catch (_b) { }
33
- try {
34
- var items = document.querySelectorAll('item');
35
- if (items === null || items === void 0 ? void 0 : items.length) {
36
- return Array.from(items).map(function (item) {
37
- var _a, _b, _c, _d, _e, _f, _g;
38
- return ({
39
- title: (_c = (_b = (_a = item.querySelector('title')) === null || _a === void 0 ? void 0 : _a.textContent) === null || _b === void 0 ? void 0 : _b.trim()) !== null && _c !== void 0 ? _c : '',
40
- description: (_e = (_d = item.querySelector('description')) === null || _d === void 0 ? void 0 : _d.textContent) !== null && _e !== void 0 ? _e : '',
41
- link: (_g = (_f = item.querySelector('link')) === null || _f === void 0 ? void 0 : _f.textContent) !== null && _g !== void 0 ? _g : ''
42
- });
43
- });
44
- }
45
- }
46
- catch (_c) { }
47
- return [];
19
+ /** ------------------------------------------------------------------
20
+ * Helpers -----------------------------------------------------------
21
+ * ------------------------------------------------------------------*/
22
+ function normalizeMovimentacao(text) {
23
+ return text
24
+ .replace('Falências', 'Falência')
25
+ .replace('Requeridas', 'Requerida')
26
+ .replace('Decretadas', 'Decretada')
27
+ .replace('Extintos', 'Extinto')
28
+ .trim();
29
+ }
30
+ function cleanDate(dateStr) {
31
+ return dateStr.replace(/\s+\d{2}h\d{2}/, '').trim();
32
+ }
33
+ function buildSubtitle(records) {
34
+ // Busca o primeiro registro que realmente possua movimentação
35
+ var rec = records.find(function (r) { return Array.isArray(r.falimentar) && r.falimentar.length; });
36
+ if (!rec)
37
+ return 'Movimentos falimentares encontrados.';
38
+ var latest = rec.falimentar[0];
39
+ if (!latest)
40
+ return 'Movimentos falimentares encontrados.';
41
+ var movimentacao = normalizeMovimentacao(latest.movimentacao);
42
+ var date = cleanDate(latest.data);
43
+ return "".concat(movimentacao, " - ").concat(date);
48
44
  }
45
+ /** ------------------------------------------------------------------
46
+ * Componente principal ---------------------------------------------
47
+ * ------------------------------------------------------------------*/
49
48
  var Falencia = function (_a) {
50
49
  var documento = _a.documento;
51
50
  var setData = useGlobalData().setData;
52
51
  var _b = useState(false), dataUpdated = _b[0], setDataUpdated = _b[1];
53
52
  var _c = useQuery("SELECT FROM 'ValorEconomico'.'Falencia'", { documento: documento }), response = _c.response, error = _c.error, isLoading = _c.isLoading, loadingProgress = _c.loadingProgress, refetch = _c.refetch;
54
- var items = useMemo(function () { return parseFalencia(response === null || response === void 0 ? void 0 : response.document); }, [response]);
55
- var insolvencia = useMemo(function () { return items.length > 0; }, [items]);
53
+ // Transforma o retorno em array tipado ----------------------------------
54
+ var records = useMemo(function () {
55
+ if (!(response === null || response === void 0 ? void 0 : response.document))
56
+ return [];
57
+ try {
58
+ if (Array.isArray(response.document))
59
+ return response.document;
60
+ return JSON.parse(response.document);
61
+ }
62
+ catch (_a) {
63
+ return [];
64
+ }
65
+ }, [response]);
66
+ /**
67
+ * Há insolvência quando existe pelo menos UMA movimentação falimentar.
68
+ */
69
+ var insolvencia = useMemo(function () {
70
+ return records.some(function (r) { return Array.isArray(r.falimentar) && r.falimentar.length > 0; });
71
+ }, [records]);
72
+ /** Atualiza o contexto global apenas uma vez ---------------------------*/
56
73
  useEffect(function () {
57
74
  if (insolvencia && !dataUpdated) {
58
75
  setData(function (prev) { return (__assign(__assign({}, prev), { insolvencia: insolvencia })); });
59
76
  setDataUpdated(true);
60
77
  }
61
78
  }, [insolvencia, setData, dataUpdated]);
62
- if (!isLoading && items.length === 0)
79
+ /** Se não dados e não estamos carregando, não renderiza o componente */
80
+ if (!isLoading && !insolvencia)
63
81
  return null;
64
82
  var variant = isLoading
65
83
  ? 'loading'
@@ -79,6 +97,23 @@ var Falencia = function (_a) {
79
97
  Section: Section,
80
98
  progress: loadingProgress
81
99
  };
82
- return (React.createElement(Section, { title: "Fal\u00EAncias", subtitle: "Movimentos falimentares encontrados.", icon: FalenciaIcon, variant: variant, minimized: false, ctx: ctx }));
100
+ var subtitle = buildSubtitle(records);
101
+ /** ------------------------------------------------------------------
102
+ * RENDERIZA LISTA DE MOVIMENTAÇÕES ANTERIORES ------------------------
103
+ * ------------------------------------------------------------------*/
104
+ var renderMovimentacoes = function () {
105
+ var movimentos = records
106
+ .flatMap(function (r) { return r.falimentar; })
107
+ .map(function (m) { return ({
108
+ movimentacao: normalizeMovimentacao(m.movimentacao),
109
+ data: cleanDate(m.data)
110
+ }); });
111
+ if (!movimentos.length)
112
+ return null;
113
+ return (React.createElement(Result, { resultContentStriped: true, className: "falencia" }, movimentos.map(function (mov, idx) { return (React.createElement(ResultContent, { desktop: "repeat(2, 1fr)", tablet: "repeat(2, 1fr)", mobile: "repeat(2, 1fr)", key: idx },
114
+ React.createElement(AddItemField, { name: "Movimenta\u00E7\u00E3o", value: mov.movimentacao, style: { display: 'inline-block' } }),
115
+ React.createElement(AddItemField, { name: "Data", value: mov.data, style: { display: 'inline-block' } }))); })));
116
+ };
117
+ return (React.createElement(Section, { title: "Movimento Falimentar", subtitle: subtitle, icon: FalenciaIcon, variant: variant, minimized: false, ctx: ctx, onError: renderMovimentacoes, onSuccess: renderMovimentacoes }));
83
118
  };
84
119
  export default Falencia;
@@ -28,8 +28,8 @@ import ProtestosGeraisIcon from '../../assets/icones/protestosGerais';
28
28
  import ProtestosImpostosIcon from '../../assets/icones/protestosImpostos';
29
29
  import { useGlobalData } from '../../contexts/globalDataContext';
30
30
  import { classifyProtestos, useProtestosClassification } from '../../hooks/useProtestosClassification';
31
- import { formatDatePtBrToDate } from '../../utils/date';
32
31
  import { extractIntegerFromText } from '../../utils/number';
32
+ import { parseProtesto } from '../../utils/parseProtesto';
33
33
  import XPathUtils from '../../utils/xpath';
34
34
  import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
35
35
  import styled from 'styled-components';
@@ -41,17 +41,9 @@ import ProtestosCategory from './protestosCategory';
41
41
  import { ProtestoItem } from './protestosList';
42
42
  var ResultProtestos = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n flex-direction: column;\n row-gap: 20px;\n margin-top: 20px;\n"], ["\n display: flex;\n flex-direction: column;\n row-gap: 20px;\n margin-top: 20px;\n"])));
43
43
  var BtnWrapper = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n text-align: center;\n @media print {\n display: none;\n }\n"], ["\n text-align: center;\n @media print {\n display: none;\n }\n"])));
44
- // Função de ordenação por data
45
- var byDate = function (protesto, protesto2) {
46
- var _a, _b;
47
- var v0 = ((_a = formatDatePtBrToDate(XPathUtils.select('string(./dataProtesto)', protesto2))) === null || _a === void 0 ? void 0 : _a.getTime()) || 0;
48
- var v1 = ((_b = formatDatePtBrToDate(XPathUtils.select('string(./dataProtesto)', protesto))) === null || _b === void 0 ? void 0 : _b.getTime()) || 0;
49
- return v0 - v1;
50
- };
44
+ // Remover função de ordenação por data não usada
51
45
  // Função utilitária para extrair as chaves dos protestos
52
- var getChaves = function (arr) {
53
- return arr.map(function (protesto) { return XPathUtils.select('string(./nm_chave)', protesto); });
54
- };
46
+ var getChaves = function (arr) { return arr.map(function (p) { return p.nm_chave; }); };
55
47
  var Protestos = function () {
56
48
  var _a;
57
49
  var ctx = useContext(Queries.Protestos);
@@ -67,9 +59,16 @@ var Protestos = function () {
67
59
  }
68
60
  return 0;
69
61
  }, [ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.type, ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.document]);
70
- // NOVO: usa classificação centralizada
62
+ // converte XML Protesto[]
63
+ var protestosAll = useMemo(function () {
64
+ if (!ctx.document)
65
+ return [];
66
+ return XPathUtils.selectArray('//body//protesto', ctx.document).map(parseProtesto);
67
+ }, [ctx.document]);
71
68
  var iaOverrides = (_a = globalData.protestosData) === null || _a === void 0 ? void 0 : _a.iaOverrides;
72
- var _d = useProtestosClassification(ctx.document, iaOverrides), protestosDeCredito = _d.protestosDeCredito, protestosDeImposto = _d.protestosDeImposto, protestosGerais = _d.protestosGerais;
69
+ var _d = useProtestosClassification(protestosAll, iaOverrides), protestosDeCredito = _d.protestosDeCredito, protestosDeImposto = _d.protestosDeImposto, protestosGerais = _d.protestosGerais;
70
+ // Total de protestos
71
+ var registros = protestosAll.length;
73
72
  useEffect(function () {
74
73
  if ((ctx === null || ctx === void 0 ? void 0 : ctx.type) === RequestStatus.Error ||
75
74
  (ctx === null || ctx === void 0 ? void 0 : ctx.type) === RequestStatus.Empty) {
@@ -121,14 +120,11 @@ var Protestos = function () {
121
120
  }
122
121
  }, [ctx.type]);
123
122
  // Callback memorizado para a renderização do conteúdo em caso de sucesso
124
- var handleSuccess = useCallback(function (data, _ctx) {
123
+ var handleSuccess = useCallback(function (data) {
125
124
  var registrosText = XPathUtils.select('string(//registros)', data);
126
- var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
127
- var registros = haveException
128
- ? extractIntegerFromText(registrosText) + total
129
- : extractIntegerFromText(registrosText);
130
- // Usa função pura para classificar
131
- var _a = classifyProtestos(data, iaOverrides), protestosDeCredito = _a.protestosDeCredito, protestosDeImposto = _a.protestosDeImposto, protestosGerais = _a.protestosGerais;
125
+ var parsed = XPathUtils.selectArray('//body//protesto', data).map(parseProtesto);
126
+ // função pura – não adiciona hooks extras dentro de Section
127
+ var _a = classifyProtestos(parsed, iaOverrides), protestosDeCredito = _a.protestosDeCredito, protestosDeImposto = _a.protestosDeImposto, protestosGerais = _a.protestosGerais;
132
128
  var elements = [
133
129
  {
134
130
  total: protestosDeCredito.length,
@@ -157,7 +153,7 @@ var Protestos = function () {
157
153
  : "Encontrados ".concat(registros, " protestos")
158
154
  : 'Não há ocorrência de protesto'))
159
155
  };
160
- }, [total, iaOverrides]);
156
+ }, [iaOverrides]);
161
157
  return (React.createElement(Section, { ctx: ctx, title: "Apontamentos na Central de Protestos (CENPROT)", subtitle: "Consulta de protestos de cr\u00E9dito, imposto e gerais.", icon: ProtestosIcon, onSuccess: handleSuccess, actions: typeof harlan !== 'undefined' ? (React.createElement(BtnWrapper, null,
162
158
  React.createElement(Button, { onClick: function () {
163
159
  var _a;
@@ -1,11 +1,12 @@
1
+ import { Protesto } from '../../utils/parseProtesto';
1
2
  import React from 'react';
2
3
  export declare const ProtestoItem: React.MemoExoticComponent<({ protesto }: {
3
- protesto: Node;
4
+ protesto: Protesto;
4
5
  }) => React.JSX.Element>;
5
6
  export declare const Instrumento: ({ nm_chave, cpfCnpj }: {
6
7
  nm_chave?: string;
7
8
  cpfCnpj?: string;
8
9
  }) => React.JSX.Element | null;
9
10
  export declare const ProtestosList: React.FC<{
10
- protestos: Node[];
11
+ protestos: Protesto[];
11
12
  }>;
@@ -49,8 +49,7 @@ import { useGlobalData } from '../../contexts/globalDataContext';
49
49
  import { formatMoney } from '../../utils/number';
50
50
  import { openFormThenRedirect } from '../../utils/protestosp';
51
51
  import { formatDocument } from '../../utils/string';
52
- import XPathUtils from '../../utils/xpath';
53
- import React, { memo, useContext, useEffect, useMemo, useState } from 'react';
52
+ import React, { memo, useContext, useEffect, useState } from 'react';
54
53
  import AddItemField from '../common/addItem';
55
54
  import Button from '../common/button';
56
55
  import { ResultContent } from '../interface/result';
@@ -114,12 +113,8 @@ export var ProtestoItem = memo(function (_a) {
114
113
  var _e = useState(false), loading = _e[0], setLoading = _e[1];
115
114
  var _f = useState(false), queued = _f[0], setQueued = _f[1];
116
115
  var _g = useState(false), isAIData = _g[0], setIsAIData = _g[1];
117
- var getField = function (path, formatter) {
118
- var value = XPathUtils.select("string(".concat(path, ")"), protesto);
119
- return formatter ? formatter(value) : value;
120
- };
121
- var documento = useMemo(function () { return getField('//consulta/@documento'); }, [protesto]);
122
- var nm_chave = getField('./nm_chave');
116
+ var documento = protesto.cpfCnpj;
117
+ var nm_chave = protesto.nm_chave;
123
118
  var formatBooleanField = function (value) {
124
119
  return value === 'true' ? 'Sim' : 'Não';
125
120
  };
@@ -155,7 +150,10 @@ export var ProtestoItem = memo(function (_a) {
155
150
  setData(function (prev) {
156
151
  var _a;
157
152
  var _b;
158
- return (__assign(__assign({}, prev), { protestosData: __assign(__assign({}, prev.protestosData), { iaOverrides: __assign(__assign({}, (((_b = prev.protestosData) === null || _b === void 0 ? void 0 : _b.iaOverrides) || {})), (_a = {}, _a[nm_chave] = nomeDetectado_1, _a)) }) }));
153
+ // Garante que string é atribuída
154
+ if (!nomeDetectado_1)
155
+ return prev;
156
+ return __assign(__assign({}, prev), { protestosData: __assign(__assign({}, prev.protestosData), { iaOverrides: __assign(__assign({}, (((_b = prev.protestosData) === null || _b === void 0 ? void 0 : _b.iaOverrides) || {})), (_a = {}, _a[nm_chave] = nomeDetectado_1, _a)) }) });
159
157
  });
160
158
  }
161
159
  return [3 /*break*/, 6];
@@ -187,7 +185,7 @@ export var ProtestoItem = memo(function (_a) {
187
185
  }
188
186
  };
189
187
  useEffect(function () {
190
- var nomeCedente = getField('./nomeCedente');
188
+ var nomeCedente = protesto.nomeCedente;
191
189
  if (nomeCedente && nomeCedente.trim() !== '')
192
190
  return;
193
191
  if (nm_chave) {
@@ -202,7 +200,7 @@ export var ProtestoItem = memo(function (_a) {
202
200
  };
203
201
  }, []);
204
202
  var getQuemProtestouDisplay = function () {
205
- var original = getField('./nomeCedente');
203
+ var original = protesto.nomeCedente;
206
204
  var override = iaOverrides[nm_chave];
207
205
  if (override && override.trim() !== '') {
208
206
  return (React.createElement(React.Fragment, null,
@@ -221,12 +219,12 @@ export var ProtestoItem = memo(function (_a) {
221
219
  };
222
220
  return (React.createElement(ResultContent, { print: "repeat(7, 1fr)", desktop: "repeat(8, 1fr)", tablet: "repeat(4, 1fr)", mobile: "repeat(2, 1fr)" },
223
221
  React.createElement(AddItemField, { name: "Quem Protestou", value: getQuemProtestouDisplay() }),
224
- React.createElement(AddItemField, { name: "Atrav\u00E9s De", value: getField('./nomeApresentante') }),
225
- React.createElement(AddItemField, { name: "CPF/CNPJ Protestado", value: formatDocument(getField('./cpfCnpj')) }),
226
- React.createElement(AddItemField, { name: "Data Do Protesto", value: getField('./dataProtesto') }),
227
- React.createElement(AddItemField, { name: "Possui Anu\u00EAncia / Protesto Pago", value: formatBooleanField(getField('./temAnuencia')) }),
228
- React.createElement(AddItemField, { name: "Valor Do Protesto", value: formatMoney(getField('./valor')) }),
229
- getField('./vl_custas') && (React.createElement(AddItemField, { name: "Custas de Cart\u00F3rio para Baixa", value: formatMoney(getField('./vl_custas')) })),
222
+ React.createElement(AddItemField, { name: "Atrav\u00E9s De", value: protesto.nomeApresentante }),
223
+ React.createElement(AddItemField, { name: "CPF/CNPJ Protestado", value: formatDocument(protesto.cpfCnpj) }),
224
+ React.createElement(AddItemField, { name: "Data Do Protesto", value: protesto.dataProtesto }),
225
+ React.createElement(AddItemField, { name: "Possui Anu\u00EAncia / Protesto Pago", value: formatBooleanField(String(protesto.temAnuencia)) }),
226
+ React.createElement(AddItemField, { name: "Valor Do Protesto", value: formatMoney(protesto.valor) }),
227
+ protesto.vl_custas && (React.createElement(AddItemField, { name: "Custas de Cart\u00F3rio para Baixa", value: formatMoney(protesto.vl_custas) })),
230
228
  React.createElement(Instrumento, { nm_chave: nm_chave, cpfCnpj: documento })));
231
229
  });
232
230
  export var Instrumento = function (_a) {
@@ -276,5 +274,5 @@ export var Instrumento = function (_a) {
276
274
  };
277
275
  export var ProtestosList = function (_a) {
278
276
  var protestos = _a.protestos;
279
- return (React.createElement(ResultContent, null, (protestos === null || protestos === void 0 ? void 0 : protestos.length) ? (protestos.map(function (protesto, i) { return (React.createElement(ProtestoItem, { key: i, protesto: protesto })); })) : (React.createElement(AddItemField, { name: "Informa\u00E7\u00E3o", value: "N\u00E3o h\u00E1 registros de protestos." }))));
277
+ return (React.createElement(ResultContent, null, (protestos === null || protestos === void 0 ? void 0 : protestos.length) ? (protestos.map(function (protesto) { return (React.createElement(ProtestoItem, { key: protesto.nm_chave, protesto: protesto })); })) : (React.createElement(AddItemField, { name: "Informa\u00E7\u00E3o", value: "N\u00E3o h\u00E1 registros de protestos." }))));
280
278
  };
@@ -1,12 +1,13 @@
1
+ import { Protesto } from '../utils/parseProtesto';
1
2
  export interface ProtestosClassificados {
2
- protestosDeCredito: Node[];
3
- protestosDeImposto: Node[];
4
- protestosGerais: Node[];
3
+ protestosDeCredito: Protesto[];
4
+ protestosDeImposto: Protesto[];
5
+ protestosGerais: Protesto[];
5
6
  }
6
- export declare function classifyProtestos(document: Document | null | undefined, iaOverrides?: Record<string, string>): ProtestosClassificados;
7
+ export declare function classifyProtestos(protestos: Protesto[], iaOverrides?: Record<string, string>): ProtestosClassificados;
7
8
  /**
8
9
  * Hook para classificar protestos em Crédito, Imposto e Gerais, com suporte a overrides de IA.
9
10
  * @param document Documento XML dos protestos
10
11
  * @param iaOverrides Mapa opcional de chaves para nomes de cedente ajustados por IA
11
12
  */
12
- export declare function useProtestosClassification(document: Document | null | undefined, iaOverrides?: Record<string, string>): ProtestosClassificados;
13
+ export declare function useProtestosClassification(protestos: Protesto[], iaOverrides?: Record<string, string>): ProtestosClassificados;
@@ -1,46 +1,37 @@
1
1
  import { REGEX_PROTESTOS_DE_CREDITO, REGEX_PROTESTOS_DE_IMPOSTO } from '../constants/regex';
2
2
  import { formatDatePtBrToDate } from '../utils/date';
3
- import XPathUtils from '../utils/xpath';
4
3
  import { useMemo } from 'react';
5
4
  // Função de ordenação por data
6
- var byDate = function (protesto, protesto2) {
5
+ var byDate = function (a, b) {
7
6
  var _a, _b;
8
- var v0 = ((_a = formatDatePtBrToDate(XPathUtils.select('string(./dataProtesto)', protesto2))) === null || _a === void 0 ? void 0 : _a.getTime()) || 0;
9
- var v1 = ((_b = formatDatePtBrToDate(XPathUtils.select('string(./dataProtesto)', protesto))) === null || _b === void 0 ? void 0 : _b.getTime()) || 0;
7
+ var v0 = ((_a = formatDatePtBrToDate(b.dataProtesto)) === null || _a === void 0 ? void 0 : _a.getTime()) || 0;
8
+ var v1 = ((_b = formatDatePtBrToDate(a.dataProtesto)) === null || _b === void 0 ? void 0 : _b.getTime()) || 0;
10
9
  return v0 - v1;
11
10
  };
12
- export function classifyProtestos(document, iaOverrides) {
13
- if (!document) {
11
+ export function classifyProtestos(protestos, iaOverrides) {
12
+ if (!(protestos === null || protestos === void 0 ? void 0 : protestos.length)) {
14
13
  return {
15
14
  protestosDeCredito: [],
16
15
  protestosDeImposto: [],
17
16
  protestosGerais: []
18
17
  };
19
18
  }
20
- var filterProtestos = function (regex, data, iaOverrides) {
21
- return XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
22
- var cedente = XPathUtils.select('string(./nomeCedente)', protesto);
23
- var chave = XPathUtils.select('string(./nm_chave)', protesto);
24
- var iaNome = (iaOverrides === null || iaOverrides === void 0 ? void 0 : iaOverrides[chave]) || '';
25
- if (iaNome) {
26
- return regex.test(iaNome);
27
- }
28
- return regex.test(cedente);
19
+ var filter = function (regex) {
20
+ return protestos.filter(function (_a) {
21
+ var nomeCedente = _a.nomeCedente, nm_chave = _a.nm_chave;
22
+ var iaNome = (iaOverrides === null || iaOverrides === void 0 ? void 0 : iaOverrides[nm_chave]) || '';
23
+ return iaNome ? regex.test(iaNome) : regex.test(nomeCedente);
29
24
  });
30
25
  };
31
- var protestosDeCredito = filterProtestos(REGEX_PROTESTOS_DE_CREDITO, document, iaOverrides).sort(byDate);
32
- var protestosDeImposto = filterProtestos(REGEX_PROTESTOS_DE_IMPOSTO, document, iaOverrides).sort(byDate);
33
- var protestosGerais = XPathUtils.selectArray('//body//protesto', document)
34
- .filter(function (protesto) {
35
- var cedente = XPathUtils.select('string(./nomeCedente)', protesto);
36
- var chave = XPathUtils.select('string(./nm_chave)', protesto);
37
- var iaNome = (iaOverrides === null || iaOverrides === void 0 ? void 0 : iaOverrides[chave]) || '';
38
- if (iaNome) {
39
- return (!REGEX_PROTESTOS_DE_IMPOSTO.test(iaNome) &&
40
- !REGEX_PROTESTOS_DE_CREDITO.test(iaNome));
41
- }
42
- return (!REGEX_PROTESTOS_DE_IMPOSTO.test(cedente) &&
43
- !REGEX_PROTESTOS_DE_CREDITO.test(cedente));
26
+ var protestosDeCredito = filter(REGEX_PROTESTOS_DE_CREDITO).sort(byDate);
27
+ var protestosDeImposto = filter(REGEX_PROTESTOS_DE_IMPOSTO).sort(byDate);
28
+ var protestosGerais = protestos
29
+ .filter(function (_a) {
30
+ var nomeCedente = _a.nomeCedente, nm_chave = _a.nm_chave;
31
+ var iaNome = (iaOverrides === null || iaOverrides === void 0 ? void 0 : iaOverrides[nm_chave]) || '';
32
+ var target = iaNome || nomeCedente;
33
+ return (!REGEX_PROTESTOS_DE_IMPOSTO.test(target) &&
34
+ !REGEX_PROTESTOS_DE_CREDITO.test(target));
44
35
  })
45
36
  .sort(byDate);
46
37
  return {
@@ -54,6 +45,6 @@ export function classifyProtestos(document, iaOverrides) {
54
45
  * @param document Documento XML dos protestos
55
46
  * @param iaOverrides Mapa opcional de chaves para nomes de cedente ajustados por IA
56
47
  */
57
- export function useProtestosClassification(document, iaOverrides) {
58
- return useMemo(function () { return classifyProtestos(document, iaOverrides); }, [document, iaOverrides]);
48
+ export function useProtestosClassification(protestos, iaOverrides) {
49
+ return useMemo(function () { return classifyProtestos(protestos, iaOverrides); }, [protestos, iaOverrides]);
59
50
  }
@@ -0,0 +1,11 @@
1
+ export interface Protesto {
2
+ nm_chave: string;
3
+ cpfCnpj: string;
4
+ nomeCedente: string;
5
+ nomeApresentante: string;
6
+ dataProtesto: string;
7
+ valor: string;
8
+ vl_custas?: string;
9
+ temAnuencia: boolean;
10
+ }
11
+ export declare const parseProtesto: (node: Node) => Protesto;
@@ -0,0 +1,14 @@
1
+ import XPathUtils from '../utils/xpath';
2
+ export var parseProtesto = function (node) {
3
+ var $ = function (xp) { return XPathUtils.select("string(".concat(xp, ")"), node); };
4
+ return {
5
+ nm_chave: $('./nm_chave'),
6
+ cpfCnpj: $('./cpfCnpj'),
7
+ nomeCedente: $('./nomeCedente'),
8
+ nomeApresentante: $('./nomeApresentante'),
9
+ dataProtesto: $('./dataProtesto'),
10
+ valor: $('./valor'),
11
+ vl_custas: $('./vl_custas') || undefined,
12
+ temAnuencia: $('./temAnuencia') === 'true'
13
+ };
14
+ };