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', + }, + ]); + } + } + ); }