<?php 
include"inc/vt.php";

$ayarx = $dbh->query("SELECT * FROM general_settings WHERE id = 1 ", PDO::FETCH_ASSOC);
if ($ayarx->rowCount()) {
	foreach ($ayarx as $ayarx) {
	}
}



$sip      =   $dbh->prepare("SELECT * FROM product_orders where siparis_id =? ");
$sip      ->  execute(array($_GET['id']));
$sip      =   $sip      ->fetch(PDO::FETCH_OBJ);


?>



<!DOCTYPE html>
<html lang="en" >
<head>
	<meta charset="UTF-8">
	<title><?=$ayarx['page_title'];?></title>
	<link rel="stylesheet" href="./style.css">

</head>
<body> 
	<div id="invoice-POS">

		<center id="top">  
			<!-- <div class="logo" style="background:url(../img/<?=$ayarx['foto'];?>)">
			</div> -->
			<img style="    background-color: black;
			width: 105px;" src="../img/<?=$ayarx['foto'];?>" alt="logo-large" class="logo-lg logo-light">

			<div class="info"> 
				<h2><?=$ayarx['page_title'];?></h2>
			</div><!--End Info-->
		</center><!--End InvoiceTop-->

		<div id="mid">
			<div class="info">
				<h2>Kullanıcı Bilgileri</h2>
				<ul class="mt-3 mb-0">
					
				</ul>
				<p> 
					<h2><b>Sipariş:</b> #<?=$sip->siparis_id;?> / <?=$sip->tarih?><br>
					<b>İsim Soyisim:</b><?=$sip->adi_soyadi;?><br>
					<?php if(!empty($sip->mail)){ ?><b>Mail:</b> <?=$sip->mail;?><?php } ?><br>
					<?php if(!empty($sip->telefon)){ ?><b>Telefon:</b> <?=$sip->telefon;?>  <?php } ?><br>
					<b>Adres:</b> <?=$sip->adres?>  /  <?=$mahh->mahalle_title?> mah.  <br></h2>
				<!-- Address : street city, state 0000</br>
			Email   : JohnDoe@gmail.com</br>
		Phone   : 555-555-5555</br> -->
	</p>
</div>
</div><!--End Invoice Mid-->

<div id="bot">

	<div id="table">
		<table>
			<tr class="tabletitle">
				<td class="item"><h2>Ürün</h2></td>
				<td class="Hours"><h2>Adet</h2></td>
				<td class="Rate"><h2>Tutar</h2></td>
			</tr>


			<?php 
			$_SESSION['sepete'] =json_decode($sip->sip);
			$toplam2=0;
			foreach ($_SESSION['sepete']  as $siparis => $siparisdetay) {
				$array=$siparisdetay;
				$urun_getir = $dbh -> prepare("SELECT * FROM product WHERE id = ?");
				$urun_getir-> execute(array($siparisdetay->urunid));
				$urun = $urun_getir->fetch(PDO::FETCH_ASSOC);
				$fiyat = $urun["product_price"];

				$ekstraistek=0;
				$porsyon="";
				$pfiyat=0;
				if($siparisdetay->menu_porsiyon>0){
					$porsyon = $dbh -> prepare("SELECT * FROM product_portion WHERE id = ?");
					$porsyon-> execute(array($siparisdetay->menu_porsiyon));
					$porsyon = $porsyon->fetch(PDO::FETCH_ASSOC);
					$key= array_search($siparisdetay->menu_porsiyon,json_decode($urun['product_portion']) );
					$porsiyonfler=json_decode($urun['product_portion_price']) ;
					$pfiyat= $porsiyonfler[$key];
				}  
				if($siparisdetay->ekstra){
					$ekstralara=" ";
					$eksftop=0;
					foreach ($siparisdetay->ekstra as $eks) {
						$ekstrad = $dbh -> prepare("SELECT * FROM selectable WHERE id = ?");
						$ekstrad-> execute(array($eks));
						$ekstrad = $ekstrad->fetch(PDO::FETCH_ASSOC);
						$key= array_search($eks,json_decode($urun['product_optionek']) );
						$ekstrafiyat=json_decode($urun['product_optionek_price']) ;
						$ekfiyat= $ekstrafiyat[$key];
						$eksftop+=$ekfiyat;

						if($ekfiyat>0){
							$ekstralara.= $ekstrad['option']." ".$ekfiyat."TL + ";
						}else{
							$ekstralara.= $ekstrad['option']." + ";
						}
					}
					$ekstralara=rtrim($ekstralara," + " );
				}

				$toplam = ($fiyat + $pfiyat +  $eksftop)*$array->qty; 
				$urun = cevir("menu",$urun,$_SESSION["dil"]);
				$toplam2 += $toplam;

				$porsyon = cevir("porsiyon_secenekleri",$porsyon,$_SESSION["dil"]);
				?>


				<tr class="service">
					<td class="tableitem"><p class="itemtext"> <h2><?=$urun['product_name']?></h2><br>
						<span style="font-size: 8px;"><h2><?php if(!empty( $porsyon['portion'])){ echo   $porsyon['portion'] ." + " .$pfiyat . "TL";}?></h2></span>
						<span style="font-size: 8px;"><hb><?php if(!empty($ekstralara)){echo " +".$ekstralara."  " ;}?></hb></span>
					</p></td>
					<td class="tableitem"><p class="itemtext"><h2><?=$array->qty?></h2></p></td>
					<td class="tableitem"><p class="itemtext"><h2><?=$toplam?> TL</h2></p></td>
				</tr>

			<?php } ?>


		<!-- 	<tr class="service">
				<td class="tableitem"><p class="itemtext">Asset Gathering</p></td>
				<td class="tableitem"><p class="itemtext">3</p></td>
				<td class="tableitem"><p class="itemtext">$225.00</p></td>
			</tr>

			<tr class="service">
				<td class="tableitem"><p class="itemtext">Design Development</p></td>
				<td class="tableitem"><p class="itemtext">5</p></td>
				<td class="tableitem"><p class="itemtext">$375.00</p></td>
			</tr>

			<tr class="service">
				<td class="tableitem"><p class="itemtext">Animation</p></td>
				<td class="tableitem"><p class="itemtext">20</p></td>
				<td class="tableitem"><p class="itemtext">$1500.00</p></td>
			</tr>

			<tr class="service">
				<td class="tableitem"><p class="itemtext">Animation Revisions</p></td>
				<td class="tableitem"><p class="itemtext">10</p></td>
				<td class="tableitem"><p class="itemtext">$750.00</p></td>
			</tr> -->


			<tr class="tabletitle">
				<td></td>
				<td class="Rate"><h2>Toplam Tutar</h2></td>
				<td class="payment"><h2><?=$toplam2 ?> TL</h2></td>
			</tr>
			<tr class="tabletitle">
				<td></td>
				<td class="Rate"><h2>İndirim Tutarı</h2></td>
				<td class="payment"><h2><?php 

				$kodkontrol = $dbh -> prepare("SELECT * FROM coupon WHERE coupon_code = ?");
				$kodkontrol-> execute(array($sip->coupon));
				$kodkontrol = $kodkontrol->fetch(PDO::FETCH_OBJ);

				if($sip->coupon){
					echo "".$kodkontrol->discount_amount."TL indirim Kodu: ".$sip->coupon;
				}else{echo "0 TL";} ?> </h2></td>
			</tr>

			<tr class="tabletitle">
				<td></td>
				<td class="Rate"><h2>Genel Tutar</h2></td>
				<td class="payment"><h2><?=$toplam2 -$kodkontrol->discount_amount?> TL</h2></td>
			</tr>

		</table>
	</div><!--End Table-->

	<div id="legalcopy">
		<p class="legal"><strong><h2>Siparişiniz için teşekkür ederiz.</h2></strong>
		</p>
	</div>

</div><!--End InvoiceBot-->
</div><!--End Invoice-->
<!-- partial -->

</body>
</html>
<script type="text/javascript">
	window.print();
</script>
