process/payments: extract function generateSeasonPaymentsRows

This commit is contained in:
Chika 2022-10-14 14:00:03 +03:00
parent 600bb1a730
commit de26e39eff

View File

@ -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');