добавлена выгрузка в CSV

This commit is contained in:
tore 2026-09-04 06:15:53 +00:00
parent cd37571b0c
commit 0d51f0b451

View File

@ -64,6 +64,13 @@
<option value="3">3 месяца назад</option>
</select>
</div>
<div class="kt-ai-field" style="margin:0;min-width:180px">
<label class="kt-ai-label" style="margin-bottom:4px">Экспорт</label>
<button class="kt-ai-btn" data-variant="primary" id="exportBtn" style="width:100%">
<svg class="kt-icon kt-icon-sm" style="margin-right:6px"><use href="design-system/icons/kt-ai-lucide-sprite.svg#download"></use></svg>
Выгрузить в Excel
</button>
</div>
</div>
</div>
@ -291,6 +298,35 @@ function refresh() {
}, 600);
}
function exportToCsv() {
const monthOffset = parseInt(document.getElementById('monthSelect').value) || 0;
const data = loadData();
const monthName = MONTH_NAMES[new Date().getMonth() - monthOffset];
const head = ['Регион', 'План (₸)', 'Факт (₸)', 'Выполнение (%)', 'Статус', 'Сделки'];
const body = data.data.map(d => [
d.region,
d.plan.toString().replace(',', '.'),
d.actual.toString().replace(',', '.'),
d.percent.toString(),
getStatusText(d.status),
d.deals.toString()
]);
const csv = '\uFEFF' + [head.join(';'), ...body.map(row => row.join(';'))].join('\n');
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'prodazhi_' + monthName + '.csv';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
document.getElementById('exportBtn').addEventListener('click', exportToCsv);
document.getElementById('monthSelect').addEventListener('change', function() {
const data = loadData();
renderChart(data.data);