# ⚡ Quick Setup - Auto Reset Kehadiran

## 🎯 Goal
Reset status kehadiran otomatis setiap jam 00:00 (tengah malam)

---

## ✅ Metode 1: Auto-Reset on Access (SUDAH AKTIF!)

**Status:** ✅ Sudah otomatis berjalan, tidak perlu setup!

**Cara Kerja:**
- Saat dashboard/display dibuka, otomatis cek tanggal
- Jika hari baru, otomatis create data dengan status "TIDAK ADA"
- Proses cepat (< 1 detik)

**Test:**
1. Buka: `https://yourdomain.com/api/check_and_reset.php`
2. Lihat response JSON
3. Cek database: `SELECT * FROM attendance WHERE attendance_date = CURDATE();`

---

## 🔧 Metode 2: Cron Job (Recommended)

### Setup via cPanel (5 menit):

1. **Login cPanel** → Cari "Cron Jobs"

2. **Add New Cron Job:**
   ```
   Minute: 0
   Hour: 0
   Day: *
   Month: *
   Weekday: *
   ```

3. **Command:**
   ```bash
   /usr/bin/php /home/username/public_html/cron/reset_attendance.php
   ```
   
   Atau via wget:
   ```bash
   wget -q -O - https://yourdomain.com/cron/reset_attendance.php
   ```

4. **Save**

5. **Test Manual:**
   - Buka: `https://yourdomain.com/cron/reset_attendance.php`
   - Cek output di browser
   - Cek log: `cron/reset_attendance.log`

---

### Setup via SSH (3 menit):

```bash
# 1. Edit crontab
crontab -e

# 2. Tambahkan baris ini:
0 0 * * * /usr/bin/php /path/to/project/cron/reset_attendance.php >> /path/to/project/cron/reset_attendance.log 2>&1

# 3. Save (Ctrl+X, Y, Enter)

# 4. Verifikasi
crontab -l

# 5. Test manual
php /path/to/project/cron/reset_attendance.php
```

---

## 📊 Verifikasi

### Cek Log:
```bash
cat cron/reset_attendance.log
```

### Cek Database:
```sql
SELECT attendance_date, COUNT(*) as total 
FROM attendance 
GROUP BY attendance_date 
ORDER BY attendance_date DESC 
LIMIT 7;
```

### Expected Result:
- Setiap hari ada 9 records (sesuai jumlah jabatan)
- Status awal semua "absent"

---

## 🎯 Rekomendasi

| Hosting Type | Metode | Setup |
|--------------|--------|-------|
| Shared Hosting | Auto-Reset + Cron (cPanel) | 5 menit |
| VPS/Dedicated | Cron (SSH) | 3 menit |
| Tidak bisa Cron | Auto-Reset saja | ✅ Sudah aktif |

---

## 📚 Dokumentasi Lengkap

- **Detail Setup:** `docs/CRON_SETUP_GUIDE.md`
- **Summary:** `AUTO_RESET_SUMMARY.md`
- **Cron README:** `cron/README.md`

---

**Status:** ✅ Ready to Use  
**Version:** 3.0.0  
**Date:** 18 Feb 2026
