<?php
require_once '../../config.php';
require_once ROOT . 'app/db.php';

$daireID = isset($_GET['daireID']) ? (int)$_GET['daireID'] : 0;

$sql = "
SELECT *,
    CASE 
    WHEN durum='BORÇ' THEN CONCAT(
        '<button class=\"btn btn-sm btn-success odemeBtn\" data-borc=\"', ID, '\" data-tutar=\"', tutar, '\" data-kategori=\"', kategori, '\">  &#128179; Öde</button>'
    )
    ELSE CONCAT(
        '<button class=\"btn btn-sm btn-warning iptalBtn\" data-odeme=\"', ID, '\">↩️ İptal</button>'
    )
END AS actions
FROM tb_borc
WHERE daireID = ?
ORDER BY gercek_odeme_tarihi DESC, odeme_tarihi DESC
";

$liste = db::execAll($sql, [$daireID]);

echo json_encode(["data" => $liste]);
