<?php

$path_to_root = "";
include $path_to_root . 'database.php';

$db = new database();

if (isset($_GET['id']) && $_GET['id'] != '') {
	$id = $_GET['id'];

	$sql = "SELECT * FROM `order` WHERE id=$id";

	$result = $db->db_query($sql);

	while ($rows = $db->db_fetch_array($result)) {
		$id_user = $rows['id_user'];
		$bayar = $rows['bayar'];
		$status = $rows['status'];
		$tanggal_pesanan = $rows['tanggal_pesanan'];
		$tanggal_pengambilan = $rows['tanggal_pengambilan'];

		$sql2 = "SELECT * FROM `profil_user` WHERE id_user=$id_user";
		$result2 = $db->db_query($sql2);
		while ($rows2 = $db->db_fetch_array($result2)) {
			$nama = $rows2['nama'];
			$hp = $rows2['hp'];
			$email = $rows2['email'];
			$alamat = $rows2['alamat'];

			print_header_bukti($id, $id_user, $bayar, $status, $nama, $hp, $email, $alamat, $tanggal_pesanan, $tanggal_pengambilan);
		}
	}
} else {
	header("location:index.php");
}

?>

<div class="upload-bukti-relative-layout">
	<div class="layout-list-produk-order">
		<div class="garis"></div>
		<div class="title-tabel-list-order">
			<div class="produk">Produk</div>
			<div class="harga">Harga</div>
			<div class="quantity">Quantity</div>
			<div class="quantity">Durasi Sewa (Hari)</div>
			<div class="subtotal">Subtotal</div>
		</div>
		<div class="garis"></div>
		<?php

		$id =$_GET['id'];

		$sql_produk_order = "SELECT * FROM order_produk WHERE id_order=$id";

		$result_produk_order = $db->db_query($sql_produk_order);

		while ($row = $db->db_fetch_array($result_produk_order)) {
		 	upload_list_produk($row['nama'], $row['harga'], $row['foto'], $row['quantity'], $row['lama_sewa']);
		 } 

		?>
	</div>
	<div class="container">
		<div class="layout-form-upload-bukti">
			<div class="title">Form Upload Bukti Pembayaran</div>
			<div class="keterangan">Text keterangan pembayaran</div>
			<form action="function-upload-bukti.php?id=<?php echo $_GET['id'];?>" method="post" enctype="multipart/form-data">
				<div class="field-upload">
					<div class="titlea">Foto Bukti</div>
					<div>
						<input type="file" name="gambar">
					</div>
				</div>
				<div class="btn-upload">
					<input type="submit" value="Simpan">
				</div>
			</form>
		</div>
	</div>
</div>

<?php

function print_header_bukti($id, $id_user, $bayar, $status, $nama, $hp, $email, $alamat, $tanggal_pesanan, $tanggal_pengambilan){
	echo '
		<div class="upload-bukti-header">
			<div class="upload-bukti-relative-layout" style="width:50%">
				<div>
					<div>Id Pesanan</div>
					<div>Tanggal Pesanan</div>
					<div>Tanggal Pengambilan</div>
					<div>Status Pembayaran</div>
				</div>
				<div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$id.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$tanggal_pesanan.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$tanggal_pengambilan.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$status.'</div>
				</div>
			</div>
			<div class="upload-bukti-relative-layout" style="width:50%">
				<div>
					<div>Nama Pemesan</div>
					<div>Nomor Hp</div>
					<div>Email</div>
					<div>Alamat</div>
				</div>
				<div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$nama.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$hp.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$email.'</div>
					<div>&nbsp;&nbsp;:&nbsp;&nbsp;'.$alamat.'</div>
				</div>
			</div>
		</div>
	';
}

function upload_list_produk($nama, $harga, $foto, $quantity, $lama_sewa){
	echo '
		<div class="title-tabel-list-order">
			<div class="upload-bukti-relative-layout">
				<img src="img-barang/'.$foto.'">
				<div class="produk">'.$nama.'</div>
			</div>
			<div class="harga">Rp. '.number_format($harga, 0, ',', '.').'</div>
			<div class="quantity">'.$quantity.'</div>
			<div class="quantity">'.$lama_sewa.' Hari</div>
			<div class="subtotal">Rp. '.subtotal_keranjang($harga, $quantity, $lama_sewa).'</div>
		</div>
		<div class="garis"></div>
	';
}

function subtotal_keranjang($harga, $quantity, $lama_sewa){
	$subtotal = $harga * $quantity * $lama_sewa;
	return number_format($subtotal, 0, ',', '.');
}

?>