<?php
require_once '../config/database.php';
header('Content-Type: application/json');

// Ambil data 7 hari terakhir
$query = "SELECT transaction_date, SUM(total_profit) as profit 
          FROM transactions 
          GROUP BY transaction_date 
          ORDER BY transaction_date ASC LIMIT 7";

$stmt = $pdo->query($query);
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($data);