<?php

// array for JSON response
$response = array();
require_once __DIR__ . '/db_config.php';
$response["tickets"]= array();
if (isset($_POST["companyname"]) && isset($_POST["Assignedto"])) {
    
 $companyname = $_POST['companyname'];
 $Assignedto = $_POST['Assignedto'];

 $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());
  
$query = "SELECT ticketnumber,customername,atmid,source,priority,createddateandtime,assigneddateandtime,questionorcallreason,ticketstatus FROM tickets WHERE ( companyname = '$companyname' AND Assignedto = '$Assignedto' AND rejectedby != '$Assignedto'  AND  ( ticketstatus = 'assigned' OR  ticketstatus = 'underprogress' OR  ticketstatus = 'Complete' OR  ticketstatus = 'Incomplete' ) ) order by assigneddateandtime DESC ";

    
$result=mysqli_query($con,$query);
    if(!empty($result) && mysqli_num_rows($result) > 0){
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            array_push($response["tickets"], $row);
        }
    $response["s"] = 1;
    }else{
            $response["s"] = 2;
    }

}else {
    $response["s"] = 0;
}
    echo json_encode($response);




?>