From fbac09d375b054684f32870519e1e609a6927428 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 16 Nov 2020 11:57:10 +0300 Subject: [PATCH] fix plprice & discount --- src/client/services/prepareData.ts | 63 ++++++++++++------------------ 1 file changed, 25 insertions(+), 38 deletions(-) diff --git a/src/client/services/prepareData.ts b/src/client/services/prepareData.ts index 8ef40bb..61848b1 100644 --- a/src/client/services/prepareData.ts +++ b/src/client/services/prepareData.ts @@ -1,10 +1,9 @@ import { calcPrice } from 'client/stores/CalculationStore/Effects/lib/tools'; import valuesConstants from 'core/constants/values'; -import { PreparedValues } from 'core/types/Calculation/Prepare'; +import { PaymentRow, PreparedValues } from 'core/types/Calculation/Prepare'; import { IGetCalculationRequest } from 'core/types/Calculation/Requests'; import { ICalculationStore } from 'core/types/Calculation/Store'; import { DateTime } from 'luxon'; -import { PaymentRow } from './../../core/types/Calculation/Prepare'; export const prepareCalculationData = ({ calculationStore, @@ -225,46 +224,34 @@ export const prepareCalculationData = ({ preparedValues.firstPayment = values.firstPaymentPerc / 100; } - const transactioncurrencyRUB = options.selectSupplierCurrency?.find( - x => x.isocurrencycode === 'RUB', + //plPrice && discount + const supplierCurrency = options.selectSupplierCurrency?.find( + x => x.transactioncurrencyid === values.supplierCurrency, ); - if ( - values.supplierCurrency === transactioncurrencyRUB?.transactioncurrencyid - ) { - preparedValues.plPrice = - values.leaseObjectPrice / (1 + valuesConstants.VAT); - preparedValues.discount = - values.supplierDiscountRub / (1 + valuesConstants.VAT); - } else { - const evo_currencychanges = calculationStore.getStaticData( - 'evo_currencychange', - ); + const evo_currencychanges = calculationStore.getStaticData( + 'evo_currencychange', + ); + const evo_currencychange = evo_currencychanges.find( + x => x.evo_ref_transactioncurrency === values.supplierCurrency, + ); - if (evo_currencychanges && evo_currencychanges.length > 0) { - const evo_currencychange_supplier = evo_currencychanges.find( - x => x.transactioncurrencyid === values.supplierCurrency, - ); + preparedValues.plPrice = + calcPrice( + supplierCurrency?.isocurrencycode, + values.leaseObjectPrice, + evo_currencychange?.evo_currencychange || 1, + ) / + (1 + valuesConstants.VAT); - if (evo_currencychange_supplier) { - preparedValues.plPrice = - calcPrice( - evo_currencychange_supplier.isocurrencycode, - values.leaseObjectPrice, - evo_currencychange_supplier.evo_currencychange || 0, - ) / - (1 + valuesConstants.VAT); - - preparedValues.discount = - calcPrice( - evo_currencychange_supplier.isocurrencycode, - values.supplierDiscountRub, - evo_currencychange_supplier.evo_currencychange || 0, - ) / - (1 + valuesConstants.VAT); - } - } - } + preparedValues.discount = + calcPrice( + supplierCurrency?.isocurrencycode, + values.supplierDiscountRub, + evo_currencychange?.evo_currencychange || 1, + ) / + (1 + valuesConstants.VAT); + // preparedValues.acceptSum = (preparedValues.plPrice || 0) - (preparedValues.discount || 0);