@credithub/harlan-components 1.19.5 → 1.20.1

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/lib/cjs/index.js CHANGED
@@ -13683,6 +13683,10 @@ var isDocumentoPF = function (documento) {
13683
13683
  var cleanDocument = documento.replace(/\D/g, '');
13684
13684
  return cleanDocument.length === 11;
13685
13685
  };
13686
+ var converterParaFormatoValido = function (data) {
13687
+ var _a = data.split('/'), dia = _a[0], mes = _a[1], ano = _a[2];
13688
+ return "".concat(mes, "/").concat(dia, "/").concat(ano);
13689
+ };
13686
13690
  function formatDatePtBrToDate(date) {
13687
13691
  var _a, _b;
13688
13692
  return new Date((_b = (_a = date === null || date === void 0 ? void 0 : date.split('/')) === null || _a === void 0 ? void 0 : _a.reverse()) === null || _b === void 0 ? void 0 : _b.join('-'));
@@ -13836,7 +13840,7 @@ var ProtestosCategory = function (_a) {
13836
13840
  React.createElement(Result, null, children))));
13837
13841
  };
13838
13842
 
13839
- var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
13843
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
13840
13844
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13841
13845
  return new (P || (P = Promise))(function (resolve, reject) {
13842
13846
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -13845,7 +13849,7 @@ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _argu
13845
13849
  step((generator = generator.apply(thisArg, _arguments || [])).next());
13846
13850
  });
13847
13851
  };
13848
- var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
13852
+ var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
13849
13853
  var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13850
13854
  return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13851
13855
  function verb(n) { return function (v) { return step([n, v]); }; }
@@ -13898,9 +13902,9 @@ var Instrumento = function (_a) {
13898
13902
  var _c = React.useState(false), isLoading = _c[0], setIsLoading = _c[1];
13899
13903
  if (!nm_chave)
13900
13904
  return null;
13901
- return (React.createElement(Button$1, { onClick: function () { return __awaiter$1(void 0, void 0, void 0, function () {
13905
+ return (React.createElement(Button$1, { onClick: function () { return __awaiter(void 0, void 0, void 0, function () {
13902
13906
  var request, pdfWindow, e_1;
13903
- return __generator$1(this, function (_a) {
13907
+ return __generator(this, function (_a) {
13904
13908
  switch (_a.label) {
13905
13909
  case 0:
13906
13910
  setIsLoading(true);
@@ -22103,42 +22107,6 @@ var __makeTemplateObject$h = (undefined && undefined.__makeTemplateObject) || fu
22103
22107
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
22104
22108
  return cooked;
22105
22109
  };
22106
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
22107
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22108
- return new (P || (P = Promise))(function (resolve, reject) {
22109
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22110
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22111
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22112
- step((generator = generator.apply(thisArg, _arguments || [])).next());
22113
- });
22114
- };
22115
- var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
22116
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
22117
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
22118
- function verb(n) { return function (v) { return step([n, v]); }; }
22119
- function step(op) {
22120
- if (f) throw new TypeError("Generator is already executing.");
22121
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
22122
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
22123
- if (y = 0, t) op = [op[0] & 2, t.value];
22124
- switch (op[0]) {
22125
- case 0: case 1: t = op; break;
22126
- case 4: _.label++; return { value: op[1], done: false };
22127
- case 5: _.label++; y = op[1]; op = [0]; continue;
22128
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
22129
- default:
22130
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
22131
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
22132
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
22133
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
22134
- if (t[2]) _.ops.pop();
22135
- _.trys.pop(); continue;
22136
- }
22137
- op = body.call(thisArg, _);
22138
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
22139
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
22140
- }
22141
- };
22142
22110
  var ContainerSummary$1 = styled.div(templateObject_1$h || (templateObject_1$h = __makeTemplateObject$h(["\n display: flex;\n padding: 0 20px;\n width: 100%;\n justify-content: space-between;\n @media (max-width: 768px) {\n padding: 0px;\n }\n\n @media (max-width: 992px) {\n flex-direction: column;\n }\n"], ["\n display: flex;\n padding: 0 20px;\n width: 100%;\n justify-content: space-between;\n @media (max-width: 768px) {\n padding: 0px;\n }\n\n @media (max-width: 992px) {\n flex-direction: column;\n }\n"])));
22143
22111
  var ContentSummary = styled.div(templateObject_2$9 || (templateObject_2$9 = __makeTemplateObject$h(["\n display: grid;\n grid-row: 1 / 8;\n grid-template-columns: repeat(4, 1fr);\n gap: 0 16px;\n\n @media (max-width: 1280px) {\n grid-template-columns: repeat(3, 1fr);\n justify-content: center;\n align-items: center;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n width: 100%;\n }\n"], ["\n display: grid;\n grid-row: 1 / 8;\n grid-template-columns: repeat(4, 1fr);\n gap: 0 16px;\n\n @media (max-width: 1280px) {\n grid-template-columns: repeat(3, 1fr);\n justify-content: center;\n align-items: center;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n width: 100%;\n }\n"])));
22144
22112
  var FieldSummary = styled.div(templateObject_3$4 || (templateObject_3$4 = __makeTemplateObject$h(["\n align-items: center;\n margin-bottom: 16px;\n grid-column: ", ";\n"], ["\n align-items: center;\n margin-bottom: 16px;\n grid-column: ", ";\n"])), function (props) { return (props.fullRow ? '1 / 3' : 'auto'); });
@@ -22146,7 +22114,7 @@ var ButtonsSummary = styled.div(templateObject_4$3 || (templateObject_4$3 = __ma
22146
22114
  var ButtonsWrapper = styled.div(templateObject_5$2 || (templateObject_5$2 = __makeTemplateObject$h(["\n display: flex;\n gap: 10px;\n flex-direction: column;\n\n @media (max-width: 1000px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(1, 1fr);\n flex-direction: row;\n }\n\n @media print {\n display: none;\n }\n"], ["\n display: flex;\n gap: 10px;\n flex-direction: column;\n\n @media (max-width: 1000px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(1, 1fr);\n flex-direction: row;\n }\n\n @media print {\n display: none;\n }\n"])));
22147
22115
  var SummaryButton = styled(Button$1)(templateObject_6$2 || (templateObject_6$2 = __makeTemplateObject$h(["\n height: 100%;\n"], ["\n height: 100%;\n"])));
22148
22116
  var Summary = function (_a) {
22149
- var finderResponse = _a.finderResponse, rfbResponse = _a.rfbResponse, document = _a.document;
22117
+ var finderResponse = _a.finderResponse, rfbResponse = _a.rfbResponse, onClickPrint = _a.onClickPrint;
22150
22118
  var _b = useCardsAndProducts({
22151
22119
  finderResponse: finderResponse,
22152
22120
  rfbResponse: rfbResponse
@@ -22158,25 +22126,12 @@ var Summary = function (_a) {
22158
22126
  React.createElement(ButtonsWrapper, null,
22159
22127
  products.map(function (product, index) { return (React.createElement(ButtonsSummary, { key: index, style: { display: (product === null || product === void 0 ? void 0 : product.hide) ? 'none' : '', width: '100%' } },
22160
22128
  React.createElement(SummaryButton, { onClick: function () { return (product === null || product === void 0 ? void 0 : product.onClick) && (product === null || product === void 0 ? void 0 : product.onClick()); }, smallContent: product.price ? formatMoney(product.price) : undefined }, product.title))); }),
22161
- React.createElement(PrintButton, { document: document })))));
22129
+ React.createElement(PrintButton, { onClickPrint: onClickPrint })))));
22162
22130
  };
22163
22131
  var PrintButton = function (_a) {
22164
- var document = _a.document;
22165
- var client = React.useContext(WebService);
22166
- var url = React.useMemo(function () {
22167
- var url = new URL('https://pdfnode.credithub.com.br/relatorio/analitico/pdf');
22168
- url.searchParams.append('apiKey', client.apiKey);
22169
- url.searchParams.append('documento', document.replace(/\D/g, ''));
22170
- return url;
22171
- }, [document, client.apiKey]);
22172
- var onClick = React.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
22173
- return __generator(this, function (_a) {
22174
- window.open(url.toString(), '_blank');
22175
- return [2 /*return*/];
22176
- });
22177
- }); }, [url]);
22132
+ var onClickPrint = _a.onClickPrint;
22178
22133
  return (React.createElement(ButtonsSummary, null,
22179
- React.createElement(SummaryButton, { onClick: onClick }, "PDF para Impress\u00E3o")));
22134
+ React.createElement(SummaryButton, { onClick: onClickPrint }, "PDF para Impress\u00E3o")));
22180
22135
  };
22181
22136
  var templateObject_1$h, templateObject_2$9, templateObject_3$4, templateObject_4$3, templateObject_5$2, templateObject_6$2;
22182
22137
 
@@ -28263,7 +28218,7 @@ var __makeTemplateObject$c = (undefined && undefined.__makeTemplateObject) || fu
28263
28218
  var DossieContent = styled.div(templateObject_1$c || (templateObject_1$c = __makeTemplateObject$c(["\n display: grid;\n grid-template-columns: 1fr 2fr;\n justify-items: center;\n align-items: flex-start;\n margin-bottom: 20px;\n gap: 20px;\n\n @media (max-width: 992px) {\n grid-template-columns: 1fr;\n }\n"], ["\n display: grid;\n grid-template-columns: 1fr 2fr;\n justify-items: center;\n align-items: flex-start;\n margin-bottom: 20px;\n gap: 20px;\n\n @media (max-width: 992px) {\n grid-template-columns: 1fr;\n }\n"])));
28264
28219
  var DossieContainer = styled.div(templateObject_2$5 || (templateObject_2$5 = __makeTemplateObject$c(["\n padding: 0px 70px;\n\n @media (max-width: 1000px) {\n padding: 0px 30px;\n }\n"], ["\n padding: 0px 70px;\n\n @media (max-width: 1000px) {\n padding: 0px 30px;\n }\n"])));
28265
28220
  var Dossie = function (_a) {
28266
- var documento = _a.documento;
28221
+ var documento = _a.documento, onClickPrint = _a.onClickPrint;
28267
28222
  var finderCtx = React.useContext(Queries.Finder);
28268
28223
  var rfbResponse = useConsultaRfb().rfbResponse;
28269
28224
  var Section = finderCtx.Section;
@@ -28281,7 +28236,7 @@ var Dossie = function (_a) {
28281
28236
  return (React.createElement(DossieContainer, null,
28282
28237
  React.createElement(DossieContent, null,
28283
28238
  React.createElement(DossieCarrousel, null),
28284
- React.createElement(Summary, { finderResponse: data, rfbResponse: rfbResponse, document: document })),
28239
+ React.createElement(Summary, { onClickPrint: onClickPrint, finderResponse: data, rfbResponse: rfbResponse, document: document })),
28285
28240
  React.createElement(TransactionsTable, { events: XPathUtils.select('//historico/consulta', data) || [] })));
28286
28241
  };
28287
28242
  return (React.createElement(Section, { ctx: finderCtx, hideHeader: true, minimized: false, isError: function (e) { return response(e); }, onSuccess: response }));
@@ -64746,29 +64701,54 @@ var processData = function (data, quantidadeProcessosJuridicos) {
64746
64701
  .filter(function (info) { return info.data; });
64747
64702
  return __assign$6(__assign$6({}, data), { protestos: data.protestos, ccfs: data.ccfs, boaVista: data.boaVista, serasa: data.serasa, dividasPublicasGrafico: data.dividasPublicasGrafico, pieChartTotalConfig: __assign$6(__assign$6({}, data.pieChartTotalConfig), { processosJuridicos: quantidadeProcessosJuridicos }) });
64748
64703
  };
64704
+ var obterUltimaData = function (protestos) {
64705
+ if (!protestos.length)
64706
+ return null;
64707
+ var datas = protestos
64708
+ .map(function (p) { return new Date(converterParaFormatoValido(p.dataProtesto)).getTime(); })
64709
+ .filter(function (d) { return !isNaN(d); });
64710
+ return datas.length
64711
+ ? new Date(Math.max.apply(Math, datas)).toLocaleDateString()
64712
+ : null;
64713
+ };
64749
64714
  function processProtestData(document) {
64750
- var _a, _b;
64751
64715
  var filterProtestos = function (regex, data) {
64752
- return XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
64716
+ return XPathUtils.selectArray('//body//protesto', data)
64717
+ .filter(function (protesto) {
64753
64718
  return regex.test(XPathUtils.select('string(./nomeCedente)', protesto));
64754
- });
64719
+ })
64720
+ .map(function (protesto) { return ({
64721
+ dataProtesto: XPathUtils.select('string(./dataProtesto)', protesto),
64722
+ valor: parseFloat(XPathUtils.select('string(./valor)', protesto))
64723
+ }); });
64755
64724
  };
64725
+ var protestosDeCredito = filterProtestos(REGEX_PROTESTOS_DE_CREDITO, document);
64726
+ var protestosDeImpostos = filterProtestos(REGEX_PROTESTOS_DE_IMPOSTO, document);
64727
+ var protestosGerais = XPathUtils.selectArray('//body//protesto', document)
64728
+ .filter(function (protesto) {
64729
+ var nomeCedente = XPathUtils.select('string(./nomeCedente)', protesto);
64730
+ return (!REGEX_PROTESTOS_DE_IMPOSTO.test(nomeCedente) &&
64731
+ !REGEX_PROTESTOS_DE_CREDITO.test(nomeCedente));
64732
+ })
64733
+ .map(function (protesto) { return ({
64734
+ dataProtesto: XPathUtils.select('string(./dataProtesto)', protesto),
64735
+ valor: parseFloat(XPathUtils.select('string(./valor)', protesto))
64736
+ }); });
64756
64737
  return [
64757
64738
  {
64758
64739
  categoria: 'Protestos de Crédito',
64759
- quantidade: (_a = filterProtestos(REGEX_PROTESTOS_DE_CREDITO, document)) === null || _a === void 0 ? void 0 : _a.length
64740
+ quantidade: protestosDeCredito.length,
64741
+ ultimaOcorrencia: obterUltimaData(protestosDeCredito)
64760
64742
  },
64761
64743
  {
64762
64744
  categoria: 'Protestos de Impostos',
64763
- quantidade: (_b = filterProtestos(REGEX_PROTESTOS_DE_IMPOSTO, document)) === null || _b === void 0 ? void 0 : _b.length
64745
+ quantidade: protestosDeImpostos.length,
64746
+ ultimaOcorrencia: obterUltimaData(protestosDeImpostos)
64764
64747
  },
64765
64748
  {
64766
64749
  categoria: 'Protestos Gerais',
64767
- quantidade: XPathUtils.selectArray('//body//protesto', document).filter(function (protesto) {
64768
- var nomeCedente = XPathUtils.select('string(./nomeCedente)', protesto);
64769
- return (!REGEX_PROTESTOS_DE_IMPOSTO.test(nomeCedente) &&
64770
- !REGEX_PROTESTOS_DE_CREDITO.test(nomeCedente));
64771
- }).length
64750
+ quantidade: protestosGerais.length,
64751
+ ultimaOcorrencia: obterUltimaData(protestosGerais)
64772
64752
  }
64773
64753
  ];
64774
64754
  }
@@ -64863,8 +64843,17 @@ var ChartSystem = function (_a) {
64863
64843
  var _q = useCalculation((data === null || data === void 0 ? void 0 : data.boaVista) || []), quantidadeBoaVista = _q.quantidade, valorTotalBoaVista = _q.valorTotal;
64864
64844
  var quantidadeCCFs = useCalculation((data === null || data === void 0 ? void 0 : data.ccfs) || []).quantidade;
64865
64845
  var ultimaOcorrenciaProtestos = '';
64866
- if ((data === null || data === void 0 ? void 0 : data.protestos) && data.protestos.length > 0) {
64867
- ultimaOcorrenciaProtestos = new Date(data.protestos[data.protestos.length - 1].data).toLocaleDateString();
64846
+ if ((data === null || data === void 0 ? void 0 : data.protestosCategory) && data.protestosCategory.length > 0) {
64847
+ var datasOcorrencias = data.protestosCategory
64848
+ .map(function (categoria) { return categoria.ultimaOcorrencia; })
64849
+ .filter(Boolean)
64850
+ .map(function (data) {
64851
+ return new Date(converterParaFormatoValido(data)).getTime();
64852
+ })
64853
+ .filter(function (timestamp) { return !isNaN(timestamp); });
64854
+ if (datasOcorrencias.length > 0) {
64855
+ ultimaOcorrenciaProtestos = new Date(Math.max.apply(Math, datasOcorrencias)).toLocaleDateString();
64856
+ }
64868
64857
  }
64869
64858
  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;
64870
64859
  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;
@@ -65504,7 +65493,7 @@ var __makeTemplateObject = (undefined && undefined.__makeTemplateObject) || func
65504
65493
  Chart$1.register.apply(Chart$1, registerables);
65505
65494
  var Wrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-family: 'Open Sans Condensed';\n display: flex;\n flex-direction: column;\n gap: 20px;\n"], ["\n font-family: 'Open Sans Condensed';\n display: flex;\n flex-direction: column;\n gap: 20px;\n"])));
65506
65495
  var ConsultaSimples = function (_a) {
65507
- var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits;
65496
+ var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, onClickPrint = _a.onClickPrint, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits;
65508
65497
  var documento = _documento.replace(/\D+/g, '');
65509
65498
  return (React.createElement(React.Fragment, null,
65510
65499
  React.createElement(GlobalStyle, null),
@@ -65519,7 +65508,7 @@ var ConsultaSimples = function (_a) {
65519
65508
  React.createElement(Wrapper, null,
65520
65509
  React.createElement(ConsultaSimplesSection, { documento: documento, onClose: onClose },
65521
65510
  React.createElement(ConsultaRfbProvider, { documento: documento },
65522
- React.createElement(Dossie, { documento: documento }),
65511
+ React.createElement(Dossie, { onClickPrint: onClickPrint, documento: documento }),
65523
65512
  React.createElement(Liminar, null),
65524
65513
  React.createElement(Addresses, { apiKey: apiKey }),
65525
65514
  React.createElement(Contacts, null),
@@ -16,6 +16,7 @@ import ChevronDown from '../../assets/btn/chevronDown';
16
16
  import useChartData from './hooks/useChartData';
17
17
  import ResumoDeNegativacoesIcon from '../../assets/icones/resumoNegativacoes';
18
18
  import { ConsultasComplementaresContext } from '../consultasComplementares';
19
+ import { converterParaFormatoValido } from '../../utils/string';
19
20
  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'); });
20
21
  var ChartSystem = function (_a) {
21
22
  var _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -32,8 +33,17 @@ var ChartSystem = function (_a) {
32
33
  var _q = useCalculation((data === null || data === void 0 ? void 0 : data.boaVista) || []), quantidadeBoaVista = _q.quantidade, valorTotalBoaVista = _q.valorTotal;
33
34
  var quantidadeCCFs = useCalculation((data === null || data === void 0 ? void 0 : data.ccfs) || []).quantidade;
34
35
  var ultimaOcorrenciaProtestos = '';
35
- if ((data === null || data === void 0 ? void 0 : data.protestos) && data.protestos.length > 0) {
36
- ultimaOcorrenciaProtestos = new Date(data.protestos[data.protestos.length - 1].data).toLocaleDateString();
36
+ if ((data === null || data === void 0 ? void 0 : data.protestosCategory) && data.protestosCategory.length > 0) {
37
+ var datasOcorrencias = data.protestosCategory
38
+ .map(function (categoria) { return categoria.ultimaOcorrencia; })
39
+ .filter(Boolean)
40
+ .map(function (data) {
41
+ return new Date(converterParaFormatoValido(data)).getTime();
42
+ })
43
+ .filter(function (timestamp) { return !isNaN(timestamp); });
44
+ if (datasOcorrencias.length > 0) {
45
+ ultimaOcorrenciaProtestos = new Date(Math.max.apply(Math, datasOcorrencias)).toLocaleDateString();
46
+ }
37
47
  }
38
48
  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;
39
49
  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;
@@ -29,6 +29,7 @@ export interface DataInput {
29
29
  export interface ProtestoData {
30
30
  categoria: string;
31
31
  quantidade: number;
32
+ ultimaOcorrencia: string | null;
32
33
  }
33
34
  export interface DataSetCommon {
34
35
  label: string;
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { formatDatePtBrToDate } from '../../../utils/string';
12
+ import { converterParaFormatoValido, formatDatePtBrToDate } from '../../../utils/string';
13
13
  import { groupBy, sortBy, unique } from 'underscore';
14
14
  import XPathUtils from '../../../utils/xpath';
15
15
  import { REGEX_PROTESTOS_DE_CREDITO, REGEX_PROTESTOS_DE_IMPOSTO } from '../../../constants/regex';
@@ -58,29 +58,54 @@ export var processData = function (data, quantidadeProcessosJuridicos) {
58
58
  .filter(function (info) { return info.data; });
59
59
  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 }) });
60
60
  };
61
+ var obterUltimaData = function (protestos) {
62
+ if (!protestos.length)
63
+ return null;
64
+ var datas = protestos
65
+ .map(function (p) { return new Date(converterParaFormatoValido(p.dataProtesto)).getTime(); })
66
+ .filter(function (d) { return !isNaN(d); });
67
+ return datas.length
68
+ ? new Date(Math.max.apply(Math, datas)).toLocaleDateString()
69
+ : null;
70
+ };
61
71
  export function processProtestData(document) {
62
- var _a, _b;
63
72
  var filterProtestos = function (regex, data) {
64
- return XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
73
+ return XPathUtils.selectArray('//body//protesto', data)
74
+ .filter(function (protesto) {
65
75
  return regex.test(XPathUtils.select('string(./nomeCedente)', protesto));
66
- });
76
+ })
77
+ .map(function (protesto) { return ({
78
+ dataProtesto: XPathUtils.select('string(./dataProtesto)', protesto),
79
+ valor: parseFloat(XPathUtils.select('string(./valor)', protesto))
80
+ }); });
67
81
  };
82
+ var protestosDeCredito = filterProtestos(REGEX_PROTESTOS_DE_CREDITO, document);
83
+ var protestosDeImpostos = filterProtestos(REGEX_PROTESTOS_DE_IMPOSTO, document);
84
+ var protestosGerais = XPathUtils.selectArray('//body//protesto', document)
85
+ .filter(function (protesto) {
86
+ var nomeCedente = XPathUtils.select('string(./nomeCedente)', protesto);
87
+ return (!REGEX_PROTESTOS_DE_IMPOSTO.test(nomeCedente) &&
88
+ !REGEX_PROTESTOS_DE_CREDITO.test(nomeCedente));
89
+ })
90
+ .map(function (protesto) { return ({
91
+ dataProtesto: XPathUtils.select('string(./dataProtesto)', protesto),
92
+ valor: parseFloat(XPathUtils.select('string(./valor)', protesto))
93
+ }); });
68
94
  return [
69
95
  {
70
96
  categoria: 'Protestos de Crédito',
71
- quantidade: (_a = filterProtestos(REGEX_PROTESTOS_DE_CREDITO, document)) === null || _a === void 0 ? void 0 : _a.length
97
+ quantidade: protestosDeCredito.length,
98
+ ultimaOcorrencia: obterUltimaData(protestosDeCredito)
72
99
  },
73
100
  {
74
101
  categoria: 'Protestos de Impostos',
75
- quantidade: (_b = filterProtestos(REGEX_PROTESTOS_DE_IMPOSTO, document)) === null || _b === void 0 ? void 0 : _b.length
102
+ quantidade: protestosDeImpostos.length,
103
+ ultimaOcorrencia: obterUltimaData(protestosDeImpostos)
76
104
  },
77
105
  {
78
106
  categoria: 'Protestos Gerais',
79
- quantidade: XPathUtils.selectArray('//body//protesto', document).filter(function (protesto) {
80
- var nomeCedente = XPathUtils.select('string(./nomeCedente)', protesto);
81
- return (!REGEX_PROTESTOS_DE_IMPOSTO.test(nomeCedente) &&
82
- !REGEX_PROTESTOS_DE_CREDITO.test(nomeCedente));
83
- }).length
107
+ quantidade: protestosGerais.length,
108
+ ultimaOcorrencia: obterUltimaData(protestosGerais)
84
109
  }
85
110
  ];
86
111
  }
@@ -3,6 +3,7 @@ interface DossieProps {
3
3
  documento: string;
4
4
  rfbResponse?: Document;
5
5
  onOpenNewTransactionModal?: () => void;
6
+ onClickPrint: () => void;
6
7
  }
7
8
  declare const Dossie: React.FC<DossieProps>;
8
9
  export default Dossie;
@@ -17,7 +17,7 @@ import { useConsultaRfb } from '../../hooks/useConsultaRfb';
17
17
  var DossieContent = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: grid;\n grid-template-columns: 1fr 2fr;\n justify-items: center;\n align-items: flex-start;\n margin-bottom: 20px;\n gap: 20px;\n\n @media (max-width: 992px) {\n grid-template-columns: 1fr;\n }\n"], ["\n display: grid;\n grid-template-columns: 1fr 2fr;\n justify-items: center;\n align-items: flex-start;\n margin-bottom: 20px;\n gap: 20px;\n\n @media (max-width: 992px) {\n grid-template-columns: 1fr;\n }\n"])));
18
18
  var DossieContainer = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n padding: 0px 70px;\n\n @media (max-width: 1000px) {\n padding: 0px 30px;\n }\n"], ["\n padding: 0px 70px;\n\n @media (max-width: 1000px) {\n padding: 0px 30px;\n }\n"])));
19
19
  var Dossie = function (_a) {
20
- var documento = _a.documento;
20
+ var documento = _a.documento, onClickPrint = _a.onClickPrint;
21
21
  var finderCtx = useContext(Queries.Finder);
22
22
  var rfbResponse = useConsultaRfb().rfbResponse;
23
23
  var Section = finderCtx.Section;
@@ -35,7 +35,7 @@ var Dossie = function (_a) {
35
35
  return (React.createElement(DossieContainer, null,
36
36
  React.createElement(DossieContent, null,
37
37
  React.createElement(DossieCarrousel, null),
38
- React.createElement(Summary, { finderResponse: data, rfbResponse: rfbResponse, document: document })),
38
+ React.createElement(Summary, { onClickPrint: onClickPrint, finderResponse: data, rfbResponse: rfbResponse, document: document })),
39
39
  React.createElement(TransactionsTable, { events: XPathUtils.select('//historico/consulta', data) || [] })));
40
40
  };
41
41
  return (React.createElement(Section, { ctx: finderCtx, hideHeader: true, minimized: false, isError: function (e) { return response(e); }, onSuccess: response }));
@@ -14,6 +14,7 @@ interface SummaryProps {
14
14
  finderResponse?: Document;
15
15
  rfbResponse?: Document;
16
16
  document: string;
17
+ onClickPrint: () => void;
17
18
  }
18
19
  export declare const Summary: React.FC<SummaryProps>;
19
20
  export default Summary;
@@ -2,49 +2,12 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
2
2
  if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
3
  return cooked;
4
4
  };
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- var __generator = (this && this.__generator) || function (thisArg, body) {
15
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
16
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
17
- function verb(n) { return function (v) { return step([n, v]); }; }
18
- function step(op) {
19
- if (f) throw new TypeError("Generator is already executing.");
20
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
21
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
22
- if (y = 0, t) op = [op[0] & 2, t.value];
23
- switch (op[0]) {
24
- case 0: case 1: t = op; break;
25
- case 4: _.label++; return { value: op[1], done: false };
26
- case 5: _.label++; y = op[1]; op = [0]; continue;
27
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
28
- default:
29
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
30
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
31
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
32
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
33
- if (t[2]) _.ops.pop();
34
- _.trys.pop(); continue;
35
- }
36
- op = body.call(thisArg, _);
37
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
38
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
39
- }
40
- };
41
- import React, { useCallback, useContext, useMemo } from 'react';
5
+ import React from 'react';
42
6
  import AddItemField from '../../../components/common/addItem';
43
7
  import Button from '../../../components/common/button';
44
8
  import { formatMoney } from '../../../utils/number';
45
9
  import useCardsAndProducts from './cardsAndProducts';
46
10
  import styled from 'styled-components';
47
- import { WebService } from '../../../components/webservice';
48
11
  var ContainerSummary = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n padding: 0 20px;\n width: 100%;\n justify-content: space-between;\n @media (max-width: 768px) {\n padding: 0px;\n }\n\n @media (max-width: 992px) {\n flex-direction: column;\n }\n"], ["\n display: flex;\n padding: 0 20px;\n width: 100%;\n justify-content: space-between;\n @media (max-width: 768px) {\n padding: 0px;\n }\n\n @media (max-width: 992px) {\n flex-direction: column;\n }\n"])));
49
12
  var ContentSummary = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: grid;\n grid-row: 1 / 8;\n grid-template-columns: repeat(4, 1fr);\n gap: 0 16px;\n\n @media (max-width: 1280px) {\n grid-template-columns: repeat(3, 1fr);\n justify-content: center;\n align-items: center;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n width: 100%;\n }\n"], ["\n display: grid;\n grid-row: 1 / 8;\n grid-template-columns: repeat(4, 1fr);\n gap: 0 16px;\n\n @media (max-width: 1280px) {\n grid-template-columns: repeat(3, 1fr);\n justify-content: center;\n align-items: center;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n width: 100%;\n }\n"])));
50
13
  var FieldSummary = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n align-items: center;\n margin-bottom: 16px;\n grid-column: ", ";\n"], ["\n align-items: center;\n margin-bottom: 16px;\n grid-column: ", ";\n"])), function (props) { return (props.fullRow ? '1 / 3' : 'auto'); });
@@ -52,7 +15,7 @@ var ButtonsSummary = styled.div(templateObject_4 || (templateObject_4 = __makeTe
52
15
  var ButtonsWrapper = styled.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n gap: 10px;\n flex-direction: column;\n\n @media (max-width: 1000px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(1, 1fr);\n flex-direction: row;\n }\n\n @media print {\n display: none;\n }\n"], ["\n display: flex;\n gap: 10px;\n flex-direction: column;\n\n @media (max-width: 1000px) {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n flex-direction: row;\n }\n\n @media (max-width: 768px) {\n display: grid;\n grid-template-columns: repeat(1, 1fr);\n flex-direction: row;\n }\n\n @media print {\n display: none;\n }\n"])));
53
16
  var SummaryButton = styled(Button)(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n height: 100%;\n"], ["\n height: 100%;\n"])));
54
17
  export var Summary = function (_a) {
55
- var finderResponse = _a.finderResponse, rfbResponse = _a.rfbResponse, document = _a.document;
18
+ var finderResponse = _a.finderResponse, rfbResponse = _a.rfbResponse, onClickPrint = _a.onClickPrint;
56
19
  var _b = useCardsAndProducts({
57
20
  finderResponse: finderResponse,
58
21
  rfbResponse: rfbResponse
@@ -64,25 +27,12 @@ export var Summary = function (_a) {
64
27
  React.createElement(ButtonsWrapper, null,
65
28
  products.map(function (product, index) { return (React.createElement(ButtonsSummary, { key: index, style: { display: (product === null || product === void 0 ? void 0 : product.hide) ? 'none' : '', width: '100%' } },
66
29
  React.createElement(SummaryButton, { onClick: function () { return (product === null || product === void 0 ? void 0 : product.onClick) && (product === null || product === void 0 ? void 0 : product.onClick()); }, smallContent: product.price ? formatMoney(product.price) : undefined }, product.title))); }),
67
- React.createElement(PrintButton, { document: document })))));
30
+ React.createElement(PrintButton, { onClickPrint: onClickPrint })))));
68
31
  };
69
32
  var PrintButton = function (_a) {
70
- var document = _a.document;
71
- var client = useContext(WebService);
72
- var url = useMemo(function () {
73
- var url = new URL('https://pdfnode.credithub.com.br/relatorio/analitico/pdf');
74
- url.searchParams.append('apiKey', client.apiKey);
75
- url.searchParams.append('documento', document.replace(/\D/g, ''));
76
- return url;
77
- }, [document, client.apiKey]);
78
- var onClick = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
79
- return __generator(this, function (_a) {
80
- window.open(url.toString(), '_blank');
81
- return [2 /*return*/];
82
- });
83
- }); }, [url]);
33
+ var onClickPrint = _a.onClickPrint;
84
34
  return (React.createElement(ButtonsSummary, null,
85
- React.createElement(SummaryButton, { onClick: onClick }, "PDF para Impress\u00E3o")));
35
+ React.createElement(SummaryButton, { onClick: onClickPrint }, "PDF para Impress\u00E3o")));
86
36
  };
87
37
  export default Summary;
88
38
  var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
@@ -6,6 +6,7 @@ type ConsultaSimplesProps = {
6
6
  apiKey: string;
7
7
  onClose?: () => void;
8
8
  hasCredits?: HasCreditsType;
9
+ onClickPrint: () => void;
9
10
  onClickConsultarProcessoJuridico?: (processoId: string) => void;
10
11
  };
11
12
  declare const ConsultaSimples: React.FC<ConsultaSimplesProps>;
@@ -18,7 +18,7 @@ import ConsultaSimplesSection from './components/consultaSimplesSection/consulta
18
18
  Chart.register.apply(Chart, registerables);
19
19
  var Wrapper = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n font-family: 'Open Sans Condensed';\n display: flex;\n flex-direction: column;\n gap: 20px;\n"], ["\n font-family: 'Open Sans Condensed';\n display: flex;\n flex-direction: column;\n gap: 20px;\n"])));
20
20
  var ConsultaSimples = function (_a) {
21
- var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits;
21
+ var _documento = _a.documento, onClickConsultarProcessoJuridico = _a.onClickConsultarProcessoJuridico, onClickQSA = _a.onClickQSA, onClickPrint = _a.onClickPrint, apiKey = _a.apiKey, onClose = _a.onClose, hasCredits = _a.hasCredits;
22
22
  var documento = _documento.replace(/\D+/g, '');
23
23
  return (React.createElement(React.Fragment, null,
24
24
  React.createElement(GlobalStyle, null),
@@ -33,7 +33,7 @@ var ConsultaSimples = function (_a) {
33
33
  React.createElement(Wrapper, null,
34
34
  React.createElement(ConsultaSimplesSection, { documento: documento, onClose: onClose },
35
35
  React.createElement(ConsultaRfbProvider, { documento: documento },
36
- React.createElement(Dossie, { documento: documento }),
36
+ React.createElement(Dossie, { onClickPrint: onClickPrint, documento: documento }),
37
37
  React.createElement(Liminar, null),
38
38
  React.createElement(Addresses, { apiKey: apiKey }),
39
39
  React.createElement(Contacts, null),
@@ -4,6 +4,7 @@ export declare function formatDocument(documento: string): string;
4
4
  export declare function isCpf(documento: string): boolean;
5
5
  export declare function isCnpj(documento: string): boolean;
6
6
  export declare const isDocumentoPF: (documento: string) => boolean;
7
+ export declare const converterParaFormatoValido: (data: string) => string;
7
8
  export declare function formatDatePtBrToDate(date: string): Date;
8
9
  export declare function capitalize(value: string): string | null;
9
10
  export declare function capitalizeFirstLetter(value: string): string | null;
@@ -29,6 +29,10 @@ export var isDocumentoPF = function (documento) {
29
29
  var cleanDocument = documento.replace(/\D/g, '');
30
30
  return cleanDocument.length === 11;
31
31
  };
32
+ export var converterParaFormatoValido = function (data) {
33
+ var _a = data.split('/'), dia = _a[0], mes = _a[1], ano = _a[2];
34
+ return "".concat(mes, "/").concat(dia, "/").concat(ano);
35
+ };
32
36
  export function formatDatePtBrToDate(date) {
33
37
  var _a, _b;
34
38
  return new Date((_b = (_a = date === null || date === void 0 ? void 0 : date.split('/')) === null || _a === void 0 ? void 0 : _a.reverse()) === null || _b === void 0 ? void 0 : _b.join('-'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credithub/harlan-components",
3
- "version": "1.19.5",
3
+ "version": "1.20.1",
4
4
  "description": "Provide a set of web components to be used in Harlan and other projects",
5
5
  "keywords": [
6
6
  "harlan",