tables/payments: Дегрессия
This commit is contained in:
parent
326257cd7c
commit
2b6960de45
@ -1,6 +1,41 @@
|
||||
import { alphabetical } from 'radash/dist/array';
|
||||
import type { CalculationOptions } from 'stores/calculation/options/types';
|
||||
|
||||
export const selectSeasonType = [
|
||||
{
|
||||
label: '6/6',
|
||||
value: 100_000_000,
|
||||
},
|
||||
{
|
||||
label: '8/4',
|
||||
value: 100_000_001,
|
||||
},
|
||||
{
|
||||
label: '4/4/4',
|
||||
value: 100_000_002,
|
||||
},
|
||||
{
|
||||
label: 'Гибкая дегрессия',
|
||||
value: 100_000_007,
|
||||
},
|
||||
{
|
||||
label: '100.50.25',
|
||||
value: 100_000_003,
|
||||
},
|
||||
{
|
||||
label: '100.30.10',
|
||||
value: 100_000_004,
|
||||
},
|
||||
{
|
||||
label: '100.70.40',
|
||||
value: 100_000_005,
|
||||
},
|
||||
{
|
||||
label: '100.7.3',
|
||||
value: 100_000_006,
|
||||
},
|
||||
];
|
||||
|
||||
const defaultOptions: CalculationOptions = {
|
||||
radioLastPaymentRule: [
|
||||
{
|
||||
@ -51,40 +86,7 @@ const defaultOptions: CalculationOptions = {
|
||||
},
|
||||
],
|
||||
|
||||
selectSeasonType: [
|
||||
{
|
||||
label: '6/6',
|
||||
value: 100_000_000,
|
||||
},
|
||||
{
|
||||
label: '8/4',
|
||||
value: 100_000_001,
|
||||
},
|
||||
{
|
||||
label: '4/4/4',
|
||||
value: 100_000_002,
|
||||
},
|
||||
{
|
||||
label: 'Гибкая дегрессия',
|
||||
value: 100_000_007,
|
||||
},
|
||||
{
|
||||
label: '100.50.25',
|
||||
value: 100_000_003,
|
||||
},
|
||||
{
|
||||
label: '100.30.10',
|
||||
value: 100_000_004,
|
||||
},
|
||||
{
|
||||
label: '100.70.40',
|
||||
value: 100_000_005,
|
||||
},
|
||||
{
|
||||
label: '100.7.3',
|
||||
value: 100_000_006,
|
||||
},
|
||||
],
|
||||
selectSeasonType,
|
||||
|
||||
selectHighSeasonStart: Array.from(
|
||||
{
|
||||
|
||||
@ -23,7 +23,7 @@ const defaultValues: CalculationValues = {
|
||||
balanceHolder: 100_000_001,
|
||||
graphType: 100_000_000,
|
||||
parmentsDecreasePercent: 94,
|
||||
seasonType: 100_000_000,
|
||||
seasonType: null,
|
||||
highSeasonStart: 100_000_000,
|
||||
comissionPerc: 0,
|
||||
comissionRub: 0,
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
/* eslint-disable function-paren-newline */
|
||||
/* 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 { reaction, toJS } from 'mobx';
|
||||
import { sort } from 'radash/dist/array';
|
||||
import type RootStore from 'stores/root';
|
||||
@ -207,4 +210,131 @@ export default function paymentsReactions(
|
||||
} else if (removeError) removeError();
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Дегрессия
|
||||
*/
|
||||
const mapGraphTypeToSeasonTypes: { [key: number]: Array<number> } = {
|
||||
100_000_001: [100_000_003, 100_000_004, 100_000_005, 100_000_006, 100_000_007],
|
||||
100_000_003: [100_000_000, 100_000_001, 100_000_002],
|
||||
};
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
const graphType = $calculation.getElementValue('radioGraphType');
|
||||
|
||||
return graphType;
|
||||
},
|
||||
(graphType) => {
|
||||
if (!graphType) {
|
||||
$calculation.setElementOptions('selectSeasonType', []);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const allowedSeasonTypes = mapGraphTypeToSeasonTypes[graphType];
|
||||
const selectSeasonTypeOptions = selectSeasonType.filter((option) =>
|
||||
allowedSeasonTypes.includes(option.value)
|
||||
);
|
||||
$calculation.setElementOptions('selectSeasonType', selectSeasonTypeOptions);
|
||||
}
|
||||
);
|
||||
|
||||
const degressionSteps: { [key: number]: Array<number> } = {
|
||||
100_000_003: [100, 50, 25],
|
||||
100_000_004: [100, 30, 10],
|
||||
100_000_005: [100, 70, 40],
|
||||
100_000_006: [100, 7, 3],
|
||||
};
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
const degressionType = $calculation.getElementValue('selectSeasonType');
|
||||
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
|
||||
const graphType = $calculation.getElementValue('radioGraphType');
|
||||
|
||||
return {
|
||||
degressionType,
|
||||
leasingPeriod,
|
||||
graphType,
|
||||
};
|
||||
},
|
||||
({ degressionType, leasingPeriod, graphType }) => {
|
||||
if (graphType === 100_000_001) {
|
||||
let payments: Row[] = [];
|
||||
|
||||
switch (degressionType) {
|
||||
case 100_000_007: {
|
||||
const editablePayments: Row[] = Array.from(
|
||||
{
|
||||
length: leasingPeriod - 3,
|
||||
},
|
||||
() => ({
|
||||
value: 100,
|
||||
status: 'Default',
|
||||
})
|
||||
);
|
||||
|
||||
payments = [
|
||||
{
|
||||
value: 100,
|
||||
status: 'Disabled',
|
||||
},
|
||||
...editablePayments,
|
||||
];
|
||||
|
||||
break;
|
||||
}
|
||||
case 100_000_003:
|
||||
case 100_000_004:
|
||||
case 100_000_005:
|
||||
case 100_000_006: {
|
||||
const [step1, step2, step3] = degressionSteps[degressionType];
|
||||
const paymentsInStep = Math.ceil((leasingPeriod - 2) / 3);
|
||||
|
||||
payments = Array.from(
|
||||
{
|
||||
length: leasingPeriod - 2,
|
||||
},
|
||||
(_v, i) => {
|
||||
let value = step3;
|
||||
|
||||
if (i <= paymentsInStep * 2 - 1) {
|
||||
value = step2;
|
||||
}
|
||||
|
||||
if (i <= paymentsInStep - 1) {
|
||||
value = step1;
|
||||
}
|
||||
|
||||
return {
|
||||
value,
|
||||
status: 'Disabled',
|
||||
};
|
||||
}
|
||||
);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
|
||||
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
|
||||
|
||||
$tables.payments.setRows([
|
||||
{
|
||||
value: firstPaymentPerc,
|
||||
status: 'Disabled',
|
||||
},
|
||||
...payments,
|
||||
{
|
||||
value: lastPaymentPerc,
|
||||
status: 'Disabled',
|
||||
},
|
||||
]);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ export default class OptionsStore {
|
||||
if (
|
||||
// eslint-disable-next-line operator-linebreak
|
||||
!this.options[elementName]?.length ||
|
||||
this.options[elementName].some((x) => x.value === value)
|
||||
!this.options[elementName].some((x) => x.value === value)
|
||||
) {
|
||||
this.root.$calculation.resetElementValue(elementName);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user