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

$transfer->city = $data->city;
$transfer->date = $data->date;

$stmt = $transfer->getAllRows();
$num = $stmt->rowCount();

$arr=array();
$arr["records"]=array();
if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
        $detail = array(
			"id" => $id,
			"city" => $city,
            "voucher_no" => $voucher_no,
			"transfer_reason" => $transfer_reason,
            "particular" => $particular,
	        "transfer_by" => $transfer_by,
	        "date" => $date,
            "transfer_to" => $transfer_to,
	        "amount" => number_format($amount),
            "quantity" => number_format($quantity),
            "total_amount" => number_format($quantity*$amount)
        );
        $net_amount += $quantity*$amount;

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

}
echo json_encode($arr);
?>