<?php
require "api/config/database.php";
require "api/helpers/Response.php";
require "api/helpers/Validator.php";
require "api/helpers/UUID.php";
require "api/services/AccountingService.php";
require "api/helpers/AuditLogger.php";
require "api/controllers/PurchaseController.php";

try {
    $db = Database::connect();
    $ctrl = new PurchaseController($db, (object)["id" => 1]);
    $stmt = $db->query("SELECT id FROM purchase_master ORDER BY id DESC LIMIT 1");
    $id = $stmt->fetchColumn();
    if ($id) {
        $ctrl->reverse($id);
        echo "SUCCESSFULLY REVERSED ID " . $id;
    } else {
        echo "NO PURCHASES FOUND";
    }
} catch (Throwable $e) {
    echo "ERROR: " . $e->getMessage() . " at " . $e->getFile() . ":" . $e->getLine();
}

