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

$conn = new mysqli("localhost", "root", "", "tsakane");

$sql = "SELECT DAY(salesDate) AS dia,SUM(productTotal) AS total FROM vendas
WHERE productStatus = 'vendido' AND MONTH(salesDate) = MONTH(CURDATE())
AND YEAR(salesDate) = YEAR(CURDATE()) GROUP BY DAY(salesDate) ORDER BY dia";

$result = $conn->query($sql);
$dias = [];
$totais = [];

while ($row = $result->fetch_assoc()) {
    $dias[]   = $row['dia'];
    $totais[] = (float)$row['total'];
}

echo json_encode([
    'dias'   => $dias,
    'totais' => $totais
]);
?>