aggiunti trasferte, export excel, miglioramenti generali

This commit is contained in:
2026-02-04 12:55:04 +01:00
parent 17453f5d13
commit 5f4ef6faee
30 changed files with 1558 additions and 325 deletions

View File

@@ -113,6 +113,77 @@ async function loadOffices() {
// Initial update of office display
updateOfficeDisplay();
// Show export card for Admin/Manager
if (['admin', 'manager'].includes(currentUser.role)) {
const exportCard = document.getElementById('exportCard');
if (exportCard) {
exportCard.style.display = 'block';
// Set defaults (current month)
const today = new Date();
const firstDay = new Date(today.getFullYear(), today.getMonth(), 1);
const lastDay = new Date(today.getFullYear(), today.getMonth() + 1, 0);
document.getElementById('exportStartDate').valueAsDate = firstDay;
document.getElementById('exportEndDate').valueAsDate = lastDay;
document.getElementById('exportBtn').addEventListener('click', handleExport);
}
}
}
async function handleExport() {
const startStr = document.getElementById('exportStartDate').value;
const endStr = document.getElementById('exportEndDate').value;
const officeId = document.getElementById('officeFilter').value;
if (!startStr || !endStr) {
alert('Seleziona le date di inizio e fine');
return;
}
// Construct URL
let url = `/api/reports/team-export?start_date=${startStr}&end_date=${endStr}`;
if (officeId) {
url += `&office_id=${officeId}`;
}
try {
const btn = document.getElementById('exportBtn');
const originalText = btn.innerHTML;
btn.disabled = true;
btn.textContent = 'Generazione...';
// Use fetch directly to handle blob
const token = api.getToken();
const headers = token ? { 'Authorization': `Bearer ${token}` } : {};
const response = await fetch(url, { headers });
if (response.ok) {
const blob = await response.blob();
const downloadUrl = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = `report_presenze_${startStr}_${endStr}.xlsx`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(downloadUrl);
a.remove();
} else {
const err = await response.json();
alert('Errore export: ' + (err.detail || 'Sconosciuto'));
}
btn.disabled = false;
btn.innerHTML = originalText;
} catch (e) {
console.error(e);
alert('Errore durante l\'export');
document.getElementById('exportBtn').disabled = false;
document.getElementById('exportBtn').textContent = 'Esporta Excel';
}
}
function getDateRange() {