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

try {
    $stmt = $pdo->query("
        SELECT ct.*, ca.account_name, cc.category_name_bn 
        FROM cash_transactions ct
        JOIN cash_accounts ca ON ct.cash_account_id = ca.id
        JOIN cash_categories cc ON ct.category_id = cc.id
        ORDER BY ct.id DESC LIMIT 50
    ");
    echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
} catch (Exception $e) {
    echo json_encode([]);
}
