<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
session_start();
include_once '../config/database.php';
include_once '../objects/sales.php';
date_default_timezone_set('Asia/Rangoon'); 

$database = new Database();
$db = $database->getConnection();

$sales = new Sales($db);
$data = json_decode(file_get_contents("php://input"));

$sales->y = $data->y;
$sales->yy = $data->y . '-';
$sales->month = $data->ym;

$container_di = array();
$container_i = array();
$container_e = array();
$container_ii = array();
$container_ee = array();
$container_ie = array();

$amountF = $examountF  = 0;

$arr=array();

$stmt = $sales->getInOut();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    extract($row);
    $d=array(
        $sales_date
    );

    $i=array(
        (int)$amount
    );

    $e=array(
        (int)$examount
    );

    $amountF += $amount ;
    $examountF += $examount ;
    // array_push($item_name_container, $item_name);
    array_push($container_di, $d);
    array_push($container_i, $i);
    array_push($container_e, $e);
}


$arr=array(
    "container_di" => $container_di,
    "container_i" => $container_i,
    "container_e" => $container_e,
    "container_ii" => number_format($amountF),
    "container_ee" => number_format($examountF),
    "container_ie" => number_format($amountF-$examountF),

);

echo json_encode($arr);

?>