<?php
include 'includes/config.php';

header('Content-Type: application/json');
$data = json_decode(file_get_contents('php://input'), true);

$id = $data['id'] ?? null;
$source = $data['source'] ?? null;

if ($id && $source) {
    try {
        $table = ($source === 'bank_debit_amount') ? 'bank_debit_amount' : 'supplier_purchase_manual';

        $stmt = $conn->prepare("DELETE FROM $table WHERE id = :id");
        $stmt->execute(['id' => $id]);

        echo json_encode(['success' => true]);
    } catch (Exception $e) {
        echo json_encode(['success' => false, 'message' => $e->getMessage()]);
    }
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid request data.']);
}
?>
