Skip to content

Commit 940ceaf

Browse files
Version 2.6 Prototype
1 parent b117d01 commit 940ceaf

11 files changed

+486
-35
lines changed

calendar.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
include_once 'functions/menu/offcanva-menu.php';
33
include_once 'functions/authentication.php';
4+
include_once 'functions/tables/datatables.php';
45
?>
56
<!DOCTYPE html>
67
<html data-bs-theme="light" lang="en">
@@ -46,7 +47,7 @@
4647
<div class="row align-items-center no-gutters">
4748
<div class="col me-2">
4849
<div class="text-uppercase text-primary fw-bold text-xs mb-1"><span>CURRENT SALES</span></div>
49-
<div class="text-dark fw-bold h5 mb-0"><span>&lt;customer&gt;</span></div>
50+
<div class="text-dark fw-bold h5 mb-0"><span><?php echo get_sales()?></span></span></div>
5051
</div>
5152
<div class="col-auto"><i class="fas fa-calendar fa-2x text-gray-300"></i></div>
5253
</div>
@@ -59,7 +60,7 @@
5960
<div class="row align-items-center no-gutters">
6061
<div class="col me-2">
6162
<div class="text-uppercase text-warning fw-bold text-xs mb-1"><span>MONTLY SALES</span></div>
62-
<div class="text-dark fw-bold h5 mb-0"><span>0</span></div>
63+
<div class="text-dark fw-bold h5 mb-0"><span><?php echo get_sales()?></span></span></div>
6364
</div>
6465
<div class="col-auto"><i class="fas fa-calendar fa-2x text-gray-300"></i></div>
6566
</div>
@@ -72,7 +73,7 @@
7273
<div class="row align-items-center no-gutters">
7374
<div class="col me-2">
7475
<div class="text-uppercase text-warning fw-bold text-xs mb-1"><span>ANNUAL SALES</span></div>
75-
<div class="text-dark fw-bold h5 mb-0"><span>0</span></div>
76+
<div class="text-dark fw-bold h5 mb-0"><span><?php echo get_sales('annual')?></span></span></div>
7677
</div>
7778
<div class="col-auto"><i class="fas fa-calendar fa-2x text-gray-300"></i></div>
7879
</div>

functions/change-password.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
include_once 'connection.php';
3+
if (session_start() === PHP_SESSION_NONE) {
4+
session_start();
5+
}
6+
$current = $_POST['current'];
7+
$new = $_POST['new'];
8+
$id = $_SESSION['id'];
9+
$sql = "SELECT * FROM users WHERE id = :id";
10+
$stmt = $db->prepare($sql);
11+
$stmt->bindParam(':id', $id);
12+
$stmt->execute();
13+
$user = $stmt->fetch(PDO::FETCH_ASSOC);
14+
15+
if ($user && password_verify($current, $user['password'])) {
16+
17+
$sql = "UPDATE users SET password = :new WHERE id = :id";
18+
$statement = $db->prepare($sql);
19+
$statement->bindParam(':id', $id);
20+
$statement->bindParam(':new', password_hash($new, PASSWORD_DEFAULT));
21+
$statement->execute();
22+
23+
generate_logs('Change Password', $user['username'].'| Password was updated');
24+
header('Location: ../index.php?type=success&message=Password was updated successfully!');
25+
exit();
26+
} else {
27+
header('location: ../index.php?type=error&message=Wrong password');
28+
exit();
29+
}
30+
?>

functions/chart/get-chart.php

+178
Original file line numberDiff line numberDiff line change
@@ -1 +1,179 @@
11
<?php
2+
3+
function current_chart($type = 'line'){
4+
global $db;
5+
$sql = "SELECT DATE(t.created_at) AS date,
6+
SUM(CASE
7+
WHEN r.type = 'day' THEN co.priceDay
8+
WHEN r.type = 'night' THEN co.priceNight
9+
ELSE 0
10+
END) AS total_sales
11+
FROM transactions t
12+
JOIN rentals r ON t.id = r.transact_id
13+
JOIN cottages co ON r.cottage_id = co.id
14+
WHERE t.status = 'Proceed'
15+
AND DATE(t.created_at) = CURDATE()
16+
GROUP BY DATE(t.created_at)
17+
ORDER BY DATE(t.created_at);";
18+
19+
$stmt = $db->prepare($sql);
20+
$stmt->execute();
21+
22+
$labels = [];
23+
$data = [];
24+
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
25+
$labels[] = date("D m", strtotime($row['date']));
26+
$data[] = $row['total_sales'];
27+
}
28+
$chartData = [
29+
'labels' => $labels,
30+
'datasets' => [
31+
[
32+
'label' => 'Earnings',
33+
'fill' => true,
34+
'data' => $data,
35+
'backgroundColor' => 'rgba(78, 115, 223, 0.05)',
36+
'borderColor' => 'rgba(78, 115, 223, 1)'
37+
]
38+
]
39+
];
40+
41+
$chartDataJson = json_encode($chartData);
42+
?>
43+
<canvas data-bss-chart='{"type":"<?php echo $type?>","data":<?php echo $chartDataJson; ?>,"options":{"maintainAspectRatio":false,"legend":{"display":false,"labels":{"fontStyle":"normal"}},"title":{"fontStyle":"normal"},"scales":{"xAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"],"drawOnChartArea":false},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}],"yAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"]},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}]}}}'></canvas>
44+
<?php
45+
}
46+
47+
function weekly_chart($type = 'line'){
48+
global $db;
49+
$sql = "SELECT YEAR(t.created_at) AS year, WEEK(t.created_at) AS week, SUM(CASE
50+
WHEN r.type = 'day' THEN co.priceDay
51+
WHEN r.type = 'night' THEN co.priceNight
52+
ELSE 0
53+
END) AS total_sales
54+
FROM transactions t
55+
JOIN rentals r ON t.id = r.transact_id
56+
JOIN cottages co ON r.cottage_id = co.id
57+
WHERE t.status = 'Proceed'
58+
AND DATE_FORMAT(t.created_at, '%Y-%m') = DATE_FORMAT(CURRENT_DATE, '%Y-%m')
59+
GROUP BY YEAR(t.created_at), WEEK(t.created_at)
60+
ORDER BY YEAR(t.created_at), WEEK(t.created_at);";
61+
62+
$stmt = $db->prepare($sql);
63+
$stmt->execute();
64+
65+
$labels = [];
66+
$data = [];
67+
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
68+
$weekLabel = "Week " . $row['week'] . " (" . $row['year'] . ")";
69+
$labels[] = $weekLabel;
70+
$data[] = $row['total_sales'];
71+
}
72+
$chartData = [
73+
'labels' => $labels,
74+
'datasets' => [
75+
[
76+
'label' => 'Earnings',
77+
'fill' => true,
78+
'data' => $data,
79+
'backgroundColor' => 'rgba(78, 115, 223, 0.05)',
80+
'borderColor' => 'rgba(78, 115, 223, 1)'
81+
]
82+
]
83+
];
84+
85+
$chartDataJson = json_encode($chartData);
86+
87+
?>
88+
<canvas data-bss-chart='{"type":"<?php echo $type?>","data":<?php echo $chartDataJson; ?>,"options":{"maintainAspectRatio":false,"legend":{"display":false,"labels":{"fontStyle":"normal"}},"title":{"fontStyle":"normal"},"scales":{"xAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"],"drawOnChartArea":false},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}],"yAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"]},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}]}}}'></canvas>
89+
<?php
90+
}
91+
92+
function month_chart($type = 'line'){
93+
global $db;
94+
$sql = "SELECT YEAR(t.created_at) AS year, MONTH(t.created_at) AS month, SUM(CASE
95+
WHEN r.type = 'day' THEN co.priceDay
96+
WHEN r.type = 'night' THEN co.priceNight
97+
ELSE 0
98+
END) AS total_sales
99+
FROM transactions t
100+
JOIN rentals r ON t.id = r.transact_id
101+
JOIN cottages co ON r.cottage_id = co.id
102+
WHERE t.status = 'Proceed' AND DATE_FORMAT(t.created_at, '%Y-%m') = DATE_FORMAT(CURRENT_DATE, '%Y-%m')
103+
GROUP BY YEAR(t.created_at), MONTH(t.created_at)
104+
ORDER BY YEAR(t.created_at), MONTH(t.created_at);";
105+
106+
$stmt = $db->prepare($sql);
107+
$stmt->execute();
108+
109+
$labels = [];
110+
$data = [];
111+
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
112+
$monthName = date("M", mktime(0, 0, 0, $row['month'], 10));
113+
$labels[] = $monthName . ' ' . $row['year'];
114+
$data[] = $row['total_sales'];
115+
}
116+
$chartData = [
117+
'labels' => $labels,
118+
'datasets' => [
119+
[
120+
'label' => 'Earnings',
121+
'fill' => true,
122+
'data' => $data,
123+
'backgroundColor' => 'rgba(78, 115, 223, 0.05)',
124+
'borderColor' => 'rgba(78, 115, 223, 1)'
125+
]
126+
]
127+
];
128+
129+
130+
$chartDataJson = json_encode($chartData);
131+
?>
132+
<canvas data-bss-chart='{"type":"<?php echo $type?>","data":<?php echo $chartDataJson; ?>,"options":{"maintainAspectRatio":false,"legend":{"display":false,"labels":{"fontStyle":"normal"}},"title":{"fontStyle":"normal"},"scales":{"xAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"],"drawOnChartArea":false},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}],"yAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"]},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}]}}}'></canvas>
133+
<?php
134+
}
135+
136+
137+
function annual_chart($type = 'line'){
138+
global $db;
139+
$sql = "SELECT YEAR(t.created_at) AS year, MONTH(t.created_at) AS month, SUM(CASE
140+
WHEN r.type = 'day' THEN co.priceDay
141+
WHEN r.type = 'night' THEN co.priceNight
142+
ELSE 0
143+
END) AS total_sales
144+
FROM transactions t
145+
JOIN rentals r ON t.id = r.transact_id
146+
JOIN cottages co ON r.cottage_id = co.id
147+
WHERE t.status = 'Proceed' AND DATE_FORMAT(t.created_at, '%Y') = DATE_FORMAT(CURRENT_DATE, '%Y')
148+
GROUP BY YEAR(t.created_at), MONTH(t.created_at)
149+
ORDER BY YEAR(t.created_at), MONTH(t.created_at);";
150+
151+
$stmt = $db->prepare($sql);
152+
$stmt->execute();
153+
154+
$labels = [];
155+
$data = [];
156+
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
157+
$monthName = date("M", mktime(0, 0, 0, $row['month'], 10));
158+
$labels[] = $monthName . ' ' . $row['year'];
159+
$data[] = $row['total_sales'];
160+
}
161+
$chartData = [
162+
'labels' => $labels,
163+
'datasets' => [
164+
[
165+
'label' => 'Earnings',
166+
'fill' => true,
167+
'data' => $data,
168+
'backgroundColor' => 'rgba(78, 115, 223, 0.05)',
169+
'borderColor' => 'rgba(78, 115, 223, 1)'
170+
]
171+
]
172+
];
173+
174+
175+
$chartDataJson = json_encode($chartData);
176+
?>
177+
<canvas data-bss-chart='{"type":"<?php echo $type?>","data":<?php echo $chartDataJson; ?>,"options":{"maintainAspectRatio":false,"legend":{"display":false,"labels":{"fontStyle":"normal"}},"title":{"fontStyle":"normal"},"scales":{"xAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"],"drawOnChartArea":false},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}],"yAxes":[{"gridLines":{"color":"rgb(234, 236, 244)","zeroLineColor":"rgb(234, 236, 244)","drawBorder":false,"drawTicks":false,"borderDash":["2"],"zeroLineBorderDash":["2"]},"ticks":{"fontColor":"#858796","fontStyle":"normal","padding":20}}]}}}'></canvas>
178+
<?php
179+
}

functions/data/get-data.php

+9
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,13 @@ function get_current_sales(){
202202
$statement->execute();
203203
$result = $statement->fetch();
204204
return number_format($result['total'], 2);
205+
}
206+
207+
function get_total_user_logs(){
208+
global $db;
209+
$sql = "SELECT COUNT(*) AS total FROM logs";
210+
$statement = $db->prepare($sql);
211+
$statement->execute();
212+
$result = $statement->fetch();
213+
return $result['total'] ?? 0;
205214
}

functions/menu/offcanva-menu.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,31 @@ function menu()
3636
<div>
3737
<hr>
3838
<div class="dropdown"><a class="dropdown-toggle link-body-emphasis d-flex align-items-center text-decoration-none" aria-expanded="false" data-bs-toggle="dropdown" role="button"><img class="rounded-circle me-2" alt="" width="32" height="32" src="assets/img/icon.png" style="object-fit: cover;"><strong>Administrator</strong>&nbsp;</a>
39-
<div class="dropdown-menu shadow text-small" data-popper-placement="top-start"><a class="dropdown-item" href="#">Users Logs</a><a class="dropdown-item" href="#">Change Password</a>
39+
<div class="dropdown-menu shadow text-small" data-popper-placement="top-start"><a class="dropdown-item" href="users-logs.php">Users Logs</a><a class="dropdown-item" data-bs-target="#change" data-bs-toggle="modal">Change Password</a>
4040
<div class="dropdown-divider"></div><a class="dropdown-item" href="functions/logout.php">Sign out</a>
4141
</div>
4242
</div>
4343
</div>
4444
</div>
4545
</div>
46+
47+
48+
49+
<div class="modal fade" role="dialog" tabindex="-1" id="change">
50+
<div class="modal-dialog" role="document">
51+
<div class="modal-content">
52+
<div class="modal-header">
53+
<h4 class="modal-title">Change Password</h4><button class="btn-close" type="button" aria-label="Close" data-bs-dismiss="modal"></button>
54+
</div>
55+
<div class="modal-body">
56+
<form action="functions/change-password.php" method="post">
57+
<div class="my-1"><label class="form-label">Current Password</label><input name="current" class="form-control" type="password" required="" pattern="^(?!\s).*$"></div>
58+
<div class="my-1"><label class="form-label">New Password</label><input name="new" class="form-control" type="password" pattern="^(?!\s).*$" required=""></div>
59+
</div>
60+
<div class="modal-footer"><button class="btn btn-light" type="button" data-bs-dismiss="modal">Close</button><button class="btn btn-primary" type="submit">Save</button></div>
61+
</form>
62+
</div>
63+
</div>
64+
</div>
4665
<?php
4766
}

functions/tables/datatables.php

+53-4
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ function get_top_customers(){
146146
global $db;
147147
$sql = "SELECT c.fullname, COUNT(*) AS total FROM transactions t
148148
JOIN customers c ON t.customer_id = c.id
149-
WHERE t.status = 'Pending'
149+
WHERE t.status = 'Proceed'
150150
GROUP BY c.fullname
151151
ORDER BY total DESC
152152
LIMIT 3";
153153
$statement = $db->prepare($sql);
154154
$statement->execute();
155-
$results = $statement->fetchAll(); // Fetch all results
155+
$results = $statement->fetchAll();
156156

157157
foreach ($results as $row) {
158158
?>
@@ -172,8 +172,9 @@ function get_top_customers(){
172172

173173
function get_top_cottages(){
174174
global $db;
175-
$sql = "SELECT c.name, COUNT(*) AS total FROM rentals r
176-
JOIN cottages c ON r.cottage_id = c.id
175+
$sql = "SELECT c.name, COUNT(*) AS total FROM transactions t
176+
JOIN cottages c ON t.customer_id = c.id
177+
WHERE t.status = 'Proceed'
177178
GROUP BY c.name
178179
ORDER BY total DESC
179180
LIMIT 3";
@@ -195,4 +196,52 @@ function get_top_cottages(){
195196
</li>
196197
<?php
197198
}
199+
}
200+
201+
202+
function activity_logs(){
203+
global $db;
204+
$sql = 'SELECT * FROM logs';
205+
$stmt = $db->prepare($sql);
206+
$stmt->execute();
207+
$results = $stmt->fetchAll();
208+
209+
foreach ($results as $row) {
210+
?>
211+
<tr>
212+
<td><?php echo $row['id']; ?></td>
213+
<td><?php echo $row['type'] ?></td>
214+
<td><?php echo $row['logs'] ?></td>
215+
<td><?php echo $row['created_at'] ?></td>
216+
</tr>
217+
<?php
218+
}
219+
}
220+
221+
function sales_report(){
222+
global $db;
223+
$sql = "SELECT r.id AS rental_id,
224+
r.type as rental_type,
225+
c.name AS cottage_name,
226+
CASE
227+
WHEN r.type = 'day' THEN c.priceDay
228+
WHEN r.type = 'night' THEN c.priceNight
229+
ELSE 0
230+
END AS cottage_price
231+
FROM rentals r
232+
JOIN cottages c ON r.cottage_id = c.id;";
233+
$stmt = $db->prepare($sql);
234+
$stmt->execute();
235+
$results = $stmt->fetchAll();
236+
237+
foreach ($results as $row) {
238+
?>
239+
<tr>
240+
<td class="sorting_1"><img class="rounded-circle me-2" width="30" height="30" src="assets/img/icon.png"><?php echo $row['cottage_name']?></td>
241+
<td><?php echo $row['cottage_price']?></td>
242+
<td><?php echo $row['r.rental_type']?></td>
243+
<td><?php echo $row['r.created_at']?></td>
244+
</tr>
245+
<?php
246+
}
198247
}

0 commit comments

Comments
 (0)