<?php
	include_once('../config.php');   
    include_once(ABS_PATH.'/custom_function/default.php');       
          
        
               
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
    
            if(isset($_POST['submit'])) 
            {            
                    $ext = explode(".",$_FILES['payment_slip']['name']);//explode file name from dot(.)   
                    $Fname =  substr(md5(uniqid()),26).".".end($ext);  
                    $target_path = ABS_PATH."/uploads/temp/".$Fname;//set the target path with a new name of image   
                    move_uploaded_file($_FILES['payment_slip']['tmp_name'], $target_path);   
                    
                    $URL =  ROOTPATH.'/uploads/temp/'.$Fname;
                    $access_token = "";
                    $ch = curl_init('http://api.qrserver.com/v1/read-qr-code/?fileurl='.$URL);                                             
                    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");                                                                     
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $access_token);                                                                  
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
                    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
                    'x-tera-tenant-region: IN', 
                    'Content-Type: application/json', 
                    'Content-Length: ' . strlen($access_token))                                                                       
                    );       																		 
                    $response = curl_exec($ch);  
                    $json_response = json_decode($response);  
                    $_SESSION['QRSET'] = $json_response[0]->symbol[0]->data; 
                    header("Location: Payout.php"); 
                    die;  
            }           
       
            $stmt=$conn->prepare("select *  from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
            $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_INT);  
            $stmt->execute(); 
            $UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
            
             
            $totalWithdrwa = 0;
            foreach($UI__WithDraw as $tl)
            {
                $totalWithdrwa +=$tl->amt;
            }
            
    $stmt=$conn->prepare("select nm  from UI__Rgst    where cuurentId=:cuurentId     ");   
    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_INT);  
    $stmt->execute(); 
    $UI__nm = $stmt->fetch(PDO::FETCH_OBJ);     
    $BY = $UI__nm->nm;
    
    $PAYWAllet =  ($Tamnt+$LevelI+$directIncome)-($totalWithdrwa);
  
    
include_once("../view/dashboard/scaQr.php");
?>