From 901211b061684a47ea10adff87d5be703f335655 Mon Sep 17 00:00:00 2001 From: Chika Date: Fri, 12 Feb 2021 17:27:55 +0300 Subject: [PATCH] merge release/calc-15_calc-by-total-expected --- .../Containers/Calculation/Info/infoList.ts | 7 +++++- .../Calculation/lib/elements/components.ts | 2 ++ .../Calculation/lib/elements/elementsProps.ts | 8 ++++++ .../Calculation/lib/elements/titles.ts | 2 ++ .../Calculation/lib/elements/values.ts | 2 ++ .../Effects/actions/calculate/index.js | 1 + .../Effects/actions/calculate/prepareData.ts | 4 +-- .../Effects/actions/calculate/results.ts | 12 ++++++++- .../Effects/reactions/loadKpReaction/index.ts | 13 +++++++--- .../reactions/loadKpReaction/quoteQuery.js | 1 + .../Effects/reactions/otherReactions.ts | 25 +++++++++++++++++++ .../CalculationStore/config/initialOptions.ts | 10 ++++++++ .../CalculationStore/config/initialValues.ts | 2 ++ src/core/types/Calculation/Store/elements.ts | 4 ++- src/core/types/Calculation/Store/values.ts | 4 ++- src/core/types/Entities/crmEntities.ts | 1 + 16 files changed, 88 insertions(+), 10 deletions(-) diff --git a/src/client/Containers/Calculation/Info/infoList.ts b/src/client/Containers/Calculation/Info/infoList.ts index cb497a3..571b49d 100644 --- a/src/client/Containers/Calculation/Info/infoList.ts +++ b/src/client/Containers/Calculation/Info/infoList.ts @@ -21,7 +21,12 @@ export const controlsList: IGroup[] = [ title: 'Параметры расчета', blocks: [ { - elements: ['tbxIRR_Perc', 'labelIrrInfo'], + elements: [ + 'labelIrrInfo', + 'radioCalcType', + 'tbxIRR_Perc', + 'tbxTotalPayments', + ], }, ], }, diff --git a/src/client/Containers/Calculation/lib/elements/components.ts b/src/client/Containers/Calculation/lib/elements/components.ts index b35bfc9..a6f781b 100644 --- a/src/client/Containers/Calculation/lib/elements/components.ts +++ b/src/client/Containers/Calculation/lib/elements/components.ts @@ -159,6 +159,8 @@ const elementsComponents: TElements = { labelResultBonusDopProd: Label, linkDownloadKp: Download, tbxMileage: InputNumber, + radioCalcType: Radio, + tbxTotalPayments: InputNumber, }; const tablesComponents: StoreTables = { diff --git a/src/client/Containers/Calculation/lib/elements/elementsProps.ts b/src/client/Containers/Calculation/lib/elements/elementsProps.ts index 86478fe..b994f39 100644 --- a/src/client/Containers/Calculation/lib/elements/elementsProps.ts +++ b/src/client/Containers/Calculation/lib/elements/elementsProps.ts @@ -334,6 +334,14 @@ const elementsProps: TElements = { marginBottom: '8px', }, }, + radioCalcType: { + style: 'button', + }, + tbxTotalPayments: { + min: 0, + step: 1000, + precision: 2, + }, }; const resultElementsProps: TElements = [ diff --git a/src/client/Containers/Calculation/lib/elements/titles.ts b/src/client/Containers/Calculation/lib/elements/titles.ts index 12550ac..25d6643 100644 --- a/src/client/Containers/Calculation/lib/elements/titles.ts +++ b/src/client/Containers/Calculation/lib/elements/titles.ts @@ -123,6 +123,8 @@ const elementsTitles: TElements = { selectUserSession: 'Загрузить сессию пользователя', labelIrrInfo: 'Диапазон IRR (Номинал)', tbxMileage: 'Пробег, км', + radioCalcType: 'Расчет от', + tbxTotalPayments: 'Сумма платежей', }; const resultsTitles: TElements = { diff --git a/src/client/Containers/Calculation/lib/elements/values.ts b/src/client/Containers/Calculation/lib/elements/values.ts index 5680c76..2c8fb25 100644 --- a/src/client/Containers/Calculation/lib/elements/values.ts +++ b/src/client/Containers/Calculation/lib/elements/values.ts @@ -124,6 +124,8 @@ export const elementsValues: TElements = { selectTelematic: 'telematic', selectTracker: 'tracker', tbxMileage: 'mileage', + radioCalcType: 'calcType', + tbxTotalPayments: 'totalPayments', }; const resultElementsValues: TElements = { diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/index.js b/src/client/stores/CalculationStore/Effects/actions/calculate/index.js index 6addcd0..45458bc 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/index.js +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/index.js @@ -81,6 +81,7 @@ export default async () => { results.showResultsTable(preparedData, res); results.showResults(preparedData, res); + results.setResValues(res); return Object.assign(preparedData, res); }) diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts index a63b537..8d39d3e 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/prepareData.ts @@ -93,10 +93,10 @@ export default ({ }; preparedValues.calcDate = currentDate; - preparedValues.calcType = 100000000; + preparedValues.calcType = values.calcType; preparedValues.irrExpected = (values.IRR_Perc as number) / 100; preparedValues.npvniExpected = 0; - preparedValues.totalExpected = 0; + preparedValues.totalExpected = values.totalPayments; preparedValues.nmper = values.leasingPeriod; preparedValues.leasing0K = values.product === 'LEASING0' diff --git a/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts b/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts index 6e14e0f..0addc48 100644 --- a/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts +++ b/src/client/stores/CalculationStore/Effects/actions/calculate/results.ts @@ -39,7 +39,7 @@ export default { ); CalculationStore.setValue( 'resultPriceUpPr', - (res?.postValues?.priceUP_PR || 0) * 100, + (res?.postValues?.priceUP_Year_PR || 0) * 100, ); CalculationStore.setValue( 'resultIRRGraphPerc', @@ -124,4 +124,14 @@ export default { ), ); }, + setResValues: (res: IGetCalculationResponse) => { + CalculationStore.setValue( + 'IRR_Perc', + (res?.columns?.cashflowMsfoColumn?.nominal || 0) * 100, + ); + CalculationStore.setValue( + 'totalPayments', + res?.columns?.sumWithVatColumn?.values[0] || 0, + ); + }, }; diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts index c1e43cf..8f7f46e 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/index.ts @@ -54,6 +54,7 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ opportunity, recalcWithRevision, leaseObjectCount, + calcType, } = calculationStore.values; calculationStore.setStatus('selectQuote', ElementStatus.Disabled); @@ -203,11 +204,11 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ } } - const evo_planpayments = quote.evo_graphs.sort( + const evo_graph = quote.evo_graphs.sort( (a, b) => b.createdon - a.createdon, - )[0].evo_planpayments; - const payments = evo_planpayments - .slice(1, evo_planpayments.length - 1) + )[0]; + const payments = evo_graph.evo_planpayments + .slice(1, evo_graph.evo_planpayments.length - 1) .map((evo_planpayment, i) => ({ paymentRelation: { validation: undefined, @@ -285,6 +286,8 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ } } + const { evo_sumpay_withnds } = evo_graph; + calculationStore.setValues({ ...initialValues, ...newValues, @@ -299,6 +302,8 @@ const loadKpReaction: IReactionEffect = calculationStore => ({ clientRisk, regionRegistration, townRegistration, + calcType, + totalPayments: evo_sumpay_withnds, }); message.success({ diff --git a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js index 008934c..7eb1ff1 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js +++ b/src/client/stores/CalculationStore/Effects/reactions/loadKpReaction/quoteQuery.js @@ -20,6 +20,7 @@ export default gql` evo_insurance_period evo_graphs { createdon + evo_sumpay_withnds evo_planpayments { evo_payment_ratio } diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index f71a780..d06f43b 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -1667,6 +1667,31 @@ const reactionEffects: IReactionEffect[] = [ } }, }), + + calculationStore => ({ + expression: () => { + const { calcType } = calculationStore.values; + return calcType; + }, + effect: calcType => { + switch (calcType) { + default: + case 100000000: { + calculationStore.setStatus('tbxIRR_Perc', ElementStatus.Default); + calculationStore.setStatus('tbxTotalPayments', ElementStatus.Disabled); + break; + } + case 100000002: { + calculationStore.setStatus('tbxIRR_Perc', ElementStatus.Disabled); + calculationStore.setStatus('tbxTotalPayments', ElementStatus.Default); + break; + } + } + }, + options: { + fireImmediately: true, + }, + }), ]; export default reactionEffects; diff --git a/src/client/stores/CalculationStore/config/initialOptions.ts b/src/client/stores/CalculationStore/config/initialOptions.ts index a955f94..308320c 100644 --- a/src/client/stores/CalculationStore/config/initialOptions.ts +++ b/src/client/stores/CalculationStore/config/initialOptions.ts @@ -296,6 +296,16 @@ const initialOptions: TElements = { // value: 100000003, // }, ], + radioCalcType: [ + { + name: 'IRR', + value: 100000000, + }, + { + name: 'Суммы', + value: 100000002, + }, + ], }; export default initialOptions; diff --git a/src/client/stores/CalculationStore/config/initialValues.ts b/src/client/stores/CalculationStore/config/initialValues.ts index cea509e..40e351a 100644 --- a/src/client/stores/CalculationStore/config/initialValues.ts +++ b/src/client/stores/CalculationStore/config/initialValues.ts @@ -79,5 +79,7 @@ const initialValues: TValues = { disableChecks: false, insFranchise: 0, rate: 'BASE', + calcType: 100000000, + totalPayments: 0, }; export default initialValues; diff --git a/src/core/types/Calculation/Store/elements.ts b/src/core/types/Calculation/Store/elements.ts index 18cb872..bbd04e4 100644 --- a/src/core/types/Calculation/Store/elements.ts +++ b/src/core/types/Calculation/Store/elements.ts @@ -133,7 +133,9 @@ export type ElementsNames = | 'selectTelematic' | 'selectTracker' | 'labelIrrInfo' - | 'tbxMileage'; + | 'tbxMileage' + | 'radioCalcType' + | 'tbxTotalPayments'; export type LinkElementsNames = 'linkDownloadKp'; diff --git a/src/core/types/Calculation/Store/values.ts b/src/core/types/Calculation/Store/values.ts index 8f28bca..9f4cf7a 100644 --- a/src/core/types/Calculation/Store/values.ts +++ b/src/core/types/Calculation/Store/values.ts @@ -120,7 +120,9 @@ export type ValuesNames = | 'technicalCard' | 'telematic' | 'tracker' - | 'mileage'; + | 'mileage' + | 'calcType' + | 'totalPayments'; export type ComputedValuesNames = | 'leadName' diff --git a/src/core/types/Entities/crmEntities.ts b/src/core/types/Entities/crmEntities.ts index 7ef302f..b1511e9 100644 --- a/src/core/types/Entities/crmEntities.ts +++ b/src/core/types/Entities/crmEntities.ts @@ -88,6 +88,7 @@ export interface IQuote { interface IEvoGraph { createdon?: Date; + evo_sumpay_withnds?: number; evo_planpayment?: IEvoPlanPayment[]; }