<?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/installation.php';
session_start();
$database = new Database();
$db = $database->getConnection();
 
$installation = new Installation($db);   

$installation->city =isset($_GET['city'])?$_GET['city']:"-";
$stmt = $installation->getDeviceForSales();

$num = $stmt->rowCount();

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

$i = 0;
$s = "";
$status="";

if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);

        // if($status==0){
        //     $s = "New Device";
        // }else if($status==3){
        //     $s = "Terminate Device";
        // }

        $detail=array(
            ++$i,
            $id_no,
            $customer_name,
            $phone,
            $member_type,
            $install_address,
            $customer_id,
            $member_discount,
            $member_install_discount
            
        );
        array_push($arr["data"], $detail);
    }
}
echo json_encode($arr);
?>