<?php
	include_once('../config.php');    
	include_once(ABS_PATH.'/custom_function/default.php');  
	    
	    
             
        $set = 0;
        if(date("H:i")=="00:45")
        $set = 1;     
 					     
                if(($_REQUEST['Ffnvwvbv']=='NEUIEUBNDDOUIOEIONKLV6897634fnfvBVKV34') && ($set==1)) 
	            {    
	    
                    $stmt=$conn->prepare("select  *   from  UI__Mtwi  where status=1   ");   
                    $stmt->execute();  
                    $UI__DailyROIGeneCt = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    //echo '<pre>'; print_r($UI__DailyROIGeneCt); die;  
                    
                    foreach($UI__DailyROIGeneCt as $dmt)
                    {           
                        
                                //end    
                
                				$_POST['cuurentId'] = $dmt->custId;    
                				$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;
                                        }
                                    }  
                                }
				
				
				     
				                
				 $data['Data'] = $dmt->Amt;       
				 if(end($ard)==0)
                 {  
                    for($j1=0;$j1<(count($ard)-1);$j1++)
                    {
                        if($j1==0)
                        {       
                                $CoinVal = ($data['Data']*0.1)/100;     
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 1  , PDO::PARAM_STR); 
                                $stmt->execute();   
                                
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }      
                        }
                        else if($j1==1)
                        { 
                                  $CoinVal = ($data['Data']*0.08)/100;        
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 2  , PDO::PARAM_STR); 
                                $stmt->execute();   
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
                             
 					    }else if($j1==2)
                        { 
                                $CoinVal = ($data['Data']*0.07)/100;          
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 3  , PDO::PARAM_STR); 
                                $stmt->execute();    
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
                             
 					    }else if($j1==3)
                        { 
                                $CoinVal = ($data['Data']*0.06)/100;        
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 4  , PDO::PARAM_STR); 
                                $stmt->execute();   
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
                             
 					    }else if($j1==4)
                        {
                            
                                $CoinVal = ($data['Data']*0.05)/100;        
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 5  , PDO::PARAM_STR); 
                                $stmt->execute();      
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
                              
 				        }else if($j1==5)
                        { 
                        
                                $CoinVal = ($data['Data']*0.04)/100;            
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 6  , PDO::PARAM_STR); 
                                $stmt->execute();            
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
                             
 					    }else if($j1==6)
                        { 
                        
                                $CoinVal = ($data['Data']*0.03)/100;        
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 7  , PDO::PARAM_STR); 
                                $stmt->execute();           
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
 					    }else if($j1==7)
                        { 
                        
                                $CoinVal = ($data['Data']*0.02)/100;           
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 8  , PDO::PARAM_STR); 
                                $stmt->execute();     
                                if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
 					    }else if($j1==8)
                        { 
                             
                                $CoinVal = ($data['Data']*0.01)/100;           
                                $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                                $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                                $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                                $stmt->bindValue(':level', 9 , PDO::PARAM_STR); 
                                $stmt->execute();  
                               if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
 					   }else if($j1==9)
                        { 
                            
                            $CoinVal = ($data['Data']*0.01)/100;           
                            $stmt=$conn->prepare("insert into  UI__BnsAtw (Rid,Brid,Tdate,Tamt,BAmt,level) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level)");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR); 
                            $stmt->bindValue(':Brid', $_POST['cuurentId'], PDO::PARAM_STR); 
                            $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR); 
                            $stmt->bindValue(':Tamt', $CoinVal , PDO::PARAM_STR);   
                            $stmt->bindValue(':BAmt', $data['Data'] , PDO::PARAM_STR);      
                            $stmt->bindValue(':level', 10  , PDO::PARAM_STR); 
                            $stmt->execute();     
                            if($ard[$j1]!='DP112233') 
                                {
                                    LvBal_new($ard[$j1],$CoinVal,1,"ATW Level Balance",$_POST['cuurentId']);    
                                }   
                            
 					      }
 					      
                         }
                      }  
					}// for end   
					
					
				     
                    { 
                    				       
                        $stmt=$conn->prepare("select  *   from   UI__ConirmQr where trasnferStatus = 0 and tranfredDate=''  group by custId");   
                        $stmt->execute();  
                        $UI__DailyROIGeneCt = $stmt->fetchAll(PDO::FETCH_OBJ);  
                         
                         
                        $yestDay = date('d-M-Y', strtotime('-1 day', strtotime(date("d-M-Y")))); 
                        foreach($UI__DailyROIGeneCt as $mpp)
                        {
                            
                            $stmt=$conn->prepare("select  *   from   UI__ConirmQr where custId=:custId and  trasnferStatus = 0 and tranfredDate='' ");   
                            $stmt->bindValue(':custId',  $mpp->custId , PDO::PARAM_STR);   
                            $stmt->execute();  
                            $UI__ConirmQr = $stmt->fetchAll(PDO::FETCH_OBJ); 
                            
                            $amt = 0;
                            foreach($UI__ConirmQr as $mp)
                                 $amt +=$mp->Amt; 
                            
                            
                            $stmt=$conn->prepare("select  *   from   UI__CollTopup where custId=:custId and Tdate=:Tdate ");   
                            $stmt->bindValue(':custId',  $mpp->custId , PDO::PARAM_STR);   
                            $stmt->bindValue(':Tdate', $yestDay , PDO::PARAM_STR);   
                            $stmt->execute();  
                            $UI__CollTopup = $stmt->fetchAll(PDO::FETCH_OBJ); 
                            
                            $camt =0;
                            foreach($UI__CollTopup as $mp)
                                 $camt +=$mp->Amt; 
                                  
                             
                            AddFundNew($mpp->custId,($amt-$camt),"Collection QR Transfered");  
                            
                            
                            $stmt=$conn->prepare("update   UI__ConirmQr  set tranfredDate=:tranfredDate ,trasnferStatus = 1 where  custId=:custId  ");   
                            $stmt->bindValue(':tranfredDate',  date("d-M-Y") , PDO::PARAM_STR);   
                            $stmt->bindValue(':custId',  $mpp->custId , PDO::PARAM_STR);   
                            $stmt->execute(); 
                            
                            
                            $stmt=$conn->prepare("insert into  UI__ConirmQr(custId,Tdate,Amt,tranfredDate,trasnferStatus,type,sender_vpa,sender_name,balance) values(:custId,:Tdate,:Amt,:tranfredDate,1,1,'NA',:sender_name,0)"); 
                            $stmt->bindValue(':custId',    $mpp->custId , PDO::PARAM_STR);   
                            $stmt->bindValue(':Tdate',   date("d-M-Y") , PDO::PARAM_STR);   
                            $stmt->bindValue(':Amt',   ($amt-$camt) , PDO::PARAM_STR); 
                            $stmt->bindValue(':tranfredDate',   date("d-M-Y H:i") , PDO::PARAM_STR);  
                            $stmt->bindValue(':sender_name',   "Auto transfered to main balance" , PDO::PARAM_STR);    
                            $stmt->execute(); 
                           
                        }   
                
                    }
					
	             //***************************************************************************************************************************
                 /// Security bonding Start.. 
	                    
           }          
                   