1145 lines
60 KiB
PHP
1145 lines
60 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
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'] ?? '';
|
|
$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]);
|
|
|
|
// 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;
|
|
}
|
|
}
|
|
|
|
// 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
|
|
$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 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();
|
|
|
|
$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();
|
|
|
|
$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();
|
|
|
|
// Fetch Chart Data
|
|
$chart_days = isset($_GET['chart_days']) ? (int)$_GET['chart_days'] : 7;
|
|
if (!in_array($chart_days, [7, 14, 30])) $chart_days = 7;
|
|
|
|
$chartDataQuery = db()->prepare("
|
|
SELECT entry_date, SUM(hours) as total_hours
|
|
FROM labour_entries
|
|
WHERE tenant_id = ? AND entry_date > DATE_SUB(CURRENT_DATE, INTERVAL ? DAY)
|
|
GROUP BY entry_date
|
|
ORDER BY entry_date ASC
|
|
");
|
|
$chartDataQuery->execute([$tenant_id, $chart_days]);
|
|
$rawChartData = $chartDataQuery->fetchAll(PDO::FETCH_KEY_PAIR);
|
|
|
|
// Fill missing dates
|
|
$chartLabels = [];
|
|
$chartValues = [];
|
|
for ($i = $chart_days - 1; $i >= 0; $i--) {
|
|
$date = date('Y-m-d', strtotime("-$i days"));
|
|
$chartLabels[] = date('M d', strtotime($date));
|
|
$chartValues[] = (float)($rawChartData[$date] ?? 0);
|
|
}
|
|
|
|
$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 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 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" 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="#" 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="#" 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>
|
|
<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="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>
|
|
<li><hr class="dropdown-divider"></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">
|
|
<!-- Dashboard Chart Section -->
|
|
<div class="row mb-4">
|
|
<div class="col-12">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-header bg-white d-flex justify-content-between align-items-center py-3">
|
|
<h5 class="mb-0 fw-bold">Labour Hours Overview</h5>
|
|
<div class="btn-group btn-group-sm">
|
|
<a href="?chart_days=7" class="btn btn-outline-primary <?= $chart_days == 7 ? 'active' : '' ?>">7 Days</a>
|
|
<a href="?chart_days=14" class="btn btn-outline-primary <?= $chart_days == 14 ? 'active' : '' ?>">14 Days</a>
|
|
<a href="?chart_days=30" class="btn btn-outline-primary <?= $chart_days == 30 ? 'active' : '' ?>">30 Days</a>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div style="height: 300px;">
|
|
<canvas id="hoursChart"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-12">
|
|
<?php if (isset($_GET['success'])): ?>
|
|
<div class="alert alert-success alert-dismissible fade show border-0 shadow-sm mb-4" role="alert">
|
|
<?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; ?>
|
|
|
|
<div class="d-flex gap-3 mb-4 position-relative">
|
|
<div class="flex-grow-1">
|
|
<div class="card h-100">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span>Active Projects</span>
|
|
<div class="d-flex gap-2">
|
|
<button class="btn btn-sm btn-outline-secondary" onclick="toggleFilters()"><i class="bi bi-funnel"></i> Filter</button>
|
|
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#addProjectModal">+ New Project</button>
|
|
</div>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table align-middle">
|
|
<thead>
|
|
<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-4 text-muted">No projects found matching the filters.</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>
|
|
|
|
<div class="filter-sidebar shadow-sm" id="projectFilterSidebar">
|
|
<div class="card filter-card">
|
|
<div class="card-header bg-light small fw-bold d-flex justify-content-between align-items-center">
|
|
<span>FILTERS</span>
|
|
<button type="button" class="btn-close extra-small" onclick="toggleFilters()"></button>
|
|
</div>
|
|
<div class="card-body p-3">
|
|
<form method="GET" id="filterForm">
|
|
<div class="mb-3">
|
|
<label class="form-label extra-small fw-bold text-uppercase text-muted">Search</label>
|
|
<input type="text" name="search" class="form-control form-control-sm" placeholder="Name or code..." value="<?= htmlspecialchars($search) ?>">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label extra-small fw-bold text-uppercase text-muted">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 extra-small fw-bold text-uppercase text-muted">Start Date</label>
|
|
<select name="date_preset" class="form-select form-select-sm" onchange="handleDatePreset(this.value)">
|
|
<option value="">Any Time</option>
|
|
<option value="today" <?= $date_preset === 'today' ? 'selected' : '' ?>>Today</option>
|
|
<option value="this_week" <?= $date_preset === 'this_week' ? 'selected' : '' ?>>This Week</option>
|
|
<option value="last_week" <?= $date_preset === 'last_week' ? 'selected' : '' ?>>Last Week</option>
|
|
<option value="this_month" <?= $date_preset === 'this_month' ? 'selected' : '' ?>>This Month</option>
|
|
<option value="last_month" <?= $date_preset === 'last_month' ? 'selected' : '' ?>>Last Month</option>
|
|
<option value="this_year" <?= $date_preset === 'this_year' ? 'selected' : '' ?>>This Year</option>
|
|
<option value="last_year" <?= $date_preset === 'last_year' ? 'selected' : '' ?>>Last 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="index.php" class="btn btn-sm btn-link text-decoration-none extra-small">Clear All</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</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; ?>
|
|
</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>
|
|
</div>
|
|
|
|
<!-- Recent Activity Section -->
|
|
<div class="row mt-4">
|
|
<div class="col-12">
|
|
<div class="card border-0 shadow-sm">
|
|
<div class="card-header bg-white py-3">
|
|
<h5 class="mb-0 fw-bold">Recent Activity</h5>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover align-middle mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th style="width: 200px;">Time</th>
|
|
<th>Action</th>
|
|
<th>Details</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($activityList as $a): ?>
|
|
<tr>
|
|
<td class="text-muted small"><?= date('M d, Y H:i', strtotime($a['created_at'])) ?></td>
|
|
<td><span class="badge bg-light text-primary border"><?= htmlspecialchars($a['action']) ?></span></td>
|
|
<td class="small"><?= htmlspecialchars($a['details']) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- Modals -->
|
|
<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" placeholder="e.g. 5G Network Optimization" 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" placeholder="PRJ-001" 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">Est. Completion Date</label>
|
|
<input type="date" name="estimated_completion_date" class="form-control">
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label class="form-label small fw-bold">Estimated Hours</label>
|
|
<div class="input-group">
|
|
<input type="number" name="estimated_hours" class="form-control" step="0.5" min="0" value="0">
|
|
<span class="input-group-text">hours</span>
|
|
</div>
|
|
</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>
|
|
|
|
<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 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']) ?></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">Time (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 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>
|
|
<script>
|
|
function toggleFilters() {
|
|
const sidebar = document.getElementById('projectFilterSidebar');
|
|
sidebar.classList.toggle('collapsed');
|
|
}
|
|
|
|
function handleDatePreset(value) {
|
|
const customRange = document.getElementById('customDateRange');
|
|
if (value === 'custom') {
|
|
customRange.classList.remove('d-none');
|
|
} else {
|
|
customRange.classList.add('d-none');
|
|
}
|
|
}
|
|
|
|
// Initial state check for sidebar on mobile
|
|
if (window.innerWidth < 992) {
|
|
document.getElementById('projectFilterSidebar').classList.add('collapsed');
|
|
}
|
|
|
|
// Hours Chart
|
|
const ctx = document.getElementById('hoursChart').getContext('2d');
|
|
new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
labels: <?= json_encode($chartLabels) ?>,
|
|
datasets: [{
|
|
label: 'Logged Hours',
|
|
data: <?= json_encode($chartValues) ?>,
|
|
borderColor: '#3b82f6',
|
|
backgroundColor: 'rgba(59, 130, 246, 0.1)',
|
|
borderWidth: 3,
|
|
fill: true,
|
|
tension: 0.4,
|
|
pointRadius: 4,
|
|
pointBackgroundColor: '#3b82f6'
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: {
|
|
legend: { display: false }
|
|
},
|
|
scales: {
|
|
y: {
|
|
beginAtZero: true,
|
|
grid: { color: '#f1f5f9' },
|
|
ticks: { font: { size: 11 } }
|
|
},
|
|
x: {
|
|
grid: { display: false },
|
|
ticks: { font: { size: 11 } }
|
|
}
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|