prepare("INSERT INTO users (tenant_id, name, email, phone, password, require_password_change, role) VALUES (?, ?, ?, ?, ?, ?, 'staff') ON DUPLICATE KEY UPDATE phone = VALUES(phone), password = COALESCE(VALUES(password), password), require_password_change = VALUES(require_password_change)"); $stmt->execute([$tenant_id, "$first_name $last_name", $email, $phone, $hashed_password, $force_password_change]); $stmt = db()->prepare("SELECT id FROM users WHERE email = ? AND tenant_id = ?"); $stmt->execute([$email, $tenant_id]); $user_id = (int)($stmt->fetchColumn() ?: null); } $stmt = db()->prepare("INSERT INTO employees (tenant_id, first_name, last_name, email, phone, position, start_date, is_limited, user_id, name) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$tenant_id, $first_name, $last_name, $email, $phone, $position, $start_date, $is_limited, $user_id, "$first_name $last_name"]); $employee_id = (int)db()->lastInsertId(); if ($initial_wage > 0) { $stmt = db()->prepare("INSERT INTO employee_wages (tenant_id, employee_id, hourly_rate, effective_date) VALUES (?, ?, ?, ?)"); $stmt->execute([$tenant_id, $employee_id, $initial_wage, $start_date]); } if (!empty($team_ids)) { foreach ($team_ids as $tid) { $stmt = db()->prepare("INSERT INTO employee_teams (tenant_id, employee_id, team_id) VALUES (?, ?, ?)"); $stmt->execute([$tenant_id, $employee_id, $tid]); } } $stmt = db()->prepare("INSERT INTO activity_log (tenant_id, action, details) VALUES (?, ?, ?)"); $stmt->execute([$tenant_id, 'Employee Created', "Added employee: $first_name $last_name"]); header("Location: employees.php?success=1"); exit; } } // Fetch Data $stmt = db()->prepare("SELECT pref_key, pref_value FROM system_preferences WHERE tenant_id = ?"); $stmt->execute([$tenant_id]); $prefs = $stmt->fetchAll(PDO::FETCH_KEY_PAIR); $employees = db()->prepare(" SELECT e.*, (SELECT hourly_rate FROM employee_wages WHERE employee_id = e.id ORDER BY effective_date DESC LIMIT 1) as current_wage FROM employees e WHERE e.tenant_id = ? ORDER BY e.first_name, e.last_name "); $employees->execute([$tenant_id]); $employeeList = $employees->fetchAll(); $teams = db()->prepare("SELECT * FROM teams WHERE tenant_id = ? ORDER BY name"); $teams->execute([$tenant_id]); $teamList = $teams->fetchAll(); $pageTitle = "SR&ED Manager - Employees"; include __DIR__ . '/includes/header.php'; ?>

Employees

Name Position Teams Wage Access Actions
No employees found.
prepare("SELECT t.name FROM teams t JOIN employee_teams et ON t.id = et.team_id WHERE et.employee_id = ?"); $e_teams->execute([$e['id']]); $t_names = $e_teams->fetchAll(PDO::FETCH_COLUMN); foreach ($t_names as $tn) { echo '' . htmlspecialchars($tn) . ''; } ?> $/h View