move recalc reactions to separate file
This commit is contained in:
parent
28616bb8e4
commit
8e929a1d2b
@ -4,6 +4,7 @@ import priceReactions from './priceReactions';
|
||||
import tablesReactions from './tablesReactions';
|
||||
import loadKpReaction from './loadKpReaction';
|
||||
import statusReactions from './statusReactions';
|
||||
import recalcWoRevisionReactions from './recalcWoRevisionReactions';
|
||||
|
||||
export default [
|
||||
...otherReactions,
|
||||
@ -11,5 +12,6 @@ export default [
|
||||
...requestReactions,
|
||||
...tablesReactions,
|
||||
...statusReactions,
|
||||
...recalcWoRevisionReactions,
|
||||
loadKpReaction,
|
||||
];
|
||||
|
||||
@ -3,7 +3,6 @@ import { IReactionEffect } from 'core/types/Calculation/Store/effect';
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
import { round } from 'lodash';
|
||||
import { convertPrice } from '../lib/tools';
|
||||
|
||||
const reactionEffects: IReactionEffect[] = [
|
||||
// calculationStore => ({
|
||||
@ -1179,173 +1178,6 @@ 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 = convertPrice(
|
||||
supplierCurrency?.isocurrencycode,
|
||||
leaseObjectPrice,
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
|
||||
let maxPriceChange =
|
||||
price - supplierDiscountRub < 800000
|
||||
? price - supplierDiscountRub + 50000
|
||||
: (price - supplierDiscountRub) * 1.05;
|
||||
|
||||
calculationStore.setValue('maxPriceChange', maxPriceChange);
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { recalcWithRevision } = calculationStore.values;
|
||||
return recalcWithRevision;
|
||||
},
|
||||
effect: recalcWithRevision => {
|
||||
if (recalcWithRevision === true) {
|
||||
calculationStore.setStatus('selectLead', ElementStatus.Disabled);
|
||||
calculationStore.setStatus('selectOpportunity', ElementStatus.Disabled);
|
||||
} else {
|
||||
calculationStore.setStatus('selectLead', ElementStatus.Default);
|
||||
calculationStore.setStatus('selectOpportunity', ElementStatus.Default);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { recalcWithRevision } = calculationStore.values;
|
||||
return recalcWithRevision;
|
||||
},
|
||||
effect: recalcWithRevision => {
|
||||
if (recalcWithRevision === true) {
|
||||
calculationStore.setFilter('selectQuote', quotes =>
|
||||
quotes.filter(
|
||||
quote =>
|
||||
quote.evo_recalc_limit &&
|
||||
quote.evo_recalc_limit > 0 &&
|
||||
quote.evo_statuscode &&
|
||||
quote.evo_statuscode.evo_id &&
|
||||
quote.evo_statuscode.evo_id === '2.3',
|
||||
),
|
||||
);
|
||||
const { quote } = calculationStore.values;
|
||||
const { selectQuote: selectQuoteFilter } = calculationStore.filters;
|
||||
const { selectQuote: selectQuoteOptions } = calculationStore.options;
|
||||
if (
|
||||
selectQuoteFilter &&
|
||||
selectQuoteOptions &&
|
||||
!selectQuoteFilter(selectQuoteOptions).some(x => x.value === quote)
|
||||
) {
|
||||
calculationStore.setValue('quote', null);
|
||||
}
|
||||
} else {
|
||||
calculationStore.setFilter('selectQuote', undefined);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const {
|
||||
supplierDiscountRub,
|
||||
leaseObjectPrice,
|
||||
supplierCurrency,
|
||||
recalcWithRevision,
|
||||
} = calculationStore.values;
|
||||
return [
|
||||
supplierDiscountRub,
|
||||
leaseObjectPrice,
|
||||
supplierCurrency,
|
||||
recalcWithRevision,
|
||||
];
|
||||
},
|
||||
effect: ([
|
||||
supplierDiscountRub,
|
||||
leaseObjectPrice,
|
||||
supplierCurrencyId,
|
||||
recalcWithRevision,
|
||||
]) => {
|
||||
if (!recalcWithRevision) {
|
||||
calculationStore.setValidation('tbxLeaseObjectPrice', undefined);
|
||||
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 = convertPrice(
|
||||
supplierCurrency?.isocurrencycode,
|
||||
leaseObjectPrice,
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
|
||||
const { quote: quoteId } = calculationStore.values;
|
||||
const quote = calculationStore.options.selectQuote?.find(
|
||||
x => x.value === quoteId,
|
||||
);
|
||||
|
||||
if (quote && quote.evo_max_price_change) {
|
||||
if (price - supplierDiscountRub > quote.evo_max_price_change) {
|
||||
calculationStore.setValidation('tbxLeaseObjectPrice', false);
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description:
|
||||
'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра. ' +
|
||||
'Уменьшите стоимость предмета лизинга',
|
||||
})();
|
||||
} else {
|
||||
calculationStore.setValidation('tbxLeaseObjectPrice', undefined);
|
||||
}
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { leaseObjectUsed } = calculationStore.values;
|
||||
@ -1385,37 +1217,6 @@ const reactionEffects: IReactionEffect[] = [
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { firstPaymentPerc, recalcWithRevision } = calculationStore.values;
|
||||
return { firstPaymentPerc, recalcWithRevision };
|
||||
},
|
||||
effect: ({ firstPaymentPerc, recalcWithRevision }) => {
|
||||
if (!recalcWithRevision) {
|
||||
calculationStore.setValidation('tbxFirstPaymentPerc', undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const { quote: quoteId } = calculationStore.values;
|
||||
const quote = calculationStore.options.selectQuote?.find(
|
||||
x => x.quoteid === quoteId,
|
||||
);
|
||||
if (quote && quote.evo_approved_first_payment) {
|
||||
if (firstPaymentPerc < quote.evo_approved_first_payment) {
|
||||
calculationStore.setValidation('tbxFirstPaymentPerc', false);
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description:
|
||||
'Указанный первый платеж меньше одобренного. При пересчете без пересмотра изменение первого платежа возможно только в большую сторону от одобренного значения',
|
||||
})();
|
||||
} else {
|
||||
calculationStore.setValidation('tbxFirstPaymentPerc', undefined);
|
||||
}
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { brand, model, leaseObjectUsed } = calculationStore.values;
|
||||
|
||||
@ -0,0 +1,206 @@
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
import { convertPrice } from '../lib/tools';
|
||||
|
||||
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 = convertPrice(
|
||||
supplierCurrency?.isocurrencycode,
|
||||
leaseObjectPrice,
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
|
||||
let maxPriceChange =
|
||||
price - supplierDiscountRub < 800000
|
||||
? price - supplierDiscountRub + 50000
|
||||
: (price - supplierDiscountRub) * 1.05;
|
||||
|
||||
calculationStore.setValue('maxPriceChange', maxPriceChange);
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { recalcWithRevision } = calculationStore.values;
|
||||
return recalcWithRevision;
|
||||
},
|
||||
effect: recalcWithRevision => {
|
||||
if (recalcWithRevision === true) {
|
||||
calculationStore.setStatus('selectLead', ElementStatus.Disabled);
|
||||
calculationStore.setStatus('selectOpportunity', ElementStatus.Disabled);
|
||||
} else {
|
||||
calculationStore.setStatus('selectLead', ElementStatus.Default);
|
||||
calculationStore.setStatus('selectOpportunity', ElementStatus.Default);
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fireImmediately: true,
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { recalcWithRevision } = calculationStore.values;
|
||||
return recalcWithRevision;
|
||||
},
|
||||
effect: recalcWithRevision => {
|
||||
if (recalcWithRevision === true) {
|
||||
calculationStore.setFilter('selectQuote', quotes =>
|
||||
quotes.filter(
|
||||
quote =>
|
||||
quote.evo_recalc_limit &&
|
||||
quote.evo_recalc_limit > 0 &&
|
||||
quote.evo_statuscode &&
|
||||
quote.evo_statuscode.evo_id &&
|
||||
quote.evo_statuscode.evo_id === '2.3',
|
||||
),
|
||||
);
|
||||
const { quote } = calculationStore.values;
|
||||
const { selectQuote: selectQuoteFilter } = calculationStore.filters;
|
||||
const { selectQuote: selectQuoteOptions } = calculationStore.options;
|
||||
if (
|
||||
selectQuoteFilter &&
|
||||
selectQuoteOptions &&
|
||||
!selectQuoteFilter(selectQuoteOptions).some(x => x.value === quote)
|
||||
) {
|
||||
calculationStore.setValue('quote', null);
|
||||
}
|
||||
} else {
|
||||
calculationStore.setFilter('selectQuote', undefined);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const {
|
||||
supplierDiscountRub,
|
||||
leaseObjectPrice,
|
||||
supplierCurrency,
|
||||
recalcWithRevision,
|
||||
} = calculationStore.values;
|
||||
return [
|
||||
supplierDiscountRub,
|
||||
leaseObjectPrice,
|
||||
supplierCurrency,
|
||||
recalcWithRevision,
|
||||
];
|
||||
},
|
||||
effect: ([
|
||||
supplierDiscountRub,
|
||||
leaseObjectPrice,
|
||||
supplierCurrencyId,
|
||||
recalcWithRevision,
|
||||
]) => {
|
||||
if (!recalcWithRevision) {
|
||||
calculationStore.setValidation('tbxLeaseObjectPrice', undefined);
|
||||
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 = convertPrice(
|
||||
supplierCurrency?.isocurrencycode,
|
||||
leaseObjectPrice,
|
||||
evo_currencychangeValue,
|
||||
);
|
||||
|
||||
const { quote: quoteId } = calculationStore.values;
|
||||
const quote = calculationStore.options.selectQuote?.find(
|
||||
x => x.value === quoteId,
|
||||
);
|
||||
|
||||
if (quote && quote.evo_max_price_change) {
|
||||
if (price - supplierDiscountRub > quote.evo_max_price_change) {
|
||||
calculationStore.setValidation('tbxLeaseObjectPrice', false);
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description:
|
||||
'Указанная стоимость предмета лизинга больше возмножного изменения стоимости предмета лизинга при пересчете без пересмотра. ' +
|
||||
'Уменьшите стоимость предмета лизинга',
|
||||
})();
|
||||
} else {
|
||||
calculationStore.setValidation('tbxLeaseObjectPrice', undefined);
|
||||
}
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
calculationStore => ({
|
||||
expression: () => {
|
||||
const { firstPaymentPerc, recalcWithRevision } = calculationStore.values;
|
||||
return { firstPaymentPerc, recalcWithRevision };
|
||||
},
|
||||
effect: ({ firstPaymentPerc, recalcWithRevision }) => {
|
||||
if (!recalcWithRevision) {
|
||||
calculationStore.setValidation('tbxFirstPaymentPerc', undefined);
|
||||
return;
|
||||
}
|
||||
|
||||
const { quote: quoteId } = calculationStore.values;
|
||||
const quote = calculationStore.options.selectQuote?.find(
|
||||
x => x.quoteid === quoteId,
|
||||
);
|
||||
if (quote && quote.evo_approved_first_payment) {
|
||||
if (firstPaymentPerc < quote.evo_approved_first_payment) {
|
||||
calculationStore.setValidation('tbxFirstPaymentPerc', false);
|
||||
openNotification({
|
||||
type: 'error',
|
||||
title: 'Ошибка',
|
||||
description:
|
||||
'Указанный первый платеж меньше одобренного. При пересчете без пересмотра изменение первого платежа возможно только в большую сторону от одобренного значения',
|
||||
})();
|
||||
} else {
|
||||
calculationStore.setValidation('tbxFirstPaymentPerc', undefined);
|
||||
}
|
||||
}
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
export default reactionEffects;
|
||||
Reference in New Issue
Block a user