Excel
This commit is contained in:
1 parent
36307faf13
commit
857795165a
2 files changed
+36
-15
No files matched your search
+11
-9
@@ -392,11 +392,11 @@ def export_daily_xlsx():
|
||||
cur = conn.cursor()
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT counting_date, total_count, total_batches,
|
||||
ROUND(CAST(total_count AS FLOAT) / NULLIF(total_batches, 0), 1) as avg_per_batch
|
||||
FROM daily_summaries
|
||||
SELECT counting_date, batch_number, count, start_time, end_time,
|
||||
ROUND((julianday(end_time) - julianday(start_time)) * 24 * 60, 1) as duration_minutes
|
||||
FROM batches
|
||||
WHERE counting_date >= ?
|
||||
ORDER BY counting_date ASC
|
||||
ORDER BY counting_date ASC, batch_number ASC
|
||||
""",
|
||||
(date_from,),
|
||||
)
|
||||
@@ -405,14 +405,16 @@ def export_daily_xlsx():
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "Daily Records"
|
||||
_style_header(ws, [("A", "Date"), ("B", "Total Count"), ("C", "Total Batches"), ("D", "Avg per Batch")])
|
||||
ws.title = "Batch Details"
|
||||
_style_header(ws, [("A", "Date"), ("B", "Batch #"), ("C", "Count"), ("D", "Start Time"), ("E", "End Time"), ("F", "Duration (min)")])
|
||||
|
||||
for r_idx, row in enumerate(rows, 2):
|
||||
ws.cell(row=r_idx, column=1, value=row["counting_date"])
|
||||
ws.cell(row=r_idx, column=2, value=row["total_count"])
|
||||
ws.cell(row=r_idx, column=3, value=row["total_batches"])
|
||||
ws.cell(row=r_idx, column=4, value=row["avg_per_batch"] or 0)
|
||||
ws.cell(row=r_idx, column=2, value=row["batch_number"])
|
||||
ws.cell(row=r_idx, column=3, value=row["count"])
|
||||
ws.cell(row=r_idx, column=4, value=row["start_time"])
|
||||
ws.cell(row=r_idx, column=5, value=row["end_time"])
|
||||
ws.cell(row=r_idx, column=6, value=row["duration_minutes"] or 0)
|
||||
|
||||
_auto_width(ws)
|
||||
filename = f"daily_records_{datetime.now().strftime('%Y%m%d_%H%M%S')}.xlsx"
|
||||
|
||||
@@ -707,7 +707,7 @@
|
||||
<div class="toolbar-group">
|
||||
<input type="date" id="date-filter">
|
||||
<button class="btn btn-primary" onclick="filterByDate()">FILTER</button>
|
||||
<button class="btn btn-ghost" onclick="loadAllDates()">RESET</button>
|
||||
<button class="btn btn-ghost" onclick="resetFilter()">RESET</button>
|
||||
<button class="btn btn-export-btn" onclick="exportDayDetail()">EXPORT EXCEL</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1008,6 +1008,11 @@ async function loadAllDates() {
|
||||
}
|
||||
}
|
||||
|
||||
function resetFilter() {
|
||||
document.getElementById('date-filter').value = '';
|
||||
loadAllDates();
|
||||
}
|
||||
|
||||
function renderDailyTable(dates) {
|
||||
const tbody = document.getElementById('daily-table-body');
|
||||
const currentDate = document.getElementById('current-date').textContent;
|
||||
@@ -1179,12 +1184,26 @@ function hideVideoError() {
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function exportDayDetail() {
|
||||
async function exportDayDetail() {
|
||||
try {
|
||||
const date = document.getElementById('date-filter')?.value;
|
||||
if (date) {
|
||||
window.location.href = `/api/export-day-csv/${date}`;
|
||||
} else {
|
||||
window.location.href = '/api/export-daily-csv';
|
||||
const url = date ? `/api/export-day-csv/${date}` : '/api/export-daily-csv';
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) throw new Error('Export failed');
|
||||
const blob = await res.blob();
|
||||
const disposition = res.headers.get('Content-Disposition');
|
||||
const filename = disposition
|
||||
? decodeURIComponent(disposition.replace(/.*filename="?([^";]+)"?.*/, '$1'))
|
||||
: `export_${date || 'all'}.xlsx`;
|
||||
const a = document.createElement('a');
|
||||
a.href = URL.createObjectURL(blob);
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(a.href);
|
||||
} catch (err) {
|
||||
alert('Export error: ' + err.message);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user