forked from hawariMuflihMunte/pupuk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.php
More file actions
197 lines (184 loc) · 8.89 KB
/
page.php
File metadata and controls
197 lines (184 loc) · 8.89 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
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
<?php include('./php/session.php') ?>
<?php if (!isset($_SESSION['role'])): ?>
<?php
header('location: ./index.php');
exit();
?>
<?php else: ?>
<?php if ($_SESSION['role'] == 1): ?>
<!-- Admin # -->
<?php include('./template/head.php') ?>
<?php include('./php/connection.php') ?>
<?php include('./template/nav.php') ?>
<div class="container pt-5">
<div class="d-flex gap-3">
<div class="card" style="width: 14rem;">
<div class="card-body">
<h5 class="card-title">Konsumen</h5>
<hr>
<p class="card-text text-muted">
Data konsumen
</p>
<a href="./user.php" class="btn btn-primary">Selengkapnya</a>
</div>
</div>
<div class="card" style="width: 14rem;">
<div class="card-body">
<h5 class="card-title">Produk</h5>
<hr>
<p class="card-text text-muted">
Data produk
</p>
<a href="./product.php" class="btn btn-primary">Selengkapnya</a>
</div>
</div>
<div class="card" style="width: 14rem;">
<div class="card-body">
<h5 class="card-title">Pembelian</h5>
<hr>
<p class="card-text text-muted">
Data Pembelian
</p>
<a href="./transaction.php" class="btn btn-primary">Selengkapnya</a>
</div>
</div>
</div>
</div>
<?php include('./template/foot.php') ?>
<!-- # Admin -->
<?php else: ?>
<!-- User # -->
<?php include('./template/head.php') ?>
<?php include('./php/connection.php') ?>
<?php include('./template/nav.php') ?>
<?php
if (isset($_REQUEST['return'])) {
$id_user = $_SESSION['id'];
$id_pembelian = $_REQUEST['id'];
$id_produk = $_REQUEST['id_produk'];
$jumlah_beli_kg = $_REQUEST['jumlah'];
$sql = "UPDATE
produk
SET
jumlah_produk_kg = jumlah_produk_kg + $jumlah_beli_kg
WHERE
id = $id_produk
;";
$query = mysqli_query($connection, $sql);
if ($query) {
$sql = "DELETE
FROM
pembelian
WHERE
id = $id_pembelian
;";
$query = mysqli_query($connection, $sql);
if ($query) {
echo "<script>
window.alert('Berhasil mengembalikan produk')
window.location.href = './page.php'
</script>";
} else {
echo "<script>
window.alert('Gagal mengembalikan produk. Terjadi kesalahan sistem')
window.location.href = './page.php'
</script>";
}
} else {
echo "<script>
window.alert('Gagal mengembalikan produk. Terjadi kesalahan sistem')
window.location.href = './page.php'
</script>";
}
}
?>
<div class="container pt-5">
<h4 class="text-secondary">Selamat Datang</h4>
<hr>
<?php
$id = $_SESSION['id'];
$sql = "SELECT
*
FROM
pembelian
WHERE
id_pengguna = $id
;";
$query = mysqli_query($connection, $sql);
?>
<?php if (mysqli_num_rows($query) > 0): ?>
<h5 class="text-secondary pt-3">Produk yang dibeli</h5>
<div class="table-responsive pt-3">
<table class="table table-hover">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$id = $_SESSION['id'];
$sql = "SELECT
pb.id id,
pb.id_produk id_produk,
pr.nama_produk nama_produk,
pr.gambar_produk gambar,
pb.jumlah_beli_produk jumlah
FROM
pembelian pb
JOIN produk pr ON
pb.id_produk = pr.id
WHERE
pb.id_pengguna = $id
;";
$query = mysqli_query($connection, $sql);
$i = 1;
?>
<?php while(list($id, $id_produk, $nama_produk, $gambar, $jumlah_kg) = mysqli_fetch_array($query)): ?>
<tr>
<form action="" method="post">
<input type="hidden" name="id" value="<?= $id ?>">
<input type="hidden" name="id_produk" value="<?= $id_produk ?>">
<td><?= $i ?></td>
<td>
<img src="<?= $gambar ?>" alt="<?= $nama_produk ?>" width="100">
</td>
<td>
<div class="d-flex flex-column">
<p>
<?= $nama_produk ?>
</p>
<div class="input-group mb-3">
<span class="input-group-text" id="jumlah"><i class="bi bi-diagram-2-fill"></i></span>
<input type="number" min="1" max="<?= $jumlah_kg ?>" name="jumlah" class="form-control" placeholder="Jumlah" aria-label="jumlah" aria-describedby="jumlah" readonly value="<?= $jumlah_kg ?>">
<span class="input-group-text">kg</span>
</div>
</div>
</td>
<td></td>
<td>
<div class="d-flex justify-content-evenly">
<button type="submit" name="return" onclick="return confirm('Yakin ingin mengembalikan produk ini?')" class="btn btn-danger btn-sm"><i class="bi bi-cart-x"></i></button>
</div>
</td>
</form>
<?php $i++ ?>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<h5 class="text-secondary">
Tidak ada produk yang dibeli
</h5>
<?php endif; ?>
</div>
<?php include('./template/foot.php') ?>
<!-- # User -->
<?php endif; ?>
<?php endif; ?>