v2
This commit is contained in:
parent
4942cdceb2
commit
3de696a092
115
index.html
115
index.html
@ -52,6 +52,20 @@ th{background:var(--gray-100);font-weight:600}
|
|||||||
<h2>Добавьте работников</h2>
|
<h2>Добавьте работников</h2>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
|
<h3 style="margin-bottom:16px">Загрузка списка работников</h3>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="fileUpload">Загрузите файл (TSV/CSV - разделитель Tab или запятая)</label>
|
||||||
|
<input type="file" id="fileUpload" accept=".tsv,.csv,.txt">
|
||||||
|
<small style="color:var(--gray-500)">Ожидаемые столбцы: Табельный номер, ФИО, Штатная должность, Грейд, МВЗ, ОрганизационнЕдиница, Текст Орг.Единицы, Факт-дни, Оклад по ШР, Оклад факт, ДатаВзыскания, ВидВзыскания, ДатаПриема (формат: ДД.ММ.ГГГГ)</small>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="reportMonth">Отчетный месяц</label>
|
||||||
|
<input type="month" id="reportMonth">
|
||||||
|
</div>
|
||||||
|
<button class="btn-add" onclick="loadFromFile()">Загрузить из файла</button>
|
||||||
|
|
||||||
|
<div style="margin:24px 0;text-align:center;color:var(--gray-500)">— или добавляйте вручную —</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="fullName">ФИО работника</label>
|
<label for="fullName">ФИО работника</label>
|
||||||
<input type="text" id="fullName" placeholder="Иванов Иван Иванович">
|
<input type="text" id="fullName" placeholder="Иванов Иван Иванович">
|
||||||
@ -72,11 +86,6 @@ th{background:var(--gray-100);font-weight:600}
|
|||||||
<input type="number" id="workedDays" placeholder="22">
|
<input type="number" id="workedDays" placeholder="22">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="reportMonth">Отчетный месяц</label>
|
|
||||||
<input type="month" id="reportMonth">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button class="btn-add" onclick="addWorker()">Добавить работника</button>
|
<button class="btn-add" onclick="addWorker()">Добавить работника</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -135,6 +144,102 @@ function addWorker() {
|
|||||||
clearForm();
|
clearForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadFromFile() {
|
||||||
|
const fileInput = document.getElementById('fileUpload');
|
||||||
|
const reportMonth = document.getElementById('reportMonth').value;
|
||||||
|
|
||||||
|
if (!fileInput.files.length) {
|
||||||
|
alert('Выберите файл для загрузки');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!reportMonth) {
|
||||||
|
alert('Укажите отчетный месяц');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = fileInput.files[0];
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
reader.onload = function(e) {
|
||||||
|
const content = e.target.result;
|
||||||
|
const lines = content.split('\n').filter(line => line.trim());
|
||||||
|
|
||||||
|
// Skip header row if exists (check if first line contains "ФИО" or similar)
|
||||||
|
const startIndex = lines[0].includes('ФИО') || lines[0].includes('Табельный') ? 1 : 0;
|
||||||
|
|
||||||
|
let loadedCount = 0;
|
||||||
|
|
||||||
|
for (let i = startIndex; i < lines.length; i++) {
|
||||||
|
const line = lines[i].trim();
|
||||||
|
if (!line) continue;
|
||||||
|
|
||||||
|
// Detect separator: tab or comma
|
||||||
|
const separator = line.includes('\t') ? '\t' : ',';
|
||||||
|
const columns = line.split(separator).map(col => col.trim());
|
||||||
|
|
||||||
|
// Expected structure based on user's columns:
|
||||||
|
// 0: Табельный номер
|
||||||
|
// 1: ФИО
|
||||||
|
// 2: Штатная должность
|
||||||
|
// 3: Грейд
|
||||||
|
// 4: МВЗ
|
||||||
|
// 5: ОрганизационнЕдиница
|
||||||
|
// 6: Текст Орг.Единицы
|
||||||
|
// 7: Факт-дни
|
||||||
|
// 8: Оклад по ШР
|
||||||
|
// 9: Оклад факт
|
||||||
|
// 10: ДатаВзыскания
|
||||||
|
// 11: ВидВзыскания
|
||||||
|
// 12: ДатаПриема
|
||||||
|
|
||||||
|
if (columns.length < 13) {
|
||||||
|
console.log(`Строка ${i+1}: недостаточно столбцов (${columns.length}), пропускаем`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullName = columns[1];
|
||||||
|
const workedDays = parseInt(columns[7]);
|
||||||
|
const salary = parseFloat(columns[9].replace(/\s/g, ''));
|
||||||
|
const hireDateRaw = columns[12];
|
||||||
|
|
||||||
|
// Parse hire date (format: DD.MM.YYYY or YYYY-MM-DD)
|
||||||
|
let hireDate;
|
||||||
|
if (hireDateRaw.includes('.')) {
|
||||||
|
const [day, month, year] = hireDateRaw.split('.');
|
||||||
|
hireDate = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}`;
|
||||||
|
} else if (hireDateRaw.includes('-')) {
|
||||||
|
hireDate = hireDateRaw;
|
||||||
|
} else {
|
||||||
|
console.log(`Строка ${i+1}: неверный формат даты "${hireDateRaw}", пропускаем`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fullName || isNaN(workedDays) || isNaN(salary)) {
|
||||||
|
console.log(`Строка ${i+1}: некорректные данные, пропускаем`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
workers.push({
|
||||||
|
id: Date.now() + i,
|
||||||
|
fullName,
|
||||||
|
hireDate,
|
||||||
|
salary,
|
||||||
|
workedDays,
|
||||||
|
reportMonth
|
||||||
|
});
|
||||||
|
|
||||||
|
loadedCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTable();
|
||||||
|
alert(`Загружено ${loadedCount} работников`);
|
||||||
|
fileInput.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
|
|
||||||
function removeWorker(id) {
|
function removeWorker(id) {
|
||||||
workers = workers.filter(w => w.id !== id);
|
workers = workers.filter(w => w.id !== id);
|
||||||
updateTable();
|
updateTable();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user