<?php
require_once __DIR__ . '/../config/database.php';
session_start();
header('Content-Type: application/json');

if (!isset($_SESSION['user_id'])) {
    echo json_encode(['success' => false, 'message' => 'Not authenticated']);
    exit;
}

$input = json_decode(file_get_contents('php://input'), true);
if (!$input) { $input = $_POST; }

// Store held sale in session
if (!isset($_SESSION['held_sales'])) {
    $_SESSION['held_sales'] = [];
}

$_SESSION['held_sales'][] = [
    'date' => date('Y-m-d H:i:s'),
    'items' => $input['items'] ?? [],
    'customer_id' => $input['customer_id'] ?? null,
    'discount_type' => $input['discount_type'] ?? 'Percentage',
    'discount_value' => $input['discount_value'] ?? 0,
    'tax_type' => $input['tax_type'] ?? 'Percentage',
    'tax_value' => $input['tax_value'] ?? 0,
];

echo json_encode(['success' => true]);
