new recalc reactions

This commit is contained in:
Chika 2021-01-26 15:42:51 +03:00
parent cbc5941e7d
commit 4d7444e92a
2 changed files with 114 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import { openNotification } from 'client/Elements/Notification';
import valuesConstants from 'core/constants/values';
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
import { ElementStatus } from 'core/types/statuses';
import { convertPrice } from '../lib/tools';
@ -254,6 +255,117 @@ const reactionEffects: IReactionEffect[] = [
}
},
}),
calculationStore => ({
expression: () => {
const { maxMass, recalcWithRevision } = calculationStore.values;
return { maxMass, recalcWithRevision };
},
effect: ({ maxMass, recalcWithRevision }) => {
if (recalcWithRevision) {
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.value === quoteId,
);
if (quote && quote.evo_max_mass)
if (
(maxMass < valuesConstants.MAX_VEHICLE_MASS &&
quote.evo_max_mass < valuesConstants.MAX_VEHICLE_MASS) ||
(maxMass >= valuesConstants.MAX_VEHICLE_MASS &&
quote.evo_max_mass >= valuesConstants.MAX_VEHICLE_MASS)
) {
calculationStore.setValidation('tbxMaxMass', undefined);
} else {
openNotification({
type: 'error',
title: 'Ошибка',
description:
'Указанная разрешенная макс. масса выходит из утвержденного диапазона. Для изменения параметра требуется пересмотр сделки',
})();
calculationStore.setValidation('tbxMaxMass', false);
}
}
},
}),
calculationStore => ({
expression: () => {
const {
countSeats,
leaseObjectCategory,
recalcWithRevision,
} = calculationStore.values;
return {
countSeats,
leaseObjectCategory,
recalcWithRevision,
};
},
effect: ({ countSeats, leaseObjectCategory, recalcWithRevision }) => {
if (recalcWithRevision && leaseObjectCategory === 100000003) {
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.value === quoteId,
);
if (quote && quote?.evo_seats)
if (
(countSeats < valuesConstants.MAX_VEHICLE_SEATS &&
quote.evo_seats < valuesConstants.MAX_VEHICLE_SEATS) ||
(countSeats >= valuesConstants.MAX_VEHICLE_SEATS &&
quote.evo_seats >= valuesConstants.MAX_VEHICLE_SEATS)
) {
calculationStore.setValidation('tbxCountSeats', undefined);
} else {
openNotification({
type: 'error',
title: 'Ошибка',
description:
'Указанная разрешенная макс. масса выходит из утвержденного диапазона. Для изменения параметра требуется пересмотр сделки',
})();
calculationStore.setValidation('tbxCountSeats', false);
}
} else {
calculationStore.setValidation('tbxCountSeats', undefined);
}
},
}),
calculationStore => ({
expression: () => {
const { leaseObjectUsed, recalcWithRevision } = calculationStore.values;
return { leaseObjectUsed, recalcWithRevision };
},
effect: ({ leaseObjectUsed, recalcWithRevision }) => {
calculationStore.setStatus(
'tbxLeaseObjectYear',
recalcWithRevision && leaseObjectUsed
? ElementStatus.Disabled
: ElementStatus.Default,
);
},
}),
calculationStore => ({
expression: () => {
const { leaseObjectYear, recalcWithRevision } = calculationStore.values;
return { leaseObjectYear, recalcWithRevision };
},
effect: ({ leaseObjectYear, recalcWithRevision }) => {
const { leaseObjectUsed } = calculationStore.values;
if (recalcWithRevision && !leaseObjectUsed && leaseObjectYear) {
const { quote: quoteId } = calculationStore.values;
const quote = calculationStore.options.selectQuote?.find(
x => x.value === quoteId,
);
if (quote && quote.evo_year)
if (leaseObjectYear >= quote.evo_year) {
calculationStore.setValidation('tbxLeaseObjectYear', undefined);
} else {
calculationStore.setValidation('tbxLeaseObjectYear', false);
}
}
},
}),
];
export default reactionEffects;

View File

@ -5,4 +5,6 @@ export default {
KASKO_BONUS_PR: 0.35,
NSIB_MAX: 5000000,
NDFL: 0.13,
MAX_VEHICLE_MASS: 3500,
MAX_VEHICLE_SEATS: 20,
};