v4
This commit is contained in:
parent
93ce22780f
commit
28c20eda62
50
index.html
50
index.html
@ -313,35 +313,50 @@ function calculateBonus() {
|
|||||||
probationEndDate.setMonth(probationEndDate.getMonth() + 1);
|
probationEndDate.setMonth(probationEndDate.getMonth() + 1);
|
||||||
|
|
||||||
const [reportYear, reportMonth] = worker.reportMonth.split('-').map(Number);
|
const [reportYear, reportMonth] = worker.reportMonth.split('-').map(Number);
|
||||||
|
const reportStartDate = new Date(reportYear, reportMonth - 1, 1);
|
||||||
const reportEndDate = new Date(reportYear, reportMonth, 0);
|
const reportEndDate = new Date(reportYear, reportMonth, 0);
|
||||||
|
const daysInMonth = reportEndDate.getDate();
|
||||||
|
|
||||||
const isProbationEnded = probationEndDate <= reportEndDate;
|
|
||||||
|
|
||||||
let includedDays = 0;
|
let includedDays = 0;
|
||||||
let bonusAmount = 0;
|
let recalculatedSalary = 0;
|
||||||
let excludedReason = '';
|
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])}`;
|
excludedReason = `Испытательный срок до ${formatDate(probationEndDate.toISOString().split('T')[0])}`;
|
||||||
} else {
|
} else {
|
||||||
const daysInMonth = reportEndDate.getDate();
|
// Calculate days after probation ends
|
||||||
const daysBeforeProbation = Math.max(0, Math.ceil((probationEndDate - new Date(reportYear, reportMonth-1, 1)) / (1000*60*60*24)));
|
let daysAfterProbation;
|
||||||
includedDays = daysInMonth - daysBeforeProbation;
|
|
||||||
|
|
||||||
const dailyRate = worker.salary / daysInMonth;
|
if (probationEndDate <= reportStartDate) {
|
||||||
bonusAmount = dailyRate * includedDays;
|
// 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({
|
results.push({
|
||||||
...worker,
|
...worker,
|
||||||
isProbationEnded,
|
isExcluded,
|
||||||
includedDays,
|
includedDays,
|
||||||
bonusAmount,
|
recalculatedSalary,
|
||||||
excludedReason,
|
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);
|
displayResults(results, totalBonus);
|
||||||
@ -353,12 +368,15 @@ function displayResults(results, totalBonus) {
|
|||||||
const totalResult = document.getElementById('totalResult');
|
const totalResult = document.getElementById('totalResult');
|
||||||
|
|
||||||
resultsList.innerHTML = results.map(r => `
|
resultsList.innerHTML = results.map(r => `
|
||||||
<div class="result-item ${r.isProbationEnded ? 'included' : 'excluded'}">
|
<div class="result-item ${r.isExcluded ? 'excluded' : 'included'}">
|
||||||
<div>
|
<div>
|
||||||
<strong>${r.fullName}</strong><br>
|
<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>
|
||||||
<div>${r.isProbationEnded ? r.bonusAmount.toLocaleString('ru-RU') + ' ₽' : '—'}</div>
|
<div>${r.isExcluded ? '—' : r.recalculatedSalary.toLocaleString('ru-RU') + ' ₽'}</div>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user