diff --git a/employees.php b/employees.php new file mode 100644 index 0000000..28bc60b --- /dev/null +++ b/employees.php @@ -0,0 +1,193 @@ +prepare("INSERT IGNORE INTO users (tenant_id, name, email, role) VALUES (?, ?, ?, 'staff')"); + $stmt->execute([$tenant_id, "$first_name $last_name", $email]); + $user_id = (int)db()->lastInsertId(); + if ($user_id === 0) { + $stmt = db()->prepare("SELECT id FROM users WHERE email = ?"); + $stmt->execute([$email]); + $user_id = (int)($stmt->fetchColumn() ?: null); + } + } + + $stmt = db()->prepare("INSERT INTO employees (tenant_id, first_name, last_name, email, position, start_date, is_limited, user_id, name) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$tenant_id, $first_name, $last_name, $email, $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 +$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'; +?> + +
| Name | +Position | +Teams | +Wage | +Access | +Actions | +
|---|---|---|---|---|---|
| No employees found. | |||||
| = htmlspecialchars($e['first_name'] . ' ' . $e['last_name']) ?> | += htmlspecialchars($e['position']) ?> | ++ 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) . ''; + } + ?> + | +$= number_format((float)($e['current_wage'] ?? 0), 2) ?>/h | += $e['is_limited'] ? 'Limited' : 'Regular' ?> | ++ + | +
| Date | +Supplier | +Project | +Amount | +Allocation | +Actions | +
|---|---|---|---|---|---|
| No expenses found. | |||||
| = $ex['entry_date'] ?> | +
+ = htmlspecialchars($ex['supplier_name']) ?> + = htmlspecialchars($ex['expense_type'] ?? '') ?> + |
+ = htmlspecialchars($ex['project_name']) ?> | +$= number_format((float)$ex['amount'], 2) ?> | +
+
+
+
+ = (float)$ex['allocation_percent'] ?>% SR&ED
+ |
+ + + | +