35 lines
948 B
TypeScript
35 lines
948 B
TypeScript
import type { ProcessContext } from '../types';
|
|
import { toJS } from 'mobx';
|
|
import notification from 'ui/elements/notification';
|
|
|
|
const key = 'ACTION_CALCULATE';
|
|
const message = 'Ошибка во время расчета графика';
|
|
|
|
export async function action({ store, trpcClient }: ProcessContext) {
|
|
const { $calculation, $tables } = store;
|
|
|
|
const values = $calculation.$values.getValues();
|
|
|
|
const insurance = {
|
|
fingap: toJS($tables.insurance.row('fingap').getValues()),
|
|
kasko: toJS($tables.insurance.row('kasko').getValues()),
|
|
osago: toJS($tables.insurance.row('osago').getValues()),
|
|
};
|
|
|
|
const payments = toJS($tables.payments.values);
|
|
|
|
const { error, success } = await trpcClient.calculate.calculate.query({
|
|
insurance: { values: insurance },
|
|
payments: { values: payments },
|
|
values,
|
|
});
|
|
|
|
if (!success) {
|
|
notification.error({
|
|
description: error,
|
|
key,
|
|
message,
|
|
});
|
|
}
|
|
}
|