-
Notifications
You must be signed in to change notification settings - Fork 1
/
viewSalesReport.jsp
117 lines (113 loc) · 3.39 KB
/
viewSalesReport.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="javax.servlet.http.*, javax.servlet.*" %>
<%@ page session="true" %>
<%@ page import="com.cs336.pkg.ApplicationDB" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>View Sales Report</title>
<style>
body {
font-family: Arial, sans-serif;
}
table {
border-collapse: collapse;
width: 80%;
margin: 20px auto;
}
th, td {
border: 1px solid #999;
padding: 10px;
text-align: left;
}
th {
background-color: #eee;
}
.back-link {
display: inline-block;
margin: 20px;
padding: 8px;
background-color: lightblue;
text-decoration: none;
color: black;
border-radius: 5px;
}
.back-link:hover {
background-color: lightcoral;
}
</style>
</head>
<body>
<%
String user = (String) session.getAttribute("user");
String role = (String) session.getAttribute("role");
if (user == null || !"manager".equalsIgnoreCase(role)) {
%>
<h2>You are not authorized to access this page. Please <a href="login.jsp">log in</a>.</h2>
<%
} else {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<Map<String, Object>> revenueData = new ArrayList<>();
String errorMessage = null;
try {
ApplicationDB db = new ApplicationDB();
con = db.getConnection();
String query = "SELECT DATE_FORMAT(date_made, '%Y-%m') AS month, SUM(total_fare) AS revenue " +
"FROM Reservation WHERE canceled = FALSE " +
"GROUP BY DATE_FORMAT(date_made, '%Y-%m') " +
"ORDER BY DATE_FORMAT(date_made, '%Y-%m')";
ps = con.prepareStatement(query);
rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> row = new HashMap<>();
row.put("month", rs.getString("month"));
row.put("revenue", rs.getDouble("revenue"));
revenueData.add(row);
}
} catch (SQLException e) {
errorMessage = "Error retrieving revenue data: " + e.getMessage();
} finally {
try { if (rs != null) rs.close(); } catch (SQLException e) {}
try { if (ps != null) ps.close(); } catch (SQLException e) {}
}
%>
<h1 style="text-align:center;">Sales Report</h1>
<p style="text-align:center;"><a href="managerHome.jsp" class="back-link">Back to Manager Home</a></p>
<%
if (errorMessage != null) {
%>
<p style="color: red; text-align: center;"><%= errorMessage %></p>
<%
} else if (revenueData.isEmpty()) {
%>
<p style="text-align: center;">No revenue data available.</p>
<%
} else {
%>
<table>
<tr>
<th>Month</th>
<th>Total Revenue ($)</th>
</tr>
<%
for (Map<String, Object> row : revenueData) {
%>
<tr>
<td><%= row.get("month") %></td>
<td><%= row.get("revenue") %></td>
</tr>
<%
}
%>
</table>
<%
}
}
%>
</body>
</html>