From 4acbcde1ccfea393756c7036d57eb37905bd935c Mon Sep 17 00:00:00 2001 From: Chika Date: Fri, 14 Oct 2022 13:11:00 +0300 Subject: [PATCH] process/payments: add highSeasonStart filtering --- config/default-options.ts | 2 +- process/payments/lib/seasons.ts | 9 +++++++++ process/payments/reactions.ts | 35 +++++++++++++++++++++++++++++---- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/config/default-options.ts b/config/default-options.ts index 60ef2be..7882924 100644 --- a/config/default-options.ts +++ b/config/default-options.ts @@ -36,7 +36,7 @@ export const selectSeasonType = [ }, ]; -const selectHighSeasonStart = Array.from( +export const selectHighSeasonStart = Array.from( { length: 12, }, diff --git a/process/payments/lib/seasons.ts b/process/payments/lib/seasons.ts index 2dfd6a2..da7133b 100644 --- a/process/payments/lib/seasons.ts +++ b/process/payments/lib/seasons.ts @@ -9,8 +9,17 @@ const SEASONS_PERIODS: Record> = { 100_000_001: [0, 8], 100_000_002: [0, 4, 8], }; + +export const FORBIDDEN_HIGH_SEASON_START: Record> = { + 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; diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index fe76c1f..86ef1e3 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -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,