<?php 
include 'db.php'; 
$id = $_GET['id']; 

// Get employee details
$emp = $conn->query("SELECT * FROM employees WHERE id=$id")->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
    <title>Payment History - <?= $emp['name'] ?></title>
       <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        table { border-collapse: collapse; width: 100%; }
        th, td { border: 1px solid #ddd; padding: 8px; }
        th { background: #f2f2f2; }
    </style>
</head>
<body>
    <h2>Payment History for <?= $emp['name'] ?></h2>
    <p><b>Email:</b> <?= $emp['email'] ?> | <b>Phone:</b> <?= $emp['phone'] ?> | <b>Status:</b> <?= $emp['status'] ?></p>
    <p><b>Position:</b> <?= $emp['position'] ?> | <b>Date Joined:</b> <?= $emp['date_joined'] ?> | <b>Date Left:</b> <?= $emp['date_left'] ?></p>

 <a href="payment_add.php">Make Payment</a> | 
<a href="payment_list.php">All Payments</a> | 
<a href="index.php">Employee List</a> | 
<a href="payment_history_pdf.php?id=<?= $id ?>" target="_blank">Export PDF</a>
    <br><br>

    <table>
        <tr>
            <th>ID</th><th>Amount</th><th>Payment Date</th><th>Method</th><th>Remarks</th><th>Created At</th>
        </tr>
        <?php
        $sql = "SELECT * FROM payments WHERE employee_id=$id ORDER BY id DESC";
        $result = $conn->query($sql);
        $total = 0;
        while($row = $result->fetch_assoc()):
            $total += $row['amount'];
        ?>
        <tr>
            <td><?= $row['id'] ?></td>
            <td><?= number_format($row['amount'],2) ?></td>
            <td><?= $row['payment_date'] ?></td>
            <td><?= $row['method'] ?></td>
            <td><?= $row['remarks'] ?></td>
            <td><?= $row['created_at'] ?></td>
        </tr>
        <?php endwhile; ?>
        <tr>
            <th colspan="6" style="text-align:right;">Total Paid: <?= number_format($total,2) ?></th>
        </tr>
    </table>
</body>
</html>