<?php
        $quApiOldBal = "SELECT ApiBal FROM recharge WHERE Lapu='$LapuApi' AND Status='SUCCESS' ORDER BY Id DESC";
	    $reApiOldBal = mysqli_query($con,$quApiOldBal);
	    $dataApiOldBal = mysqli_fetch_array($reApiOldBal);
		$ApiOldBalRow  = mysqli_num_rows($reApiOldBal);
		$ApiOldBal     = $dataApiOldBal['ApiBal'];
	    if($ApiOldBalRow==0 || $ApiOldBalRow=="")
		{
		    $ApiOldBal = 0;
		}
	    $remaiBal = $ApiOldBal-$amount;
		$ApiDiff  = $ApiBal-$remaiBal;
		$UpadateStatus="UPDATE recharge SET Status='SUCCESS', R_Offer='$roffer', OpId='$txnId', Diff='$ApiDiff', ApiBal='$ApiBal' WHERE Id='$newrechid'";
		mysqli_query($con,$UpadateStatus);
		
		$parentId     = $dataUser['Parent'];
		$p_comm       = getComm($parentId,$OpCode);
	    $net_p_comm   = $p_comm-$usrComm;
	    $p_commAmount = $net_p_comm*$amount/100;
	        
	    $insrtPcomm="INSERT INTO comm_wallet (Date,Time,Userid,Txn,TxnId) VALUES ('$date','$time','$parentId','$net_p_comm','$newrechid')";
	    mysqli_query($con,$insrtPcomm);
		
		if($userType=="RETAILER")
		{   
		    $G_parentId    = $dataUser['G_Parent'];
	        $gp_comm       = getComm($G_parentId,$OpCode);
	        $net_gp_comm   = $gp_comm-$p_comm;
	        $gp_commAmount = $net_gp_comm*$amount/100;
	        
	        $insrtGPcomm="INSERT INTO comm_wallet (Date,Time,Userid,Txn,TxnId) VALUES ('$date','$time','$G_parentId','$gp_commAmount','$newrechid')";
	        mysqli_query($con,$insrtGPcomm);
		}
		
		if($usrType=="API")
	    {
	        $rechStatus="SUCCESS";
	        require'../LinkFile/respoApi.php';
	    }
	    else
	    {
	        $respoStatus="SUCCESS";
	        $msg="Recharge Success !";
	        require'../LinkFile/respoPanel.php';
	    }
?>