<?php 	include_once('../../config.php');   	
		include_once(ABS_PATH.'/admin/login_check.php');    
 
			//if(isset($_POST['submitF']))
			
			             
			                
			                
                                            $RE = mysql_query("SELECT count(*), custId FROM UI__DailyROIGene where `Tdate` LIKE '%05-Apr-2025%' GROUP BY custId HAVING COUNT(*) > 1"); 
                                            while($row = mysql_fetch_object($RE))
                                            {
                                                   echo '<pre>'; print_r($row);
                                                   die;
                                            }  
			                     
			                     die;
			                    
			    $_POST['userid'] = trim($_POST['userid'],"");          
                $stmt=$conn->prepare("insert into UI__WithDraw(userid,Tdate,amt,orgAmt,accept) values(:userid,:Tdate,:amt,:orgAmt,1)"); 
                $stmt->bindValue(':userid',   $_POST['userid']  , PDO::PARAM_STR);   
                $stmt->bindValue(':Tdate',  date("d-M-Y H:i") , PDO::PARAM_STR);   
                $stmt->bindValue(':amt', $_POST['fund'] , PDO::PARAM_STR);
                $stmt->bindValue(':orgAmt', "Debit by admin" , PDO::PARAM_STR);  
                $stmt->execute();       
                
                
                  $stmt=$conn->prepare("select *  from UI__DailyROIGene    where custId=:sId     ");   
                    $stmt->bindValue(':sId',  $_POST['userid'] , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $Tamnt = 0;
                    foreach($XUI__DailyROIGene as $xx)
                    {
                    $Tamnt +=$xx->amount;
                    }      
                    
                    
                    $stmt=$conn->prepare("select *  from UI__Bns    where Rid =:sId   ");   
                    $stmt->bindValue(':sId',  $_POST['userid'] , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    
                    $LevelI = 0;
                    foreach($UI__Bns as $dddm)
                    {
                    $LevelI +=$dddm->Tamt;
                    }
                    
                    
                    $stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
                    $stmt->bindValue(':refId',  $_POST['userid'] , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $directIncome = 0;
                    foreach($MdirectB as $dmm)
                    $directIncome += $dmm->Amt;                
                    
                    
                    
                    
                    $stmt=$conn->prepare("select *  from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
                    $stmt->bindValue(':sId', $_POST['userid'] , 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',  $_POST['userid'] , 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', $_POST['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);     
                    
                    $stmt=$conn->prepare("insert into  UI__DebitCredit (custId,addDel,availableBal,Tdate,type,Intype,byw) values(:custId,:addDel,:availableBal,:Tdate,:type,:Intype,'NA')    "); 
                    $stmt->bindValue(':custId',$_POST['userid'], PDO::PARAM_STR); 
                    $stmt->bindValue(':addDel',$_POST['fund'], PDO::PARAM_STR); 
                    $stmt->bindValue(':availableBal',$PAYWAllet, PDO::PARAM_STR);  
                    $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);  
                    $stmt->bindValue(':type', 2 , PDO::PARAM_STR);  
                    $stmt->bindValue(':Intype', "Fund Debited By Admin" , PDO::PARAM_STR);  
                    $stmt->execute();   
                    
                    $stmt=$conn->prepare("select id from UI__Rgst  where  cuurentId=:cuurentId    ");   
                    $stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
                    $stmt->execute(); 
                    $UIid = $stmt->fetch(PDO::FETCH_OBJ);   
                    
                    $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', date("d-M-Y H:i"), PDO::PARAM_STR); 
                    $stmt->bindValue(':Uxd', $UIid->id, PDO::PARAM_STR);  
                    $stmt->execute();  

                    
 
		
 