TIF_NGANJUK_E41212020/qris/index.php

90 lines
3.5 KiB
PHP

<?php include '../template/template1.php'; ?>
<?php
include '../config.php';
// Pastikan pengguna sudah login
if (!isset($_SESSION['status_login']) || !$_SESSION['status_login']) {
echo "<script>alert('Harap login terlebih dahulu.');window.location='/login';</script>";
exit;
}
$id_pembeli = $_SESSION['id_pembeli']; // ID pembeli dari session
// Ambil data pesanan
$query_orders = mysqli_query($conn, "SELECT * FROM orders WHERE id_pembeli = '$id_pembeli' ORDER BY tanggal_order DESC");
?>
<?php include '../template/header.php'; ?>
<section id="orders" class="orders">
<div class="container">
<h2>Pesanan Saya</h2>
<?php
if (mysqli_num_rows($query_orders) > 0) {
while ($order = mysqli_fetch_assoc($query_orders)) {
// Ambil detail pesanan untuk setiap order
$order_id = $order['id_order'];
$query_details = mysqli_query($conn, "SELECT * FROM order_details WHERE id_order = '$order_id'");
?>
<div class="order-item">
<h3>ID Pesanan: <?php echo $order['id_order']; ?></h3>
<p>Tanggal Pesanan: <?php echo date('d-m-Y H:i', strtotime($order['tanggal_order'])); ?></p>
<p>Status Pesanan: <?php echo ucfirst($order['status_order']); ?></p>
<?php if ($order['metode_pembayaran'] === 'QRIS' && $order['status_order'] === 'Menunggu Pembayaran') { ?>
<div class="payment-info">
<h4>Scan QR Code untuk Membayar:</h4>
<div class="qr-code-container">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=250x250&data=<?php echo urlencode($order['qris_url']); ?>" alt="QR Code" class="qr-code">
</div>
<p>Atau klik <a href="<?php echo $order['qris_url']; ?>" target="_blank">di sini</a> jika QR Code tidak muncul.</p>
</div>
<?php } ?>
<h4>Detail Pesanan:</h4>
<table class="table">
<thead>
<tr>
<th>Nama Produk</th>
<th>Jumlah</th>
<th>Potongan</th>
<th>Harga</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php
while ($detail = mysqli_fetch_assoc($query_details)) {
// Ambil data produk
$product_id = $detail['id_produk'];
$query_product = mysqli_query($conn, "SELECT * FROM produk WHERE id_produk = '$product_id'");
$product = mysqli_fetch_assoc($query_product);
?>
<tr>
<td><?php echo $product['nama_produk']; ?></td>
<td><?php echo $detail['jumlah']; ?></td>
<td><?php echo $detail['potong']; ?></td>
<td>Rp<?php echo number_format($detail['harga'], 0, ',', '.'); ?></td>
<td>Rp<?php echo number_format($detail['jumlah'] * $detail['harga'], 0, ',', '.'); ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<hr>
</div>
<?php
}
} else {
echo "<p>Anda belum memiliki pesanan.</p>";
}
?>
</div>
</section>
<?php include '../template/footer.php'; ?>
<?php include '../template/template2.php'; ?>