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

// Fetch data for report
$query = "SELECT * FROM assets ORDER BY date DESC";
$result = $conn->query($query);

// Start HTML output for PDF
$html = '
<!DOCTYPE html>
<html>
<head>
    <title>Assets Report</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 40px; }
        h1 { color: #3a57e8; text-align: center; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th, td { border: 1px solid #ddd; padding: 10px; text-align: left; }
        th { background-color: #3a57e8; color: white; }
        .total-row { font-weight: bold; background-color: #f5f7ff; }
        .footer { margin-top: 30px; text-align: right; font-size: 12px; color: #666; }
    </style>
</head>
<body>
    <h1>Assets Report</h1>
    <p>Generated on: ' . date('F j, Y') . '</p>
    
    <table>
        <thead>
            <tr>
                <th>Description</th>
                <th>Amount</th>
                <th>Date Added</th>
            </tr>
        </thead>
        <tbody>';

$total = 0;
while ($row = $result->fetch_assoc()) {
    $html .= '
            <tr>
                <td>' . htmlspecialchars($row['description']) . '</td>
                <td>$' . number_format($row['amount'], 2) . '</td>
                <td>' . $row['date'] . '</td>
            </tr>';
    $total += $row['amount'];
}

$html .= '
            <tr class="total-row">
                <td colspan="2">Total Asset Value</td>
                <td>$' . number_format($total, 2) . '</td>
            </tr>
        </tbody>
    </table>
    
    <div class="footer">
        <p>Report generated by EduConnect</p>
    </div>
</body>
</html>';

// For actual PDF generation, you would use a library like Dompdf or TCPDF
// This is a simplified version that outputs HTML that can be printed or converted

// Output the HTML
echo $html;

// Close connection
$conn->close();
?>