```php prepare("SELECT SUM(total_amount) as total_sales FROM orders WHERE created_at BETWEEN ? AND ?"); $stmt->execute([$start_date, $end_date]); $total_sales = $stmt->fetch(PDO::FETCH_ASSOC); // Top products $stmt = $pdo->prepare(" SELECT p.name, SUM(oi.quantity) as total_sold, SUM(oi.quantity * oi.unit_price) as revenue FROM order_items oi JOIN products p ON oi.product_id = p.id JOIN orders o ON oi.order_id = o.id WHERE o.created_at BETWEEN ? AND ? GROUP BY p.id ORDER BY total_sold DESC LIMIT 5 "); $stmt->execute([$start_date, $end_date]); $top_products = $stmt->fetchAll(PDO::FETCH_ASSOC); // Report data $report = array( 'total_sales' => $total_sales['total_sales'] ?? 0, 'start_date' => $start_date, 'end_date' => $end_date, 'top_products' => $top_products ); echo json_encode($report); } ?> ``` You'll also need to create the database tables. Here's the SQL schema: