<?php
require_once __DIR__ . '/../includes/bootstrap.php'; require_login();
$rows = [];
$stmt = db()->query("SELECT l.employee_id, l.leave_type, l.start_date, l.end_date, l.status, e.full_name, e.hire_date FROM leaves_requests l JOIN employees e ON e.id=l.employee_id ORDER BY l.id DESC");
foreach ($stmt as $r) { $vac = vacation_balance(['id'=>$r['employee_id'],'hire_date'=>$r['hire_date']]); $rows[] = [$r['full_name'],$r['leave_type'],$r['start_date'],$r['end_date'],leave_days_between($r['start_date'],$r['end_date']),$r['status'],$vac['pending']]; }
download_xlsx('permisos_vacaciones.xlsx', ['Empleado','Tipo','Desde','Hasta','Días','Estado','Saldo vacaciones'], $rows);
