<?php
include '../includes/config.php';

	$id = $_POST['id'];
	$betdate = $_POST['betdate'];

	$sql = "SELECT * , SUM(betting_amount) as amt , COUNT(betting_id) as cont FROM betting WHERE b_market_id='$id' AND Date(betting_date)=Date('$betdate') ORDER BY betting_id DESC";

	$qry = mysqli_query($conn,$sql);
	$row = mysqli_fetch_assoc($qry);
    $betamt = $row['amt'];


    $sql1 = "SELECT * , SUM(transaction_amount) as amt , COUNT(w_transaction_id) as cont FROM `wallet_transaction` WHERE transaction_type='WinningBat' AND Date(transaction_update_date)=Date('$betdate') AND market_id ='$id' ";

	$qry1 = mysqli_query($conn,$sql1);
	$row1 = mysqli_fetch_assoc($qry1);
    $winamt = $row1['amt'];

    $totalamt = $betamt - $winamt;

    if ($totalamt > 0) {
    	$type = "Profit";
    }elseif($totalamt == 0){
    	$type = "Noloss";
    }else{
    	$type = "Loss";
    }

    $data['data'] = array(
		"betamt" =>$betamt,
		"winamt" =>$winamt,
		"totalamt" =>$totalamt,
		"type" =>$type,
	);

echo json_encode($data);

?>


