<?php
require_once 'db_connect.php';

header('Content-Type: application/json');

if (isset($_GET['employee_id']) && !empty($_GET['employee_id'])) {
    $employee_id = intval($_GET['employee_id']);
    try {
        $stmt = $conn->prepare("SELECT salary FROM employees WHERE id = :id");
        $stmt->execute([':id' => $employee_id]);
        $employee = $stmt->fetch(PDO::FETCH_ASSOC);
        if ($employee) {
            echo json_encode(['status' => 'success', 'salary' => $employee['salary']]);
        } else {
            echo json_encode(['status' => 'error', 'message' => 'موظف غير موجود']);
        }
    } catch (PDOException $e) {
        error_log("Error fetching salary: " . $e->getMessage());
        echo json_encode(['status' => 'error', 'message' => 'حدث خطأ']);
    }
} else {
    echo json_encode(['status' => 'error', 'message' => 'معرف الموظف مطلوب']);
}
exit();