<?php
// required headers
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");

include_once '../config/database.php';
include_once '../objects/sales.php';
date_default_timezone_set('Asia/Rangoon');
session_start();
$database = new Database();
$db = $database->getConnection();
 
$sales = new Sales($db);
$data = json_decode(file_get_contents("php://input"));

$sales->df = $data->df;
$sales->dt = $data->dt;
$sales->city = $data->city;
$sales->r = $data->r;
$sales->st = explode(" - ",$data->st)[0];
$sales->st_p_type = explode(" - ",$data->st)[1];
// $sales->t = $data->t;
$sales->accounting_view = isset($_SESSION['accounting_view'])?$_SESSION['accounting_view']:"";

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

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

$total_amountF = 0;

if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
        $detail=array( 
            // "id" => $id,
            "date" => ($d)?$d:"",	
            "description" => ($ii)?$ii:"",	
            "particular" => ($particular)?$particular:"",  
			"amount" => number_format($p)
        );  
        $total_amountF += $p ;
        array_push($arr["records"], $detail);
    }

}
$arr["total_amountF"] = number_format($total_amountF);
echo json_encode($arr);
?>