<?php
declare(strict_types=1);
require_once __DIR__ . '/../helpers.php';
$userId = as_int((string)($_GET['user_id'] ?? '0'));
require_user($userId);
$conn = db();
$sql = "SELECT DATE_FORMAT(sale_datetime, '%Y-%m-%d') AS sale_date, COALESCE(SUM(total_amount), 0) AS total_amount, COUNT(*) AS total_orders FROM sales WHERE " . sales_active_where_sql('sales') . " AND sale_datetime >= DATE_SUB(CURDATE(), INTERVAL 6 DAY) GROUP BY DATE(sale_datetime) ORDER BY sale_date DESC";
$result = $conn->query($sql);
$data = [];
while ($row = $result->fetch_assoc()) $data[] = $row;
respond(['success' => true, 'data' => $data]);
