diff --git a/index.html b/index.html index 8a52991..d6e6296 100644 --- a/index.html +++ b/index.html @@ -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 daysInMonth = reportEndDate.getDate(); - const isProbationEnded = probationEndDate <= reportEndDate; - 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 => ` -