<?php
	include_once('../config.php');   
     
          
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
    
    if(isset($_POST['submit'])) 
    {  
       
            $stmt=$conn->prepare("select * from UI__Crper");    
            $stmt->execute(); 
            $Cper = $stmt->fetch(PDO::FETCH_OBJ);      
            
                    
            $stmt=$conn->prepare("select  custId   from UI__Rgst where cuurentId =:cuurentId ");   
            $stmt->bindValue(':cuurentId', $_POST['cuurentId'] , PDO::PARAM_INT);  
            $stmt->execute(); 
            $FResult = $stmt->fetch(PDO::FETCH_OBJ);  
            
            $stmt=$conn->prepare("select id from  UI__DChstr where typ=1 and sId=:sId ");    
            $stmt->bindValue(':sId', $FResult->custId , PDO::PARAM_STR);  
            $stmt->execute(); 
            $affected_rows_UI__DChstr = $stmt->rowCount();	    
         
            $MPin  = ($_POST['TopPin']);//+3400; 
            $stmt = $conn->prepare("SELECT AMMT,id FROM UI__PnMX WHERE MPin=:MPin and exp!=1");  
            $stmt->execute(array(':MPin'=>$MPin));
            $affected_rows = $stmt->rowCount();	 
            
              
            $data['Data'] =  $_POST['AMMT'];  
            $stmt=$conn->prepare("select  availableFund  from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
            $stmt->bindValue(':cuurentId', $_SESSION['userId']  , PDO::PARAM_STR);
            $stmt->execute();  
            $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
            $availableFund = 0;
             
            if($AllUsers->availableFund>=$data['Data']) 
            {
                $availableFund = 1;    
                $totalAvaib = $AllUsers->availableFund;
            }    
                 
           
            if( ($availableFund > 0)  && ($data['Data']>=100))
            {    
                $Result = $stmt->fetch(PDO::FETCH_OBJ);    
                $stmt=$conn->prepare("update  UI__PnMX set exp=1 where id=:id ");    
                $stmt->bindValue(':id', $Result->id , PDO::PARAM_STR);  
               // $stmt->execute(); 
                     
                $PlanAMt = $data['Data'] ;    
                $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)
                {     
                    $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;
                        }
                    }  
                }   
                   
                function Refcall($ref)
                {
                    global $conn;
                    $stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId =:cuurentId ");   
                    $stmt->bindValue(':cuurentId', $ref , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $Result = $stmt->fetchAll(PDO::FETCH_OBJ);   
                    return $Result;
                }          
				 
                $totalAvaib -= $data['Data'];  
                $stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund,topUpId) values(:userid,:Tdate,:amt,:availableFund,:topUpId)    "); 
                $stmt->bindValue(':userid', $_SESSION['userId'] , PDO::PARAM_STR); 
                $stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
                $stmt->bindValue(':amt',$data['Data'], PDO::PARAM_STR);  
                $stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
                $stmt->bindValue(':topUpId', $_POST['cuurentId'] , PDO::PARAM_STR);    
                $stmt->execute();  
                
                $CoinVal = ($data['Data']);    
                $stmt=$conn->prepare("insert into  UI__DChstr (typ,amt,Tdate,Rid,sId,percet,coin,byId) values(:typ,:amt,:Tdate,:Rid,:sId,:percet,:coin,:byId) ");   
                $stmt->bindValue(':typ', 1, PDO::PARAM_INT); 
                $stmt->bindValue(':amt', $data['Data'], PDO::PARAM_INT); 
                $stmt->bindValue(':Tdate', date("d-M-Y H:i:s") , PDO::PARAM_STR); 
                $stmt->bindValue(':Rid', $_POST['cuurentId']  , PDO::PARAM_STR);
                $stmt->bindValue(':sId', $MyCust  , PDO::PARAM_STR);
                $stmt->bindValue(':percet', 0  , PDO::PARAM_STR);  
                $stmt->bindValue(':coin', 0  , PDO::PARAM_STR);   
                $stmt->bindValue(':byId', $_SESSION['userId']  , PDO::PARAM_STR);     
                $stmt->execute();   
                     
				 
				$stmt=$conn->prepare("select refId,custId   from UI__Rgst where cuurentId =:cuurentId ");   
                $stmt->bindValue(':cuurentId', $_POST['cuurentId'] , PDO::PARAM_INT);  
                $stmt->execute(); 
				$Dref = $stmt->fetch(PDO::FETCH_OBJ);   
				
                if($affected_rows_UI__DChstr < 1)
                {
				$stmt=$conn->prepare("insert into  UI__DChstr (typ,amt,Tdate,Rid,sId,level) values(:typ,:amt,:Tdate,:Rid,:sId,1) ");   
				$stmt->bindValue(':typ', 7, PDO::PARAM_STR); 
				$stmt->bindValue(':amt', (($data['Data']*5)/100) , PDO::PARAM_INT); 
				$stmt->bindValue(':Tdate', date("d-M-Y H:i:s") , PDO::PARAM_STR); 
				$stmt->bindValue(':Rid', $_POST['cuurentId'] , PDO::PARAM_STR);   
				$stmt->bindValue(':sId', $Dref->refId, PDO::PARAM_STR);    
				$stmt->execute(); 
                }
				
				$stmt=$conn->prepare("select  custId from UI__Rgst where cuurentId =:cuurentId ");   
                $stmt->bindValue(':cuurentId', $Dref->refId , PDO::PARAM_INT);  
                $stmt->execute(); 
				$MdRef = $stmt->fetch(PDO::FETCH_OBJ);    
				 
				
				 if(end($ard)==0)
                 {  
                    for($j1=0;$j1<(count($ard)-1);$j1++)
                    {
                        if($j1==0)
                        {       
                                $CoinVal = ($data['Data']*0.1)/100;    
                                $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                                $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                if($stmt->rowCount() > 0) 
                                {    
                                    $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                    
                                    $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                    $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                    $stmt->execute();  
                                    $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                    
                                    $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                    $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                    $stmt->execute();  
                                    
                                    
                                }
                        }
                        else if($j1==1)
                        { 
                            $CoinVal = ($data['Data']*0.05)/100;    
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					    }else if($j1==2)
                        { 
                            $CoinVal = ($data['Data']*(0.03))/100;   
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					    }else if($j1==3)
                        { 
                            $CoinVal = ($data['Data']*(0.02))/100;       
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1  and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					    }else if($j1==4)
                        { 
                            $CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            } 
 					      }else if($j1==5)
                        { 
                            $CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					      }else if($j1==6)
                        { 
                            $CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					      }else if($j1==7)
                        { 
                            $CoinVal = ($data['Data']*(0.01))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					      }else if($j1==8)
                        { 
                            $CoinVal = ($data['Data']*(0.005))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					      }else if($j1==9)
                        { 
                            $CoinVal = ($data['Data']*(0.005))/100;     
                            $stmt=$conn->prepare("select id from UI__DChstr where Rid=:Rid and typ=1 and status=0 ");   
                            $stmt->bindValue(':Rid', $ard[$j1] , PDO::PARAM_STR);   
                            $stmt->execute();  
                            if($stmt->rowCount() > 0) 
                            {
                                $stmt=$conn->prepare("insert into  UI__Bns (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();   
                                
                                $stmt=$conn->prepare("select  * from  UI__Rgst where cuurentId=:cuurentId  ");   
                                $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_STR);   
                                $stmt->execute();  
                                $custId = $stmt->fetch(PDO::FETCH_OBJ);
                                
                                $stmt=$conn->prepare("update  UI__Mnt set Mnnnt = Mnnnt + $CoinVal  where sId=:sId");    
                                $stmt->bindValue(':sId', $custId->custId, PDO::PARAM_STR);  
                                $stmt->execute();     
                            }
                             
 					      }
 					    
                       }
                 }	  
                
                $Data = (($data['Data']*5)/100);  
                $stmt=$conn->prepare("select  refId from UI__Rgst where cuurentId=:cuurentId  "); 
                $stmt->bindValue(':cuurentId', $_POST['cuurentId']   , PDO::PARAM_STR);  
                $stmt->execute();  
                $refId = $stmt->fetch(PDO::FETCH_OBJ);
                
                 
                $stmt=$conn->prepare("insert into  UI__Tpm (TopUpId,Amt,Tdate,RefTbl,custId) values(:TopUpId,:Amt,:Tdate,:RefTbl,:custId)"); 
                $stmt->bindValue(':TopUpId', $refId->refId , PDO::PARAM_STR); 
                $stmt->bindValue(':Amt', $Data , PDO::PARAM_STR); 
                $stmt->bindValue(':Tdate', date("d-M-Y") , PDO::PARAM_STR);  
                $stmt->bindValue(':RefTbl', $_POST['cuurentId'] , PDO::PARAM_STR);  
                $stmt->bindValue(':custId', $_POST['cuurentId'] , PDO::PARAM_STR);    
                $stmt->execute();  
                
                
                $Tdt = date("d-M-Y", strtotime($dmt->Tdate));   
                $amount = number_format((float)(($data['Data']*2)/400), 2, '.', '');
                $stmt=$conn->prepare("insert into UI__DailyROIGene(custId,amount,Tdate,TopUpdate) values(:custId,:amount,:Tdate,:TopUpdate)"); 
                $stmt->bindValue(':custId',  $_POST['cuurentId'] , PDO::PARAM_INT);   
                $stmt->bindValue(':amount', $amount , PDO::PARAM_INT);    
                $stmt->bindValue(':Tdate',  date("d-M-Y") , PDO::PARAM_STR);   
                $stmt->bindValue(':TopUpdate',  date("d-M-Y") , PDO::PARAM_STR);      
                $stmt->execute();  
                
                $stmt=$conn->prepare("insert into UI__TopWithDrw(custId,Tdate,status,type,amt) values(:custId,:Tdate,:status,:type,:amt)"); 
                $stmt->bindValue(':custId',  $_POST['cuurentId'] , PDO::PARAM_STR);   
                $stmt->bindValue(':Tdate',  date("d-M-Y") , PDO::PARAM_STR);   
                $stmt->bindValue(':status', 0 , PDO::PARAM_INT);     
                $stmt->bindValue(':type',  1 , PDO::PARAM_INT);
                $stmt->bindValue(':amt', $data['Data'] , PDO::PARAM_STR);
                $stmt->execute();      
                
                
                
                
					///
					
								
					$stmt=$conn->prepare("select *  from UI__DailyROIGene    where custId=:sId     ");   
					$stmt->bindValue(':sId',  $_SESSION['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',  $_SESSION['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',  $_SESSION['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',  $_SESSION['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',  $_SESSION['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',  $_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);        
				
				
					///
                    $stmt=$conn->prepare("insert into  UI__DebitCredit (custId,addDel,availableBal,Tdate,type,Intype) values(:custId,:addDel,:availableBal,:Tdate,:type,'Top Up')    "); 
                    $stmt->bindValue(':custId',$_SESSION['userId'], PDO::PARAM_STR); 
                    $stmt->bindValue(':addDel',$_POST['AMMT'], 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', 1 , PDO::PARAM_STR);  
                    $stmt->execute();
                    
                $_SESSION['Regis'] = "Congratulations Top Up Successful!!";
                $_SESSION['topSuc'] =  1;
                header("Location: topup-user-id.php"); 
            }
            else 
			{ 
                 
                 $_SESSION['Regis'] = "Top Up Failed";
                 header("Location: topup-user-id.php");
                 die; 
            }
    }       
    
          
            $stmt=$conn->prepare("select * from  UI__PnMX   where Transfered=:custId ");    
            $stmt->bindValue(':custId',  $_SESSION['userCustId'], PDO::PARAM_STR);
            $stmt->execute(); 
            $AllIds = $stmt->fetchAll(PDO::FETCH_OBJ); 
            
            
    $stmt=$conn->prepare("select *  from UI__Fundtransfer    where userid =:sId  order by id desc  ");   
    $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_INT);  
    $stmt->execute(); 
    $UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ);
    
        
    $stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
    $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_INT);  
    $stmt->execute(); 
    $UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ); 
    
    
     $stmt=$conn->prepare("select *  from UI__DailyROIGene    where custId=:sId     ");   
        $stmt->bindValue(':sId',  $_SESSION['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',  $_SESSION['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',  $_SESSION['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',  $_SESSION['userId'] , PDO::PARAM_INT);  
        $stmt->execute(); 
        $UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
        
        
        $totalWithdrwa = 0;
        foreach($UI__WithDraw as $tl)
        {
            $totalWithdrwa +=$tl->amt;
        }
        
        $PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);           
        
    
include_once("../view/dashboard/topup-user-id.php");
?>