v5
This commit is contained in:
parent
28c20eda62
commit
cad96a0dcd
112
index.html
112
index.html
@ -112,6 +112,7 @@ th{background:var(--gray-100);font-weight:600}
|
|||||||
<h3>Результаты расчета</h3>
|
<h3>Результаты расчета</h3>
|
||||||
<div id="resultsList"></div>
|
<div id="resultsList"></div>
|
||||||
<div id="totalResult" class="total"></div>
|
<div id="totalResult" class="total"></div>
|
||||||
|
<button class="btn" onclick="exportToExcel()" style="margin-top:16px">Выгрузить в Excel</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@ -119,6 +120,7 @@ th{background:var(--gray-100);font-weight:600}
|
|||||||
<script src="https://cdn.sheetjs.com/xlsx-0.20.0/package/dist/xlsx.full.min.js"></script>
|
<script src="https://cdn.sheetjs.com/xlsx-0.20.0/package/dist/xlsx.full.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
let workers = [];
|
let workers = [];
|
||||||
|
let originalData = []; // Store original Excel data for export
|
||||||
|
|
||||||
function addWorker() {
|
function addWorker() {
|
||||||
const fullName = document.getElementById('fullName').value;
|
const fullName = document.getElementById('fullName').value;
|
||||||
@ -179,6 +181,9 @@ function loadFromFile() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store original data for export
|
||||||
|
originalData = jsonData;
|
||||||
|
|
||||||
// Find header row index (look for "ФИО" in any cell)
|
// Find header row index (look for "ФИО" in any cell)
|
||||||
let headerRowIndex = -1;
|
let headerRowIndex = -1;
|
||||||
for (let i = 0; i < Math.min(5, jsonData.length); i++) {
|
for (let i = 0; i < Math.min(5, jsonData.length); i++) {
|
||||||
@ -373,15 +378,116 @@ function displayResults(results, totalBonus) {
|
|||||||
<strong>${r.fullName}</strong><br>
|
<strong>${r.fullName}</strong><br>
|
||||||
<small>${r.isExcluded ?
|
<small>${r.isExcluded ?
|
||||||
`Исключен: ${r.excludedReason}` :
|
`Исключен: ${r.excludedReason}` :
|
||||||
`Включен: ${r.includedDays} дней (пересчет с ${r.probationEndDate}), оклад ${r.recalculatedSalary.toLocaleString('ru-RU')} ₽`
|
`Включен: ${r.includedDays} дней (пересчет с ${r.probationEndDate}), оклад ${r.recalculatedSalary.toLocaleString('ru-RU')} ₸`
|
||||||
}</small>
|
}</small>
|
||||||
</div>
|
</div>
|
||||||
<div>${r.isExcluded ? '—' : r.recalculatedSalary.toLocaleString('ru-RU') + ' ₽'}</div>
|
<div>${r.isExcluded ? '—' : r.recalculatedSalary.toLocaleString('ru-RU') + ' ₸'}</div>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
|
|
||||||
totalResult.innerHTML = `Итого к выплате: ${totalBonus.toLocaleString('ru-RU')} ₽`;
|
totalResult.innerHTML = `Итого к выплате: ${totalBonus.toLocaleString('ru-RU')} ₸`;
|
||||||
resultsDiv.style.display = 'block';
|
resultsDiv.style.display = 'block';
|
||||||
|
|
||||||
|
// Store results for export
|
||||||
|
window.lastResults = results;
|
||||||
|
}
|
||||||
|
|
||||||
|
function exportToExcel() {
|
||||||
|
if (!window.lastResults || window.lastResults.length === 0) {
|
||||||
|
alert('Сначала выполните расчет');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (originalData.length === 0) {
|
||||||
|
alert('Нет исходных данных для экспорта');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = window.lastResults;
|
||||||
|
|
||||||
|
// Create new workbook
|
||||||
|
const wb = XLSX.utils.book_new();
|
||||||
|
|
||||||
|
// Prepare data for export
|
||||||
|
// Start with original data (header + data rows)
|
||||||
|
const exportData = [];
|
||||||
|
|
||||||
|
// Find header row index
|
||||||
|
let headerRowIndex = 0;
|
||||||
|
for (let i = 0; i < Math.min(5, originalData.length); i++) {
|
||||||
|
const row = originalData[i];
|
||||||
|
if (row && row.some(cell => cell && cell.toString().includes('ФИО'))) {
|
||||||
|
headerRowIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add header rows (before actual data header)
|
||||||
|
for (let i = 0; i <= headerRowIndex; i++) {
|
||||||
|
const row = originalData[i] ? [...originalData[i]] : [];
|
||||||
|
if (i === headerRowIndex) {
|
||||||
|
// Add new column headers to the header row
|
||||||
|
row.push('Факт-дни (перерасчет)', 'Оклад факт (перерасчет)', 'Примечание');
|
||||||
|
}
|
||||||
|
exportData.push(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add data rows with results
|
||||||
|
const dataRows = originalData.slice(headerRowIndex + 1);
|
||||||
|
|
||||||
|
for (let i = 0; i < dataRows.length; i++) {
|
||||||
|
const row = dataRows[i] ? [...dataRows[i]] : [];
|
||||||
|
|
||||||
|
// Find matching result by worker name (column 1)
|
||||||
|
const workerName = row[1] ? row[1].toString().trim() : '';
|
||||||
|
const result = results.find(r => r.fullName === workerName);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
if (result.isExcluded) {
|
||||||
|
row.push(0, 0, `Исключен: ${result.excludedReason}`);
|
||||||
|
} else {
|
||||||
|
row.push(
|
||||||
|
result.includedDays,
|
||||||
|
result.recalculatedSalary,
|
||||||
|
`Пересчет с ${result.probationEndDate}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
row.push('', '', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
exportData.push(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create worksheet
|
||||||
|
const ws = XLSX.utils.aoa_to_sheet(exportData);
|
||||||
|
|
||||||
|
// Set column widths
|
||||||
|
ws['!cols'] = [
|
||||||
|
{wch: 15}, // Табельный номер
|
||||||
|
{wch: 30}, // ФИО
|
||||||
|
{wch: 25}, // Штатная должность
|
||||||
|
{wch: 10}, // Грейд
|
||||||
|
{wch: 15}, // МВЗ
|
||||||
|
{wch: 20}, // ОрганизационнЕдиница
|
||||||
|
{wch: 25}, // Текст Орг.Единицы
|
||||||
|
{wch: 12}, // Факт-дни
|
||||||
|
{wch: 15}, // Оклад по ШР
|
||||||
|
{wch: 15}, // Оклад факт
|
||||||
|
{wch: 15}, // ДатаВзыскания
|
||||||
|
{wch: 20}, // ВидВзыскания
|
||||||
|
{wch: 15}, // ДатаПриема
|
||||||
|
{wch: 18}, // Факт-дни (перерасчет)
|
||||||
|
{wch: 18}, // Оклад факт (перерасчет)
|
||||||
|
{wch: 30} // Примечание
|
||||||
|
];
|
||||||
|
|
||||||
|
// Add worksheet to workbook
|
||||||
|
XLSX.utils.book_append_sheet(wb, ws, 'Результат');
|
||||||
|
|
||||||
|
// Generate file and download
|
||||||
|
const fileName = `Премии_${new Date().toISOString().slice(0, 10)}.xlsx`;
|
||||||
|
XLSX.writeFile(wb, fileName);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user