<?

require_once("../dasar/session.php");
require_once("conn.php");
include '../dasar/ubahtgl.php';
$menu3='active';
$kode = $_SESSION['kode'];

if(isset($_POST['limit']))
{
    $limit = $_POST['limit'];
}
else if(isset($_GET['limit']))
{
    $limit=$_GET['limit'];
}
else
{
	 $limit=20;
}

if(isset($_POST['keterangan']))
{
    $keterangan = $_POST['keterangan'];
    
}
else
{
	 $keterangan='';
}

$idate=date('Y-m-d');

if(isset($_GET['tglawal']))
{
$tanggalawal = $_GET['tglawal'];

}
else if(isset($_POST['tgla'])) 
{
$tanggalawal = $_POST['tgla'];
}
else
{
	$tanggalawal=date('Y-m-d');
}


if(isset($_GET['tglakhir']))
{
$tanggalakhir = $_GET['tglakhir'];
}
else if(isset($_POST['tglb']))
{
$tanggalakhir = $_POST['tglb'];
}
else
{
	$tanggalakhir=date('Y-m-d');
}



if(isset($_GET['awal']))
{
$noPage = $_GET['awal'];
}
else
{
	$noPage=1;
}
$offset = ($noPage - 1) *$limit;
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>Mutasi - Web Report</title>

        <!-- Bootstrap Core CSS -->
        <link href="../css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="../css/metisMenu.min.css" rel="stylesheet">

        <!-- DataTables CSS -->
        <link href="../css/dataTables/dataTables.bootstrap.css" rel="stylesheet">
 <link rel="icon" href="../favicon.ico" type="image/icon"/>
        <!-- DataTables Responsive CSS -->
        <link href="../css/dataTables/dataTables.responsive.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="../css/startmin.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="../css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->

		<style>
.pagination {
    display: inline-block;
}

.pagination a {
    color: black;
    float: left;
    padding: 8px 16px;
    text-decoration: none;
    transition: background-color .3s;
}

.pagination a.active {
    background-color: #4CAF50;
    color: white;
}

.pagination a:hover:not(.active) {background-color: #ddd;}
</style>

    </head>
    <body>

        <div id="wrapper">

            <?
			require_once("nav.php");
			?>

            <div id="page-wrapper">
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">Mutasi</h1>
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
				
                <!-- /.row -->
                <div class="row">
                    <div class="col-lg-12">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                <i class="fa fa-line-chart fa-fw"></i>&nbsp;&nbsp;Data Mutasi
                            </div>
                            <!-- /.panel-heading -->
                            <div class="panel-body">
                                <div class="dataTable_wrapper" style="overflow-x:auto;">
									<form name='loginform' method='post' action='mutasi.php'>
									<i class="fa fa-calendar fa-fw"></i>Tanggal Awal&nbsp;&nbsp;<input type="date" name='tgla' value="<? echo $tanggalawal; ?>">&nbsp;&nbsp;
									<i class="fa fa-calendar fa-fw"></i>Tanggal Akhir&nbsp;&nbsp;<input type="date" name='tglb' value="<? echo $tanggalakhir; ?>">&nbsp;&nbsp;<br><br>
									Keterangan / Limit&nbsp;&nbsp;<input type="text" name='keterangan' value="<? echo $keterangan; ?>">&nbsp;&nbsp;
									<input type="text" name='limit' value="<? echo $limit; ?>" style="width:50px;" />&nbsp;&nbsp;<button type="submit" class="btn btn-primary" name='tampilkan' value='Tampilkan'>Lihat</button><br><br>
									</form>
                                    <table class="table table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th><center>No</center></th>
                                                <th><center>Tanggal</center></th>
                                                <th><center>Jumlah Rp</center></th>
                                                <th><center>Saldo Rp</center></th>
                                                <th><center>Keterangan</center></th>
                                            </tr>
                                        </thead>
										<?
										$exe = mysqli_query($conn,"SELECT * FROM mutasi where kode_reseller = '$kode' and keterangan LIKE '%$keterangan%' and tanggal BETWEEN '$tanggalawal' AND '".$tanggalakhir." 23:59:59' order by kode desc limit $offset,$limit");

										$jml = mysqli_query($conn,"SELECT * FROM mutasi where kode_reseller = '$kode' and keterangan LIKE '%$keterangan%' and tanggal BETWEEN '$tanggalawal' AND '".$tanggalakhir." 23:59:59'");	
					
										$jumlah0=mysqli_num_rows($jml);

				       					$no = 1+$offset;
										while($record = mysqli_fetch_array($exe)){
									   
										$kode = $record['kode'];
										$reseller = $record['kode_reseller'];
										$jumlah = $record['jumlah'];
										$saldo = $record['saldo_akhir'];
										$ket = $record['keterangan'];
										$ket = substr($ket,0,strlen($ket) -3).'xxx';
										$tanggal = tampildate($record['tanggal']);
										$jumlah2=number_format($jumlah,0,',','.');
										$saldo2=number_format($saldo,0,',','.');

                                        ?><tbody>
                                            <tr>
                                                <td><center><? echo $no ;?></center></td>
                                                <td><center><? echo $tanggal ;?></center></td>
                                                <td><center><? echo $jumlah2 ;?></center></td>
                                                <td><center><? echo $saldo2 ;?></center></td>
                                                <td><center><? echo $ket ;?></center></td>
                                   
                                            </tr>
                                        </tbody>

											<?$no++;}?>
                                    </table>
									<div class="pagination">
										
									<?$i=$jumlah0/$limit;
									$i=ceil($i);
									$showPage=0;
									if ($noPage > 1) echo "<a href='".$_SERVER['PHP_SELF']."?tglawal=".$tanggalawal."&&tglakhir=".$tanggalakhir."&&awal=".($noPage-1)."&&limit=".$limit."'> Prev</a>";
									for($j = 1; $j <= $i; $j++)
									{
										if ((($j >= $noPage - 3) && ($j <= $noPage + 3)) || ($j == 1) || ($j == $i))
										{
											if (($showPage == 1) && ($j != 2))  echo "<a>...</a>";
											if (($showPage != ($i - 1)) && ($j == $i))  echo "<a >...</a>";
											if ($j == $noPage) echo ' <a class="active">'.$j."</a> ";
												else echo " <a href='".$_SERVER['PHP_SELF']."?tglawal=".$tanggalawal."&&tglakhir=".$tanggalakhir."&&awal=".$j."&&limit=".$limit."'>".$j."</a> ";
											$showPage = $j;
											}
										}
									if ($noPage < $i) echo "<a href='".$_SERVER['PHP_SELF']."?tglawal=".$tanggalawal."&&tglakhir=".$tanggalakhir."&&awal=".($noPage+1)."&&limit=".$limit."'>Next</a>";

									?>
									
										
									</div> 
                                </div>
                                <!-- /.table-responsive
                                <div class="well">
                                    <h4>DataTables Usage Information</h4>
                                    <p>DataTables is a very flexible, advanced tables plugin for jQuery. In SB Admin, we are using a specialized version of DataTables built for Bootstrap 3. We have also customized the table headings to use Font Awesome icons in place of images. For complete documentation on DataTables, visit their website at <a target="_blank" href="https://datatables.net/">https://datatables.net/</a>.</p>
                                    <a class="btn btn-default btn-lg btn-block" target="_blank" href="https://datatables.net/">View DataTables Documentation</a>
                                </div>-->
                            </div>
                            <!-- /.panel-body -->
                        </div>
                        <!-- /.panel -->
                    </div>
                    <!-- /.col-lg-12 -->
                </div>
                
                <!-- /.row -->
            </div>
            <!-- /#page-wrapper -->

        </div>
        <!-- /#wrapper -->

        <!-- jQuery -->
        <script src="../js/jquery.min.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="../js/bootstrap.min.js"></script>

        <!-- Metis Menu Plugin JavaScript -->
        <script src="../js/metisMenu.min.js"></script>

        <!-- DataTables JavaScript -->
        <script src="../js/dataTables/jquery.dataTables.min.js"></script>
        <script src="../js/dataTables/dataTables.bootstrap.min.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="../js/startmin.js"></script>

        <!-- Page-Level Demo Scripts - Tables - Use for reference -->
        <script>
            $(document).ready(function() {
                $('#dataTables-example').DataTable({
                        responsive: true
                });
            });
        </script>
    <?
        include 'chat.php';
    ?>
    </body>
</html>
