<?php
	// required headers
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");
	// header("Access-Control-Allow-Methods: POST");
	header("Access-Control-Max-Age: 3600");
	header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
	 
	// include database and object files
	include_once '../config/database.php';
	include_once '../objects/complaint.php';
	// include_once '../objects/sales.php';
	date_default_timezone_set('Asia/Rangoon'); 
	session_start();
	// instantiate database
	$database = new Database();
	$db = $database->getConnection();
	 
	$complaint = new Complaint($db);
	$data = json_decode(file_get_contents("php://input"));
	// $sales = new Sales($db);

	// $complaint->city =  $data->city;
	// $complaint->df =  $data->df?$data->df:"";
	// $complaint->dt =  $data->dt?$data->dt:"";
	// $complaint->status =  $data->status?$data->status:"";
	// $complaint->id_no =  isset($data->id_no)?$data->id_no:"";
	$complaint->city = $_GET['city']; 
	$complaint->status = $_GET['status']; 
	$stmt = $complaint->getAllRows();
	$num = $stmt->rowCount();
	$arr=array();
	$arr["data"]=array();
	// $arr["sales_no"]=array();
	if($num>0){
		$i=1;

		while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
			extract($row);
			$item=array(
				$i,
				$complaint_date,
				$id_no,
				$name,
				$complaint,
				$particular,
				// $customer_id,
				($answer_date)?$answer_date:"",
				$id
				// ($answer_by)?$answer_by:"",
				// ($remark)?$remark:""
			);
			$i++;
			array_push($arr["data"], $item);
		}
	 

	}
	// array_push($arr["sales_no"], $sales->getGenerateSalesNo(date("ymd")));
	echo json_encode($arr);
?>