37138-vm/export_laporan.php
Flatlogic Bot bb0884a9fc SIAKAD 1.0
2025-12-24 04:07:02 +00:00

62 lines
1.7 KiB
PHP

<?php
ini_set('display_errors', 0); // Disable error display for this script
require_once 'db/config.php';
require_once 'functions.php';
require_once 'libs/SimpleXLSXGen.php';
// Check for required POST data
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['kelas_id'], $_POST['start_date'], $_POST['end_date'])) {
http_response_code(400);
echo "Bad Request: Missing required parameters.";
exit;
}
// Get filter data from POST
$kelas_id = $_POST['kelas_id'];
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
// Fetch the data
$rekap_data = get_rekap_absensi($kelas_id, $start_date, $end_date);
$kelas_info = get_kelas_by_id($kelas_id);
$nama_kelas = $kelas_info ? str_replace(' ', '_', $kelas_info['nama_kelas']) : 'Laporan';
// Prepare data for Excel generation
$data_for_excel = [
[
'<b>NIS</b>',
'<b>Nama Lengkap</b>',
'<b>Hadir</b>',
'<b>Sakit</b>',
'<b>Izin</b>',
'<b>Alpa</b>',
'<b>Total Jam</b>'
]
];
if (empty($rekap_data)) {
$data_for_excel[] = ['Tidak ada data absensi pada periode ini.', '', '', '', '', '', ''];
} else {
foreach ($rekap_data as $row) {
$data_for_excel[] = [
$row['nis'],
$row['nama_lengkap'],
(int)$row['total_hadir'],
(int)$row['total_sakit'],
(int)$row['total_izin'],
(int)$row['total_alpa'],
(int)$row['total_absensi'],
];
}
}
// Generate file name
$filename = "Laporan_Absensi_{$nama_kelas}_{$start_date}_to_{$end_date}.xlsx";
// Generate and download the Excel file
Shuchkin\SimpleXLSXGen::fromArray($data_for_excel)->downloadAs($filename);
exit();