const Database = require('better-sqlite3');
const path = require('path');
const dbPath = path.join(__dirname, '../data/school.db');
const db = new Database(dbPath);

console.log('--- TESTING UPDATED REVENUE QUERY ---');

try {
  const revenue = db.prepare(`
    SELECT 
      strftime('%m', payment_date) as month,
      COALESCE(SUM(amount), 0) as revenue,
      COALESCE((SELECT SUM(amount) FROM expenses WHERE strftime('%m', expense_date) = strftime('%m', p.payment_date) AND is_deleted = 0), 0) as expenses
    FROM payments p
    WHERE payment_date >= date('now', '-6 months') AND is_deleted = 0
    GROUP BY month
    ORDER BY payment_date ASC
  `).all();
  console.log('Revenue query result:', revenue);
} catch (err) {
  console.error('Error:', err.message);
}
