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

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

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

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

$totalAssets = getTotalAssets($conn);
$totalLiabilities = getTotalLiabilities($conn);
$totalEquity = getTotalEquity($conn);

?>

<!DOCTYPE html>
<html>
<head>
    <title>Balance Sheet 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>Balance Sheet Report</h2>
    <p>Total Assets (Total Liabilities+Total Equity): <?php echo $totalAssets; ?></p>
    <p>Total Liabilities: <?php echo $totalLiabilities; ?></p>
    <p>Total Equity: <?php echo $totalEquity; ?></p>
    <p>Net Worth: <?php echo $totalAssets - $totalLiabilities; ?></p>
</body>
</html>
