<?php
session_start();
require_once "db.php";

header('Content-Type: application/json');

try {

    if (!isset($_POST['doc_no'])) {
        echo json_encode([
            'status' => 'error',
            'message' => 'Missing document number'
        ]);
        exit;
    }

    $doc_no = trim($_POST['doc_no']);

    $stmt = $pdo->prepare("
        UPDATE transactions
        SET t_status = 'Confirmed'
        WHERE t_doc_no = ?
    ");

    $stmt->execute([$doc_no]);

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

} catch (PDOException $e) {

    echo json_encode([
        'status' => 'error',
        'message' => $e->getMessage()
    ]);
}
?>