<?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/bank_in_out.php';
	date_default_timezone_set('Asia/Rangoon'); 
	session_start();
	
	$database = new Database();
	$db = $database->getConnection();
	 
	$bank_in_out = new BankInOut($db);
	$data = json_decode(file_get_contents("php://input"));
	

	// $bank_in_out->city =isset($_GET['city'])?$_GET['city']:"-";
	$bank_in_out->city = $data->city;
	$stmt = $bank_in_out->getAllRows();
	$num = $stmt->rowCount();
	$arr=array();
	$arr["data"]=array();
	$balance = $in_total = $out_total = $b_total = 0;
	if($num>0){
			$i=1;

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

			$balance += $in_amount;
			$balance -= $out_amount;
    		
			$item=array(
				"i" =>$i,
				"date" =>($date)?$date:"",
				"description" =>($description)?$description:"",
				"in_amount" => ($in_amount !== null) ? number_format($in_amount, 2, '.', ',') : "",
				"out_amount" =>($out_amount !== null) ? number_format($out_amount, 2, '.', ',') : "",
				"balance" =>($balance !== null) ? number_format($balance, 2, '.', ',') : "",
				"remark" =>($remark)?$remark:"",
				"id" =>(int)$id
			);
			$i++;
			$in_total += $in_amount ;
			$out_total += $out_amount ;
			$b_total += $in_amount - $out_amount ;
			array_push($arr["data"], $item);
		}
	 

	}
	// array_push($arr["sales_no"], $sales->getGenerateSalesNo(date("ymd")));
	$arr["in_total"] = number_format($in_total, 2, '.', ',') ;
	$arr["out_total"] = number_format($out_total, 2, '.', ',');
	$arr["b_total"] = number_format($b_total, 2, '.', ',');
	echo json_encode($arr);
?>