<?php
include "../../../src/config.php";

if (!auth::user()) {
    endrequest("You dont have access to this api");
}

if (!isset($_GET["year"])) {
    endrequest("Invalid request");
}

$query  = "SELECT DAYOFYEAR(received) as day, DATE_FORMAT(received,'%b') as month, day(received) as date, count(*) as count FROM `mis_letters` where year (received) = :year group by received";

$response = database::query($query, ["year" => $_GET["year"]]);

echo json_encode($response);
