<?php
// Include the database connection
include 'db_connection.php';

function getTotalIncome($conn) {
    $query = "SELECT SUM(amount) AS total_income FROM income";
    $result = $conn->query($query);
    $row = $result->fetch_assoc();
    return $row['total_income'];
}

function getTotalExpenses($conn) {
    $query = "SELECT SUM(amount) AS total_expenses FROM expenses";
    $result = $conn->query($query);
    $row = $result->fetch_assoc();
    return $row['total_expenses'];
}

$totalIncome = getTotalIncome($conn);
$totalExpenses = getTotalExpenses($conn);
$netIncome = $totalIncome - $totalExpenses;

?>

<!DOCTYPE html>
<html>
<head>
    <title>Generate Report</title>
    <link rel="stylesheet" type="text/css" href="#">
    <style type="text/css">
    body {
    font-family: Arial, sans-serif;
}

h2 {
    text-align: center;
}

form {
    width: 300px;
    margin: 0 auto;
}

label {
    display: block;
    margin: 10px 0 5px;
}

input[type="text"], input[type="number"], input[type="date"], input[type="file"] {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
}

input[type="submit"] {
    width: 100%;
    padding: 10px;
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
}

table {
    width: 80%;
    margin: 20px auto;
    border-collapse: collapse;
}

th, td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

th {
    background-color: #4CAF50;
    color: white;
}

    </style>
</head>
<body>
    <h2>Income and Expenditure Report</h2>
    <p>Total Income: <?php echo $totalIncome; ?></p>
    <p>Total Expenses: <?php echo $totalExpenses; ?></p>
    <p>Net Income: <?php echo $netIncome; ?></p>
</body>
</html>
