From 048da7947a5e3690b7efb9e743605d95e45f61f7 Mon Sep 17 00:00:00 2001 From: Chika Date: Mon, 3 Oct 2022 14:34:01 +0300 Subject: [PATCH] =?UTF-8?q?tables/payments:=20=D0=A0=D0=B0=D0=B2=D0=BD?= =?UTF-8?q?=D0=BE=D1=83=D0=B1=D1=8B=D0=B2=D0=B0=D1=8E=D1=89=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- process/payments/reactions.ts | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index f1ee5e7..42c4e26 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -71,4 +71,53 @@ export default function paymentsReactions( fireImmediately: true, } ); + + /** + * Равноубывающий + */ + reaction( + () => { + const graphType = $calculation.getElementValue('radioGraphType'); + const leasingPeriod = $calculation.getElementValue('tbxLeasingPeriod'); + const parmentsDecreasePercent = $calculation.getElementValue('tbxParmentsDecreasePercent'); + + return { + graphType, + leasingPeriod, + parmentsDecreasePercent, + }; + }, + ({ graphType, leasingPeriod, parmentsDecreasePercent }) => { + if (graphType === 100_000_002) { + const middleValues: Row[] = Array.from( + { + length: leasingPeriod - 2, + }, + (_, k) => { + const payment = 100 * (parmentsDecreasePercent / 100) ** k; + + return { + value: Number(payment.toFixed(2)), + status: 'Disabled', + }; + } + ); + + const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc'); + const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc'); + + $tables.payments.setRows([ + { + value: firstPaymentPerc, + status: 'Disabled', + }, + ...middleValues, + { + value: lastPaymentPerc, + status: 'Disabled', + }, + ]); + } + } + ); }