<?php
include "../../inc/inc.koneksi.php";
include "../../inc/fungsi_tanggal.php";

$kode	= $_POST['siswa'];
        $query = mysql_query("delete from faktur_pjt where kode_pj=:kode_pj");
        
	

?>
<!DOCTYPE html>
<html>
    <head>
        <title>Hapus Data Dengan Checkbox</title>
        <style>
            table {
                border: 1px solid #ddd;
                border-collapse: collapse;
            }
            table td, table th {
                padding: 8px;
                border: 1px solid #ddd;
            }
        </style>
    </head>
    <body>
        <h1>Data Siswa</h1>
        <form action="" method="POST" onsubmit="return konfirmasi()">
            <p><button type="submit">Hapus</button></p>
            <table>
                <thead>
                    <tr>
                        <th><input type="checkbox" onchange="selectAll(this)"></th>
                        <th>Tanggal</th>
                        <th>Jml. Item</th>
                        <th>Jml. Unit</th>
                        <th>Total Harga</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $tgl_awal	= $_GET['tgl_awal'];
					$tgl_akhir	= $_GET['tgl_akhir'];
					$kasir		= $_GET['kasir'];
                    if(!empty($kasir))
						$sql = mysql_query("SELECT kode_pj,tanggal,count(kode_st) as titem,sum(jml_unit) as junit,sum(jumlah) as tjumlah FROM faktur_pjt WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND user LIKE '%$kasir' AND posting='P' GROUP BY kode_pj");
					else
						$sql = mysql_query("SELECT kode_pj,tanggal,count(kode_st) as titem,sum(jml_unit) as junit,sum(jumlah) as tjumlah FROM faktur_pjt WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND posting='P' GROUP BY kode_pj");
                    while($r=mysql_fetch_array($sql)){
                    ?>
                    <tr>
                        <td><input type="checkbox" class="siswa" name="siswa[]" value="<?php echo $r['kode_pj'];?>"></td>
                        <td><?php echo htmlentities($r['tanggal']);?></td>
                        <td><?php echo htmlentities($r['titem']);?></td>
                        <td><?php echo htmlentities($r['junit']);?></td>
                        <td><?php echo htmlentities($r['tjumlah']);?></td>
                    </tr>
                    <?php 
                    }
                    ?>
                </tbody>
            </table>
            <p><button type="submit">Hapus</button></p>
        </form>
        <script>
            function konfirmasi() {
                return confirm('Apakah ada yakin menghapus data siswa tersebut?');
            }
 
            function selectAll(input) {
                let checkboxes = document.querySelectorAll('.siswa');
                checkboxes.forEach(function (checkbox) {
                    checkbox.checked = input.checked;
                });
            }
        </script>
    </body>
</html>