<?php
	include_once('../../config.php');    
	 
	                    
	                    
	                     die;
	                 
	                   
                        $stmt=$conn->prepare("select  custId,amount   from UI__DailyROIGeneClone   group by custId  ");   
                        $stmt->execute(); 
                        
                        $UI__DailyROIGeneClone = $stmt->fetchAll(PDO::FETCH_OBJ);    
                        if($stmt->rowCount()>0)
                        {
                         
                            foreach($UI__DailyROIGeneClone as $ampp)
                            {
                                $stmt=$conn->prepare("select  custId,amount   from UI__DailyROIGeneClone where custId=:custId  and paidStatus=0"); 
                                $stmt->bindValue(':custId',  $ampp->custId , PDO::PARAM_STR); 
                                $stmt->execute();  
                                $AllUsers = $stmt->fetchAll(PDO::FETCH_OBJ); 
                                
                                
                                $amt = 0;
                                foreach($AllUsers as $ap)
                                 $amt +=$ap->amount;   
                                 
                                $stmt=$conn->prepare("select *   from  UI__DailyPayTopup  where custId =:custId   and status = 0   ");   
                                $stmt->bindValue(':custId',  $ampp->custId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $UI__DailyPayTopup = $stmt->fetchAll(PDO::FETCH_OBJ);  
                                
                                $Dpwltwallet = 0;
                                foreach($UI__DailyPayTopup as $rmt)
                                     $Dpwltwallet += $rmt->Amt; 
                                     
                                $amt -=  $Dpwltwallet;   
                                
                             
                                
                                $stmt=$conn->prepare("update  UI__DailyROIGeneClone set paidStatus = 1  where custId =:custId       ");   
                                $stmt->bindValue(':custId',  $ampp->custId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                
                                 $stmt=$conn->prepare("update  UI__DailyPayTopup set status = 1  where custId =:custId       ");   
                                $stmt->bindValue(':custId',  $ampp->custId , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                
                                AddFundNew($ampp->custId,$amt,"Daily Payout") ;   
                                
                                $stmt=$conn->prepare("insert into   UI__DailyROIGeneClone  (custId,amount,Tdate,paidStatus,type) values (:custId,:amount,:Tdate,1,1)  "); 
                                $stmt->bindValue(':custId',  $ampp->custId , PDO::PARAM_STR); 
                                $stmt->bindValue(':amount',  $amt , PDO::PARAM_STR); 
                                $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR);   
                                $stmt->execute(); 
                                
                                

                            
                            }    
                            
                        }
                        
                        die;
                        
                        
                       