-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdsd.php
375 lines (325 loc) · 14.5 KB
/
sdsd.php
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<?php
session_start();
require 'config/connect.php';
// if (!isset($_SESSION['user'])) {
// header("Location: page.php?mod=home");
// exit();
// }
// // Periksa apakah pengguna adalah pengelola
// if ($_SESSION['user']['role'] !== 'rumah_tangga') {
// // Jika bukan pengelola, redirect ke halaman unauthorized
// header("Location: page.php?mod=unaut2");
// exit();
// }
$id_rumah_tangga = $_SESSION['user']['id'];
// Saldo terakhir
$query_saldo = "SELECT saldo FROM rumah_tangga WHERE id = '$id_rumah_tangga'";
$result_saldo = mysqli_query($conn, $query_saldo);
$current_saldo = mysqli_fetch_assoc($result_saldo)['saldo'];
// Ambil data sampah yang statusnya menunggu pickup
$query_sampah = "SELECT s.id, s.berat, s.total_harga, s.status, js.nama_jenis
FROM sampah s
JOIN jenis_sampah js ON s.id_jenis_sampah = js.id
WHERE s.id_rumah_tangga = '$id_rumah_tangga' AND s.status = 'siap hitung'";
$result_sampah = mysqli_query($conn, $query_sampah);
// Hitung total harga sampah yang menunggu pickup
$total_pickup = 0;
while ($row = mysqli_fetch_assoc($result_sampah)) {
$total_pickup += $row['total_harga'];
}
// Ambil semua data sampah untuk history
$query_history = "SELECT s.berat, s.total_harga, s.status, s.created_at, js.nama_jenis
FROM sampah s
JOIN jenis_sampah js ON s.id_jenis_sampah = js.id
WHERE s.id_rumah_tangga = '$id_rumah_tangga'
ORDER BY s.id DESC";
$result_history = mysqli_query($conn, $query_history);
// Hitung total harga untuk history
$total_history = 0;
while ($row = mysqli_fetch_assoc($result_history)) {
$total_history += $row['total_harga'];
}
// Ambil history pembayaran
$query_riwayat = "SELECT t.*, wm.nama_warung
FROM transaksi t
JOIN warung_mitra wm ON t.id_warung_mitra = wm.id
WHERE t.id_rumah_tangga = '$id_rumah_tangga'
ORDER BY t.tanggal DESC";
$result_riwayat = mysqli_query($conn, $query_riwayat);
// Hapus sampah
if (isset($_POST['action']) && $_POST['action'] == 'hapus') {
$id_sampah = $_POST['id_sampah'];
$query_delete = "DELETE FROM sampah WHERE id = '$id_sampah'";
mysqli_query($conn, $query_delete);
header("Location: page.php?mod=riwayat");
exit();
}
// if ($_SERVER["REQUEST_METHOD"] == "POST") {
// $id_sampah = $_POST['id_sampah'];
// $status = $_POST['status'];
// // Ambil data sampah berdasarkan ID
// $query_sampah_detail = "SELECT * FROM sampah WHERE id = '$id_sampah'";
// $result_sampah_detail = mysqli_query($conn, $query_sampah_detail);
// $sampah = mysqli_fetch_assoc($result_sampah_detail);
// // Update status sampah hanya jika confirmed_by_rumah_tangga dan confirmed_by_pengelola adalah 1
// if ($sampah['confirmed_by_rumah_tangga'] == 1 && $sampah['confirmed_by_pengelola'] == 1) {
// // Update status sampah
// $query_update_status = "UPDATE sampah SET status = '$status' WHERE id = '$id_sampah'";
// mysqli_query($conn, $query_update_status);
// // Jika status diubah menjadi "selesai", tambahkan saldo rumah tangga
// if ($status == 'selesai') {
// $id_rumah_tangga = $sampah['id_rumah_tangga'];
// $total_harga = $sampah['total_harga'];
// // Update saldo rumah tangga
// $query_update_saldo = "UPDATE rumah_tangga SET saldo = saldo + $total_harga WHERE id = '$id_rumah_tangga'";
// mysqli_query($conn, $query_update_saldo);
// }
// }
// header("Location: page.php?mod=riwayat");
// exit();
// }
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id_sampah = $_POST['id_sampah'];
$confirmed_by_rumah_tangga = $_POST['confirmed_by_rumah_tangga'];
$confirmed_by_pengelola = $_POST['confirmed_by_pengelola'];
// Ambil data sampah berdasarkan ID untuk menghitung saldo
$query_sampah_detail = "SELECT * FROM sampah WHERE id = '$id_sampah'";
$result_sampah_detail = mysqli_query($conn, $query_sampah_detail);
$sampah = mysqli_fetch_assoc($result_sampah_detail);
// Update status sampah
$query_update_rumah_tangga = "UPDATE sampah SET confirmed_by_rumah_tangga = 'diterima' WHERE id = '$id_sampah'";
mysqli_query($conn, $query_update_rumah_tangga);
if ($sampah['confirmed_by_rumah_tangga'] == 'diterima' && $sampah['confirmed_by_pengelola'] == 'diterima') {
// Update status sampah
$query_update_status = "UPDATE sampah SET status = '$status' WHERE id = '$id_sampah'";
mysqli_query($conn, $query_update_status);
// Jika status diubah menjadi "selesai", tambahkan saldo rumah tangga
if ($status == 'selesai') {
$id_rumah_tangga = $sampah['id_rumah_tangga'];
$total_harga = $sampah['total_harga'];
// Update saldo rumah tangga
$query_update_saldo = "UPDATE rumah_tangga SET saldo = saldo + $total_harga WHERE id = '$id_rumah_tangga'";
mysqli_query($conn, $query_update_saldo);
}
}
header("Location: page.php?mod=riwayat");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard Rumah Tangga</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: 'Poppins', sans-serif;
background-color: #f4f6f9;
}
h1, h2, h3, h4 {
font-weight: 600;
}
.container {
margin-top: 30px;
}
.btn-primary {
background-color: #007bff;
border: none;
font-weight: 600;
padding: 10px 20px;
border-radius: 5px;
transition: all 0.3s ease;
}
.btn-primary:hover {
background-color: #0056b3;
}
.card {
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
border: none;
margin-bottom: 20px;
}
.table th, .table td {
vertical-align: middle;
}
.modal-content {
border-radius: 10px;
padding: 20px;
}
.no-data {
color: #6c757d;
text-align: center;
margin-top: 20px;
}
.no-data i {
font-size: 50px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<!-- Header -->
<?php include 'assets/components/header.php'; ?>
<div class="container">
<h1 class="text-center">Dashboard Rumah Tangga</h1>
<div class="card p-4">
<h3>Saldo: Rp. <?= number_format($current_saldo, 2, ',', '.') ?></h3>
<a href="?mod=pembayaran" class="btn btn-primary mt-4">Bayar</a>
</div>
<!-- Sampah Siap Pick-Up -->
<div class="card p-4">
<h4>Order Sampah</h4>
<?php if (mysqli_num_rows($result_sampah) > 0): ?>
<table class="table table-striped">
<thead>
<tr>
<th>Jenis Sampah</th>
<th>Berat (kg)</th>
<th>Total Harga (Rp)</th>
<th>Status</th>
<th>Pembayaran</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php
mysqli_data_seek($result_sampah, 0);
while ($sampah = mysqli_fetch_assoc($result_sampah)): ?>
<tr>
<td><?= $sampah['nama_jenis'] ?></td>
<td><?= number_format($sampah['berat'], 2, ',', '.') ?></td>
<td><?= number_format($sampah['total_harga'], 2, ',', '.') ?></td>
<td><?= $sampah['status'] ?></td>
<td><?= $sampah['confirmed_by_rumah_tangga'] ?></td>
<td>
<!-- Button to trigger modal for delete confirmation -->
<button class="btn btn-danger btn-sm" onclick="confirmDelete(<?= $sampah['id'] ?>)">Hapus</button>
<form method="POST" class="d-inline">
<input type="hidden" name="id_sampah" value="<?= $sampah['id'] ?>">
<button value="selesai" name="status" class="btn btn-success mt-2" <?= ($sampah['confirmed_by_pengelola'] == 'belum diterima') ? 'disabled' : '' ?>>Selesai</button>
</form>
</td>
</tr>
<?php endwhile; ?>
<tr>
<td colspan="2" class="text-end"><strong>Total Harga (Rp):</strong></td>
<td><strong><?= number_format($total_pickup, 2, ',', '.') ?></strong></td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
<?php else: ?>
<div class="no-data">
<i class="fas fa-trash-alt"></i>
<p>Tidak ada sampah yang siap untuk di-pickup.</p>
</div>
<?php endif; ?>
<a href="page.php?mod=jual" class="btn btn-primary mt-4">Jual Sampah</a>
</div>
<!-- History Transaksi Sampah -->
<div class="card p-4">
<h4>History Transaksi Sampah</h4>
<?php if (mysqli_num_rows($result_history) > 0): ?>
<table class="table table-striped">
<thead>
<tr>
<th>Jenis Sampah</th>
<th>Berat (kg)</th>
<th>Total Harga (Rp)</th>
<th>Status</th>
<th>Tanggal</th>
</tr>
</thead>
<tbody>
<?php
mysqli_data_seek($result_history, 0);
while ($history = mysqli_fetch_assoc($result_history)): ?>
<tr>
<td><?= $history['nama_jenis'] ?></td>
<td><?= number_format($history['berat'], 2, ',', '.') ?></td>
<td><?= number_format($history['total_harga'], 2, ',', '.') ?></td>
<td><?= $history['status'] ?></td>
<td><?= $history['created_at'] ?></td>
</tr>
<?php endwhile; ?>
<tr>
<td colspan="2" class="text-end"><strong>Total Penjualan (Rp):</strong></td>
<td><strong><?= number_format($total_history, 2, ',', '.') ?></strong></td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
<?php else: ?>
<div class="no-data">
<i class="fas fa-history"></i>
<p>Tidak ada history transaksi.</p>
</div>
<?php endif; ?>
</div>
<!-- Riwayat Pembayaran -->
<div class="card p-4">
<h4>Riwayat Pembayaran</h4>
<?php if (mysqli_num_rows($result_riwayat) > 0): ?>
<table class="table table-striped">
<thead>
<tr>
<th>Nama Warung</th>
<th>Jumlah Pembayaran (Rp)</th>
<th>Tanggal</th>
</tr>
</thead>
<tbody>
<?php while ($riwayat = mysqli_fetch_assoc($result_riwayat)): ?>
<tr>
<td><?= $riwayat['nama_warung'] ?></td>
<td><?= number_format($riwayat['jumlah_pembayaran'], 2, ',', '.') ?></td>
<td><?= $riwayat['tanggal'] ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?>
<div class="no-data">
<i class="fas fa-receipt"></i>
<p>Tidak ada riwayat pembayaran.</p>
</div>
<?php endif; ?>
</div>
</div>
<!-- Modal Konfirmasi Penghapusan -->
<div class="modal fade" id="confirmModal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirmModalLabel">Konfirmasi Penghapusan</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Apakah Anda yakin ingin menghapus sampah ini?
</div>
<div class="modal-footer">
<form id="deleteForm" action="page.php?mod=riwayat" method="POST">
<input type="hidden" name="id_sampah" id="id_sampah">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
<button type="submit" name="action" value="hapus" class="btn btn-danger">Hapus</button>
</form>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS and dependencies -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<!-- Script for delete confirmation modal -->
<script>
// Function to trigger modal and set the id of sampah to be deleted
function confirmDelete(id) {
document.getElementById('id_sampah').value = id; // Set the id in the hidden input
var myModal = new bootstrap.Modal(document.getElementById('confirmModal')); // Initialize Bootstrap Modal
myModal.show(); // Show the modal
}
</script>
</body>
</html>