<?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_once '../config/database.php';
include_once '../objects/customer.php';
date_default_timezone_set('Asia/Rangoon');
session_start();
$database = new Database();
$db = $database->getConnection();
 
$customer = new Customer($db);
$data = json_decode(file_get_contents("php://input"));

// $ont->expire_date = $data->expire_date;   
$customer->city = $data->city;   
$customer->name = $data->name;
$customer->phone = $data->phone;
// $customer->id_no = $data->id_no;


$stmt = $customer->search();
$num = $stmt->rowCount();

$arr=array();
$arr["records"]=array();

if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
        $detail=array( 
            "id" => $id,
            // "sales_no" => $sales_no,
            // "id_no" => $id_no,
            "name" => ($name)?$name:"",
            "member_type" => ($member_type)?$member_type:"",
            "phone" => ($phone)?$phone:"",
            "nrc" => ($nrc)?$nrc:"",
            "address" => ($address)?$address:""
            // "package" => ($package)?$package:"",
            // "end_date" => ($end_date)?$end_date:"",	
			// "balance" => number_format($balance)
        );  
        array_push($arr["records"], $detail);
    }
}
echo json_encode($arr);
?>