add export to Excel

This commit is contained in:
tore 2026-09-03 19:11:19 +00:00
parent 6a3b99ae17
commit 3687fe98ce

View File

@ -87,6 +87,7 @@
<div class="history-actions">
<span class="kt-ai-chip" id="historyCount">0 записей</span>
<button class="kt-ai-btn" data-variant="ghost" onclick="exportCsv()">Выгрузить в Excel</button>
</div>
<div class="kt-ai-table-container">
@ -193,6 +194,28 @@ function clearHistory() {
}
}
function exportCsv() {
const history = getHistory();
if (history.length === 0) {
alert('История пуста — нечего выгружать');
return;
}
const head = ['Дата', 'Оборудование', 'Срок (мес)', 'Количество (шт)', 'Скидка (%)', 'Сумма (₸)'];
const body = history.map(r => [
r.date,
r.equipment,
r.months,
r.quantity,
r.discount,
r.total
].map(v => '"' + String(v ?? '').replace(/"/g, '""') + '"').join(';'));
const csv = '\uFEFF' + [head.join(';'), ...body].join('\n');
const a = document.createElement('a');
a.href = URL.createObjectURL(new Blob([csv], { type: 'text/csv; charset=utf-8' }));
a.download = 'istoriya_arendy.csv';
a.click();
}
function renderHistory() {
const history = getHistory();
const tbody = document.getElementById('historyTable');