2026-08-05 21:35:22 +03:30
|
|
|
"use strict";
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.calculateCheckRass = calculateCheckRass;
|
2026-08-08 14:55:26 +03:30
|
|
|
const tehran_time_1 = require("./tehran-time");
|
2026-08-05 21:35:22 +03:30
|
|
|
function calculateCheckRass(checks, baseDate = new Date()) {
|
|
|
|
|
if (checks.length === 0) {
|
|
|
|
|
return {
|
|
|
|
|
checkCount: 0,
|
|
|
|
|
totalAmount: 0,
|
|
|
|
|
nearestDueDate: null,
|
|
|
|
|
farthestDueDate: null,
|
|
|
|
|
rassDays: 0,
|
|
|
|
|
rassDate: null,
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-08-08 14:55:26 +03:30
|
|
|
const base = (0, tehran_time_1.tehranCalendarDay)(baseDate);
|
2026-08-05 21:35:22 +03:30
|
|
|
let totalAmount = 0;
|
|
|
|
|
let weightedDays = 0;
|
|
|
|
|
const dueDates = [];
|
|
|
|
|
for (const check of checks) {
|
2026-08-08 14:55:26 +03:30
|
|
|
const due = (0, tehran_time_1.calendarDayOf)(check.dueDate);
|
2026-08-05 21:35:22 +03:30
|
|
|
dueDates.push(due);
|
2026-08-08 14:55:26 +03:30
|
|
|
const days = Math.max(0, (0, tehran_time_1.diffInDays)(base, due));
|
2026-08-05 21:35:22 +03:30
|
|
|
totalAmount += check.amount;
|
|
|
|
|
weightedDays += check.amount * days;
|
|
|
|
|
}
|
|
|
|
|
const rassDays = totalAmount > 0 ? Math.round(weightedDays / totalAmount) : 0;
|
2026-08-08 14:55:26 +03:30
|
|
|
const rassDate = (0, tehran_time_1.addDays)(base, rassDays);
|
2026-08-05 21:35:22 +03:30
|
|
|
dueDates.sort((a, b) => a.getTime() - b.getTime());
|
|
|
|
|
return {
|
|
|
|
|
checkCount: checks.length,
|
|
|
|
|
totalAmount,
|
|
|
|
|
nearestDueDate: dueDates[0]?.toISOString() ?? null,
|
|
|
|
|
farthestDueDate: dueDates[dueDates.length - 1]?.toISOString() ?? null,
|
|
|
|
|
rassDays,
|
|
|
|
|
rassDate: rassDate.toISOString(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
//# sourceMappingURL=check-rass.js.map
|