<?php
	include_once('../config.php');   
    include_once(ABS_PATH.'/custom_function/default.php');  
          
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
     
        
                   
    $stmt=$conn->prepare("select * from  UI__ConirmQr   where custId=:custId  and trasnferStatus=0 and tranfredDate='' ");    
    $stmt->bindValue(':custId',  $_SESSION['userId'], PDO::PARAM_STR);
    $stmt->execute(); 
    $PAYWAllet1 = $stmt->fetchAll(PDO::FETCH_OBJ); 
    
     
    
    $wallet = 0;
    foreach($PAYWAllet1 as $rmt)
        $Awltwallet += $rmt->Amt; 
        
          

    $stmt=$conn->prepare("select * from  UI__CollTopup   where custId=:custId  and Tdate=:Tdate  ");    
    $stmt->bindValue(':custId',  $_SESSION['userId'], PDO::PARAM_STR);
    $stmt->bindValue(':Tdate', date("d-M-Y"), PDO::PARAM_STR);
    $stmt->execute(); 
    $UI__CollTopup = $stmt->fetchAll(PDO::FETCH_OBJ); 
	
	 $cllTp = 0;    
	 if($stmt->rowCount() > 0)
	 {
	    foreach($UI__CollTopup as $mp)
	        $cllTp +=$mp->Amt; 
	 }
	
	
        
    if(isset($_POST['Poolsubmit'])) 
    {
        
        $data['Data'] =  $_POST['AMMT']; 
        $AllUsersT = GetBalance();   
        if( ($AllUsersT>=$data['Data'])  && ($data['Data']==10000)) 
        {  
              
            $stmt=$conn->prepare("select  count  from    UI__PoolPlan  order by id desc ");     
            $stmt->execute();   
            $FRct = $stmt->fetch(PDO::FETCH_OBJ);  
            
            if($FRct->count < 4)
                $MyincstCt = $FRct->count+1;
            else if($FRct->count > 3)
                $MyincstCt   = 1; 
            
             
             
             
             
            $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:cuurentId ");   
            $stmt->bindValue(':cuurentId', $_POST['cuurentId']  , PDO::PARAM_INT);  
            $stmt->execute();    
            $refIdP = $stmt->fetch(PDO::FETCH_OBJ);
            
            $digits = 6;  
            $cuurentId = "AP".rand(pow(10, $digits-1), pow(10, $digits)-1);  
            $stmt=$conn->prepare("insert into  UI__PoolPlan (custId,Tdate,amount,refId,count,idRef) values(:custId,:Tdate,:amount,:refId,:count,:idRef)    "); 
            $stmt->bindValue(':custId', $cuurentId, PDO::PARAM_STR); 
            $stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR);  
            $stmt->bindValue(':amount',$data['Data'], PDO::PARAM_STR);  
            $stmt->bindValue(':refId',$_POST['cuurentId'] , PDO::PARAM_STR);  
            $stmt->bindValue(':count',$MyincstCt , PDO::PARAM_STR);    
            $stmt->bindValue(':idRef',  $refIdP->refId , PDO::PARAM_STR);      
            $stmt->execute();   
            $LastId = $conn->lastInsertId(); 
            
           
           
            if($MyincstCt > 3)
            {
                
                $stmt=$conn->prepare("select  *  from    UI__PoolPlan  where  is_active = 0 order by id ASC ");     
                $stmt->execute();   
                $FRct = $stmt->fetch(PDO::FETCH_OBJ);   
                
                $_POST['userid'] = $FRct->refId;    
                $stmt=$conn->prepare("update   UI__PoolPlan set is_active=1 where id=:id ");      
                $stmt->bindValue(':id', $FRct->id , PDO::PARAM_STR);  
                $stmt->execute();
                
                $stmt=$conn->prepare("update   UI__PoolPlan set forId=:forId  , forCust=:forCust  where id=:id ");     
                $stmt->bindValue(':forId', $FRct->refId , PDO::PARAM_STR);  
                $stmt->bindValue(':forCust',$FRct->custId , PDO::PARAM_STR);  
                $stmt->bindValue(':id', $LastId , PDO::PARAM_STR);  
                $stmt->execute();
				

				$stmt=$conn->prepare("insert into  UI__PoolPlanEntr (custId,DpId,Tdate) values(:custId,:DpId,:Tdate)    "); 
				$stmt->bindValue(':custId', $FRct->custId, PDO::PARAM_STR); 
				$stmt->bindValue(':DpId',$FRct->refId , PDO::PARAM_STR);  
				$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR);   
				$stmt->execute();    
				
                
            
                    $_POST['fund'] = 10000;
                    $stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
                    $stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
                    $stmt->execute(); 
                    if($stmt->rowCount() > 0)
                    {
                       $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
                       $totalAvaib = $AllUsers->availableFund+$_POST['fund'];  
                    }else
                        $totalAvaib =  $_POST['fund'];
                        
                        
                     
        			$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
                    $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(':availableFund', $totalAvaib , 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);   
                    
                       
                    $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,'Pool Plan Credit','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', 1 , PDO::PARAM_STR);   
                    $stmt->execute();     
                    $LastIntId = $conn->lastInsertId();
                    
                    $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();   
                    
                    $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                    $stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
                    $stmt->execute();
                    $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);     	
                    
                    
                    $stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
                    $stmt->bindValue(':type',   20 , PDO::PARAM_STR);   
                    $stmt->bindValue(':bank',  "Pool Plan Credit" , PDO::PARAM_STR);   
                    $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                    $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                    $stmt->bindValue(':amountPaid', $_POST['fund']  , PDO::PARAM_STR); 
                    $stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
                    $stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
                    $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
                    $stmt->bindValue(':custId', $_POST['userid'], PDO::PARAM_STR);  
                    $stmt->bindValue(':cdId', $LastIntId  , PDO::PARAM_STR); 
                    $stmt->bindValue(':Topay',  $_POST['userid'] , PDO::PARAM_STR); 
                    $stmt->bindValue(':TopayName',  $_POST['userid'] , PDO::PARAM_STR);     
                    $stmt->execute();  
                    
                   
            } 
            
            
            
            $stmt=$conn->prepare("select  * 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,poolSpoat) values(:TopUpId,:Amt,:Tdate,:RefTbl,:custId,1)"); 
            $stmt->bindValue(':TopUpId',  $refId->refId  , PDO::PARAM_STR); 
            $stmt->bindValue(':Amt', 500 , 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();   
            
            if($refId->refId!='DP112233')
            LvBal($refId->refId,500,1,"Spot Balance",$_POST['cuurentId']);  
                
                
             ///// credit cleared
                    
                    //debist start..
                    $_SESSION['Regis'] = "Congratulations Top Up Successful!!";
                    $_SESSION['topSuc'] =  1;
                    header("Location: topup-user-id.php"); 
                    die; 
            
        }else
        {           
             $_SESSION['Regis'] = "Top Up Failed";
             header("Location: topup-user-id.php");
             die; 
        }
    }
    
    
    
    
    if(isset($_POST['Poolsubmit100K'])) 
    {
        
        $data['Data'] =  $_POST['AMMT']; 
        $AllUsersT = GetBalance();   
        if( ($AllUsersT>=$data['Data'])  && ($data['Data']==100000)) 
        {  
              
              
            $stmt=$conn->prepare("select  count  from    UI__PoolPlan100k  order by id desc ");     
            $stmt->execute();   
            $FRct = $stmt->fetch(PDO::FETCH_OBJ);  
            
            if($FRct->count < 4)
                $MyincstCt = $FRct->count+1;
            else if($FRct->count > 3)
                $MyincstCt   = 1; 
              
             
             
            $stmt=$conn->prepare("select  refId from  UI__Rgst where  cuurentId=:cuurentId ");   
            $stmt->bindValue(':cuurentId', $_POST['cuurentId']  , PDO::PARAM_INT);  
            $stmt->execute();    
            $refIdP = $stmt->fetch(PDO::FETCH_OBJ);
            
            $digits = 6;  
            $cuurentId = "AP".rand(pow(10, $digits-1), pow(10, $digits)-1);  
            $stmt=$conn->prepare("insert into  UI__PoolPlan100k (custId,Tdate,amount,refId,count,idRef) values(:custId,:Tdate,:amount,:refId,:count,:idRef)    "); 
            $stmt->bindValue(':custId', $cuurentId, PDO::PARAM_STR); 
            $stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR);  
            $stmt->bindValue(':amount',$data['Data'], PDO::PARAM_STR);  
            $stmt->bindValue(':refId',$_POST['cuurentId'] , PDO::PARAM_STR);  
            $stmt->bindValue(':count',$MyincstCt , PDO::PARAM_STR);    
            $stmt->bindValue(':idRef',  $refIdP->refId , PDO::PARAM_STR);      
            $stmt->execute();   
            $LastId = $conn->lastInsertId(); 
            
           
           
            if($MyincstCt > 3)
            {
                
                $stmt=$conn->prepare("select  *  from    UI__PoolPlan100k  where  is_active = 0 order by id ASC ");     
                $stmt->execute();   
                $FRct = $stmt->fetch(PDO::FETCH_OBJ);   
                
                $_POST['userid'] = $FRct->refId;    
                $stmt=$conn->prepare("update   UI__PoolPlan100k set is_active=1 where id=:id ");      
                $stmt->bindValue(':id', $FRct->id , PDO::PARAM_STR);  
                $stmt->execute();
                
                $stmt=$conn->prepare("update   UI__PoolPlan100k set forId=:forId  , forCust=:forCust  where id=:id ");     
                $stmt->bindValue(':forId', $FRct->refId , PDO::PARAM_STR);  
                $stmt->bindValue(':forCust',$FRct->custId , PDO::PARAM_STR);  
                $stmt->bindValue(':id', $LastId , PDO::PARAM_STR);  
                $stmt->execute();
				
				

				$stmt=$conn->prepare("insert into  UI__PoolPlan100kEntr (custId,DpId,Tdate) values(:custId,:DpId,:Tdate)    "); 
				$stmt->bindValue(':custId', $FRct->custId, PDO::PARAM_STR); 
				$stmt->bindValue(':DpId',$FRct->refId , PDO::PARAM_STR);  
				$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR);   
				$stmt->execute();    
				  
                    
            
                    $_POST['fund'] = 100000;
                    $stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
                    $stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
                    $stmt->execute(); 
                    if($stmt->rowCount() > 0)
                    {
                       $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
                       $totalAvaib = $AllUsers->availableFund+$_POST['fund'];  
                    }else
                        $totalAvaib =  $_POST['fund'];
                        
                        
                     
        			$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
                    $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(':availableFund', $totalAvaib , 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);   
                    
                       
                    $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,'Pool Plan Credit','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', 1 , PDO::PARAM_STR);   
                    $stmt->execute();     
                    $LastIntId = $conn->lastInsertId();
                    
                    $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();   
                    
                    $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                    $stmt->bindValue(':cuurentId',  $_POST['userid'] , PDO::PARAM_STR);  
                    $stmt->execute();
                    $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);     	
                    
                    
                    $stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
                    $stmt->bindValue(':type',   20 , PDO::PARAM_STR);   
                    $stmt->bindValue(':bank',  "Pool Plan Credit" , PDO::PARAM_STR);   
                    $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                    $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                    $stmt->bindValue(':amountPaid', $_POST['fund']  , PDO::PARAM_STR); 
                    $stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
                    $stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
                    $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
                    $stmt->bindValue(':custId', $_POST['userid'], PDO::PARAM_STR);  
                    $stmt->bindValue(':cdId', $LastIntId  , PDO::PARAM_STR); 
                    $stmt->bindValue(':Topay',  $_POST['userid'] , PDO::PARAM_STR); 
                    $stmt->bindValue(':TopayName',  $_POST['userid'] , PDO::PARAM_STR);     
                    $stmt->execute();  
                    
                   
            } 
            
            
            
            $stmt=$conn->prepare("select  * 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,poolSpoat) values(:TopUpId,:Amt,:Tdate,:RefTbl,:custId,1)"); 
            $stmt->bindValue(':TopUpId',  $refId->refId  , PDO::PARAM_STR); 
            $stmt->bindValue(':Amt', 5000 , 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();   
            
            if($refId->refId!='DP112233')
            LvBal($refId->refId,5000,1,"Spot Balance",$_POST['cuurentId']);  
                
                
             ///// credit cleared
                    
                    //debist start..
                    $_SESSION['Regis'] = "Congratulations Top Up Successful!!";
                    $_SESSION['topSuc'] =  1;
                    header("Location: topup-user-id.php"); 
                    die; 
            
        }else
        {           
             $_SESSION['Regis'] = "Top Up Failed";
             header("Location: topup-user-id.php");
             die; 
        }
    }
    
    if(isset($_POST['submit'])) 
    {   
        
        $stmt=$conn->prepare("select  othertopup from  UI__Rgst where  cuurentId=:cuurentId ");   
        $stmt->bindValue(':cuurentId', $_SESSION['userId']  , PDO::PARAM_INT);  
        $stmt->execute();    
        $othertopup = $stmt->fetch(PDO::FETCH_OBJ);
        
            if( ($othertopup->othertopup==1)   )
            {
             
              if($_POST['cuurentId']==$_SESSION['userId'])
              {            
                    if($_POST['availableBal']==1)
                        include("maintopup.php");
                    else
                        include("collectiontp.php");    
              }
             
            }else {
    
            if($_POST['availableBal']==1)
                include("maintopup.php");
            else
                include("collectiontp.php");    
            }
        
    }       
    
          
    $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); 
    
    $PAYWAllet =  GetBalance();   

include_once("../view/dashboard/topup-user-id.php");
?>