<?php
	include_once('../config.php');   
    include_once(ABS_PATH.'/custom_function/default.php');  
          
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
    
			    
    
    
    if(isset($_POST['Submit'])) 
    {   
                
            $PAYWAllet =  GetBalance();    
            if($PAYWAllet>$_POST['amtG'])
            { 
                
                
                    $stmt=$conn->prepare("select  inrVal     from    UI__USDTINR    ");    
                    $stmt->execute(); 
                    $dateOfra = $stmt->fetch(PDO::FETCH_OBJ);  
                                
                              
                    $stmt=$conn->prepare("insert into   UI__USDTRest (custId,AMMT,PgTYpe,address,Tdate,INRVAl) values(:custId,:AMMT,2,:address,:Tdate,:INRVAl)"); 
                    $stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
                    $stmt->bindValue(':custId', $_SESSION['userId'] , PDO::PARAM_STR);  
                    $stmt->bindValue(':AMMT', $_POST['amtG'] , PDO::PARAM_STR); 
                    $stmt->bindValue(':address',$_POST['address'], PDO::PARAM_STR); 
                    $stmt->bindValue(':INRVAl',$dateOfra->inrVal, PDO::PARAM_STR); 
                    $stmt->execute();  
                    $LAtINt = $conn->lastInsertId();
                  
                    $payee_txn_id = mt_rand(29902,23894);
                    $stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,order_id,bank_remark,status,accept) values(:userid,:Tdate,:amt,:orgAmt,:order_id,:bank_remark,:status,:accept)"); 
                    $stmt->bindValue(':userid',   $_SESSION['userId']  , PDO::PARAM_STR);   
                    $stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
                    $stmt->bindValue(':amt',$_POST['amtG'] , PDO::PARAM_STR);
                    $stmt->bindValue(':orgAmt', $_POST['amtG'] , PDO::PARAM_STR); 
                    $stmt->bindValue(':order_id',  $payee_txn_id , PDO::PARAM_STR); 
                    $stmt->bindValue(':bank_remark', "PA", PDO::PARAM_STR); 
                    $stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
                    $stmt->bindValue(':accept', 1 , PDO::PARAM_STR);      
                    $stmt->execute();
                    
                    LvBal($_SESSION['userId'],$_POST['amtG'],2,"USDT Withdrawls",$_SESSION['userId']);   
                    
                    $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                    $stmt->execute();
                    $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);  
                    
                    
                   /* $stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
                    $stmt->bindValue(':type',   7 , PDO::PARAM_STR);   
                    $stmt->bindValue(':bank',  "IMPS Tranfered" , PDO::PARAM_STR);   
                    $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                    $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                    $stmt->bindValue(':amountPaid', $deduction  , PDO::PARAM_STR); 
                    $stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
                    $stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
                    $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
                    $stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR);  
                    $stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
                    $stmt->bindValue(':Topay',  $beneficiary_accountno , PDO::PARAM_STR); 
                    $stmt->bindValue(':TopayName',  $beneficiary_accountno  , PDO::PARAM_STR);     
                    $stmt->execute();  */
                        
                    $_SESSION['Regis'] = "Request Sent Successfully"; 
                    header("Location: USDT3.php?id=".$LAtINt); 
                    die;

            }else
            {
            $_SESSION['Regis'] = "Request Sent Successfully"; 
            header("Location: USDT_Depo.php"); 
            die;
            }
            
     }       
    
                    
                    $stmt=$conn->prepare("select  inrVal     from    UI__USDTINR    ");   
                    //$stmt->bindValue(':randNo', $_REQUEST['randNo'] , PDO::PARAM_STR); 
                    $stmt->execute(); 
                    $dateOfra = $stmt->fetch(PDO::FETCH_OBJ); 
           

include_once("../view/dashboard/USDT_Depo.php");
?>