<?php
/**
 * SAC 2026 - BILL PAYMENTS HISTORY ENGINE v1.0
 * Kernel V4.0.90
 */
require_once 'config.php';

if (!isset($_SESSION['user_id'])) response(["error" => "No autorizado"], 401);

try {
    $sql = "
        SELECT 
            p.*, 
            b.provider, 
            b.description as bill_desc
        FROM pending_bill_payments p
        JOIN pending_bills b ON p.bill_id = b.id
        ORDER BY p.payment_date DESC, p.id DESC
    ";

    $stmt = $pdo->query($sql);
    $data = $stmt->fetchAll();
    
    response(["success" => true, "data" => $data]);

} catch (PDOException $e) {
    response(["error" => "Error de auditoría de egresos: " . $e->getMessage()], 500);
}
?>