From 231331a5bd5ac6e1b2aebb375d0f86e56609d6c6 Mon Sep 17 00:00:00 2001 From: Chika Date: Tue, 29 Sep 2020 17:31:42 +0300 Subject: [PATCH] effect: recalcWithRevision --- .../CalculationStore/Effects/lib/tools.js | 6 +-- .../CalculationStore/Effects/reaction.ts | 52 ++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/lib/tools.js b/src/client/stores/CalculationStore/Effects/lib/tools.js index 0e9ec4a..4952e5e 100644 --- a/src/client/stores/CalculationStore/Effects/lib/tools.js +++ b/src/client/stores/CalculationStore/Effects/lib/tools.js @@ -1,4 +1,4 @@ -export function calcSupplierPrice( +export function calcPrice( isocurrencycode, leaseObjectPrice, evo_currencychange, @@ -26,7 +26,7 @@ export const calculatePerc = calculationStore => ( ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); const evo_currencychangeValue = (evo_currencychange && evo_currencychange.evo_currencychange) || 0; - let price = calcSupplierPrice( + let price = calcPrice( supplierCurrency?.isocurrencycode, parseFloat(leaseObjectPrice), evo_currencychangeValue, @@ -50,7 +50,7 @@ export const calculateRub = calculationStore => ( ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); const evo_currencychangeValue = (evo_currencychange && evo_currencychange.evo_currencychange) || 0; - let price = calcSupplierPrice( + let price = calcPrice( supplierCurrency?.isocurrencycode, parseFloat(leaseObjectPrice), evo_currencychangeValue, diff --git a/src/client/stores/CalculationStore/Effects/reaction.ts b/src/client/stores/CalculationStore/Effects/reaction.ts index 46e2275..986c09d 100644 --- a/src/client/stores/CalculationStore/Effects/reaction.ts +++ b/src/client/stores/CalculationStore/Effects/reaction.ts @@ -2,7 +2,7 @@ import { openNotification } from 'client/Elements/Notification'; import CalculationService from 'client/services/CalculationService'; import { IReactionEffect } from 'core/types/effect'; import { Status } from 'core/types/statuses'; -import { calculatePerc, calculateRub } from './lib/tools'; +import { calcPrice, calculatePerc, calculateRub } from './lib/tools'; const reactionEffects: IReactionEffect[] = [ calculationStore => ({ @@ -1725,6 +1725,56 @@ const reactionEffects: IReactionEffect[] = [ ); }, }), + + calculationStore => ({ + expression: () => { + const { + recalcWithRevision, + supplierCurrency, + supplierDiscountRub, + supplierDiscountPerc, + leaseObjectPrice, + } = calculationStore.values; + return [ + recalcWithRevision, + supplierCurrency, + supplierDiscountRub, + supplierDiscountPerc, + leaseObjectPrice, + ]; + }, + effect: ([ + recalcWithRevision, + supplierCurrencyId, + supplierDiscountRub, + supplierDiscountPerc, + leaseObjectPrice, + ]) => { + if (recalcWithRevision === true) { + return; + } + const supplierCurrency = calculationStore + .getOptions('selectSupplierCurrency') + .find(x => x.transactioncurrencyid === supplierCurrencyId); + const evo_currencychange = calculationStore + .getStaticData('evo_currencychange') + ?.find(x => x.evo_ref_transactioncurrency === supplierCurrencyId); + const evo_currencychangeValue = + (evo_currencychange && evo_currencychange.evo_currencychange) || 0; + let price = calcPrice( + supplierCurrency?.isocurrencycode, + leaseObjectPrice, + evo_currencychangeValue, + ); + + let maxPriceChange = + price - supplierDiscountRub < 800000 + ? price - supplierDiscountRub + 50000 + : (price - supplierDiscountRub) * 1.05; + + calculationStore.setValue('maxPriceChange', maxPriceChange); + }, + }), ]; export default reactionEffects;