<?php
/**
 * =====================================================
 * SIMPAS v1.0
 * Modul : Laporan Absensi
 * File   : index.php
 * =====================================================
 */

include "../../config/koneksi.php";
include "../../config/session.php";

include "../../templates/header.php";
include "../../templates/navbar.php";
include "../../templates/sidebar.php";

?>

<div class="content-wrapper">

<section class="content-header">

<div class="container-fluid">

<div class="row mb-2">

<div class="col-sm-6">

<h1>

<i class="fas fa-chart-bar"></i>

Laporan Absensi

</h1>

</div>

</div>

</div>

</section>

<section class="content">

<div class="container-fluid">

<div class="card shadow">

<div class="card-header bg-primary">

<h3 class="card-title">

Filter Laporan

</h3>

</div>

<div class="card-body">

<form method="GET">

<div class="row">

<div class="col-md-4">

<label>Tanggal Awal</label>

<input
type="date"
name="tgl1"
class="form-control"
required
value="<?= isset($_GET['tgl1']) ? $_GET['tgl1'] : date('Y-m-01'); ?>">

</div>

<div class="col-md-4">

<label>Tanggal Akhir</label>

<input
type="date"
name="tgl2"
class="form-control"
required
value="<?= isset($_GET['tgl2']) ? $_GET['tgl2'] : date('Y-m-d'); ?>">

</div>

<div class="col-md-4">

<label>&nbsp;</label>

<button
type="submit"
class="btn btn-success btn-block">

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

Tampilkan

</button>

</div>

</div>

</form>

</div>

</div>
<?php

if(isset($_GET['tgl1'])){

$tgl1=$_GET['tgl1'];

$tgl2=$_GET['tgl2'];

$query=mysqli_query($conn,"
SELECT
a.*,
s.nama_siswa,
s.nis,
k.nama_kelas

FROM absensi a

LEFT JOIN siswa s
ON a.id_siswa=s.id_siswa

LEFT JOIN kelas k
ON s.id_kelas=k.id_kelas

WHERE
tanggal BETWEEN '$tgl1' AND '$tgl2'

ORDER BY
tanggal DESC,
jam_masuk DESC
");

?>

<div class="card shadow">

<div class="card-header">

<h3 class="card-title">

Hasil Laporan

</h3>

<div class="float-right">

<a
href="cetak.php?tgl1=<?= $tgl1 ?>&tgl2=<?= $tgl2 ?>"
class="btn btn-danger">

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

Cetak
<a
href="export_excel.php?tgl1=<?= $tgl1 ?>&tgl2=<?= $tgl2 ?>"
class="btn btn-success">

<i class="fas fa-file-excel"></i>

Export Excel

</a>

</a>

</div>

</div>

<div class="card-body">

<div class="table-responsive">

<table
id="laporan"
class="table table-bordered table-striped">

<thead class="bg-primary">

<tr>

<th>No</th>

<th>Tanggal</th>

<th>NIS</th>

<th>Nama</th>

<th>Kelas</th>

<th>Masuk</th>

<th>Pulang</th>

<th>Status</th>

</tr>

</thead>

<tbody>

<?php

$no=1;

while($row=mysqli_fetch_assoc($query)):

?>

<tr>

<td><?= $no++; ?></td>

<td><?= date('d-m-Y',strtotime($row['tanggal'])); ?></td>

<td><?= $row['nis']; ?></td>

<td><?= $row['nama_siswa']; ?></td>

<td><?= $row['nama_kelas']; ?></td>

<td><?= $row['jam_masuk']; ?></td>

<td><?= empty($row['jam_pulang'])?'-':$row['jam_pulang']; ?></td>

<td><?= $row['status']; ?></td>

</tr>

<?php endwhile; ?>

</tbody>
</table>

</div>

</div>

</div>

<?php } ?>

</div>

</section>

</div>

<script>

$(document).ready(function(){

    $('#laporan').DataTable({

        responsive:true,

        autoWidth:false,

        pageLength:25,

        order:[[1,'desc']],

        language:{

            search:"Cari :",

            lengthMenu:"Tampilkan _MENU_ data",

            zeroRecords:"Data tidak ditemukan",

            info:"Menampilkan _START_ - _END_ dari _TOTAL_ data",

            infoEmpty:"Belum ada data",

            infoFiltered:"(difilter dari _MAX_ data)",

            paginate:{

                first:"Awal",

                last:"Akhir",

                next:"›",

                previous:"‹"

            }

        }

    });

});

</script>

<?php
include "../../templates/footer.php";
?>