From 3087bc7d34b4647865d23b278d59ef080f707e83 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 22 May 2023 17:16:15 +0300 Subject: [PATCH] fix kasko result sum request: use tbxInsFranchise value reaction: reset kasko results on change tbxInsFranchise --- .../Components/Calculation/Form/ELT/Kasko.tsx | 16 ++++++++++++++-- .../Calculation/Form/ELT/lib/make-request.ts | 2 +- apps/web/process/elt/reactions/common.ts | 13 +++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx index 16f9761..b57974e 100644 --- a/apps/web/Components/Calculation/Form/ELT/Kasko.tsx +++ b/apps/web/Components/Calculation/Form/ELT/Kasko.tsx @@ -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, }); } diff --git a/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts b/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts index 1cb1b1c..00ec0f6 100644 --- a/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts +++ b/apps/web/Components/Calculation/Form/ELT/lib/make-request.ts @@ -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 = ''; diff --git a/apps/web/process/elt/reactions/common.ts b/apps/web/process/elt/reactions/common.ts index c5e2539..8c2fb8b 100644 --- a/apps/web/process/elt/reactions/common.ts +++ b/apps/web/process/elt/reactions/common.ts @@ -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'), () => {