UNPKG

@railzai/railz-visualizations

Version:
296 lines (290 loc) 17.2 kB
/*! * Accounting Data as a Service™ is the solution that makes sense of your business customers' financial data. * Built with Stencil * Copyright (c) FIS. */ import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client'; import { T as Translations } from './en.js'; import { r as isNil, p as pick, R as RequestServiceInstance, e as errorLog, g as getConfiguration, C as ConfigurationInstance, a as getFilter, b as getOptions, J as validateIndustryCodeAndRegionParams, K as isTaxBenchmarking, o as handleError, c as getTitleByReportType } from './chart.utils.js'; import { g as RVReportTypesUrlMapping } from './financial-ratios.js'; import { d as defineCustomElement$4 } from './error-image.js'; import { d as defineCustomElement$3 } from './loading.js'; import { d as defineCustomElement$2 } from './tooltip.js'; import { i as isEqual } from './isEqual.js'; import { i as isEmpty } from './isEmpty.js'; const MONTHS = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ]; /** * Percentage change calculation, 2 decimal places */ const getPercentageChange = (value1, value2) => { if (isNil(value1) || isNil(value2) || value2 === 0) { return null; } return Math.round(((value1 - value2) / value2) * 10000) / 100; }; const formatDate = (dateString) => { const date = new Date(dateString); const fullMonthName = MONTHS[date.getMonth()]; const formattedDate = `${fullMonthName} ${date.getDate()}, ${date.getFullYear()}`; return formattedDate; }; /** * Make API call to tax benchmarking report */ const getReportData = async ({ filter, }) => { let reportData; try { const allParameters = pick(Object.assign({}, filter), ['industryCode', 'region', 'connectionUuid']); if (isNil(allParameters === null || allParameters === void 0 ? void 0 : allParameters.region)) allParameters === null || allParameters === void 0 ? true : delete allParameters.region; reportData = await RequestServiceInstance.getReportData({ path: RVReportTypesUrlMapping[filter.reportType], filter: allParameters, }); } catch (error) { errorLog(Translations.RV_NOT_ABLE_TO_RETRIEVE_REPORT_DATA, error); reportData = { error }; } return reportData; }; const taxBenchmarkingCss = "@font-face{font-family:Inter;src:url(\"../assets/fonts/Inter-italic-var.woff2\");font-family:Inter;src:url(\"../assets/fonts/Inter-upright-var.woff2\")}body,div[class^=railz-],div[class*=\" railz-\"]{font-family:Inter, Roboto, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}.rv-container{display:flex;padding:16px;position:relative;border:1px solid #eee;border-radius:7px;flex-direction:column;justify-content:space-between;width:auto}.rv-container p{margin-block:0}.rv-container *{font-family:Inter, Roboto, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}.rv-header-container{display:flex;flex-direction:row;justify-content:space-between}.rv-tax-benchmarking-container{width:100%;height:100%}.rv-title{display:flex;color:#015b7e;font-size:18px;font-weight:600;margin:0;padding:0;text-align:left;flex-grow:1;line-height:1.235;align-items:baseline}.rv-chart-percentage{visibility:inherit;-webkit-font-smoothing:antialiased;margin:0;line-height:1.5;display:flex;flex-direction:row;font-size:14px;font-weight:500;padding-left:8px}.rv-chart-percentage .rv-positive{color:#006037}.rv-chart-percentage .rv-negative{color:#b30000}.rv-score-last-updated{align-self:center;text-align:center;font-size:12px;color:#757575;font-weight:500;line-height:28px}.rv-tax-benchmarking-group{margin-top:24px}.rv-tax-benchmarking-business-info{display:flex;justify-content:space-between;font-size:12px;font-weight:600;color:#424242}.table-container{overflow-x:auto;width:100%}.benchmarking-table{border-collapse:collapse;width:100%;margin-top:24px}th,td{padding:16px;text-align:left}.table-header{font-size:12px;font-weight:600;color:#424242}.header-with-tooltip{display:flex}tr{border-bottom:1px solid #ddd}select{border:none;background-color:transparent;font-size:1rem;font-family:inherit;cursor:pointer}option{background-color:white;font-size:1rem;font-family:inherit}option:checked{font-weight:bold}"; const renderPercentageChange = (percentage, options) => { var _a, _b, _c, _d; if (percentage < 0) { return (h("div", { class: "rv-negative", style: (_b = (_a = options === null || options === void 0 ? void 0 : options.chart) === null || _a === void 0 ? void 0 : _a.pie) === null || _b === void 0 ? void 0 : _b.negative }, "\u25BC ", Math.abs(percentage), "%")); } else { return (h("div", { class: "rv-positive", style: (_d = (_c = options === null || options === void 0 ? void 0 : options.chart) === null || _c === void 0 ? void 0 : _c.pie) === null || _d === void 0 ? void 0 : _d.positive }, isNil(percentage) || isNaN(percentage) || Math.abs(percentage) === Infinity ? ('-') : (h("div", null, "\u25B2 ", Math.abs(percentage), "%")))); } }; const TaxBenchmarking = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.loading = ''; this.updateTaxBenchmarkingParams = () => { this.selectedLineItem = this._taxBenchmarkingData && Object.keys(this._taxBenchmarkingData)[0]; this.selectedCategory = this._taxBenchmarkingData && Object.keys(this._taxBenchmarkingData[this.selectedLineItem])[0]; // set initial options and selected values this.lineItemOptions = Object.keys(this._taxBenchmarkingData); this.setCategoryOptions(); }; this.setCategoryOptions = () => { this.categoryOptions = Object.keys(this._taxBenchmarkingData[this.selectedLineItem]); this.selectedCategory = this.categoryOptions[0]; this.refreshTableData(); }; this.setSelectedLineItem = (event) => { var _a; this.selectedLineItem = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value; this.setCategoryOptions(); }; this.setSelectedCategory = (event) => { var _a; this.selectedCategory = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value; this.refreshTableData(); }; this.refreshTableData = () => { if (this.selectedLineItem !== null && this.selectedCategory !== null) { const businessValueItem = this._businessValuesData[this.selectedLineItem]; // set the keys and values for the table data as a row object // [['Assets', 1234.56], ['Equity', 2134.67].....] const tempDataArray = Object.entries(this._taxBenchmarkingData[this.selectedLineItem][this.selectedCategory]); const dataResp = tempDataArray.map((data) => { return { lineItemName: data[0], businessValue: businessValueItem[data[0]], benchmarkValue: data[1], differencePercent: getPercentageChange(businessValueItem[data[0]], data[1]), }; }); this.tableData = dataResp; } }; /** * Validates if configuration was passed correctly before setting filter * @param configuration - Config for authentication * @param filter - filter to decide chart type to show * @param options: Whitelabeling options * @param triggerRequest - indicate if api request should be made */ this.validateParams = async (configuration, filter, options, triggerRequest = true) => { this._configuration = getConfiguration(configuration); if (this._configuration) { ConfigurationInstance.configuration = this._configuration; try { this._filter = getFilter(filter); this._options = getOptions(options); if (validateIndustryCodeAndRegionParams(this._filter)) { if (isTaxBenchmarking(this._filter.reportType)) { if (triggerRequest) { await this.requestReportData(); } } else { this.errorStatusCode = 500; errorLog(Translations.RV_ERROR_INVALID_REPORT_TYPE); } } else { this.errorStatusCode = 204; } } catch (e) { this.errorStatusCode = 500; errorLog(e); } } else { this.errorStatusCode = 0; } }; this.propsUpdated = async (triggerRequest = true) => { await this.validateParams(this.configuration, this.filter, this.options, triggerRequest); }; /** * Request report data based on filter and configuration param * Formats retrieved data into Highcharts format using formatData */ this.requestReportData = async () => { this.errorStatusCode = undefined; this.loading = Translations.RV_LOADING_REPORT; try { const reportData = (await getReportData({ filter: this._filter, })); if (!isNil(reportData === null || reportData === void 0 ? void 0 : reportData.taxBenchmarkingData) && !isNil(reportData === null || reportData === void 0 ? void 0 : reportData.businessValues)) { this._data = reportData; this._taxBenchmarkingData = reportData === null || reportData === void 0 ? void 0 : reportData.taxBenchmarkingData; this._businessValuesData = reportData === null || reportData === void 0 ? void 0 : reportData.businessValues; this.updateTaxBenchmarkingParams(); } else { this.errorStatusCode = handleError(reportData); } } catch (error) { errorLog(Translations.RV_NOT_ABLE_TO_PARSE_REPORT_DATA, error); } finally { this.loading = ''; } }; } async watchConfiguration(newValue, oldValue) { if (newValue && oldValue && !isEqual(oldValue, newValue)) { await this.validateParams(newValue, this.filter, this.options); } } async watchFilter(newValue, oldValue) { if (newValue && oldValue && !isEqual(oldValue, newValue)) { await this.validateParams(this.configuration, newValue, this.options); } } async watchOptions(newValue, oldValue) { if (newValue && oldValue && !isEqual(oldValue, newValue)) { await this.validateParams(this.configuration, this.filter, newValue); } } componentWillLoad() { this.propsUpdated && this.propsUpdated(); } render() { var _a, _b, _c, _d; const TitleElement = () => { var _a, _b, _c, _d, _e; return (h("p", { class: "rv-title", style: (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.title) === null || _b === void 0 ? void 0 : _b.style }, ((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.title) || getTitleByReportType((_e = this._filter) === null || _e === void 0 ? void 0 : _e.reportType) || '', ' ')); }; const renderMain = () => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; if (isEmpty(this.loading) && this.errorStatusCode === undefined && isEmpty((_a = this._data) === null || _a === void 0 ? void 0 : _a.taxBenchmarkingData) && isEmpty((_b = this._data) === null || _b === void 0 ? void 0 : _b.businessValues)) { // if it's not loading and all are empty, show no data error this.errorStatusCode = 204; } if (this.errorStatusCode !== undefined) { return (h("railz-error-image", Object.assign({ statusCode: this.errorStatusCode || 500 }, (_c = this._options) === null || _c === void 0 ? void 0 : _c.errorIndicator))); } if (!isEmpty(this.loading)) { return h("railz-loading", Object.assign({ loadingText: this.loading }, (_d = this._options) === null || _d === void 0 ? void 0 : _d.loadingIndicator)); } return (h("div", { class: "rv-tax-benchmarking-container" }, h("div", { class: "rv-tax-benchmarking-group" }, h("div", { class: "rv-tax-benchmarking-business-info" }, h("div", null, "Current Business:", ' ', h("span", { style: { color: '#111111' } }, isEmpty(this.loading) && ((_f = (_e = this._data) === null || _e === void 0 ? void 0 : _e.meta) === null || _f === void 0 ? void 0 : _f.businessName))), h("div", null, "As of ", isEmpty(this.loading) && formatDate((_h = (_g = this._data) === null || _g === void 0 ? void 0 : _g.meta) === null || _h === void 0 ? void 0 : _h.endDate))), h("div", { class: "table-container" }, h("table", { class: "benchmarking-table", id: "benchmarking-table" }, h("thead", null, h("tr", null, h("th", null, h("div", { class: "table-header" }, "Line Item ", '-', h("select", { onChange: this.setSelectedLineItem }, this.lineItemOptions.map((lineItem) => (h("option", { selected: this.selectedLineItem === lineItem, value: lineItem }, lineItem)))))), h("th", null, h("div", { class: "header-with-tooltip table-header" }, "Business Value", ' ', h("railz-tooltip", { tooltipStyle: Object.assign(Object.assign({ position: 'bottom-center' }, (_j = this._options) === null || _j === void 0 ? void 0 : _j.tooltipIndicator), { style: Object.assign({ marginLeft: '6px' }, (_l = (_k = this._options) === null || _k === void 0 ? void 0 : _k.tooltipIndicator) === null || _l === void 0 ? void 0 : _l.style) }), tooltipText: ((_p = (_o = (_m = this._options) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o.tooltip) === null || _p === void 0 ? void 0 : _p.description) || Translations.RV_TOOLTIP_TAX_BENCHMARKING_BUSINESS_VALUE }))), h("th", null, h("div", { class: "header-with-tooltip table-header" }, "Benchmark Value", ' ', h("railz-tooltip", { tooltipStyle: Object.assign(Object.assign({ position: 'bottom-center' }, (_q = this._options) === null || _q === void 0 ? void 0 : _q.tooltipIndicator), { style: Object.assign({ marginLeft: '6px' }, (_s = (_r = this._options) === null || _r === void 0 ? void 0 : _r.tooltipIndicator) === null || _s === void 0 ? void 0 : _s.style) }), tooltipText: ((_v = (_u = (_t = this._options) === null || _t === void 0 ? void 0 : _t.content) === null || _u === void 0 ? void 0 : _u.tooltip) === null || _v === void 0 ? void 0 : _v.description) || Translations.RV_TOOLTIP_TAX_BENCHMARKING_BENCHMARK_VALUE }))), h("th", null, h("div", { class: "table-header" }, h("select", { onChange: this.setSelectedCategory }, this.categoryOptions.map((category) => (h("option", { selected: this.selectedCategory === category, value: category }, category)))))))), h("tbody", null, this.tableData.map((row) => (h("tr", null, h("td", null, row.lineItemName), h("td", null, row.businessValue || '-'), h("td", null, row.benchmarkValue), h("td", null, h("div", { class: "rv-chart-percentage" }, renderPercentageChange(row.differencePercent, {})))))))))))); }; return (h("div", { class: "rv-container", style: (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.container) === null || _b === void 0 ? void 0 : _b.style }, h("div", { class: "rv-header-container" }, ((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.visible) === false ? '' : h(TitleElement, null)), renderMain())); } static get watchers() { return { "configuration": ["watchConfiguration"], "filter": ["watchFilter"], "options": ["watchOptions"] }; } static get style() { return taxBenchmarkingCss; } }, [1, "railz-tax-benchmarking", { "configuration": [16], "filter": [16], "options": [16], "_options": [32], "loading": [32], "_configuration": [32], "_filter": [32], "_data": [32], "_taxBenchmarkingData": [32], "_businessValuesData": [32], "errorStatusCode": [32], "selectedLineItem": [32], "selectedCategory": [32], "lineItemOptions": [32], "categoryOptions": [32], "tableData": [32] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["railz-tax-benchmarking", "railz-error-image", "railz-loading", "railz-tooltip"]; components.forEach(tagName => { switch (tagName) { case "railz-tax-benchmarking": if (!customElements.get(tagName)) { customElements.define(tagName, TaxBenchmarking); } break; case "railz-error-image": if (!customElements.get(tagName)) { defineCustomElement$4(); } break; case "railz-loading": if (!customElements.get(tagName)) { defineCustomElement$3(); } break; case "railz-tooltip": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; } }); } const RailzTaxBenchmarking = TaxBenchmarking; const defineCustomElement = defineCustomElement$1; export { RailzTaxBenchmarking, defineCustomElement }; //# sourceMappingURL=railz-tax-benchmarking.js.map