employees

This commit is contained in:
Flatlogic Bot 2026-02-15 00:26:46 +00:00
parent a2a711f887
commit f03a7a8de5
3 changed files with 592 additions and 32 deletions

View File

@ -0,0 +1,48 @@
-- Table for Suppliers/Contractors
CREATE TABLE IF NOT EXISTS suppliers (
id INT AUTO_INCREMENT PRIMARY KEY,
tenant_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
type ENUM('supplier', 'contractor') DEFAULT 'supplier',
contact_info TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX (tenant_id)
);
-- Table for Expense Types (Company editable list)
CREATE TABLE IF NOT EXISTS expense_types (
id INT AUTO_INCREMENT PRIMARY KEY,
tenant_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX (tenant_id)
);
-- Table for Expenses
CREATE TABLE IF NOT EXISTS expenses (
id INT AUTO_INCREMENT PRIMARY KEY,
tenant_id INT NOT NULL,
project_id INT NOT NULL,
supplier_id INT NOT NULL,
expense_type_id INT NOT NULL,
amount DECIMAL(15, 2) NOT NULL,
allocation_percent DECIMAL(5, 2) DEFAULT 100.00,
entry_date DATE NOT NULL,
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (project_id) REFERENCES projects(id),
FOREIGN KEY (supplier_id) REFERENCES suppliers(id),
FOREIGN KEY (expense_type_id) REFERENCES expense_types(id),
INDEX (tenant_id)
);
-- Insert some default data for the demo tenant (tenant_id = 1)
INSERT INTO suppliers (tenant_id, name, type, contact_info) VALUES
(1, 'Cloud Services Inc.', 'supplier', 'billing@cloudservices.com'),
(1, 'John Doe Consulting', 'contractor', 'john@doe.com');
INSERT INTO expense_types (tenant_id, name) VALUES
(1, 'Materials'),
(1, 'Subcontractors'),
(1, 'Software Licenses'),
(1, 'Overhead');

View File

@ -0,0 +1,50 @@
-- Migration for Enhanced Employee Management
-- 1. Alter employees table to add required fields
ALTER TABLE employees ADD COLUMN first_name VARCHAR(100) AFTER tenant_id;
ALTER TABLE employees ADD COLUMN last_name VARCHAR(100) AFTER first_name;
ALTER TABLE employees ADD COLUMN start_date DATE AFTER position;
ALTER TABLE employees ADD COLUMN is_limited BOOLEAN DEFAULT TRUE AFTER start_date;
ALTER TABLE employees ADD COLUMN user_id INT NULL AFTER is_limited;
ALTER TABLE employees ADD CONSTRAINT fk_employee_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
-- Migrate existing names to first/last (rough split)
UPDATE employees SET first_name = SUBSTRING_INDEX(name, ' ', 1), last_name = SUBSTRING_INDEX(name, ' ', -1) WHERE name LIKE '% %';
UPDATE employees SET first_name = name, last_name = '' WHERE name NOT LIKE '% %';
-- 2. Wage History Table
CREATE TABLE IF NOT EXISTS employee_wages (
id INT AUTO_INCREMENT PRIMARY KEY,
tenant_id INT NOT NULL,
employee_id INT NOT NULL,
hourly_rate DECIMAL(10, 2) NOT NULL,
effective_date DATE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE,
FOREIGN KEY (employee_id) REFERENCES employees(id) ON DELETE CASCADE
);
-- 3. Teams Table
CREATE TABLE IF NOT EXISTS teams (
id INT AUTO_INCREMENT PRIMARY KEY,
tenant_id INT NOT NULL,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE
);
-- 4. Employee-Team Link (Many-to-Many)
CREATE TABLE IF NOT EXISTS employee_teams (
employee_id INT NOT NULL,
team_id INT NOT NULL,
tenant_id INT NOT NULL,
PRIMARY KEY (employee_id, team_id),
FOREIGN KEY (employee_id) REFERENCES employees(id) ON DELETE CASCADE,
FOREIGN KEY (team_id) REFERENCES teams(id) ON DELETE CASCADE,
FOREIGN KEY (tenant_id) REFERENCES tenants(id) ON DELETE CASCADE
);
-- Seed some teams
INSERT IGNORE INTO teams (tenant_id, name) VALUES (1, 'Engineering');
INSERT IGNORE INTO teams (tenant_id, name) VALUES (1, 'R&D');
INSERT IGNORE INTO teams (tenant_id, name) VALUES (1, 'Product Management');

526
index.php
View File

@ -5,6 +5,83 @@ require_once __DIR__ . '/db/config.php';
// Simulate Tenant Context (Hardcoded for demo)
$tenant_id = 1;
// Handle Add Employee
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_employee'])) {
$first_name = $_POST['first_name'] ?? '';
$last_name = $_POST['last_name'] ?? '';
$email = $_POST['email'] ?? '';
$position = $_POST['position'] ?? '';
$start_date = $_POST['start_date'] ?? date('Y-m-d');
$is_limited = isset($_POST['is_limited']) ? 1 : 0;
$initial_wage = (float)($_POST['initial_wage'] ?? 0);
$team_ids = $_POST['teams'] ?? [];
if ($first_name && $last_name) {
$user_id = null;
// If not limited, create a user account
if (!$is_limited && $email) {
$stmt = db()->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) { // Already exists
$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();
// Initial Wage
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]);
}
// Teams
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]);
}
}
// Log Activity
$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: index.php?success=employee");
exit;
}
}
// Handle Add Team
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_team'])) {
$name = $_POST['name'] ?? '';
if ($name) {
$stmt = db()->prepare("INSERT INTO teams (tenant_id, name) VALUES (?, ?)");
$stmt->execute([$tenant_id, $name]);
header("Location: index.php?success=team");
exit;
}
}
// Handle Add Wage Adjustment
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_wage'])) {
$employee_id = (int)$_POST['employee_id'];
$rate = (float)$_POST['hourly_rate'];
$effective_date = $_POST['effective_date'];
if ($employee_id && $rate > 0) {
$stmt = db()->prepare("INSERT INTO employee_wages (tenant_id, employee_id, hourly_rate, effective_date) VALUES (?, ?, ?, ?)");
$stmt->execute([$tenant_id, $employee_id, $rate, $effective_date]);
header("Location: index.php?success=wage");
exit;
}
}
// Handle Add Project
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_project'])) {
$name = $_POST['name'] ?? '';
@ -65,15 +142,90 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_labour'])) {
}
}
// Handle Add Expense
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_expense'])) {
$project_id = (int)($_POST['project_id'] ?? 0);
$supplier_id = (int)($_POST['supplier_id'] ?? 0);
$expense_type_id = (int)($_POST['expense_type_id'] ?? 0);
$amount = (float)($_POST['amount'] ?? 0);
$allocation = (float)($_POST['allocation_percent'] ?? 100);
$entry_date = $_POST['entry_date'] ?? date('Y-m-d');
$notes = $_POST['notes'] ?? '';
if ($project_id && $supplier_id && $amount > 0) {
$stmt = db()->prepare("INSERT INTO expenses (tenant_id, project_id, supplier_id, expense_type_id, amount, allocation_percent, entry_date, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$tenant_id, $project_id, $supplier_id, $expense_type_id, $amount, $allocation, $entry_date, $notes]);
$expense_id = (int)db()->lastInsertId();
// Handle File Uploads (Centralized Attachments)
if (!empty($_FILES['attachments']['name'][0])) {
foreach ($_FILES['attachments']['tmp_name'] as $key => $tmp_name) {
if (!$_FILES['attachments']['error'][$key]) {
$file_name = $_FILES['attachments']['name'][$key];
$file_size = $_FILES['attachments']['size'][$key];
$mime_type = $_FILES['attachments']['type'][$key];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
$new_file_name = uniqid() . '.' . $file_ext;
$file_path = 'uploads/' . $new_file_name;
if (move_uploaded_file($tmp_name, $file_path)) {
$stmt = db()->prepare("INSERT INTO attachments (tenant_id, entity_type, entity_id, file_name, file_path, file_size, mime_type) VALUES (?, 'expense', ?, ?, ?, ?, ?)");
$stmt->execute([$tenant_id, $expense_id, $file_name, $file_path, $file_size, $mime_type]);
}
}
}
}
// Log Activity
$stmt = db()->prepare("INSERT INTO activity_log (tenant_id, action, details) VALUES (?, ?, ?)");
$stmt->execute([$tenant_id, 'Expense Logged', "Logged \$" . number_format($amount, 2) . " expense for project ID $project_id"]);
header("Location: index.php?success=expense");
exit;
}
}
// Handle Add Supplier
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_supplier'])) {
$name = $_POST['name'] ?? '';
$type = $_POST['type'] ?? 'supplier';
$contact = $_POST['contact_info'] ?? '';
if ($name) {
$stmt = db()->prepare("INSERT INTO suppliers (tenant_id, name, type, contact_info) VALUES (?, ?, ?, ?)");
$stmt->execute([$tenant_id, $name, $type, $contact]);
header("Location: index.php?success=supplier");
exit;
}
}
// Fetch Data
$projects = db()->prepare("SELECT * FROM projects WHERE tenant_id = ? ORDER BY created_at DESC");
$projects->execute([$tenant_id]);
$projectList = $projects->fetchAll();
$employees = db()->prepare("SELECT * FROM employees WHERE tenant_id = ? ORDER BY name");
$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();
$suppliers = db()->prepare("SELECT * FROM suppliers WHERE tenant_id = ? ORDER BY name");
$suppliers->execute([$tenant_id]);
$supplierList = $suppliers->fetchAll();
$expenseTypes = db()->prepare("SELECT * FROM expense_types WHERE tenant_id = ? ORDER BY name");
$expenseTypes->execute([$tenant_id]);
$expenseTypeList = $expenseTypes->fetchAll();
$labourTypes = db()->prepare("SELECT * FROM labour_types WHERE tenant_id = ? ORDER BY name");
$labourTypes->execute([$tenant_id]);
$labourTypeList = $labourTypes->fetchAll();
@ -95,6 +247,18 @@ $labourEntries = db()->prepare("
$labourEntries->execute([$tenant_id]);
$labourList = $labourEntries->fetchAll();
$expenseEntries = db()->prepare("
SELECT e.*, p.name as project_name, s.name as supplier_name, et.name as expense_type
FROM expenses e
JOIN projects p ON e.project_id = p.id
JOIN suppliers s ON e.supplier_id = s.id
LEFT JOIN expense_types et ON e.expense_type_id = et.id
WHERE e.tenant_id = ?
ORDER BY e.entry_date DESC, e.created_at DESC
");
$expenseEntries->execute([$tenant_id]);
$expenseList = $expenseEntries->fetchAll();
$activities = db()->prepare("SELECT * FROM activity_log WHERE tenant_id = ? ORDER BY created_at DESC LIMIT 10");
$activities->execute([$tenant_id]);
$activityList = $activities->fetchAll();
@ -138,14 +302,20 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Expenses</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Add Expense</a></li>
<li><a class="dropdown-item" href="#">List Expenses</a></li>
<li><a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#addExpenseModal">Add Expense</a></li>
<li><a class="dropdown-item" href="#expense-section">List Expenses</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#addSupplierModal">Manage Suppliers</a></li>
<li><a class="dropdown-item" href="#">Expense Types</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Users</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Employees</a></li>
<li><a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#addEmployeeModal">Add Employee</a></li>
<li><a class="dropdown-item" href="#employee-section">Manage Employees</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#addTeamModal">Manage Teams</a></li>
<li><a class="dropdown-item" href="#">Roles</a></li>
</ul>
</li>
@ -168,11 +338,20 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<div class="container-fluid py-4">
<div class="row">
<!-- Main Content -->
<div class="col-lg-9">
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
<?= $_GET['success'] === 'labour' ? 'Labour entry successfully saved.' : 'Project successfully added to the tracker.' ?>
<?php
switch($_GET['success']) {
case 'labour': echo 'Labour entry successfully saved.'; break;
case 'expense': echo 'Expense successfully logged.'; break;
case 'supplier': echo 'Supplier successfully added.'; break;
case 'employee': echo 'Employee record created.'; break;
case 'team': echo 'New team created.'; break;
case 'wage': echo 'Wage adjustment recorded.'; break;
default: echo 'Action successfully completed.'; break;
}
?>
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
@ -205,9 +384,6 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($projectList)): ?>
<tr><td colspan="5" class="text-center py-5 text-muted">No projects found. Start by adding one.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
@ -246,16 +422,97 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
</td>
</tr>
<?php endforeach; ?>
<?php if (empty($labourList)): ?>
<tr><td colspan="6" class="text-center py-5 text-muted">No labour entries found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
<div class="card mb-4" id="expense-section">
<div class="card-header d-flex justify-content-between align-items-center">
<span>Recent Expenses</span>
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addExpenseModal">+ Add Expense</button>
</div>
<div class="table-responsive">
<table class="table align-middle">
<thead>
<tr>
<th>Date</th>
<th>Supplier</th>
<th>Project</th>
<th>Amount</th>
<th>Allocation</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($expenseList as $ex): ?>
<tr>
<td><?= $ex['entry_date'] ?></td>
<td><strong><?= htmlspecialchars($ex['supplier_name']) ?></strong><br><small class="text-muted"><?= htmlspecialchars($ex['expense_type'] ?? '') ?></small></td>
<td><?= htmlspecialchars($ex['project_name']) ?></td>
<td><span class="fw-bold">$<?= number_format((float)$ex['amount'], 2) ?></span></td>
<td>
<div class="progress" style="height: 6px; width: 80px;">
<div class="progress-bar bg-info" role="progressbar" style="width: <?= $ex['allocation_percent'] ?>%"></div>
</div>
<small><?= (float)$ex['allocation_percent'] ?>% SR&ED</small>
</td>
<td class="text-end">
<button class="btn btn-sm btn-outline-secondary">Details</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<div class="card mb-4" id="employee-section">
<div class="card-header d-flex justify-content-between align-items-center">
<span>Manage Employees</span>
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addEmployeeModal">+ New Employee</button>
</div>
<div class="table-responsive">
<table class="table align-middle">
<thead>
<tr>
<th>Name</th>
<th>Teams</th>
<th>Wage</th>
<th>Access</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($employeeList as $e): ?>
<tr>
<td>
<strong><?= htmlspecialchars($e['first_name'] . ' ' . $e['last_name']) ?></strong><br>
<small class="text-muted"><?= htmlspecialchars($e['position']) ?></small>
</td>
<td>
<?php
$e_teams = db()->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 '<span class="badge bg-light text-dark border me-1">' . htmlspecialchars($tn) . '</span>';
}
?>
</td>
<td><span class="fw-bold text-success">$<?= number_format((float)($e['current_wage'] ?? 0), 2) ?>/h</span></td>
<td><span class="badge <?= $e['is_limited'] ? 'bg-secondary' : 'bg-primary' ?>"><?= $e['is_limited'] ? 'Limited' : 'Regular' ?></span></td>
<td class="text-end">
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#wageHistoryModal<?= $e['id'] ?>">Wages</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Activity Hub -->
<div class="col-lg-3">
<div class="card">
<div class="card-header">Activity Hub</div>
@ -264,7 +521,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<?php foreach ($activityList as $a): ?>
<li class="activity-item">
<div class="fw-bold small"><?= htmlspecialchars($a['action']) ?></div>
<div class="text-muted extra-small" style="font-size: 0.8rem;"><?= htmlspecialchars($a['details']) ?></div>
<div class="text-muted extra-small"><?= htmlspecialchars($a['details']) ?></div>
<div class="activity-time mt-1"><?= date('M d, H:i', strtotime($a['created_at'])) ?></div>
</li>
<?php endforeach; ?>
@ -275,10 +532,10 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
</div>
</div>
<!-- Add Project Modal -->
<!-- Modals -->
<div class="modal fade" id="addProjectModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content border-0">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold">Add New Project</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
@ -287,11 +544,11 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<div class="modal-body">
<div class="mb-3">
<label class="form-label small fw-bold">Project Name</label>
<input type="text" name="name" class="form-control" placeholder="e.g. AI Optimization" required>
<input type="text" name="name" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Project Code</label>
<input type="text" name="code" class="form-control" placeholder="SR-2025-01" required>
<input type="text" name="code" class="form-control" required>
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Start Date</label>
@ -299,7 +556,6 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
</div>
</div>
<div class="modal-footer border-0">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
<button type="submit" name="add_project" class="btn btn-primary px-4">Create Project</button>
</div>
</form>
@ -307,10 +563,9 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
</div>
</div>
<!-- Add Labour Modal -->
<div class="modal fade" id="addLabourModal" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content border-0">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold">Add Labour Tracking</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
@ -323,7 +578,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<select name="project_id" class="form-select" required>
<option value="">Select Project...</option>
<?php foreach ($projectList as $p): ?>
<option value="<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?> (<?= htmlspecialchars($p['code']) ?>)</option>
<option value="<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
@ -332,7 +587,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<select name="employee_id" class="form-select" required>
<option value="">Select Employee...</option>
<?php foreach ($employeeList as $e): ?>
<option value="<?= $e['id'] ?>"><?= htmlspecialchars($e['name']) ?> (<?= htmlspecialchars($e['position']) ?>)</option>
<option value="<?= $e['id'] ?>"><?= htmlspecialchars($e['first_name'] . ' ' . $e['last_name']) ?></option>
<?php endforeach; ?>
</select>
</div>
@ -342,12 +597,11 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Time (Hours)</label>
<input type="number" name="hours" class="form-control" step="0.25" min="0.25" placeholder="e.g. 7.5" required>
<input type="number" name="hours" class="form-control" step="0.25" min="0" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Type of Labour</label>
<select name="labour_type_id" class="form-select">
<option value="">Select Type...</option>
<?php foreach ($labourTypeList as $lt): ?>
<option value="<?= $lt['id'] ?>"><?= htmlspecialchars($lt['name']) ?></option>
<?php endforeach; ?>
@ -356,7 +610,6 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Objective Evidence</label>
<select name="evidence_type_id" class="form-select">
<option value="">Select Evidence Type...</option>
<?php foreach ($evidenceTypeList as $et): ?>
<option value="<?= $et['id'] ?>"><?= htmlspecialchars($et['name']) ?></option>
<?php endforeach; ?>
@ -365,23 +618,232 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking
<div class="col-12 mb-3">
<label class="form-label small fw-bold">Attachments</label>
<input type="file" name="attachments[]" class="form-control" multiple>
<div class="extra-small text-muted mt-1">Upload relevant evidence (logs, photos, docs).</div>
</div>
<div class="col-12 mb-3">
<label class="form-label small fw-bold">Comments / Notes</label>
<textarea name="notes" class="form-control" rows="3" placeholder="Briefly describe the work done..."></textarea>
<div class="col-12">
<label class="form-label small fw-bold">Notes</label>
<textarea name="notes" class="form-control" rows="2"></textarea>
</div>
</div>
</div>
<div class="modal-footer border-0">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Cancel</button>
<button type="submit" name="add_labour" class="btn btn-primary px-4">Save Labour Entry</button>
<button type="submit" name="add_labour" class="btn btn-primary px-4">Save Labour</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="addEmployeeModal" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold">Add New Employee</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST">
<div class="modal-body">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">First Name</label>
<input type="text" name="first_name" class="form-control" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Last Name</label>
<input type="text" name="last_name" class="form-control" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Email</label>
<input type="email" name="email" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Position</label>
<input type="text" name="position" class="form-control">
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Start Date</label>
<input type="date" name="start_date" class="form-control" value="<?= date('Y-m-d') ?>">
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Hourly Wage ($)</label>
<input type="number" name="initial_wage" class="form-control" step="0.01">
</div>
<div class="col-md-12 mb-3">
<label class="form-label small fw-bold d-block">Teams</label>
<div class="row px-2">
<?php foreach ($teamList as $t): ?>
<div class="col-md-4 form-check">
<input class="form-check-input" type="checkbox" name="teams[]" value="<?= $t['id'] ?>" id="teamCheck<?= $t['id'] ?>">
<label class="form-check-label small" for="teamCheck<?= $t['id'] ?>"><?= htmlspecialchars($t['name']) ?></label>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="col-12">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" name="is_limited" id="limitedCheck" checked>
<label class="form-check-label small fw-bold" for="limitedCheck">Limited Web Reporting (Cannot Login)</label>
</div>
</div>
</div>
</div>
<div class="modal-footer border-0">
<button type="submit" name="add_employee" class="btn btn-primary px-4">Create Employee</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="addTeamModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold">Add New Team</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST">
<div class="modal-body">
<div class="mb-3">
<label class="form-label small fw-bold">Team Name</label>
<input type="text" name="name" class="form-control" required>
</div>
</div>
<div class="modal-footer border-0">
<button type="submit" name="add_team" class="btn btn-primary px-4">Create Team</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="addExpenseModal" tabindex="-1">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold">Add Expense</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST" enctype="multipart/form-data">
<div class="modal-body">
<div class="row">
<div class="col-md-12 mb-3">
<label class="form-label small fw-bold">Project</label>
<select name="project_id" class="form-select" required>
<?php foreach ($projectList as $p): ?>
<option value="<?= $p['id'] ?>"><?= htmlspecialchars($p['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Supplier</label>
<select name="supplier_id" class="form-select" required>
<?php foreach ($supplierList as $s): ?>
<option value="<?= $s['id'] ?>"><?= htmlspecialchars($s['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Cost Type</label>
<select name="expense_type_id" class="form-select">
<?php foreach ($expenseTypeList as $et): ?>
<option value="<?= $et['id'] ?>"><?= htmlspecialchars($et['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-4 mb-3">
<label class="form-label small fw-bold">Amount ($)</label>
<input type="number" name="amount" class="form-control" step="0.01" required>
</div>
<div class="col-md-4 mb-3">
<label class="form-label small fw-bold">Allocation (%)</label>
<input type="number" name="allocation_percent" class="form-control" value="100">
</div>
<div class="col-md-4 mb-3">
<label class="form-label small fw-bold">Date</label>
<input type="date" name="entry_date" class="form-control" value="<?= date('Y-m-d') ?>">
</div>
<div class="col-12">
<label class="form-label small fw-bold">Receipts</label>
<input type="file" name="attachments[]" class="form-control" multiple>
</div>
</div>
</div>
<div class="modal-footer border-0">
<button type="submit" name="add_expense" class="btn btn-primary px-4">Save Expense</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="addSupplierModal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold">Add Supplier / Contractor</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<form method="POST">
<div class="modal-body">
<div class="mb-3">
<label class="form-label small fw-bold">Name</label>
<input type="text" name="name" class="form-control" placeholder="Company or Individual" required>
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Type</label>
<select name="type" class="form-select">
<option value="supplier">Supplier (Materials/Services)</option>
<option value="contractor">Contractor (Labour)</option>
</select>
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Contact Info</label>
<textarea name="contact_info" class="form-control" rows="2" placeholder="Email, phone, or address"></textarea>
</div>
</div>
<div class="modal-footer border-0">
<button type="submit" name="add_supplier" class="btn btn-primary px-4">Save Supplier</button>
</div>
</form>
</div>
</div>
</div>
<?php foreach ($employeeList as $e): ?>
<div class="modal fade" id="wageHistoryModal<?= $e['id'] ?>" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content border-0 shadow">
<div class="modal-header">
<h5 class="modal-title fw-bold">Wage History: <?= htmlspecialchars($e['first_name']) ?></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<table class="table table-sm small">
<thead><tr><th>Rate</th><th>Date</th></tr></thead>
<tbody>
<?php
$wages = db()->prepare("SELECT * FROM employee_wages WHERE employee_id = ? ORDER BY effective_date DESC");
$wages->execute([$e['id']]);
foreach ($wages->fetchAll() as $w): ?>
<tr><td>$<?= number_format((float)$w['hourly_rate'], 2) ?>/h</td><td><?= $w['effective_date'] ?></td></tr>
<?php endforeach; ?>
</tbody>
</table>
<hr>
<form method="POST">
<input type="hidden" name="employee_id" value="<?= $e['id'] ?>">
<div class="row g-2">
<div class="col-6"><input type="number" name="hourly_rate" class="form-control form-control-sm" step="0.01" placeholder="New Rate" required></div>
<div class="col-6"><input type="date" name="effective_date" class="form-control form-control-sm" value="<?= date('Y-m-d') ?>" required></div>
<div class="col-12"><button type="submit" name="add_wage" class="btn btn-sm btn-primary w-100">Update Wage</button></div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>