<?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_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);

$customer->status = $_GET['status'];
$customer->city = $_GET['city'];
$customer->date = date("Y-m-d");

if($customer->status=='activate'){
    $stmt = $customer->getToActivate();
}else if($customer->status=='deactivate'){
    $stmt = $customer->getToDeActivate();
}else if($customer->status=='terminate'){
    $stmt = $customer->getToTerminate();
}else if($customer->status=='package_change'){
    $stmt = $customer->getToPackageChange();
}

$num = $stmt->rowCount();

$arr = array();
$arr["data"] = array();
$i = 0;

if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
        $detail = array(
            ++$i,
            $invoice_no,
            $id_no,
            $name,
            $phone,
            $package,
            $start_date,
            ($end_date)?$end_date:"",
            $customer_id

        );
        array_push($arr["data"], $detail);
    }
}

echo json_encode($arr);
?>