<?php
require_once "../config.php";

$query = "
    SELECT 
        cnomer,
        dtanggal,
        cnoorder,
        ckdcust,
        cnmcust,
        dtglorder,
        etglexpired,
        nnominal,
        cjnsbiaya,
        cnoid,
        clinkpembayaran,
        cstatuspembayaran
    FROM tbpiutang
    ORDER BY dtanggal ASC, cnomer DESC
";

$result = $conn->query($query);

$data_rows = [];
if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $data_rows[] = $row;
    }
}

echo json_encode($data_rows);
?>
