<?php
    include 'session.php';
    include 'style.php';
    include 'navbar.php'; 
?> 


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Add icon library -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  border: 1px solid #ddd;
}

th, td {
  text-align: left;
  padding: 5px;
  font-size: 12px;
}

table tr:hover td {
            background-color: #e7f3fe;
        }



.pagination a {
  color: black;
  float: left;
  padding: 8px 16px;
  text-decoration: none;
  transition: background-color .3s;
  background-color: #e7f3fe;
}

.pagination a.active {
  background-color: dodgerblue;
  color: white;
}

.pagination a:hover:not(.active) {background-color: #ddd;}

input[type=text], select {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  display: block;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: medium;
}

.btn {
  background-color: DodgerBlue;
  border: none;
  color: white;
  padding: 6px 8px;
  font-size: 14px;
  cursor: pointer;
}

/* Darker background on mouse-over */
.btn:hover {
  background-color: RoyalBlue;
}

.success {background-color: #04AA6D;} /* Green */
.info {background-color: #2196F3;} /* Blue */
.warning {background-color: #ff9800;} /* Orange */
.danger {background-color: #f44336;} /* Red */ 
.other {background-color: #e7e7e7; color: black;} /* Gray */ 

</style>
<?php
$no=1;
$status=0;
$nama='';
$isi='';
$jawaban='';
$petugas='';
$jabatan='';


$username = $_SESSION['username'];

?>
<head>
</head>
<body>

<div style="overflow-x:auto;">
<table border=3>
<form action="admlist.php" method="GET">
<button id="myBtn"  hidden>Button</button>
<button id="myBtn1"  hidden>Button</button>
<button id="myBtn2"  hidden>Button</button>
<button id="myBtn3"  hidden>Button</button>
  <tr>

    <div class="topnav">
    <div class="search-container">

    </div>
    </div>
    <th></th>
    <th></th>
  </tr>
</form>
<tr>
  <?php
        function tglIndonesia($indo_tgl){
          $tr   = trim($indo_tgl);
          $indo_tgl    = str_replace(array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), array('Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jum\'at', 'Sabtu', 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'), $tr);
          return $indo_tgl;
        }

        $jum_roti = 0;

        $query_sql_flight = "SELECT DISTINCT DATE_FORMAT(order_datetime, '%d-%m-%Y') AS tanggal,
                            DATE_FORMAT(order_datetime, '%a, %d-%m-%Y') AS tanggal_format
                            FROM produk_temp
                                LEFT JOIN order_data ON order_no = temp_master
                                WHERE order_datetime IS NOT NULL
                                AND (DATE_FORMAT(order_datetime, '%Y-%m-%d') >= DATE_FORMAT(NOW(),'%Y-%m-%d'))
                            ORDER BY order_datetime ASC";
        $result_flight = mysqli_query($conn, $query_sql_flight);
        while($mas_flight = mysqli_fetch_array($result_flight)){
            $jum_roti = 0;
            $tanggal_format = tglIndonesia($mas_flight["tanggal_format"]);
            echo "<tr bgcolor='#FFA800' align='center'>";
            echo "<th colspan=100>&nbsp;&nbsp;<font size=4>$tanggal_format (Update)</th>";
            echo "</tr>";
            ?>
            </tr>
            <tr bgcolor="#d1d1d1" align="center">
                <th><font size=4>No</th>
                <th><font size=4>Barang</th>
                <th><font size=4>Jumlah</th>
                <th></th>
            </tr>
            <?php

           

                  $query_sql = "SELECT produk_nama, SUM(temp_jumlah) as jumlah,
                                produk_jenis,
                                order_kirim
                                FROM produk_temp 
                                    LEFT JOIN order_data ON order_no = temp_master
                                    LEFT JOIN produk ON produk_id = temp_produk
                                WHERE DATE_FORMAT(order_datetime, '%d-%m-%Y') LIKE ('$mas_flight[tanggal]')
                                AND (DATE_FORMAT(order_datetime, '%Y-%m-%d') >= DATE_FORMAT(NOW(),'%Y-%m-%d'))
                                AND order_kirim = 0
                                GROUP BY produk_nama";
                  $result = mysqli_query($conn, $query_sql);
                  while($mas = mysqli_fetch_array($result)){
                  if ($mas['produk_jenis']==2) {
                    $jum_roti=$jum_roti+$mas['jumlah'];
                  }
                  ?>
                      <tr>
                        <td align="center"><font size=4><?=$no++?></td>
                        <td><font size=4><?php echo $mas['produk_nama']?></td>
                        <td><font size=4><?php echo $mas['jumlah']?></td>
                      </tr>
                  <?php
                  
                  }$no=1;
            ?>      
            <tr bgcolor="#d1d1d1" align="center">
                <th colspan=4><font size=4>Jumlah Roti : <?php echo $jum_roti; ?></th>

            </tr>
            <tr bgcolor="#d1d1d1" align="center">
                <th colspan=4><font size=4>Jam cetak : <?php 
                    date_default_timezone_set('Asia/Jakarta');
                    echo date("h:i:s"); 
                ?></th>

            </tr>
            <?php
        }    
                ?>
        

</table>
</div>

    
</body>
</html>

<script>
var input = document.getElementById("myInput");
    input.addEventListener("keypress", function(event) {
    if (event.key === "Enter") {
        event.preventDefault();
        document.getElementById("myBtn").click();
    }
});

var input = document.getElementById("myInput1");
    input.addEventListener("keypress", function(event) {
    if (event.key === "Enter") {
        event.preventDefault();
        document.getElementById("myBtn1").click();
    }
});

var input = document.getElementById("myInput2");
    input.addEventListener("keypress", function(event) {
    if (event.key === "Enter") {
        event.preventDefault();
        document.getElementById("myBtn2").click();
    }
});

var input = document.getElementById("myInput3");
    input.addEventListener("keypress", function(event) {
    if (event.key === "Enter") {
        event.preventDefault();
        document.getElementById("myBtn3").click();
    }
});
</script>
