From 0fb0abde5d075060b2d5aed1ab372bc2065aeb74 Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 16 Dec 2020 19:58:52 +0300 Subject: [PATCH] fix check price when non rub currency --- .../Effects/reactions/priceReactions/index.ts | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts index 7993db6..8c0e201 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts @@ -1,6 +1,7 @@ import { openNotification } from 'client/Elements/Notification'; import { IReactionEffect } from 'core/types/Calculation/Store/effect'; import { Process } from 'core/types/Calculation/Store/process'; +import { convertPrice } from '../../lib/tools'; import { calculatePerc, calculateRub } from './calculate'; export default [ @@ -239,11 +240,23 @@ export default [ }, effect: supplierDiscountRub => { const { leaseObjectPrice } = calculationStore.values; - if ( - leaseObjectPrice && - leaseObjectPrice > 0 && - supplierDiscountRub >= leaseObjectPrice - ) { + + const { supplierCurrency: supplierCurrencyId } = calculationStore.values; + 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 = convertPrice( + supplierCurrency?.isocurrencycode, + leaseObjectPrice, + evo_currencychangeValue, + ); + + if (price && price > 0 && supplierDiscountRub >= price) { calculationStore.setValidation('tbxSupplierDiscountRub', false); openNotification({ type: 'error', @@ -264,11 +277,22 @@ export default [ }, effect: firstPaymentRub => { const { leaseObjectPrice } = calculationStore.values; - if ( - leaseObjectPrice && - leaseObjectPrice > 0 && - firstPaymentRub >= leaseObjectPrice - ) { + + const { supplierCurrency: supplierCurrencyId } = calculationStore.values; + 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 = convertPrice( + supplierCurrency?.isocurrencycode, + leaseObjectPrice, + evo_currencychangeValue, + ); + if (price && price > 0 && firstPaymentRub >= price) { calculationStore.setValidation('tbxFirstPaymentRub', false); openNotification({ type: 'error',