This commit is contained in:
Dauren777 2026-06-19 06:49:49 +00:00
parent 93ce22780f
commit 28c20eda62

View File

@ -313,35 +313,50 @@ function calculateBonus() {
probationEndDate.setMonth(probationEndDate.getMonth() + 1);
const [reportYear, reportMonth] = worker.reportMonth.split('-').map(Number);
const reportStartDate = new Date(reportYear, reportMonth - 1, 1);
const reportEndDate = new Date(reportYear, reportMonth, 0);
const isProbationEnded = probationEndDate <= reportEndDate;
const daysInMonth = reportEndDate.getDate();
let includedDays = 0;
let bonusAmount = 0;
let recalculatedSalary = 0;
let excludedReason = '';
let isExcluded = false;
if (!isProbationEnded) {
// Check if probation ends after the report month
if (probationEndDate > reportEndDate) {
isExcluded = true;
excludedReason = `Испытательный срок до ${formatDate(probationEndDate.toISOString().split('T')[0])}`;
} else {
const daysInMonth = reportEndDate.getDate();
const daysBeforeProbation = Math.max(0, Math.ceil((probationEndDate - new Date(reportYear, reportMonth-1, 1)) / (1000*60*60*24)));
includedDays = daysInMonth - daysBeforeProbation;
// Calculate days after probation ends
let daysAfterProbation;
const dailyRate = worker.salary / daysInMonth;
bonusAmount = dailyRate * includedDays;
if (probationEndDate <= reportStartDate) {
// Probation ended before the report month started - full month
daysAfterProbation = daysInMonth;
} else {
// Probation ends during the report month
const probationEndDay = probationEndDate.getDate();
daysAfterProbation = daysInMonth - probationEndDay + 1;
}
// Recalculate worked days and salary proportionally
includedDays = Math.round((worker.workedDays / daysInMonth) * daysAfterProbation * 100) / 100;
recalculatedSalary = Math.round((worker.salary / daysInMonth) * daysAfterProbation * 100) / 100;
}
results.push({
...worker,
isProbationEnded,
isExcluded,
includedDays,
bonusAmount,
recalculatedSalary,
excludedReason,
probationEndDate: formatDate(probationEndDate.toISOString().split('T')[0])
probationEndDate: formatDate(probationEndDate.toISOString().split('T')[0]),
daysAfterProbation: isExcluded ? 0 : (probationEndDate <= reportStartDate ? daysInMonth : daysInMonth - probationEndDate.getDate() + 1)
});
totalBonus += bonusAmount;
if (!isExcluded) {
totalBonus += recalculatedSalary;
}
});
displayResults(results, totalBonus);
@ -353,12 +368,15 @@ function displayResults(results, totalBonus) {
const totalResult = document.getElementById('totalResult');
resultsList.innerHTML = results.map(r => `
<div class="result-item ${r.isProbationEnded ? 'included' : 'excluded'}">
<div class="result-item ${r.isExcluded ? 'excluded' : 'included'}">
<div>
<strong>${r.fullName}</strong><br>
<small>${r.isProbationEnded ? `Включен: ${r.includedDays} дней` : `Исключен: ${r.excludedReason}`}</small>
<small>${r.isExcluded ?
`Исключен: ${r.excludedReason}` :
`Включен: ${r.includedDays} дней (пересчет с ${r.probationEndDate}), оклад ${r.recalculatedSalary.toLocaleString('ru-RU')} ₽`
}</small>
</div>
<div>${r.isProbationEnded ? r.bonusAmount.toLocaleString('ru-RU') + ' ₽' : '—'}</div>
<div>${r.isExcluded ? '—' : r.recalculatedSalary.toLocaleString('ru-RU') + ' ₽'}</div>
</div>
`).join('');