<?php
	include_once('../config.php');   
    include_once(ABS_PATH.'/custom_function/default.php');  
          
    	
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }                            
    header("Location: topup-user-id.php");
    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(); 
    $PAYWAllet = $stmt->fetchAll(PDO::FETCH_OBJ); 
    
     
    
    $Awltwallet = 0;
    foreach($PAYWAllet 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['submit'])) 
    {  
        
        $stmt=$conn->prepare("select  tokenGen  from    UI__DChstr where tokenGen=:tokenGen");     
        $stmt->bindValue(':tokenGen', $_POST['tokenGen'] , PDO::PARAM_STR);   
        $stmt->execute();   
        if($stmt->rowCount() < 1)
        {  
            $stmt=$conn->prepare("select  dys  from    UI__TpDys");     
            $stmt->execute();   
            $UI__TpDys = $stmt->fetch(PDO::FETCH_OBJ); 
            

            $stmt=$conn->prepare("select * from UI__Crper");    
            $stmt->execute(); 
            $Cper = $stmt->fetch(PDO::FETCH_OBJ);      
            
            $_POST['cuurentId'] = trim($_POST['cuurentId']);        
            $stmt=$conn->prepare("select  *   from UI__Rgst where cuurentId =:cuurentId ");   
            $stmt->bindValue(':cuurentId', $_POST['cuurentId'] , PDO::PARAM_STR);  
            $stmt->execute(); 
            $affected_rows_UI__DChstr = $stmt->rowCount();  
            $FResult = $stmt->fetch(PDO::FETCH_OBJ);   
            $tNAM = $FResult->nm;
            $tId = $_POST['cuurentId'];
            $tPhm  = $FResult->phm;
            
            
            
            
            $stmt=$conn->prepare("select id from  UI__DChstr where typ=1 and sId=:sId ");    
            $stmt->bindValue(':sId', $FResult->custId , PDO::PARAM_STR);  
            $stmt->execute(); 
            
         
            $MPin  = ($_POST['TopPin']);
            $stmt = $conn->prepare("SELECT AMMT,id FROM UI__PnMX WHERE MPin=:MPin and exp!=1");  
            $stmt->execute(array(':MPin'=>$MPin));
            $affected_rows = $stmt->rowCount();	 
            
         
            $stmt=$conn->prepare("select id from UI__Rgst  where  cuurentId=:cuurentId  ");   
            $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
            $stmt->execute();
            $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);   
            
            $data['Data'] = $_POST['AMMT'];   
            if( (($Awltwallet-$cllTp)>= $data['Data'])  && ($data['Data']>=1000))
            {    
                $Result = $stmt->fetch(PDO::FETCH_OBJ);    
                
                     
                $PlanAMt = $data['Data'] ;    
                $stmt=$conn->prepare("select refId,custId,nm  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);
                    $userNm = $Result->nm;
                    $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;
                }          
				 
               
                   

                $CoinVal = ($data['Data']);    
                $stmt=$conn->prepare("insert into  UI__DChstr (typ,amt,Tdate,Rid,sId,percet,coin,byId,dys,tokenGen) values(:typ,:amt,:Tdate,:Rid,:sId,:percet,:coin,:byId,:dys,:tokenGen) ");   
                $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->bindValue(':dys', $UI__TpDys->dys  , PDO::PARAM_STR);     
                $stmt->bindValue(':tokenGen', $_POST['tokenGen'], 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);     
                
                LvBal($_SESSION['userId'],0,2,"Collection TopUp of Rs ".$_POST['AMMT'],$userNm." (".$_POST['cuurentId'].")");  
                
                
                $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                $stmt->execute();
                $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);     	
                
                
                
                $stmt=$conn->prepare("insert into UI__CollTopup(custId,Tdate,Amt) values(:custId,:Tdate,:Amt)"); 
                $stmt->bindValue(':custId',   $_SESSION['userId'], PDO::PARAM_STR);   
                $stmt->bindValue(':Tdate',   date("d-M-Y") , PDO::PARAM_STR);   
                $stmt->bindValue(':Amt',   $_POST['AMMT'] , PDO::PARAM_STR); 
                $stmt->execute(); 
                
                
                $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); 
                
                
                
                $Awltwallet = 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; 
                }
                

                
                $stmt=$conn->prepare("insert into  UI__ConirmQr(custId,Tdate,Amt,tranfredDate,trasnferStatus,type,sender_vpa,sender_name,balance) values(:custId,:Tdate,:Amt,:tranfredDate,1,1,'NA',:sender_name,:balance)"); 
                $stmt->bindValue(':custId',   $_SESSION['userId'], PDO::PARAM_STR);   
                $stmt->bindValue(':Tdate',   date("d-M-Y") , PDO::PARAM_STR);   
                $stmt->bindValue(':Amt',   $_POST['AMMT'] , PDO::PARAM_STR); 
                $stmt->bindValue(':tranfredDate',   date("d-M-Y H:i") , PDO::PARAM_STR);  
                $stmt->bindValue(':sender_name',   "Topup By ".$userNam->nm , PDO::PARAM_STR);   
                $stmt->bindValue(':balance', ($Awltwallet-$cllTp), PDO::PARAM_STR);  
                $stmt->execute();
                
                
                $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',   6 , PDO::PARAM_STR);   
                $stmt->bindValue(':bank',  "Top Up" , 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['AMMT']  , 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['cuurentId'] , PDO::PARAM_STR);  
                $stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
                $stmt->bindValue(':Topay',  $_POST['cuurentId']  , PDO::PARAM_STR); 
                $stmt->bindValue(':TopayName', $_POST['cuurentId'] , PDO::PARAM_STR);     
                $stmt->execute();    
                $MYLASTID = $_SESSION['LastIntId'];
                unset($_SESSION['LastIntId']);
                 
            	
				$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', 119  , 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);
                                    
                                    if($ard[$j1]!='DP112233')
                                    LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                    
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119  , 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);
                                
                                if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                
                                $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119  , 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);
                                
                               if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                               
                                
                               $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                            }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119  , 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);
                                
                                if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                
                                $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119  , 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);
                                
                                if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                
                                $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119  , 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);
                                
                                if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                
                                
                                     $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                            }else
                            {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119 , 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);
                                
                                 if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);      
                                 
                                
                                $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119  , 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);
                                
                                if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);   
                                
                               $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119 , 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);
                                
                                if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                
                                $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], 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', 119  , 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);
                                
                                if($ard[$j1]!='DP112233')
                                LvBal($ard[$j1],$CoinVal,1,"Level Balance",$_POST['cuurentId']);  
                                
                                $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',1, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                    
                                }else
                                {
                                    $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', $ard[$j1] , PDO::PARAM_STR); 
                                    $stmt->bindValue(':cct',0, PDO::PARAM_STR);  
                                    $stmt->bindValue(':bid', $_POST['cuurentId'], PDO::PARAM_STR);   
                                    $stmt->execute();
                                }
                             
 					      }
 					      
 					      
 					         
 					        if($stmt->rowCount()>0) 
 					        {
 					      
 					        /*$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                            $stmt->bindValue(':cuurentId',  $ard[$j1] , 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',   5 , PDO::PARAM_STR);   
                            $stmt->bindValue(':bank',  "Level Balance" , PDO::PARAM_STR);   
                            $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                            $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                            $stmt->bindValue(':amountPaid', $CoinVal  , 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', $ard[$j1] , PDO::PARAM_STR);  
                            $stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
                            $stmt->bindValue(':Topay',  $_POST['cuurentId'] , PDO::PARAM_STR); 
                            $stmt->bindValue(':TopayName',  $_POST['cuurentId'] , PDO::PARAM_STR);     
                            $stmt->execute();    
                            unset($_SESSION['LastIntId']);*/
 					        }
 					        
                            
                       }
                 }	  
                
                
              
                {
                 
                
                $Data = (($data['Data']*5)/100);  
                $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("select  id from UI__DChstr where Rid=:cuurentId  and typ=1 "); 
                $stmt->bindValue(':cuurentId',  $refId->refId  , PDO::PARAM_STR);  
                $stmt->execute();  
                if($stmt->rowCount() > 0)    
				{
				
				
				$stmt=$conn->prepare("select  * from UI__Rgst where cuurentId=:cuurentId  "); 
                $stmt->bindValue(':cuurentId',  $refId->refId  , PDO::PARAM_STR);  
                $stmt->execute();  
                $refIdXXX = $stmt->fetch(PDO::FETCH_OBJ); 
                    
                $CMB = $refId->refId;
                $AM = $Data;
                $mob = $refIdXXX->phm;
                $msg = urlencode('Dear '.$CMB.', Congratulations, Rs. '.$AM.' has been credited in your DAILYPAY account, DailyPay team.'); 
                $URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169907278194379';
                
                $crl = curl_init();
                curl_setopt($crl, CURLOPT_URL, $URL);
                curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
                curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); 
                $response = curl_exec($crl);


                $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();   
                
                if($refId->refId!='DP112233')
                    LvBal($refId->refId,$Data,1,"Spot Balance",$_POST['cuurentId']);     
                    
                    
                   
                 
                $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                $stmt->bindValue(':cuurentId',  $refId->refId , PDO::PARAM_STR);  
                $stmt->execute();
                $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);     	
                

                if($refId->refId!='DP112233'){
                $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',   4 , PDO::PARAM_STR);   
                $stmt->bindValue(':bank',  "Spot Balance" , PDO::PARAM_STR);   
                $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                $stmt->bindValue(':amountPaid', $Data  , 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['cuurentId'], PDO::PARAM_STR);  
                $stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
                $stmt->bindValue(':Topay',  $refId->refId  , PDO::PARAM_STR); 
                $stmt->bindValue(':TopayName',  $refId->refId , PDO::PARAM_STR);     
                $stmt->execute();    
                }  
                unset($_SESSION['LastIntId']);
				}
				
				 
                
                
                
                
                
                
                $Tdt = date("d-M-Y", strtotime($dmt->Tdate));   
                $amount = number_format((float)(($data['Data']*2)/$UI__TpDys->dys), 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","NA");   
                
                
                $stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
                $stmt->bindValue(':cuurentId',  $_POST['cuurentId'] , 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',   3 , PDO::PARAM_STR);   
                $stmt->bindValue(':bank',  "Daily Balance" , PDO::PARAM_STR);   
                $stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
                $stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
                $stmt->bindValue(':amountPaid', $amount  , 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['cuurentId'] , PDO::PARAM_STR);  
                $stmt->bindValue(':cdId', $_SESSION['LastIntId']  , PDO::PARAM_STR); 
                $stmt->bindValue(':Topay',  "NA" , PDO::PARAM_STR); 
                $stmt->bindValue(':TopayName',  "NA"  , PDO::PARAM_STR);     
                $stmt->execute();    
                //unset($_SESSION['LastIntId']);
                
                $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 eml from UI__Rgst  where  cuurentId=:cuurentId    ");   
                $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                $stmt->execute(); 
                $EMAIL = $stmt->fetch(PDO::FETCH_OBJ);   

                
                $subject = "Top Up  On ".$SITE_NAME;  
                $template_type = 1;
                $attachment = '';
                $name = $_POST['cuurentId'];
                $Amt = $data['Data'];
                
                $message="
                <tr>
                <td align='left' valign='top'>
                <h4 style='font-weight:bold; padding:2px 2px; margin:3px; text-align:left; color:#002368;'>Dear user,</h4>
                <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'>Thanks for Wallet Transfer with us. Your Details are as follows </h5> 
                <h5 style='font-weight:bold; padding:2px 2px; margin:0px; text-align:center; color:#002368;'> To: $name , Amount Rs : $Amt </h5>
                
                </td>
                </tr>"; 
                
                  
                  
                $tNAM = $FResult->nm;
                $tId = $_POST['cuurentId'];  
                $CMB = '('.$tId.'),'.$tNAM;
                $am = $_POST['AMMT'];
                $mob = $tPhm;
                $msg = urlencode('Dear '.$CMB.', Congratulations, your TOPUP amount Rs. '.$am.' has been successfully done, DailyPay team.'); 
                $URL  = 'http://mobicomm.dove-sms.com//submitsms.jsp?user=DailyPAY&key=d92eabc025XX&mobile=+91'.$mob.'&message='.$msg.'&senderid=DAYPAY&accusage=1&entityid=1201169824017740929&tempid=1207169907140786246';
                
                
                $crl = curl_init();
                curl_setopt($crl, CURLOPT_URL, $URL);
                curl_setopt($crl, CURLOPT_FRESH_CONNECT, true);
                curl_setopt($crl, CURLOPT_RETURNTRANSFER, true); 
                $response = curl_exec($crl);  

                
                SendMail($EMAIL->eml,$subject,$message,$template_type,$attachment);  
                SendMail("vsn.national@gmail.com",$subject,$message,$template_type,$attachment); 
                }
                
                header("Location: ".ROOTPATH."/dashboard/viewRec.php?id=".$MYLASTID);
                die;

                $_SESSION['Regis'] = "Congratulations Top Up Successful!!";
                $_SESSION['topSuc'] =  1;
                header("Location: colletionWallet.php"); 
                die;
            }
            else 
			{ 
                 
                 $_SESSION['Regis'] = "Top Up Failed";
                 header("Location: colletionWallet.php");
                 die; 
            }
        }
        else
        {
            $_SESSION['Regis'] = "Congratulations Top Up Successful!!";
            $_SESSION['topSuc'] =  1;
            header("Location: colletionWallet.php"); 
            die;
        }
    }       
    
          

        
    

    
    

include_once("../view/dashboard/colletionWallet.php");
?>