<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
require(root."/___simple_config.php");
session_start();
require(root."/".adminFolder."/_common.php");
require(root."/".adminFolder."/_lib/db.php");
require(root."/".adminFolder."/_lib/main.php");
require(root."/".adminFolder."/_lib/auth.php");
require(root."/".adminFolder."/_lib/bootstraps.php");
$pageSubOf = "Reports";
$pageName = "report_deposits";
$pageTitle = "Report Deposits";
$thisUrl = "reports/deposits";
$ajax_page = "ajax_report_deposits.php";
$pageUrl = "/".adminFolder."/$thisUrl";
$a = cekpost(cleanQuery($_GET["a"]), "");
$err = "";
if ($a=="show_today") {
	
}
if ($a=="section_main") {
	$fil_stgl = trim(cekpost(cleanQuery($_REQUEST["fil_stgl"]), ""));
	$fil_etgl = trim(cekpost(cleanQuery($_REQUEST["fil_etgl"]), ""));
	$fil_username = trim(cekpost(cleanQuery($_REQUEST["fil_username"]), ""));
	$fil_kdbank = trim(cekpost(cleanQuery($_REQUEST["fil_kdbank"]), ""));
	$fil_kdgame = trim(cekpost(cleanQuery($_REQUEST["fil_kdgame"]), ""));
	$fil_norek = trim(cekpost(cleanQuery($_REQUEST["fil_norek"]), ""));
	$fil_namarek = trim(cekpost(cleanQuery($_REQUEST["fil_namarek"]), ""));
	$swhere = '';
	$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;
	$fil_stgl = strtotime($stgl);
	$fil_etgl = strtotime($etgl);
	## today's quick report
	cout('<div class="row">');
		cout('<div class="col-sm-12">'.date('d M Y', $q_stgl).' s/d '.date('d M Y', strtotime($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);
		
		$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"];
		
		$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"];
		
		$color_style = $tj_today<0?'color:#ff7669;':'';
		cout('<div class="col-sm-2">');
			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>');
		
		cout('<div class="col-sm-2">');
			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 class="data" style="margin:5px 0;">AVG Rp.'.number_format($rsnd[0]["tjum"]/$rsnd[0]["tdp"]/1000,2).'</div>');
			cout('</div>');
		cout('</div>');
		
		cout('<div class="col-sm-2">');
			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 class="data" style="margin:5px 0;">AVG Rp.'.number_format($rsnw[0]["tjum"]/$rsnw[0]["twd"]/1000,2).'</div>');
			cout('</div>');
		cout('</div>');
		
		cout('<div class="col-sm-2">');
			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>');
	## end today's quick report
	cout('<hr>');
	cout('<div class="container-fluid">');
		cout('<div class="row">');
			cout('<div class="col-sm-12">');
				$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-12">');
				$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>');
	cout('<hr>');
	cout('<div class="row">');
		$grandTotalDP = 0;
		$grandTotalWD = 0;
		$grandTotalTransDP = 0;
		$grandTotalTransWD = 0;
		$startTotalDate = $q_ytgl;
		$super_str = '';
		#$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;
		$sstgl = $q_stgl;
		$flag = 0;
		do {
			$rsnm=array();
			$qnm="SELECT COUNT(kdmember) AS tmem FROM members
				WHERE 1=1
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$sstgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".($sstgl+86400).")) 
				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(".$sstgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".($sstgl+86400).")) 
				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(".$sstgl.")) 
				AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".($sstgl+86400).")) 
				AND isclear = 1";
			callRS($rsnw, $qnw);
			$tj_ytday = $tj_ytday - $rsnw[0]["tjum"];
			$tt_ytday = $tt_ytday + $rsnw[0]["twd"];
			
			$super_str .= ('<div class="col-sm-3" style="margin-bottom:5px;">
				<div class="home-mini-box">
					<div>'.date('d M Y', $sstgl).'</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" style="color:#7d6fff;">Rp.  '.number_format($rsnd[0]["tjum"],0).'</td><td>('.number_format($rsnd[0]["tdp"],0).')</td></tr>
						<tr><td>WD</td><td>:</td><td class="text-right" style="color:#ff6f6f;">Rp. -'.number_format($rsnw[0]["tjum"],0).'</td><td>('.number_format($rsnw[0]["twd"],0).')</td></tr>
						<tr><td>Total</td><td>:</td><td class="text-right" style="'.($tj_ytday<0?'color:#ff6f6f;':'color:#7d6fff;').'">Rp. '.number_format($tj_ytday,0).'</td><td>('.number_format($tt_ytday,0).')</td></tr>
						<tr><td>AVG DP</td><td>:</td><td class="text-right" colspan="2" style="color:#7d6fff;">Rp. '.number_format($rsnd[0]["tjum"]/$rsnd[0]["tdp"]/1000,2).'</td></tr>
						<tr><td>AVG WD</td><td>:</td><td class="text-right" colspan="2" style="color:#ff6f6f;">Rp. '.number_format($rsnw[0]["tjum"]/$rsnw[0]["twd"]/1000,2).'</td></tr>
					</table>
				</div><!--/.home-mini-box-->
			</div>');
			
			$grandTotalDP += $rsnd[0]["tjum"];
			$grandTotalWD += $rsnw[0]["tjum"];
			$grandTotalTransDP += $rsnd[0]["tdp"];
			$grandTotalTransWD += $rsnw[0]["twd"];
			
			#echo date('d-m-Y', $sstgl).'<br/>';
			$sstgl = $sstgl + 86400;
			
			if ($sstgl == $q_etgl) { $flag = 1; }
		} while($flag == 0);
		
		$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', $q_stgl).' - '.date('d-M-Y', $q_etgl-86400).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total DP</td><td>:</td><td class="text-right" style="color:#7d6fff;">Rp. '.number_format($grandTotalDP,0).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total WD</td><td>:</td><td class="text-right" style="color:#ff6f6f;">Rp. -'.number_format($grandTotalWD,0).'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Grand Total</td><td>:</td><td class="text-right" 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>'.$grandTotalTransDP.'</td><td></td></tr>');
				$super_rekap_str .= ('<tr><td>Total Trans. WD</td><td>:</td><td>'.$grandTotalTransWD.'</td><td></td></tr>');
			$super_rekap_str .= ('</table>');
		$super_rekap_str .= ('</div>');
		$super_rekap_str .= ('<div class="col-xs-12">');
			$super_rekap_str .= ('<table class="tdata">');
				$super_rekap_str .= ('<tr><td>AVG. DP</td><td>:</td><td class="text-right" style="color:#7d6fff;">Rp. '.number_format($grandTotalDP/$grandTotalTransDP/1000,2).'</td><td>per TRX</td></tr>');
				$super_rekap_str .= ('<tr><td>AVG. WD</td><td>:</td><td class="text-right" style="color:#ff6f6f;">Rp. '.number_format($grandTotalWD/$grandTotalTransWD/1000,2).'</td><td>per TRX</td></tr>');
			$super_rekap_str .= ('</table>');
		$super_rekap_str .= ('</div>');
		
		
		#cout($super_rekap_str);
		cout($super_str);
		cout($super_rekap_str);
	cout('</div><!--/.row-->');
	/* 
	if (!authorizedModule("report_deposits_main", $ses_kduser)) {
		unAuthorizedAccess("report_deposits_main");
	} else {
		$fil_stgl = trim(cekpost(cleanQuery($_REQUEST["fil_stgl"]), ""));
		$fil_etgl = trim(cekpost(cleanQuery($_REQUEST["fil_etgl"]), ""));
		$fil_username = trim(cekpost(cleanQuery($_REQUEST["fil_username"]), ""));
		$fil_kdbank = trim(cekpost(cleanQuery($_REQUEST["fil_kdbank"]), ""));
		$fil_kdgame = trim(cekpost(cleanQuery($_REQUEST["fil_kdgame"]), ""));
		$fil_norek = trim(cekpost(cleanQuery($_REQUEST["fil_norek"]), ""));
		$fil_namarek = trim(cekpost(cleanQuery($_REQUEST["fil_namarek"]), ""));
		$swhere = '';
		$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;
		$fil_stgl = strtotime($stgl);
		$fil_etgl = strtotime($etgl);
		if ($fil_kdbank!="") { $swhere .= " AND a.kdbank='$fil_kdbank' "; }
		if ($fil_kdgame!="") { $swhere .= " AND a.kdgame='$fil_kdgame' "; }
		if ($fil_username!="") { $swhere .= " AND a.username LIKE '%$fil_username%' "; }
		if ($fil_norek!="") { $swhere .= " AND a.norek LIKE '%$fil_norek%' "; }
		if ($fil_namarek!="") { $swhere .= " AND a.namarek LIKE '%$fil_namarek%' "; }
		$q = "SELECT UNIX_TIMESTAMP(FROM_UNIXTIME(cleartime)) AS x, 
			UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) AS y,
			UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) AS z,
			a.*, a.username AS username_default, c.username, namabank, inisial, COALESCE(depo.jdepo,0) AS jdepox, e.nama AS nama_game
			FROM deposits a
			LEFT JOIN members b ON b.kdmember=a.kdmember
			LEFT JOIN accounts c ON c.kdaccount=b.kdaccount
			LEFT JOIN banks d ON d.kdbank=a.kdbank
			LEFT JOIN games e ON e.kdgame=a.kdgame
			LEFT JOIN (
				SELECT COUNT(kddeposit) AS jdepo, kdmember FROM deposits WHERE isclear=1
				GROUP BY kdmember
			) AS depo ON depo.kdmember = a.kdmember
			WHERE isclear = 1
			$swhere
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
			AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
			ORDER BY tanggal DESC";
		callRS($rs, $q);
		if (count($rs)!=0) {
			$ld = 50;
			$cp = cekpost(cleanQuery($_GET["cp"]), "1");
			$tp = intval(count($rs) / $ld) + (count($rs)%$ld==0?0:1);
			$sr = ($cp-1) * $ld;
			$pagination = '';
			if ($tp!=1) {
				$pagination .= ('<ul class="pagination pagination-sm">');
					$disabled = '';
					$purl = '#';
					$onclick = '';
					if ($cp<=1) {
						$disabled = 'disabled';
						$onclick = ' onclick="return false;" ';
					}
					$pagination .= ('<li class="'.$disabled.'"><a href="'.$purl.'" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', 1);return false;"').'>&lt;&lt;</a></li>');
					$pagination .= ('<li class="'.$disabled.'"><a href="'.$purl.'" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.($cp-1).');return false;"').'>&lt;</a></li>');
					for ($c=1;$c<=$tp;$c++) {
						$active = '';
						$purl = '#';
						$disabled = '';
						$onclick = '';
						if ($c==$cp) {
							$active = 'active';
						} else {
							$purl = '#';
							$onclick = ' onclick="filterReload(\''.$pageName.'\', '.$c.');return false;" ';
						}
						$pagination .= ('<li class="'.$active.' '.$disabled.'"><a href="'.$purl.'" '.$onclick.'>'.$c.'</a></li>');
					}
					$disabled = '';
					$onclick = '';
					if ($cp>=$tp) {
						$disabled = 'disabled';
						$onclick = ' onclick="return false;" ';
					}
					$pagination .= ('<li class="'.$disabled.'"><a href="#" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.($cp+1).');return false;"').'>&gt;</a></li>');
					$pagination .= ('<li class="'.$disabled.'"><a href="#" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.$tp.');return false;"').'>&gt;&gt;</a></li>');
				$pagination .= ('</ul>');
			}
			cout('<div class="alert alert-info" role="alert"><strong>Total whole data</strong> <span class="badge">'.count($rs).'</span></div>');
			
			if ($tp!=1) {
			#	cout($pagination);
			}
			cout('<table class="table table-striped table-bordered">');
				cout('<thead>');
					cout('<tr>');
						cout('<th class="text-center">TR#ID</th>');
						if (authorizedModule("report_deposits_element_games", $ses_kduser)) {
							cout('<th class="text-center">Games</th>');
						}
						if (authorizedModule("report_deposits_element_username", $ses_kduser)) {
							cout('<th class="text-center">UserID</th>');
						}
						if (authorizedModule("report_deposits_element_banks", $ses_kduser)) {
							cout('<th class="text-center">Banks</th>');
						}
						if (authorizedModule("report_deposits_element_bank_account_number", $ses_kduser)) {
							cout('<th class="text-center">Bank Account Number</th>');
						}
						if (authorizedModule("report_deposits_element_bank_account_holder", $ses_kduser)) {
							cout('<th class="text-center">Bank Account Holder</th>');
						}
						if (authorizedModule("report_deposits_element_amount", $ses_kduser)) {
							cout('<th class="text-center" colspan="2">Amount</th>');
						}
						if (authorizedModule("report_deposits_element_status", $ses_kduser)) {
							cout('<th class="text-center">Deposit Time</th>');
						}
						if (authorizedModule("report_deposits_element_status", $ses_kduser)) {
							cout('<th class="text-center">Approve Time</th>');
						}
						if (authorizedModule("report_deposits_element_status", $ses_kduser)) {
							cout('<th class="text-center">Process Time</th>');
						}
					cout('</tr>');
				cout('</thead>');
				cout('<tbody>');
				$total = 0;
				for ($i=0;$i<count($rs);$i++) {
					$total = $total + $rs[$i]["jumlah"];
				}
				cout('<tr class="data-ke-'.$kddeposit.'">');
					cout('<td class="text-right" colspan="6"><strong>Total Deposit</strong></td>');
					if (authorizedModule("report_deposits_element_amount", $ses_kduser)) {
						cout('<td class="text-center">Rp.</td>');
						cout('<td class="text-right"><strong>'.number_format($total).'</strong></td>');
					}
					cout('<td class="text-center" colspan="3"></td>');
				cout('</tr>');
				$cnt = 0;
				for ($i=0;$i<count($rs);$i++) {
				#for ($i=$sr;$i<count($rs) && $cnt<$ld;$i++) {
					$kddeposit = $rs[$i]["kddeposit"];
					$cnt++;
					$status = intval($rs[$i]["isactive"])==0?'Non-Active':'Active';
					$assigned = intval($rs[$i]["kdaccount"])==0?'Not Assigned Yet':'Assigned';
					cout('<tr class="data-ke-'.$kddeposit.'">');
						cout('<td class="text-center">'.$kddeposit.'</td>');
						if (authorizedModule("report_deposits_element_games", $ses_kduser)) {
							cout('<td class="text-center">'.$rs[$i]["nama_game"].'</td>');
						}
						if (authorizedModule("report_deposits_element_username", $ses_kduser)) {
							cout('<td class="text-center">'.$rs[$i]["username_default"].'</td>');
						}
						if (authorizedModule("report_deposits_element_banks", $ses_kduser)) {
							cout('<td class="text-center">'.$rs[$i]["inisial"].'</td>');
						}
						if (authorizedModule("report_deposits_element_bank_account_number", $ses_kduser)) {
							cout('<td class="text-center">'.$rs[$i]["norek"].'</td>');
						}
						if (authorizedModule("report_deposits_element_bank_account_holder", $ses_kduser)) {
							cout('<td class="text-center">'.$rs[$i]["namarek"].'</td>');
						}
						if (authorizedModule("report_deposits_element_amount", $ses_kduser)) {
							cout('<td class="text-center">Rp.</td>');
							cout('<td class="text-right">'.number_format($rs[$i]["jumlah"]).'</td>');
						}
						if (authorizedModule("report_deposits_element_status", $ses_kduser)) {
							cout('<td class="text-center">'.date('d-M-Y H:i:s', $rs[$i]["tanggal"]).'</td>');
						}
						if (authorizedModule("report_deposits_element_status", $ses_kduser)) {
							cout('<td class="text-center">'.date('d-M-Y H:i:s', $rs[$i]["cleartime"]).'</td>');
						}
						if (authorizedModule("report_deposits_element_status", $ses_kduser)) {
							cout('<td class="text-center">'.convertSecToStr($rs[$i]["cleartime"]-$rs[$i]["tanggal"]).'</td>');
						}
					cout('</tr>');
				}
				cout('<tr class="data-ke-'.$kddeposit.'">');
					cout('<td class="text-right" colspan="6"><strong>Total Deposit</strong></td>');
					if (authorizedModule("report_deposits_element_amount", $ses_kduser)) {
						cout('<td class="text-center">Rp.</td>');
						cout('<td class="text-right"><strong>'.number_format($total).'</strong></td>');
					}
					cout('<td class="text-center" colspan="3"></td>');
				cout('</tr>');
				cout('</tbody>');
			cout('</table>');
			
			if ($tp!=1) {
			#	cout($pagination);
			}
			cout('<div class="alert alert-info" role="alert"><strong>Total whole data</strong> <span class="badge">'.count($rs).'</span></div>');
			$act_ket = "Report Deposits: Main List";
			if ($swhere!="") { $act_ket .= ": ".cleanQuery($swhere).""; }
			updateUserActivities($act_ket);
		} else {
			cout('<div class="alert alert-info" role="alert">');
				cout('<strong>No data available.</strong> No Player do any deposits ;(');
			cout('</div>');
		}
	}
	*/
}
?>