<?php
	// required headers
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");
	 
	// include database and object files
	include_once '../config/database.php';
	include_once '../objects/sales.php';
	// include_once '../objects/sales.php';
	date_default_timezone_set('Asia/Rangoon'); 
	session_start();
	// instantiate database
	$database = new Database();
	$db = $database->getConnection();
	 
	$sales = new Sales($db);
	// $sales = new Sales($db);

	$stmt = $sales->getTotalMbpsList();
	$num = $stmt->rowCount();
	$arr=array();
	$arr["records"]=array();

	if($num>0){
        $c_countT=$totalT=$removeT=$total_cT=0;
		$i=1;
		while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
			extract($row);
                $item=array(
					"no" => $i++,
                    "city" => $city,
                    "c_count" => number_format($total_customer),
                    "remove_device" => number_format($re_device),
                    "total" => number_format($total_mbps)
                );
                $c_countT += $total_customer;
                $removeT += $re_device;
                $totalT += $total_mbps;
                array_push($arr["records"], $item);      
		}
        $arr["c_countT"] = number_format($c_countT);
        $arr["removeT"] = number_format($removeT);
        $arr["totalT"] = number_format($totalT);
	}



	echo json_encode($arr);
?>