<?php

include("../config.php");
session_start();

if(isset($_SESSION["user_login"])){
	$userid = $_SESSION["user_login"];
}else{
		header("location: ../register-login.php");
	}
	
	
	

		//get user info
		
		$stmt="SELECT * FROM users WHERE userid = :userid";
		$stmt=$pdo->prepare($stmt);
		$stmt->bindParam("userid", $userid, PDO::PARAM_STR);
		$stmt->execute();
		$row=$stmt->fetch();
		$userimage = (!empty($row["profilepix"]) ? "../img/users/".$row["profilepix"]: "../img/avatar.png");
		
		
		//redirect incase it was admin
		if($row["type"]=="admin"){
			header("location: ../admin/dashboard.php");
		}
		
		//Generate unique transcation ID
		$gen = "ABCDEFGHIJKlmnopqrstuvwxyz1234567890";
		$shuff = str_shuffle($gen);
		$ref = substr($shuff,0,25);
	
?>

<style>
form label{
	font-weight:500!important;
	color:#444;
	cursor:pointer;
	font-size:16px!important;
}

.prime-hover{
	color:#4583c3;
	font-weight:500;
	cursor:pointer;
}
.prime-hover:hover{
	color:#3d77b3;
}
select{
	-moz-appearance:none;
	-webkit-appearance:none;
	appearance:none;
	text-indent:1px;
	text-overflow:'';
}
</style>


<!DOCTYPE html>

<html lang="en">

<head>

        <meta charset="utf-8" />

        <title> Transaction History | Six Digital Assets</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <meta content="A fully featured cryptocurrency investment platform" name="description" />

        <meta content="Coderthemes" name="author" />

        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

      

            <link rel="stylesheet" type="text/css" href="w3.css">

        <!-- Bootstrap Css -->

        <link href="assets/css/bootstrap.min.css" id="bootstrap-stylesheet" rel="stylesheet" type="text/css" />

        <!-- Icons Css -->

        <link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <!-- App Css-->

        <link href="assets/css/app.min.css" id="app-stylesheet" rel="stylesheet" type="text/css" />

			<link href="../css/style7eda3860.css" rel="stylesheet">

    </head>



    <body>


	<div class='coversoverlay'>
	<center><img src="../img/loader.gif" style="width:60px; margin-top:20%;"></center>
	</div>

  <!-- Begin page -->
  <div id="wrapper" style="overflow:auto!important">

 
 
	<!-- Topbar Start -->
	<?php
	include("header.php");
	?>
    <!-- end Topbar -->
 
 

    <!-- ========== Left Sidebar Start ========== -->
    <div class="left-side-menu">

      <div class="slimscroll-menu">

        <!-- User box -->
        <div class="user-box text-center ">

          <div class="dropdown">
            <a href="#" class="user-name dropdown-toggle h5 mt-2 mb-1 d-block" data-toggle="dropdown" aria-expanded="false"></a>
            <div class="dropdown-menu user-pro-dropdown">




            </div>
          </div>


        </div>

        <!--- Sidemenu -->
        <?php include("sidebar.php");?>
		
        <!-- End Sidebar -->
        <div class="clearfix"></div>



                </div>

                <!-- Sidebar -left -->



            </div>

            <!-- Left Sidebar End -->






            <div class="content-page" >

                <div class="content" style="width: 100%;color: white;">



                    <!-- Start Content-->

                    <div class="container-fluid" >

                        <div id="google_translate_element"></div>

                         <div class="row">

                            <div class="col-md-12" style="padding-left:0px; padding-right:0px">
                            
						
						
				<div class="col-md-7" style="margin-top:20px!important;margin: auto;">
				
                <div class="card-box">
				<h3 align="center" style='color:#767e80' id="wlcm"><i class="fas fa-history"></i> Transactions</h3>
				<div class="dropdown-divider"></div>




			<?php	
		//Get Total Approved Investments
		$stmt=$pdo->prepare("SELECT SUM(amount) AS total FROM transactions WHERE type='investment' AND status='approved' AND userid = :userid");
		$stmt->bindParam(":userid",$userid, PDO::PARAM_STR);
		$stmt->execute();
		$sumInv = $stmt->fetch();
		
		
		//Get Total Approved Withdrawals
		$stmt=$pdo->prepare("SELECT SUM(amount) AS total FROM transactions WHERE type='withdrawal' AND status='approved' AND userid = :userid");
		$stmt->bindParam(":userid",$userid, PDO::PARAM_STR);
		$stmt->execute();
		$sumWith = $stmt->fetch();
		?>
		
		
		<div style="color:#405972; font-size:15px; margin-top:4px;text-align:left">
		<b>Total Approved Investments</b><br>
		<div style="color:#2aab00;font-size:14px;margin-top:4px;">$ <?php echo number_format(intval($sumInv["total"]))?>.00</div>
		</div>
		<div class="dropdown-divider" style="border-color:#e9eff5;"></div>
		
		
		<div class="dropdown-divider" style="border-color:#e9eff5;"></div>
		<div style="color:#405972; font-size:15px; margin-top:4px;text-align:left">
		<b>Total Approved Withdrawals</b><br>
		<div style="color:#e13131;font-size:14px;margin-top:4px;">$ <?php echo number_format(intval($sumWith["total"]))?>.00</div>
		</div>
		<div class="dropdown-divider" style="border-color:#e9eff5;"></div>
		




			
				
				
				
		<?php	
		$stmt=$pdo->prepare("SELECT * FROM transactions WHERE userid = :userid ORDER BY id DESC");
		$stmt->bindParam("userid", $userid, PDO::PARAM_STR);
		$stmt->execute();
		$tran=$stmt->fetchAll();
		$count = 1;
		if($stmt->rowCount()<1){
			echo '<h4 class="title" style="text-align: center;">No recorded transaction</h4>';
		}else{
		?>
				<div class="transact-con">
				<table class="table table-bordered">
				
				<thead class="thead-dark">
				<th>S/N</th>
				<th>Status</th>
				<th>Date</th>
				<th>Transaction</th>
				<th>Plan</th>
				<th>Amount</th>
				<th>Reference ID</th>
				</thead>
					
		<?php
		foreach($tran as $trans){	
		?>
		
		<tr>
		<td><?php echo $count++;?></td>
		<td><?php echo htmlspecialchars($trans["status"]);?></td>
		<td><?php echo date("d/m/y", strtotime($trans["dateTime"]));?></td>
		<td><?php echo htmlspecialchars($trans["type"]);?></td>
		<td><?php if(empty($trans["plan"])){echo "<center>- -</center>";}else{echo htmlspecialchars($trans["plan"]);}?></td>
		<td><?php echo "$". htmlspecialchars(number_format($trans["amount"]));?></td>
		<td><?php echo htmlspecialchars($trans["ref"]);?></td>
		</tr>
		
			
		<?php } }?>

		  </table>
		  </div>
			   
			   
		<p>
		<div class="dropdown-divider"></div>
		<div style="text-align:center">
		<a href="account.php" style="color:#2e657e; font-size:16px;"><i class="fas fa-tachometer-alt"></i> Dashboard</a> 
		&nbsp; &nbsp; <a href="../" style="color:#2e657e; font-size:16px;"> <i class="fas fa-home"></i> Back Home</a>
		</div> 
			   
			   
			   
			   
			   
               </div>
              </div>

                   
						   </div>
							</div> <!-- container-fluid -->



                </div> <!-- content -->
                </div> 
              
					</div> 
	
					</div>
               


       

        <!-- Vendor js -->

        <script src="assets/js/vendor.min.js"></script>



        <!-- knob plugin -->

        <script src="assets/libs/jquery-knob/jquery.knob.min.js"></script>



        <!--Morris Chart-->

        <script src="assets/libs/morris-js/morris.min.js"></script>

        <script src="assets/libs/raphael/raphael.min.js"></script>



        <!-- Dashboard init js-->

        <script src="assets/js/pages/dashboard.init.js"></script>



        <!-- App js -->

        <script src="assets/js/app.min.js"></script>

   
   
   
   
   
   
   
   
   
   <script>
   
   $(document).ready(function(){
	   $(".coversoverlay").hide();
   });
  
   </script>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
    </body>

</html>