<?php

include "../../config/koneksi.php";
date_default_timezone_set("Asia/Jakarta");

$tanggal = date("Y-m-d");

/* Hadir Tepat Waktu */
$q1 = mysqli_query($conn,"
SELECT COUNT(*) AS total
FROM absensi
WHERE tanggal='$tanggal'
AND status='Hadir'
");
$hadir = mysqli_fetch_assoc($q1)['total'];

/* Terlambat */
$q2 = mysqli_query($conn,"
SELECT COUNT(*) AS total
FROM absensi
WHERE tanggal='$tanggal'
AND status='Terlambat'
");
$terlambat = mysqli_fetch_assoc($q2)['total'];

/* Sudah Pulang */
$q3 = mysqli_query($conn,"
SELECT COUNT(*) AS total
FROM absensi
WHERE tanggal='$tanggal'
AND jam_pulang IS NOT NULL
AND jam_pulang<>''
");
$pulang = mysqli_fetch_assoc($q3)['total'];

/* Total Siswa Aktif */
$q4 = mysqli_query($conn,"
SELECT COUNT(*) AS total
FROM siswa
WHERE status='Aktif'
");
$total = mysqli_fetch_assoc($q4)['total'];

$belum = $total - ($hadir + $terlambat);

?>

<div class="row">

<div class="col-12 mb-2">

<div class="small-box bg-success">

<div class="inner">

<h3><?= $hadir ?></h3>

<p>Hadir Tepat Waktu</p>

</div>

<div class="icon">

<i class="fas fa-user-check"></i>

</div>

</div>

</div>

<div class="col-12 mb-2">

<div class="small-box bg-warning">

<div class="inner">

<h3><?= $terlambat ?></h3>

<p>Terlambat</p>

</div>

<div class="icon">

<i class="fas fa-clock"></i>

</div>

</div>

</div>

<div class="col-12 mb-2">

<div class="small-box bg-primary">

<div class="inner">

<h3><?= $pulang ?></h3>

<p>Sudah Pulang</p>

</div>

<div class="icon">

<i class="fas fa-home"></i>

</div>

</div>

</div>

<div class="col-12">

<div class="small-box bg-danger">

<div class="inner">

<h3><?= $belum ?></h3>

<p>Belum Hadir</p>

</div>

<div class="icon">

<i class="fas fa-user-times"></i>

</div>

</div>

</div>

</div>