<?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/sales.php';
date_default_timezone_set('Asia/Rangoon');
session_start();
$database = new Database();
$db = $database->getConnection();
 
$sales = new Sales($db);   

$sales->city = $_GET['city'];
$stmt = $sales->getAllIDNoRenew();
$num = $stmt->rowCount();

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

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

        $edate = $end_date;
        $rsdate = date('Y-m-d', strtotime("+1 days", strtotime($edate)));

        $sales->id_no =  $id_no;

        $detail=array(
            ++$i,
            $id_no,
            $cname,
            $phone,
            $package,
            $end_dates,
            $customer_id,
            $installation_address,
            $mbps,
            $days,
            number_format($price),
            $customer_status,
            $end_dates,
            ($mdp)?$mdp:0,
            ($mid)?$mid:0,
            $member_type,
            $invoice_no,
            $bal
            // number_format($sales->getCurrentBalance())
            // $city,

            // $rsdate
            // $sales_no
        );
        array_push($arr["data"], $detail);
    }
}
echo json_encode($arr);
?>