From 14134e0dd9f1ad90d1b57a0bc7ed2026ec3e3105 Mon Sep 17 00:00:00 2001 From: Chika Date: Tue, 15 Dec 2020 12:49:38 +0300 Subject: [PATCH] selectTechnicalCard reactions --- .../Calculation/Sections/sectionsList.ts | 2 +- .../lib/fetchData/queries/optionsQuery.ts | 3 + .../Effects/reactions/otherReactions.ts | 77 ++++++++++++++++++- .../config/initialStatuses.ts | 1 - 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index f5d0de1..3b2c3fe 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -308,11 +308,11 @@ const sections: ISection[] = [ { elements: [ 'selectRegistration', + 'selectTechnicalCard', 'selectInsNSIB', 'radioRequirementTelematic', 'selectTracker', // 'selectTelematic', - // 'selectTechnicalCard', ], }, ], diff --git a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts index 7444222..55fb0ff 100644 --- a/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts +++ b/src/client/Containers/Calculation/lib/fetchData/queries/optionsQuery.ts @@ -195,6 +195,9 @@ const query = gql` evo_min_period evo_controls_program evo_helpcard_type + evo_leasingobject_types { + evo_leasingobject_typeid + } } selectTarif: evo_tarifs( statecode: $statecode diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index c6eaaf1..a02ee51 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -3,6 +3,7 @@ import { IReactionEffect } from 'core/types/Calculation/Store/effect'; import { Process } from 'core/types/Calculation/Store/process'; import { ElementStatus } from 'core/types/statuses'; import { calcPrice, calculatePerc, calculateRub } from '../lib/tools'; +import { round } from 'lodash'; const reactionEffects: IReactionEffect[] = [ // calculationStore => ({ @@ -1095,7 +1096,7 @@ const reactionEffects: IReactionEffect[] = [ ) { const max_sale_bonus = evo_coefficient_bonus.evo_sot_coefficient * 100; - if (parseFloat(saleBonus) > max_sale_bonus) { + if (parseFloat(saleBonus) > round(max_sale_bonus, 2)) { calculationStore.setValidation('tbxSaleBonus', false); openNotification({ type: 'error', @@ -1768,6 +1769,80 @@ const reactionEffects: IReactionEffect[] = [ } }, }), + + calculationStore => ({ + expression: () => { + const { leasingPeriod, leaseObjectType } = calculationStore.values; + return { leasingPeriod, leaseObjectType }; + }, + effect: ({ leasingPeriod, leaseObjectType }) => { + calculationStore.setFilter('selectTechnicalCard', options => + options.filter( + x => + x && + x.evo_max_period && + x.evo_min_period && + x.evo_max_period >= leasingPeriod && + x.evo_min_period <= leasingPeriod && + x.evo_leasingobject_types?.find( + x => x.evo_leasingobject_typeid === leaseObjectType, + ), + ), + ); + }, + options: { + fireImmediately: true, + }, + }), + + calculationStore => ({ + expression: () => { + const { leaseObjectType } = calculationStore.values; + return { leaseObjectType }; + }, + effect: () => { + calculationStore.setValue('technicalCard', null); + }, + }), + + calculationStore => ({ + expression: () => { + const { leasingPeriod } = calculationStore.values; + return leasingPeriod; + }, + effect: () => { + const { technicalCard: technicalCardId } = calculationStore.values; + + const technicalCard = calculationStore.options.selectTechnicalCard?.find( + x => x.evo_addproduct_typeid === technicalCardId, + ); + + if (technicalCard) { + const selectTechnicalCard_filter = calculationStore.getFilter( + 'selectTechnicalCard', + ); + + const selectTechnicalCard_options = calculationStore.getOptions( + 'selectTechnicalCard', + ); + + if (selectTechnicalCard_filter && selectTechnicalCard_options) { + const new_technicalCard = selectTechnicalCard_filter( + selectTechnicalCard_options, + ).find( + x => x && x.evo_helpcard_type === technicalCard.evo_helpcard_type, + ); + + if (new_technicalCard) { + calculationStore.setValue( + 'technicalCard', + new_technicalCard.evo_addproduct_typeid, + ); + } + } + } + }, + }), ]; export default reactionEffects; diff --git a/src/client/stores/CalculationStore/config/initialStatuses.ts b/src/client/stores/CalculationStore/config/initialStatuses.ts index e07d771..89bc610 100644 --- a/src/client/stores/CalculationStore/config/initialStatuses.ts +++ b/src/client/stores/CalculationStore/config/initialStatuses.ts @@ -10,7 +10,6 @@ const initialStatuses: TElements = { tbxInsKaskoPriceLeasePeriod: ElementStatus.Disabled, selectClientType: ElementStatus.Disabled, selectTelematic: ElementStatus.Disabled, - selectTechnicalCard: ElementStatus.Disabled, tbxImporterRewardRub: ElementStatus.Disabled, tbxImporterRewardPerc: ElementStatus.Disabled, tbxMaxPriceChange: ElementStatus.Disabled,