Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin dashboard #54

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class AdminController extends Controller
{
public function adminDashboard()
{
// Fetch counts for technicians, customers, and service centers
$counts = Admin::countEntities();

// Set the layout and render the dashboard with counts
$this->setLayout('auth');
return $this->render('/admin/dashboard');
return $this->render('/admin/admin-dashboard', $counts);
}


public function manageUsers()
{
$this->setLayout('auth');
Expand Down Expand Up @@ -153,6 +156,16 @@ public function technicians()
return $this->render('/admin/technicians', ['technicians' => $technicians]);

}
public function serviceCentres()
{
// Fetch all service centers records
$serviceCentres = Admin::findAllServiceCentres();
// Render the all the customer in the database
$this->setLayout('auth');
return $this->render('/admin/admin-service_centre', ['serviceCentres' => $serviceCentres]);

}


public function deleteCustomer(Request $request)
{
Expand Down
49 changes: 49 additions & 0 deletions models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ public static function findAllTechnicians()
$statement->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}
public static function findAllServiceCentres()
{
$sql = "SELECT ser_cen_id, name, email, phone_no, address, reg_date FROM service_center";
$statement = (new Admin)->prepare($sql);
$statement->execute();
return $statement->fetchAll(\PDO::FETCH_ASSOC);
}
public static function countTechnicians()
{
// Query to count total technicians
$sql = "SELECT COUNT(*) AS technicianCount FROM technician";
$statement = (new Admin)->prepare($sql);
$statement->execute();
$result = $statement->fetch(\PDO::FETCH_ASSOC);

// Return the count
return (int)($result['technicianCount'] ?? 0);
}



public static function deleteCustomerById($cus_id)
{
Expand All @@ -116,5 +136,34 @@ public static function deleteTechnicianById($tech_id)
return $stmt->execute();
}

public static function countEntities()
{
$db = new Admin();

// Query to count total technicians
$sqlTech = "SELECT COUNT(*) AS technicianCount FROM technician";
$stmtTech = $db->prepare($sqlTech);
$stmtTech->execute();
$technicianCount = (int)($stmtTech->fetch(\PDO::FETCH_ASSOC)['technicianCount'] ?? 0);

// Query to count total customers
$sqlCust = "SELECT COUNT(*) AS customerCount FROM customer";
$stmtCust = $db->prepare($sqlCust);
$stmtCust->execute();
$customerCount = (int)($stmtCust->fetch(\PDO::FETCH_ASSOC)['customerCount'] ?? 0);

// Query to count total service centers
$sqlSC = "SELECT COUNT(*) AS serviceCentreCount FROM service_center";
$stmtSC = $db->prepare($sqlSC);
$stmtSC->execute();
$serviceCentreCount = (int)($stmtSC->fetch(\PDO::FETCH_ASSOC)['serviceCentreCount'] ?? 0);

return [
'technicianCount' => $technicianCount,
'customerCount' => $customerCount,
'serviceCentreCount' => $serviceCentreCount
];
}


}
10 changes: 6 additions & 4 deletions public/css/admin/admin-dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,15 @@ body {

.cardBox .card {
position: relative;
background: var(--white);
padding: 50px;
background: #0a9bcc;
padding: 10px;
border-radius: 20px;
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
box-shadow: 0 7px 25px rgba(0, 0, 0, 0.08);
width: 500px;
}

.cardBox .card .numbers {
Expand All @@ -244,14 +245,15 @@ body {
}

.cardBox .card .cardName {
color: var(--black2);
color: var(--white);
font-size: 1.1rem;
margin-top: 5px;
}

.cardBox .card .iconBx {
font-size: 3.5rem;
color: var(--black2);
color: var(--black);
margin-left: 0px;
}

.cardBox .card:hover {
Expand Down
3 changes: 3 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
$app->router->get('/customers', [AdminController::class, 'customers']);
$app->router->get('/technicians', [AdminController::class, 'technicians']);
$app->router->post('/admin/delete-technician', [AdminController::class, 'deleteTechnician']);
$app->router->get('/admin-service_centre', [AdminController::class, 'serviceCentres']);
$app->router->post('/admin/delete-service-centre', [AdminController::class, 'deleteServiceCentre']);
$app->router->get('/admin-settings', [AdminController::class, 'adminSettings']);
$app->router->get('/admin-profile', [AdminController::class, 'adminProfile']);
$app->router->post('/update-admin-profile', [AdminController::class, 'updateAdminProfile']);
Expand All @@ -147,6 +149,7 @@
$app->router->get('/admin-promotions', [AdminController::class, 'promotions']);



/* Auth routes handled by AuthController */

/* Customer Auth routes */
Expand Down
101 changes: 87 additions & 14 deletions views/admin/admin-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Admin Dashboard</title>
<link rel="stylesheet" href="/css/admin/admin-dashboard.css">
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Rubik:wght@400;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="/css/admin/chart.css" />
</head>
<body>
<?php
Expand All @@ -18,26 +25,30 @@
<!-- ======================= Cards ================== -->
<div class="cardBox">
<div class="card">
<div>
<div class="numbers">16</div>
<div class="cardName">Active Service Requests</div>
</div>
<div class="programming-stats">
<div class="chart-container">
<canvas class="my-chart"></canvas>
</div>

<div class="iconBx">
<ion-icon name="cog-outline"></ion-icon>
</div>
<div class="details">
<ul></ul>
</div>
</div>
</div>

<div class="card">
<div>
<div class="numbers">20</div>
<div class="cardName">Total Reviews</div>
</div>

<div class="iconBx">
<ion-icon name="star-outline"></ion-icon>
<div>
<div class="numbers">
<?= htmlspecialchars($technicianCount, ENT_QUOTES, 'UTF-8'); ?>
</div>
<div class="cardName">Total Technicians</div>
</div>
<div class="iconBx">
<ion-icon name="pencil-outline"></ion-icon>
</div>
</div>



<div class="card">
<div>
Expand All @@ -51,6 +62,68 @@
</div>
</div>

<div class="MainChart">

<div class="Chart">
<h1>Earnings(Past 12 Months)</h1>
<div>
<canvas id="lineChart"></canvas>
</div>
</div>

<div class="Chart doughnut-chart">
<h1>Employees</h1>
<div>
<canvas id="doughnut"></canvas>
</div>
</div>


</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="/js/admin/main.js"></script>
<script src="/js/admin/chart.js"></script>
<script >
// For Doughnut-chart
var ctx2 = document.getElementById("doughnut").getContext("2d");
// Pass PHP counts to JavaScript
var technicianCount = <?= json_encode($technicianCount); ?>;
var customerCount = <?= json_encode($customerCount); ?>;
var serviceCentreCount = <?= json_encode($serviceCentreCount); ?>;

// Get the canvas element
var ctx2 = document.getElementById("doughnut").getContext("2d");

// Create Doughnut Chart
var myChart2 = new Chart(ctx2, {
type: "doughnut",
data: {
labels: ["Customers", "Technicians", "Service Centers"],
datasets: [
{
label: "Entities",
data: [customerCount, technicianCount, serviceCentreCount],
backgroundColor: [
"#f30707",
"rgb(19, 0, 230)",
"rgb(252, 183, 9)"
],
borderColor: [
"#f30707",
"rgb(19, 0, 230)",
"rgb(252, 183, 9)"
],
borderWidth: 1,
},
],
},
options: {
responsive: true,
},
});
</script>

</div>

<!-- Icons-->
<script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script>
Expand Down
73 changes: 73 additions & 0 deletions views/admin/admin-service_centre.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/admin/customers.css">
<link rel="stylesheet" href="/css/admin/admin-dashboard.css">
<title>Admin service center management</title>
</head>
<body>

<?php
include_once 'components/sidebar.php';
include_once 'components/header.php';
?>
<div class="customers-container">

<div id="customers-table">
<table class="table">
<thead>
<tr>
<th>Service Center ID</th>
<th>Name</th>
<th>Email</th>
<th>Phone Number</th>
<th>Address</th>
<th>Registered Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="table-body">
<?php if (!empty($serviceCentres)): ?>
<?php foreach ($serviceCentres as $serviceCentres): ?>
<tr data-service_Centre-id="<?= htmlspecialchars($serviceCentres['ser_cen_id']) ?>">
<td><?= htmlspecialchars($serviceCentres['ser_cen_id']) ?></td>
<td><?= htmlspecialchars($serviceCentres['name']) ?></td>
<td><?= htmlspecialchars($serviceCentres['email']) ?></td>
<td><?= htmlspecialchars($serviceCentres['phone_no']) ?></td>
<td><?= htmlspecialchars($serviceCentres['address']) ?></td>
<td><?= htmlspecialchars($serviceCentres['reg_date']) ?></td>
<td>
<button class="delete-btn">Delete</button>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="7">No Service Centers found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
<p id="no-packages-message" style="display: none;">You have no packages yet!</p>
</div>

<!-- Modal -->
<div id="delete-modal" class="modal hidden">
<div class="modal-content">
<h3>Are you sure you want to delete this technician?</h3>
<div class="modal-buttons">
<button id="confirm-delete" class="button failure">Yes</button>
<button id="cancel-delete" class="button gray">No, cancel</button>
</div>
</div>
</div>
</div>

<script src="/js/admin/technicians.js"></script>
<!-- Icons-->
<script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions views/admin/components/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
<span class="title">Technicians</span>
</a>
</li>

<li>
<a href="/admin-service_centre">
<span class="icon">
<ion-icon name = "construct-outline"></ion-icon>
</span>
<span class="title">Service Centre</span>
</a>
</li>


<li>
Expand Down
Loading