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

// Check if 'user' exists in the $_SESSION array, and set a default value if not found
$user = isset($_SESSION['user']) ? $_SESSION['user'] : 'DefaultUser';

// Check for the HTTP request method
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
    // Build the SQL query to get all products
    $sql = "SELECT amount_received, payment_method, phone_number, seller_date, seller_name, total, trans_id, table_name
            FROM transaction_receipts
            WHERE seller_name='$user' AND amount_received < total";

    // Execute the query and fetch the results
    $result = $conn->query($sql);
    $data = [];

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

    // Return the data as JSON
    header('Content-Type: application/json');
    echo json_encode($data);
}
?>
