This commit is contained in:
Flatlogic Bot 2026-02-15 01:22:25 +00:00
parent bb0b464262
commit 2c1612942a
9 changed files with 1369 additions and 1029 deletions

193
employees.php Normal file
View File

@ -0,0 +1,193 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
$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 (!$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) {
$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';
?>
<div class="container-fluid py-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold mb-0">Employees</h2>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addEmployeeModal">+ New Employee</button>
</div>
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
Employee record successfully created.
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="card border-0 shadow-sm">
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead class="bg-light">
<tr>
<th>Name</th>
<th>Position</th>
<th>Teams</th>
<th>Wage</th>
<th>Access</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($employeeList)): ?>
<tr><td colspan="6" class="text-center py-5 text-muted">No employees found.</td></tr>
<?php endif; ?>
<?php foreach ($employeeList as $e): ?>
<tr>
<td><strong><?= htmlspecialchars($e['first_name'] . ' ' . $e['last_name']) ?></strong></td>
<td class="small text-muted"><?= htmlspecialchars($e['position']) ?></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">Edit</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Modal -->
<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>
<?php include __DIR__ . '/includes/footer.php'; ?>

202
expenses.php Normal file
View File

@ -0,0 +1,202 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
$tenant_id = 1;
// 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
if (!empty($_FILES['attachments']['name'][0])) {
foreach ($_FILES['attachments']['tmp_name'] as $key => $tmp_name) {
if ($_FILES['attachments']['error'][$key] === UPLOAD_ERR_OK) {
$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 (!is_dir('uploads')) mkdir('uploads', 0775, true);
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]);
}
}
}
}
$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: expenses.php?success=1");
exit;
}
}
// Fetch Data
$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();
$projects = db()->prepare("SELECT id, name FROM projects WHERE tenant_id = ? ORDER BY name");
$projects->execute([$tenant_id]);
$projectList = $projects->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();
$pageTitle = "SR&ED Manager - Expenses";
include __DIR__ . '/includes/header.php';
?>
<div class="container-fluid py-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold mb-0">Expenses</h2>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addExpenseModal">+ Add Expense</button>
</div>
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
Expense successfully logged.
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="card border-0 shadow-sm">
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead class="bg-light">
<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 if (empty($expenseList)): ?>
<tr><td colspan="6" class="text-center py-5 text-muted">No expenses found.</td></tr>
<?php endif; ?>
<?php foreach ($expenseList as $ex): ?>
<tr>
<td class="text-muted"><?= $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 mb-1" style="height: 6px; width: 100px;">
<div class="progress-bar bg-info" role="progressbar" style="width: <?= $ex['allocation_percent'] ?>%"></div>
</div>
<small class="extra-small text-muted"><?= (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>
<!-- Modal -->
<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>
<option value="">Select Project...</option>
<?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>
<option value="">Select Supplier...</option>
<?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 mb-3">
<label class="form-label small fw-bold">Receipts</label>
<input type="file" name="attachments[]" class="form-control" multiple>
</div>
<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="submit" name="add_expense" class="btn btn-primary px-4">Log Expense</button>
</div>
</form>
</div>
</div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>

35
includes/footer.php Normal file
View File

@ -0,0 +1,35 @@
<footer class="py-4 mt-auto border-top bg-white">
<div class="container-fluid">
<div class="d-flex align-items-center justify-content-between small text-muted">
<div>&copy; <?= date('Y') ?> SR&ED Manager ERP</div>
<div>
<a href="#" class="text-decoration-none text-muted me-3">Privacy Policy</a>
<a href="#" class="text-decoration-none text-muted">Terms of Service</a>
</div>
</div>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
// Smooth scroll for anchors
document.querySelectorAll('a[href^="index.php#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const url = new URL(this.href);
if (window.location.pathname.endsWith('index.php') || window.location.pathname === '/') {
e.preventDefault();
const targetId = url.hash.substring(1);
const targetElement = document.getElementById(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
}
});
});
</script>
</body>
</html>

66
includes/header.php Normal file
View File

@ -0,0 +1,66 @@
<?php
/**
* Global Header with Static Navigation
*/
$currentPage = basename($_SERVER['PHP_SELF']);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= $pageTitle ?? 'SR&ED Manager' ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="assets/css/custom.css?v=<?= time() ?>" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
.nav-link.active {
color: #3b82f6 !important;
border-bottom: 2px solid #3b82f6;
}
</style>
</head>
<body>
<div class="container-fluid py-3 bg-white">
<a class="navbar-brand fs-3" href="index.php">SR&ED MANAGER</a>
</div>
<nav class="navbar navbar-expand-lg sticky-top border-top">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<a class="nav-link <?= $currentPage === 'index.php' ? 'active' : '' ?>" href="index.php">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $currentPage === 'projects.php' ? 'active' : '' ?>" href="projects.php">Projects</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $currentPage === 'labour.php' ? 'active' : '' ?>" href="labour.php">Labour</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $currentPage === 'expenses.php' ? 'active' : '' ?>" href="expenses.php">Expenses</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $currentPage === 'employees.php' ? 'active' : '' ?>" href="employees.php">Employees</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $currentPage === 'reports.php' ? 'active' : '' ?>" href="reports.php">Reports</a>
</li>
<li class="nav-item">
<a class="nav-link <?= $currentPage === 'settings.php' ? 'active' : '' ?>" href="settings.php">Settings</a>
</li>
</ul>
<div class="d-flex align-items-center text-muted small">
<span class="me-3">Tenant: <strong>Acme Research</strong></span>
<span class="badge bg-light text-dark border">Global Admin</span>
</div>
</div>
</div>
</nav>

1127
index.php

File diff suppressed because it is too large Load Diff

208
labour.php Normal file
View File

@ -0,0 +1,208 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
$tenant_id = 1;
// Handle Add Labour
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_labour'])) {
$project_id = (int)($_POST['project_id'] ?? 0);
$employee_id = (int)($_POST['employee_id'] ?? 0);
$entry_date = $_POST['entry_date'] ?? date('Y-m-d');
$hours = (float)($_POST['hours'] ?? 0);
$labour_type_id = (int)($_POST['labour_type_id'] ?? 0);
$evidence_type_id = (int)($_POST['evidence_type_id'] ?? 0);
$notes = $_POST['notes'] ?? '';
if ($project_id && $employee_id && $hours > 0) {
$stmt = db()->prepare("INSERT INTO labour_entries (tenant_id, project_id, employee_id, entry_date, hours, labour_type_id, evidence_type_id, notes) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$tenant_id, $project_id, $employee_id, $entry_date, $hours, $labour_type_id, $evidence_type_id, $notes]);
$labour_entry_id = (int)db()->lastInsertId();
// Handle File Uploads
if (!empty($_FILES['attachments']['name'][0])) {
foreach ($_FILES['attachments']['tmp_name'] as $key => $tmp_name) {
if ($_FILES['attachments']['error'][$key] === UPLOAD_ERR_OK) {
$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 (!is_dir('uploads')) mkdir('uploads', 0775, true);
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 (?, 'labour_entry', ?, ?, ?, ?, ?)");
$stmt->execute([$tenant_id, $labour_entry_id, $file_name, $file_path, $file_size, $mime_type]);
}
}
}
}
$stmt = db()->prepare("INSERT INTO activity_log (tenant_id, action, details) VALUES (?, ?, ?)");
$stmt->execute([$tenant_id, 'Labour Added', "Logged $hours hours for employee ID $employee_id"]);
header("Location: labour.php?success=1");
exit;
}
}
// Fetch Data
$labourEntries = db()->prepare("
SELECT le.*, p.name as project_name, e.name as employee_name, lt.name as labour_type, et.name as evidence_type
FROM labour_entries le
JOIN projects p ON le.project_id = p.id
JOIN employees e ON le.employee_id = e.id
LEFT JOIN labour_types lt ON le.labour_type_id = lt.id
LEFT JOIN evidence_types et ON le.evidence_type_id = et.id
WHERE le.tenant_id = ?
ORDER BY le.entry_date DESC, le.created_at DESC
");
$labourEntries->execute([$tenant_id]);
$labourList = $labourEntries->fetchAll();
$projects = db()->prepare("SELECT id, name FROM projects WHERE tenant_id = ? ORDER BY name");
$projects->execute([$tenant_id]);
$projectList = $projects->fetchAll();
$employees = db()->prepare("SELECT id, first_name, last_name FROM employees WHERE tenant_id = ? ORDER BY first_name, last_name");
$employees->execute([$tenant_id]);
$employeeList = $employees->fetchAll();
$labourTypes = db()->prepare("SELECT * FROM labour_types WHERE tenant_id = ? ORDER BY name");
$labourTypes->execute([$tenant_id]);
$labourTypeList = $labourTypes->fetchAll();
$evidenceTypes = db()->prepare("SELECT * FROM evidence_types WHERE tenant_id = ? ORDER BY name");
$evidenceTypes->execute([$tenant_id]);
$evidenceTypeList = $evidenceTypes->fetchAll();
$pageTitle = "SR&ED Manager - Labour Tracking";
include __DIR__ . '/includes/header.php';
?>
<div class="container-fluid py-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold mb-0">Labour Tracking</h2>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addLabourModal">+ Add Labour Entry</button>
</div>
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
Labour entry successfully saved.
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="card border-0 shadow-sm">
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead class="bg-light">
<tr>
<th>Date</th>
<th>Employee</th>
<th>Project</th>
<th>Hours</th>
<th>Type / Evidence</th>
<th>Notes</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($labourList)): ?>
<tr><td colspan="7" class="text-center py-5 text-muted">No labour entries found.</td></tr>
<?php endif; ?>
<?php foreach ($labourList as $l): ?>
<tr>
<td class="text-muted"><?= $l['entry_date'] ?></td>
<td><strong><?= htmlspecialchars($l['employee_name']) ?></strong></td>
<td><?= htmlspecialchars($l['project_name']) ?></td>
<td><span class="badge bg-light text-primary border"><?= number_format((float)$l['hours'], 2) ?> h</span></td>
<td>
<div class="small fw-bold"><?= htmlspecialchars($l['labour_type'] ?? 'N/A') ?></div>
<div class="extra-small text-muted"><?= htmlspecialchars($l['evidence_type'] ?? 'N/A') ?></div>
</td>
<td class="small text-muted"><?= htmlspecialchars($l['notes'] ?? '') ?></td>
<td class="text-end">
<button class="btn btn-sm btn-outline-secondary">Details</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="addLabourModal" 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 Labour Entry</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-6 mb-3">
<label class="form-label small fw-bold">Project</label>
<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']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Employee</label>
<select name="employee_id" class="form-select" required>
<option value="">Select Employee...</option>
<?php foreach ($employeeList as $e): ?>
<option value="<?= $e['id'] ?>"><?= htmlspecialchars($e['first_name'] . ' ' . $e['last_name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 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') ?>" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Hours</label>
<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">
<?php foreach ($labourTypeList as $lt): ?>
<option value="<?= $lt['id'] ?>"><?= htmlspecialchars($lt['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<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">
<?php foreach ($evidenceTypeList as $et): ?>
<option value="<?= $et['id'] ?>"><?= htmlspecialchars($et['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<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>
<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="submit" name="add_labour" class="btn btn-primary px-4">Save Entry</button>
</div>
</form>
</div>
</div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>

275
projects.php Normal file
View File

@ -0,0 +1,275 @@
<?php
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
$tenant_id = 1;
// Handle Add Project
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_project'])) {
$name = $_POST['name'] ?? '';
$code = $_POST['code'] ?? '';
$start_date = $_POST['start_date'] ?? date('Y-m-d');
$owner_id = !empty($_POST['owner_id']) ? (int)$_POST['owner_id'] : null;
$est_completion = !empty($_POST['estimated_completion_date']) ? $_POST['estimated_completion_date'] : null;
$type = $_POST['type'] ?? 'Internal';
$est_hours = (float)($_POST['estimated_hours'] ?? 0);
if ($name && $code) {
$stmt = db()->prepare("INSERT INTO projects (tenant_id, name, code, start_date, owner_id, estimated_completion_date, type, estimated_hours) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$tenant_id, $name, $code, $start_date, $owner_id, $est_completion, $type, $est_hours]);
$stmt = db()->prepare("INSERT INTO activity_log (tenant_id, action, details) VALUES (?, ?, ?)");
$stmt->execute([$tenant_id, 'Project Created', "Added project: $name ($code)"]);
header("Location: projects.php?success=1");
exit;
}
}
// Fetch Data
$search = $_GET['search'] ?? '';
$status_filter = $_GET['status'] ?? '';
$date_preset = $_GET['date_preset'] ?? '';
$start_from = $_GET['start_from'] ?? '';
$start_to = $_GET['start_to'] ?? '';
$query = "
SELECT p.*,
CONCAT(e.first_name, ' ', e.last_name) as owner_name,
COALESCE((SELECT SUM(hours) FROM labour_entries WHERE project_id = p.id), 0) as total_hours
FROM projects p
LEFT JOIN employees e ON p.owner_id = e.id
WHERE p.tenant_id = ?";
$params = [$tenant_id];
if ($search) {
$query .= " AND (p.name LIKE ? OR p.code LIKE ?)";
$params[] = "%$search%";
$params[] = "%$search%";
}
if ($status_filter) {
$query .= " AND p.status = ?";
$params[] = $status_filter;
}
if ($date_preset && $date_preset !== 'custom') {
switch ($date_preset) {
case 'today': $query .= " AND p.start_date = CURRENT_DATE"; break;
case 'this_week': $query .= " AND p.start_date >= DATE_SUB(CURRENT_DATE, INTERVAL WEEKDAY(CURRENT_DATE) DAY)"; break;
case 'last_week': $query .= " AND p.start_date >= DATE_SUB(CURRENT_DATE, INTERVAL WEEKDAY(CURRENT_DATE) + 7 DAY) AND p.start_date < DATE_SUB(CURRENT_DATE, INTERVAL WEEKDAY(CURRENT_DATE) DAY)"; break;
case 'this_month': $query .= " AND p.start_date >= DATE_FORMAT(CURRENT_DATE, '%Y-%m-01')"; break;
case 'last_month': $query .= " AND p.start_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH), '%Y-%m-01') AND p.start_date < DATE_FORMAT(CURRENT_DATE, '%Y-%m-01')"; break;
case 'this_year': $query .= " AND p.start_date >= DATE_FORMAT(CURRENT_DATE, '%Y-01-01')"; break;
case 'last_year': $query .= " AND p.start_date >= DATE_FORMAT(DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR), '%Y-01-01') AND p.start_date < DATE_FORMAT(CURRENT_DATE, '%Y-01-01')"; break;
}
} elseif ($date_preset === 'custom' && $start_from && $start_to) {
$query .= " AND p.start_date BETWEEN ? AND ?";
$params[] = $start_from;
$params[] = $start_to;
}
$query .= " ORDER BY p.created_at DESC";
$projects = db()->prepare($query);
$projects->execute($params);
$projectList = $projects->fetchAll();
$employees = db()->prepare("SELECT id, first_name, last_name FROM employees WHERE tenant_id = ? ORDER BY first_name, last_name");
$employees->execute([$tenant_id]);
$employeeList = $employees->fetchAll();
$pageTitle = "SR&ED Manager - Projects";
include __DIR__ . '/includes/header.php';
?>
<div class="container-fluid py-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="fw-bold mb-0">Projects</h2>
<div class="d-flex gap-2">
<button class="btn btn-outline-secondary" onclick="toggleFilters()"><i class="bi bi-funnel"></i> Filter</button>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProjectModal">+ New Project</button>
</div>
</div>
<?php if (isset($_GET['success'])): ?>
<div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
Project successfully created.
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
<?php endif; ?>
<div class="row position-relative">
<div class="col-12">
<div class="card border-0 shadow-sm">
<div class="table-responsive">
<table class="table align-middle mb-0">
<thead class="bg-light">
<tr>
<th>Project Name</th>
<th>Owner</th>
<th>Type</th>
<th>Hours (Logged/Est)</th>
<th>Variance</th>
<th>Status</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($projectList)): ?>
<tr><td colspan="7" class="text-center py-5 text-muted">No projects found.</td></tr>
<?php endif; ?>
<?php foreach ($projectList as $p):
$total_hours = (float)$p['total_hours'];
$est_hours = (float)$p['estimated_hours'];
$variance = $est_hours - $total_hours;
$is_over = $total_hours > $est_hours && $est_hours > 0;
?>
<tr>
<td>
<strong><?= htmlspecialchars($p['name']) ?></strong><br>
<code class="extra-small text-primary"><?= htmlspecialchars($p['code']) ?></code>
</td>
<td><small><?= htmlspecialchars($p['owner_name'] ?: 'Unassigned') ?></small></td>
<td><span class="badge bg-light text-dark border"><?= $p['type'] ?></span></td>
<td>
<span class="fw-bold <?= $is_over ? 'text-danger' : '' ?>"><?= number_format($total_hours, 1) ?></span>
<span class="text-muted">/ <?= number_format($est_hours, 1) ?></span>
</td>
<td>
<span class="fw-bold <?= $is_over ? 'text-danger' : 'text-success' ?>">
<?= ($variance >= 0 ? '+' : '') . number_format($variance, 1) ?>
</span>
</td>
<td><span class="status-badge status-<?= str_replace('_', '-', $p['status']) ?>"><?= ucfirst(str_replace('_', ' ', $p['status'])) ?></span></td>
<td class="text-end">
<button class="btn btn-sm btn-outline-secondary">Edit</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Filter Sidebar (Absolute or slide-in) -->
<div class="filter-sidebar shadow-sm" id="projectFilterSidebar" style="display:none; position: absolute; top: 0; right: 0; z-index: 1050; width: 300px;">
<div class="card border-0">
<div class="card-header bg-light d-flex justify-content-between align-items-center">
<span class="fw-bold">FILTERS</span>
<button type="button" class="btn-close" onclick="toggleFilters()"></button>
</div>
<div class="card-body">
<form method="GET">
<div class="mb-3">
<label class="form-label small fw-bold">Search</label>
<input type="text" name="search" class="form-control form-control-sm" value="<?= htmlspecialchars($search) ?>">
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Status</label>
<select name="status" class="form-select form-select-sm">
<option value="">All Statuses</option>
<option value="active" <?= $status_filter === 'active' ? 'selected' : '' ?>>Active</option>
<option value="on_hold" <?= $status_filter === 'on_hold' ? 'selected' : '' ?>>On Hold</option>
<option value="completed" <?= $status_filter === 'completed' ? 'selected' : '' ?>>Completed</option>
</select>
</div>
<div class="mb-3">
<label class="form-label small fw-bold">Start Date</label>
<select name="date_preset" class="form-select form-select-sm" onchange="handleDatePreset(this.value)">
<option value="">Any Time</option>
<option value="this_month" <?= $date_preset === 'this_month' ? 'selected' : '' ?>>This Month</option>
<option value="this_year" <?= $date_preset === 'this_year' ? 'selected' : '' ?>>This Year</option>
<option value="custom" <?= $date_preset === 'custom' ? 'selected' : '' ?>>Custom Range...</option>
</select>
</div>
<div id="customDateRange" class="<?= $date_preset === 'custom' ? '' : 'd-none' ?>">
<div class="mb-2">
<label class="form-label extra-small text-muted">From</label>
<input type="date" name="start_from" class="form-control form-control-sm" value="<?= htmlspecialchars($start_from) ?>">
</div>
<div class="mb-3">
<label class="form-label extra-small text-muted">To</label>
<input type="date" name="start_to" class="form-control form-control-sm" value="<?= htmlspecialchars($start_to) ?>">
</div>
</div>
<div class="d-grid gap-2">
<button type="submit" class="btn btn-sm btn-primary">Apply Filters</button>
<a href="projects.php" class="btn btn-sm btn-link text-decoration-none">Clear</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="addProjectModal" 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 Project</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-8 mb-3">
<label class="form-label small fw-bold">Project Name</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="col-md-4 mb-3">
<label class="form-label small fw-bold">Project Code</label>
<input type="text" name="code" class="form-control" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Project Owner</label>
<select name="owner_id" class="form-select">
<option value="">Select Owner...</option>
<?php foreach ($employeeList as $e): ?>
<option value="<?= $e['id'] ?>"><?= htmlspecialchars($e['first_name'] . ' ' . $e['last_name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 mb-3">
<label class="form-label small fw-bold">Project Type</label>
<select name="type" class="form-select">
<option value="Internal">Internal</option>
<option value="SRED">SR&ED</option>
</select>
</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">Estimated Hours</label>
<input type="number" name="estimated_hours" class="form-control" step="0.5" min="0" value="0">
</div>
</div>
</div>
<div class="modal-footer border-0">
<button type="submit" name="add_project" class="btn btn-primary px-4">Create Project</button>
</div>
</form>
</div>
</div>
</div>
<script>
function toggleFilters() {
const sidebar = document.getElementById('projectFilterSidebar');
sidebar.style.display = sidebar.style.display === 'none' ? 'block' : 'none';
}
function handleDatePreset(val) {
const custom = document.getElementById('customDateRange');
if (val === 'custom') {
custom.classList.remove('d-none');
} else {
custom.classList.add('d-none');
}
}
</script>
<?php include __DIR__ . '/includes/footer.php'; ?>

View File

@ -99,47 +99,9 @@ $labourTypes = db()->prepare("SELECT id, name FROM labour_types WHERE tenant_id
$labourTypes->execute([$tenant_id]);
$labourTypeList = $labourTypes->fetchAll();
$pageTitle = "SR&ED Manager - Reports";
include __DIR__ . '/includes/header.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SR&ED Manager - Reports</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="assets/css/custom.css?v=<?= time() ?>" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg sticky-top">
<div class="container-fluid">
<a class="navbar-brand" href="index.php">SR&ED MANAGER</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav me-auto">
<li class="nav-item"><a class="nav-link" href="index.php">Dashboard</a></li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Projects</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="index.php">List Projects</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle active" href="#" role="button" data-bs-toggle="dropdown">Reports</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="reports.php?report_type=labour_export">Labour Export</a></li>
<li><a class="dropdown-item" href="reports.php?report_type=calendar">Monthly Calendar</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid py-4">
<div class="row mb-4">
@ -365,6 +327,4 @@ $labourTypeList = $labourTypes->fetchAll();
<?php endif; ?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php include __DIR__ . '/includes/footer.php'; ?>

246
settings.php Normal file
View File

@ -0,0 +1,246 @@
<?php
/**
* Settings Page - Manage System Datasets
*/
declare(strict_types=1);
require_once __DIR__ . '/db/config.php';
$tenant_id = 1;
// Handle Form Submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
$name = $_POST['name'] ?? '';
if ($action === 'add_labour_type' && $name) {
$stmt = db()->prepare("INSERT INTO labour_types (tenant_id, name) VALUES (?, ?)");
$stmt->execute([$tenant_id, $name]);
} elseif ($action === 'add_evidence_type' && $name) {
$stmt = db()->prepare("INSERT INTO evidence_types (tenant_id, name) VALUES (?, ?)");
$stmt->execute([$tenant_id, $name]);
} elseif ($action === 'add_expense_type' && $name) {
$stmt = db()->prepare("INSERT INTO expense_types (tenant_id, name) VALUES (?, ?)");
$stmt->execute([$tenant_id, $name]);
} elseif ($action === 'add_team' && $name) {
$stmt = db()->prepare("INSERT INTO teams (tenant_id, name) VALUES (?, ?)");
$stmt->execute([$tenant_id, $name]);
} elseif ($action === 'add_supplier' && $name) {
$type = $_POST['type'] ?? 'supplier';
$contact = $_POST['contact_info'] ?? '';
$stmt = db()->prepare("INSERT INTO suppliers (tenant_id, name, type, contact_info) VALUES (?, ?, ?, ?)");
$stmt->execute([$tenant_id, $name, $type, $contact]);
}
header("Location: settings.php?success=1");
exit;
}
// Fetch all datasets
$labourTypes = db()->prepare("SELECT * FROM labour_types WHERE tenant_id = ? ORDER BY name");
$labourTypes->execute([$tenant_id]);
$labourTypeList = $labourTypes->fetchAll();
$evidenceTypes = db()->prepare("SELECT * FROM evidence_types WHERE tenant_id = ? ORDER BY name");
$evidenceTypes->execute([$tenant_id]);
$evidenceTypeList = $evidenceTypes->fetchAll();
$expenseTypes = db()->prepare("SELECT * FROM expense_types WHERE tenant_id = ? ORDER BY name");
$expenseTypes->execute([$tenant_id]);
$expenseTypeList = $expenseTypes->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();
$pageTitle = "SR&ED Manager - Settings";
include __DIR__ . '/includes/header.php';
?>
<div class="container-fluid py-4">
<div class="row">
<div class="col-12">
<div class="d-flex justify-content-between align-items-center mb-4">
<h4 class="fw-bold mb-0">System Settings & Datasets</h4>
<?php if (isset($_GET['success'])): ?>
<span class="badge bg-success">Dataset updated successfully</span>
<?php endif; ?>
</div>
<div class="row">
<!-- Labour Types -->
<div class="col-md-6 mb-4">
<div class="card h-100 border-0 shadow-sm">
<div class="card-header bg-white d-flex justify-content-between align-items-center">
<span class="fw-bold">Labour Types</span>
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#addLabourTypeModal">+ Add</button>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead><tr><th>Name</th></tr></thead>
<tbody>
<?php foreach ($labourTypeList as $item): ?>
<tr><td><?= htmlspecialchars($item['name']) ?></td></tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Evidence Types -->
<div class="col-md-6 mb-4">
<div class="card h-100 border-0 shadow-sm">
<div class="card-header bg-white d-flex justify-content-between align-items-center">
<span class="fw-bold">Evidence Types</span>
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#addEvidenceTypeModal">+ Add</button>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead><tr><th>Name</th></tr></thead>
<tbody>
<?php foreach ($evidenceTypeList as $item): ?>
<tr><td><?= htmlspecialchars($item['name']) ?></td></tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Expense Types -->
<div class="col-md-6 mb-4">
<div class="card h-100 border-0 shadow-sm">
<div class="card-header bg-white d-flex justify-content-between align-items-center">
<span class="fw-bold">Expense Types</span>
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#addExpenseTypeModal">+ Add</button>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead><tr><th>Name</th></tr></thead>
<tbody>
<?php foreach ($expenseTypeList as $item): ?>
<tr><td><?= htmlspecialchars($item['name']) ?></td></tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Teams -->
<div class="col-md-6 mb-4">
<div class="card h-100 border-0 shadow-sm">
<div class="card-header bg-white d-flex justify-content-between align-items-center">
<span class="fw-bold">Teams</span>
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#addTeamModal">+ Add</button>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead><tr><th>Name</th></tr></thead>
<tbody>
<?php foreach ($teamList as $item): ?>
<tr><td><?= htmlspecialchars($item['name']) ?></td></tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Suppliers -->
<div class="col-12 mb-4">
<div class="card border-0 shadow-sm">
<div class="card-header bg-white d-flex justify-content-between align-items-center">
<span class="fw-bold">Suppliers & Contractors</span>
<button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" data-bs-target="#addSupplierModal">+ Add</button>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Contact Info</th>
</tr>
</thead>
<tbody>
<?php foreach ($supplierList as $item): ?>
<tr>
<td><strong><?= htmlspecialchars($item['name']) ?></strong></td>
<td><span class="badge bg-light text-dark border"><?= ucfirst($item['type']) ?></span></td>
<td><small class="text-muted"><?= htmlspecialchars($item['contact_info'] ?? '') ?></small></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Modals -->
<?php
$modals = [
['id' => 'addLabourTypeModal', 'title' => 'Add Labour Type', 'action' => 'add_labour_type'],
['id' => 'addEvidenceTypeModal', 'title' => 'Add Evidence Type', 'action' => 'add_evidence_type'],
['id' => 'addExpenseTypeModal', 'title' => 'Add Expense Type', 'action' => 'add_expense_type'],
['id' => 'addTeamModal', 'title' => 'Add Team', 'action' => 'add_team'],
];
foreach ($modals as $m):
?>
<div class="modal fade" id="<?= $m['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"><?= $m['title'] ?></h5><button type="button" class="btn-close" data-bs-dismiss="modal"></button></div>
<form method="POST">
<div class="modal-body">
<input type="hidden" name="action" value="<?= $m['action'] ?>">
<div class="mb-3">
<label class="form-label small fw-bold">Name</label>
<input type="text" name="name" class="form-control" placeholder="Enter name..." required>
</div>
</div>
<div class="modal-footer border-0"><button type="submit" class="btn btn-primary px-4">Add Item</button></div>
</form>
</div>
</div>
</div>
<?php endforeach; ?>
<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">
<input type="hidden" name="action" value="add_supplier">
<div class="mb-3">
<label class="form-label small fw-bold">Name</label>
<input type="text" name="name" class="form-control" placeholder="Company name" 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</option>
<option value="contractor">Contractor</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="Address, Phone, Email..."></textarea>
</div>
</div>
<div class="modal-footer border-0"><button type="submit" class="btn btn-primary px-4">Add Supplier</button></div>
</form>
</div>
</div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>