<?php 
session_start();
ini_set('date.timezone', 'Asia/Kolkata');
error_reporting(E_ERROR | E_WARNING);
#error_reporting(E_ALL);  		 
include_once('config/GLOBALS.php'); 
include_once('config/database.php'); 

      
      
                      
                    if(isset($_SESSION['userLogin']))
                    {   
                    
                        $stmt=$conn->prepare("select nm,cuurentId,UPI,marchant,phm from   UI__Rgst where custId=:custId ");   
                        $stmt->bindValue(':custId',$_SESSION['userCustId'], PDO::PARAM_STR);   
                        $stmt->execute(); 
                        $userNam = $stmt->fetch(PDO::FETCH_OBJ);   
                        
                           $Ssprcl100 = 0; 
                        if (strpos($userNam->cuurentId, 'SP') !== false)   
                            $Ssprcl100=1;   
                      
                            
                         
                        $marchatS = $userNam->marchant;
                        
                        $ekycset = 0; 
                        $stmt=$conn->prepare("select id from   UI__PanVeri where custId=:cuurentId");    
                        $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
                        $stmt->execute(); 
                        $PanVer = $stmt->rowCount();
                        
                        $stmt=$conn->prepare("select nm from   UI__AdharVeri where custId=:cuurentId");    
                        $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
                        $stmt->execute(); 
                        $AdharVer = $stmt->rowCount();
                        $eKyc = $stmt->fetch(PDO::FETCH_OBJ); 
                        
                        if( ($PanVer>0) &&  ($AdharVer>0))
                            $ekycset = 1;
                            
                            
                        $Cevar = 0; 
                        $stmt=$conn->prepare("select id from   UI__PanVeri where custId=:cuurentId");    
                        $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
                        $stmt->execute(); 
                        $PanVerCg = $stmt->rowCount();
                        
                        
                        $stmt=$conn->prepare("select id from   UI__AdharVeri where custId=:cuurentId");    
                        $stmt->bindValue(':cuurentId',  $_SESSION['userId'], PDO::PARAM_STR);     
                        $stmt->execute(); 
                        $AdharVerCg = $stmt->rowCount();
                        
                        if( ($PanVerCg>0) &&  ($AdharVerCg>0))
                            $Cevar = 1;    
                            
                            
                        $stmt=$conn->prepare("select id,cuurentId from   UI__Rgst where refId=:refId ");   
                        $stmt->bindValue(':refId', $_SESSION['userId'], PDO::PARAM_STR);   
                        $stmt->execute(); 
                        $TotalRefCount = $stmt->rowCount();
                        $TotalActualRef = $TotalRefCount;
                   
                         
                        
                        if($TotalRefCount>0)
                        { 
                	        $TotalRefCountRst = $stmt->fetchAll(PDO::FETCH_OBJ);
                	        $myDirectBussiness = 0;
                	        
                	      
                	        foreach($TotalRefCountRst as $mpp)
                	        {
                    	        $stmt=$conn->prepare("select amt  from  UI__DChstr where Rid=:Rid  ");   
        						$stmt->bindValue(':Rid', $mpp->cuurentId , PDO::PARAM_STR);   
        						$stmt->execute();
        						$UI__DChstr2 = $stmt->fetchAll(PDO::FETCH_OBJ);
        						
        						
        						foreach($UI__DChstr2 as $dpp1)
        						    $myDirectBussiness +=$dpp1->amt;
        						    
                	        } 
                	        
                	        
                	     
                	        if($myDirectBussiness < 999)
                	            $TotalRefCount  = 0;
                	            
                        } 
                        
                         
                    }    
 
 
                    function totalDebit()
                    {  
                               
                        global $conn; 
                        if( ($_SESSION['userId']=="DP841053") && ($_SESSION['MasterPwd']==1))
                        {
                            
                        $stmt=$conn->prepare("select amt  from UI__WithDrawForD    where userid=:sId and (accept=1 ||accept=2)  ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                        $totalWithdrwa = 0;
                        foreach($UI__WithDraw as $tl)
                            $totalWithdrwa +=$tl->amt; 
                        return $totalWithdrwa;      
                            
                        }else {
                        
                        $stmt=$conn->prepare("select amt from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                        $totalWithdrwa = 0;
                        foreach($UI__WithDraw as $tl)
                            $totalWithdrwa +=$tl->amt; 
                        
                        return $totalWithdrwa;  
                        }
                    }
                    
                    function totalCredit()
                    { 
                        
                        global $conn;		          
                          												
                        $stmt=$conn->prepare("select amount  from UI__DailyROIGeneAtw    where custId=:sId     ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                        $stmt->execute(); 
                        $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                        $Tamnt = 0;
                        foreach($XUI__DailyROIGene as $xx)
                        {
                        $Tamnt +=$xx->amount;
                        }

                        $stmt=$conn->prepare("select amount  from UI__DailyROIGene    where custId=:sId     ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                        $stmt->execute(); 
                        $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                         
                        foreach($XUI__DailyROIGene as $xx)
                        {
                            $Tamnt +=$xx->amount;
                        }       
                        
                        $stmt=$conn->prepare("select Tamt  from UI__BnsAtw    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                        $stmt->execute(); 
                        $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                        
                        $LevelI = 0; 
                        foreach($UI__Bns as $dddm)
                        {
                        $LevelI +=$dddm->Tamt;
                        }

                        $stmt=$conn->prepare("select Tamt  from UI__Bns    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                        $stmt->execute(); 
                        $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                        
                        
                        foreach($UI__Bns as $dddm)
                        {
                        $LevelI +=$dddm->Tamt;
                        }
                        
                        
                        $stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
                        $stmt->bindValue(':refId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                        $directIncome = 0;
                        foreach($MdirectB as $dmm)
                        $directIncome += $dmm->Amt;          
                        
                          
                        
                        $stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
                        $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ); 
                        
                        
                        
                        $stmt=$conn->prepare("select nm  from UI__Rgst    where cuurentId=:cuurentId     ");   
                        $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $UI__nm = $stmt->fetch(PDO::FETCH_OBJ);     
                        $BY = $UI__nm->nm;
                        
                        $PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund);     
                        return $PAYWAllet;
                        
                    } 
                    
                    
                    function GetBalanceTest()
                    { 
                        global $conn;   
                         
                        $stmt=$conn->prepare("select amount  from UI__DailyROIGeneAtw    where custId=:sId     ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                        $stmt->execute(); 
                        $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                        $Tamnt = 0;
                        foreach($XUI__DailyROIGene as $xx)
                        {
                        $Tamnt +=$xx->amount;
                        }

                        $stmt=$conn->prepare("select amount  from UI__DailyROIGene    where custId=:sId     ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                        $stmt->execute(); 
                        $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                         
                        foreach($XUI__DailyROIGene as $xx)
                        {
                        $Tamnt +=$xx->amount;
                        }      
                        
                        
                        $LevelI = 0; 
                        $stmt=$conn->prepare("select Tamt  from UI__BnsAtw    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                        $stmt->execute(); 
                        
                        if($stmt->rowCount()>0)
                        {   
                            $UI__BnsAtw = $stmt->fetchAll(PDO::FETCH_OBJ); 
                            foreach($UI__Bns as $iD)
                                $LevelI +=$iD->Tamt;
                        }

                        $stmt=$conn->prepare("select Tamt  from UI__Bns    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                        $stmt->execute(); 
                        $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                        
                        
                        if($stmt->rowCount()>0)
                        {   
                            $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                            foreach($UI__Bns as $iD)
                                $LevelI +=$iD->Tamt;
                        } 
                        
                         
                        
                        $PAYWAllet =  ($Tamnt);//+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);     
                        return $PAYWAllet;
                     
                    }
                    
                    function GetBalance()
                    { 
                        global $conn;		          
                          												
                        if( ($_SESSION['userId']=="DP841053") && ($_SESSION['MasterPwd']==1))
                        { 
                            
                                $stmt=$conn->prepare("select *   from   UI__DebitCreditForD order by Id desc   ");   
                                $stmt->bindValue(':userid', $LPB  , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $UI__DebitCreditForD = $stmt->fetch(PDO::FETCH_OBJ);   
                                $PAYWAllet =  $UI__DebitCreditForD->availableBal;   

                                
                                
                                return $PAYWAllet;
                        
                            
                        }else {
                        $stmt=$conn->prepare("select amount from UI__DailyROIGeneAtw    where custId=:sId     ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                        $stmt->execute(); 
                        $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                        $Tamnt = 0;
                        foreach($XUI__DailyROIGene as $xx)
                        {
                        $Tamnt +=$xx->amount;
                        }

                        $stmt=$conn->prepare("select amount  from UI__DailyROIGene    where custId=:sId     ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                        $stmt->execute(); 
                        $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                         
                        foreach($XUI__DailyROIGene as $xx)
                        {
                        $Tamnt +=$xx->amount;
                        }      
                        
                        
                        $stmt=$conn->prepare("select Tamt  from UI__BnsAtw    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);   
                        $stmt->execute(); 
                        $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                        
                        $LevelI = 0; 
                        foreach($UI__Bns as $dddm)
                        {
                        $LevelI +=$dddm->Tamt;
                        }

                        $stmt=$conn->prepare("select Tamt from UI__Bns    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);  
                        $stmt->execute(); 
                        $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                        
                        
                        foreach($UI__Bns as $dddm)
                        {
                        $LevelI +=$dddm->Tamt;
                        }
                        
                        
                        $stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
                        $stmt->bindValue(':refId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
                        
                        $directIncome = 0;
                        foreach($MdirectB as $dmm)
                        $directIncome += $dmm->Amt;                
                        
                        
                        
                        
                        $stmt=$conn->prepare("select amt from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
                        $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
                        
                        
                        $totalWithdrwa = 0;
                        foreach($UI__WithDraw as $tl)
                        {
                        $totalWithdrwa +=$tl->amt;
                        }  
                        
                        
                        $stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
                        $stmt->bindValue(':userid',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ); 
                        
                        
                        
                        $stmt=$conn->prepare("select nm  from UI__Rgst    where cuurentId=:cuurentId     ");   
                        $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                        $stmt->execute(); 
                        $UI__nm = $stmt->fetch(PDO::FETCH_OBJ);     
                        $BY = $UI__nm->nm;
                        
                        $PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);     
                        return $PAYWAllet;
                        }
                        
                    }
                    
                    
            function LvBal($LPB,$CoinVal,$type,$msg,$byw)
            {
                
                    global $conn;	
                    
                    $stmt=$conn->prepare("select amount  from UI__DailyROIGeneAtw    where custId=:sId     ");   
                    $stmt->bindValue(':sId', $LPB, PDO::PARAM_STR);  
                    $stmt->execute(); 
                    $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $Tamnt = 0;
                    foreach($XUI__DailyROIGene as $xx)
                    {
                    $Tamnt +=$xx->amount;
                    }
                    

                    $stmt=$conn->prepare("select amount  from UI__DailyROIGene    where custId=:sId     ");   
                    $stmt->bindValue(':sId', $LPB, PDO::PARAM_STR);  
                    $stmt->execute(); 
                    $XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                     
                    foreach($XUI__DailyROIGene as $xx)
                    {
                    $Tamnt +=$xx->amount;
                    }
                    
                            
                    $stmt=$conn->prepare("select Tamt  from UI__BnsAtw    where Rid =:sId   ");   
                    $stmt->bindValue(':sId',  $LPB , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    
                    $LevelI = 0;
                    foreach($UI__Bns as $dddm)
                    {
                    $LevelI +=$dddm->Tamt;
                    }
            
                    
                    
                    $stmt=$conn->prepare("select Tamt from UI__Bns    where Rid =:sId   ");   
                    $stmt->bindValue(':sId',  $LPB , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    
                     
                    foreach($UI__Bns as $dddm)
                    {
                    $LevelI +=$dddm->Tamt;
                    }
                    
                    
                    $stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
                    $stmt->bindValue(':refId',  $LPB , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
                    
                    $directIncome = 0;
                    foreach($MdirectB as $dmm)
                    $directIncome += $dmm->Amt;                
                    
                    
                    
                    
                    $stmt=$conn->prepare("select amt  from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
                    $stmt->bindValue(':sId',  $LPB, PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
                    
                    
                    $totalWithdrwa = 0;
                    foreach($UI__WithDraw as $tl)
                    {
                    $totalWithdrwa +=$tl->amt;
                    }
                    
                    
                    
                    
                    $stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
                    $stmt->bindValue(':userid',  $LPB, PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ); 
                    
                    
                    
                    $stmt=$conn->prepare("select nm  from UI__Rgst    where cuurentId=:cuurentId     ");   
                    $stmt->bindValue(':cuurentId',  $ard[$j1] , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__nm = $stmt->fetch(PDO::FETCH_OBJ);     
                    $BY = $UI__nm->nm;
                    
                    $PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);        
                    
                    
                    $stmt=$conn->prepare("insert into  UI__DebitCredit (custId,addDel,availableBal,Tdate,type,Intype,byw) values(:custId,:addDel,:availableBal,:Tdate,:type,:Intype,:byw)"); 
                    $stmt->bindValue(':custId',$LPB, PDO::PARAM_STR); 
                    $stmt->bindValue(':addDel',$CoinVal, PDO::PARAM_STR); 
                    $stmt->bindValue(':availableBal',  number_format((float)($PAYWAllet), 2, '.', '') , PDO::PARAM_STR);  
                    $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);  
                    $stmt->bindValue(':Intype', $msg , PDO::PARAM_STR);    
                    $stmt->bindValue(':type', $type , PDO::PARAM_STR);  
                    $stmt->bindValue(':byw', $byw , PDO::PARAM_STR);    
                    $stmt->execute();  
                    $_SESSION['LastIntId'] = $conn->lastInsertId();;
                    
                    $stmt=$conn->prepare("select id from UI__Rgst  where  cuurentId=:cuurentId    ");   
                    $stmt->bindValue(':cuurentId',  $LPB , PDO::PARAM_STR);  
                    $stmt->execute(); 
                    $UIid = $stmt->fetch(PDO::FETCH_OBJ);   
                    
                    $amount = password_hash(($PAYWAllet),PASSWORD_DEFAULT);  
                    $stmt =  $conn->prepare("update _pkCc__ set bl1=:bl1,tm=:tm where Uxd=:Uxd "); 
                    $stmt->bindValue(':bl1', $amount, PDO::PARAM_STR); 
                    $stmt->bindValue(':tm', date("d-M-Y H:i"), PDO::PARAM_STR); 
                    $stmt->bindValue(':Uxd', $UIid->id, PDO::PARAM_STR);  
                    $stmt->execute(); 
            }
            
            function AddFundNew($UserId,$Fund,$msg) 
			{
							
							 global $conn;	
							
							$stmt=$conn->prepare("select  amt,availableFund from  UI__Fundtransfer   where userid=:cuurentId order by id desc");  
							$stmt->bindValue(':cuurentId', $UserId , PDO::PARAM_STR);
							$stmt->execute();  
							
							 
							
							if($stmt->rowCount() > 0)
							{
							   $AllUsers = $stmt->fetch(PDO::FETCH_OBJ); 
							   $totalAvaib = $AllUsers->availableFund+$Fund;  
							}else
								$totalAvaib =  $Fund;   

								
							 
							$stmt=$conn->prepare("insert into  UI__Fundtransfer (userid,Tdate,amt,availableFund) values(:userid,:Tdate,:amt,:availableFund)    "); 
							$stmt->bindValue(':userid',$UserId, PDO::PARAM_STR); 
							$stmt->bindValue(':Tdate',date("d-M-Y H:i"), PDO::PARAM_STR); 
							$stmt->bindValue(':amt',$Fund, PDO::PARAM_STR);  
							$stmt->bindValue(':availableFund', $totalAvaib , PDO::PARAM_STR);  
							$stmt->execute(); 
							 
							
							$stmt=$conn->prepare("select amount  from UI__DailyROIGene    where custId=:sId     ");   
							$stmt->bindValue(':sId',  $UserId , PDO::PARAM_INT);  
							$stmt->execute(); 
							$XUI__DailyROIGene = $stmt->fetchAll(PDO::FETCH_OBJ);  
							
							$Tamnt = 0;
							foreach($XUI__DailyROIGene as $xx)
							{
							$Tamnt +=$xx->amount;
							}      
							
							
							$stmt=$conn->prepare("select  Tamt  from UI__Bns    where Rid =:sId   ");   
							$stmt->bindValue(':sId',  $UserId , PDO::PARAM_INT);  
							$stmt->execute(); 
							$UI__Bns = $stmt->fetchAll(PDO::FETCH_OBJ); 
							
							$LevelI = 0;
							foreach($UI__Bns as $dddm)
							{
							$LevelI +=$dddm->Tamt;
							}
							
							
							$stmt=$conn->prepare("select Amt   from UI__Tpm where TopUpId=:refId   ");   
							$stmt->bindValue(':refId',  $UserId , PDO::PARAM_INT);  
							$stmt->execute(); 
							$MdirectB = $stmt->fetchAll(PDO::FETCH_OBJ);  
							
							$directIncome = 0;
							foreach($MdirectB as $dmm)
							$directIncome += $dmm->Amt;                
							
							
							
							
							$stmt=$conn->prepare("select amt from UI__WithDraw    where userid=:sId and (accept=1 ||accept=2)  ");   
							$stmt->bindValue(':sId', $UserId , PDO::PARAM_INT);  
							$stmt->execute(); 
							$UI__WithDraw = $stmt->fetchAll(PDO::FETCH_OBJ); 
							
							
							$totalWithdrwa = 0;
							foreach($UI__WithDraw as $tl)
							{
							$totalWithdrwa +=$tl->amt;
							}
							
							  
							$stmt=$conn->prepare("select availableFund from UI__Fundtransfer  where  userid=:userid  order by id desc  ");   
							$stmt->bindValue(':userid',  $UserId , PDO::PARAM_INT);  
							$stmt->execute(); 
							$UI__Fundtransfer = $stmt->fetch(PDO::FETCH_OBJ);   
							
							   
							$PAYWAllet =  ($Tamnt+$LevelI+$directIncome+$UI__Fundtransfer->availableFund)-($totalWithdrwa);      
							$stmt=$conn->prepare("insert into  UI__DebitCredit (custId,addDel,availableBal,Tdate,type,Intype,byw) values(:custId,:addDel,:availableBal,:Tdate,:type,:Intype,'NA')"); 
							$stmt->bindValue(':custId',$UserId, PDO::PARAM_STR); 
							$stmt->bindValue(':addDel',$Fund, PDO::PARAM_STR); 
							$stmt->bindValue(':availableBal',$PAYWAllet, PDO::PARAM_STR);  
							$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);  
							$stmt->bindValue(':Intype', $msg , PDO::PARAM_STR);   
							$stmt->bindValue(':type', 1 , PDO::PARAM_STR);   
							$stmt->execute();     
							$LastIntId = $conn->lastInsertId();
							
							$stmt=$conn->prepare("select id from UI__Rgst  where  cuurentId=:cuurentId    ");   
							$stmt->bindValue(':cuurentId',  $UserId , PDO::PARAM_STR);  
							$stmt->execute(); 
							$UIid = $stmt->fetch(PDO::FETCH_OBJ);   
							
							$amount = password_hash(($PAYWAllet),PASSWORD_DEFAULT);  
							$stmt =  $conn->prepare("update _pkCc__ set bl1=:bl1,tm=:tm where Uxd=:Uxd "); 
							$stmt->bindValue(':bl1', $amount, PDO::PARAM_STR); 
							$stmt->bindValue(':tm', date("d-M-Y H:i"), PDO::PARAM_STR); 
							$stmt->bindValue(':Uxd', $UIid->id, PDO::PARAM_STR);  
							$stmt->execute();   
							
							$stmt=$conn->prepare("select * from UI__Rgst  where  cuurentId=:cuurentId  ");   
							$stmt->bindValue(':cuurentId',  $UserId , PDO::PARAM_STR);  
							$stmt->execute();
							$UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);     	
							
							
							$stmt=$conn->prepare("insert into UI__Receipt(type,bank,mobile,email,amountPaid,Tid,status,Tdate,custId,cdId,Topay,TopayName) values(:type,:bank,:mobile,:email,:amountPaid,:Tid,:status,:Tdate,:custId,:cdId,:Topay,:TopayName)"); 
							$stmt->bindValue(':type',   11 , PDO::PARAM_STR);   
							$stmt->bindValue(':bank',  "Fund Added By User" , PDO::PARAM_STR);   
							$stmt->bindValue(':mobile', $UI__Rgst->phm, PDO::PARAM_STR);
							$stmt->bindValue(':email', $UI__Rgst->eml , PDO::PARAM_STR); 
							$stmt->bindValue(':amountPaid', $Fund  , PDO::PARAM_STR); 
							$stmt->bindValue(':Tid', mt_rand(1234552,23555), PDO::PARAM_STR); 
							$stmt->bindValue(':status', 1 , PDO::PARAM_STR); 
							$stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);      
							$stmt->bindValue(':custId', $UserId, PDO::PARAM_STR);  
							$stmt->bindValue(':cdId', $LastIntId  , PDO::PARAM_STR); 
							$stmt->bindValue(':Topay',  $UserId , PDO::PARAM_STR); 
							$stmt->bindValue(':TopayName',  $UserId , PDO::PARAM_STR);     
							$stmt->execute();    
				}
				
				 
				 
				 
				            
            function LvBalForD($LPB,$CoinVal,$type,$msg,$byw)
            {
                
                    global $conn;  
                    
                    $stmt=$conn->prepare("select *   from   UI__DebitCreditForD order by Id desc   ");   
                    $stmt->bindValue(':userid', $LPB  , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__DebitCreditForD = $stmt->fetch(PDO::FETCH_OBJ);   
                    $PAYWAllet =  $UI__DebitCreditForD->availableBal-$CoinVal;  
                    
                    $stmt=$conn->prepare("insert into  UI__DebitCreditForD (custId,addDel,availableBal,Tdate,type,Intype,byw) values(:custId,:addDel,:availableBal,:Tdate,:type,:Intype,:byw)"); 
                    $stmt->bindValue(':custId',$LPB, PDO::PARAM_STR); 
                    $stmt->bindValue(':addDel',$CoinVal, PDO::PARAM_STR); 
                    $stmt->bindValue(':availableBal',  number_format((float)($PAYWAllet), 2, '.', '') , PDO::PARAM_STR);  
                    $stmt->bindValue(':Tdate', date("d-M-Y H:i") , PDO::PARAM_STR);  
                    $stmt->bindValue(':Intype', $msg , PDO::PARAM_STR);    
                    $stmt->bindValue(':type', $type , PDO::PARAM_STR);  
                    $stmt->bindValue(':byw', $byw , PDO::PARAM_STR);    
                    $stmt->execute();  
                    $_SESSION['LastIntId'] = $conn->lastInsertId();  
            }
            
            
                
                function notifc($token,$title,$message)
                {
                    
                    
                    $curl = curl_init(); 
                    curl_setopt_array($curl, array(
                    CURLOPT_URL => 'https://janteriapp.com/NOTIFICATION/firebase.php',
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_ENCODING => '',
                    CURLOPT_MAXREDIRS => 10,
                    CURLOPT_TIMEOUT => 0,
                    CURLOPT_FOLLOWLOCATION => true,
                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST => 'POST',
                    CURLOPT_POSTFIELDS => array('token' =>"$token",'title' =>"$title",'message' =>"$message",'audiourl' => '""'),
                    ));
                    
                    $response = curl_exec($curl); 
                    curl_close($curl); 
                }
            
            $stmt=$conn->prepare("select PinDis,UPI5  from  UI__Rgst    where cuurentId=:cuurentId     ");   
            $stmt->bindValue(':cuurentId', $_SESSION['userId'], PDO::PARAM_STR);
            $stmt->execute(); 
            $PinDisR = $stmt->fetch(PDO::FETCH_OBJ);  
            $PinDis=$PinDisR->PinDis;
            $UPI5 = $PinDisR->UPI5;
            
            
            $stmt=$conn->prepare("select *   from UI__DChstr where Rid =:sId  and typ=1");   
            $stmt->bindValue(':sId',  $_SESSION['userId'] , PDO::PARAM_STR);  
            $stmt->execute(); 
            if($stmt->rowCount() > 0)
                $UI__DChstr = 1;
                
                
            $stmt=$conn->prepare("select marchant from   UI__Rgst where custId=:custId ");   
            $stmt->bindValue(':custId',$_SESSION['userCustId'], PDO::PARAM_STR);   
            $stmt->execute(); 
            $usermarchat = $stmt->fetch(PDO::FETCH_OBJ);     
            $marchant = $usermarchat->marchant; 
            
            
             $Remail =  "dailypay2024@gmail.com";
            $Rd =  "gp6ZiH";  
            $access_token = '{"email":"'.$Remail.'","password":"'.$Rd.'"}';  
            
            
            $ch = curl_init('https://erp.pay2all.in/api/token');                                             
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
            curl_setopt($ch, CURLOPT_POSTFIELDS, $access_token);                                                                  
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
            'x-tera-tenant-region: IN', 
            'Content-Type: application/json', 
            'Content-Length: ' . strlen($access_token))                                                                       
            );       																		 
            $response = curl_exec($ch);  
            $json_response = json_decode($response);   
            $RechargeAccess_token = $json_response->token;  
            
                     