-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaporanmenu_admin.php
More file actions
155 lines (113 loc) · 5.37 KB
/
laporanmenu_admin.php
File metadata and controls
155 lines (113 loc) · 5.37 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!-- Untuk Akses Masuk -->
<?php
session_start();
// cek apakah yang mengakses halaman ini sudah login
if ($_SESSION['level'] == "") {
header("location:login.php?pesan=gagal");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Orders Admin</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:400,700" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Great+Vibes" rel="stylesheet">
<link rel="stylesheet" href="css/open-iconic-bootstrap.min.css">
<link rel="stylesheet" href="css/animate.css">
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/owl.theme.default.min.css">
<link rel="stylesheet" href="css/magnific-popup.css">
<link rel="stylesheet" href="css/aos.css">
<link rel="stylesheet" href="css/ionicons.min.css">
<link rel="stylesheet" href="css/bootstrap-datepicker.css">
<link rel="stylesheet" href="css/jquery.timepicker.css">
<link rel="stylesheet" href="css/flaticon.css">
<link rel="stylesheet" href="css/icomoon.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'header_admin.php'; ?>
<br><br><br>
<div class="container mt-5">
<h2>Laporan Menu Terjual</h2>
<div class="table-responsive">
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>Nama Produk</th>
<th>Jumlah Terjual</th>
</tr>
</thead>
<tbody>
<?php
// Menghubungkan ke database
include 'koneksi.php';
// Periksa koneksi
if (mysqli_connect_errno()) {
echo "Koneksi database gagal: " . mysqli_connect_error();
exit();
}
// Query untuk mengambil semua data orders
$query = "SELECT * FROM orders";
$result = mysqli_query($koneksi, $query);
if ($result && mysqli_num_rows($result) > 0) {
$menuTerjual = [];
while ($row = mysqli_fetch_assoc($result)) {
// Mendapatkan jumlah terjual dari nama_produk menggunakan regex
$namaProduk = $row['nama_produk'];
preg_match('/\((\d+)\)/', $namaProduk, $matches);
$jumlahTerjual = isset($matches[1]) ? $matches[1] : 0;
// Menghapus bagian jumlah terjual dari nama_produk
$namaProduk = preg_replace('/\(\d+\)/', '', $namaProduk);
// Menambahkan jumlah terjual ke dalam array menuTerjual
if (!isset($menuTerjual[$namaProduk])) {
$menuTerjual[$namaProduk] = (int)$jumlahTerjual;
} else {
$menuTerjual[$namaProduk] += (int)$jumlahTerjual;
}
}
// Menampilkan data dalam tabel
foreach ($menuTerjual as $namaProduk => $jumlahTerjual) {
echo "<tr>";
echo "<td>" . $namaProduk . "</td>";
echo "<td>" . $jumlahTerjual . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='2'>Tidak ada data untuk ditampilkan.</td></tr>";
}
// Tutup koneksi
mysqli_close($koneksi);
?>
</tbody>
</table>
</div>
</div>
<br><br><br><br><br>
<!-- loader -->
<div id="ftco-loader" class="show fullscreen"><svg class="circular" width="48px" height="48px">
<circle class="path-bg" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke="#eeeeee" />
<circle class="path" cx="24" cy="24" r="22" fill="none" stroke-width="4" stroke-miterlimit="10" stroke="#F96D00" />
</svg></div>
<script src="js/jquery.min.js"></script>
<script src="js/jquery-migrate-3.0.1.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.waypoints.min.js"></script>
<script src="js/jquery.stellar.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/aos.js"></script>
<script src="js/jquery.animateNumber.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.timepicker.min.js"></script>
<script src="js/scrollax.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBVWaKrjvy3MaE7SQ74_uJiULgl1JY0H2s&sensor=false"></script>
<script src="js/google-map.js"></script>
<script src="js/main.js"></script>
</body>
</html>