49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import { toJS } from 'mobx';
|
|
import notification from 'ui/elements/notification';
|
|
|
|
const key = 'ACTION_CALCULATE';
|
|
const message = 'Ошибка во время расчета графика';
|
|
|
|
/**
|
|
* @param {import('../types').ProcessContext} context
|
|
* @param {*} onCompleted
|
|
*/
|
|
export async function action({ store, trpcClient }) {
|
|
const { $calculation, $tables, $results } = store;
|
|
|
|
$calculation.$status.setStatus('btnCalculate', 'Loading');
|
|
$calculation.$status.setStatus('btnCreateKP', 'Loading');
|
|
$results.clear();
|
|
|
|
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 res = await trpcClient.calculate.calculate.query({
|
|
insurance: { values: insurance },
|
|
payments: { values: payments },
|
|
values,
|
|
});
|
|
|
|
if (res.success === false) {
|
|
notification.error({
|
|
description: res.error,
|
|
key,
|
|
message,
|
|
});
|
|
} else {
|
|
$results.setPayments(res.data.resultPayments);
|
|
$results.setValues(res.data.resultValues);
|
|
$calculation.$values.setValues(res.data.values);
|
|
}
|
|
|
|
$calculation.$status.setStatus('btnCalculate', 'Default');
|
|
$calculation.$status.setStatus('btnCreateKP', 'Default');
|
|
}
|