<?php
/**
 * Test Statutory Save Functionality
 * This page helps test if the save is working
 */

require_once __DIR__ . '/includes/init.php';
requireLogin();

$db = getDB();
$siteId = getCurrentSiteId();

// Get one employee for testing
$stmt = $db->prepare("SELECT employee_id, employee_code, first_name, last_name, pan_number, aadhar_number, remarks FROM employees WHERE site_id = ? LIMIT 1");
$stmt->execute([$siteId]);
$testEmployee = $stmt->fetch(PDO::FETCH_ASSOC);

?>
<!DOCTYPE html>
<html>
<head>
    <title>Test Statutory Save</title>
    <style>
        body { font-family: Arial; padding: 20px; }
        .form-group { margin: 10px 0; }
        label { display: inline-block; width: 150px; }
        input, textarea { padding: 5px; width: 300px; }
        button { padding: 10px 20px; background: #007bff; color: white; border: none; cursor: pointer; }
        .result { margin-top: 20px; padding: 15px; border-radius: 5px; }
        .success { background: #d4edda; color: #155724; }
        .error { background: #f8d7da; color: #721c24; }
    </style>
</head>
<body>
    <h2>Test Statutory Save</h2>
    
    <?php if ($testEmployee): ?>
        <p><strong>Testing with Employee:</strong> <?php echo htmlspecialchars($testEmployee['first_name'] . ' ' . $testEmployee['last_name']); ?> (ID: <?php echo $testEmployee['employee_id']; ?>)</p>
        
        <form method="POST" action="modules/employee/new_joinee_statutory.php">
            <input type="hidden" name="employee_id" value="<?php echo $testEmployee['employee_id']; ?>">
            
            <div class="form-group">
                <label>PAN Number:</label>
                <input type="text" name="pan_no_<?php echo $testEmployee['employee_id']; ?>" 
                       value="<?php echo htmlspecialchars($testEmployee['pan_number'] ?? ''); ?>" 
                       placeholder="Enter PAN">
            </div>
            
            <div class="form-group">
                <label>Aadhar Number:</label>
                <input type="text" name="aadhar_<?php echo $testEmployee['employee_id']; ?>" 
                       value="<?php echo htmlspecialchars($testEmployee['aadhar_number'] ?? ''); ?>" 
                       placeholder="Enter Aadhar">
            </div>
            
            <div class="form-group">
                <label>Remarks:</label>
                <textarea name="remarks_<?php echo $testEmployee['employee_id']; ?>" 
                          placeholder="Enter remarks"><?php echo htmlspecialchars($testEmployee['remarks'] ?? ''); ?></textarea>
            </div>
            
            <button type="submit" name="save_statutory">Test Save</button>
        </form>
        
        <div class="result">
            <h3>Current Values in Database:</h3>
            <p><strong>PAN:</strong> <?php echo htmlspecialchars($testEmployee['pan_number'] ?? 'NULL'); ?></p>
            <p><strong>Aadhar:</strong> <?php echo htmlspecialchars($testEmployee['aadhar_number'] ?? 'NULL'); ?></p>
            <p><strong>Remarks:</strong> <?php echo htmlspecialchars($testEmployee['remarks'] ?? 'NULL'); ?></p>
        </div>
    <?php else: ?>
        <p class="error">No employees found. Please add an employee first.</p>
    <?php endif; ?>
    
    <p><a href="modules/employee/new_joinee_statutory.php">Go to New Joinee Statutory</a></p>
</body>
</html>

