<?php
//delete_contribution.php
include 'db_connect.php';

$contribution_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$partner_id = isset($_GET['partner_id']) ? intval($_GET['partner_id']) : 0;
$agreement_id = isset($_GET['agreement_id']) ? intval($_GET['agreement_id']) : 0;
$month_year = isset($_GET['month_year']) ? htmlspecialchars($_GET['month_year']) : '';

if ($contribution_id === 0 || $partner_id === 0 || $agreement_id === 0 || empty($month_year)) {
    die("Invalid request. Contribution ID, Partner ID, Agreement ID, and Month/Year are required.");
}

// Ensure only related contribution is deleted
$sql = "
    DELETE FROM Financial_Contributions
    WHERE contribution_id = ? AND partner_id = ? AND agreement_id = ?
";
$stmt = $conn->prepare($sql);
$stmt->bind_param("iii", $contribution_id, $partner_id, $agreement_id);

if ($stmt->execute() && $stmt->affected_rows > 0) {
    // Redirect back to details page with success flag
    header("Location: individual_partner_details.php?partner_id=$partner_id&agreement_id=$agreement_id&month_year=" . urlencode($month_year) . "&deleted=1");
    exit;
} else {
    // Redirect back with failure flag
    header("Location: individual_partner_details.php?partner_id=$partner_id&agreement_id=$agreement_id&month_year=" . urlencode($month_year) . "&deleted=0");
    exit;
}

$stmt->close();
$conn->close();
?>






