<?php
header('Content-Type: application/json');

// $con = mysqli_connect("localhost", "root", "", "jibran84_ach");

$con=mysqli_connect("localhost", "jibran84_itc70kk", "Smartest1", "jibran84_cms");

// SELECT DAYNAME(created_at), COUNT(*)
// FROM new_invoice 
// WHERE DATE(created_at ) > DATE_SUB( CURDATE( ) , INTERVAL 1 WEEK ) 
// GROUP BY DAYNAME(created_at)
// ORDER BY created_at

if( isset($_GET['decline'])){
    $sqlQuery = "SELECT MONTHNAME(dates) as month, COUNT(user_status.status) as total
FROM user_status
join new_invoice on new_invoice.id = user_status.user_id
WHERE DATE(new_invoice.dates ) > DATE_SUB( CURDATE( ) , INTERVAL 1 YEAR )
and user_status.status = 'Decline'
GROUP BY MONTHNAME(new_invoice.dates)
ORDER BY new_invoice.dates";
}else{
$sqlQuery = "SELECT MONTHNAME(dates) as month, COUNT(*) as total
FROM new_invoice 
WHERE DATE(dates ) > DATE_SUB( CURDATE( ) , INTERVAL 1 YEAR ) 
GROUP BY MONTHNAME(dates)
ORDER BY dates";
}
$result = mysqli_query($con,$sqlQuery);

$data = array();
foreach ($result as $row) {
	$data[] = $row;
}

mysqli_close($con);

  echo json_encode($data);
?>
