<?php
session_start();
include 'session_check.php';
require_once('include/constant.php');
include 'get_user_info.php';
require_once('include/functions.php');
$slt = "select * from wallet_balance where balance_user_id='$got_unique_id' ";
$slt_con2 = mysqli_query($conn, $slt);
if (mysqli_num_rows($slt_con2) > 0) {
	while ($row = mysqli_fetch_array($slt_con2)) {
		$total_balance = $row['total_balance'];
		$total_bv = $row['bv_balance'];
	}
}


?>

<head>
	<meta charset="UTF-8">
	<title>AdminLTE 2 | Dashboard</title>
	<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
	<!-- Bootstrap 3.3.2 -->
	<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<!-- FontAwesome 4.3.0 -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	<!-- Ionicons 2.0.0 -->
	<link href="https://code.ionicframework.com/ionicons/2.0.0/css/ionicons.min.css" rel="stylesheet" type="text/css" />
	<!-- Theme style -->
	<link href="dist/css/AdminLTE.min.css" rel="stylesheet" type="text/css" />
	<!-- AdminLTE Skins. Choose a skin from the css/skins 
         folder instead of downloading all of them to reduce the load. -->
	<link href="dist/css/skins/_all-skins.min.css" rel="stylesheet" type="text/css" />
	<!-- iCheck -->
	<link href="plugins/iCheck/flat/blue.css" rel="stylesheet" type="text/css" />
	<!-- Morris chart -->
	<link href="plugins/morris/morris.css" rel="stylesheet" type="text/css" />
	<!-- jvectormap -->
	<link href="plugins/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet" type="text/css" />
	<!-- Date Picker -->
	<link href="plugins/datepicker/datepicker3.css" rel="stylesheet" type="text/css" />
	<!-- Daterange picker -->
	<link href="plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" type="text/css" />
	<!-- bootstrap wysihtml5 - text editor -->
	<link href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet" type="text/css" />
	<!----    data table css file   ---->
	<link href="DataTables/datatables.min.css" rel="stylesheet" type="text/css">
	<!-----		sweet alert css and js link	---->
	<link rel="stylesheet" href="dist/sweetalert.css">
	<script src="dist/sweetalert.min.js"> </script>


	<link rel="stylesheet" type="text/css" href="custom/custom.css">
	<!---- Ck editor-->
	<script src="ckeditor/ckeditor.js"></script>

</head>

<?php
include 'include/header.php';
include 'include/left-nav.php';
?>

<?php


?>
<!-- Right side column. Contains the navbar and content of the page -->
<div class="content-wrapper">
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<h1>
			User wallet
			<small>Control panel</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="dashboard.php"><i class="fa fa-dashboard"></i> Home</a></li>
			<li class="active">user wallet</li>
		</ol>
	</section>

	<!-- Main content -->
	<section class="content">
		<!-- Small boxes (Stat box) -->
		<div class="row">
			<div class="col-sm-12">
				<div class="col-lg-4 col-xs-6">
					<!-- small box -->
					<div class="small-box bg-aqua">
						<div class="inner">
							<h3> <?php echo isset($total_balance) ? number_format((float)$total_balance, 2, '.', '') : 0.00; ?> </h3>
							<p>My balance</p>
						</div>
						<div class="icon">
							<i class="fa fa-money"></i>
						</div>
						<a href="wallet.php" class="small-box-footer"> More info <i class="fa fa-arrow-circle-right"></i></a>
					</div>
				</div><!-- ./col -->
				<!-- <div class="col-lg-4 col-xs-6">
              
              <div class="small-box bg-green">
                <div class="inner">
                  <h3> <?php echo isset($total_bv) ? $total_bv : 0; ?> </h3>
                  <p> My BV </p>
                </div>
                <div class="icon">
                  <i class="ion ion-stats-bars"></i>
                </div>
                <a href="wallet.php" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
              </div>
            </div>-->
				<!-- ./col -->
				<div class="col-lg-4 col-xs-6">
					<!-- small box -->
					<div class="small-box bg-yellow">
						<div class="inner">
							<?php
							$slt12 = "select SUM(purchase_product_price) from product_purchase where LOWER(purchase_user_id) = '" . strtolower(trim($got_unique_id)) . "' ";
							$slt_con12 = mysqli_query($conn, $slt12);
							if (mysqli_num_rows($slt_con12) > 0) {
								while ($row2 = mysqli_fetch_array($slt_con12)) {
									if ($row2['SUM(purchase_product_price)'] != '') {
										echo '<h3>' . number_format((float)$row2['SUM(purchase_product_price)'], 2, '.', '') . '</h3>';
									} else {
										echo '<h3> 0 </h3>';
									}
								}
							}
							?>
							<p> Buy products </p>
						</div>
						<div class="icon">
							<i class="ion ion-bag"></i>
						</div>
						<a href="buy_products.php" class="small-box-footer">More info <i class="fa fa-arrow-circle-right"></i></a>
					</div>
				</div><!-- ./col -->
			</div>







			<div class="row">
				<div class="col-sm-12" style="padding: 25px 20px; font-size: 18px; font-weight: 600">
					Transaction details
				</div>

				<!------------filter--------------->
				<form>
					<div class="well">
						<!--<div class="form-group">
						 <div class="row" style="max-width: 500px">
							   <div class="col-md-3">
								 Filter by Pair
							   </div>
							   <div class="col-md-5">
								   <select class="form-control filter_status" name="filter_status">
									 <option value=""> Select any pair </option>
									 <?php
										$pair_list = get_pair_msg('all');
										$pair_list = array_keys($pair_list);
										if (!empty($pair_list) && count($pair_list) > 0) {
											foreach ($pair_list as $pair) {
												echo '<option value="' . $pair . '"> ' . $pair . ' </option>';
											}
										}
										?>
								   </select>
							   </div>
						  </div>
					  </div>-->
						<div class="form-group">
							<div class="row">
								<div class="col-sm-2">
									From Date
								</div>
								<div class="col-sm-4">
									<input type="date" name="from_date" class="form-control">
								</div>
								<div class="col-sm-2">
									To Date
								</div>
								<div class="col-sm-4">
									<input type="date" name="to_date" class="form-control">
								</div>
							</div>
						</div>
						<div class="form-group">
							<div class="row">
								<div class="col-sm-12" style="">
									<button type="button" style="float: right; margin-left: 5px" name="search_button" class="btn btn-primary"> Search </button>
									<button type="reset" style="float: right" name="reset" class="btn btn-primary"> Reset </button>
								</div>
							</div>
						</div>
					</div>
				</form>
				<!------------filter--------------->


			</div>
			<!--- check user or admin -->
			<?php

			?>

			<div class="row">
				<div class="col-sm-10 col-sm-offset-1">
					<div class="table-responsive">
						<table id="wallet_report" class="table table-striped table-bordered nowrap" style="width:100%">

						</table>
					</div>
				</div>
			</div>
		</div>
		<?php

		?>

</div>
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<!-----  show some details  ---->

<!-----------------modal for transaction detail----->
<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal">&times;</button>
				<h4 class="modal-title text-center">Transaction Details</h4>
			</div>
			<div class="modal-body" style="line-height: 35px" id="modal_body">

			</div>
		</div>
	</div>
</div>
<!-----------------modal for transaction detail----->




<!-- jQuery 2.1.3 -->
<script src="plugins/jQuery/jQuery-2.1.3.min.js"></script>
<!-- jQuery UI 1.11.2 -->
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js" type="text/javascript"></script>
<?php
if ($status == 'Deactive') {
	include 'modal_show.php';
}
?>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
	$.widget.bridge('uibutton', $.ui.button);
</script>
<!-- Bootstrap 3.3.2 JS -->
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- Morris.js charts -->
<!-- <script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>-->
<!---<script src="plugins/morris/morris.min.js" type="text/javascript"></script>-->
<!-- Sparkline -->
<script src="plugins/sparkline/jquery.sparkline.min.js" type="text/javascript"></script>
<!-- jvectormap -->
<script src="plugins/jvectormap/jquery-jvectormap-1.2.2.min.js" type="text/javascript"></script>
<script src="plugins/jvectormap/jquery-jvectormap-world-mill-en.js" type="text/javascript"></script>
<!-- jQuery Knob Chart -->
<script src="plugins/knob/jquery.knob.js" type="text/javascript"></script>
<!-- daterangepicker -->
<script src="plugins/daterangepicker/daterangepicker.js" type="text/javascript"></script>
<!-- datepicker -->
<script src="plugins/datepicker/bootstrap-datepicker.js" type="text/javascript"></script>
<!-- Bootstrap WYSIHTML5 -->
<script src="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js" type="text/javascript"></script>
<!-- iCheck -->
<script src="plugins/iCheck/icheck.min.js" type="text/javascript"></script>
<!-- Slimscroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js" type="text/javascript"></script>
<!-- FastClick -->
<script src='plugins/fastclick/fastclick.min.js'></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js" type="text/javascript"></script>

<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<!-- <script src="dist/js/pages/dashboard.js" type="text/javascript"></script>-->
<!--  Data table js link   --->
<script src="DataTables/datatables.min.js"></script>


<script>
	$(document).ready(function() {
		rewards_data_load();
		//  filter by status
		$('button[name=search_button]').click(function() {
			rewards_data_load();
		});
		$('button[name=reset]').click(function() {
			setTimeout(function() {
				rewards_data_load();
			}, 400);
		});
	});

	function rewards_data_load() {

		//var status = $('.filter_status').children("option:selected").val();
		var from_date = $('input[name=from_date]').val();
		var to_date = $('input[name=to_date]').val();

		var resource = 'wallet_report';
		$.ajax({
			type: "POST",
			data: {
				resource: resource,
				from_date: from_date,
				to_date: to_date
			},
			url: "ajax_call_manage.php",
			success: function(response) {
				if (response.trim() != '') {
					$('#wallet_report').html(response.trim());
				}
				setTimeout(function() {
					$('#wallet_report').DataTable({
						"destroy": true, //use for reinitialize datatable
					});
				}, 1000);



			}
		});
	}


	/********* call transction modal details and append to the transaction modal ****/
	$('#wallet_report').on("click", '.wallet_class', function(e) {
		var wallet_id = $(this).attr("id");
		var id = wallet_id.split("wallet");
		console.log(id[1]);
		var resource = 'wallet_report';
		$.ajax({
			type: "POST",
			data: {
				resource: resource,
				id: id[1]
			},
			url: "ajax_call_manage.php",
			success: function(response) {
				console.log(response);
				if (response.trim()) {
					$('#myModal').modal('show');
					$('#modal_body').html(response.trim());
				}

			}
		});
	});
</script>

<?php
include 'include/footer.php';
?>