effects: currency

This commit is contained in:
Chika 2020-09-29 17:08:30 +03:00
parent 6cb0bda37d
commit 4222d0565c
2 changed files with 204 additions and 32 deletions

View File

@ -10,3 +10,51 @@ export function calcSupplierPrice(
}
return price;
}
export const calculatePerc = calculationStore => (
supplierCurrencyId,
leaseObjectPrice,
discountRub,
discountPercFieldName,
) => {
// TODO: check evo_currecychange
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 = calcSupplierPrice(
supplierCurrency?.isocurrencycode,
parseFloat(leaseObjectPrice),
evo_currencychangeValue,
);
let perc = (discountRub / price) * 100;
calculationStore.setValue(discountPercFieldName, perc);
};
export const calculateRub = calculationStore => (
supplierCurrencyId,
leaseObjectPrice,
discountPerc,
discountRubFieldName,
) => {
// TODO: check evo_currecychange
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 = calcSupplierPrice(
supplierCurrency?.isocurrencycode,
parseFloat(leaseObjectPrice),
evo_currencychangeValue,
);
let rub = (discountPerc * price) / 100;
calculationStore.setValue(discountRubFieldName, rub);
};

View File

@ -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 { calcSupplierPrice } from './lib/tools';
import { calculatePerc, calculateRub } from './lib/tools';
const reactionEffects: IReactionEffect[] = [
calculationStore => ({
@ -1551,25 +1551,14 @@ const reactionEffects: IReactionEffect[] = [
if (supplierDiscountRub === undefined) {
return;
}
// TODO: check evo_currecychange
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 = calcSupplierPrice(
supplierCurrency?.isocurrencycode,
parseFloat(leaseObjectPrice),
evo_currencychangeValue,
calculatePerc(calculationStore)(
supplierCurrencyId,
leaseObjectPrice,
supplierDiscountRub,
'supplierDiscountPerc',
);
let perc = (supplierDiscountRub / price) * 100;
calculationStore.setValue('supplierDiscountPerc', perc);
},
}),
calculationStore => ({
expression: () => {
const {
@ -1583,22 +1572,157 @@ const reactionEffects: IReactionEffect[] = [
if (supplierDiscountPerc === undefined) {
return;
}
// TODO: check evo_currecychange
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 = calcSupplierPrice(
supplierCurrency?.isocurrencycode,
parseFloat(leaseObjectPrice),
evo_currencychangeValue,
calculateRub(calculationStore)(
supplierCurrencyId,
leaseObjectPrice,
supplierDiscountPerc,
'supplierDiscountRub',
);
},
}),
calculationStore => ({
expression: () => {
const { firstPaymentRub } = calculationStore.values;
return firstPaymentRub;
},
effect: firstPaymentRub => {
if (firstPaymentRub === undefined) {
return;
}
const { supplierCurrency, leaseObjectPrice } = calculationStore.values;
calculatePerc(calculationStore)(
supplierCurrency,
leaseObjectPrice,
firstPaymentRub,
'firstPaymentPerc',
);
},
}),
calculationStore => ({
expression: () => {
const {
supplierCurrency,
leaseObjectPrice,
firstPaymentPerc,
} = calculationStore.values;
return [supplierCurrency, leaseObjectPrice, firstPaymentPerc];
},
effect: ([supplierCurrencyId, leaseObjectPrice, firstPaymentPerc]) => {
if (firstPaymentPerc === undefined) {
return;
}
calculateRub(calculationStore)(
supplierCurrencyId,
leaseObjectPrice,
firstPaymentPerc,
'firstPaymentRub',
);
},
}),
calculationStore => ({
expression: () => {
const {
supplierCurrency,
leaseObjectPrice,
comissionPerc,
} = calculationStore.values;
return [supplierCurrency, leaseObjectPrice, comissionPerc];
},
effect: ([supplierCurrencyId, leaseObjectPrice, comissionPerc]) => {
if (comissionPerc === undefined) {
return;
}
calculateRub(calculationStore)(
supplierCurrencyId,
leaseObjectPrice,
comissionPerc,
'comissionRub',
);
},
}),
calculationStore => ({
expression: () => {
const { comissionRub } = calculationStore.values;
return comissionRub;
},
effect: comissionRub => {
if (comissionRub === undefined) {
return;
}
const { supplierCurrency, leaseObjectPrice } = calculationStore.values;
calculatePerc(calculationStore)(
supplierCurrency,
leaseObjectPrice,
comissionRub,
'comissionPerc',
);
},
}),
calculationStore => ({
expression: () => {
const {
supplierCurrency,
leaseObjectPrice,
lastPaymentPerc,
lastPaymentRule,
} = calculationStore.values;
return [
supplierCurrency,
leaseObjectPrice,
lastPaymentPerc,
lastPaymentRule,
];
},
effect: ([
supplierCurrencyId,
leaseObjectPrice,
lastPaymentPerc,
lastPaymentRule,
]) => {
if (lastPaymentPerc === undefined || lastPaymentRule !== 100000001) {
return;
}
calculateRub(calculationStore)(
supplierCurrencyId,
leaseObjectPrice,
lastPaymentPerc,
'lastPaymentRub',
);
},
}),
calculationStore => ({
expression: () => {
const {
supplierCurrency,
leaseObjectPrice,
lastPaymentRub,
lastPaymentRule,
} = calculationStore.values;
return [
supplierCurrency,
leaseObjectPrice,
lastPaymentRub,
lastPaymentRule,
];
},
effect: ([
supplierCurrencyId,
leaseObjectPrice,
lastPaymentRub,
lastPaymentRule,
]) => {
if (lastPaymentRub === undefined || lastPaymentRule !== 100000000) {
return;
}
calculatePerc(calculationStore)(
supplierCurrencyId,
leaseObjectPrice,
lastPaymentRub,
'lastPaymentPerc',
);
let rub = (supplierDiscountPerc * price) / 100;
calculationStore.setValue('supplierDiscountRub', rub);
},
}),
];