Tambah rekap & ekspor laporan per kegiatan; "hari ini" selalu WIB

- Halaman rekap per bulan / seluruh periode: kelengkapan, hari terisi/belum,
  tabel laporan per tanggal beserta komentar
- Unduh Excel (Ringkasan, Rekap Harian, Detail Laporan) via exceljs
- Tata letak cetak A4 untuk simpan PDF dari browser
- TZ default Asia/Jakarta agar batas tanggal laporan tidak bergeser di server UTC

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 14:47:22 +07:00
co-authored by Claude Opus 5.5
parent 425eb704b4
commit 9dee30cf5a
9 changed files with 2613 additions and 2 deletions
+41
View File
@@ -9,6 +9,7 @@ const {
} = require('../access');
const { handleUpload, removeFiles, UPLOAD_DIR, MAX_FILES, MAX_SIZE_MB } = require('../upload');
const cal = require('../calendar');
const rekap = require('../rekap');
const MAX_DESC = 5000;
@@ -105,6 +106,46 @@ router.get('/kegiatan/:id', loadKegiatan, (req, res) => {
});
});
/* ---------- Rekap & ekspor ---------- */
function rekapBulan(req, k, t) {
const q = req.query.bulan || '';
if (q === 'semua' || /^\d{4}-(0[1-9]|1[0-2])$/.test(q)) return q;
return cal.defaultMonth(k, t);
}
// Daftar bulan dalam periode kegiatan (sampai bulan ini) untuk pilihan rekap.
function periodMonths(k, t) {
const p = cal.period(k);
const last = cal.monthKey(p.end && p.end < t ? p.end : (t < p.start ? p.start : t));
const months = [];
for (let m = cal.monthKey(p.start); m <= last && months.length < 120; m = cal.shiftMonth(m, 1)) months.push(m);
return months.reverse().map((m) => ({ key: m, label: cal.monthLabel(m) }));
}
router.get('/kegiatan/:id/rekap', loadKegiatan, (req, res) => {
const k = req.kegiatan;
const t = today();
const bulan = rekapBulan(req, k, t);
res.render('rekap', {
title: 'Rekap ' + k.nama, k, bulan, months: periodMonths(k, t),
dosen: getDosenKegiatan(k.id), rekap: rekap.build(k, bulan, t), STATUS_LABEL: rekap.STATUS_LABEL,
});
});
router.get('/kegiatan/:id/rekap.xlsx', loadKegiatan, async (req, res, next) => {
try {
const k = req.kegiatan;
const t = today();
const bulan = rekapBulan(req, k, t);
const buf = await rekap.toXlsx(k, rekap.build(k, bulan, t), getDosenKegiatan(k.id));
const slug = k.nama.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '').slice(0, 50) || 'kegiatan';
res.set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
res.set('Content-Disposition', `attachment; filename="rekap-${slug}-${bulan}.xlsx"`);
res.set('Cache-Control', 'private, no-store');
res.send(Buffer.from(buf));
} catch (err) { next(err); }
});
/* ---------- Laporan satu hari (isi popup kalender) ---------- */
router.get('/kegiatan/:id/hari/:tanggal', loadKegiatan, (req, res) => {
const k = req.kegiatan;