<?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();	  
            
            
            /*            
              if($_POST['AMMT']==1) 
                    $data['Data'] = 10000;
                else if($_POST['AMMT']==2) 
                    $data['Data'] =  20000;
                else if($_POST['AMMT']==3) 
                    $data['Data'] = 30000;
                else if($_POST['AMMT']==4) 
                    $data['Data'] = 40000;
                else if($_POST['AMMT']==5) 
                    $data['Data'] = 50000;
                else if($_POST['AMMT']==6) 
                    $data['Data'] = 60000;    
                else if($_POST['AMMT']==7) 
                    $data['Data'] = 70000;    
                else if($_POST['AMMT']==8) 
                    $data['Data'] = 80000;    
                else if($_POST['AMMT']==9) 
                    $data['Data'] = 90000;    
                else if($_POST['AMMT']==10) 
                    $data['Data'] = 100000;
                else if($_POST['AMMT']==11) 
                    $data['Data'] = 200000;
                else if($_POST['AMMT']==12) 
                    $data['Data'] = 300000;
                else if($_POST['AMMT']==13) 
                    $data['Data'] = 400000;
                else if($_POST['AMMT']==14) 
                    $data['Data'] = 500000;
                else if($_POST['AMMT']==15) 
                    $data['Data'] = 600000;
                else if($_POST['AMMT']==16) 
                    $data['Data'] = 700000;
                else if($_POST['AMMT']==17) 
                    $data['Data'] = 800000;
                else if($_POST['AMMT']==18) 
                    $data['Data'] = 900000;
                else if($_POST['AMMT']==19) 
                    $data['Data'] = 1000000;    
                 
                */ 
              
              $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']>=10000))
            {    
                $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,typ) values(:userid,:Tdate,:amt,:availableFund,:topUpId,1)    "); 
                $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']);  
                $Perset = ($data['Data'])/$Cper->per;      
                
                
                $RoiAmt = ($data['Data']*7.4)/100; 
                $stmt=$conn->prepare("insert into  UI__Droi (Cid,Tamt,Perset,UpdatedOn,RoiAmt,Dys) values(:Cid,:Tamt,:Perset,:UpdatedOn,:RoiAmt,:Dys) ");   
                $stmt->bindValue(':Cid', $MyCust, PDO::PARAM_INT); 
                $stmt->bindValue(':Tamt', $data['Data'], PDO::PARAM_INT); 
                $stmt->bindValue(':Perset',  0, PDO::PARAM_STR);  
                $stmt->bindValue(':UpdatedOn', date("d-M-Y H:i")  , PDO::PARAM_STR); 
                $stmt->bindValue(':RoiAmt', $RoiAmt  , PDO::PARAM_STR);   
                $stmt->bindValue(':Dys', 0  , PDO::PARAM_STR);     
                $stmt->execute(); 
               
                    
                $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)
                        {      
                             
                            $stmt=$conn->prepare("select id,amt  from UI__DChstr where Rid=:Rid and typ=1 ");   
                            $stmt->bindValue(':Rid', $_POST['cuurentId'] , PDO::PARAM_STR);   
                            $stmt->execute();     
                            $custIdResult = $stmt->fetch(PDO::FETCH_OBJ);    
                            $CoinVal = ($custIdResult->amt*8)/100;  
                            
                            $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', $custIdResult->amt  , 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)
                        { 
                            $stmt=$conn->prepare("select custId   from UI__Rgst where cuurentId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId',  $ard[$j1]  , PDO::PARAM_INT);  
                            $stmt->execute(); 
                            $Result1 = $stmt->fetch(PDO::FETCH_OBJ);  
                               
                            $stmt=$conn->prepare("select cuurentId from UI__Rgst where custId =:custId ");   
                            $stmt->bindValue(':custId', $Result1->custId   , PDO::PARAM_STR);  
                            $stmt->execute(); 
                            $Result = $stmt->fetch(PDO::FETCH_OBJ);
                            
                              
                            $myRefId = $Result->cuurentId;   
                            $stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId', $Result->cuurentId  , PDO::PARAM_INT);  
                            $stmt->execute();
                            
                            $myTT = 0;
                            if($stmt->rowCount()>0)
                            { 
                                $Result = $stmt->fetchAll(PDO::FETCH_OBJ);     
                                foreach($Result as $dtm) 
                                    $stepCt['step1']['id'][] = $dtm->cuurentId;
                                    
                                    
                                $myTT +=count($stepCt['step1']['id']);       
                                foreach($Result as $dtm) 
                                    $stepCt['step2']['id'][] =  Refcall($dtm->cuurentId); 
                                
                            } 
                            
                            $NBusinessAmt = 0; 
                            foreach($stepCt['step2']['id'] as $dtm) 
                            {         
                                foreach($dtm as $dtmx) 
                                {    
                                    $stmt=$conn->prepare("select *  from UI__DChstr where Rid=:Rid and typ=1");   
                                    $stmt->bindValue(':Rid', $dtmx->cuurentId , PDO::PARAM_STR);  
                                    $stmt->execute(); 
                                    $Resultx = $stmt->fetch(PDO::FETCH_OBJ);  
                                    $NBusinessAmt +=$Resultx->amt; 
                                } 
                            }
                            
                                if($NBusinessAmt>=100000) 
                                {
                                    $CoinVal = ($data['Data']*4)/100;   
                                    $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)
                        { 
                            $stmt=$conn->prepare("select custId   from UI__Rgst where cuurentId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId',  $ard[$j1]  , PDO::PARAM_INT);  
                            $stmt->execute(); 
                            $Result1 = $stmt->fetch(PDO::FETCH_OBJ);  
                               
                            $stmt=$conn->prepare("select cuurentId from UI__Rgst where custId =:custId ");   
                            $stmt->bindValue(':custId', $Result1->custId   , PDO::PARAM_STR);  
                            $stmt->execute(); 
                            $Result = $stmt->fetch(PDO::FETCH_OBJ);
                            
                              
                            $myRefId = $Result->cuurentId;   
                            $stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId', $Result->cuurentId  , PDO::PARAM_INT);  
                            $stmt->execute();
                            
                            $myTT = 0;
                            if($stmt->rowCount()>0)
                            { 
                                $Result = $stmt->fetchAll(PDO::FETCH_OBJ);     
                                foreach($Result as $dtm) 
                                    $stepCt['step1']['id'][] = $dtm->cuurentId;
                                    
                                    
                                $myTT +=count($stepCt['step1']['id']);       
                                foreach($Result as $dtm) 
                                    $stepCt['step2']['id'][] =  Refcall($dtm->cuurentId); 
                                
                            }   
							  
							for($i=0;$i<count($stepCt['step2']['id']);$i++)
							{
								 
								if(count($stepCt['step2']['id'][$i])>0)
								{
									   $myTT +=count($stepCt['step2']['id'][$i]);     
									   
								   foreach($stepCt['step2']['id'][$i] as $dtm)
									 $stepCt['step3']['id'][] =  Refcall($dtm->cuurentId);  
								}
								
							} 
							 
                            
                            $NBusinessAmt = 0; 
                            foreach($stepCt['step3']['id'] as $dtm) 
                            {         
                                foreach($dtm as $dtmx) 
                                {    
                                    $stmt=$conn->prepare("select *  from UI__DChstr where Rid=:Rid and typ=1");   
                                    $stmt->bindValue(':Rid', $dtmx->cuurentId , PDO::PARAM_STR);  
                                    $stmt->execute(); 
                                    $Resultx = $stmt->fetch(PDO::FETCH_OBJ);  
                                    $NBusinessAmt +=$Resultx->amt; 
                                } 
                            }
                            
                                if($NBusinessAmt>=100000) 
                                {
                                    $CoinVal = ($data['Data']*3)/100;   
                                    $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)
                       { 
                            $stmt=$conn->prepare("select custId   from UI__Rgst where cuurentId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId',  $ard[$j1]  , PDO::PARAM_INT);  
                            $stmt->execute(); 
                            $Result1 = $stmt->fetch(PDO::FETCH_OBJ);  
                               
                            $stmt=$conn->prepare("select cuurentId from UI__Rgst where custId =:custId ");   
                            $stmt->bindValue(':custId', $Result1->custId   , PDO::PARAM_STR);  
                            $stmt->execute(); 
                            $Result = $stmt->fetch(PDO::FETCH_OBJ);
                            
                              
                            $myRefId = $Result->cuurentId;   
                            $stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId', $Result->cuurentId  , PDO::PARAM_INT);  
                            $stmt->execute();
                            
                            $myTT = 0;
                            if($stmt->rowCount()>0)
                            { 
                                $Result = $stmt->fetchAll(PDO::FETCH_OBJ);     
                                foreach($Result as $dtm) 
                                    $stepCt['step1']['id'][] = $dtm->cuurentId;
                                    
                                    
                                $myTT +=count($stepCt['step1']['id']);       
                                foreach($Result as $dtm) 
                                    $stepCt['step2']['id'][] =  Refcall($dtm->cuurentId); 
                                
                            }   
							  
							for($i=0;$i<count($stepCt['step2']['id']);$i++)
							{
								 
								if(count($stepCt['step2']['id'][$i])>0)
								{
									   $myTT +=count($stepCt['step2']['id'][$i]);     
									   
								   foreach($stepCt['step2']['id'][$i] as $dtm)
									 $stepCt['step3']['id'][] =  Refcall($dtm->cuurentId);  
								}
								
							} 
							
							for($i=0;$i<count($stepCt['step3']['id']);$i++)
							{

							if(count($stepCt['step3']['id'][$i])>0)
							{
							$myTT +=count($stepCt['step3']['id'][$i]);     

							foreach($stepCt['step3']['id'][$i] as $dtm)
							$stepCt['step4']['id'][] =  Refcall($dtm->cuurentId);  
							}
							} 
							 
                            
                            $NBusinessAmt = 0; 
                            foreach($stepCt['step4']['id'] as $dtm) 
                            {         
                                foreach($dtm as $dtmx) 
                                {    
                                    $stmt=$conn->prepare("select *  from UI__DChstr where Rid=:Rid and typ=1");   
                                    $stmt->bindValue(':Rid', $dtmx->cuurentId , PDO::PARAM_STR);  
                                    $stmt->execute(); 
                                    $Resultx = $stmt->fetch(PDO::FETCH_OBJ);  
                                    $NBusinessAmt +=$Resultx->amt; 
                                } 
                            }
                            
                                if($NBusinessAmt>=100000) 
                                {
                                    $CoinVal = ($data['Data']*2)/100;   
                                    $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)
                       { 
                            $stmt=$conn->prepare("select custId   from UI__Rgst where cuurentId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId',  $ard[$j1]  , PDO::PARAM_INT);  
                            $stmt->execute(); 
                            $Result1 = $stmt->fetch(PDO::FETCH_OBJ);  
                               
                            $stmt=$conn->prepare("select cuurentId from UI__Rgst where custId =:custId ");   
                            $stmt->bindValue(':custId', $Result1->custId   , PDO::PARAM_STR);  
                            $stmt->execute(); 
                            $Result = $stmt->fetch(PDO::FETCH_OBJ);
                            
                              
                            $myRefId = $Result->cuurentId;   
                            $stmt=$conn->prepare("select cuurentId   from UI__Rgst where refId =:cuurentId ");   
                            $stmt->bindValue(':cuurentId', $Result->cuurentId  , PDO::PARAM_INT);  
                            $stmt->execute();
                            
                            $myTT = 0;
                            if($stmt->rowCount()>0)
                            { 
                                $Result = $stmt->fetchAll(PDO::FETCH_OBJ);     
                                foreach($Result as $dtm) 
                                    $stepCt['step1']['id'][] = $dtm->cuurentId;
                                    
                                    
                                $myTT +=count($stepCt['step1']['id']);       
                                foreach($Result as $dtm) 
                                    $stepCt['step2']['id'][] =  Refcall($dtm->cuurentId); 
                                
                            }   
							  
							for($i=0;$i<count($stepCt['step2']['id']);$i++)
							{
								 
								if(count($stepCt['step2']['id'][$i])>0)
								{
									   $myTT +=count($stepCt['step2']['id'][$i]);     
									   
								   foreach($stepCt['step2']['id'][$i] as $dtm)
									 $stepCt['step3']['id'][] =  Refcall($dtm->cuurentId);  
								}
								
							} 
							
							for($i=0;$i<count($stepCt['step3']['id']);$i++)
							{

							if(count($stepCt['step3']['id'][$i])>0)
							{
							$myTT +=count($stepCt['step3']['id'][$i]);     

							foreach($stepCt['step3']['id'][$i] as $dtm)
							$stepCt['step4']['id'][] =  Refcall($dtm->cuurentId);  
							}
							} 
							
								 for($i=0;$i<count($stepCt['step4']['id']);$i++)
							{
								 
								if(count($stepCt['step4']['id'][$i])>0)
								{
									
								   $myTT +=count($stepCt['step4']['id'][$i]);   
								   
								   foreach($stepCt['step4']['id'][$i] as $dtm)
									 $stepCt['step5']['id'][] =  Refcall($dtm->cuurentId);  
								}
							} 
							 
                            
                            $NBusinessAmt = 0; 
                            foreach($stepCt['step5']['id'] as $dtm) 
                            {         
                                foreach($dtm as $dtmx) 
                                {    
                                    $stmt=$conn->prepare("select *  from UI__DChstr where Rid=:Rid and typ=1");   
                                    $stmt->bindValue(':Rid', $dtmx->cuurentId , PDO::PARAM_STR);  
                                    $stmt->execute(); 
                                    $Resultx = $stmt->fetch(PDO::FETCH_OBJ);  
                                    $NBusinessAmt +=$Resultx->amt; 
                                } 
                            }
                            
                                if($NBusinessAmt>=100000) 
                                {
                                    $CoinVal = ($data['Data']*1)/100;   
                                    $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();      
                                }
						    }     
                        }
                    }	
                
                $_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);   
  
    
include_once("../view/dashboard/topup-user-id.php");
?>