@credithub/harlan-components 1.72.0 → 1.73.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.
- package/dist/components/chart/chartSystem.js +74 -34
- package/dist/components/chart/hooks/useChartData.d.ts +2 -8
- package/dist/components/chart/hooks/useChartData.js +51 -107
- package/dist/components/chart/hooks/useDividasPublicas.d.ts +6 -0
- package/dist/components/chart/hooks/useDividasPublicas.js +45 -0
- package/dist/components/chart/utils/dataProcessing.js +1 -1
- package/dist/components/protestos/protestos.js +1 -1
- package/dist/hooks/useProtestosClassification.d.ts +12 -0
- package/dist/hooks/useProtestosClassification.js +59 -0
- package/lib/cjs/index.js +1761 -2935
- package/lib/esm/index.js +1761 -2935
- package/package.json +1 -1
|
@@ -51,25 +51,34 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
51
51
|
};
|
|
52
52
|
import ResumoDeNegativacoesIcon from '../../assets/icones/resumoNegativacoes';
|
|
53
53
|
import { useGlobalData } from '../../contexts/globalDataContext';
|
|
54
|
+
import { useConsultasComplementares } from '../../hooks/useConsultasComplementares';
|
|
54
55
|
import { converterParaFormatoValido } from '../../utils/date';
|
|
56
|
+
import { formatMoney } from '../../utils/number';
|
|
57
|
+
import { isCpf } from '../../utils/string';
|
|
58
|
+
import { Spinner } from 'phosphor-react';
|
|
55
59
|
import React, { useContext, useEffect, useState } from 'react';
|
|
56
60
|
import styled from 'styled-components';
|
|
57
61
|
import useToggle from '../../hooks/useToggle';
|
|
58
62
|
import { ConsultasComplementaresContext } from '../consultasComplementares';
|
|
63
|
+
import { ButtonsSummary, SummaryButton } from '../dossie/summary/styles';
|
|
64
|
+
import { getProductsPrices } from '../dossie/summary/utils';
|
|
59
65
|
import StatusMessage from '../interface/statusMessage';
|
|
60
66
|
import Section from '../section';
|
|
61
67
|
import { RequestStatus } from '../webservice';
|
|
62
68
|
import ChartContent from './chartContent';
|
|
63
|
-
import useChartData
|
|
69
|
+
import useChartData from './hooks/useChartData';
|
|
70
|
+
import { useDividasPublicas } from './hooks/useDividasPublicas';
|
|
64
71
|
import QuantidadeResultados from './quantityResult';
|
|
65
72
|
import { useCalculation, useUltimaOcorrenciaCCF } from './utils/chartUtils';
|
|
66
|
-
import { useConsultasComplementares } from '../../hooks/useConsultasComplementares';
|
|
67
|
-
import { getProductsPrices } from '../dossie/summary/utils';
|
|
68
|
-
import { isCpf } from '../../utils/string';
|
|
69
|
-
import { ButtonsSummary, SummaryButton } from '../dossie/summary/styles';
|
|
70
|
-
import { Spinner } from 'phosphor-react';
|
|
71
|
-
import { formatMoney } from '../../utils/number';
|
|
72
73
|
var Content = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: ", ";\n padding: 0px 30px;\n\n @media print {\n display: block;\n }\n"], ["\n display: ", ";\n padding: 0px 30px;\n\n @media print {\n display: block;\n }\n"])), function (props) { return (props.isOpen ? 'block' : 'none'); });
|
|
74
|
+
function calcularProtestoLiminar(history) {
|
|
75
|
+
var _a;
|
|
76
|
+
if (!history.length)
|
|
77
|
+
return false;
|
|
78
|
+
var teveAnterior = history.slice(0, -1).some(function (h) { return h.quantidade > 0; });
|
|
79
|
+
var ultimoZerado = ((_a = history.at(-1)) === null || _a === void 0 ? void 0 : _a.quantidade) === 0;
|
|
80
|
+
return teveAnterior && ultimoZerado;
|
|
81
|
+
}
|
|
73
82
|
var ChartSystem = function (_a) {
|
|
74
83
|
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
75
84
|
var documento = _a.documento;
|
|
@@ -124,7 +133,7 @@ var ChartSystem = function (_a) {
|
|
|
124
133
|
});
|
|
125
134
|
}); };
|
|
126
135
|
};
|
|
127
|
-
var _o = useChartData(
|
|
136
|
+
var _o = useChartData(consultaSerasa, consultaBoaVista), chartData = _o.data, isLoadingChart = _o.isLoading, errorChart = _o.error, refetchChart = _o.refetch, chartDataProgress = _o.loadingProgress;
|
|
128
137
|
var _p = useDividasPublicas(), quantidadeDividas = _p.quantidade, valorTotalDividas = _p.valorTotal, ultimaOcorrenciaDividas = _p.ultimaOcorrencia, dividasProgress = _p.loadingProgress;
|
|
129
138
|
useEffect(function () {
|
|
130
139
|
if (consultaSerasa || consultaBoaVista) {
|
|
@@ -159,30 +168,45 @@ var ChartSystem = function (_a) {
|
|
|
159
168
|
}
|
|
160
169
|
var loadingProgress = (chartDataProgress + dividasProgress) / 2;
|
|
161
170
|
useEffect(function () {
|
|
171
|
+
var _a, _b;
|
|
162
172
|
if (!dataUpdated && chartData) {
|
|
163
|
-
|
|
164
|
-
var _a;
|
|
165
|
-
return (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
173
|
+
var protestoHistory_1 = (_b = (_a = chartData.protestos) === null || _a === void 0 ? void 0 : _a.map(function (p) {
|
|
174
|
+
var _a, _b;
|
|
175
|
+
return ({
|
|
176
|
+
documento: documento,
|
|
177
|
+
data: typeof p.data === 'string' ? p.data : p.data.toISOString(),
|
|
178
|
+
quantidade: (_a = p.quantidade) !== null && _a !== void 0 ? _a : 0,
|
|
179
|
+
valorTotal: (_b = p.valorTotal) !== null && _b !== void 0 ? _b : 0
|
|
180
|
+
});
|
|
181
|
+
}).sort(function (a, b) { return new Date(a.data).getTime() - new Date(b.data).getTime(); })) !== null && _b !== void 0 ? _b : [];
|
|
182
|
+
var protestoLiminar_1 = calcularProtestoLiminar(protestoHistory_1);
|
|
183
|
+
setGlobalState(function (prev) {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
var docHistory = {
|
|
186
|
+
protestoHistory: protestoHistory_1,
|
|
187
|
+
protestoLiminar: protestoLiminar_1,
|
|
188
|
+
quantidadeProtestos: quantidadeProtestos,
|
|
189
|
+
quantidadeProcessos: (_b = (_a = chartData.pieChartTotalConfig) === null || _a === void 0 ? void 0 : _a.processosJuridicos) !== null && _b !== void 0 ? _b : 0,
|
|
190
|
+
quantidadeDividas: quantidadeDividas,
|
|
191
|
+
quantidadeDividasSerasa: quantidadeSerasa,
|
|
192
|
+
quantidadeDividasBoaVista: quantidadeBoaVista,
|
|
193
|
+
quantidadeChequesSemFundos: quantidadeCCFs,
|
|
194
|
+
ultimaOcorrenciaChequesSemFundos: ultimaOcorrenciaCCF,
|
|
195
|
+
valorTotalDividasSerasa: valorTotalSerasa,
|
|
196
|
+
valorTotalDividasBoaVista: valorTotalBoaVista,
|
|
197
|
+
valorTotalProtestos: valorTotalProtestos,
|
|
198
|
+
valorTotalDividas: valorTotalDividas,
|
|
199
|
+
ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos,
|
|
200
|
+
ultimaOcorrenciaDividas: ultimaOcorrenciaDividas,
|
|
201
|
+
ultimaOcorrenciaPefinBoaVista: quantidadeBoaVista > 0 && ultimaOcorrenciaBoaVista
|
|
202
|
+
? ultimaOcorrenciaBoaVista
|
|
203
|
+
: undefined,
|
|
204
|
+
ultimaOcorrenciaPefinSerasa: quantidadeSerasa > 0 && ultimaOcorrenciaSerasa
|
|
205
|
+
? ultimaOcorrenciaSerasa
|
|
206
|
+
: undefined
|
|
207
|
+
};
|
|
208
|
+
console.log('documentHistory', docHistory);
|
|
209
|
+
return __assign(__assign({}, prev), { documentHistory: docHistory });
|
|
186
210
|
});
|
|
187
211
|
setDataUpdated(true);
|
|
188
212
|
}
|
|
@@ -210,9 +234,25 @@ var ChartSystem = function (_a) {
|
|
|
210
234
|
var _a, _b, _c;
|
|
211
235
|
return (React.createElement(Content, { isOpen: isOpen },
|
|
212
236
|
chartData && React.createElement(ChartContent, { dataInput: chartData }),
|
|
213
|
-
React.createElement(QuantidadeResultados, { data: chartData, consultarSerasa: React.createElement(ButtonsSummary, { style: {
|
|
214
|
-
|
|
215
|
-
|
|
237
|
+
React.createElement(QuantidadeResultados, { data: chartData, consultarSerasa: React.createElement(ButtonsSummary, { style: {
|
|
238
|
+
display: loadingButtons['refinSerasa'] ||
|
|
239
|
+
((_a = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.refinSerasa) === null || _a === void 0 ? void 0 : _a.consultaRealizada)
|
|
240
|
+
? 'none'
|
|
241
|
+
: '',
|
|
242
|
+
marginTop: 'auto'
|
|
243
|
+
} },
|
|
244
|
+
React.createElement(SummaryButton, { onClick: handleOnClick('refinSerasa'), disabled: loadingButtons['refinSerasa'], smallContent: productsPrices['refinSerasa']
|
|
245
|
+
? formatMoney(productsPrices['refinSerasa'])
|
|
246
|
+
: undefined }, loadingButtons['refinSerasa'] ? (React.createElement(Spinner, null)) : ('Consultar Pefin/Refin Serasa'))), consultarBoaVista: React.createElement(ButtonsSummary, { style: {
|
|
247
|
+
display: loadingButtons['refinBoaVista'] ||
|
|
248
|
+
((_b = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.refinBoaVista) === null || _b === void 0 ? void 0 : _b.consultaRealizada)
|
|
249
|
+
? 'none'
|
|
250
|
+
: '',
|
|
251
|
+
marginTop: 'auto'
|
|
252
|
+
} },
|
|
253
|
+
React.createElement(SummaryButton, { onClick: handleOnClick('refinBoaVista'), disabled: loadingButtons['refinBoaVista'], smallContent: productsPrices['refinBoaVista']
|
|
254
|
+
? formatMoney(productsPrices['refinBoaVista'])
|
|
255
|
+
: undefined }, loadingButtons['refinBoaVista'] ? (React.createElement(Spinner, null)) : ('Consultar Pefin/Refin Boa Vista'))), quantidadeProtestos: quantidadeProtestos, quantidadeProcessos: (_c = chartData === null || chartData === void 0 ? void 0 : chartData.pieChartTotalConfig) === null || _c === void 0 ? void 0 : _c.processosJuridicos, quantidadeDividas: quantidadeDividas, quantidadeDividasSerasa: quantidadeSerasa, quantidadeDividasBoaVista: quantidadeBoaVista, quantidadeChequesSemFundos: quantidadeCCFs, ultimaOcorrenciaChequesSemFundos: ultimaOcorrenciaCCF, valorTotalDividasSerasa: valorTotalSerasa, valorTotalDividasBoaVista: valorTotalBoaVista, valorTotalProtestos: valorTotalProtestos, valorTotalDividas: valorTotalDividas, ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos, ultimaOcorrenciaDividas: ultimaOcorrenciaDividas, ultimaOcorrenciaPefinBoaVista: Array.isArray(chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) &&
|
|
216
256
|
chartData.boaVista.length > 0
|
|
217
257
|
? (ultimaOcorrenciaBoaVista !== null && ultimaOcorrenciaBoaVista !== void 0 ? ultimaOcorrenciaBoaVista : undefined)
|
|
218
258
|
: undefined, ultimaOcorrenciaPefinSerasa: Array.isArray(chartData === null || chartData === void 0 ? void 0 : chartData.serasa) && chartData.serasa.length > 0
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { DataInput } from '../../../components/chart/types/iChart';
|
|
2
|
-
|
|
3
|
-
loadingProgress: number;
|
|
4
|
-
quantidade: number;
|
|
5
|
-
valorTotal: number;
|
|
6
|
-
ultimaOcorrencia: string;
|
|
7
|
-
};
|
|
8
|
-
declare const useChartData: (documento: string, consultaSerasa: any, consultaBoaVista: any) => {
|
|
2
|
+
declare const useChartData: (consultaSerasa: any, consultaBoaVista: any) => {
|
|
9
3
|
data: DataInput | null;
|
|
10
4
|
isLoading: boolean;
|
|
11
|
-
error: string |
|
|
5
|
+
error: string | null;
|
|
12
6
|
refetch: () => void;
|
|
13
7
|
loadingProgress: number;
|
|
14
8
|
};
|
|
@@ -1,142 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
import { Queries, RequestStatus, useQuery } from '../../../components/webservice';
|
|
1
|
+
import { Queries, RequestStatus } from '../../../components/webservice';
|
|
13
2
|
import { useGlobalData } from '../../../contexts/globalDataContext';
|
|
14
|
-
import XPathUtils from '../../../utils/xpath';
|
|
15
3
|
import { useContext, useEffect, useMemo, useState } from 'react';
|
|
16
4
|
import { processData, processProtestData } from '../utils/dataProcessing';
|
|
17
|
-
|
|
18
|
-
var ctxFinder = useContext(Queries.Finder);
|
|
19
|
-
var _a = useState(0), loadingProgress = _a[0], setLoadingProgress = _a[1];
|
|
20
|
-
useEffect(function () {
|
|
21
|
-
if ((ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Loading) {
|
|
22
|
-
setLoadingProgress(function (prev) { return Math.min(prev + 15, 90); });
|
|
23
|
-
}
|
|
24
|
-
else if ((ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Success ||
|
|
25
|
-
(ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Error) {
|
|
26
|
-
setLoadingProgress(100);
|
|
27
|
-
}
|
|
28
|
-
}, [ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type]);
|
|
29
|
-
var dividasPublicasData = useMemo(function () {
|
|
30
|
-
if ((ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Success) {
|
|
31
|
-
var quantidade = XPathUtils.select('number(//dividas/resumo/quantidade_dividas)', ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.document) || 0;
|
|
32
|
-
var valorTotal = XPathUtils.select('number(//dividas/resumo/valor_total_dividas)', ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.document) || 0;
|
|
33
|
-
var datasInscricao = XPathUtils.select('//dividas//divida/data_inscricao', ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.document) || [];
|
|
34
|
-
var datasValidas = datasInscricao
|
|
35
|
-
.map(function (element) { var _a; return ((_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || ''; })
|
|
36
|
-
.filter(Boolean)
|
|
37
|
-
.map(function (data) { return new Date(data).getTime(); })
|
|
38
|
-
.filter(function (timestamp) { return !isNaN(timestamp); });
|
|
39
|
-
var ultimaOcorrencia = datasValidas.length > 0
|
|
40
|
-
? new Date(Math.max.apply(Math, datasValidas)).toLocaleDateString('pt-BR')
|
|
41
|
-
: '';
|
|
42
|
-
return {
|
|
43
|
-
quantidade: quantidade,
|
|
44
|
-
valorTotal: valorTotal,
|
|
45
|
-
ultimaOcorrencia: ultimaOcorrencia
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
quantidade: 0,
|
|
50
|
-
valorTotal: 0,
|
|
51
|
-
ultimaOcorrencia: ''
|
|
52
|
-
};
|
|
53
|
-
}, [ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type]);
|
|
54
|
-
return __assign(__assign({}, dividasPublicasData), { loadingProgress: loadingProgress });
|
|
55
|
-
};
|
|
56
|
-
var useChartData = function (documento, consultaSerasa, consultaBoaVista) {
|
|
5
|
+
var useChartData = function (consultaSerasa, consultaBoaVista) {
|
|
57
6
|
var _a;
|
|
58
7
|
var _b = useState(null), data = _b[0], setData = _b[1];
|
|
59
8
|
var _c = useState(null), errorState = _c[0], setErrorState = _c[1];
|
|
60
9
|
var _d = useState(0), loadingProgress = _d[0], setLoadingProgress = _d[1];
|
|
61
|
-
var
|
|
62
|
-
var _f = useQuery("SELECT FROM 'DOCUMENTHISTORY'.'BASICHISTORY'", {
|
|
63
|
-
documento: documento
|
|
64
|
-
}), response = _f.response, queryError = _f.error, isLoading = _f.isLoading, refetch = _f.refetch;
|
|
10
|
+
var ctxHistory = useContext(Queries.GraficosAnaliticos);
|
|
65
11
|
var ctxProtestos = useContext(Queries.Protestos);
|
|
66
12
|
var ctxCCF = useContext(Queries.CCF);
|
|
67
|
-
var
|
|
13
|
+
var ctxProcessos = useContext(Queries.ProcessosJuridicos);
|
|
68
14
|
var globalData = useGlobalData().data;
|
|
69
15
|
var iaOverrides = (_a = globalData === null || globalData === void 0 ? void 0 : globalData.protestosData) === null || _a === void 0 ? void 0 : _a.iaOverrides;
|
|
70
|
-
var
|
|
71
|
-
var _a;
|
|
72
|
-
if (
|
|
73
|
-
((_a =
|
|
74
|
-
return ctxProcessosJuridicos.document.empresa.length;
|
|
16
|
+
var quantidadeProcessos = useMemo(function () {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
if (ctxProcessos.type === RequestStatus.Success) {
|
|
19
|
+
return (_c = (_b = (_a = ctxProcessos.document) === null || _a === void 0 ? void 0 : _a.empresa) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
75
20
|
}
|
|
76
21
|
return 0;
|
|
77
|
-
}, [
|
|
78
|
-
var liveQueriesIsFinish = useMemo(function () {
|
|
79
|
-
return [
|
|
80
|
-
ctxProtestos === null || ctxProtestos === void 0 ? void 0 : ctxProtestos.type,
|
|
81
|
-
ctxCCF === null || ctxCCF === void 0 ? void 0 : ctxCCF.type,
|
|
82
|
-
ctxProcessosJuridicos === null || ctxProcessosJuridicos === void 0 ? void 0 : ctxProcessosJuridicos.type
|
|
83
|
-
].every(function (status) {
|
|
84
|
-
return status !== RequestStatus.Loading && status !== RequestStatus.Empty;
|
|
85
|
-
});
|
|
86
|
-
}, [ctxProtestos === null || ctxProtestos === void 0 ? void 0 : ctxProtestos.type, ctxCCF === null || ctxCCF === void 0 ? void 0 : ctxCCF.type, ctxProcessosJuridicos === null || ctxProcessosJuridicos === void 0 ? void 0 : ctxProcessosJuridicos.type]);
|
|
22
|
+
}, [ctxProcessos.type, ctxProcessos.document]);
|
|
87
23
|
var dadosProtestos = useMemo(function () {
|
|
88
|
-
if (
|
|
24
|
+
if (ctxProtestos.type === RequestStatus.Success && ctxProtestos.document) {
|
|
89
25
|
return processProtestData(ctxProtestos.document, iaOverrides);
|
|
90
26
|
}
|
|
91
27
|
return [];
|
|
92
|
-
}, [ctxProtestos, iaOverrides]);
|
|
28
|
+
}, [ctxProtestos.type, ctxProtestos.document, iaOverrides]);
|
|
29
|
+
// aggregate progress from all contexts
|
|
93
30
|
useEffect(function () {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
31
|
+
var _a, _b, _c, _d;
|
|
32
|
+
var parts = [
|
|
33
|
+
(_a = ctxHistory.progress) !== null && _a !== void 0 ? _a : 0,
|
|
34
|
+
(_b = ctxProtestos.progress) !== null && _b !== void 0 ? _b : 0,
|
|
35
|
+
(_c = ctxCCF.progress) !== null && _c !== void 0 ? _c : 0,
|
|
36
|
+
(_d = ctxProcessos.progress) !== null && _d !== void 0 ? _d : 0
|
|
37
|
+
];
|
|
38
|
+
var avg = parts.reduce(function (sum, p) { return sum + p; }, 0) / parts.length;
|
|
39
|
+
setLoadingProgress(avg);
|
|
40
|
+
}, [
|
|
41
|
+
ctxHistory.progress,
|
|
42
|
+
ctxProtestos.progress,
|
|
43
|
+
ctxCCF.progress,
|
|
44
|
+
ctxProcessos.progress
|
|
45
|
+
]);
|
|
46
|
+
// trigger refetch when complementary queries change
|
|
98
47
|
useEffect(function () {
|
|
99
|
-
if (
|
|
100
|
-
refetch();
|
|
48
|
+
if (consultaSerasa || consultaBoaVista) {
|
|
49
|
+
ctxHistory.refetch();
|
|
101
50
|
}
|
|
102
|
-
}, [
|
|
51
|
+
}, [consultaSerasa, consultaBoaVista, ctxHistory.refetch]);
|
|
52
|
+
// handle history response
|
|
103
53
|
useEffect(function () {
|
|
104
|
-
|
|
105
|
-
|
|
54
|
+
var _a;
|
|
55
|
+
if (ctxHistory.type === RequestStatus.Loading) {
|
|
56
|
+
setErrorState(null);
|
|
106
57
|
}
|
|
107
|
-
else if (
|
|
108
|
-
|
|
58
|
+
else if (ctxHistory.type === RequestStatus.Error) {
|
|
59
|
+
setErrorState(((_a = ctxHistory.error) === null || _a === void 0 ? void 0 : _a.message) || 'Erro ao consultar histórico');
|
|
109
60
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!isLoading &&
|
|
113
|
-
!queryError &&
|
|
114
|
-
(response === null || response === void 0 ? void 0 : response.document) &&
|
|
115
|
-
liveQueriesIsFinish) {
|
|
61
|
+
else if (ctxHistory.type === RequestStatus.Success &&
|
|
62
|
+
ctxHistory.document) {
|
|
116
63
|
try {
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
var
|
|
120
|
-
setData(
|
|
64
|
+
var parsed = JSON.parse(ctxHistory.document);
|
|
65
|
+
parsed.protestosCategory = dadosProtestos;
|
|
66
|
+
var processed = processData(parsed, quantidadeProcessos);
|
|
67
|
+
setData(processed);
|
|
121
68
|
}
|
|
122
|
-
catch (
|
|
123
|
-
console.error('%c Erro ao processar os dados', 'color: red', e);
|
|
69
|
+
catch (_b) {
|
|
124
70
|
setErrorState('Erro ao processar os dados');
|
|
125
71
|
}
|
|
126
72
|
}
|
|
127
73
|
}, [
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
quantidadeProcessosJuridicos,
|
|
133
|
-
dadosProtestos
|
|
74
|
+
ctxHistory.type,
|
|
75
|
+
ctxHistory.document,
|
|
76
|
+
dadosProtestos,
|
|
77
|
+
quantidadeProcessos
|
|
134
78
|
]);
|
|
135
79
|
return {
|
|
136
80
|
data: data,
|
|
137
|
-
isLoading:
|
|
138
|
-
error: errorState
|
|
139
|
-
refetch: refetch,
|
|
81
|
+
isLoading: ctxHistory.type === RequestStatus.Loading,
|
|
82
|
+
error: errorState,
|
|
83
|
+
refetch: ctxHistory.refetch,
|
|
140
84
|
loadingProgress: loadingProgress
|
|
141
85
|
};
|
|
142
86
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { Queries, RequestStatus } from '../../../components/webservice';
|
|
13
|
+
import XPathUtils from '../../../utils/xpath';
|
|
14
|
+
import { useContext, useEffect, useMemo, useState } from 'react';
|
|
15
|
+
export var useDividasPublicas = function () {
|
|
16
|
+
var ctxFinder = useContext(Queries.Finder);
|
|
17
|
+
var _a = useState(0), loadingProgress = _a[0], setLoadingProgress = _a[1];
|
|
18
|
+
useEffect(function () {
|
|
19
|
+
if (ctxFinder.type === RequestStatus.Loading) {
|
|
20
|
+
setLoadingProgress(function (prev) { return Math.min(prev + 15, 90); });
|
|
21
|
+
}
|
|
22
|
+
else if (ctxFinder.type === RequestStatus.Success ||
|
|
23
|
+
ctxFinder.type === RequestStatus.Error) {
|
|
24
|
+
setLoadingProgress(100);
|
|
25
|
+
}
|
|
26
|
+
}, [ctxFinder.type]);
|
|
27
|
+
var dividasPublicasData = useMemo(function () {
|
|
28
|
+
if (ctxFinder.type === RequestStatus.Success && ctxFinder.document) {
|
|
29
|
+
var quantidade = XPathUtils.select('number(//dividas/resumo/quantidade_dividas)', ctxFinder.document) || 0;
|
|
30
|
+
var valorTotal = XPathUtils.select('number(//dividas/resumo/valor_total_dividas)', ctxFinder.document) || 0;
|
|
31
|
+
var datasInscricao = XPathUtils.select('//dividas//divida/data_inscricao', ctxFinder.document) || [];
|
|
32
|
+
var datasValidas = datasInscricao
|
|
33
|
+
.map(function (el) { var _a; return ((_a = el.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || ''; })
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.map(function (d) { return new Date(d).getTime(); })
|
|
36
|
+
.filter(function (t) { return !isNaN(t); });
|
|
37
|
+
var ultimaOcorrencia = datasValidas.length > 0
|
|
38
|
+
? new Date(Math.max.apply(Math, datasValidas)).toLocaleDateString('pt-BR')
|
|
39
|
+
: '';
|
|
40
|
+
return { quantidade: quantidade, valorTotal: valorTotal, ultimaOcorrencia: ultimaOcorrencia };
|
|
41
|
+
}
|
|
42
|
+
return { quantidade: 0, valorTotal: 0, ultimaOcorrencia: '' };
|
|
43
|
+
}, [ctxFinder.type, ctxFinder.document]);
|
|
44
|
+
return __assign(__assign({}, dividasPublicasData), { loadingProgress: loadingProgress });
|
|
45
|
+
};
|
|
@@ -9,10 +9,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
import { classifyProtestos } from '../../../hooks/useProtestosClassification';
|
|
12
13
|
import { converterParaFormatoValido, formatDatePtBrToDate } from '../../../utils/date';
|
|
13
14
|
import XPathUtils from '../../../utils/xpath';
|
|
14
15
|
import { groupBy, sortBy, unique } from 'underscore';
|
|
15
|
-
import { classifyProtestos } from '../hooks/useProtestosClassification';
|
|
16
16
|
export var processData = function (data, quantidadeProcessosJuridicos) {
|
|
17
17
|
var removeZeros = function (current, index, arr) {
|
|
18
18
|
return index === 0 || index === arr.length - 1
|
|
@@ -18,12 +18,12 @@ import ProtestosCreditoIcon from '../../assets/icones/protestosCredito';
|
|
|
18
18
|
import ProtestosGeraisIcon from '../../assets/icones/protestosGerais';
|
|
19
19
|
import ProtestosImpostosIcon from '../../assets/icones/protestosImpostos';
|
|
20
20
|
import { useGlobalData } from '../../contexts/globalDataContext';
|
|
21
|
+
import { classifyProtestos, useProtestosClassification } from '../../hooks/useProtestosClassification';
|
|
21
22
|
import { formatDatePtBrToDate } from '../../utils/date';
|
|
22
23
|
import { extractIntegerFromText } from '../../utils/number';
|
|
23
24
|
import XPathUtils from '../../utils/xpath';
|
|
24
25
|
import React, { useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
25
26
|
import styled from 'styled-components';
|
|
26
|
-
import { classifyProtestos, useProtestosClassification } from '../chart/hooks/useProtestosClassification';
|
|
27
27
|
import StatusMessage from '../interface/statusMessage';
|
|
28
28
|
import Section from '../section';
|
|
29
29
|
import { Queries, RequestStatus } from '../webservice';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface ProtestosClassificados {
|
|
2
|
+
protestosDeCredito: Node[];
|
|
3
|
+
protestosDeImposto: Node[];
|
|
4
|
+
protestosGerais: Node[];
|
|
5
|
+
}
|
|
6
|
+
export declare function classifyProtestos(document: Document | null | undefined, iaOverrides?: Record<string, string>): ProtestosClassificados;
|
|
7
|
+
/**
|
|
8
|
+
* Hook para classificar protestos em Crédito, Imposto e Gerais, com suporte a overrides de IA.
|
|
9
|
+
* @param document Documento XML dos protestos
|
|
10
|
+
* @param iaOverrides Mapa opcional de chaves para nomes de cedente ajustados por IA
|
|
11
|
+
*/
|
|
12
|
+
export declare function useProtestosClassification(document: Document | null | undefined, iaOverrides?: Record<string, string>): ProtestosClassificados;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { REGEX_PROTESTOS_DE_CREDITO, REGEX_PROTESTOS_DE_IMPOSTO } from '../constants/regex';
|
|
2
|
+
import { formatDatePtBrToDate } from '../utils/date';
|
|
3
|
+
import XPathUtils from '../utils/xpath';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
// Função de ordenação por data
|
|
6
|
+
var byDate = function (protesto, protesto2) {
|
|
7
|
+
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;
|
|
10
|
+
return v0 - v1;
|
|
11
|
+
};
|
|
12
|
+
export function classifyProtestos(document, iaOverrides) {
|
|
13
|
+
if (!document) {
|
|
14
|
+
return {
|
|
15
|
+
protestosDeCredito: [],
|
|
16
|
+
protestosDeImposto: [],
|
|
17
|
+
protestosGerais: []
|
|
18
|
+
};
|
|
19
|
+
}
|
|
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);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
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));
|
|
44
|
+
})
|
|
45
|
+
.sort(byDate);
|
|
46
|
+
return {
|
|
47
|
+
protestosDeCredito: protestosDeCredito,
|
|
48
|
+
protestosDeImposto: protestosDeImposto,
|
|
49
|
+
protestosGerais: protestosGerais
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Hook para classificar protestos em Crédito, Imposto e Gerais, com suporte a overrides de IA.
|
|
54
|
+
* @param document Documento XML dos protestos
|
|
55
|
+
* @param iaOverrides Mapa opcional de chaves para nomes de cedente ajustados por IA
|
|
56
|
+
*/
|
|
57
|
+
export function useProtestosClassification(document, iaOverrides) {
|
|
58
|
+
return useMemo(function () { return classifyProtestos(document, iaOverrides); }, [document, iaOverrides]);
|
|
59
|
+
}
|