315 lines
16 KiB
PHP
315 lines
16 KiB
PHP
<?php include '../template/template1.php'; ?>
|
|
<?php include '../template/header.php'; ?>
|
|
|
|
<!-- Tambahkan script di bagian atas sebelum konten -->
|
|
<script>
|
|
function batalkanPesanan(idOrder) {
|
|
Swal.fire({
|
|
title: 'Apakah Anda yakin?',
|
|
text: "Pesanan akan dibatalkan dan tidak dapat dikembalikan!",
|
|
icon: 'warning',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#d33',
|
|
cancelButtonColor: '#3085d6',
|
|
confirmButtonText: 'Ya, Batalkan Pesanan!',
|
|
cancelButtonText: 'Tidak'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
// Kirim request untuk membatalkan pesanan
|
|
const formData = new FormData();
|
|
formData.append('id_order', idOrder);
|
|
|
|
fetch('batalkan_pesanan.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
return response.text().then(text => {
|
|
try {
|
|
return JSON.parse(text);
|
|
} catch (e) {
|
|
console.error('Response text:', text);
|
|
throw new Error('Invalid JSON response from server');
|
|
}
|
|
});
|
|
})
|
|
.then(data => {
|
|
if (data.status === 'success') {
|
|
Swal.fire({
|
|
title: 'Berhasil!',
|
|
text: data.message,
|
|
icon: 'success'
|
|
}).then(() => {
|
|
window.location.reload();
|
|
});
|
|
} else {
|
|
Swal.fire({
|
|
title: 'Gagal!',
|
|
text: data.message || 'Terjadi kesalahan saat membatalkan pesanan',
|
|
icon: 'error'
|
|
});
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error:', error);
|
|
Swal.fire({
|
|
title: 'Error!',
|
|
text: 'Terjadi kesalahan saat membatalkan pesanan. Silakan coba lagi.',
|
|
icon: 'error'
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
</script>
|
|
|
|
<?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 from session
|
|
$id_order = isset($_GET['id_order']) ? intval($_GET['id_order']) : null;
|
|
$status_filter = isset($_GET['status']) ? $_GET['status'] : '';
|
|
|
|
// Query untuk mengambil pesanan
|
|
$query_orders = "SELECT * FROM orders WHERE id_pembeli = '$id_pembeli'";
|
|
if ($id_order) {
|
|
$query_orders .= " AND id_order = '$id_order'"; // Filter hanya pesanan dengan id_order jika ada
|
|
}
|
|
if ($status_filter && $status_filter !== 'semua') {
|
|
$query_orders .= " AND status_order = '$status_filter'";
|
|
}
|
|
$query_orders .= " ORDER BY tanggal_order DESC"; // Urutkan berdasarkan tanggal pesanan terbaru
|
|
|
|
$result_orders = mysqli_query($conn, $query_orders);
|
|
?>
|
|
|
|
<section id="orders" class="orders">
|
|
<div class="container">
|
|
<h2 class="mt-5">Pesanan Saya</h2>
|
|
|
|
<!-- Filter Status -->
|
|
<?php if (!$id_order): ?>
|
|
<div class="card shadow-sm mb-4">
|
|
<div class="card-header" style="background-color: #FFA836;">
|
|
<h5 class="mb-0 text-white">Filter Status Pesanan</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="d-flex flex-wrap gap-2">
|
|
<a href="?status=semua" class="btn <?php echo ($status_filter === '' || $status_filter === 'semua') ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-list"></i> Semua
|
|
</a>
|
|
<a href="?status=Belum Dibayar" class="btn <?php echo $status_filter === 'Belum Dibayar' ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-clock"></i> Belum Dibayar
|
|
</a>
|
|
<a href="?status=Pembayaran Sukses" class="btn <?php echo $status_filter === 'Pembayaran Sukses' ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-check-circle"></i> Pembayaran Sukses
|
|
</a>
|
|
<a href="?status=Diproses" class="btn <?php echo $status_filter === 'Diproses' ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-cogs"></i> Diproses
|
|
</a>
|
|
<a href="?status=Dikemas" class="btn <?php echo $status_filter === 'Dikemas' ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-box"></i> Dikemas
|
|
</a>
|
|
<a href="?status=Dikirim" class="btn <?php echo $status_filter === 'Dikirim' ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-truck"></i> Dikirim
|
|
</a>
|
|
<a href="?status=Selesai" class="btn <?php echo $status_filter === 'Selesai' ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-check-double"></i> Selesai
|
|
</a>
|
|
<a href="?status=Dibatalkan" class="btn <?php echo $status_filter === 'Dibatalkan' ? 'btn-warning text-white' : 'btn-outline-warning'; ?>">
|
|
<i class="fas fa-times-circle"></i> Dibatalkan
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (mysqli_num_rows($result_orders) > 0): ?>
|
|
<?php while ($order = mysqli_fetch_assoc($result_orders)): ?>
|
|
<?php
|
|
$order_id = $order['id_order'];
|
|
// Query untuk mendapatkan detail pesanan
|
|
$query_details = mysqli_query($conn, "SELECT * FROM order_details WHERE id_order = '$order_id'");
|
|
?>
|
|
|
|
<div class="order-item mb-4">
|
|
<div class="card shadow-sm">
|
|
<div class="card-header" style="background-color: #FFA836;">
|
|
<h5 class="mb-0 text-white">ID Pesanan: <?php echo $order['id_order']; ?></h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<p><strong>Tanggal Pesanan:</strong> <?php echo date('d-m-Y H:i', strtotime($order['tanggal_order'])); ?></p>
|
|
<p><strong>Status Pesanan:</strong>
|
|
<span class="badge bg-<?php echo ($order['status_order'] === 'Selesai') ? 'success' : 'warning'; ?>">
|
|
<?php echo ucfirst($order['status_order']); ?>
|
|
</span>
|
|
</p>
|
|
|
|
<?php
|
|
|
|
if (($order['status_order'] === 'Belum Dibayar' && ($order['metode_pembayaran'] === 'COD' || $order['metode_pembayaran'] === 'QRIS')) ||
|
|
($order['status_order'] === 'Pembayaran Sukses' && $order['metode_pembayaran'] === 'SALDO')): ?>
|
|
<button type="button" class="btn btn-danger btn-sm mt-2" onclick="batalkanPesanan(<?php echo $order['id_order']; ?>)">
|
|
Batalkan Pesanan
|
|
</button>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($order['metode_pembayaran'] === 'QRIS' && $order['status_order'] === 'Belum Dibayar'): ?>
|
|
<div class="text-center mt-3">
|
|
<h5>Silakan Scan QR Code Berikut untuk Melakukan Pembayaran:</h5>
|
|
<img src="<?= $base_url; ?>/checkout/qris/qris_dana.png" alt="QR Code" class="img-fluid" style="max-width: 250px;">
|
|
<p class="mt-2">Setelah melakukan pembayaran, mohon tunggu hingga admin kami memverifikasi pembayaran Anda secara manual.</p>
|
|
|
|
<button class="btn btn-success mt-3" data-bs-toggle="modal" data-bs-target="#uploadBuktiModal">
|
|
Saya Sudah Bayar
|
|
</button>
|
|
</div>
|
|
|
|
<!-- Modal Upload Bukti Pembayaran -->
|
|
<div class="modal fade" id="uploadBuktiModal" tabindex="-1" aria-labelledby="uploadBuktiModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<form action="upload_bukti.php" method="POST" enctype="multipart/form-data">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="uploadBuktiModalLabel">Upload Bukti Pembayaran</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Tutup"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<input type="hidden" name="id_order" value="<?= $order['id_order']; ?>">
|
|
<div class="mb-3">
|
|
<label for="bukti_pembayaran" class="form-label">Pilih Gambar Bukti Pembayaran:</label>
|
|
<input type="file" class="form-control" name="bukti_pembayaran" id="bukti_pembayaran" accept="image/*" required>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="submit" class="btn btn-primary">Kirim Bukti</button>
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<h5 class="mt-4">Detail Pesanan:</h5>
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered text-center">
|
|
<thead class="bg-light">
|
|
<tr>
|
|
<th>Nama Produk</th>
|
|
<th>Jumlah</th>
|
|
<th>Potongan</th>
|
|
<th>Harga</th>
|
|
<th>Total</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (mysqli_num_rows($query_details) > 0): ?>
|
|
<?php while ($detail = mysqli_fetch_assoc($query_details)): ?>
|
|
<?php
|
|
$product_id = $detail['id_produk'];
|
|
$query_product = mysqli_query($conn, "SELECT nama_produk FROM produk WHERE id_produk = '$product_id'");
|
|
$product = mysqli_fetch_assoc($query_product);
|
|
?>
|
|
<tr>
|
|
<td><?php echo $product['nama_produk'] ?? 'Produk Tidak Ditemukan'; ?></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 endwhile; ?>
|
|
<?php else: ?>
|
|
<tr><td colspan="5">Tidak ada detail pesanan.</td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<hr>
|
|
<a href="cetak_pesanan.php?id_order=<?php echo $order['id_order']; ?>" target="_blank" style="background-color: #FFA836;" class="btn text-white">Cetak Pesanan</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php endwhile; ?>
|
|
<?php else: ?>
|
|
<p>Anda belum memiliki pesanan.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
|
|
<?php
|
|
// Menampilkan notifikasi testimoni untuk pesanan selesai dan belum diberikan testimoni
|
|
$query_cek_testimoni = mysqli_query($conn, "SELECT o.id_order FROM orders o
|
|
LEFT JOIN testimoni t ON o.id_order = t.id_order
|
|
WHERE o.id_pembeli = '$id_pembeli'
|
|
AND o.status_order = 'Selesai'
|
|
AND t.id_order IS NULL
|
|
ORDER BY o.tanggal_order DESC LIMIT 1");
|
|
|
|
if ($row = mysqli_fetch_assoc($query_cek_testimoni)) {
|
|
$id_order_selesai = $row['id_order'];
|
|
?>
|
|
|
|
<script>
|
|
// Kode testimoni yang sudah ada tetap di sini
|
|
<?php if (isset($id_order_selesai)): ?>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
Swal.fire({
|
|
title: "Beri Testimoni",
|
|
html:
|
|
'<form id="testimoniForm" action="simpan_testimoni.php" method="POST" enctype="multipart/form-data">' +
|
|
'<input type="hidden" name="id_order" value="<?php echo $id_order_selesai; ?>">' +
|
|
'<label class="swal2-label">Rating:</label>' +
|
|
'<div id="rating-stars" class="mb-3">' +
|
|
[1, 2, 3, 4, 5].map(i =>
|
|
`<label style="cursor:pointer;font-size:2rem;">` +
|
|
`<input type="radio" name="rating" value="${i}" required style="display:none;">` +
|
|
`<span data-index="${i}" class="star">☆</span>` + // default kosong
|
|
`</label>`
|
|
).join('') +
|
|
'</div>' +
|
|
'<label class="swal2-label">Deskripsi:</label>' +
|
|
'<textarea name="deskripsi" class="swal2-textarea" placeholder="Ceritakan pengalamanmu..." required></textarea>' +
|
|
'<label class="swal2-label mt-3">Upload Gambar (opsional):</label>' +
|
|
'<input type="file" name="gambar_testimoni" accept="image/*" class="swal2-file">' +
|
|
'</form>',
|
|
didOpen: () => {
|
|
const stars = Swal.getPopup().querySelectorAll('.star');
|
|
stars.forEach((star, idx) => {
|
|
star.addEventListener('click', () => {
|
|
const radioInputs = Swal.getPopup().querySelectorAll('input[name="rating"]');
|
|
radioInputs[idx].checked = true;
|
|
|
|
// Reset semua bintang ke kosong
|
|
stars.forEach(s => s.textContent = '☆');
|
|
|
|
// Isi bintang sampai yang diklik
|
|
for (let i = 0; i <= idx; i++) {
|
|
stars[i].textContent = '⭐';
|
|
}
|
|
});
|
|
});
|
|
},
|
|
showCancelButton: true,
|
|
confirmButtonText: "Kirim",
|
|
cancelButtonText: "Batal",
|
|
preConfirm: () => {
|
|
document.getElementById("testimoniForm").submit();
|
|
}
|
|
});
|
|
<?php endif; ?>
|
|
</script>
|
|
|
|
<?php } ?>
|
|
|
|
<?php include '../template/footer.php'; ?>
|
|
<?php include '../template/template2.php'; ?>
|