<?php
	// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");    
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/customer.php';
	// include_once '../objects/sales.php';
	date_default_timezone_set('Asia/Rangoon'); 
	session_start();
	// instantiate database
	$database = new Database();
	$db = $database->getConnection();
	 
	$customer = new Customer($db);
	$data = json_decode(file_get_contents("php://input"));
	// $sales = new Sales($db);

	$customer->city =isset($_GET['city'])?$_GET['city']:"-";
	
	$stmt = $customer->getUnsalesCustomer();
	$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,
				(int)$id,
				($name)?$name:"",
				($phone)?$phone:"",
				($member_type)?$member_type:"",
				($nrc)?$nrc:"",
				($address)?$address:"",
				(int)$member_discount,
				(int)$member_install_discount
			);
			$i++;
			array_push($arr["data"], $item);
		}
	 

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