<?php
ob_start();
session_start();
if($_SESSION['userid']=="")
{
    header("location:index.php?msg1=notauthorized");
    exit();
}

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Adminsuit | Manage Transactions</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="plugins/select2/select2.min.css">
    <link rel="stylesheet" href="plugins/iCheck/all.css">
    <link href="css/custom.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/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="css/app.css" id="maincss">
<style>
    .nav-tabs>li>a{
        color:#000;
    }
    /*.nb{margin-top: -200px;}*/
</style>
</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
    <?php include ("include/connection.php");?>
    <?php include ("include/header.inc.php");?>
    <!-- Left side column. contains the logo and sidebar -->
    <?php include ("include/navigation.inc.php");?>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>Transactions</h1>
            <ol class="breadcrumb">
                <li><a href="desktop.php"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Transactions</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
           <div class="tabbable-responsive">
        <div class="tabbable">
          <ul class="nav nav-tabs" id="myTab" role="tablist">
            <li class="nav-item active">
              <a class="nav-link active" id="first-tab" data-toggle="tab" href="#first" role="tab" aria-controls="first" aria-selected="true">Level 1</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" id="second-tab" data-toggle="tab" href="#second" role="tab" aria-controls="second" aria-selected="false">Level 2</a>
            </li>
            <!--<li class="nav-item">
              <a class="nav-link" id="third-tab" data-toggle="tab" href="#third" role="tab" aria-controls="second" aria-selected="false">Level 3 (0)</a>
            </li>-->
          </ul>
        </div>
      </div>
      <div class="card-body">
      <div class="tab-content">
        <div class="tab-pane fade show active in" id="first" role="tabpanel" aria-labelledby="first-tab">
          <div class="table-responsive">
              <table class="table">
                <thead>
                  <tr>
                    
                    <th >ID</th>
                    <th >Phone</th>
                     <th scope="col">Commission</th>
                    <th >First Recharge</th>
                     <th >Total Recharge</th>
                    
                  </tr>
                </thead>
                <tbody>
                <?php 
      $userid=$_GET['ID'];
      $user=mysqli_query($con,"select * from `tbl_user` where `id`='".$userid."'");
	  $userResult=mysqli_fetch_array($user);
	  $owncode=$userResult['owncode'];
	  $userlevel1=mysqli_query($con,"select * from `tbl_user` where `code`='".$owncode."' order by id desc");
	  while($userlevel1Rows=mysqli_fetch_array($userlevel1))
	  {
	  
	  ?>
                  <tr>
                    
                    <td><?php echo $userlevel1Rows['id'];?></td>
                    <td><?php echo $userlevel1Rows['mobile'];?></td>
                    <td>
                    
                    <?php 
                    $id=$userlevel1Rows['id'];
                    $comsql =mysqli_query($con,"select * from  tbl_bonussummery  where level1id='$id'");
			        $comsqlResult=mysqli_fetch_array($comsql);
                    echo $comsqlResult['level1amount'];
                    
                    ?>
                    
                    </td>
                    <td>
                    <?php
            $id=$userlevel1Rows['id'];
            $firstrecharge=mysqli_query($con,"select * from  tbl_walletsummery  where userid='$id' and actiontype='recharge' and status='1'");
			$firstResult=mysqli_fetch_array($firstrecharge);
			// print_r($firstResult);exit;
            echo number_format($firstResult['amount'],2);
            ?></td>
            <td>
            <?php
            $id=$userlevel1Rows['id'];
            $firstrecharge12=mysqli_query($con,"select * from  tbl_walletsummery  where userid='$id' and actiontype='recharge' and status='1'");
            $rechtotalamount=0;
		while($firstResult12=mysqli_fetch_array($firstrecharge12))
		{
		 $rechtotalamount=$rechtotalamount+ $firstResult12['amount'];   
		}
            echo number_format($rechtotalamount,2);
            ?></td>
                    
                  </tr>
             <?php } ?>     
                </tbody>
              </table>
            </div>
        </div>
        
        <div class="tab-pane fade" id="second" role="tabpanel" aria-labelledby="second-tab">
          <div class="table-responsive nb">
              <table class="table">
                <thead>
                    
                  <tr>
                    
                    <th scope="col">ID</th>
                    <th scope="col">Phone</th>
                     <th scope="col">Commission</th>
                    <th >First Recharge</th>
                     <th >Total Recharge</th>
                    
                  </tr>
                  
                </thead>
                <tbody>
                    <?php 
      $userid=$_GET['ID'];
      $user=mysqli_query($con,"select * from `tbl_user` where `id`='".$userid."'");
	  $userResult=mysqli_fetch_array($user);
	  $owncode=$userResult['owncode'];
	  $userlevel1=mysqli_query($con,"select * from `tbl_user` where `code`='".$owncode."' order by id desc");
	  while($userlevel1Rows=mysqli_fetch_array($userlevel1))
	  {
	  $owncodeid=$userlevel1Rows['owncode'];
	  $userlevel2=mysqli_query($con,"select * from `tbl_user` where `code`='".$owncodeid."' order by id desc");
	  
	  while($userlevel2Rows=mysqli_fetch_array($userlevel2))
	  {
	      
	  ?>
                  <tr>
                   <td><?php echo $userlevel2Rows['id'];?></td>
                    <td><?php echo $userlevel2Rows['mobile'];?></td>
                     <td>
                     <?php 
                    $id2=$userlevel2Rows['id'];
                    $comsql1 =mysqli_query($con,"select * from  tbl_bonussummery  where level2id='$id2'");
			        $comsqlResult1=mysqli_fetch_array($comsql1);
                    echo $comsqlResult1['level2amount'];
                    
                    ?></td>
                    <td>
                    <?php
            $id2=$userlevel2Rows['id'];
            $firstrecharge2=mysqli_query($con,"select * from  tbl_walletsummery  where userid='$id2' and actiontype='recharge' and status='1'");
			$firstResult2=mysqli_fetch_array($firstrecharge2);
			// print_r($firstResult);exit;
            echo number_format($firstResult2['amount'],2);
            ?></td>
            <td>
                    <?php
            $id2=$userlevel2Rows['id'];
            $firstrecharge2123=mysqli_query($con,"select * from  tbl_walletsummery  where userid='$id2' and actiontype='recharge' and status='1'");
			$rechtotalamount123=0;
			while($firstResult2123=mysqli_fetch_array($firstrecharge2123))
			{
			  $rechtotalamount123=$rechtotalamount123+ $firstResult2123['amount'];     
			}
			// print_r($firstResult);exit;
            echo number_format($rechtotalamount123,2);
            ?></td>
                    
                  </tr>
                 <?php } }?>  
                </tbody>
              </table>
            </div>
        </div>
        </div>
        </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->

    <?php include("include/footer.inc.php");?></div>
<!-- ./wrapper -->


<script>

    $(function () {
        $('#example1').DataTable({
            "paging": true,
            "lengthChange": false,
            "searching": true,
            "ordering": false,
            "info": true,
            "autoWidth": true
        });
    });
</script>

</body>
</html>
