<?php
	include_once('../config.php');   
     
          
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
     
				
    
    if(isset($_POST['submit'])) 
    {  
			  
            $stmt=$conn->prepare("select * from UI__UTRVefry where UTR=:UTR and Upstats=0");   
			$stmt->bindValue(':UTR', $_POST['AMMT'] , PDO::PARAM_STR);  			
            $stmt->execute();   
		  
			if( ($stmt->rowCount()>0) )   
			{ 
				$Cper = $stmt->fetch(PDO::FETCH_OBJ);       
				$MYUTR = $Cper->UTR;
				$_POST['AMMT'] = $Cper->Amt;
				$TopUp = 2;   
				if($_POST['TopUPlaced']==1)
						$TopUp = 1;
						
				$_POST['fund'] = $_POST['AMMT'];	
				$_POST['userid'] = $_POST['cuurentId'];		
				 
						 		
				if($TopUp==1)        
				{  
				
				$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);     
				  
				$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(($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'];  
					 
					
					$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);   
					
					 
					$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);    
					
					   
					
					$stmt=$conn->prepare("select  id from  UI__DChstr order by id desc  ");    
					$stmt->execute();  
					$UI__DChstrId = $stmt->fetch(PDO::FETCH_OBJ);
					$DSCId = $UI__DChstrId->id;
					   
					 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
										$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->bindValue(':DaysLeft', 29  , 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);
										
										LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
										 
										
                                        $stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
                                    $stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                    $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                    $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance"); 
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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,DaysLeft) values(:Rid,:Brid,:Tdate,:Tamt,:BAmt,:level,:DaysLeft) ");   
									$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->bindValue(':DaysLeft', 29  , 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);
									
									LvBal($ard[$j1],$CoinVal,1,"Level Balance");  
									
									$stmt=$conn->prepare("insert into  UI__LevlCt (tblId,custId,cct,bid) values(:tblId,:custId,:cct,:bid) "); 
                                        $stmt->bindValue(':tblId',$DSCId, PDO::PARAM_STR); 
                                        $stmt->bindValue(':custId',$_POST['cuurentId'], PDO::PARAM_STR); 
                                        $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                        $stmt->bindValue(':bid', $ard[$j1] , 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();  
					
					LvBal($refId->refId,$Data,1,"Spot Balance");   
					
					$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();  
					LvBal($_POST['cuurentId'],$amount,1,"Daily Balanace");   
                
					
					$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();       
					$_SESSION['Regis'] = "Congratulations Top Up Successful!!";
					$_SESSION['topSuc'] =  1; 
					LvBal($_SESSION['userId'],$_POST['AMMT'],2,"UTR Top Up");     

				}
				else
				{
							$_POST['fund'] = $_POST['AMMT'];
							$_POST['userid'] = $_POST['cuurentId'];
							 
							$stmt=$conn->prepare("select  cuurentId from   UI__Rgst   where cuurentId=:cuurentId");  
							$stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
							$stmt->execute();    
							if($stmt->rowCount() > 0)
							{    
									$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,UTR) values(:userid,:Tdate,:amt,:availableFund,:UTR)    "); 
									$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->bindValue(':UTR', $MYUTR, PDO::PARAM_STR);  
									$stmt->execute();   
									LvBal($_POST['userid'],$_POST['fund'],1,"Wallet Balance");
							}

						$_SESSION['Regis'] = "Fund Added Successful!!";
						$_SESSION['topSuc'] =  1;
					  
				} 
					
					$stmt=$conn->prepare("update   UI__UTRVefry  set Upstats=1 where  UTR=:UTR");   
					$stmt->bindValue(':UTR', $MYUTR, PDO::PARAM_STR);  			
					$stmt->execute();      
					header("Location: UTRvarify.php");
					die;
				}else
				{ 
						$_POST['fund'] = $_POST['AMMT'];
						$_POST['userid'] = $_POST['cuurentId'];
						 
						$stmt=$conn->prepare("select  cuurentId from   UI__Rgst   where cuurentId=:cuurentId");  
						$stmt->bindValue(':cuurentId', $_POST['userid'] , PDO::PARAM_STR);
						$stmt->execute();    
						if($stmt->rowCount() > 0)
						{    
								$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,UTR) values(:userid,:Tdate,:amt,:availableFund,:UTR)    "); 
								$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->bindValue(':UTR', $MYUTR, PDO::PARAM_STR);  
								$stmt->execute();   
								LvBal($_POST['userid'],$_POST['fund'],1,"Wallet Balance");
						}       
					
				}  
				$stmt=$conn->prepare("update   UI__UTRVefry  set Upstats=1 where  UTR=:UTR");   
				$stmt->bindValue(':UTR', $MYUTR, PDO::PARAM_STR);  			
				$stmt->execute();   
				
				
				
				$_SESSION['Regis'] = "Fund Added Successful!!";
				$_SESSION['topSuc'] =  1;
				header("Location: UTRvarify.php");
				die;
			}
            else 
			{ 
                 
                 $_SESSION['Regis'] = "Top Up Failed";
                 header("Location: UTRvarify.php");
                 die; 
            }
    }       
    
      

    $PAYWAllet =  GetBalance(); 
    $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);   
  
    
include_once("../view/dashboard/UTRvarify.php");
?>