From cca03a0f4aefb299556decebae3e48a1a8962d1b Mon Sep 17 00:00:00 2001 From: Chika Date: Wed, 14 Apr 2021 16:33:33 +0300 Subject: [PATCH] remove cloned code --- .../reactions/priceReactions/calculate.js | 33 ++++++++------- .../Effects/reactions/priceReactions/index.ts | 16 ++----- .../reactions/recalcWoRevisionReactions.ts | 15 ++----- .../Effects/reactions/tablesReactions.ts | 42 ------------------- 4 files changed, 27 insertions(+), 79 deletions(-) diff --git a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/calculate.js b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/calculate.js index 1a5cc45..906351d 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/calculate.js +++ b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/calculate.js @@ -1,9 +1,9 @@ import { convertPrice } from '../../lib/tools'; -export const calculatePerc = calculationStore => ( +export const getPrice = ( supplierCurrencyId, leaseObjectPrice, - rubSum, + calculationStore, ) => { const supplierCurrency = calculationStore .getOptions('selectSupplierCurrency') @@ -18,6 +18,19 @@ export const calculatePerc = calculationStore => ( parseFloat(leaseObjectPrice), evo_currencychangeValue, ); + return price; +}; + +export const calculatePerc = calculationStore => ( + supplierCurrencyId, + leaseObjectPrice, + rubSum, +) => { + const price = getPrice( + supplierCurrencyId, + leaseObjectPrice, + calculationStore, + ); return (rubSum / price) * 100; }; @@ -26,18 +39,10 @@ export const calculateRub = calculationStore => ( leaseObjectPrice, perc, ) => { - 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, - parseFloat(leaseObjectPrice), - evo_currencychangeValue, + const price = getPrice( + supplierCurrencyId, + leaseObjectPrice, + calculationStore, ); return (perc * price) / 100; }; diff --git a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts index 062320a..571ec96 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/priceReactions/index.ts @@ -2,7 +2,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'; +import { calculatePerc, calculateRub, getPrice } from './calculate'; export default [ (calculationStore, calculationProcess) => ({ @@ -242,18 +242,10 @@ export default [ const { leaseObjectPrice } = calculationStore.values; 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; - const price = convertPrice( - supplierCurrency?.isocurrencycode, + const price = getPrice( + supplierCurrencyId, leaseObjectPrice, - evo_currencychangeValue, + calculationStore, ); if (price && price > 0 && supplierDiscountRub >= price) { diff --git a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts index 0f005f1..0701bb9 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/recalcWoRevisionReactions.ts @@ -5,6 +5,7 @@ import { ElementsNames } from 'core/types/Calculation/Store/elements'; import { TableNames } from 'core/types/Calculation/Store/tables'; import { ElementStatus } from 'core/types/statuses'; import { convertPrice } from '../lib/tools'; +import { getPrice } from './priceReactions/calculate'; const reactionEffects: IReactionEffect[] = [ calculationStore => ({ @@ -34,18 +35,10 @@ const reactionEffects: IReactionEffect[] = [ 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; - const price = convertPrice( - supplierCurrency?.isocurrencycode, + const price = getPrice( + supplierCurrencyId, leaseObjectPrice, - evo_currencychangeValue, + calculationStore, ); const maxPriceChange = diff --git a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts index 0352327..2b5e61d 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/tablesReactions.ts @@ -113,48 +113,6 @@ export default [ }, }), - (calculationStore, calculationProcess) => ({ - expression: () => { - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - const kaskoRow = tableRows[kaskoRowIndex]; - const { leasingPeriod } = calculationStore.values; - - return { - insTerm: kaskoRow.insTerm?.value, - leasingPeriod, - }; - }, - effect: ({ insTerm, leasingPeriod }) => { - if (calculationProcess.process === Process.LoadKp) { - return; - } - const { rows: tableRows } = calculationStore.tables.tableInsurance; - const kaskoRowIndex = tableRows.findIndex( - x => x.policyType?.value === 'КАСКО', - ); - if (insTerm === 100000001 && leasingPeriod > 15 && kaskoRowIndex) { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { value: 100000001, status: ElementStatus.Disabled }, - }); - } else { - if (kaskoRowIndex >= 0) - calculationStore.setTableRow( - 'tableInsurance', - kaskoRowIndex, - )({ - insured: { status: ElementStatus.Default }, - }); - } - }, - }), - (calculationStore, calculationProcess) => ({ expression: () => { const { leasingPeriod } = calculationStore.values;