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

$expense->df = isset($_GET['df']) ? $_GET['df'] : null;
$expense->dt = isset($_GET['dt']) ? $_GET['dt'] : null;
$expense->account_type = isset($_GET['account_type']) ? $_GET['account_type'] : null;
$expense->account_code = isset($_GET['account_code']) ? $_GET['account_code'] : null;

$stmt = $expense->search();
$num = $stmt->rowCount();

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

$net_amount = 0;
if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
        $detail = array(
			$id,
            $date,
            $voucher_no,
            $type,
            $account_code,
			$ah,
            $particular,
            ($quantity),
            ($price),
            number_format(round(($quantity*$price), 2), 2, '.', ''),
	        $remark,
        );
        $net_amount += $quantity*$price;

        array_push($arr["records"], $detail);
    }
    $arr["net_amount"] = ($net_amount);

}
echo json_encode($arr);
?>