388 lines
20 KiB
PHP
388 lines
20 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
// Simulate Tenant Context (Hardcoded for demo)
|
|
$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');
|
|
|
|
if ($name && $code) {
|
|
$stmt = db()->prepare("INSERT INTO projects (tenant_id, name, code, start_date) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([$tenant_id, $name, $code, $start_date]);
|
|
|
|
// Log Activity
|
|
$stmt = db()->prepare("INSERT INTO activity_log (tenant_id, action, details) VALUES (?, ?, ?)");
|
|
$stmt->execute([$tenant_id, 'Project Created', "Added project: $name ($code)"]);
|
|
|
|
header("Location: index.php?success=1");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// 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) {
|
|
$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 (?, 'labour_entry', ?, ?, ?, ?, ?)");
|
|
$stmt->execute([$tenant_id, $labour_entry_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, 'Labour Added', "Logged $hours hours for employee ID $employee_id"]);
|
|
|
|
header("Location: index.php?success=labour");
|
|
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->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();
|
|
|
|
$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();
|
|
|
|
$activities = db()->prepare("SELECT * FROM activity_log WHERE tenant_id = ? ORDER BY created_at DESC LIMIT 10");
|
|
$activities->execute([$tenant_id]);
|
|
$activityList = $activities->fetchAll();
|
|
|
|
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'SR&ED Project Tracking Software';
|
|
?>
|
|
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>SR&ED Manager - Dashboard</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<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">
|
|
</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 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="#" data-bs-toggle="modal" data-bs-target="#addProjectModal">Add Project</a></li>
|
|
<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" href="#" role="button" data-bs-toggle="dropdown">Labour</a>
|
|
<ul class="dropdown-menu">
|
|
<li><a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#addLabourModal">Add Labour</a></li>
|
|
<li><a class="dropdown-item" href="#labour-section">List Labour</a></li>
|
|
</ul>
|
|
</li>
|
|
<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>
|
|
</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="#">Roles</a></li>
|
|
</ul>
|
|
</li>
|
|
<li class="nav-item dropdown">
|
|
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Reports</a>
|
|
<ul class="dropdown-menu">
|
|
<li><a class="dropdown-item" href="#">Labour Summary</a></li>
|
|
<li><a class="dropdown-item" href="#">Project Expenses</a></li>
|
|
<li><a class="dropdown-item" href="#">SR&ED Claim Export</a></li>
|
|
</ul>
|
|
</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>
|
|
|
|
<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.' ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span>Active Projects</span>
|
|
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addProjectModal">+ New Project</button>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Project Name</th>
|
|
<th>Code</th>
|
|
<th>Start Date</th>
|
|
<th>Status</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($projectList as $p): ?>
|
|
<tr>
|
|
<td><strong><?= htmlspecialchars($p['name']) ?></strong></td>
|
|
<td><code class="text-primary"><?= htmlspecialchars($p['code']) ?></code></td>
|
|
<td><?= $p['start_date'] ?></td>
|
|
<td><span class="status-badge status-<?= $p['status'] ?>"><?= ucfirst($p['status']) ?></span></td>
|
|
<td class="text-end">
|
|
<button class="btn btn-sm btn-outline-secondary">Edit</button>
|
|
</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>
|
|
</div>
|
|
|
|
<div class="card mb-4" id="labour-section">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span>Recent Labour Entries</span>
|
|
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addLabourModal">+ Add Labour</button>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table align-middle">
|
|
<thead>
|
|
<tr>
|
|
<th>Date</th>
|
|
<th>Employee</th>
|
|
<th>Project</th>
|
|
<th>Hours</th>
|
|
<th>Type / Evidence</th>
|
|
<th class="text-end">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($labourList as $l): ?>
|
|
<tr>
|
|
<td><?= $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="text-end">
|
|
<button class="btn btn-sm btn-outline-secondary">Details</button>
|
|
</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>
|
|
|
|
<!-- Activity Hub -->
|
|
<div class="col-lg-3">
|
|
<div class="card">
|
|
<div class="card-header">Activity Hub</div>
|
|
<div class="card-body p-3">
|
|
<ul class="activity-feed">
|
|
<?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="activity-time mt-1"><?= date('M d, H:i', strtotime($a['created_at'])) ?></div>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add Project Modal -->
|
|
<div class="modal fade" id="addProjectModal" tabindex="-1">
|
|
<div class="modal-dialog modal-dialog-centered">
|
|
<div class="modal-content border-0">
|
|
<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="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>
|
|
</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>
|
|
</div>
|
|
<div class="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>
|
|
<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>
|
|
</div>
|
|
</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-header">
|
|
<h5 class="modal-title fw-bold">Add Labour Tracking</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']) ?> (<?= htmlspecialchars($p['code']) ?>)</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['name']) ?> (<?= htmlspecialchars($e['position']) ?>)</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">Time (Hours)</label>
|
|
<input type="number" name="hours" class="form-control" step="0.25" min="0.25" placeholder="e.g. 7.5" 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; ?>
|
|
</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">
|
|
<option value="">Select Evidence Type...</option>
|
|
<?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 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>
|
|
</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>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|