<?php
	include'connection.php';
	include'time.php';
	
	function getUBWI($usrId)
    {
        include'connection.php';
	    include'time.php';
        $quGetEwalletId="SELECT * FROM RetBal WHERE Userid='$usrId'";
        $reGetEwalletId=mysqli_query($con,$quGetEwalletId);
        $dataGetEwalletId=mysqli_fetch_array($reGetEwalletId);
        $EwalletId=$dataGetEwalletId['Walletid'];
        $EwalletIdDate=$dataGetEwalletId['Date'];
    
        $quDisOpBal="SELECT * FROM wallet WHERE Userid='$usrId' AND Id>=$EwalletId";
	    $reDisOpBal=mysqli_query($con,$quDisOpBal);
	    $countTxn=mysqli_num_rows($reDisOpBal);
	    if($countTxn>=1000 && $date!=$EwalletIdDate)
	    {
	        $Bal=0;
	        while($dataDisOpBal=mysqli_fetch_array($reDisOpBal))
	        {
	            $OldDisTxn= $dataDisOpBal['Txn'];
	            $Bal=$Bal+$OldDisTxn;
	        }
	        
	        echo $insertWallet="INSERT INTO wallet (Userid,OpBal,Txn,ClBal,Date,Time,Remarks) VALUES ('$usrId','$Bal','$Bal','$Bal','$date','$time','Update Wallet Id')";
	        if(mysqli_query($con,$insertWallet))
	        {
	            $newWalletId=mysqli_insert_id($con);
	            
	            echo $update="UPDATE RetBal SET Date='$date', Time='$time', Walletid='$newWalletId', Balance='$Bal' WHERE Userid='$usrId'";
	            mysqli_query($con,$update);
	        }
	    }
    }
    
	getUBWI(200003);
    
    exit();
	
	
	
	
	
	
	
	
	//$id=$_GET['id'];
	$id=281646;
	date_default_timezone_set("asia/Kolkata");
	$date= Date("Y-m-d");
	$time= Date("h:i:s A");
	if(isset($_POST['submit']))
	{
	    $msg=$_POST['msg'];
	    $solved=$_POST['solved'];
	    
    	$query="select * from recharge where Id=$id";
	    $result=mysqli_query($con,$query);
	    $data=mysqli_fetch_array($result);
	
	    $userid=$data['Userid'];
	    $debitamount=$data['Debitamount'];
	    $ewalletid=$data['Ewalletid'];
	    $oper=$data['Companyname'];
	    $mobile=$data['Mobile'];
	    $amount=$data['Amount'];
	    $Partnerid=$data['Partnerid'];
	    if(empty($Partnerid))
	    {
	        $Partnerid=123456789;
	    }
	    $query2="select * from retailer where Userid='$userid'";
		$result2=mysqli_query($con,$query2);
		$databal=mysqli_fetch_array($result2);
		$CallBackUrl=$databal['CallBackUrl'];
		$ApiActive=$databal['ApiActive'];
	    
	        if($ApiActive==1 || 1==1)
	        {
	          echo  $myurl ="$CallBackUrl?partnertid=$Partnerid&status=FAILED&orderid=$id&opid=$msg&errmsg=$msg";
                
	        
	            $qu="insert into Test(Testdata)values('$myurl')";
	            if(mysqli_query($con,$qu))
	            {
	                echo "Success";
	            }
	            else
	            {
	                echo "failed";
	            }
	            $myurl ="$CallBackUrl?partnertid=$Partnerid&status='FAILED'&orderid=$id&opid=$msg&errmsg=$msg";
	            
                $ch = curl_init();
                $timeout = 30; // set to zero for no timeout
                curl_setopt ($ch, CURLOPT_URL, $myurl);
                curl_setopt ($ch, CURLOPT_HEADER, 0);
                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); //timeout in seconds
                $getMsg= curl_exec($ch);
                $code =curl_getinfo($ch, CURLINFO_HTTP_CODE);
                curl_close($ch);
	        }
	}

?>
<html>
    <head>
       <style>
        #msg{width:200px; height:40px; font-size:22px;}
       </style>
    </head>
    <body>
        <form method="post">
        <table>
            <tr>
                <th><h2>Print Message</h2></th>
                <th><h2>Complain Close</h2></th>
                <th><h2>Action</h2></th>
            </tr>
            <tr>
                <td>
                    <select name="msg" id="msg">
                        <option>Failed !</option>
                        <option>Invalid Number Or Operator !</option>
                        <option>Invalid Number Or Amount !</option>
                        <option>Invalid Amount !</option>
                        <option>Operator Down !</option>
                        <option>Refund !</option>
                        <option>You can only select other than prime plan for recharge.	</option>
                    </select>
                </td>
                <td><input type="checkbox" value="solved" name="solved" id="msg"></td>
                <td><input type="submit" name="submit" id="msg"></td>
            </tr>
        </table>
        </form>
    </body>
</html>