@credithub/harlan-components 1.46.0 → 1.46.2

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.
@@ -13,6 +13,15 @@ var __assign = (this && this.__assign) || function () {
13
13
  };
14
14
  return __assign.apply(this, arguments);
15
15
  };
16
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
17
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
18
+ if (ar || !(i in from)) {
19
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
20
+ ar[i] = from[i];
21
+ }
22
+ }
23
+ return to.concat(ar || Array.prototype.slice.call(from));
24
+ };
16
25
  import ResumoDeNegativacoesIcon from '../../assets/icones/resumoNegativacoes';
17
26
  import { useGlobalData } from '../../contexts/globalDataContext';
18
27
  import { converterParaFormatoValido } from '../../utils/date';
@@ -22,7 +31,7 @@ import useToggle from '../../hooks/useToggle';
22
31
  import { ConsultasComplementaresContext } from '../consultasComplementares';
23
32
  import StatusMessage from '../interface/statusMessage';
24
33
  import Section from '../section';
25
- import { RequestStatus } from '../webservice';
34
+ import { Queries, RequestStatus } from '../webservice';
26
35
  import ChartContent from './chartContent';
27
36
  import useChartData, { useDividasPublicas } from './hooks/useChartData';
28
37
  import QuantidadeResultados from './quantityResult';
@@ -32,13 +41,35 @@ var ChartSystem = function (_a) {
32
41
  var _b, _c, _d, _e, _f, _g, _h, _j;
33
42
  var documento = _a.documento;
34
43
  var ctxConsultasComplementares = useContext(ConsultasComplementaresContext);
44
+ var ctxProtestosSP = useContext(Queries.Liminar);
35
45
  var setGlobalState = useGlobalData().setData;
36
46
  var _k = useState(false), dataUpdated = _k[0], setDataUpdated = _k[1];
37
47
  var ultimaOcorrenciaCCF = useUltimaOcorrenciaCCF();
38
48
  var consultaSerasa = (_c = (_b = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _b === void 0 ? void 0 : _b.refinSerasa) === null || _c === void 0 ? void 0 : _c.data;
39
49
  var consultaBoaVista = (_e = (_d = ctxConsultasComplementares === null || ctxConsultasComplementares === void 0 ? void 0 : ctxConsultasComplementares.consultasComplementares) === null || _d === void 0 ? void 0 : _d.refinBoaVista) === null || _e === void 0 ? void 0 : _e.data;
40
- var _l = useChartData(documento, consultaSerasa, consultaBoaVista), chartData = _l.data, isLoadingChart = _l.isLoading, errorChart = _l.error, refetchChart = _l.refetch, chartDataProgress = _l.loadingProgress;
41
- var _m = useDividasPublicas(), quantidadeDividas = _m.quantidade, valorTotalDividas = _m.valorTotal, ultimaOcorrenciaDividas = _m.ultimaOcorrencia, dividasProgress = _m.loadingProgress;
50
+ var _l = useState(0), totalProtestosSP = _l[0], setTotalProtestosSP = _l[1];
51
+ var _m = useState(0), valorTotalProtestosSP = _m[0], setValorTotalProtestosSP = _m[1];
52
+ var _o = useChartData(documento, consultaSerasa, consultaBoaVista), chartData = _o.data, isLoadingChart = _o.isLoading, errorChart = _o.error, refetchChart = _o.refetch, chartDataProgress = _o.loadingProgress;
53
+ var _p = useDividasPublicas(), quantidadeDividas = _p.quantidade, valorTotalDividas = _p.valorTotal, ultimaOcorrenciaDividas = _p.ultimaOcorrencia, dividasProgress = _p.loadingProgress;
54
+ useEffect(function () {
55
+ if ((ctxProtestosSP === null || ctxProtestosSP === void 0 ? void 0 : ctxProtestosSP.type) === RequestStatus.Success &&
56
+ ctxProtestosSP.document &&
57
+ Array.isArray(ctxProtestosSP.document.data)) {
58
+ var totalProtestos_1 = ctxProtestosSP.document.data.reduce(function (sum, cartorio) { return sum + Number((cartorio === null || cartorio === void 0 ? void 0 : cartorio[9]) || 0); }, 0);
59
+ var valorTotal = ctxProtestosSP.document.data.reduce(function (sum, cartorio) {
60
+ var _a, _b;
61
+ var valorString = (_b = (_a = cartorio === null || cartorio === void 0 ? void 0 : cartorio[7]) === null || _a === void 0 ? void 0 : _a.match(/[\d,.]+/g)) === null || _b === void 0 ? void 0 : _b[0];
62
+ var valor = parseFloat((valorString === null || valorString === void 0 ? void 0 : valorString.replace('.', '').replace(',', '.')) || '0');
63
+ return sum + valor;
64
+ }, 0);
65
+ setTotalProtestosSP(totalProtestos_1);
66
+ setValorTotalProtestosSP(valorTotal);
67
+ }
68
+ else if ((ctxProtestosSP === null || ctxProtestosSP === void 0 ? void 0 : ctxProtestosSP.type) === RequestStatus.Error) {
69
+ setTotalProtestosSP(0);
70
+ setValorTotalProtestosSP(0);
71
+ }
72
+ }, [ctxProtestosSP === null || ctxProtestosSP === void 0 ? void 0 : ctxProtestosSP.type, ctxProtestosSP === null || ctxProtestosSP === void 0 ? void 0 : ctxProtestosSP.document]);
42
73
  useEffect(function () {
43
74
  if (consultaSerasa || consultaBoaVista) {
44
75
  refetchChart();
@@ -48,8 +79,8 @@ var ChartSystem = function (_a) {
48
79
  var isOpen = useToggle(true)[0];
49
80
  var quantidadeProtestos = ((_g = (_f = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _f === void 0 ? void 0 : _f[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _g === void 0 ? void 0 : _g.quantidade) || 0;
50
81
  var valorTotalProtestos = ((_j = (_h = chartData === null || chartData === void 0 ? void 0 : chartData.protestos) === null || _h === void 0 ? void 0 : _h[(chartData === null || chartData === void 0 ? void 0 : chartData.protestos.length) - 1]) === null || _j === void 0 ? void 0 : _j.valorTotal) || 0;
51
- var _o = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.serasa) || []), quantidadeSerasa = _o.quantidade, valorTotalSerasa = _o.valorTotal, ultimaOcorrenciaSerasa = _o.dataMaisRecente;
52
- var _p = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) || []), quantidadeBoaVista = _p.quantidade, valorTotalBoaVista = _p.valorTotal, ultimaOcorrenciaBoaVista = _p.dataMaisRecente;
82
+ var _q = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.serasa) || []), quantidadeSerasa = _q.quantidade, valorTotalSerasa = _q.valorTotal, ultimaOcorrenciaSerasa = _q.dataMaisRecente;
83
+ var _r = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.boaVista) || []), quantidadeBoaVista = _r.quantidade, valorTotalBoaVista = _r.valorTotal, ultimaOcorrenciaBoaVista = _r.dataMaisRecente;
53
84
  var quantidadeCCFs = useCalculation((chartData === null || chartData === void 0 ? void 0 : chartData.ccfs) || []).quantidade;
54
85
  var ultimaOcorrenciaProtestos = '';
55
86
  if ((chartData === null || chartData === void 0 ? void 0 : chartData.protestosCategory) && chartData.protestosCategory.length > 0) {
@@ -70,13 +101,15 @@ var ChartSystem = function (_a) {
70
101
  ultimaOcorrenciaProtestos = new Date(Math.max.apply(Math, datasOcorrencias)).toLocaleDateString();
71
102
  }
72
103
  }
104
+ var totalProtestos = quantidadeProtestos + totalProtestosSP;
105
+ var totalValorProtestos = valorTotalProtestos + valorTotalProtestosSP;
73
106
  var loadingProgress = (chartDataProgress + dividasProgress) / 2;
74
107
  useEffect(function () {
75
108
  if (!dataUpdated && chartData) {
76
109
  setGlobalState(function (prevState) {
77
110
  var _a;
78
111
  return (__assign(__assign({}, prevState), { documentHistory: {
79
- quantidadeProtestos: quantidadeProtestos,
112
+ quantidadeProtestos: totalProtestos,
80
113
  quantidadeProcessos: ((_a = chartData === null || chartData === void 0 ? void 0 : chartData.pieChartTotalConfig) === null || _a === void 0 ? void 0 : _a.processosJuridicos) || 0,
81
114
  quantidadeDividas: quantidadeDividas,
82
115
  quantidadeDividasSerasa: quantidadeSerasa,
@@ -85,7 +118,7 @@ var ChartSystem = function (_a) {
85
118
  ultimaOcorrenciaChequesSemFundos: ultimaOcorrenciaCCF,
86
119
  valorTotalDividasSerasa: valorTotalSerasa,
87
120
  valorTotalDividasBoaVista: valorTotalBoaVista,
88
- valorTotalProtestos: valorTotalProtestos,
121
+ valorTotalProtestos: totalValorProtestos,
89
122
  valorTotalDividas: valorTotalDividas,
90
123
  ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos,
91
124
  ultimaOcorrenciaDividas: ultimaOcorrenciaDividas,
@@ -105,7 +138,9 @@ var ChartSystem = function (_a) {
105
138
  valorTotalDividas,
106
139
  ultimaOcorrenciaDividas,
107
140
  setGlobalState,
108
- ultimaOcorrenciaCCF
141
+ ultimaOcorrenciaCCF,
142
+ totalProtestos,
143
+ totalValorProtestos
109
144
  ]);
110
145
  return (React.createElement(Section, { ctx: {
111
146
  response: undefined,
@@ -122,8 +157,14 @@ var ChartSystem = function (_a) {
122
157
  }, title: "Resumo de Negativa\u00E7\u00F5es", subtitle: "Veja a quantidade de ocorr\u00EAncias conforme o documento foi consultado ao longo do tempo", icon: ResumoDeNegativacoesIcon, onSuccess: function () {
123
158
  var _a;
124
159
  return (React.createElement(Content, { isOpen: isOpen },
125
- chartData && React.createElement(ChartContent, { dataInput: chartData }),
126
- React.createElement(QuantidadeResultados, { data: chartData, quantidadeProtestos: quantidadeProtestos, quantidadeProcessos: (_a = chartData === null || chartData === void 0 ? void 0 : chartData.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
160
+ chartData && (React.createElement(ChartContent, { dataInput: __assign(__assign({}, chartData), { protestos: __spreadArray(__spreadArray([], chartData.protestos, true), [
161
+ {
162
+ quantidade: totalProtestosSP,
163
+ valorTotal: valorTotalProtestosSP,
164
+ data: new Date().toISOString()
165
+ }
166
+ ], false) }) })),
167
+ React.createElement(QuantidadeResultados, { data: chartData, quantidadeProtestos: totalProtestos, quantidadeProcessos: (_a = chartData === null || chartData === void 0 ? void 0 : chartData.pieChartTotalConfig) === null || _a === void 0 ? void 0 : _a.processosJuridicos, quantidadeDividas: quantidadeDividas, quantidadeDividasSerasa: quantidadeSerasa, quantidadeDividasBoaVista: quantidadeBoaVista, quantidadeChequesSemFundos: quantidadeCCFs, ultimaOcorrenciaChequesSemFundos: ultimaOcorrenciaCCF, valorTotalDividasSerasa: valorTotalSerasa, valorTotalDividasBoaVista: valorTotalBoaVista, valorTotalProtestos: totalValorProtestos, valorTotalDividas: valorTotalDividas, ultimaOcorrenciaProtestos: ultimaOcorrenciaProtestos, ultimaOcorrenciaDividas: ultimaOcorrenciaDividas, ultimaOcorrenciaPefinBoaVista: quantidadeBoaVista > 0
127
168
  ? (ultimaOcorrenciaBoaVista !== null && ultimaOcorrenciaBoaVista !== void 0 ? ultimaOcorrenciaBoaVista : undefined)
128
169
  : undefined, ultimaOcorrenciaPefinSerasa: quantidadeSerasa > 0
129
170
  ? (ultimaOcorrenciaSerasa !== null && ultimaOcorrenciaSerasa !== void 0 ? ultimaOcorrenciaSerasa : undefined)
@@ -53,7 +53,7 @@ var Protestos = function () {
53
53
  }
54
54
  var data = ctx.document;
55
55
  var registrosText = XPathUtils.select('string(//registros)', data);
56
- var haveException = XPathUtils.select('string(//raw)', data) != 'false';
56
+ var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
57
57
  var registros = haveException ? extractIntegerFromText(registrosText) + total : extractIntegerFromText(registrosText);
58
58
  var filterProtestos = function (regex, data) {
59
59
  return XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
@@ -80,7 +80,7 @@ var Protestos = function () {
80
80
  }, [ctx, setData, dataUpdated]);
81
81
  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: function (data) {
82
82
  var registrosText = XPathUtils.select('string(//registros)', data);
83
- var haveException = XPathUtils.select('string(//raw)', data) != 'false';
83
+ var haveException = /Falha na integra/gi.test(XPathUtils.select('string(//raw)', data));
84
84
  var registros = haveException ? extractIntegerFromText(registrosText) + total : extractIntegerFromText(registrosText);
85
85
  var protestosDeCredito = XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
86
86
  return REGEX_PROTESTOS_DE_CREDITO.test(XPathUtils.select('string(./nomeCedente)', protesto));
@@ -50,8 +50,8 @@ var ProtestosSP = function () {
50
50
  React.createElement(AddItemField, { name: "Quantidade", value: e === null || e === void 0 ? void 0 : e[9] }),
51
51
  React.createElement(AddItemField, { name: "Valor Total", value: formatMoney((_d = (_c = (_b = (_a = e === null || e === void 0 ? void 0 : e[7]) === null || _a === void 0 ? void 0 : _a.match(/[\d,.]+/g)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.replace('.', "")) === null || _d === void 0 ? void 0 : _d.replace(',', '.')) })));
52
52
  }),
53
- variant: registros ? 'error' : 'default',
54
- description: (React.createElement(StatusMessage, { type: registros ? 'error' : 'default' }, possuiProtestosSp && !registros ? 'Existem protestos' : registros
53
+ variant: registros || (possuiProtestosSp && !registros) ? 'error' : 'default',
54
+ description: (React.createElement(StatusMessage, { type: registros || (possuiProtestosSp && !registros) ? 'error' : 'default' }, possuiProtestosSp && !registros ? 'Existem protestos' : registros
55
55
  ? registros === 1
56
56
  ? 'Encontrado um protesto'
57
57
  : "Encontrados ".concat(registros, " protestos")