<meta charset="UTF-8">
<?php
	if($_GET["s19"]<>""){ $s19 = "and s19=".$_GET["s19"].""; }
	$path="../../";
	$dpath="../../";
	include("../../map.php");
?>
<style>
	table tr td {border:1px solid #ccc;}
	body {font-family: tahoma;}
</style>
<?php if($_POST["type"]=="orders"){?>
<table style="width:100%;">
    <tr>
        <th style="width:6%"><?php echo ctranslate("Sipariş ID");?></th>
        <th style="width:8%;text-align:left;"><?php echo ctranslate("Müşteri");?></th>
        <th style="width:5%;text-align:left;"><?php echo ctranslate("Tarih");?></th>
        <th style="width:5%;text-align:left;"><?php echo ctranslate("Ödeme");?></th>
        <th style="width:10%; text-align:right;"><?php echo ctranslate("Beklemede");?></th>
        <th style="width:10%; text-align:right;"><?php echo ctranslate("Onaylanan");?></th>
        <th style="width:10%; text-align:right;"><?php echo ctranslate("İptal");?></th>
    </tr>
<?php
	if($_POST["odeme"]<>""){$sorgu="and t5='".$_POST["odeme"]."'";}
	$sql = mysqli_query($conn, "select * from eticaret where ne='siparis' and t4 like '%".$_REQUEST["q"]."%' $sorgu $lorders ORDER BY t1 asc"); while($siparis=mysqli_fetch_assoc($sql)){
		$sqlm = mysqli_query($conn, "select id,t1,t13,n17 from t5 where id=".$siparis["s1"]." order by id desc"); $rsm=mysqli_fetch_assoc($sqlm); $jsci=json_decode($rsm["n17"],true);
		$gtoplam=0; $s40=0;$s41=0;$s42=0;$s44=0;
		include("../../modules/ecommerce/ecommerce_order_calc.php");
		if($siparis["s4"]==0){
			$st40=$st40+$gtoplam;
			$s40=$gtoplam;
		}
		if($siparis["s4"]==1){
			$st41=$st41+$gtoplam;
			$s41=$gtoplam;
		}
		if($siparis["s4"]==2){
			$st42=$st42+$gtoplam;
			$s42=$gtoplam;
		}
		if($siparis["s4"]==4){
			$st44=$st44+$gtoplam;
			$s44=$gtoplam;
		}
?>
       <tr>
        <td><?php echo $siparis["t4"];?></td>
        <td><?php if($jsci["ifirma"]<>""){echo kisalt($jsci["ifirma"],3);}else{echo $rsm["t1"];}?></td>
        <td><?php echo dtarih($siparis["ts1"],"gg-aa-yyyy");?></td>
        <td><?php echo $siparis["t5"];?></td>
        <td style="text-align:right;"><?php echo wprice($s40);?></td>
        <td style="text-align:right;"><?php echo wprice($s41);?></td>
        <td style="text-align:right;"><?php echo wprice($s42);?></td>
    </tr>
<?php $stutar=0;$gtoplam=0;$s40=0;$s41=0;$s42=0;$s44=0;}?>
       <tr>
        <th></th>
        <th></th>
        <th></th>
        <th style="text-align:right;"><?php echo ctranslate("Toplam")?> : </th>
        <th style="text-align:right;"><?php echo wprice($st40);?></th>
        <th style="text-align:right;"><?php echo wprice($st41);?></th>
        <th style="text-align:right;"><?php echo wprice($st42);?></th>
    </tr>
</table>
<?php }elseif($_POST["type"]=="order_items"){?>
<table style="width:100%;">
    <thead>
      <tr>
        <th style="text-align: left;"><?php echo $t24;?></th>
        <th style="text-align: right;">Miktar</th>
        <th style="text-align: right;">Birim Fiyat</th>
    </tr>
</thead>
<tbody>
    <?php
    $sqls = mysqli_query($conn, "select distinct s3 from eticaret where ne='sepet' and t5='siparis'"); while($sepet=mysqli_fetch_assoc($sqls)){
		//$sqlb = mysqli_query($conn, "select * from eticaret where ne='sepet' and t5='siparis' and s3=".$sepet["s3"].""); $basket=mysqli_fetch_assoc($sqlb); $jsi = json_decode($basket["n17"], true);
        $sqlu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where ne='kayit' and id=".$sepet["s3"].""); $rsu=mysqli_fetch_assoc($sqlu); 
        $qty=0;$sqlb = mysqli_query($conn, "select * from eticaret where ne='sepet' and t5='siparis' and s3=".$rsu["id"].""); while($basket=mysqli_fetch_assoc($sqlb)){$qty=$qty+$basket["s2"];}
        ?>
        <tr>
          <td><?php echo $rsu["t1"]?>
          <?php
          foreach($jsi as $key=>$value){
            if($value[1]<>""){ $values = explode(',',$value); }else{ $values = explode(',',$value[0]); }
            if($values[1]<>0){$extras=$extras.", ".$values[0]." : <b>+".$values[1]." ".$ikpb."</b>";}else{$extras=$extras.", ".$values[0]."";}
        }
        echo ltrim($extras,', ');
        ?>
    </td>
    <td style="text-align: right;"><?php echo $qty?> <?php echo $rsu["t10"]?></td>
    <td style="text-align: right;"><?php echo wprice($rsu["pb1"]); ?> <?php echo $rsu["t2"]; ?> </td>
</tr>
<?php }?>
</tbody>
</table>
<?php }elseif($_POST["type"]=="orders_and_items"){?>
<table style="width:100%;">
    <thead>
      <tr>
        <th>Stok Kodu</th>
        <th>Sipariş Tarihi</th>
        <th>Firma</th>
        <th>Kategori</th>
        <th><?php echo $t24;?></th>
        <th style="text-align: right;">Miktar</th>
        <th style="text-align: right;">Birim</th>
        <th style="text-align: right;">Birim Fiyat</th>
    </tr>
</thead>
<tbody>
		<?php
			$sqls = mysqli_query($conn, "select * from eticaret where ne='siparis' and s4<>2 and t4 like '%".$_REQUEST["q"]."%' $sorgu $lorders"); while($siparis=mysqli_fetch_assoc($sqls)){
			$sqlm = mysqli_query($conn, "select id,t1,t13,n17 from t5 where id=".$siparis["s1"]." order by id desc"); $rsm=mysqli_fetch_assoc($sqlm); $jsci=json_decode($rsm["n17"],true); 
			$sqlb = mysqli_query($conn, "select * from eticaret where ne='sepet' and s5=".$siparis["id"].""); while($sepet=mysqli_fetch_assoc($sqlb)){ $jsi = json_decode($basket["n17"], true);
			$sqlu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where ne='kayit' and id=".$sepet["s3"].""); $rsu=mysqli_fetch_assoc($sqlu);
        ?>
        <tr>
          <td><?php echo $rsu["t4"]?></td>
          <td><?php echo $siparis["ts1"]?></td>
          <td><?php if($jsci["ifirma"]<>""){echo $jsci["ifirma"];}else{echo $rsm["t1"];}?></td>
          <td><?php echo kategori($rsu["s9"])?></td>
          <td><?php echo $rsu["t1"]?>
          <?php
          foreach($jsi as $key=>$value){
            if($value[1]<>""){ $values = explode(',',$value); }else{ $values = explode(',',$value[0]);}
            if($values[1]<>0){$extras=$extras.", ".$values[0]." : <b>+".$values[1]." ".$ikpb."</b>";}else{$extras=$extras.", ".$values[0]."";}
        }
        echo ltrim($extras,', ');
        ?>
    </td>
     <td style="text-align: right;"><?php echo $sepet["s2"]?></td>
    <td style="text-align: right;"><?php echo $qty?> <?php echo $rsu["t10"]?></td>
    <td style="text-align: right;"><?php echo wprice($rsu["pb1"]); ?> <?php echo $rsu["t2"]; ?> </td>
</tr>
<?php }}?>
</tbody>
</table>
<?php }?>