<?php
require_once __DIR__ . '/../includes/bootstrap.php';
require_login();
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="asistencia.csv"');
$out = fopen('php://output', 'w');
fputcsv($out, ['ID','Empleado','Fecha','Entrada','Salida','Observaciones']);
$stmt = db()->query("SELECT a.id, e.full_name, a.attendance_date, a.check_in, a.check_out, a.notes FROM attendance a JOIN employees e ON e.id = a.employee_id ORDER BY a.id DESC");
foreach ($stmt as $row) {
    fputcsv($out, [$row['id'], $row['full_name'], $row['attendance_date'], $row['check_in'], $row['check_out'], $row['notes']]);
}
fclose($out);
exit;
