<?php
include_once('../config.php');     
   
   
                   
            	
            if(!isset($_SESSION['userId']))
            { 
                 header("Location: ../");
                 die;
            }   
            
            
                  
            $stmt=$conn->prepare("select *   from  UI__Bns    where Rid =:userid   and PaidDate=''  ");   
            $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_STR);  
            $stmt->execute(); 
            $UI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);    
            
             
            
            $totalTrade = 0; 
            foreach($UI__DailyROIGene as $mmt)
                $totalTrade += $mmt->Tamt;   
            
           
           
			  
			$stmt=$conn->prepare("select *  from UI__WithDraw    where userid =:sId   ");   
            $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->orgAmt;
            }
              
                 
            if(isset($_POST['Proceed'])) 
            { 
                $FtAmt = (($totalTrade)-($totalWithdrwa));
                $Famt = ($_POST['Fund']*10)/100;
                $_SESSION['Proceed']  = ($_POST['Fund']-$Famt);  
                $_SESSION['OrigailProceed']  = $_POST['Fund'];
                header("Location: withdrw.php");
                die;
            } 

            if(isset($_POST['submit'])) 
            { 
                /*
                if( (date("H")>=7)  && (date("H")<=9))
                {     
                    if(($_POST['OrigailProceed'] >= 400))  
                    {    
                       $custIdResult2 =  (($totalTrade)-($totalWithdrwa));  
                        if($custIdResult2 >= $_POST['OrigailProceed']) 
                        {  
                            $stmt=$conn->prepare("insert into UI__WithDraw (userid,Tdate,amt,orgAmt) values(:userid,:Tdate,:amt,:orgAmt)  ");   
                            $stmt->bindValue(':userid', $_SESSION['userId'] , PDO::PARAM_STR); 
                            $stmt->bindValue(':Tdate', date("d-M-Y H:i"), PDO::PARAM_STR); 
                            $stmt->bindValue(':amt', ($_POST['MyFinalWithdraw']) , PDO::PARAM_STR); 
                            $stmt->bindValue(':orgAmt', ($_POST['OrigailProceed']) , PDO::PARAM_STR);     
                            $stmt->execute();        
                            $_SESSION['Regis'] = 1;
                            header("Location: withdrw.php");
                            die;
                        }
                    }else {
                            $_SESSION['Regis'] = "Failed";  
                            header("Location: withdrw.php");
                            die;
                    }
                }*/
             }         

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