<?php
session_start();
include('db_connection.php');

if (!isset($_SESSION['teacher_id']) || $_SESSION['role'] !== 'teacher') {
    header("Location: teacher_login.php");
    exit();
}

$teacher_id = $_SESSION['teacher_id'];

$sql = "SELECT id, pay_month, pay_year, net_salary, salary, absent_days, payment_date
        FROM payrolls
        WHERE teacher_id = ?
        ORDER BY pay_year DESC, pay_month DESC";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $teacher_id);
$stmt->execute();
$result = $stmt->get_result();
$payslips = $result->fetch_all(MYSQLI_ASSOC);
$stmt->close();
?>