<?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 . '-';

$container_io_d = array();
$container_io_i = array();
$container_io_e = array();
$container_io_pl = array();

$incomeF = $expenseF = $plF = 0;

$arr=array();

$stmt = $sales->getINOutProfitAll();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    extract($row);
    $d=array(
        $d
    );
    $i=array(
        (int)$amount
    );
    $e=array(
        (int)$examount
    );
    $pl=array(
        (int)($amount-$examount)
    );
    $incomeF += $amount ;
    $expenseF += $examount ;
    $plF += ($amount-$examount) ;
    // array_push($item_name_container, $item_name);
    array_push($container_io_d, $d);
    array_push($container_io_i, $i);
    array_push($container_io_e, $e);
    array_push($container_io_pl, $pl);
}

$arr=array(

    "container_io_d" => $container_io_d,
    "container_io_i" => $container_io_i,
    "container_io_e" => $container_io_e,
    "container_io_pl" => $container_io_pl,
    "container_io_income" => number_format($incomeF),
    "container_io_expense" => number_format($expenseF),
    "container_io_profitloss" => number_format($plF),


);

echo json_encode($arr);

?>