<?php 	
    include_once('../../config.php');   
     
	 if(isset($_POST['UpdateWvallAmt']))
	 { 
	        $aPw =  explode(",",$_POST['mobileno']); 
            foreach($aPw as $mpp) 
            {  
                 
                    $stmt =  $conn->prepare("select * from UI__Rgst where id=:cuurentId  ");   
                    $stmt->bindValue(':cuurentId', $mpp, PDO::PARAM_STR);   
                    $stmt->execute(); 
                    if($stmt->rowCount() > 0)
                    {
                        $users_rec = $stmt->fetch(PDO::FETCH_OBJ);     
                        $PAYWAllet =  GetBalance($users_rec->cuurentId); 
                        $nw_date = date("d-M-Y H:i");    
                        $amount = password_hash(($PAYWAllet),PASSWORD_DEFAULT);     
                        $stmt =  $conn->prepare("update _pkCc__ set bl1=:bl1,tm=:tm where Uxd=:Uxd "); 
                        $stmt->bindValue(':bl1', $amount, PDO::PARAM_STR); 
                        $stmt->bindValue(':tm', $nw_date, PDO::PARAM_STR); 
                        $stmt->bindValue(':Uxd', $users_rec->id , PDO::PARAM_STR);  
                        $stmt->execute();  
                    } 
            }
            die;
	 }
	 
	 if(isset($_POST['UpdateWvallAmtCt']))
	 { 
	         
            $stmt =  $conn->prepare("select * from UI__Rgst where cuurentId=:cuurentId  ");   
            $stmt->bindValue(':cuurentId', $_POST['mobileno'], PDO::PARAM_STR);   
            $stmt->execute(); 
            if($stmt->rowCount() > 0)
            {
                $users_rec = $stmt->fetch(PDO::FETCH_OBJ);     
                $PAYWAllet =  GetBalance($users_rec->cuurentId); 
                $nw_date = date("d-M-Y H:i");    
                $amount = password_hash(($PAYWAllet),PASSWORD_DEFAULT);     
                $stmt =  $conn->prepare("update _pkCc__ set bl1=:bl1,tm=:tm where Uxd=:Uxd "); 
                $stmt->bindValue(':bl1', $amount, PDO::PARAM_STR); 
                $stmt->bindValue(':tm', $nw_date, PDO::PARAM_STR); 
                $stmt->bindValue(':Uxd', $users_rec->id , PDO::PARAM_STR);  
                $stmt->execute(); 
                die;
            }  
	 }
	 
	 if(isset($_POST['checkWavlAcmt']))
	{
        	    
                $stmt =  $conn->prepare("select * from UI__Rgst where cuurentId=:cuurentId  ");   
                $stmt->bindValue(':cuurentId', $_POST['mobileno'], PDO::PARAM_STR);   
                $stmt->execute(); 
                $affected_rows = $stmt->rowCount();
                 
                
                if($affected_rows > 0)
                { 
                    $users_rec = $stmt->fetch(PDO::FETCH_OBJ);     
                    $PAYWAllet =  GetBalance($_POST['mobileno']); 
                    $ary['name']   = $users_rec->nm;
                    $ary['amount']   = $PAYWAllet;
                    echo json_encode($ary); 
                    die;
                } 
	}
	
	 
	
	
	if(isset($_POST['checkWavlAcmtTransfer']))
	{
        	    
                $stmt =  $conn->prepare("select * from UI__Rgst where cuurentId=:cuurentId  ");   
                $stmt->bindValue(':cuurentId', $_POST['mobileno'], PDO::PARAM_STR);   
                $stmt->execute(); 
                $affected_rows = $stmt->rowCount();
                 
                
                if($affected_rows > 0)
                { 
                    $users_rec = $stmt->fetch(PDO::FETCH_OBJ);  
                    
                    
                    $stmt=$conn->prepare("select  custId,amount   from UI__DailyROIGeneClone where custId=:custId  and paidStatus=0"); 
                    $stmt->bindValue(':custId',  $users_rec->cuurentId , 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',  $users_rec->cuurentId , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__DailyPayTopup = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $Dpwltwallet = 0;
                    foreach($UI__DailyPayTopup as $rmt)
                    $Dpwltwallet += $rmt->Amt; 
                    
                    $amt -=  $Dpwltwallet;   
                    
                    if($amt > 0) {
                    
                    $stmt=$conn->prepare("update  UI__DailyROIGeneClone set paidStatus = 1  where custId =:custId       ");   
                    $stmt->bindValue(':custId',   $users_rec->cuurentId , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    
                    $stmt=$conn->prepare("update  UI__DailyPayTopup set status = 1  where custId =:custId       ");   
                    $stmt->bindValue(':custId',  $users_rec->cuurentId , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    
                    AddFundNew( $users_rec->cuurentId,$amt,"Daily Payout") ;   
                    
                    $stmt=$conn->prepare("insert into   UI__DailyROIGeneClone  (custId,amount,Tdate,paidStatus,type) values (:custId,:amount,:Tdate,1,1)  "); 
                    $stmt->bindValue(':custId',   $users_rec->cuurentId , PDO::PARAM_STR); 
                    $stmt->bindValue(':amount',  $amt , PDO::PARAM_STR); 
                    $stmt->bindValue(':Tdate',  date("d-M-Y"), PDO::PARAM_STR);   
                    $stmt->execute(); 
                    }
 
                    $ary['name']   = $users_rec->nm;
                    $ary['amount']   = $amt;
                    echo json_encode($ary); 
                    die;
                } 
	}
	
	if(isset($_POST['checkWavlAcmtDashb']))
	{
        	    
                $stmt =  $conn->prepare("select * from UI__Rgst where cuurentId=:cuurentId  ");   
                $stmt->bindValue(':cuurentId', $_POST['mobileno'], PDO::PARAM_STR);   
                $stmt->execute(); 
                $affected_rows = $stmt->rowCount();
                 
                
                if($affected_rows > 0)
                { 
                    $users_rec = $stmt->fetch(PDO::FETCH_OBJ);     
                    
                    /*$stmt =  $conn->prepare("select  amount  from UI__DailyROIGeneClone  where custId=:custId and paidStatus=0  ");   
                    $stmt->bindValue(':custId', $users_rec->cuurentId, PDO::PARAM_STR);   
                    $stmt->execute();   
                    $UI__DailyROIGeneClone = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    
                    $amt = 0;
                    foreach($UI__DailyROIGeneClone as $Pu)
                            $amt +=  $Pu->amount;
                    */
                    
                    $stmt=$conn->prepare("select  custId,amount   from UI__DailyROIGeneClone where custId=:custId  and paidStatus=0"); 
                    $stmt->bindValue(':custId',  $users_rec->cuurentId , 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',  $users_rec->cuurentId , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__DailyPayTopup = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $Dpwltwallet = 0;
                    foreach($UI__DailyPayTopup as $rmt)
                    $Dpwltwallet += $rmt->Amt; 
                    
                    $amt -=  $Dpwltwallet;   
                    

                    $ary['name']   = $users_rec->nm;
                    $ary['amount']   = $amt;
                    echo json_encode($ary); 
                    die;
                } 
	}
	
	/*
	    
            $stmt =  $conn->prepare("select * from UI__Rgst  ");   
            //$stmt->bindValue(':cuurentId', $_POST['mobileno'], PDO::PARAM_STR);  
            //$stmt->bindValue(':user_type', $_POST['user_type'], PDO::PARAM_STR);  
            $stmt->execute();   
            $affected_rows = $stmt->rowCount();
            
            $users_rec = $stmt->fetchAll(PDO::FETCH_OBJ);    
            foreach($users_rec as $anpp) 
            { 
            
            
            $stmt=$conn->prepare("select  id,amt from   UI__DChstr where Rid=:sId  and typ=1");  
            $stmt->bindValue(':sId', $anpp->cuurentId , PDO::PARAM_STR);
            $stmt->execute();  
            $count = $stmt->rowCount();    
            
            if($count > 0) 
            {
            $PAYWAllet =  GetBaLN($anpp->cuurentId);  
            $nw_date = date("d-M-Y H:i");    
            $amount = password_hash(($PAYWAllet),PASSWORD_DEFAULT);     
            $stmt =  $conn->prepare("update _pkCc__ set bl1=:bl1,tm=:tm where Uxd=:Uxd "); 
            $stmt->bindValue(':bl1', $amount, PDO::PARAM_STR); 
            $stmt->bindValue(':tm', $nw_date, PDO::PARAM_STR); 
            $stmt->bindValue(':Uxd', $anpp->id, PDO::PARAM_STR);  
            $stmt->execute(); 
            
            }
            }
            die;
	
	*/ 
?>