<?php
include('../../includes/config.php');
try {
    $conn->begin_transaction();

    $stmt = $conn->prepare("INSERT INTO sales_transactions (store_id, total_amount, vat_total, discount_total, payment_method, sold_by, created_at, receipt_number, customer_name, amount_paid, transaction_type, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'sale', 'completed')");
    $store_id = 1;
    $total_amount = 100.00;
    $total_vat = 15.00;
    $total_discount = 5.00;
    $payment_method = 'cash';
    $sold_by = 1;
    $created_at = date('Y-m-d H:i:s');
    $receipt_number = 'TEST-001';
    $customer_name = 'Test Customer';
    $amount_paid = 100.00;

    $stmt->bind_param("idddsisssd", $store_id, $total_amount, $total_vat, $total_discount, $payment_method, $sold_by, $created_at, $receipt_number, $customer_name, $amount_paid);
    $stmt->execute();
    $sale_id = $stmt->insert_id;
    $stmt->close();

    $conn->commit();
    echo json_encode(['success' => true, 'sale_id' => $sale_id]);
} catch (Exception $e) {
    $conn->rollback();
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
?>
