fix kasko result sum

request: use tbxInsFranchise value
reaction: reset kasko results on change tbxInsFranchise
This commit is contained in:
vchikalkin 2023-05-22 17:16:15 +03:00
parent 9bc1ffd093
commit 3087bc7d34
3 changed files with 28 additions and 3 deletions

View File

@ -27,7 +27,17 @@ export function Kasko() {
return {
enabled: false,
initialData: { ...row, error: '', kaskoSum: 0, sum: 0 },
initialData: {
...row,
error: '',
kaskoSum: 0,
paymentPeriods: [
{
kaskoSum: 0,
},
],
sum: 0,
},
queryFn: async (context: QueryFunctionContext) => {
const payload = await makeEltKaskoRequest({ apolloClient, store }, row);
const res = await getEltKasko(payload, context);
@ -43,6 +53,7 @@ export function Kasko() {
});
async function handleOnClick() {
const values = $calculation.$values.getValues();
const fetchingRows = rows.map((x) => ({ ...x, status: 'fetching', sum: 0 }));
$tables.elt.kasko.setRows(fetchingRows);
@ -57,6 +68,7 @@ export function Kasko() {
skCalcId,
totalFranchise = 0,
requestId,
paymentPeriods,
} = res.data;
let { error } = res.data;
@ -97,7 +109,7 @@ export function Kasko() {
requestId,
skCalcId,
status: error ? 'error' : null,
sum: kaskoSum,
sum: values.leasingPeriod <= 16 ? kaskoSum : paymentPeriods.at(0)?.kaskoSum || 0,
totalFranchise,
});
}

View File

@ -439,7 +439,7 @@ export async function makeEltKaskoRequest(
outsideRoadsSpecified = true;
}
const franchise = row.totalFranchise;
const franchise = $calculation.element('tbxInsFranchise').getValue();
const franchiseSpecified = getSpecified(franchise);
let puuMark = '';

View File

@ -54,6 +54,19 @@ export default function reactions(context: ProcessContext) {
}
);
disposableReaction(
() => $process.has('ELT') || $process.has('LoadKP'),
() => $calculation.element('tbxInsFranchise').getValue(),
async () => {
const initialValues = await init();
$tables.elt.kasko.setRows(initialValues.kasko);
},
{
delay: 10,
}
);
disposableReaction(
() => $process.has('ELT') || $process.has('LoadKP'),
() => {