<?
include("../../config.php");
$id=$_GET['id'];
$acc_id=$_GET['exp'];
?>


    <?php include("inc/header.php") ?>


  <body data-spy="scroll" data-target="#navSection" data-offset="100">

    <?php include("inc/sidebar.php") ?>
    
    
    <!-- sidebar -->

    <div class="content">
      <div class="header">
        <div class="header-left">
          <a href="#" class="burger-menu"><i data-feather="menu"></i></a>

        </div><!-- header-left -->

        <div class="header-right">
          <a href="#" class="header-help-link"><i data-feather="help-circle"></i></a>
          <div class="dropdown dropdown-notification">
            <a href="#" class="dropdown-link new" data-toggle="dropdown"><i data-feather="bell"></i></a>
            <div class="dropdown-menu dropdown-menu-right">
              <div class="dropdown-menu-header">
                <h6>Notifications</h6>
                <a href="#"><i data-feather="more-vertical"></i></a>
              </div><!-- dropdown-menu-header -->
              <div class="dropdown-menu-body">
                <a href="#" class="dropdown-item">
                  <div class="avatar"><span class="avatar-initial rounded-circle text-primary bg-primary-light">s</span></div>
                  <div class="dropdown-item-body">
                    <p><strong>Socrates Itumay</strong> marked the task as completed.</p>
                    <span>5 hours ago</span>
                  </div>
                </a>
                
                
                
              </div><!-- dropdown-menu-body -->
              <div class="dropdown-menu-footer">
                <a href="#">View All Notifications</a>
              </div>
            </div><!-- dropdown-menu -->
          </div>
          <div class="dropdown dropdown-loggeduser">
            <a href="#" class="dropdown-link" data-toggle="dropdown">
              <div class="avatar avatar-sm">
                <img src="assets/img/img1.jpg" class="rounded-circle" alt="">
              </div><!-- avatar -->
            </a>
            <div class="dropdown-menu dropdown-menu-right">
              <div class="dropdown-menu-header">
                <div class="media align-items-center">
                  <div class="avatar">
                    <img src="assets/img/img1.jpg" class="rounded-circle" alt="">
                  </div><!-- avatar -->
                  <div class="media-body mg-l-10">
                    <h6>Louise Kate Lumaad</h6>
                    <span>Administrator</span>
                  </div>
                </div><!-- media -->
              </div>
              <div class="dropdown-menu-body">
                <a href="#" class="dropdown-item"><i data-feather="user"></i> View Profile</a>
                
                <a href="#" class="dropdown-item"><i data-feather="log-out"></i> Sign Out</a>
              </div>
            </div><!-- dropdown-menu -->
          </div>
        </div><!-- header-right -->
      </div><!-- header -->
      <div class="content-header">
        <div>
          
        <h4 class="content-title" style="padding-left:30px;">Confirm Clients Deposit  </h4>
        </div>
      </div><!-- content-header -->
     
      <div class="content-body content-body-components">
	   
          
           
            <div class="card card-body">
                
                
          <?
            
            $pay="select * from Deposit where dep_id='$id'";
            $paye=mysqli_query($conn, $pay);
            $payee=mysqli_fetch_array($paye);
            $fname=$payee['name'];
            $emai=$payee['email'];
            $amou=$payee['amount'];
            $exp=$payee['exp_id'];
            $proof=$payee['proof'];
            $credit=$payee['credit'];
            $dep_id=['dep_id'];
            $user_id = $payee['user_id'];
            
            $moneyy=$_POST['money'];
            $money=$_POST['money2'];
            
            
            
            $tran="select * from User where user_id='$user_id'";
            $tra=mysqli_query($conn, $tran);
            $tr=mysqli_fetch_array($tra);
            $paid=$tr['paid'];
            $balac=$tr['balance'];
            $emaii=$tr['email'];
            $imgg=$tr['image'];
            

            
            
            
            
            function get_percentage($total, $number)
{
  if ( $total > 0 ) {
   return round($number / ($total / 100),2);
  } else {
    return 0;
  }
}
            
            
            if(isset($_POST['start'])){
                
                $amount= $amou+$money;
            
                
                if($credit='yes' && $dep_id = $id){
                        
                
                
                $up="update Deposit set amount='$amount' where dep_id='$id'";
                        $upd=mysqli_query($conn, $up);
                        
                                
            
                        if($paid=='waiting'){
                            echo 'Please accept payment first';
                        
                        }else{
                            $balac=$balac+$money;
                            $op1="update User set balance='$balac' where user_id='$acc_id'";
                            $oop1=mysqli_query($conn, $op1);
                        }
                
                        $url = 'transaction.php';   
    
            echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
                }else{
                    echo 'please accept payment to start transaction';
                }
                
            }
            
            
            
            
            if(isset($_POST['startt'])){
                
                $amount= $amou-$moneyy;
            
                
                
                if($credit='yes' && $dep_id = $id){
                $up="update Deposit set amount='$amount' where dep_id='$id'";
                        $upd=mysqli_query($conn, $up);
                        
                                
            
                        if($paid=='waiting'){
                        echo 'please accept payment first';
                        
                        }else{
                            $balac=$balac-$moneyy;
                            $op1="update User set balance='$balac' where user_id='$acc_id'";
                            $oop1=mysqli_query($conn, $op1);
                        }

                    $url = 'transaction.php';   
    
            echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

                }else{
                    echo 'Accept payment to start transaction';
                }
            }
            
            
            if(isset($_POST['decline'])){
                $url = 'transaction.php';   
    
            echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
            }
            
            

            if(isset($_POST['accept'])){
                
                    $p="update Deposit set credit ='yes' where dep_id='$id'";
                        $rp=mysqli_query($conn, $p);
                        
                        
                        $balac=$balac+$amou;
                        
                    $q="update User set paid='ok', balance='$balac' where user_id='$acc_id'";
                    $qr=mysqli_query($conn, $q);
                    if($qr){
                        echo "<script type='text/javascript'> alert('Payment Accepted');document.location = 'transaction.php'; </script>";
                    }
                }
            
            
          ?>
        <div class="row">
            <div class="col-md-3">
                <div class="alert alert-danger">
                <strong>CLIENT INFORMATION TAB</strong>  
                </div>
               <br>
                <center>
<img src="../../SignUp/images/<? echo $imgg; ?>" class="img-responsive" style="max-width:120px;"/>
</center>
               
               <span class="label label-default">Fullname</span>
               <input type="text" readonly class="form-control" value="<? echo $fname; ?>"  />
               <span class="label label-default">User Email</span>
               <input type="text" readonly class="form-control" value="<? echo $emaii; ?>"  />
               <span class="label label-default">Amount Deposited</span>
               <input type="text" readonly class="form-control" value="<? echo $amou; ?>"  />
               <br>
               
              
                
               
               
            </div>
            <style>
                .clok {
                    border-radius:50px;
                }
            </style>
             <div class="col-md-3">
                 
                
                <div class="row">
                    
                   <div class="col-md-12 clok">
                       <center>
                      <span class="label label-default"><strong>Proof of Payment</strong></span><br><br>
               
               <img src="../../Userdashboard/img/<? echo $proof; ?>" class="img-responsive" width="120px" height="120px"/>
               </center>
                
                   </div>
                </div>
                
                <br>
                <form method="post">
                <div class="row">
                    <?
                    if($credit=='pending'){
                    ?>
                   <div class="col-md-12 clok">
                       <center>
                       <button class="btn btn-lg btn-success" name="accept" type="submit">Accept Payment</button></center>
                   </div>
                   <? }else{} ?>
                </div>
                <br>
                <div class="row">
                    <?
                    if($credit=='pending'){
                    ?>
                   <div class="col-md-12 clok">
                       <center>
                       <button class="btn btn-lg btn-warning" name="decline" type="submit">Decline Payment</button></center>
                   </div>
                   <? }else{} ?>
               </div>
               </form>
            </div>
             <!--<div class="col-md-3">
                 <form method="post">
                <div class="row">
                    <div class="col-md-12">
                        <h5>Increase the Profit on Deposit for this User</h5>
                        <br>
                        <label>By How Much do you want to increase it ?</label><br>
                        <input type="text" class="form-control" name="money2" placeholder=""/><br>
                        
                        
                        <button class="btn btn-lg btn-outline-info" name="start" type="submit">Start</button>
                        
                    </div>
                </div>
                </form>
                <br>
                
                 <div class="row">
                    <div class="col-md-12">
                        
                    </div>
                </div>
                
            </div>
             <div class="col-md-3">
                 <form method="post">
                <div class="row">
                    <div class="col-md-12">
                        <h5>Decrease the Profit on Deposit for this User</h5>
                        <br>
                        <label>By How Much do you want to Decrease it ?</label><br>
                        <input type="text" class="form-control" name="money" placeholder=""/><br>
                        
                        <button class="btn btn-lg btn-outline-info" name="startt" type="submit">Start</button>
                        
                    </div>
                </div>
                </form>
                <br>
                
                 <div class="row">
                    <div class="col-md-12">
                        
                    </div>
                </div>
                
            </div>-->
            
        </div>
      
                
                
                
                
  <!-- table-responsive -->
          </div>
            
            
       
		  <nav aria-label="Page navigation example" style="float:right; margin-top:10px; margin-right:10px;">
            <ul class="pagination pagination-outline mg-b-0">
              <li class="page-item disabled"><a class="page-link page-link-icon" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-left"><polyline points="15 18 9 12 15 6"></polyline></svg></a></li>
              <li class="page-item active"><a class="page-link" href="#">1</a></li>
              <li class="page-item"><a class="page-link" href="#">2</a></li>
              <li class="page-item"><a class="page-link" href="#">3</a></li>
              <li class="page-item"><a class="page-link page-link-icon" href="#"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"><polyline points="9 18 15 12 9 6"></polyline></svg></a></li>
            </ul>
          </nav>
        
	  
	  
         
      </div><!-- content-body -->
     
    </div><!-- content -->

	
	
	
	
	
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
    <script src="lib/jquery/jquery.min.js"></script>
    <script src="lib/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="lib/feather-icons/feather.min.js"></script>
    <script src="lib/perfect-scrollbar/perfect-scrollbar.min.js"></script>
    <script src="lib/prismjs/prism.js"></script>
    <script src="lib/js-cookie/js.cookie.js"></script>

    <script src="assets/js/cassie.js"></script>
    <script>
      $(function(){

        'use strict'

      })
    </script>
	
	<script>
      $(function(){

        'use strict'

        $('#modal6').on('show.bs.modal', function (event) {

          var animation = $(event.relatedTarget).data('animation');
          $(this).addClass(animation);
        })

        // hide modal with effect
        $('#modal6').on('hidden.bs.modal', function (e) {
          $(this).removeClass (function (index, className) {
              return (className.match (/(^|\s)effect-\S+/g) || []).join(' ');
          });
        });

      })
    </script>
  </body>

</html>
