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

$income->date = $data->date;

$stmt = $income->getAllRows();
$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" => $iid,
            "date" => $date,
            "voucher_no" => $voucher_no,
            "type" => $type,
			"account_code" => $account_code,
            "account_head" => $ah,
            "particular" => $particular,
            "quantity" => ($quantity),
            "price" => ($price),
            "total_amount" => ($quantity*$price),
	        "remark" => $remark,
            
        );
        $net_amount += $quantity*$price;

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

}
echo json_encode($arr);
?>