<?

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

$idate=date('Y-m-d');
$bar='';
$pie='';
$line='';
$doughnut='';
if(isset($_POST['tipe']))
{
    $tipe = $_POST['tipe'];
    if ($tipe == 'bar')
    {
        $bar='selected';
    }
    else if($tipe == 'line')
    {
        $line='selected';
    }
    else if($tipe == 'pie')
    {
        $pie='selected';
    }
    else 
    {
        $doughnut='selected';
    }
}
else
{
	 $tipe='bar';
	 $bar='selected';
}

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

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


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


$koneksi     = mysqli_connect("$host", "$user", "$pass", "$db");


$datax='';
$dataxx='';
$datay='';
$sumbux = mysqli_query($koneksi, "SELECT DISTINCT date(tanggal) FROM transaksi where kode_reseller = '$kode' and status=20 and tanggal BETWEEN '$tanggalawal' AND '".$tanggalakhir." 23:59:59' order by kode asc");
$jmlx = mysqli_num_rows($sumbux);

while($record = mysqli_fetch_array($sumbux)){
      $datax0 = $record['date(tanggal)'];

	  $datax=$datax0.','.$datax;
}
//echo $datax;

for ($i=0;$i<$jmlx;$i++)
{
	$tanggalcari0=explode(',',$datax);
	$tanggalcari=date($tanggalcari0[$i]);
	
	$sumbuy  = mysqli_query($koneksi, "SELECT SUM(harga) AS harga_sum FROM transaksi where kode_reseller = '$kode' and status=20 and tanggal BETWEEN '$tanggalcari' AND '".$tanggalcari." 23:59:59'");
    while($record = mysqli_fetch_array($sumbuy)){
      $datay0 = $record['harga_sum'];

	  $datay=$datay0.','.$datay;
	  
   
	$dataxx='"'.$tanggalcari.'",'.$dataxx;
    }
}

?>
<!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>Grafik - Web Report</title>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.bundle.js"></script>
        
        <!-- 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 type="text/css">
            .container {
                width: 75%;
                margin: 15px auto;
            }
        </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">Grafik</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-bar-chart fa-fw"></i>&nbsp;&nbsp;Grafik Mutasi
                            </div>
                            <!-- /.panel-heading -->
                            <div class="panel-body">
                                <div class="dataTable_wrapper" style="overflow-x:auto;">
									<form name='loginform' method='post' action='grafik.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>
									<i class="fa fa-modx fa-fw"></i>Tipe&nbsp;&nbsp;
                                    <select name="tipe">
                                        <option value="bar" <? echo $bar; ?>>Bar</option>
                                        <option value="line" <? echo $line; ?>>Line</option>
                                        <option value="pie" <? echo $pie; ?>>Pie</option>
                                        <option value="doughnut" <? echo $doughnut; ?>>Doughnut</option>
                                    </select>
                                    &nbsp;&nbsp;<button type="submit" class="btn btn-primary" name='tampilkan' value='Tampilkan'>Lihat</button><br><hr>
									</form>
                                    <div class="container">
                                        <canvas id="myChart" width="50" height="50"></canvas>
                                    
                                    <script>
                                        var ctx = document.getElementById("myChart");
                                        var myChart = new Chart(ctx, {
                                            type: '<? echo $tipe;?>',
                                            data: {
                                                labels: [<? echo $dataxx;?>],
                                                datasets: [{
                                                        label: 'Grafik Mutasi (Rp)',
                                                        data: [<? echo $datay;?>],
                                                        backgroundColor: [
                                                            'rgba(255, 99, 132, 0.2)',
                                                            'rgba(54, 162, 235, 0.2)',
                                                            'rgba(255, 206, 86, 0.2)',
                                                            'rgba(75, 192, 192, 0.2)',
                                                            'rgba(153, 102, 255, 0.2)',
                                                            'rgba(255, 159, 64, 0.2)',
                                                            'rgba(255, 99, 132, 0.2)',
                                                            'rgba(54, 162, 235, 0.2)',
                                                            'rgba(255, 206, 86, 0.2)',
                                                            'rgba(75, 192, 192, 0.2)',
                                                            'rgba(153, 102, 255, 0.2)',
                                                            'rgba(255, 159, 64, 0.2)'
                                                        ],
                                                        borderColor: [
                                                            'rgba(255,99,132,1)',
                                                            'rgba(54, 162, 235, 1)',
                                                            'rgba(255, 206, 86, 1)',
                                                            'rgba(75, 192, 192, 1)',
                                                            'rgba(153, 102, 255, 1)',
                                                            'rgba(255, 159, 64, 1)',
                                                            'rgba(255, 99, 132, 0.2)',
                                                            'rgba(54, 162, 235, 0.2)',
                                                            'rgba(255, 206, 86, 0.2)',
                                                            'rgba(75, 192, 192, 0.2)',
                                                            'rgba(153, 102, 255, 0.2)',
                                                            'rgba(255, 159, 64, 0.2)'
                                                        ],
                                                        borderWidth: 1
                                                    }]
                                            },
                                            options: {
                                                scales: {
                                                    yAxes: [{
                                                            ticks: {
                                                                beginAtZero: true
                                                            }
                                                        }]
                                                }
                                            }
                                        });
                                    </script>
                                    </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>
