UNPKG

@railzai/railz-visualizations

Version:
60 lines 1.89 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 { pick, isNil } from 'lodash-es'; import Translations from '../../config/translations/en.json'; import { RVReportTypesUrlMapping, } from '../../types'; import { RequestServiceInstance } from '../../services/request'; import { errorLog } from '../../services/logger'; const MONTHS = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', ]; /** * Percentage change calculation, 2 decimal places */ export const getPercentageChange = (value1, value2) => { if (isNil(value1) || isNil(value2) || value2 === 0) { return null; } return Math.round(((value1 - value2) / value2) * 10000) / 100; }; export 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 */ export 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; }; //# sourceMappingURL=tax-benchmarking.utils.js.map