<?php
// books_income_del.php
require_once 'functions.php';
checkLogin(); // Security check
$conn = connect();

if(isset($_GET['inc_id'])){
    // Sanitize the ID to prevent SQL Injection
    $inc_id = (int)$_GET['inc_id'];

    // Optional: Check permissions (e.g., only Admin can delete)
    if(isset($_SESSION['log_delete']) && $_SESSION['log_delete'] == '1'){
        
        $sql = "DELETE FROM incomes WHERE inc_id = $inc_id";
        
        if(mysqli_query($conn, $sql)){
            // Success: Return to Finance page
            header("Location: finance.php?tab=DR&msg=deleted");
        } else {
            die("Error deleting record: " . mysqli_error($conn));
        }
    } else {
        // Permission denied
        echo "<script>alert('You do not have permission to delete records.'); window.location='finance.php?tab=DR';</script>";
    }
} else {
    header("Location: finance.php?tab=DR");
}
?>