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

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

$coid  = $_SESSION['co_id'];
$user_id   = $_SESSION['user_id'];

try {

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

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

    $stmt = $pdo->prepare("
        UPDATE transactions
        SET t_status = 'Deleted', t_conf_by = ?, t_conf_date=Now()
        WHERE t_id = ? AND co_id = ? AND t_type= ?
    ");

    $stmt->execute([$user_id, $doc_no, $coid, $t_type]);

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

} catch (PDOException $e) {

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