tables/payments: аннуитет
This commit is contained in:
parent
b00cc58c0e
commit
eb7dc997e4
@ -1,45 +1,70 @@
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import { reaction, toJS } from 'mobx';
|
||||
import type { QueryClient } from '@tanstack/react-query';
|
||||
import { reaction } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
import type { Row } from 'stores/tables/payments/types';
|
||||
|
||||
export default function paymentsReactions(store: RootStore, apolloClient: ApolloClient<object>) {
|
||||
export default function paymentsReactions(
|
||||
store: RootStore,
|
||||
apolloClient: ApolloClient<object>,
|
||||
queryClient: QueryClient
|
||||
) {
|
||||
const { $calculation, $tables } = store;
|
||||
|
||||
/**
|
||||
* При изменении срока лизинга регулируем длину таблицы платежей
|
||||
*/
|
||||
reaction(
|
||||
() => $calculation.$values.getValue('leasingPeriod'),
|
||||
(leasingPeriod) => {
|
||||
if (leasingPeriod) {
|
||||
$tables.payments.setValues(
|
||||
Array.from(
|
||||
{
|
||||
length: leasingPeriod,
|
||||
},
|
||||
() => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
fireImmediately: true,
|
||||
() => $calculation.getElementValue('tbxFirstPaymentPerc'),
|
||||
(firstPaymentPerc) => {
|
||||
$tables.payments.setValue(0, firstPaymentPerc);
|
||||
}
|
||||
);
|
||||
|
||||
reaction(
|
||||
() => $calculation.getElementValue('tbxLastPaymentPerc'),
|
||||
(lastPaymentPerc) => {
|
||||
const paymentsLength = $tables.payments.values.length;
|
||||
$tables.payments.setValue(paymentsLength - 1, lastPaymentPerc);
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Проверяем платежи на 0
|
||||
* Аннуитет
|
||||
*/
|
||||
const errorText = 'Значения должны быть больше 0';
|
||||
let removeError: () => void;
|
||||
|
||||
reaction(
|
||||
() => toJS($tables.payments.values),
|
||||
(values) => {
|
||||
if (values.includes(0)) {
|
||||
removeError = $tables.payments.validation.addError(errorText);
|
||||
} else {
|
||||
removeError();
|
||||
() => {
|
||||
const graphType = $calculation.getElementValue('radioGraphType');
|
||||
const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod');
|
||||
|
||||
return {
|
||||
graphType,
|
||||
leasingPeriod,
|
||||
};
|
||||
},
|
||||
({ graphType, leasingPeriod }) => {
|
||||
if (graphType === 100_000_000) {
|
||||
const middleValues: Row[] = Array.from(
|
||||
{
|
||||
length: leasingPeriod - 2,
|
||||
},
|
||||
() => ({
|
||||
value: 100,
|
||||
status: 'Disabled',
|
||||
})
|
||||
);
|
||||
|
||||
const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc');
|
||||
const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');
|
||||
|
||||
$tables.payments.setRows([
|
||||
{
|
||||
value: firstPaymentPerc,
|
||||
status: 'Disabled',
|
||||
},
|
||||
...middleValues,
|
||||
{
|
||||
value: lastPaymentPerc,
|
||||
status: 'Disabled',
|
||||
},
|
||||
]);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -4,11 +4,7 @@ import { makeAutoObservable, observable, reaction } from 'mobx';
|
||||
|
||||
import type RootStore from 'stores/root';
|
||||
import Validation from '../validation';
|
||||
|
||||
type Row = {
|
||||
value: number;
|
||||
status: Status;
|
||||
};
|
||||
import type { Row } from './types';
|
||||
|
||||
export default class PaymentsTable {
|
||||
root: RootStore;
|
||||
|
||||
6
stores/tables/payments/types.ts
Normal file
6
stores/tables/payments/types.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import type { Status } from 'Elements/types';
|
||||
|
||||
export type Row = {
|
||||
value: number;
|
||||
status: Status;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user