<?php
	include_once('../../config.php');    
	 
	  
	                        
                      
                        $set = 0;
                        if(date("H:i")=="23:30")
                        $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  Rid from  UI__DChstr where typ=1  and (Rid!='DP112233')  group By Rid ");   
                                    $stmt->execute();  
                                    $UI__DailyROIGeneCt = $stmt->fetchAll(PDO::FETCH_OBJ);  
                                    echo '<pre>'; print_r($UI__DailyROIGeneCt); die; 
                                    
                                    
                                    foreach($UI__DailyROIGeneCt as $dmt)
                                    {      
                						 
                					 
                                       // if($dmt->bnsStatus==0) // level cond staRT
                                        {
                                
                                				$_POST['cuurentId'] = $dmt->Rid;    
                                				$MrefId= $dmt->id;
                                				$stmt=$conn->prepare("select refId,custId   from UI__Rgst where cuurentId =:cuurentId ");   
                                				$stmt->bindValue(':cuurentId',  $_POST['cuurentId'] , PDO::PARAM_INT);  
                                				$stmt->execute();  
                                                if($stmt->rowCount() > 0)
                                                {     
                                                    $ard = null;
                                                    $ard = [];
                                                    $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                                    $CC = $Result->refId;
                                                    $MyCust =  $Result->custId;
                                                    $ard[] = $CC;
                                                    for($i=0;$i<=9;$i++)
                                                    {
                                                        $stmt=$conn->prepare("select refId from UI__Rgst where cuurentId =:cuurentId ");   
                                                        $stmt->bindValue(':cuurentId',$CC, PDO::PARAM_INT);  
                                                        $stmt->execute();  
                                                        if($stmt->rowCount() > 0)
                                                        { 
                                                            $Result = $stmt->fetch(PDO::FETCH_OBJ);   
                                                            $CC = $Result->refId;
                                                            $ard[] = $CC;
                                                        }
                                                    }  
                                                }
                				
                				
                	                        
                	                
                			                    echo $_POST['cuurentId'].'<br>';
                                				 if(end($ard)==0)
                                                 {    
                                                            $MyBl = GtBalance($_POST['cuurentId']);
                                                            if($MyBl>10000) 
                                                            {   
                                                                for($j1=0;$j1<(count($ard)-1);$j1++)
                                                                {    
                                                                    
                                                                    if( ($j1==0)  )
                                                                    {  
                                                                       
                                                                        $REWARD = ($MyBl*0.05)/100;  
                                                                        if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }
                                                                    else if( ($j1==1) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.08)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }
                                                                    else if( ($j1==2) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.035)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }
                                                                    else if( ($j1==3) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.03)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }  
                                                                    else if( ($j1==4) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.025)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }  
                                                                    else if( ($j1==5) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.02)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }  
                                                                    else if( ($j1==6) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.015)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }
                                                                    else if( ($j1==7) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.01)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    } 
                                                                    else if( ($j1==8) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.005)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    }  
                                                                     else if( ($j1==9) )
                                                                    {  
                                                                        
                                                                        $REWARD = ($MyBl*0.005)/100;
                                                                         if( ($ard[$j1]!='DP112233') && ($ard[$j1]!='DP212871')) 
                                                                        AddFundNew($ard[$j1],round($REWARD),"Level Incentives");  
                                                                    } 
                                                                     
                                                                    }  
                                                             } 
                                                           
                                                }
                                    
                                    }	//level condotion end 
                
                                       
                					}// for end     
                					          
                        }