<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
ob_start();
require(root."/___simple_config.php");
session_start();
require(root."/".adminFolder."/_common.php");
require(root."/".adminFolder."/_lib/db.php");
require(root."/".adminFolder."/_lib/main.php");
$a = cekpost(cleanQuery($_REQUEST["a"]), "");
$stgl = cekpost(cleanQuery($_REQUEST["fil_stgl"]), date('d-m-Y', time()));
$etgl = cekpost(cleanQuery($_REQUEST["fil_etgl"]), date('d-m-Y', time()));
$q_stgl = strtotime($stgl);
$q_etgl = strtotime($etgl)+86400;
$q_ytgl = strtotime($stgl)-86400;
if ($a=="today") {
	## today's quick report
	cout('<div class="row">');
		cout('<div class="col-sm-12">'.date('d M Y (l)', $q_stgl).'</div>');
		#cout('<div class="col-sm-12">'.date('d M Y', $q_etgl).'</div>');
		$rsnm=array();$qnm="SELECT COUNT(kdmember) AS tmem FROM members
			WHERE 1=1
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
			AND isdeleted=0 AND isactive=1";
		callRS($rsnm, $qnm);
		cout('<div class="col-sm-3">');
			cout('<div class="home-mini-box">');
				cout('<div class="title title-member"><div class="icon"></div><div class="text">Today\'s Members</div></div>');
				cout('<div class="data">'.$rsnm[0]["tmem"].'</div>');
			cout('</div>');
		cout('</div>');

		$rsnd=array();
		$qnd="SELECT SUM(jumlah) AS tjum, COUNT(kddeposit) AS tdp FROM deposits
			WHERE 1=1
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
			AND isclear = 1";
		callRS($rsnd, $qnd);
		$tj_today = $rsnd[0]["tjum"];
		$tt_today = $rsnd[0]["tdp"];
		cout('<div class="col-sm-3">');
			cout('<div class="home-mini-box">');
				cout('<div class="title title-deposit"><div class="icon"></div><div class="text">Today\'s Deposits</div></div>');
				cout('<div class="data">Rp. '.number_format($rsnd[0]["tjum"],0).'</div>');
				cout('<div class="data" style="margin:5px 0;">'.number_format($rsnd[0]["tdp"],0).' transaction(s)</div>');
			cout('</div>');
		cout('</div>');

		$rsnw=array();
		$qnw="SELECT SUM(jumlah) AS tjum, COUNT(kdwithdraw) AS twd FROM withdraws
			WHERE 1=1
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
			AND isclear = 1";
		callRS($rsnw, $qnw);
		$tj_today = $tj_today - $rsnw[0]["tjum"];
		$tt_today = $tt_today + $rsnw[0]["twd"];
		cout('<div class="col-sm-3">');
			cout('<div class="home-mini-box">');
				cout('<div class="title title-withdraw"><div class="icon"></div><div class="text">Today\'s Withdrawals</div></div>');
				cout('<div class="data" style="color:#ff7669;">Rp. -'.number_format($rsnw[0]["tjum"],0).'</div>');
				cout('<div class="data" style="margin:5px 0;">'.number_format($rsnw[0]["twd"],0).' transaction(s)</div>');
			cout('</div>');
		cout('</div>');
		$color_style = $tj_today<0?'color:#ff7669;':'';
		cout('<div class="col-sm-3">');
			cout('<div class="home-mini-box">');
				cout('<div class="title title-total"><div class="icon"></div><div class="text">Today\'s Total</div></div>');
				cout('<div class="data" style="'.$color_style.'">Rp. '.number_format($tj_today,0).'</div>');
				cout('<div class="data" style="margin:5px 0;">'.number_format($tt_today,0).' transaction(s)</div>');
			cout('</div>');
		cout('</div>');
	cout('</div>');
	
	cout('<div class="container-fluid">');
		cout('<div class="row">');
			cout('<div class="col-sm-6">');
				$rsg=array();$qg="SELECT a.*, full_path, file_ext, image_alt, image_title FROM games a LEFT JOIN u_files b ON b.kdgame_logo=a.kdgame WHERE a.isactive=1";
				callRS($rsg, $qg);
				cout('<table class="tdata2">');
					cout('<tr class="judul"><td>Game</td>');
						cout('<td>Mem</td>');
						cout('<td class="" style="color:#7d6fff;">DP Rp.</td>');
						cout('<td class="" style="color:#7d6fff;">TR DP</td>');
						cout('<td class="" style="color:#ff6f6f;">WD Rp.</td>');
						cout('<td class="" style="color:#ff6f6f;">TR WD</td>');
						cout('<td class="">DP+WD</td>');
						cout('<td class="">Total TR</td>');
					cout('</tr>');
					for ($i=0;$i<count($rsg);$i++) {
						$path = str_replace("../../", "/", $rsg[$i]["full_path"]);
						$resized = str_replace(".".$rsg[$i]["file_ext"]."", "_220.".$rsg[$i]["file_ext"]."", $path);
						#$resized = $resized."?".time();
						$rsnm=array();$qnm="SELECT COUNT(kdmember) AS tmem FROM members
							WHERE 1=1
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
							AND isdeleted=0 AND isactive=1 AND kdgame=".$rsg[$i]["kdgame"]."";
						callRS($rsnm, $qnm);
						$rsnd=array();
						$qnd="SELECT SUM(jumlah) AS tjum, COUNT(kddeposit) AS tdp FROM deposits
							WHERE 1=1
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
							AND isclear = 1 AND kdgame=".$rsg[$i]["kdgame"]."";
						callRS($rsnd, $qnd);
						$tj_today = $rsnd[0]["tjum"];
						$tt_today = $rsnd[0]["tdp"];
						$rsnw=array();
						$qnw="SELECT SUM(jumlah) AS tjum, COUNT(kdwithdraw) AS twd FROM withdraws
							WHERE 1=1
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
							AND isclear = 1 AND kdgame=".$rsg[$i]["kdgame"]."";
						callRS($rsnw, $qnw);
						$tj_today = $tj_today - $rsnw[0]["tjum"];
						$tt_today = $tt_today + $rsnw[0]["twd"];
						cout('<tr>');
							cout('<td><img class="" height="40" src="'.$resized.'" alt="'.$rsg[$i]["image_alt"].'" title="'.$rsg[$i]["image_title"].'" /></td>');
							cout('<td class="num">'.$rsnm[0]["tmem"].'</td>');
							cout('<td class="text-right num" style="color:#7d6fff;">'.number_format($rsnd[0]["tjum"],0).'</td>');
							cout('<td class="text-right num" style="color:#7d6fff;">('.number_format($rsnd[0]["tdp"],0).')</td>');
							cout('<td class="text-right num" style="color:#ff6f6f;">-'.number_format($rsnw[0]["tjum"],0).'</td>');
							cout('<td class="text-right num" style="color:#ff6f6f;">('.number_format($rsnw[0]["twd"],0).')</td>');
							cout('<td class="text-right num" style="'.($tj_today<0?'color:#ff6f6f;':'color:#7d6fff;').'">Rp. '.number_format($tj_today,0).'</td>');
							cout('<td class="text-right num">('.number_format($tt_today,0).')</td>');
						cout('</tr>');
					}
				cout('</table>');
			cout('</div>');
			cout('<div class="col-sm-6">');
				$rsg=array();$qg="SELECT a.* FROM banks a WHERE a.isactive=1";
				callRS($rsg, $qg);
				cout('<table class="tdata2">');
					cout('<tr class="judul"><td>Bank</td>');
						cout('<td>Mem</td>');
						cout('<td class="" style="color:#7d6fff;">DP Rp.</td>');
						cout('<td class="" style="color:#7d6fff;">TR DP</td>');
						cout('<td class="" style="color:#ff6f6f;">WD Rp.</td>');
						cout('<td class="" style="color:#ff6f6f;">TR WD</td>');
						cout('<td class="">DP+WD</td>');
						cout('<td class="">Total TR</td>');
					cout('</tr>');
					for ($i=0;$i<count($rsg);$i++) {
						$kdbank = $rsg[$i]["kdbank"];
						$bca_on = ''.absDom.'/img/bank-bca-on.png';
						$bca_off = ''.absDom.'/img/bank-bca-bw.png';
						$mandiri_on = ''.absDom.'/img/bank-mandiri-on.png';
						$mandiri_off = ''.absDom.'/img/bank-mandiri-bw.png';
						$bni_on = ''.absDom.'/img/bank-bni-on.png';
						$bni_off = ''.absDom.'/img/bank-bni-bw.png';
						$bri_on = ''.absDom.'/img/bank-bri-on.png';
						$bri_off = ''.absDom.'/img/bank-bri-bw.png';
						switch ($kdbank) {
							case 1: { $isrc = (intval($rsb[$bb]["ison"])==1)?$bca_on:$bca_off; break; }
							case 2: { $isrc = (intval($rsb[$bb]["ison"])==1)?$mandiri_on:$mandiri_off; break; }
							case 3: { $isrc = (intval($rsb[$bb]["ison"])==1)?$bni_on:$bni_off; break; }
							case 4: { $isrc = (intval($rsb[$bb]["ison"])==1)?$bri_on:$bri_off; break; }
						}
						$rsnm=array();$qnm="SELECT COUNT(kdmember) AS tmem FROM members
							WHERE 1=1
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
							AND isdeleted=0 AND isactive=1 AND kdbank=".$rsg[$i]["kdbank"]."";
						callRS($rsnm, $qnm);
						$rsnd=array();
						$qnd="SELECT SUM(jumlah) AS tjum, COUNT(kddeposit) AS tdp FROM deposits
							WHERE 1=1
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
							AND isclear = 1 AND kdbank=".$rsg[$i]["kdbank"]."";
						callRS($rsnd, $qnd);
						$tj_today = $rsnd[0]["tjum"];
						$tt_today = $rsnd[0]["tdp"];
						$rsnw=array();
						$qnw="SELECT SUM(jumlah) AS tjum, COUNT(kdwithdraw) AS twd FROM withdraws
							WHERE 1=1
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
							AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
							AND isclear = 1 AND kdbank=".$rsg[$i]["kdbank"]."";
						callRS($rsnw, $qnw);
						$tj_today = $tj_today - $rsnw[0]["tjum"];
						$tt_today = $tt_today + $rsnw[0]["twd"];
						cout('<tr>');
							cout('<td><img class="" height="30" src="'.$isrc.'" /></td>');
							cout('<td class="num">'.$rsnm[0]["tmem"].'</td>');
							cout('<td class="text-right num" style="color:#7d6fff;">'.number_format($rsnd[0]["tjum"],0).'</td>');
							cout('<td class="text-right num" style="color:#7d6fff;">('.number_format($rsnd[0]["tdp"],0).')</td>');
							cout('<td class="text-right num" style="color:#ff6f6f;">-'.number_format($rsnw[0]["tjum"],0).'</td>');
							cout('<td class="text-right num" style="color:#ff6f6f;">('.number_format($rsnw[0]["twd"],0).')</td>');
							cout('<td class="text-right num" style="'.($tj_today<0?'color:#ff6f6f;':'color:#7d6fff;').'">Rp. '.number_format($tj_today,0).'</td>');
							cout('<td class="text-right num">('.number_format($tt_today,0).')</td>');
						cout('</tr>');
					}
				cout('</table>');
			cout('</div>');
		cout('</div>');
	cout('</div>');
	## end today's quick report
	
	cout('<hr>');
}
if ($a=="this-month") {
	$this_month = date('m');
	$last_month = ($this_month - 1)<=0?12:$this_month - 1;
	$last_2month = ($last_month - 1)<=0?12:$last_month - 1;
	$this_year = date('Y');
	$last_year = $this_year-1;
	cout('<div class="row">');
		
		#if ($last_month==12 || $last_2month==12) { $this_year = $last_year; }
		$max_day = date('t', strtotime("15-$this_month-$this_year"));
		#echo "15-$this_month-$this_year--";
		#echo $max_day;
		$grandTotalDP = 0;
		$grandTotalWD = 0;
		$grandTotalTransDP = 0;
		$grandTotalTransWD = 0;
		$stgl = ($max_day)."-$this_month-$this_year";
		$q_ytgl = strtotime($stgl);
		$startTotalDate = $q_ytgl;
		$super_str = '';
		$super_str = "";
		$super_rekap_str = "";
		for ($i=$max_day;$i>0;$i--) {
			$stgl = ($i)."-$this_month-$this_year";
			$q_ytgl = strtotime($stgl);
			$q_stgl = strtotime($stgl)+86400;
			$rsnm=array();
			$qnm="SELECT COUNT(kdmember) AS tmem FROM members
				WHERE 1=1
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
				AND isdeleted=0 AND isactive=1";
			callRS($rsnm, $qnm);
			$rsnd=array();
			$qnd="SELECT SUM(jumlah) AS tjum, COUNT(kddeposit) AS tdp FROM deposits
				WHERE 1=1
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
				AND isclear = 1";
			callRS($rsnd, $qnd);
			$tj_ytday = $rsnd[0]["tjum"];
			$tt_ytday = $rsnd[0]["tdp"];
			
			$rsnw=array();
			$qnw="SELECT SUM(jumlah) AS tjum, COUNT(kdwithdraw) AS twd FROM withdraws
				WHERE 1=1
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
				AND isclear = 1";
			callRS($rsnw, $qnw);
			$tj_ytday = $tj_ytday - $rsnw[0]["tjum"];
			$tt_ytday = $tt_ytday + $rsnw[0]["twd"];
			if (isset($rsnd[0]["tjum"])) {
				$dataPoints[] = array("x"=>$i+1, "y"=>($rsnd[0]["tjum"]/1000));
				$dataPoints2[] = array("x"=>$i+1, "y"=>($rsnw[0]["tjum"]/1000)*(-1));
				$dataPoints3[] = array("x"=>$i+1, "y"=>(($rsnd[0]["tjum"]-$rsnw[0]["tjum"])/1000));
				$super_str .= ('<div class="col-sm-3" style="margin-bottom:5px;">
					<div class="home-mini-box">
						<!--<div>'.date('d M Y (l)', $q_stgl).'</div>-->
						<div>'.date('d M Y (l)', $q_ytgl).'</div>
						<table class="tdata">
							<tr><td>Member</td><td>:</td><td>'.$rsnm[0]["tmem"].'</td><td></td></tr>
							<tr><td>DP</td><td>:</td><td class="text-right num" style="color:#7d6fff;">Rp.  '.number_format($rsnd[0]["tjum"],0).'</td><td class="num">('.number_format($rsnd[0]["tdp"],0).')</td></tr>
							<tr><td>WD</td><td>:</td><td class="text-right num" style="color:#ff6f6f;">Rp. -'.number_format($rsnw[0]["tjum"],0).'</td><td class="num">('.number_format($rsnw[0]["twd"],0).')</td></tr>
							<tr><td>Total</td><td>:</td><td class="text-right num" style="'.($tj_ytday<0?'color:#ff6f6f;':'color:#7d6fff;').'">Rp. '.number_format($tj_ytday,0).'</td><td class="num">('.number_format($tt_ytday,0).')</td></tr>
						</table>
					</div><!--/.home-mini-box-->
				</div>');
				$grandTotalDP += $rsnd[0]["tjum"];
				$grandTotalWD += $rsnw[0]["tjum"];
				$grandTotalTransDP += $rsnd[0]["tdp"];
				$grandTotalTransWD += $rsnw[0]["twd"];
			}
		}
		$endTotalDate = $q_ytgl;
		$super_rekap_str = '';
		$super_rekap_str .= ('<div class="col-xs-12">');
			$super_rekap_str .= ('<table class="tdata" style="float:left;">');
				$super_rekap_str .= ('<tr><td>Periode</td><td>:</td><td>'.date('d M Y (l)', $startTotalDate).' - '.date('d M Y (l)', $endTotalDate).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total DP</td><td>:</td><td class="num" style="color:#7d6fff;">Rp. '.number_format($grandTotalDP,0).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total WD</td><td>:</td><td class="num" style="color:#ff6f6f;">Rp. -'.number_format($grandTotalWD,0).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Grand Total</td><td>:</td><td class="num" style="'.(($grandTotalDP-$grandTotalWD)<0?'color:#ff6f6f;':'color:#7d6fff;').'">Rp. '.number_format($grandTotalDP-$grandTotalWD,0).'</td><td></td></tr>');
			$super_rekap_str .= ('</table>');
			$super_rekap_str .= ('<table class="tdata" style="float:left;">');
				$super_rekap_str .= ('<tr><td>&nbsp;</td></tr>');
				$super_rekap_str .= ('<tr><td>Total Trans. DP</td><td>:</td><td class="num">'.$grandTotalTransDP.'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total Trans. WD</td><td>:</td><td class="num">'.$grandTotalTransWD.'</td><td></td></tr>');
			$super_rekap_str .= ('</table>');
		$super_rekap_str .= ('</div>');
		cout('<div class="row">');
		cout($super_str);
		cout($super_rekap_str);
		cout('</div>');
		
		#cout('<div id="chartContainer" style="height: 600px; width: 100%;"></div>');
		cout('<div class="muncul">');
			cout('<div class="text-right"><a href="#" class="btn btn-primary" onclick="slideThis($(this));return false;">Show/Hide</a></div>');
			cout('<div id="chartContainer" class="chart" style="height: 600px; width: 100%;"></div>');
		cout('</div>');
		cout('<hr>');
		cout('<script>');
			cout('
			$(function () {
				var chart = new CanvasJS.Chart("chartContainer", {
					theme: "theme2",
					zoomEnabled: true,
					animationEnabled: true,
					title: {
						text: "Laporan Deposit, Withdraw & Selisih This Month"
					},
					subtitles: [
						{
							text: "(x1000)"
						}
					],
					toolTip:{
						shared:true
					},
					legend:{
						verticalAlign: "center",
						horizontalAlign: "right"
					},
					data: [
						{
							type: "spline",
							name: "DP",
							dataPoints: '.json_encode($dataPoints, JSON_NUMERIC_CHECK).'
						},
						{
							type: "spline",
							name: "WD",
							dataPoints: '.json_encode($dataPoints2, JSON_NUMERIC_CHECK).'
						},
						{
							type: "spline",
							name: "SL",
							dataPoints: '.json_encode($dataPoints3, JSON_NUMERIC_CHECK).'
						}
					],
					legend:{
						cursor:"pointer",
						itemclick:function(e){
							if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
							e.dataSeries.visible = false;
						}
						else{
							e.dataSeries.visible = true;
						}
							chart.render();
						}
					}
				});
				chart.render();
			});
		');
		cout('</script>');
		
	cout('</div><!--/.row-->');
}
if ($a=="last-month") {
	$this_month = date('m');
	$last_month = ($this_month - 1)<=0?12:$this_month - 1;
	$last_2month = ($last_month - 1)<=0?12:$last_month - 1;
	$this_year = date('Y');
	$last_year = $this_year-1;
	cout('<div class="row">');
		cout('<hr>');
		if ($last_month==12) { $this_year = $last_year; }
		$max_day = date('t', strtotime("15-$last_month-$this_year"));
		$stgl = (1)."-$last_month-$this_year";
		$q_ytgl = strtotime($stgl);
		$startTotalDate = $q_ytgl;
		$grandTotalDP = 0;
		$grandTotalWD = 0;
		$grandTotalTransDP = 0;
		$grandTotalTransWD = 0;
		$super_str = "";
		$super_rekap_str = "";
		for ($i=0;$i<$max_day;$i++) {
			$stgl = ($i+1)."-$last_month-$this_year";
			$q_ytgl = strtotime($stgl);
			$q_stgl = strtotime($stgl)+86400;
			$rsnm=array();
			$qnm="SELECT COUNT(kdmember) AS tmem FROM members
				WHERE 1=1
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
				AND isdeleted=0 AND isactive=1";
			callRS($rsnm, $qnm);
			$rsnd=array();
			$qnd="SELECT SUM(jumlah) AS tjum, COUNT(kddeposit) AS tdp FROM deposits
				WHERE 1=1
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
				AND isclear = 1";
			callRS($rsnd, $qnd);
			$tj_ytday = $rsnd[0]["tjum"];
			$tt_ytday = $rsnd[0]["tdp"];
			$rsnw=array();
			$qnw="SELECT SUM(jumlah) AS tjum, COUNT(kdwithdraw) AS twd FROM withdraws
				WHERE 1=1
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
				AND isclear = 1";
			callRS($rsnw, $qnw);
			$tj_ytday = $tj_ytday - $rsnw[0]["tjum"];
			$tt_ytday = $tt_ytday + $rsnw[0]["twd"];
			if (isset($rsnd[0]["tjum"])) {
				$dataPointsL1[] = array("x"=>$i+1, "y"=>($rsnd[0]["tjum"]/1000));
				$dataPointsL2[] = array("x"=>$i+1, "y"=>($rsnw[0]["tjum"]/1000)*(-1));
				$dataPointsL3[] = array("x"=>$i+1, "y"=>(($rsnd[0]["tjum"]-$rsnw[0]["tjum"])/1000));
				$super_str .= ('<div class="col-sm-3" style="margin-bottom:5px;">
					<div class="home-mini-box">
						<!--<div>'.date('d M Y (l)', $q_stgl).'</div>-->
						<div>'.date('d M Y (l)', $q_ytgl).'</div>
						<table class="tdata">
							<tr><td>Member</td><td>:</td><td>'.$rsnm[0]["tmem"].'</td><td></td></tr>
							<tr><td>DP</td><td>:</td><td class="text-right num" style="color:#7d6fff;">Rp.  '.number_format($rsnd[0]["tjum"],0).'</td><td class="num">('.number_format($rsnd[0]["tdp"],0).')</td></tr>
							<tr><td>WD</td><td>:</td><td class="text-right num" style="color:#ff6f6f;">Rp. -'.number_format($rsnw[0]["tjum"],0).'</td><td class="num">('.number_format($rsnw[0]["twd"],0).')</td></tr>
							<tr><td>Total</td><td>:</td><td class="text-right num" style="'.($tj_ytday<0?'color:#ff6f6f;':'color:#7d6fff;').'">Rp. '.number_format($tj_ytday,0).'</td><td class="num">('.number_format($tt_ytday,0).')</td></tr>
						</table>
					</div><!--/.home-mini-box-->
				</div>');
				$grandTotalDP += $rsnd[0]["tjum"];
				$grandTotalWD += $rsnw[0]["tjum"];
				$grandTotalTransDP += $rsnd[0]["tdp"];
				$grandTotalTransWD += $rsnw[0]["twd"];
			}
		}
		$endTotalDate = $q_ytgl;
		$super_rekap_str = '';
		$super_rekap_str .= ('<div class="col-xs-12">');
			$super_rekap_str .= ('<table class="tdata" style="float:left;">');
				$super_rekap_str .= ('<tr><td>Periode</td><td>:</td><td>'.date('d M Y (l)', $startTotalDate).' - '.date('d M Y (l)', $endTotalDate).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total DP</td><td>:</td><td class="num" style="color:#7d6fff;">Rp. '.number_format($grandTotalDP,0).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total WD</td><td>:</td><td class="num" style="color:#ff6f6f;">Rp. -'.number_format($grandTotalWD,0).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Grand Total</td><td>:</td><td class="num" style="'.(($grandTotalDP-$grandTotalWD)<0?'color:#ff6f6f;':'color:#7d6fff;').'">Rp. '.number_format($grandTotalDP-$grandTotalWD,0).'</td><td></td></tr>');
			$super_rekap_str .= ('</table>');
			$super_rekap_str .= ('<table class="tdata" style="float:left;">');
				$super_rekap_str .= ('<tr><td>&nbsp;</td></tr>');
				$super_rekap_str .= ('<tr><td>Total Trans. DP</td><td>:</td><td class="num">'.$grandTotalTransDP.'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total Trans. WD</td><td>:</td><td class="num">'.$grandTotalTransWD.'</td><td></td></tr>');
			$super_rekap_str .= ('</table>');
		$super_rekap_str .= ('</div>');
		cout('<div class="row">');
		cout($super_str);
		cout($super_rekap_str);
		cout('</div>');
		
		cout('<div class="muncul">');
			cout('<div class="text-right"><a href="#" class="btn btn-primary" onclick="slideThis($(this));return false;">Show/Hide</a></div>');
			cout('<div id="chartContainer2" class="chart" style="height: 600px; width: 100%;"></div>');
		cout('</div>');
		cout('<hr>');
		cout('<script>');
			cout('
			$(function () {
				var chart2 = new CanvasJS.Chart("chartContainer2", {
					theme: "theme2",
					zoomEnabled: true,
					animationEnabled: true,
					title: {
						text: "Laporan Deposit, Withdraw & Selisih Last Month"
					},
					subtitles: [
						{
							text: "(x1000)"
						}
					],
					toolTip:{
						shared:true
					},
					legend:{
						verticalAlign: "center",
						horizontalAlign: "right"
					},
					data: [{
						type: "spline",
						name: "DP",
						dataPoints: '.json_encode($dataPointsL1, JSON_NUMERIC_CHECK).'
					},
					{
						type: "spline",
						name: "WD",
						dataPoints: '.json_encode($dataPointsL2, JSON_NUMERIC_CHECK).'
					},
					{
						type: "spline",
						name: "SL",
						dataPoints: '.json_encode($dataPointsL3, JSON_NUMERIC_CHECK).'
					}
					]
				});
				chart2.render();
			});
			');
		cout('</script>');
	cout('</div><!--/.row-->');
}
?>