<?php
include '../../config/conn.php';
if ($_GET['aksi'] == '') { ?>
    <div class="col" role="main">
        <div class="">
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title" style="text-transform: capitalize;">
                            <h2>Data Tarik Serentak</h2>
                            <div class="clearfix"></div>
                        </div>
                        <a href="?module=tarik-serentak" class="btn btn-success btn-sm" data-toggle="" data-target=""><i class="glyphicon glyphicon-plus"></i> Tambah Tarik Serentak</a>

                        <div class="divider-dashed"></div>
                        <form action="?module=<?php echo $_GET['module']; ?>&id=<?php echo $_GET['id']; ?>&periode=y" enctype="multipart/form-data" method="POST">


                            <div class="col-md-12 col-sm-12 col-xs-12" style="padding: 4px;">
                                <label for="nama">Pilih Periode :</label>
                            </div>

                            <div class="col-md-6 col-sm-12 col-xs-12" style="padding: 4px;">

                                <div class="input-group">
                                    <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                    <input type="text" autocomplete="off" class="form-control " id="tanggal3" required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                                                    echo $_POST['tanggal1'];
                                                                                                                                } else {
                                                                                                                                    echo "";
                                                                                                                                } ?>" name="tanggal1">
                                    <div class="input-group-addon" style="background:white;"><small>Sampai</small></i></div>
                                    <div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div>
                                    <input type="text" autocomplete="off" class="form-control " required value="<?php if ($_GET['periode'] == 'y') {
                                                                                                                    echo $_POST['tanggal2'];
                                                                                                                } else {
                                                                                                                    echo "";
                                                                                                                } ?>" id="tanggal2" name="tanggal2">
                                </div>
                            </div>


                            <button type="submit" class="btn btn-primary btn-sm">Pilih</button>



                        </form>
                        <div class="x_content">
                            <table id="datatable" class="table table-striped table-bordered" style="color: black;">
                                <thead>
                                    <tr>
                                        <th width="50">No</th>
                                        <th>ID Tarik</th>
                                        <!--<th>No Rekening</th>-->
                                        <th>tanggal</th>
                                        <th>jumlah santri</th>
                                        <th>keterangan</th>
                                        <th>User</th>

                                        <th>Jumlah Tarik</th>

                                        <?php if ($_SESSION['leveluser'] == 'admin' or $_SESSION['leveluser'] == 'user1') { ?>
                                            <th width="110">Aksi</th>
                                        <?php } ?>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $no = 0;

                                    if ($_GET['periode'] == 'y') {
                                        $tgl1 = date('Y-m-d', strtotime($_POST['tanggal1']));
                                        $tgl2 = date('Y-m-d', strtotime($_POST['tanggal2']));


                                        $query = mysqli_query($conn, "SELECT * FROM tarik_serentak WHERE tanggal BETWEEN '$tgl1' AND '$tgl2' order by id ASC ");
                                    } else {
                                        $hariini = date('Y-m-d');
                                        $query = mysqli_query($conn, "SELECT * FROM tarik_serentak WHERE tanggal='$hariini' ORDER BY id");
                                    }
                                    while ($row = mysqli_fetch_array($query)) {
                                        $no++;
                                    ?>
                                        <tr>
                                            <td><?php echo $no; ?></td>
                                            <td><?php echo $row['id_tarik']; ?></td>

                                            <td><?php echo tgl($row['tanggal']); ?></td>
                                            <td><?php echo jumlahsantri($row['id_tarik']); ?></td>
                                            <td><?php echo $row['keterangan']; ?></td>
                                            <td><?php echo namauser($row['user']); ?></td>
                                            <td><?php echo rupiah($row['jumlah']); ?></td>

                                            <?php if ($_SESSION['leveluser'] == 'admin' or $_SESSION['leveluser'] == 'user1') { ?>
                                                <td><a class='open_modal btn  btn-default btn-xs' href="?module=<?php echo $_GET['module']; ?>&aksi=detail&id=<?php echo $row['id_tarik']; ?>"><i class="glyphicon glyphicon-eye-open"></i> Detail</a>

                                                    <a class="btn  btn-primary btn-xs" href="javascript:void(0);" onclick="window.open('component/com_transaksi_ewallet/export_tarik_serentak.php?id=<?php echo $row['id_tarik']; ?>','nama_window_pop_up','size=800,height=800,scrollbars=yes,resizeable=no')"><i class="glyphicon glyphicon-print"></i></a>


                                                </td>
                                            <?php } ?>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>




<?php  } elseif ($_GET['aksi'] == 'detail') {

?>

    <div class="col" role="main">
        <div class="">
            <div class="clearfix"></div>
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title" style="text-transform: capitalize;">
                            <h2>Detail Tarik Serentak</h2>
                            <div class="clearfix"></div>
                        </div>
                        <a href="?module=data-tarik" class="btn btn-primary btn-sm" data-toggle="" data-target=""></i> Kembali</a>

                        <div class="divider-dashed"></div>
                        <?php $query = mysqli_query($conn, "SELECT * FROM tarik_serentak WHERE id_tarik='$_GET[id]'");
                        $r = mysqli_fetch_array($query);

                        ?>

                        <div class="x_title" style="text-transform: capitalize;">
                            <h4>ID Tarik : <?php echo $_GET['id']; ?></h4>
                            <h4>Jumlah tarik : <?php echo rupiah($r['jumlah']); ?></h4>
                            <h4>Penarik : <?php echo namauser($r['user']); ?></h4>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content ">
                            <div class="col-md-6 col-sm-12">
                                <table id="datatable" class="table table-striped table-bordered" style="color: black;">
                                    <thead>
                                        <tr>
                                            <th width="50">No</th>
                                            <th>ID Santri</th>
                                            <!--<th>No Rekening</th>-->
                                            <th>Nama</th>
                                            <th>Jumlah</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $no = 0;

                                        $hariini = date('Y-m-d');
                                        $data = $_GET['id'];
                                        $query = mysqli_query($conn, "SELECT * FROM transaksi_ewallet WHERE keterangan like '%$data%' ORDER BY id_transaksi");

                                        while ($row = mysqli_fetch_array($query)) {
                                            $no++;
                                        ?>
                                            <tr>
                                                <td><?php echo $no; ?></td>
                                                <td><?php echo $row['rekening']; ?></td>

                                                <td><?php echo nama($row['rekening']); ?></td>
                                                <td><?php echo rupiah($row['kredit']); ?></td>

                                            </tr>

                                        <?php } ?>
                                    <tfoot>
                                        <tr>
                                            <th colspan="3" style="font-weight: bolder; text-align:center">TOTAL</th>
                                            <th><?php
                                                echo rupiah(jumlahsantri($_GET['id']) * $r['jumlah']); ?></th>
                                        </tr>
                                    </tfoot>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>



<?php }
