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

$other_service_charges->df = ($data->df) ? $data->df : "";
$other_service_charges->dt = ($data->dt) ? $data->dt : "";
$other_service_charges->ym = ($data->ym)  ? $data->ym : "";
$other_service_charges->r = $data->r;
$other_service_charges->st = $data->st;

if($other_service_charges->ym){
    $stmt = $other_service_charges->searchMonthlyDetailAdmin();
}else{
    $stmt = $other_service_charges->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( 
            "date" => ($d)?$d:"",	
            "description" => ($ii)?$ii:"",	
            "particular" => ($particular)?$particular:"",	
			"amount" => number_format($p, 2, '.', '')
        );  
        $total_amountF += $p ;
        array_push($arr["records"], $detail);
    }

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