<?php include __DIR__ . '/../includes/header.php';
if (is_post()) {
  $stmt = db()->prepare("INSERT INTO attendance (employee_id, attendance_date, check_in, check_out, notes, created_at) VALUES (?, ?, ?, ?, ?, ?)");
  $stmt->execute([$_POST['employee_id'], $_POST['attendance_date'], $_POST['check_in'] ?: null, $_POST['check_out'] ?: null, trim($_POST['notes']), now()]);
  audit_log('create', 'attendance', db()->lastInsertId(), 'Alta asistencia');
  set_flash('success', 'Marcación guardada.');
  redirect('attendance/index.php');
}
$item = [];
?>
<div class="form-wrap"><h4>Nueva marcación</h4><form method="post"><?php include __DIR__ . '/form.php'; ?><button class="btn btn-primary">Guardar</button> <a class="btn btn-secondary" href="<?= e(base_url('attendance/index.php')) ?>">Volver</a></form></div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
