@credithub/harlan-components 1.35.1 → 1.36.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 +21 -7
- package/dist/components/chart/hooks/useChartData.d.ts +1 -0
- package/dist/components/chart/hooks/useChartData.js +22 -9
- package/dist/components/chart/quantityResult.d.ts +3 -0
- package/dist/components/chart/quantityResult.js +11 -9
- package/dist/components/chart/types/iChart.d.ts +7 -0
- package/dist/components/chart/utils/chartUtils.d.ts +3 -3
- package/dist/components/chart/utils/chartUtils.js +12 -4
- package/dist/components/refinSerasa/refinSerasa.d.ts +0 -17
- package/dist/components/refinSerasa/refinSerasa.js +27 -14
- package/lib/cjs/index.js +90 -51
- package/lib/esm/index.js +90 -51
- package/package.json +1 -1
- package/dist/utils/calculation.d.ts +0 -9
- package/dist/utils/calculation.js +0 -17
|
@@ -4,7 +4,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
4
4
|
};
|
|
5
5
|
import ResumoDeNegativacoesIcon from '../../assets/icones/resumoNegativacoes';
|
|
6
6
|
import { converterParaFormatoValido } from '../../utils/date';
|
|
7
|
-
import React, { useCallback, useContext, useEffect } from 'react';
|
|
7
|
+
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
|
8
8
|
import styled from 'styled-components';
|
|
9
9
|
import useToggle from '../../hooks/useToggle';
|
|
10
10
|
import { ConsultasComplementaresContext } from '../consultasComplementares';
|
|
@@ -20,15 +20,16 @@ var ChartSystem = function (_a) {
|
|
|
20
20
|
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
21
|
var documento = _a.documento;
|
|
22
22
|
var _k = useChartData(documento), data = _k.data, isLoading = _k.isLoading, error = _k.error, refetch = _k.refetch, chartDataProgress = _k.loadingProgress;
|
|
23
|
-
var _l = useDividasPublicas(), quantidadeDividas = _l.quantidade, valorTotalDividas = _l.valorTotal, dividasProgress = _l.loadingProgress;
|
|
23
|
+
var _l = useDividasPublicas(), quantidadeDividas = _l.quantidade, valorTotalDividas = _l.valorTotal, ultimaOcorrenciaDividas = _l.ultimaOcorrencia, dividasProgress = _l.loadingProgress;
|
|
24
24
|
var ctxConsultasComplementares = useContext(ConsultasComplementaresContext);
|
|
25
25
|
var errorMessage = typeof error === 'string' ? new Error(error) : error;
|
|
26
26
|
var isOpen = useToggle(true)[0];
|
|
27
27
|
var ultimaOcorrenciaCCF = useUltimaOcorrenciaCCF();
|
|
28
|
+
var _m = useState(false), refetchTriggered = _m[0], setRefetchTriggered = _m[1];
|
|
28
29
|
var quantidadeProtestos = ((_c = (_b = data === null || data === void 0 ? void 0 : data.protestos) === null || _b === void 0 ? void 0 : _b[(data === null || data === void 0 ? void 0 : data.protestos.length) - 1]) === null || _c === void 0 ? void 0 : _c.quantidade) || 0;
|
|
29
30
|
var valorTotalProtestos = ((_e = (_d = data === null || data === void 0 ? void 0 : data.protestos) === null || _d === void 0 ? void 0 : _d[(data === null || data === void 0 ? void 0 : data.protestos.length) - 1]) === null || _e === void 0 ? void 0 : _e.valorTotal) || 0;
|
|
30
|
-
var
|
|
31
|
-
var
|
|
31
|
+
var _o = useCalculation((data === null || data === void 0 ? void 0 : data.serasa) || []), quantidadeSerasa = _o.quantidade, valorTotalSerasa = _o.valorTotal, ultimaOcorrenciaSerasa = _o.dataMaisRecente;
|
|
32
|
+
var _p = useCalculation((data === null || data === void 0 ? void 0 : data.boaVista) || []), quantidadeBoaVista = _p.quantidade, valorTotalBoaVista = _p.valorTotal, ultimaOcorrenciaBoaVista = _p.dataMaisRecente;
|
|
32
33
|
var quantidadeCCFs = useCalculation((data === null || data === void 0 ? void 0 : data.ccfs) || []).quantidade;
|
|
33
34
|
var ultimaOcorrenciaProtestos = '';
|
|
34
35
|
if ((data === null || data === void 0 ? void 0 : data.protestosCategory) && data.protestosCategory.length > 0) {
|
|
@@ -46,10 +47,19 @@ var ChartSystem = function (_a) {
|
|
|
46
47
|
var consultaPefinBoaVista = (_g = (_f = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _f === void 0 ? void 0 : _f.refinBoaVista) === null || _g === void 0 ? void 0 : _g.data;
|
|
47
48
|
var consultaPefinSerasa = (_j = (_h = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _h === void 0 ? void 0 : _h.refinSerasa) === null || _j === void 0 ? void 0 : _j.data;
|
|
48
49
|
var handleRefetch = useCallback(function () {
|
|
49
|
-
if ((consultaPefinBoaVista || consultaPefinSerasa) &&
|
|
50
|
+
if ((consultaPefinBoaVista || consultaPefinSerasa) &&
|
|
51
|
+
!isLoading &&
|
|
52
|
+
!refetchTriggered) {
|
|
50
53
|
refetch();
|
|
54
|
+
setRefetchTriggered(true);
|
|
51
55
|
}
|
|
52
|
-
}, [
|
|
56
|
+
}, [
|
|
57
|
+
consultaPefinBoaVista,
|
|
58
|
+
consultaPefinSerasa,
|
|
59
|
+
refetch,
|
|
60
|
+
isLoading,
|
|
61
|
+
refetchTriggered
|
|
62
|
+
]);
|
|
53
63
|
useEffect(function () {
|
|
54
64
|
handleRefetch();
|
|
55
65
|
}, [handleRefetch]);
|
|
@@ -71,7 +81,11 @@ var ChartSystem = function (_a) {
|
|
|
71
81
|
return (React.createElement(React.Fragment, null,
|
|
72
82
|
React.createElement(Content, { isOpen: isOpen },
|
|
73
83
|
data && React.createElement(ChartContent, { dataInput: data }),
|
|
74
|
-
React.createElement(QuantidadeResultados, { data: data, quantidadeProtestos: quantidadeProtestos, quantidadeProcessos: (_a = data === null || data === void 0 ? void 0 : data.pieChartTotalConfig) === null || _a === void 0 ? void 0 : _a.processosJuridicos, quantidadeDividas: quantidadeDividas, quantidadeDividasSerasa: quantidadeSerasa, quantidadeDividasBoaVista: quantidadeBoaVista, quantidadeChequesSemFundos: quantidadeCCFs, ultimaOcorrenciaChequesSemFundos: ultimaOcorrenciaCCF, valorTotalDividasSerasa: valorTotalSerasa, valorTotalDividasBoaVista: valorTotalBoaVista, valorTotalProtestos: valorTotalProtestos, valorTotalDividas: valorTotalDividas, ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos
|
|
84
|
+
React.createElement(QuantidadeResultados, { data: data, quantidadeProtestos: quantidadeProtestos, quantidadeProcessos: (_a = data === null || data === void 0 ? void 0 : data.pieChartTotalConfig) === null || _a === void 0 ? void 0 : _a.processosJuridicos, quantidadeDividas: quantidadeDividas, quantidadeDividasSerasa: quantidadeSerasa, quantidadeDividasBoaVista: quantidadeBoaVista, quantidadeChequesSemFundos: quantidadeCCFs, ultimaOcorrenciaChequesSemFundos: ultimaOcorrenciaCCF, valorTotalDividasSerasa: valorTotalSerasa, valorTotalDividasBoaVista: valorTotalBoaVista, valorTotalProtestos: valorTotalProtestos, valorTotalDividas: valorTotalDividas, ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos, ultimaOcorrenciaDividas: ultimaOcorrenciaDividas, ultimaOcorrenciaPefinBoaVista: quantidadeBoaVista > 0
|
|
85
|
+
? (ultimaOcorrenciaBoaVista !== null && ultimaOcorrenciaBoaVista !== void 0 ? ultimaOcorrenciaBoaVista : undefined)
|
|
86
|
+
: undefined, ultimaOcorrenciaPefinSerasa: quantidadeSerasa > 0
|
|
87
|
+
? (ultimaOcorrenciaSerasa !== null && ultimaOcorrenciaSerasa !== void 0 ? ultimaOcorrenciaSerasa : undefined)
|
|
88
|
+
: undefined }))));
|
|
75
89
|
}, isError: function (err) { return ({
|
|
76
90
|
children: React.createElement(React.Fragment, null),
|
|
77
91
|
description: (React.createElement(StatusMessage, { type: "error" },
|
|
@@ -15,26 +15,39 @@ import { useContext, useEffect, useMemo, useState } from 'react';
|
|
|
15
15
|
import { processData, processProtestData } from '../utils/dataProcessing';
|
|
16
16
|
export var useDividasPublicas = function () {
|
|
17
17
|
var ctxFinder = useContext(Queries.Finder);
|
|
18
|
-
var _a = useState(0), loadingProgress = _a[0], setLoadingProgress = _a[1];
|
|
18
|
+
var _a = useState(0), loadingProgress = _a[0], setLoadingProgress = _a[1];
|
|
19
19
|
useEffect(function () {
|
|
20
20
|
if ((ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Loading) {
|
|
21
|
-
setLoadingProgress(function (prev) { return Math.min(prev + 15, 90); });
|
|
21
|
+
setLoadingProgress(function (prev) { return Math.min(prev + 15, 90); });
|
|
22
22
|
}
|
|
23
23
|
else if ((ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Success ||
|
|
24
24
|
(ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Error) {
|
|
25
|
-
setLoadingProgress(100);
|
|
25
|
+
setLoadingProgress(100);
|
|
26
26
|
}
|
|
27
27
|
}, [ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type]);
|
|
28
28
|
var dividasPublicasData = useMemo(function () {
|
|
29
29
|
if ((ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type) === RequestStatus.Success) {
|
|
30
|
+
var quantidade = XPathUtils.select('number(//dividas/resumo/quantidade_dividas)', ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.document) || 0;
|
|
31
|
+
var valorTotal = XPathUtils.select('number(//dividas/resumo/valor_total_dividas)', ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.document) || 0;
|
|
32
|
+
var datasInscricao = XPathUtils.select('//dividas//divida/data_inscricao', ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.document) || [];
|
|
33
|
+
var datasValidas = datasInscricao
|
|
34
|
+
.map(function (element) { var _a; return ((_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || ''; })
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
.map(function (data) { return new Date(data).getTime(); })
|
|
37
|
+
.filter(function (timestamp) { return !isNaN(timestamp); });
|
|
38
|
+
var ultimaOcorrencia = datasValidas.length > 0
|
|
39
|
+
? new Date(Math.max.apply(Math, datasValidas)).toLocaleDateString()
|
|
40
|
+
: '';
|
|
30
41
|
return {
|
|
31
|
-
quantidade:
|
|
32
|
-
valorTotal:
|
|
42
|
+
quantidade: quantidade,
|
|
43
|
+
valorTotal: valorTotal,
|
|
44
|
+
ultimaOcorrencia: ultimaOcorrencia
|
|
33
45
|
};
|
|
34
46
|
}
|
|
35
47
|
return {
|
|
36
48
|
quantidade: 0,
|
|
37
|
-
valorTotal: 0
|
|
49
|
+
valorTotal: 0,
|
|
50
|
+
ultimaOcorrencia: ''
|
|
38
51
|
};
|
|
39
52
|
}, [ctxFinder === null || ctxFinder === void 0 ? void 0 : ctxFinder.type]);
|
|
40
53
|
return __assign(__assign({}, dividasPublicasData), { loadingProgress: loadingProgress });
|
|
@@ -42,7 +55,7 @@ export var useDividasPublicas = function () {
|
|
|
42
55
|
var useChartData = function (documento) {
|
|
43
56
|
var _a = useState(null), data = _a[0], setData = _a[1];
|
|
44
57
|
var _b = useState(null), errorState = _b[0], setErrorState = _b[1];
|
|
45
|
-
var _c = useState(0), loadingProgress = _c[0], setLoadingProgress = _c[1];
|
|
58
|
+
var _c = useState(0), loadingProgress = _c[0], setLoadingProgress = _c[1];
|
|
46
59
|
var _d = useQuery("SELECT FROM 'DOCUMENTHISTORY'.'BASICHISTORY'", {
|
|
47
60
|
documento: documento
|
|
48
61
|
}), response = _d.response, queryError = _d.error, isLoading = _d.isLoading, refetch = _d.refetch;
|
|
@@ -77,10 +90,10 @@ var useChartData = function (documento) {
|
|
|
77
90
|
}, [liveQueriesIsFinish, refetch]);
|
|
78
91
|
useEffect(function () {
|
|
79
92
|
if (isLoading) {
|
|
80
|
-
setLoadingProgress(function (prev) { return Math.min(prev + 15, 90); });
|
|
93
|
+
setLoadingProgress(function (prev) { return Math.min(prev + 15, 90); });
|
|
81
94
|
}
|
|
82
95
|
else if (!isLoading && (queryError || response)) {
|
|
83
|
-
setLoadingProgress(100);
|
|
96
|
+
setLoadingProgress(100);
|
|
84
97
|
}
|
|
85
98
|
}, [isLoading, queryError, response]);
|
|
86
99
|
useEffect(function () {
|
|
@@ -14,6 +14,9 @@ type QuantidadeResultadosProps = Partial<{
|
|
|
14
14
|
valorTotalDividasBoaVista: number;
|
|
15
15
|
ultimaOcorrenciaProtestos: string;
|
|
16
16
|
ultimaOcorrenciaChequesSemFundos: string;
|
|
17
|
+
ultimaOcorrenciaDividas: string;
|
|
18
|
+
ultimaOcorrenciaPefinSerasa: string;
|
|
19
|
+
ultimaOcorrenciaPefinBoaVista: string;
|
|
17
20
|
}>;
|
|
18
21
|
declare const QuantidadeResultados: React.FC<QuantidadeResultadosProps>;
|
|
19
22
|
export default QuantidadeResultados;
|
|
@@ -3,19 +3,18 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
|
|
|
3
3
|
return cooked;
|
|
4
4
|
};
|
|
5
5
|
/* eslint-disable no-extra-boolean-cast */
|
|
6
|
+
import { formatMoney, formatValue } from '../../utils/number';
|
|
6
7
|
import React from 'react';
|
|
8
|
+
import styled from 'styled-components';
|
|
7
9
|
import AddItemField from '../common/addItem';
|
|
8
|
-
import { formatMoney, formatValue } from '../../utils/number';
|
|
9
10
|
import { Result, ResultContent } from '../interface/result';
|
|
10
|
-
import styled from 'styled-components';
|
|
11
11
|
var QuantityContainer = function (_a) {
|
|
12
12
|
var children = _a.children;
|
|
13
13
|
return (React.createElement("div", { className: "t" }, children));
|
|
14
14
|
};
|
|
15
15
|
var QuantidadeResultadosWrapper = styled(ResultContent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: 18px 20px;\n row-gap: 20px;\n > * {\n row-gap: 10px;\n }\n"], ["\n padding: 18px 20px;\n row-gap: 20px;\n > * {\n row-gap: 10px;\n }\n"])));
|
|
16
16
|
var QuantidadeResultados = function (_a) {
|
|
17
|
-
var _b, _c, _d, _e;
|
|
18
|
-
var data = _a.data, _f = _a.quantidadeProtestos, quantidadeProtestos = _f === void 0 ? 0 : _f, _g = _a.quantidadeProcessos, quantidadeProcessos = _g === void 0 ? 0 : _g, _h = _a.quantidadeDividas, quantidadeDividas = _h === void 0 ? 0 : _h, _j = _a.quantidadeChequesSemFundos, quantidadeChequesSemFundos = _j === void 0 ? 0 : _j, _k = _a.quantidadeDividasSerasa, quantidadeDividasSerasa = _k === void 0 ? 0 : _k, _l = _a.quantidadeDividasBoaVista, quantidadeDividasBoaVista = _l === void 0 ? 0 : _l, _m = _a.valorTotalProtestos, valorTotalProtestos = _m === void 0 ? 0 : _m, _o = _a.valorTotalDividas, valorTotalDividas = _o === void 0 ? 0 : _o, _p = _a.valorTotalDividasSerasa, valorTotalDividasSerasa = _p === void 0 ? 0 : _p, _q = _a.valorTotalDividasBoaVista, valorTotalDividasBoaVista = _q === void 0 ? 0 : _q, _r = _a.ultimaOcorrenciaProtestos, ultimaOcorrenciaProtestos = _r === void 0 ? null : _r, _s = _a.ultimaOcorrenciaChequesSemFundos, ultimaOcorrenciaChequesSemFundos = _s === void 0 ? null : _s;
|
|
17
|
+
var _b = _a.quantidadeProtestos, quantidadeProtestos = _b === void 0 ? 0 : _b, _c = _a.quantidadeProcessos, quantidadeProcessos = _c === void 0 ? 0 : _c, _d = _a.quantidadeDividas, quantidadeDividas = _d === void 0 ? 0 : _d, _e = _a.quantidadeChequesSemFundos, quantidadeChequesSemFundos = _e === void 0 ? 0 : _e, _f = _a.quantidadeDividasSerasa, quantidadeDividasSerasa = _f === void 0 ? 0 : _f, _g = _a.quantidadeDividasBoaVista, quantidadeDividasBoaVista = _g === void 0 ? 0 : _g, _h = _a.valorTotalProtestos, valorTotalProtestos = _h === void 0 ? 0 : _h, _j = _a.valorTotalDividas, valorTotalDividas = _j === void 0 ? 0 : _j, _k = _a.valorTotalDividasSerasa, valorTotalDividasSerasa = _k === void 0 ? 0 : _k, _l = _a.valorTotalDividasBoaVista, valorTotalDividasBoaVista = _l === void 0 ? 0 : _l, _m = _a.ultimaOcorrenciaProtestos, ultimaOcorrenciaProtestos = _m === void 0 ? null : _m, _o = _a.ultimaOcorrenciaChequesSemFundos, ultimaOcorrenciaChequesSemFundos = _o === void 0 ? null : _o, _p = _a.ultimaOcorrenciaDividas, ultimaOcorrenciaDividas = _p === void 0 ? null : _p, _q = _a.ultimaOcorrenciaPefinSerasa, ultimaOcorrenciaPefinSerasa = _q === void 0 ? null : _q, _r = _a.ultimaOcorrenciaPefinBoaVista, ultimaOcorrenciaPefinBoaVista = _r === void 0 ? null : _r;
|
|
19
18
|
return (React.createElement(Result, { resultContentStriped: false },
|
|
20
19
|
React.createElement(QuantidadeResultadosWrapper, { desktop: "repeat(6, 1fr)", print: "repeat(6, 1fr)", tablet: "repeat(3, 1fr)", mobile: "repeat(2, 1fr)" },
|
|
21
20
|
React.createElement(QuantityContainer, null,
|
|
@@ -29,13 +28,16 @@ var QuantidadeResultados = function (_a) {
|
|
|
29
28
|
React.createElement(AddItemField, { name: "Processos Jur\u00EDdicos", value: formatValue(quantidadeProcessos) })),
|
|
30
29
|
React.createElement(QuantityContainer, null,
|
|
31
30
|
React.createElement(AddItemField, { name: "D\u00EDvidas P\u00FAblicas", value: formatValue(quantidadeDividas) }),
|
|
32
|
-
React.createElement(AddItemField, { name: "Total D\u00EDvidas P\u00FAblicas", value: formatMoney(valorTotalDividas) })
|
|
31
|
+
React.createElement(AddItemField, { name: "Total D\u00EDvidas P\u00FAblicas", value: formatMoney(valorTotalDividas) }),
|
|
32
|
+
React.createElement(AddItemField, { hidden: quantidadeDividas == 0, name: "\u00DAltima Ocorr\u00EAncia", value: ultimaOcorrenciaDividas })),
|
|
33
33
|
React.createElement(QuantityContainer, null,
|
|
34
|
-
React.createElement(AddItemField, {
|
|
35
|
-
React.createElement(AddItemField, {
|
|
34
|
+
React.createElement(AddItemField, { name: "Pefin Refin Serasa", value: formatValue(quantidadeDividasSerasa) }),
|
|
35
|
+
React.createElement(AddItemField, { name: "Total Pefin Refin Serasa", value: formatMoney(valorTotalDividasSerasa) }),
|
|
36
|
+
React.createElement(AddItemField, { hidden: quantidadeDividasSerasa === 0 || !ultimaOcorrenciaPefinSerasa, name: "\u00DAltima Ocorr\u00EAncia", value: ultimaOcorrenciaPefinSerasa })),
|
|
36
37
|
React.createElement(QuantityContainer, null,
|
|
37
|
-
React.createElement(AddItemField, {
|
|
38
|
-
React.createElement(AddItemField, {
|
|
38
|
+
React.createElement(AddItemField, { name: "Pefin Refin Boa Vista", value: formatValue(quantidadeDividasBoaVista) }),
|
|
39
|
+
React.createElement(AddItemField, { name: "Total Pefin Refin Boa Vista", value: formatMoney(valorTotalDividasBoaVista) }),
|
|
40
|
+
React.createElement(AddItemField, { hidden: quantidadeDividasBoaVista === 0 || !ultimaOcorrenciaPefinBoaVista, name: "\u00DAltima Ocorr\u00EAncia", value: ultimaOcorrenciaPefinBoaVista })))));
|
|
39
41
|
};
|
|
40
42
|
export default QuantidadeResultados;
|
|
41
43
|
var templateObject_1;
|
|
@@ -57,3 +57,10 @@ export interface DataSetBar extends DataSetCommon {
|
|
|
57
57
|
barPercentage?: number;
|
|
58
58
|
}
|
|
59
59
|
export type TimeFilter = '1y' | '6m' | '1m' | 'all';
|
|
60
|
+
export interface ItemCalculo {
|
|
61
|
+
quantidade?: number | null;
|
|
62
|
+
valorTotal?: number | null;
|
|
63
|
+
data?: string | Date;
|
|
64
|
+
creation?: string | Date;
|
|
65
|
+
[key: string]: any;
|
|
66
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ItemCalculo } from '
|
|
2
|
-
export declare const useCalculation: (itens: ItemCalculo[]) => {
|
|
1
|
+
import { ItemCalculo } from '../types/iChart';
|
|
2
|
+
export declare const useCalculation: (itens: ItemCalculo[], dataKey?: string) => {
|
|
3
3
|
quantidade: number;
|
|
4
4
|
valorTotal: number;
|
|
5
|
-
dataMaisRecente: string;
|
|
5
|
+
dataMaisRecente: string | null;
|
|
6
6
|
};
|
|
7
7
|
export declare const useUltimaOcorrenciaCCF: () => string | undefined;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
-
import { useMemo, useContext } from 'react';
|
|
3
|
-
import { encontrarDataMaisRecente } from '../../../utils/calculation';
|
|
4
2
|
import { Queries, RequestStatus } from '../../../components/webservice';
|
|
5
3
|
import XPathUtils from '../../../utils/xpath';
|
|
6
4
|
import last from 'lodash/last';
|
|
7
|
-
|
|
5
|
+
import { useContext, useMemo } from 'react';
|
|
6
|
+
export var useCalculation = function (itens, dataKey) {
|
|
8
7
|
var quantidade = useMemo(function () { var _a; return ((_a = last(itens)) === null || _a === void 0 ? void 0 : _a.quantidade) || 0; }, [itens]);
|
|
9
8
|
var valorTotal = useMemo(function () { var _a; return ((_a = last(itens)) === null || _a === void 0 ? void 0 : _a.valorTotal) || 0; }, [itens]);
|
|
10
|
-
var dataMaisRecente = useMemo(function () {
|
|
9
|
+
var dataMaisRecente = useMemo(function () {
|
|
10
|
+
var datas = itens
|
|
11
|
+
.map(function (item) { return item[dataKey || 'data']; })
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.map(function (data) { return new Date(data).getTime(); })
|
|
14
|
+
.filter(function (timestamp) { return !isNaN(timestamp); });
|
|
15
|
+
return datas.length
|
|
16
|
+
? new Date(Math.max.apply(Math, datas)).toLocaleDateString()
|
|
17
|
+
: null;
|
|
18
|
+
}, [itens, dataKey]);
|
|
11
19
|
return { quantidade: quantidade, valorTotal: valorTotal, dataMaisRecente: dataMaisRecente };
|
|
12
20
|
};
|
|
13
21
|
export var useUltimaOcorrenciaCCF = function () {
|
|
@@ -2,21 +2,4 @@ import React from 'react';
|
|
|
2
2
|
declare const RefinSerasa: React.FC<{
|
|
3
3
|
documento: string;
|
|
4
4
|
}>;
|
|
5
|
-
export type PendenciaSerasa = {
|
|
6
|
-
ocorrencia: string;
|
|
7
|
-
credor: string;
|
|
8
|
-
entrada: string;
|
|
9
|
-
vencimento: string;
|
|
10
|
-
valor: string;
|
|
11
|
-
informante: string;
|
|
12
|
-
contrato: string;
|
|
13
|
-
avalista: string;
|
|
14
|
-
cidade: string;
|
|
15
|
-
uf: string;
|
|
16
|
-
situacao: string;
|
|
17
|
-
orgaoemissor: string;
|
|
18
|
-
totalpendencias: string;
|
|
19
|
-
totalvalor: string;
|
|
20
|
-
categoria: string;
|
|
21
|
-
};
|
|
22
5
|
export default RefinSerasa;
|
|
@@ -21,17 +21,21 @@ import StatusMessage from '../interface/statusMessage';
|
|
|
21
21
|
import { Section } from '../section';
|
|
22
22
|
import { RequestStatus, useQuery } from '../webservice';
|
|
23
23
|
var RefinSerasa = function (_a) {
|
|
24
|
-
var _b, _c
|
|
24
|
+
var _b, _c;
|
|
25
25
|
var documento = _a.documento;
|
|
26
26
|
var refinSerasaRef = useRef(null);
|
|
27
27
|
var setData = useGlobalData().setData;
|
|
28
|
-
var
|
|
28
|
+
var _d = useState(false), dataUpdated = _d[0], setDataUpdated = _d[1];
|
|
29
29
|
var consultasComplementaresContext = useContext(ConsultasComplementaresContext);
|
|
30
|
-
var
|
|
31
|
-
var
|
|
30
|
+
var _e = consultasComplementaresContext !== null && consultasComplementaresContext !== void 0 ? consultasComplementaresContext : {}, consultasComplementares = _e.consultasComplementares, setConsultasComplementares = _e.setConsultasComplementares;
|
|
31
|
+
var _f = useQuery("SELECT FROM 'PROTESTOS'.'SERASA'", { documento: documento }, !!((_b = consultasComplementares === null || consultasComplementares === void 0 ? void 0 : consultasComplementares.refinSerasa) === null || _b === void 0 ? void 0 : _b.consultaRealizada)), response = _f.response, isLoading = _f.isLoading, error = _f.error, loadingProgress = _f.loadingProgress;
|
|
32
32
|
var clearValue = function (value) {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (!value)
|
|
34
|
+
return '0';
|
|
35
|
+
var semPontos = value.replace(/\./g, '');
|
|
36
|
+
var valorFinal = semPontos.replace(',', '.');
|
|
37
|
+
var parsed = parseFloat(valorFinal);
|
|
38
|
+
return isNaN(parsed) ? '0' : valorFinal;
|
|
35
39
|
};
|
|
36
40
|
var pendenciasData = useMemo(function () {
|
|
37
41
|
var _a, _b, _c;
|
|
@@ -39,7 +43,7 @@ var RefinSerasa = function (_a) {
|
|
|
39
43
|
.map(addNoValueContent)
|
|
40
44
|
.map(function (pendencia) {
|
|
41
45
|
var _a;
|
|
42
|
-
return (__assign(__assign({}, pendencia), { valor:
|
|
46
|
+
return (__assign(__assign({}, pendencia), { valor: clearValue(pendencia.valor), totalvalor: clearValue(pendencia.totalvalor), vencimento: (_a = pendencia === null || pendencia === void 0 ? void 0 : pendencia.vencimento) === null || _a === void 0 ? void 0 : _a.slice(0, 10) }));
|
|
43
47
|
});
|
|
44
48
|
}, [response]);
|
|
45
49
|
var pendencias = pendenciasData.filter(function (_a) {
|
|
@@ -65,12 +69,21 @@ var RefinSerasa = function (_a) {
|
|
|
65
69
|
setDataUpdated(true);
|
|
66
70
|
}
|
|
67
71
|
}, [response, dataUpdated, setData]);
|
|
68
|
-
var
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
var totalPendencias = useMemo(function () { return pendencias.length; }, [pendencias]);
|
|
73
|
+
var valorTotalPendencias = useMemo(function () {
|
|
74
|
+
return pendencias.reduce(function (acc, curr) {
|
|
75
|
+
var valor = parseFloat(curr.valor) || 0;
|
|
76
|
+
return acc + valor;
|
|
77
|
+
}, 0);
|
|
78
|
+
}, [pendencias]);
|
|
79
|
+
var description = useMemo(function () {
|
|
80
|
+
if (totalPendencias === 0) {
|
|
81
|
+
return 'Nenhuma ocorrência encontrada';
|
|
82
|
+
}
|
|
83
|
+
return totalPendencias === 1
|
|
84
|
+
? "Foi encontrada 1 ocorr\u00EAncia no valor de ".concat(formatMoney(valorTotalPendencias))
|
|
85
|
+
: "Foram encontradas ".concat(totalPendencias, " ocorr\u00EAncias no valor total de ").concat(formatMoney(valorTotalPendencias));
|
|
86
|
+
}, [totalPendencias, valorTotalPendencias]);
|
|
74
87
|
return consultaRefinRealizada ? (React.createElement(Section, { ctx: {
|
|
75
88
|
type: isLoading
|
|
76
89
|
? RequestStatus.Loading
|
|
@@ -83,7 +96,7 @@ var RefinSerasa = function (_a) {
|
|
|
83
96
|
refetch: function () { },
|
|
84
97
|
Section: Section,
|
|
85
98
|
progress: loadingProgress
|
|
86
|
-
}, title: "Pefin/Refin e Contratos Vencidos Serasa", subtitle: "Confira as Pend\u00EAncias Financeiras deste documento", icon: PefinRefinSerasaIcon, description: !error && (React.createElement(StatusMessage, { type:
|
|
99
|
+
}, title: "Pefin/Refin e Contratos Vencidos Serasa", subtitle: "Confira as Pend\u00EAncias Financeiras deste documento", icon: PefinRefinSerasaIcon, description: !error && (React.createElement(StatusMessage, { type: totalPendencias === 0 ? 'success' : 'error' }, description)), variant: totalPendencias === 0 ? 'default' : 'error', onSuccess: function () { return (React.createElement(Result, null, pendencias.map(function (pendencia, i) { return (React.createElement(ResultContent, { key: i, desktop: "repeat(5, 1fr)", tablet: "repeat(3, 1fr)", mobile: "1fr 1fr" },
|
|
87
100
|
React.createElement(AddItemField, { name: "Tipo de Ocorr\u00EAncia", value: pendencia.ocorrencia }),
|
|
88
101
|
React.createElement(AddItemField, { name: "Credor", value: pendencia.credor }),
|
|
89
102
|
React.createElement(AddItemField, { name: "Data de Entrada", value: pendencia.entrada }),
|