<?php include 'includes/header.php';?>
<title><?=$seo['status_title'];?></title>
<meta name="description" content="<?=$seo['status_description'];?>">
<meta name="keywords" content="<?=$seo['status_keywords'];?>">
<meta name="author" content="ParsTech">
<style type="text/css">
  .modal-backdrop.show {
    z-index: 9;
  }
</style>
<?php 

if(isset($_POST['form1'])){


 $sip_no = $_POST['sip_no'];
 $mail = $_POST['mail'];

 if(!isset($_SESSION["masa_no"])){$masa=0;}else{
  $masa=$_SESSION["masa_no"];
}


$siparis_getir = $dbh-> prepare("SELECT durum FROM product_orders WHERE masa = ? AND mail = ? AND siparis_id=?");
$siparis_getir -> execute([ $masa,$mail,$sip_no]);
if ($siparis_getir->rowCount() > 0) {
  $siparis = $siparis_getir->fetch();
  $durum = $siparis['durum'];

  if ($durum == 0) {
   $durum = ' <div class="alert alert-warning mb-12" role="alert">
   ' . $dil['158'] . ' 
   </div> ';
 }else if($durum == 1){
  $durum = ' <div class="alert alert-warning mb-12" role="alert">
  ' . $dil['159'] . ' 
  </div> ';
}else if($durum == 2){
  $durum = ' <div class="alert alert-warning mb-12" role="alert">
  ' . $dil['160'] . ' 
  </div> ';
}else if($durum == 3){
  $durum = '  <div class="alert alert-warning mb-12" role="alert">
  ' . $dil['161'] . ' 
  </div> ';
}else{
  $durum = ' <div class="alert alert-warning mb-12" role="alert">
  ' . $dil['162'] . ' 
  </div> ';
}
}else{
  $durum = ' <div class="alert alert-warning mb-12" role="alert">
  ' . $dil['163'] . ' 
  </div> ';
}
}
?>
<body class="mobile_panel black_theme">
  <!-- Sepet_Urunler_Wrapper -->
  <div class="cart_product_wrapper">
    <div class="container">
      <form action="" method="post">
        <div class="cart_product_list flex justify-start items-start text-center flex-col pt-8">
          <div class="product_detail_title "><?php echo $dil['013'];?></div>
          <h6><?= $durum; ?></h6>    
          <?php if($_SESSION['sipid']){ ?>
            <div class="table-rep-plugin">
              <div class="table-responsive mb-0" data-pattern="priority-columns">
                <table id="tech-companies-1" class="table table-striped mb-0">
                  <thead>
                    <tr>
                      <th><?php echo $dil['178'];?></th>
                      <th data-priority="1"><?php echo $dil['179'];?></th>
                      <th data-priority="6"><?php echo $dil['065'];?></th>
                      <th data-priority="6"><?php echo $dil['066'];?></th>
                      <th data-priority="6"><?php echo $dil['136'];?></th>
                    </tr>
                  </thead>
                  <tbody>
                    <?php
                    foreach ($_SESSION['sipid'] as $key => $value) {
                      $sqll.="siparis_id=".$value." OR " ;
                    }
                    $sqll.=" siparis_id=0";
                    $sipler      =   $dbh->prepare("SELECT * FROM product_orders WHERE  $sqll order by siparis_id desc");
                    $sipler      ->  execute(array($_SESSION['user']->id));
                    $sipler      =   $sipler      ->fetchAll(PDO::FETCH_OBJ);
                    foreach ($sipler as $sip) { ?>
                      <tr>
                        <th> <span class="co-name">#<?=$sip->siparis_id?></span></th>
                        <td><?=$sip->adi_soyadi?></td>

                        <td><?=$sip->amount?> TL</td>
                        <td>
                          <?php $durum=$sip->durum;
                          if ($durum == 0) {
                            echo $dil["128"];  
                          }else if($durum == 1){
                           echo $dil["129"];  
                         }else if($durum == 2){
                          echo $dil["130"];  
                        }else if($durum == 3){
                         echo $dil["131"]; 
                       }else if($durum == 4){
                         echo $dil["160"];   
                       }

                       ?>


                     </td>
                     <td>  <button type="button" class=""   data-toggle="modal" data-target="#sipdetay<?=$sip->siparis_id;?>" ><?php echo $dil['181'];?></button></td>
                   </tr>
                 <?php }?>
               </tbody>
             </table>
           </div>
         </div>
       <?php } ?>
       <br>
       <br>


       <div class="flex flex-row justify-between items-center w-full mb-0">

        <label class="standart_label text-left mb-1 font-semibold" for="adisoyadi"><?php echo $dil['023'];?>: <span id="table_no"> <? if(!isset($_SESSION["masa_no"])){ ?>
          <label class="text-danger text-left mb-1 font-semibold -mt-2 mb-4" for="qrkod"><?php echo $dil['024'];?>.</label>
        <?php }else{


          $masa  = $dbh->prepare("SELECT * FROM masa_no where id=? ");
          $masa-> execute(array( $_SESSION["masa_no"]));
          $masa  = $masa->fetch(PDO::FETCH_ASSOC);
          echo $masa['masa_adi'];

        } ?>
      </span></label>
      <? if(!isset($_SESSION["masa_no"])){ ?>
        <a href="qrsayfa.php" class="qrcode_button btn btn-secondary">
          <img class="" src="images/icons/black/qr-code.svg">
          <span><?php echo $dil['025'];?></span>
        </a>
      <?php } ?>
    </div>

    <div class="form-group flex flex-col justify-start w-full">
      <label class=" text-left mb-1 font-semibold standart_label" for="telefon"><?php echo $dil['182'];?>*</label>
      <input type="text" name="sip_no" value="<?=$_SESSION['sonsip']?>" placeholder="<?php echo $dil['182'];?>" id="telefon" value="" class="form_input required w-full text-sm py-2  pl-2 rounded-lg" required="">
    </div>
    <? if(!isset($_SESSION["masa_no"])){ ?>
      <div class="form-group flex flex-col justify-start w-full">
        <label class=" text-left mb-1 font-semibold standart_label" for="telefon"><?php echo $dil['031'];?>*</label>
        <input type="text" name="mail" value="<?=$_SESSION['mail'];?>" placeholder="<?php echo $dil['031'];?>" id="telefon" value="" class="form_input required w-full text-sm py-2  pl-2 rounded-lg" required="">
      </div>
    <?php } ?>


    <button name="form1" type="submit" class=" btn btn-lg btn-default default-shadow btn-block"><?php echo $dil['087'];?> <span class="ml-2 icon arrow_right"></span></button>


    <label class="text-center standart_label  mb-1 font-normal w-100 mt-4 mb-4" ><?php echo $dil['088'];?> </label>

  </form>
</div>




</div>
</div>

<?php 



foreach ($sipler as $sip) { 

  $id=$sip->siparis_id;
  ?>



  <div class="modal fade" id="sipdetay<?=$id;?>" tabindex="-1" role="dialog" aria-labelledby="sipdetay<?=$id;?>" aria-hidden="true">
    <div class="modal-dialog  modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header bg-danger">
          <h6 class="modal-title m-0 text-white" id="exampleModalDanger<?=$id;?>"><?=$adress;?></h6>
          <button type="button" class="close " data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true"><i class="la la-times text-white"></i></span>
          </button>
        </div><!--end modal-header-->
        <div class="modal-body">


          <b><?php echo $dil['040'];?>:</b> <?=$sip->telefon?><br><br>

          <b><?php echo $dil['031'];?>:</b> <?=$sip->mail?><br><br>

          <b><?php echo $dil['063'];?>: </b><?=$sip->adres?><br><br>

          <?php echo $dil['064'];?>:<br>




          <?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"]);
            ?>

            <div class="alert alert-outline-primary" role="alert">
              <strong><b><?=$urun['product_name']?> (<?=$fiyat?> TL)</strong> ;</b><br><br>
              <li><?=$array->qty?> Adet</li>
              <li><b>Porsiyon Seçimi:</b> <?php echo   $porsyon['portion'] ." + " .$pfiyat . "TL";?></li>
              <li><b>Ekstra Seçim:</b> <?php echo " +".$ekstralara."  " ;?> </li> 
              <li><b>Müşteri Açıklaması:</b> <?php echo $array->icerik;?> </li>   
              <li><b>Toplam Tutar:<?=$toplam." TL";?></b></li>                     
            </div>

          <?php } ?>
          <ul class="list-group list-group-flush">
            <li class="list-group-item"><i class="la la-angle-double-right  mr-2"></i><b>Toplam Tutar:</b> <?=$toplam2 ?> TL</li>


            <li class="list-group-item"><i class="la la-angle-double-right text-info mr-2"></i><b>İndirim Kuponu:</b>   <?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"; 
            }else{echo "0 TL";} ?> 
          </li>


          <li class="list-group-item"><i class="la la-angle-double-right text-info mr-2"></i><b>Genel Toplam:</b> <?=$toplam2 -$kodkontrol->discount_amount?> TL</li>


        </ul>

    </div><!--end modal-body-->
    <div class="modal-footer">
      <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal"><?php echo $dil['140'];?></button>
    </div><!--end modal-footer-->
  </div><!--end modal-content-->
</div><!--end modal-dialog-->
</div><!--end modal-->
<?php } ?>



<?php include 'includes/modal.php';?>
<?php include 'includes/footer.php';?>