<?php 	
    include_once('../../config.php');   	
    include_once(ABS_PATH.'/admin/login_check.php');     
    include ABS_PATH.'/admin/header.php';	
    
    
                
                    function totalDebitUser($UserId)
                    {  
                               
                        global $conn;    
                        
                        if($UserId=="DP841053")
                        {
                            
                        $stmt=$conn->prepare("select *  from UI__WithDrawForD    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; 
                        
                         
                         
                            
                        }else {
                        $stmt=$conn->prepare("select *  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; 
                        }
                        
                        return $totalWithdrwa;  
                        
                         
                    }

    
                    function totalCreditUsers($UserId)
                    { 
                        
                        global $conn;
                        
                        if($UserId=="DP841053")
                        {
                        
                                 
        
                                $stmt=$conn->prepare("select *  from UI__DailyROIGeneForD    where custId=:sId     ");   
                                $stmt->bindValue(':sId',  $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 availableFund from UI__FundtransferForD  where  userid=:userid  order by id desc  ");   
                                $stmt->bindValue(':userid',  $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', $UserId  , PDO::PARAM_INT);  
                                $stmt->execute(); 
                                $UI__nm = $stmt->fetch(PDO::FETCH_OBJ);     
                                $BY = $UI__nm->nm;
                                
                                $PAYWAllet =  ($Tamnt+$UI__Fundtransfer->availableFund);     
                                return $PAYWAllet; 
                            
                        }
                      	else{											
                        $stmt=$conn->prepare("select *  from UI__DailyROIGeneAtw    where custId=:sId     ");   
                        $stmt->bindValue(':sId', $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 *  from UI__DailyROIGene    where custId=:sId     ");   
                        $stmt->bindValue(':sId',  $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 *  from UI__BnsAtw    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $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 *  from UI__Bns    where Rid =:sId   ");   
                        $stmt->bindValue(':sId',  $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',  $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',  $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', $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;
                      	}
                        
                    }
?>  

<script>
            
            function GetBalance(sr,Id)
            {
                
                    $.ajax({
                    type: 'POST',
                    url: "../../config.php",
                    //async: false,			 
                    data: {gtMybal:1,Id:Id,bYadmin:1},	  
                    success: function(ajaxresult)
                    {	      
                        $("#MyBal"+sr).html(ajaxresult);     
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) 
                    { 
                    
                            alert('Error');
                            
                    }
                    });
            
            }
	
function del_record(val)
{

	var r = confirm("Do you really want to delete record !");
	if (r == true) {    
	$.ajax({
	type: 'POST',
	url: "../ajax/default.php",
	//async: false,			 
	data: {del_city_names:1,val:val},	  
	success: function(ajaxresult){	     
		location.reload();	 	
	},
	error: function(XMLHttpRequest, textStatus, errorThrown) { 
	alert('Error');
	}
	});
	
	}	
	
	
	
}

</script>
		 
		<div class="col-md-10">  
  			<div class="content-box-large">
  				<div class="panel-heading">
					<div class="panel-title"><h3> User Credit Debit </h3></div>
					
					<!--div align="right">  <input type="button"    class="btn btn-warning" name="btnback" id="btnback" value=" Add New User " onClick="javascript:location.href='#';" />
					</div-->
					
				</div>
				
  				<div class="panel-body">
  					<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
						<thead>
							<tr>
								<th>Credit</th>
								<th>Debit</th>
								<th>Balance</th>   
							</tr>
						</thead>
						<tbody> 
							<tr class="odd gradeX">
								<td><?php echo totalCreditUsers($_REQUEST['UserId']);?></td>
								<td>
								    <?php 
								        echo (totalDebitUser($_REQUEST['UserId']));
						             ?>   
							        
						        </td>  
								<td><?php 
								         echo  (GetBalance($_REQUEST['UserId']));
					                ?>  
					                </td>  
							</tr>   
						</tbody>
					</table>
  				</div>
  			</div>



		  </div>
		</div>
    </div>

<?php  include ABS_PATH.'/admin/footer.php';	?>    