UNPKG

@railzai/railz-visualizations

Version:
109 lines 4.09 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 { format, parseISO } from 'date-fns'; import Translations from '../../config/translations/en.json'; import { RVReportTypesUrlMapping, } from '../../types'; import { RequestServiceInstance } from '../../services/request'; import { errorLog } from '../../services/logger'; import { RAILZ_DATE_FORMAT } from '../../types/constants/date'; /** * 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; }; export const getBusinessValuationsParams = (data) => { var _a; let liquidation = null; let discountedCashflow = null; let multipleToRevenue = null; let firstChicago = null; let liquidationPercentageChange = null; let discountedCashflowPercentageChange = null; let multipleToRevenuePercentageChange = null; let firstChicagoPercentageChange = null; let latestEndDate = null; if (data === null || data === void 0 ? void 0 : data.reports) { const reports = data.reports; if (reports.length >= 1) { // get latest report data latestEndDate = reports[0].meta.updatedAt; liquidation = reports[0].data.liquidationValue; discountedCashflow = reports[0].data.discountedCashflowValue; multipleToRevenue = reports[0].data.multipleToRevenueValue; firstChicago = reports[0].data.firstChicagoValue; } if (reports.length >= 2) { // liquidation percentage change over two reports const liquidation2 = (_a = reports[reports.length - 1]) === null || _a === void 0 ? void 0 : _a.data.liquidationValue; liquidationPercentageChange = getPercentageChange(liquidation, liquidation2); // discountedCashflow percentage change over two reports const discountedCashflow2 = reports[reports.length - 1].data.discountedCashflowValue; discountedCashflowPercentageChange = getPercentageChange(discountedCashflow, discountedCashflow2); // multipleToRevenue percentage change over two reports const multipleToRevenue2 = reports[reports.length - 1].data.multipleToRevenueValue; multipleToRevenuePercentageChange = getPercentageChange(multipleToRevenue, multipleToRevenue2); // firstChicago percentage change over two reports const firstChicago2 = reports[reports.length - 1].data.firstChicagoValue; firstChicagoPercentageChange = getPercentageChange(firstChicago, firstChicago2); } } return { liquidation, discountedCashflow, multipleToRevenue, firstChicago, liquidationPercentageChange, discountedCashflowPercentageChange, multipleToRevenuePercentageChange, firstChicagoPercentageChange, latestEndDate, }; }; /** * Make API call to business valuations report */ export const getReportData = async ({ filter, }) => { let reportData; try { let startDate; let endDate; try { startDate = format(parseISO(filter.startDate), RAILZ_DATE_FORMAT); } catch (error) { errorLog(Translations.RV_ERROR_START_DATE); } try { endDate = format(parseISO(filter.endDate), RAILZ_DATE_FORMAT); } catch (error) { errorLog(Translations.RV_ERROR_END_DATE); } const allParameters = pick(Object.assign(Object.assign({}, filter), { startDate, endDate }), [ 'startDate', 'endDate', 'connectionUuid', ]); allParameters.offset = 0; allParameters.limit = 100; allParameters.orderBy = '-endDate'; 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=business-valuations.utils.js.map