<?php include 'inc/header.php';?>
<?php include 'inc/sidebar.php';?>
<?php include 'inc/navbar.php';?>

<!-- Page Content-->
<div class="page-content">
    <div class="container-fluid">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="page-title-box">
                    <div class="row"> 

                    </div><!--end row-->                                                              
                </div><!--end page-title-box-->
            </div><!--end col-->
        </div><!--end row-->
        <!-- end page title end breadcrumb -->

        <?php
        $bekleyenx = $dbh->query("SELECT * FROM product_orders WHERE durum=0 ", PDO::FETCH_ASSOC); 
        $hazirlananx = $dbh->query("SELECT * FROM product_orders WHERE durum=1 ", PDO::FETCH_ASSOC); 
        $tamamlax = $dbh->query("SELECT * FROM product_orders WHERE durum=2", PDO::FETCH_ASSOC); 
        $iptalx = $dbh->query("SELECT * FROM product_orders WHERE durum=3 ", PDO::FETCH_ASSOC); 
        $yoldax = $dbh->query("SELECT * FROM product_orders WHERE durum=4 ", PDO::FETCH_ASSOC); 
        ?>
        <div class="row">
            <div class="col-lg-12">

                <div class="row justify-content-center">

                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">Bekleyen Sipariş</p>
                                        <h3 class="m-0"><?=$bekleyenx->rowCount()?></h3>
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="bell" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div>
                                </div>
                                <hr class="hr-dashed">
                                <div class="text-center">
                                    <h6 class="text-primary bg-soft-primary p-2 m-0 font-11 rounded">
                                        <a href="siparis-liste.php"><i class="ti-angle-double-right"></i>
                                        Talepleri Göster </a>
                                    </h6>
                                </div>         
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col--> 
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">Hazırlanan Sipariş</p>
                                        <h3 class="m-0"><?=$hazirlananx->rowCount()?></h3>
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                           <i data-feather="bell" class="align-self-center text-muted icon-sm"></i>  
                                       </div>
                                   </div>
                               </div>
                               <hr class="hr-dashed">
                               <div class="text-center">
                                <h6 class="text-primary bg-soft-primary p-2 mb-0 font-11 rounded">
                                  <a href="siparis-liste.php"><i class="ti-angle-double-right"></i>
                                  Talepleri Göster </a>
                              </h6>
                          </div>         
                      </div><!--end card-body--> 
                  </div><!--end card--> 
              </div> <!--end col--> 
              <div class="col-md-6 col-lg-3">
                <div class="card report-card">
                    <div class="card-body">
                        <div class="row d-flex justify-content-center">
                            <div class="col">
                                <p class="text-dark mb-0 font-weight-semibold">Teslimatta Olan Sipariş</p>
                                <h3 class="m-0"><?=$yoldax->rowCount()?></h3>
                            </div>
                            <div class="col-auto align-self-center">
                                <div class="report-main-icon bg-light-alt">
                                    <i data-feather="bell" class="align-self-center text-muted icon-sm"></i>  
                                </div>
                            </div>
                        </div>
                        <hr class="hr-dashed">
                        <div class="text-center">
                            <h6 class="text-primary bg-soft-primary p-2 mb-0 font-11 rounded">
                              <a href="siparis-liste.php"><i class="ti-angle-double-right"></i>
                              Talepleri Göster </a>
                          </h6>
                      </div>         
                  </div><!--end card-body--> 
              </div><!--end card--> 
          </div> <!--end col--> 

          <div class="col-md-6 col-lg-3">
            <div class="card report-card">
                <div class="card-body">
                    <div class="row d-flex justify-content-center">
                        <div class="col">
                            <p class="text-dark mb-0 font-weight-semibold">Tamamlanan Sipariş</p>
                            <h3 class="m-0"><?=$tamamlax->rowCount()?></h3>
                        </div>
                        <div class="col-auto align-self-center">
                            <div class="report-main-icon bg-light-alt">
                             <i data-feather="bell" class="align-self-center text-muted icon-sm"></i>  
                         </div>
                     </div>
                 </div>
                 <hr class="hr-dashed">
                 <div class="text-center">
                    <h6 class="text-primary bg-soft-primary p-2 mb-0 font-11 rounded">
                      <a href="siparis-liste.php"><i class="ti-angle-double-right"></i>
                      Talepleri Göster </a>
                  </h6>
              </div>         
          </div><!--end card-body--> 
      </div><!--end card--> 
  </div> <!--end col--> 



</div><!--end row-->

</div><!--end col-->

<div class="col-lg-12">

    <div class="row justify-content-center">

        <div class="col-md-6 col-lg-3">
            <div class="card report-card">
                <div class="card-body">
                    <div class="row d-flex justify-content-center">
                        <div class="col">
                            <p class="text-dark mb-0 font-weight-semibold">İletişim Talebi</p>
                            <h3 class="m-0"><?=$iletisim->rowCount()?></h3>
                        </div>
                        <div class="col-auto align-self-center">
                            <div class="report-main-icon bg-light-alt">
                                <i data-feather="compass" class="align-self-center text-muted icon-sm"></i>  
                            </div>
                        </div>
                    </div>
                    <hr class="hr-dashed">
                    <div class="text-center">
                        <h6 class="text-primary bg-soft-primary p-2 m-0 font-11 rounded">
                            <a href="iletisim-liste.php"><i class="ti-angle-double-right"></i>
                            Talepleri Göster </a>
                        </h6>
                    </div>         
                </div><!--end card-body--> 
            </div><!--end card--> 
        </div> <!--end col--> 
        <div class="col-md-6 col-lg-3">
            <div class="card report-card">
                <div class="card-body">
                    <div class="row d-flex justify-content-center">
                        <div class="col">
                            <p class="text-dark mb-0 font-weight-semibold">Garson Talebi</p>
                            <h3 class="m-0"><?=$garson->rowCount()?></h3>
                        </div>
                        <div class="col-auto align-self-center">
                            <div class="report-main-icon bg-light-alt">
                                <i data-feather="star" class="align-self-center text-muted icon-sm"></i>  
                            </div>
                        </div>
                    </div>
                    <hr class="hr-dashed">
                    <div class="text-center">
                        <h6 class="text-primary bg-soft-primary p-2 mb-0 font-11 rounded">
                          <a href="garson-liste.php"><i class="ti-angle-double-right"></i>
                          Talepleri Göster </a>
                      </h6>
                  </div>         
              </div><!--end card-body--> 
          </div><!--end card--> 
      </div> <!--end col--> 
      <div class="col-md-6 col-lg-3">
        <div class="card report-card">
            <div class="card-body">
                <div class="row d-flex justify-content-center">
                    <div class="col">
                        <p class="text-dark mb-0 font-weight-semibold">Hesap İsteme Talebi</p>
                        <h3 class="m-0"><?=$hesap->rowCount()?></h3>
                    </div>
                    <div class="col-auto align-self-center">
                        <div class="report-main-icon bg-light-alt">
                            <i data-feather="search" class="align-self-center text-muted icon-sm"></i>  
                        </div>
                    </div>
                </div>
                <hr class="hr-dashed">
                <div class="text-center">
                    <h6 class="text-primary bg-soft-primary p-2 mb-0 font-11 rounded">
                      <a href="hesap-liste.php"><i class="ti-angle-double-right"></i>
                      Talepleri Göster </a>
                  </h6>
              </div>         
          </div><!--end card-body--> 
      </div><!--end card--> 
  </div> <!--end col--> 

  <div class="col-md-6 col-lg-3">
    <div class="card report-card">
        <div class="card-body">
            <div class="row d-flex justify-content-center">
                <div class="col">
                    <p class="text-dark mb-0 font-weight-semibold">Yedekleme Hizmetleri</p>
                    <h3 class="m-0">SQL + FTP</h3>
                </div>
                <div class="col-auto align-self-center">
                    <div class="report-main-icon bg-light-alt">
                        <i data-feather="lock" class="align-self-center text-muted icon-sm"></i>  
                    </div>
                </div>
            </div>
            <hr class="hr-dashed">
            <div class="text-center">
                <h6 class="text-primary bg-soft-primary p-2 mb-0 font-11 rounded">
                    <a href="yedek.php"><i class="ti-angle-double-right"></i>
                    Hemen Yedekle </a>
                </h6>
            </div>         
        </div><!--end card-body--> 
    </div><!--end card--> 
</div> <!--end col-->                     




</div><!--end row-->

</div><!--end col-->

<div class="col-lg-12">
    <div class="card">
        <div class="card-header">
            <div class="row align-items-center">
                <div class="col">                      
                    <h4 class="card-title">Ziyaretci Analizi</h4>                      
                </div><!--end col--> 
            </div>  <!--end row-->                                  
        </div><!--end card-header-->
        <div class="card-body">
            <div class="text-center">
             <div id="zoomableTimeSces"></div>
         </div>  

     </div><!--end card-body--> 
 </div><!--end card--> 
</div> <!--end col--> 





</div><!--end row-->

<div class="row">
 <div class="col-lg-6">
    <div class="card"> 
        <div class="card-header">
            <div class="row align-items-center">
                <div class="col">                      
                    <h4 class="card-title">Kazanç Tablosu</h4>                   
                </div><!--end col-->  
                                            
        </div>  <!--end row-->                                  
    </div><!--end card-header-->
    <div class="card-body border-bottom-dashed">
        <div class="earning-data text-center">
            <img src="assets/images/money-beg.png" alt="" class="money-bag my-3" height="60">
            <h5 class="earn-money mb-1">

                <?php 

                $kazanct = $dbh->prepare("SELECT SUM(amount) FROM product_orders WHERE  odeme_durum=1 && tarih>=DATE_SUB(CURDATE(),INTERVAL 0 DAY)  ");
                $kazanct -> execute();
                $kazanct = $kazanct->fetch(PDO::FETCH_ASSOC);

                if( $kazanct['SUM(amount)']>0){echo  $kazanct['SUM(amount)']." TL";}else{echo "0 TL";}



                ?>


            </h5>
            <p class="text-muted font-15 mb-4">Günlük Kazanılan Ödeme</p>
            <div class="text-center my-2">
                <h6 class="text-primary bg-soft-primary p-3 mb-0 font-11 rounded">
                   
                    <?php 

                    $kazancm = $dbh->prepare("SELECT SUM(amount) FROM product_orders WHERE masa=0 &&  odeme_durum=1 && tarih>=DATE_SUB(CURDATE(),INTERVAL 0 DAY)  ");
                    $kazancm -> execute();
                    $kazancm = $kazancm->fetch(PDO::FETCH_ASSOC);

                    echo "Günlük Paket Sipariş Kazancı: ";
                    if( $kazancm['SUM(amount)']>0){echo  $kazancm['SUM(amount)']." TL";}else{echo "0 TL";}



                    ?>

                    <span class="mx-2">/</span>
                    
                    <?php 

                    $kazancm = $dbh->prepare("SELECT SUM(amount) FROM product_orders WHERE masa>0 &&  odeme_durum=1 && tarih>=DATE_SUB(CURDATE(),INTERVAL 0 DAY)  ");
                    $kazancm -> execute();
                    $kazancm = $kazancm->fetch(PDO::FETCH_ASSOC);

                    echo "Masa Sipariş Kazancı: ";
                    if( $kazancm['SUM(amount)']>0){echo  $kazancm['SUM(amount)']." TL";}else{echo "0 TL";}



                    ?>

                </h6>
            </div> 
        </div>                                                                                                          
    </div><!--end card-body-->
    <div class="card-body my-1">
        <div class="row">
            <div class="col">
                <div class="media">
                    <i data-feather="shopping-cart" class="align-self-center icon-md text-secondary mr-2"></i>
                    <div class="media-body align-self-center"> 
                        <h6 class="m-0 font-24"><?php 

                        $gunluks = $dbh->prepare("SELECT * FROM product_orders WHERE tarih<=CURDATE() && tarih>=DATE_SUB(CURDATE(),INTERVAL 0 DAY) ");
                        $gunluks -> execute();
                        $gunluks = $gunluks->fetch(PDO::FETCH_ASSOC);

                        echo count($gunluks);

                        ?></h6>
                        <p class="text-muted mb-0">Günlük Sipariş Sayısı</p>                                                                                                                                               
                    </div><!--end media body-->
                </div>
            </div><!--end col--> 
            <div class="col">
                <div class="media">
                    <i data-feather="bookmark" class="align-self-center icon-md text-secondary mr-2"></i>
                    <div class="media-body align-self-center"> 
                        <h6 class="m-0 font-24">

                            <?php 

                            $kazanca = $dbh->prepare("SELECT SUM(amount) FROM product_orders WHERE  odeme_durum=1 &&  month(tarih)=month(CURDATE()) and year(tarih)=year(CURDATE()) ");
                            $kazanca -> execute();
                            $kazanca = $kazanca->fetch(PDO::FETCH_ASSOC);

                            if( $kazanca['SUM(amount)']>0){echo  $kazanca['SUM(amount)']." TL";}else{echo "0 TL";}

                            ?>

                        </h6>
                        <p class="text-muted mb-0">Aylık Kazanç</p>                                                                                          
                    </div><!--end media body-->
                </div>
            </div><!--end col-->                                         
        </div><!--end row-->  
    </div><!--end card-body-->
</div><!--end card-->   
</div><!-- end col--> 
<div class="col-lg-6">
    <div class="card">   
        <div class="card-header">
            <div class="row align-items-center">
                <div class="col">                      
                    <h4 class="card-title">Ziyaretçi İstatislikleri Ayrıntıları (Son 10)</h4>                      
                </div><!--end col-->
                <div class="col-auto"> 
                    <div class="dropdown">
                        <a href="#" class="btn btn-sm btn-outline-light dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            Ayrıntılar<i class="las la-angle-down ml-1"></i>
                        </a>
                        <div class="dropdown-menu dropdown-menu-right">
                            <a class="dropdown-item" href="ziyaretci-log.php">Tümünü Göster</a> 
                        </div>
                    </div>          
                </div><!--end col-->
            </div>  <!--end row-->                                  
        </div><!--end card-header-->                                              
        <div class="card-body"> 
            <div class="analytic-dash-activity" data-simplebar>
                <div class="activity">
                 <?php
                 $visitorsorgu = $dbh->prepare("SELECT * FROM visitor_tracking ORDER BY entry_id DESC LIMIT 10 ");
                 $visitorsorgu->execute();

                 while ($visitorsonuc = $visitorsorgu->fetch()) {

                    $entry_id = $visitorsonuc['entry_id'];
                    $visitor_id = $visitorsonuc['visitor_id']; 
                    $ip_adress = $visitorsonuc['ip_address']; 
                    $page_name = $visitorsonuc['page_name'];
                    $date = $visitorsonuc['timestamp'];
                    $phpdate = strtotime( $date );
                    $mysqldate = date( 'd-m-Y ', $phpdate ); 
                    ?>
                    <div class="activity-info">
                        <div class="icon-info-activity">
                            <i class="las la-user-clock bg-soft-primary"></i>
                        </div>
                        <div class="activity-info-text">
                            <div class="d-flex justify-content-between align-items-center">
                                <p class="text-muted mb-0 font-13 w-75"><span><a data-toggle="tooltip" data-placement="top" title="Kayıt Numarası"><?=$visitorsonuc['entry_id'];?></a>-<a data-toggle="tooltip" data-placement="top" title="Ziyaretçi Kimlik Numarası"><?=$visitorsonuc['visitor_id'];?></a></span> 
                                   xxxxx ip adresine sahip ziyaretçi <?=$visitorsonuc['page_name'];?> sayfasına girmiştir.
                                </p>
                                <small class="text-muted"><a data-toggle="tooltip" data-placement="top" title="Kayıt Tarihi"><?=$mysqldate?></a>
                                </small>
                            </div>    
                        </div>
                    </div>   
                <?php } ?>                                                                                                            
            </div><!--end activity-->
        </div><!--end analytics-dash-activity-->
    </div>  <!--end card-body-->                                     
</div><!--end card--> 
</div><!--end col--> 

</div><!--end row-->



</div><!-- container -->

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



<script>
    <?
    /** @var PDO $dbh */
    $f = $dbh->prepare("select  count(distinct ip_address) as sayisi,DATE(timestamp) as tarih from visitor_tracking group by DATE(timestamp)");
    $fb = $f->execute();
    $strows=$f->fetchAll(PDO::FETCH_ASSOC);

    ?>
    var options = {

      series: [{
        name: "Ziyaretciler",
        data: ['<?
        $sayilar=[];
        $tarihler=[];
        foreach ($strows as  $value) {
         $sayilar[]=$value["sayisi"];
         $tarihler[]=$value["tarih"];
     }
     echo implode("','",$sayilar);
     ?>']
 }],
 chart: {
  height: 350,
  type: 'line',
  zoom: {
    enabled: false
}
},
dataLabels: {
  enabled: false
},
stroke: {
  curve: 'straight'
},
title: {
  text: '',
  align: 'left'
},
grid: {
  row: {
            colors: ['#f3f3f3', 'transparent'], // takes an array which will be repeated on columns
            opacity: 0.5
        },
    },
    xaxis: {
      categories: ['<?
      echo implode("','",$tarihler);
      ?>'],
  },
  yaxis:{
   floating: false,
   decimalsInFloat: undefined,
   labels: {
    "formatter": function (val) {
        return val.toFixed(0)
    }
}
}
};

var chart = new ApexCharts(document.querySelector("#zoomableTimeSces"), options);
chart.render();

</script>