<?php
// Database connection
require_once 'shikanisha.kts.php';

$sql = "SELECT
    `seller_name`,
    SUM(`total`) AS `total_sales`,
    SUM(`amount_received`) AS `cash_at_hand`,
    (SUM(`total`) - SUM(`amount_received`)) AS `debt`
FROM
    `transaction_receipts`
WHERE
    `seller_date` >= CONCAT(CURDATE(), ' 06:00:00') AND
    `seller_date` < CONCAT(CURDATE() + INTERVAL 1 DAY, ' 05:00:00')
GROUP BY
    `seller_name`";

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

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

echo json_encode($salesData);

$conn->close();
?>
