<?php 
session_start();
require('../db.php');
include('inc/session.php');
						
								
$user = $_SESSION['user'];
								
$ins = mysqli_query($conn,"SELECT * FROM users WHERE email='$user' ");
$data = mysqli_fetch_array($ins);
								
$email = $data['email'];
$rowpas = $data['pass'];
$bal = $data['bal'];

if(isset($_GET['id'])){
      
      $id = $_GET['id']; 
    
    $getuser = mysqli_query($conn, "SELECT * FROM users WHERE accno='$id' ");
    $qryuser = mysqli_fetch_array($getuser);
    
    $receiver = $qryuser['email'];
    $phone2 = $qryuser['phone'];
    $level2 = $qryuser['level'];
    $fname2 = $qryuser['firstname'];
    $lname2 = $qryuser['lastname'];
    $bal2 = $qryuser['bal'];  
    $status = $qryuser['status'];
    $bvn2 = $qryuser['BVN'];
    $date = $qryuser['joining_date'];
    $username2 = $qryuser['username'];
    $apikey2 = $qryuser['apikey'];
    $pass2 = $qryuser['pass'];
      
  }else{
      
      $receiver = "";
  }
							
$trans = "SELECT * FROM transactions WHERE email='$receiver' ORDER BY `date` DESC ";
$payment = $conn->query($trans);
			

$sm4 = "SELECT status from transactions WHERE email='$receiver' and status='Completed' ";
			  $acc4 =  mysqli_query($conn,$sm4);
			
			
			if(mysqli_num_rows($acc4)>0){
		   
		    $sms4_array = array();
				
			while($row = mysqli_fetch_assoc($acc4)){
			
		   $sms4_array[] = $row["status"];
			}}
			  $send = implode(",",$sms4_array);
			  
			  $trans1 = count($sms4_array);







include('../inc/logo.php');	

						?>  

<?php include('inc/header.php');?>
<body class="fixed-nav sticky-footer bg-light" id="page-top">
  <!-- Navigation-->
  <?php include('inc/nav.php');?>
        
  <!-- Navigation Ends-->  
      </ul>
      <ul class="navbar-nav sidenav-toggler">
        <li class="nav-item">
          <a class="nav-link text-center" id="sidenavToggler">
            <i class="fa fa-fw fa-angle-left"></i>
          </a>
        </li>
      </ul>
      <ul class="navbar-nav ml-auto">
      
       
            
        </li>
        <li class="nav-item">
         
        </li>
        <li class="nav-item">
        <a class="btn btn-secondary" href="logout.php">Logout</a>
          
        </li>
      </ul>
    </div>
  </nav>

  <div class="content-wrapper">
    <div class="container-fluid">
      <!-- Breadcrumbs-->
      <ol class="breadcrumb">
        <li class="breadcrumb-item">
          <a href="dashboard.php">Dashboard</a>
        </li>
        <li class="breadcrumb-item active">Transactions /  </li>
      </ol>
      <div class="row">
        <div class="col-12">
         
           <?php 
if($level2 === 'reseller'){
$accType2 = '<badge class="badge badge-pill badge-success">Portal Owner</badge>';
}elseif($level2 === 'agent'){
$accType2 = '<badge class="badge badge-pill badge-info">Agent/Reseller</badge>';
}elseif($level2 === 'special'){
$accType2 = '<badge class="badge badge-pill badge-success">Special User</badge>';
 }else{
 $accType2 = '<badge class="badge badge-pill badge-danger">Normal User</badge>'; }

if($status === 'Active'){
$status2 = '<badge class="badge badge-pill badge-success">Active</badge>';
}elseif($status === 'Pending'){
$status2 = '<badge class="badge badge-pill badge-info">Pending</badge>';
}elseif($status === 'Upgrade'){
$status2 = '<badge class="badge badge-pill badge-info">Pending</badge>';
 }else{
 $accType2 = '<badge class="badge badge-pill badge-danger">Pending</badge>'; }

?>




       
          <div class="card mb-3">
        <div class="card-header">
          <i class="fa fa-table"></i> Transactions History</div>
        <div class="card-body">

You are curently viewing the profile and transaction details of : <font color="red"><b><?php echo $fname2; ?> <?php echo $lname2;?> </b></font><br>

Name: <font color="red"><?php echo $fname2; ?> <?php echo $lname2;?> </font><br>
Email: <font color="red"><?php echo $receiver; ?> </font><br>
Username: <font color="red"><?php echo $username2; ?> </font><br>
Current Level: <?php echo $accType2; ?> <br>
Current Status: <font color="red"><?php echo $status2; ?> </font> <br>
Current BVN: <font color="red"><?php echo $bvn2; ?> </font> <br>
Current Phone: <font color="red"><?php echo $phone2; ?> </font> <br>
Current Balance: <font color="red"><?php echo $bal2; ?></font></strong><br>
Date Registered: <font color="red"><?php echo $date; ?></font></strong><br> 
Total Transactions:  <font color="red"><?php echo $trans1; ?></font></strong><br>
Current Apikey:  <font color="red"><?php echo $apikey2; ?></font></strong><br> <br>
<!--Current Password:  <font color="red"><?php echo $pass2; ?></font></strong><br> <br>-->

<a href="dashboard.php"> <div class="btn btn-danger">Back</div></a>  
<a href="activate-user.php?id=<?php echo $qryuser['accno']; ?>" class="btn btn-rounded btn-primary">Activate User</a>
<a href="upgrade-user.php?id=<?php echo $qryuser['accno']; ?>" class="btn btn-rounded btn-primary">Upgrade User</a>
<a href="update-user.php?id=<?php echo $qryuser['accno']; ?>" class="btn btn-rounded btn-primary">Update User Details</a>
<a href="update-pass.php?id=<?php echo $qryuser['accno']; ?>" class="btn btn-rounded btn-primary">Reset Password</a>
<a href="update-login.php?id=<?php echo $qryuser['accno']; ?>" class="btn btn-rounded btn-primary">Allow Login</a><br> <br>

          <div class="table-responsive">
            <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
            <thead>
              <tr>
                <!--<th>Ref</td>-->
                <th>Description</td>
                <th>Amount</td>
                <th>Amount <br>Paid</td>
                <!--<th>Customer</td>-->
               <th>Reseller Details</td>
                <th>Status</td>
                <th>BalanceB <br> (BalanceA) </td>
                <th>Date</td>
                <th></th>
               <th></th>
               <th></th>
                
                
              </tr>
              </thead>
              <tfoot>
              <tr>
                <!--<th>Ref</td>-->
                <th>Description</td>
                <th>Amount</td>
                <th>Amount <br>Paid</td>
                <!--<th>Customer</td>-->
                <th>Reseller Details</td>
                <th>Status <br> (Channel)</td>
                <th>BalanceB <br> (BalanceA) </td>
                <th>Date</td>
               <th></th>
               <th></th>
               <th></th>
                
              </tr>
              </tfoot>
              <tbody>
              <?php while($row_payment = $payment->fetch_assoc())
			  
			   { 
			   if($row_payment['status'] == 'Completed'){
							    
							    $tranStat = '<badge class="badge badge-pill badge-success">'.$row_payment['status'].'</badge>';
							}elseif($row_payment['status'] == 'Failed'){
							    
							    $tranStat = '<badge class="badge badge-pill badge-danger">'.$row_payment['status'].'</badge>';
							}elseif($row_payment['status'] == 'pending'){
								
							$tranStat = '<badge class="badge badge-pill badge-warning">'.$row_payment['status'].'</badge>';	
								}else{
								
								$tranStat = '<badge class="badge badge-pill badge-info">'.$row_payment['status'].'</badge>';		
									
									}	
			   ?>
                <tr>
                 <!-- <td><?php echo $row_payment['ref']; ?> </td>-->
                  <td><?php echo $row_payment['network']; ?> <br><?php echo $row_payment['phone']; ?> <br><?php echo $row_payment['meterno']; ?></td>
                  <td><?php  echo '&#x20A6;'.number_format($row_payment['amount'], 2, '.', ','). '';?> <br> </td>
                  <td><?php  echo '&#x20A6;'.number_format($row_payment['debit'],2, '.', ','). '';?> <br> </td>
                  
                  <!--<td><?php  echo $row_payment['customer']; ?> </td>-->
                  <td><?php  echo $row_payment['email'];; ?> <br> <?php  echo $row_payment['customer']; ?></td>
                  
                  <td><?php echo $tranStat; ?> <br> ( <?php echo $row_payment['channel']; ?> )</td>
                  <td><?php echo $row_payment['balanceB']; ?> <br> (<?php echo $row_payment['balanceA']; ?>)</td>
                  
                   <td><?php echo $row_payment['date']; ?></td>
                   
                    <td><a href="remov.php?reverse=<?php echo $row_payment['serial']; ?>"><?php if(!empty($row_payment['action'])){echo '<div class="btn btn-info">'.$row_payment['action'].'</div>';} ?></a></td>
                    
                    <td><a href="remov.php?credit=<?php echo $row_payment['serial']; ?>"><?php if(!empty($row_payment['credit'])){echo '<div class="btn btn-success">'.$row_payment['credit'].'</div>';} ?></a></td>
                   
                   <td><a href="remov.php?deltra=<?php echo $row_payment['serial']; ?>"><?php if(!empty($row_payment['del'])){echo '<div class="btn btn-danger">'.$row_payment['del'].'</div>';} ?></a></td>
                   
                  
                </tr>
                
                <?php } ?>
                </tbody>
            </table>
          </div>
        </div>
        <div class="card-footer small text-muted"></div>
      </div>
    </div>
    <!-- /.container-fluid-->
        </div>
      </div>
    </div>
    <!-- /.container-fluid-->
    <!-- /.content-wrapper-->
    <?php include('inc/footer.php');?>

 <!--============================ Modal starts here=============================== -->
                                                <div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2" aria-hidden="true">
                                                    <div class="modal-dialog" role="document">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h4 class="modal-title" id="exampleModalLabel2">Resend OTP</h4>
                                                                <a href="#" class="close" data-dismiss="modal" aria-label="Close">
                                                                            <span aria-hidden="true">&times;</span>
                                                                        </a>
                                                                   
                                                                      
                                                                        
                                                            </div>
                                                                                                    

                                                            <div class="modal-body">                                                      
                                                           <p><form method="POST" action="" accept-charset="UTF-8">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                 
                              <tr>
                                        <td>Phone</td>
                                        <td><input class="form-control"  name="email" type="text" value=""></td>
                                    </tr>
                                </table>
                            </div>
                            </p>
                                                            
                                                            <div class="modal-footer">
                                                                <a href="#" class="btn btn-secondary" data-dismiss="modal">Close</a>
                                                                <button type="submit" name="withdraw" class="btn btn-success">Resend OTP</button>
                                                            </div>
                                </form> 

                                <!--====================================Modal ends here============================-->