<?php
	include 'koneksi.php';
	include 'common/header.php';
?>

<h2> <span class="glyphicon glyphicon-shopping-cart"></span>Cart </h2>
<br/> <hr/>

<div class="col-md-12" align="center">
<table class="table table-hover table-condensed">
<tr>
	<th> No </th>
	<th> Nama </th>
	<th> Harga Satuan </th>
	<th> Jumlah </th>
	<th> Subtotal </th>
	<th> Opsi</th>
</tr>

<?php
	$id_member = $_GET['id_member'];
	$query = mysqli_query($koneksi, "SELECT menu.nama AS nama_menu, menu.harga, pemesanan.id_pemesanan ,pemesanan.jumlah FROM menu 
	INNER JOIN (pemesanan INNER JOIN member ON member_id = id_member) ON menu_id= id_menu WHERE member_id= '$id_member'");
	$no = 1;
	
	while($row = mysqli_fetch_assoc($query)){
		$subtotal = $row['jumlah'] * $row['harga'];
?>
	<tr>
		<td> <?= $no?> </td>
		<td> <?php echo $row['nama_menu'] ?> </td>
		<td> Rp. <?= number_format($row['harga'])?>,- </td>
		<td> <?= $row['jumlah']?> </td>
		<td> Rp. <?= number_format($subtotal)?>,- </td>
		<td> <a onclick="if(confirm('Apakah anda yakin ingin membatalkan pesanan ini?')){
			location.href='batal.php?id=<?= $row['id_pemesanan'] ?>&id_member=<?= $id_member?>';
		}" class="btn btn-danger"> <span class="glyphicon glyphicon-remove"></span> Batalkan </a> </td>
	</tr>
	
	<?php
		global $total;
		$total = $total += $subtotal;	
		$no++;
	}
	?>
</table>
	<div align="right">
		<font face="arial" size="5"> Total : Rp. <?php  if(mysqli_num_rows($query)){
			echo number_format($total);
			}else{
				echo '0';
			}
			?>,- </font>
	</div>
	
	<div align="center">
		<?php
		if(!mysqli_num_rows($query)){
			echo '<br><br> <h2> Cart anda masih kosong! </h2><h3> Silahkan pesan terlebih dahulu. </h3>';
			echo '<a href="member_menu.php" class="btn btn-info"><span class="glyphicon glyphicon-chevron-left"></span> Pesan</a> ';
		}
		else{
			echo '<a href="member_menu.php" class="btn btn-info"><span class="glyphicon glyphicon-chevron-left"></span> Pesan Lagi</a> ';
			echo '<a href="bayar.php?id_member='.$id_member .'" class="btn btn-success"> Checkout<span class="glyphicon glyphicon-chevron-right"></span> </a>';
		}
		?>
	</div>
<br>
</div>

<?php
	include 'common/footer.php';
?>