diff --git a/apps/web/process/payments/reactions.ts b/apps/web/process/payments/reactions.ts index 68d749a..c215858 100644 --- a/apps/web/process/payments/reactions.ts +++ b/apps/web/process/payments/reactions.ts @@ -341,7 +341,7 @@ export default function paymentsReactions({ store }: ReactionsContext) { }, ]; - if (!$process.has('LoadKP') && degressionType !== 100_000_007) { + if (!$process.has('LoadKP')) { $tables.payments.setValues(rows.map((row) => row.value)); } @@ -350,6 +350,48 @@ export default function paymentsReactions({ store }: ReactionsContext) { } ); + makeDisposable( + () => + reaction( + () => { + const graphType = $calculation.element('radioGraphType').getValue(); + const payments = toJS($tables.payments.values); + const degressionType = $calculation.element('selectSeasonType').getValue(); + + return { + degressionType, + graphType, + payments, + }; + }, + (nextParams, prevParams) => { + if (nextParams.graphType === 100_000_001 && nextParams.degressionType === 100_000_007) { + const changes = difference(nextParams.payments, prevParams.payments); + + if (changes === null || changes.length > 1) return; + + const [changeIndex] = changes; + const value = nextParams.payments[changeIndex]; + const payments = nextParams.payments.slice(1, -1).map((payment, i) => { + if (i <= changeIndex - 2) return payment; + + return value; + }); + + const firstPaymentPerc = $calculation.element('tbxFirstPaymentPerc').getValue(); + const lastPaymentPerc = $calculation.element('tbxLastPaymentPerc').getValue(); + + $tables.payments.setValues([firstPaymentPerc, ...payments, lastPaymentPerc]); + } + }, + { + delay: 50, + equals: comparer.structural, + } + ), + () => $process.has('LoadKP') + ); + /** * Сезонный */