process/payments: prepare for season graphtype

This commit is contained in:
Chika 2022-10-05 17:01:11 +03:00
parent 6107e0c15f
commit adf186d8da
2 changed files with 26 additions and 10 deletions

View File

@ -4,7 +4,7 @@ import type { ApolloClient } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import { selectSeasonType } from 'config/default-options';
import { reaction, toJS } from 'mobx';
import { last } from 'radash/dist/array';
import type { CalculationOptions } from 'stores/calculation/options/types';
import type RootStore from 'stores/root';
import type { Row } from 'stores/tables/payments/types';
import validatePaymentsTable from './validation';
@ -188,7 +188,10 @@ export default function paymentsReactions(
/**
* Дегрессия
*/
const degressionSeasonTypes = [100_000_003, 100_000_004, 100_000_005, 100_000_006, 100_000_007];
const degressionSeasonTypes = new Set([
100_000_003, 100_000_004, 100_000_005, 100_000_006, 100_000_007,
]);
const seasonSeasonTypes = new Set([100_000_000, 100_000_001, 100_000_002]);
reaction(
() => {
@ -197,17 +200,19 @@ export default function paymentsReactions(
return graphType;
},
(graphType) => {
if (!graphType || graphType !== 100_000_001) {
$calculation.setElementOptions('selectSeasonType', []);
let selectSeasonTypeOptions: CalculationOptions['selectSeasonType'] = [];
return;
if (graphType === 100_000_001) {
selectSeasonTypeOptions = selectSeasonType.filter((option) =>
degressionSeasonTypes.has(option.value)
);
} else if (graphType === 100_000_003) {
selectSeasonTypeOptions = selectSeasonType.filter((option) =>
seasonSeasonTypes.has(option.value)
);
}
const selectSeasonTypeOptions = selectSeasonType.filter((option) =>
degressionSeasonTypes.includes(option.value)
);
$calculation.setElementOptions('selectSeasonType', selectSeasonTypeOptions);
$calculation.setElementValue('selectSeasonType', last(degressionSeasonTypes));
$calculation.resetElementValue('selectSeasonType');
}
);

View File

@ -11,6 +11,9 @@ export default function validatePaymentsTable(
switch (values.graphType) {
// Дегрессия
case 100_000_001:
if (!values.seasonType) {
return 'Не выбран тип дегрессии';
}
/**
* в таблице платежей в столбце Соотношение платежей для строк с 2 до "Срок лизинга-1" минимальное значение должно быть равно 3
*/
@ -71,6 +74,14 @@ export default function validatePaymentsTable(
break;
case 100_000_003: {
if (!values.seasonType) {
return 'Не выбран тип сезонности';
}
break;
}
// Легкий старт
case 100_000_004: {
const targetPayments = payments.slice(1, 4);