process/payments: add highSeasonStart filtering

This commit is contained in:
Chika 2022-10-14 13:11:00 +03:00
parent 5a25b342f6
commit 4acbcde1cc
3 changed files with 41 additions and 5 deletions

View File

@ -36,7 +36,7 @@ export const selectSeasonType = [
},
];
const selectHighSeasonStart = Array.from(
export const selectHighSeasonStart = Array.from(
{
length: 12,
},

View File

@ -9,8 +9,17 @@ const SEASONS_PERIODS: Record<number, Array<number>> = {
100_000_001: [0, 8],
100_000_002: [0, 4, 8],
};
export const FORBIDDEN_HIGH_SEASON_START: Record<number, Array<string>> = {
100_000_000: ['9', '10'],
100_000_001: ['7', '8', '9'],
100_000_002: ['11'],
};
export const SEASONS_PERIOD_NUMBER = 12;
export const DEFAULT_SEASONS_VALUES = [100, 75, 50];
export function getPositionIndex(seasonType: SeasonType, seasonsIndex: number) {
let positionIndex = 0;

View File

@ -2,14 +2,18 @@
/* eslint-disable implicit-arrow-linebreak */
import type { ApolloClient } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import { selectSeasonType } from 'config/default-options';
import { selectHighSeasonStart, selectSeasonType } from 'config/default-options';
import { comparer, reaction, toJS } from 'mobx';
import type { CalculationOptions } from 'stores/calculation/options/types';
import type RootStore from 'stores/root';
import type { Row } from 'stores/tables/payments/types';
import { difference, shift } from 'tools/array';
import * as seasonsTools from './lib/seasons';
import { SEASONS_PERIOD_NUMBER } from './lib/seasons';
import {
DEFAULT_SEASONS_VALUES,
FORBIDDEN_HIGH_SEASON_START,
SEASONS_PERIOD_NUMBER,
} from './lib/seasons';
import validatePaymentsTable from './validation';
export default function paymentsReactions(
@ -380,7 +384,30 @@ export default function paymentsReactions(
}
);
const defaultSeasonsValues = [100, 75, 50];
reaction(
() => {
const seasonType = $calculation.getElementValue('selectSeasonType');
return seasonType;
},
(seasonType) => {
const graphType = $calculation.getElementValue('radioGraphType');
if (graphType !== 100_000_003) return;
if (!seasonType) {
$calculation.resetElement('selectHighSeasonStart');
return;
}
const highSeasonStartOptions = selectHighSeasonStart.filter(
(option) => !FORBIDDEN_HIGH_SEASON_START[seasonType].includes(option.label)
);
$calculation.setElementOptions('selectHighSeasonStart', highSeasonStartOptions);
$calculation.resetElementValue('selectHighSeasonStart');
}
);
reaction(
() => {
@ -404,7 +431,7 @@ export default function paymentsReactions(
return;
}
const seasons = seasonsTools.generateSeasons(seasonType, defaultSeasonsValues);
const seasons = seasonsTools.generateSeasons(seasonType, DEFAULT_SEASONS_VALUES);
const shiftNumber = Number.parseInt(highSeasonStartOption.label, 10) - 2;
const payments = seasonsTools.generateSeasonsPayments(
leasingPeriod,