diff --git a/process/payments/reactions.ts b/process/payments/reactions.ts index 07043c9..d9efdf2 100644 --- a/process/payments/reactions.ts +++ b/process/payments/reactions.ts @@ -403,6 +403,20 @@ export default function paymentsReactions( } ); + function generateSeasonPaymentsRows(seasonType: number, shiftNumber: number, payments: number[]) { + const shiftedPeriods = new Set( + seasonsConstants.SEASONS_PERIODS[seasonType].map( + (position) => (position + shiftNumber) % seasonsConstants.SEASONS_PERIOD_NUMBER + ) + ); + const rows: Row[] = payments.map((value, i) => ({ + value, + status: shiftedPeriods.has(i) ? 'Default' : 'Disabled', + })); + + return rows; + } + reaction( () => { const seasonType = $calculation.getElementValue('selectSeasonType'); @@ -434,15 +448,7 @@ export default function paymentsReactions( leasingPeriod, shift(seasons, shiftNumber) ); - const shiftedPeriods = new Set( - seasonsConstants.SEASONS_PERIODS[seasonType].map( - (position) => (position + shiftNumber) % seasonsConstants.SEASONS_PERIOD_NUMBER - ) - ); - const rows: Row[] = payments.map((value, i) => ({ - value, - status: shiftedPeriods.has(i) ? 'Default' : 'Disabled', - })); + const rows: Row[] = generateSeasonPaymentsRows(seasonType, shiftNumber, payments); const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc'); const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc'); @@ -494,15 +500,7 @@ export default function paymentsReactions( leasingPeriod, shift(seasons, shiftNumber) ); - const shiftedPeriods = new Set( - seasonsConstants.SEASONS_PERIODS[seasonType].map( - (position) => (position + shiftNumber) % seasonsConstants.SEASONS_PERIOD_NUMBER - ) - ); - const rows: Row[] = payments.map((value, i) => ({ - value, - status: shiftedPeriods.has(i) ? 'Default' : 'Disabled', - })); + const rows: Row[] = generateSeasonPaymentsRows(seasonType, shiftNumber, payments); const firstPaymentPerc = $calculation.getElementValue('tbxFirstPaymentPerc'); const lastPaymentPerc = $calculation.getElementValue('tbxLastPaymentPerc');