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

	$sales->city = isset($_SESSION['city'])?$_SESSION['city']:"";

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

	if($num>0){
        $total_mbps=0;
		$i=1;
		while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
			extract($row);
                $item=array(
					"no" => $i++,
                    "mbps" => $mbps,
                    "c_count" => $c_count,
                    "total" => number_format((int)$mbps * (int)$c_count)
                );
                $total_mbps += $mbps * $c_count;
                array_push($arr["records"], $item);      
		}
        $arr["total_mbps"] = number_format($total_mbps);
	}

	echo json_encode($arr);
?>