process/payments: refactor /lib files structure

This commit is contained in:
Chika 2022-10-14 13:15:48 +03:00
parent 4acbcde1cc
commit 9cac288dcc
4 changed files with 28 additions and 29 deletions

View File

@ -1,6 +1,6 @@
import { getPositionIndex } from '../seasons';
import { getPositionIndex } from '../seasons-tools';
describe('process/payments/lib/seasons', () => {
describe('process/payments/lib/seasons-tools', () => {
describe('[function] getPositionIndex', () => {
test('should return 0', () => {
const result = getPositionIndex(100_000_001, 0);

View File

@ -0,0 +1,15 @@
export const SEASONS_PERIODS: Record<number, Array<number>> = {
100_000_000: [0, 6],
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];

View File

@ -1,25 +1,10 @@
/* eslint-disable implicit-arrow-linebreak */
import type { CalculationValues } from 'stores/calculation/values/types';
import { SEASONS_PERIODS, SEASONS_PERIOD_NUMBER } from './seasons-constants';
type SeasonType = NonNullable<CalculationValues['seasonType']>;
type LeasingPeriod = CalculationValues['leasingPeriod'];
const SEASONS_PERIODS: Record<number, Array<number>> = {
100_000_000: [0, 6],
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

@ -8,12 +8,8 @@ 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 {
DEFAULT_SEASONS_VALUES,
FORBIDDEN_HIGH_SEASON_START,
SEASONS_PERIOD_NUMBER,
} from './lib/seasons';
import * as seasonsConstants from './lib/seasons-constants';
import * as seasonsTools from './lib/seasons-tools';
import validatePaymentsTable from './validation';
export default function paymentsReactions(
@ -401,7 +397,7 @@ export default function paymentsReactions(
}
const highSeasonStartOptions = selectHighSeasonStart.filter(
(option) => !FORBIDDEN_HIGH_SEASON_START[seasonType].includes(option.label)
(option) => !seasonsConstants.FORBIDDEN_HIGH_SEASON_START[seasonType].includes(option.label)
);
$calculation.setElementOptions('selectHighSeasonStart', highSeasonStartOptions);
@ -431,7 +427,10 @@ export default function paymentsReactions(
return;
}
const seasons = seasonsTools.generateSeasons(seasonType, DEFAULT_SEASONS_VALUES);
const seasons = seasonsTools.generateSeasons(
seasonType,
seasonsConstants.DEFAULT_SEASONS_VALUES
);
const shiftNumber = Number.parseInt(highSeasonStartOption.label, 10) - 2;
const payments = seasonsTools.generateSeasonsPayments(
leasingPeriod,
@ -439,7 +438,7 @@ export default function paymentsReactions(
);
const rows: Row[] = payments.map((value, i) => ({
value,
status: i < SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled',
status: i < seasonsConstants.SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled',
}));
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
@ -461,7 +460,7 @@ export default function paymentsReactions(
reaction(
() => {
const payments = toJS($tables.payments.values);
const seasons = payments.slice(1, SEASONS_PERIOD_NUMBER + 1);
const seasons = payments.slice(1, seasonsConstants.SEASONS_PERIOD_NUMBER + 1);
return seasons;
},
@ -495,7 +494,7 @@ export default function paymentsReactions(
const rows: Row[] = payments.map((value, i) => ({
value,
status: i < SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled',
status: i < seasonsConstants.SEASONS_PERIOD_NUMBER ? 'Default' : 'Disabled',
}));
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');