<?php
@session_start();
include "control/activity.php";

 $dd = new activity();
 $loginStatus = $_SESSION['loginDetails'];


  if($loginStatus == null){
    echo "<script>window.open('login.php','_self')</script>";
  }


  $iid = $_REQUEST['iid'];
  $table = "funds_request INNER JOIN userdetails ON funds_request.userKey_id = userdetails.userKey";
  $condition = " where funds_request.funds_key='$iid'";
  $getDepositDetails = $dd->single($table,$condition);
  $fundsKey = $getDepositDetails['funds_key'];




  $table = "admin_calculation";
  $condition = null;
  $getAdminDetails = $dd->single($table,$condition);
  
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title><?= $getAdminDetails['title']; ?></title>
</head>
<body>

    <div class="main" id="main">
		  <?php include "menu.php"; ?>
    <div class="right"> 
  <div class="tab-content">


   <?php include "headermenu.php"; ?>


        <!-- Overview -->
         <div id="overview" class="tab-pane active"  >
                <div class="content" >
                  
               <div class="content-wrapper">
                 <div class="container-fluid">

                      <!--======================================================  Content  ====================================================-->                                            
                          <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                              <a href="dashboard.php">Funds Transfer..!!</a>
                            </li>
                          </ol>

                          <div class="row">
                              <div class="col-xl-4 col-sm-4 mb-4">
                                 <table class="table table-bordered">
                                    <form method="post">
                                    <tr>
                                        <th>Mobile Number : <input name="email" disabled value="<?= $getDepositDetails['mobile']; ?>" class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>UTR Number : <input name="email" disabled value="<?= $getDepositDetails['refrence_number']; ?>" class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>Request Date : <input id="memname" disabled value="<?= $getDepositDetails['request_date']; ?>" class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>Transfer Amount : <input name="amount" disabled value="<?= $getDepositDetails['amount']; ?>" class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>Confirm Amount : <input name="camount" disabled value="<?= $getDepositDetails['amount']; ?>"  class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <td><button name="transferNow" class="btn btn-success fa fa-transfer">TRANSFER FUNDS</button> 
                                    </form> <button onclick="gettocancelDetails(<?= $getDepositDetails['funds_key']; ?>)" class="btn btn-danger fa fa-transfer">CANCEL</button></td>
                                    </tr>
                                 </table>
                              </div>
                          </div>
  
                           
      <!--============  FIN DE L'AJOUT  ===============-->
      
      
      
     
      </div>
      <!-- /.container-fluid-->
       </div>  <!-- /content-wrapper-->


                </div>
                </div>
             </div><!--Right panel-->
</div><!--Main-->


</body>
</html>
<script>
  function gettocancelDetails(a)
  {
    var tttt = confirm('Are you sure to REJECT this..!!');
    if(tttt == true){
      window.open('fundsDepositCancel.php?fkey='+a,'_self');
    }
    
  }
</script>



<?php include "style.php" ?>

<?php
 if(isset($_POST['transferNow']))
 {
    $userKey = $getDepositDetails['userKey'];
    $amount = $getDepositDetails['amount'];
    if ($amount >= 2000)
    {
         $finalamount = $amount;
    }
    else
    {
         $finalamount = $amount;
    }
        $table = "userdetails";
        
        $value = "wallet=wallet+$finalamount";
        
        $condition = " userKey='$userKey'";
        $result = $dd->updateData($table,$value,$condition);
        if($result){

               $table = "userdetails";
               $condition = " where userKey='$userKey'";
               $getUserDetails = $dd->single($table,$condition);
               $avlbalance = $getUserDetails['wallet'];

               $date = date("H:i d/m/Y");
               $txnNumber = date("hisdmY").mt_rand(11,99);
               $table = "funds_request";
               $value = "funds_status='Approved',approved_date='$date',avl_balance='$avlbalance'";
               $condition = " funds_key='$fundsKey'";
               $result = $dd->updateData($table,$value,$condition);
               if($result){
                 echo "<script>alert('Transfer successfull..!!'),window.open('getDeposit_request_list.php','_self')</script>";
               }
            
        }
 }

?>