<?php
	// required headers
	header("Access-Control-Allow-Origin: *");
	header("Content-Type: application/json; charset=UTF-8");
	header("Access-Control-Allow-Methods: POST");
	 
	// include database and object files
	include_once '../config/database.php';
	include_once '../objects/sales.php';
	date_default_timezone_set('Asia/Rangoon'); 
	// instantiate database
	$database = new Database();
	$db = $database->getConnection();
	 
	// initialize object
	$sales = new Sales($db);
	$data = json_decode(file_get_contents("php://input"));
	$sales->today_date = date("Y-m-d");

	$stmt = $sales->getTodayForIndex();
	$num = $stmt->rowCount();

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

	if($num>0){
		while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
			extract($row);
			$arr["today_purchase"] = number_format($today_purchase,0);
			$arr["today_sales"] = number_format($today_sales,0);
			$arr["today_income"] = number_format($today_income,0);
			$arr["today_expense"] = number_format($today_expense,0);
			// $detail=array(
			// 	"today_purchase" => number_format($today_purchase,2),
			// 	"today_sales" => number_format($today_sales,2),
			// 	"today_income" => number_format($today_income,2),
			// 	"today_expense" => number_format($today_expense,2),

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