<?php
	include_once('../../config.php');    
	 
	  
	                        
                      
                        $set = 0;
                        if(date("H:i")=="23:00")
                        $set = 1;     


                         function GtBalance($CustId)
                    { 
                        global $conn;
                        {
                                $stmt=$conn->prepare("select amount from UI__DailyROIGeneAtw    where custId=:sId     ");   
                                $stmt->bindValue(':sId',  $CustId , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                                
                                $Tamnt = 0;
                                foreach($XUI__DailyROIGene as $xx)
                                {
                                $Tamnt +=$xx->amount;
                                }
        
                                $stmt=$conn->prepare("select amount  from UI__DailyROIGene    where custId=:sId     ");   
                                $stmt->bindValue(':sId',  $CustId , PDO::PARAM_STR);  
                                $stmt->execute(); 
                                $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                                
                                 
                                foreach($XUI__DailyROIGene as $xx)
                                {
                                $Tamnt +=$xx->amount;
                                }      
                                
                                
                                $stmt=$conn->prepare("select Tamt  from UI__BnsAtw    where Rid =:sId   ");   
                                $stmt->bindValue(':sId',  $CustId , PDO::PARAM_STR);   
                                $stmt->execute(); 
                                $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                
                                $LevelI = 0; 
                                foreach($UI__Bns as $dddm)
                                {
                                $LevelI +=$dddm->Tamt;
                                }
        
                                $stmt=$conn->prepare("select Tamt from UI__Bns    where Rid =:sId   ");   
                                $stmt->bindValue(':sId',  $CustId , PDO::PARAM_STR);  
                                $stmt->execute(); 
                                $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                
                                
                                foreach($UI__Bns as $dddm)
                                {
                                $LevelI +=$dddm->Tamt;
                                }
                                
                                
                                $stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
                                $stmt->bindValue(':refId',  $CustId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
                                
                                $directIncome = 0;
                                foreach($MdirectB as $dmm)
                                $directIncome += $dmm->Amt;                
                                
                                
                                
                                
                                $stmt=$conn->prepare("select amt from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
                                $stmt->bindValue(':sId',  $CustId , 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 availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
                                $stmt->bindValue(':userid',  $CustId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ); 
                                
                                
                                
                                $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+$UI__Fundtransfer->availableFund)-($totalWithdrwa);     
                                return $PAYWAllet;
                        }
                        
                    }  
                            
                        if( ($_REQUEST['etththv']=='NEUIEUBNDDOUIOEIONKLV6897634fnfvBVKV34') && ($set==1)) 
                        {
                                    
                                    $stmt=$conn->prepare("select   * from   UI__UserInsetive     ");   
                                    $stmt->execute();  
                                    $UI__UserInsetive = $stmt->fetchAll(PDO::FETCH_OBJ);  
                                    
                                    foreach($UI__UserInsetive as $sp)
                                    {     
                                        $REWARD = (GtBalance($sp->custId)*0.0025); 
                                        AddFundNew($sp->custId,$REWARD,"Incentives");  
                                    }
                        }