<?php
    include_once 'opendb.php';
     $response["success"] = -1;
     $response["message"] = "Error";
    
    if (isset($_POST["AppID"]))
    {
	
        $AppID=$_POST["AppID"] ;
        $ReqID=$_POST["ReqID"] ;
      
        $sql = "SELECT counter_code,next_so_no,inactive,client_type FROM mobile_clients WHERE client_app_id like '".$AppID."'";
        $result = $conn->query($sql);
        
        if ($result->num_rows > 0 ) {
        
       
        
                if($row = $result->fetch_assoc()) 
                {
                
                    if ($row["inactive"]==0)
                    {
                       $response["success"] = 1;
                       $response["client_code"] = $row["counter_code"];
                       $client_Code=$row["counter_code"];
                       $response["message"] = "active";
                       $response["client_type"] = $row["client_type"];
                       
                       
                        $sql = "delete from client_requests where request_id=".$ReqID;
               
               if ($conn->query($sql) === TRUE)
               {
                 $response["message"] = "Deleted";
                 
               } else
               {
                  die ( "Error in delete Request :" . $sql . "<br>" . $conn->error);
               } 
                      
        }
        else
        {

           $response["success"] = 0;
           $response["client_code"] = $row["counter_code"];

           $response["message"] = "inactive";


        }
    }

        }
        else {
                  $response["success"] = -1;
                  $response["message"] = "client Not registered..!  : ".$AppID;
        }
        
  
    }
    else
    {
        $response["message"] = "No Data for app id";
    }
    
    $conn->close();
    echo json_encode($response);
?>