diff --git a/index.html b/index.html index d7287dc..c8597da 100644 --- a/index.html +++ b/index.html @@ -64,6 +64,13 @@ +
+ + +
@@ -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);