<?php
include "config.php";
session_start();
	if($_SESSION['status']!="index"){
		header("location:index.php");
	}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Toko Wawan</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" href="assets/img/kasir.ico" type="image/ico">
  <link href="assets/fontawesome/css/all.min.css" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="assets/DataTables/datatables.min.css"/>
  <link rel="stylesheet" href="assets/css/bootstrap.min.css">
  <link rel="stylesheet" href="assets/css/style.css">
 
 
  <style>
  .btn-group-xs > .btn, .btn-xs {
  padding: .25rem .4rem;
  font-size: .875rem;
  line-height: .5;
  border-radius: .2rem;
}
.card{
  border: none;
  border-radius: 15px;
  box-shadow: 0 6px 20px rgb(17 26 104 / 10%);
}
.card-header{
  border-radius: 15px 15px 0px 0px !important;
}
.form-control{
  border-radius: 15px;
}
.btn{
  border-radius: 15px;
}
button.buttons-html5{
  padding: .25rem .4rem !important;
  font-size: .875rem !important;
  line-height: .5 !important;
}
.bg-purple {
  background: linear-gradient(to right, #6a11cb, #2575fc) !important;
}
.text-purple {
  color: #6a11cb !important;
}
  </style>
</head>
<body>

<nav class="navbar navbar-expand-lg navbar-dark bg-purple text-white shadow-sm sticky-top d-md-none d-lg-none d-xl-none">
  <a class="navbar-brand" href=""><i class="fa fa-shopping-cart mr-1"></i><b>
  <?php 
      $toko = mysqli_query($conn,"SELECT * FROM login ORDER BY nama_toko ASC");
      while($dat = mysqli_fetch_array($toko)){
        $nama_toko = $dat['nama_toko'];
        echo "$nama_toko";
      }
          ?></b></a>
  <button class="navbar-toggler border-0" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <i class="fa fa-bars"></i>
  </button>
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link putih" href="index.php"><i class="fa fa-desktop mr-2"></i>Kasir</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link putih" href="barang.php"><i class="fa fa-shopping-bag mr-2"></i>Barang</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link putih" href="laporan.php"><i class="fa fa-table mr-2"></i>Laporan</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link putih" href="pengaturan.php"><i class="fa fa-cog mr-2"></i>Pengaturan</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link putih" href="logout.php" onclick="javascript:return confirm('Anda yakin ingin keluar ?');"><i class="fa fa-power-off mr-2"></i>Keluar</a>
                    </li>
                </ul>
            </div>
</nav>

<div class="bg-purple text-center py-2 shadow-sm sticky-top d-none d-md-block">
<a class="navbar-brand text-white" href=""><i class="fa fa-shopping-cart mr-1"></i><b>
  <?php 
      $toko = mysqli_query($conn,"SELECT * FROM login ORDER BY nama_toko ASC");
      while($dat = mysqli_fetch_array($toko)){
        $nama_toko = $dat['nama_toko'];
        $userr = $dat['user'];
        echo "$nama_toko";
      }
          ?></b></a>
</div>
<br>

<div class="container-fluid">

  <div class="row">
  
    <div class="col-md-3 mb-2 d-none d-md-block">
        <div class="card">
            <div class="card-header bg-purple">
                <div class="card-tittle text-white">Hallo, <b><?php echo $userr ?></b></div>
            </div>
            <div class="card-body">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="index.php"><i class="fa fa-desktop text-purple mr-2"></i>Kasir</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="barang.php"><i class="fa fa-shopping-bag text-purple mr-2"></i>Barang</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="laporan.php"><i class="fa fa-table text-purple mr-2"></i>Laporan</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="pengaturan.php"><i class="fa fa-cog text-purple mr-2"></i>Pengaturan</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="logout.php"onclick="javascript:return confirm('Anda yakin ingin keluar ?');"><i class="fa fa-power-off text-purple mr-2"></i>Keluar</a>
                    </li>
                </ul>
                <!-- Form Pendapatan Hari Ini di bawah row -->
                <div class="row mt-3">
                  <div class="col-md-12">
                    <div class="card shadow">
                      <div class="card-header bg-purple text-white">
                        <h6 class="mb-0">Pendapatan Per Hari</h6>
                      </div>
                      <div class="card-body text-center p-3">
                        <?php
                          $tanggal_hari_ini = date('Y-m-d');
                          $query_total = mysqli_query($conn, "
                              SELECT SUM((harga_barang * quantity) - diskon) AS total_setelah_diskon
                              FROM laporanku
                              WHERE DATE(tgl_input) = '$tanggal_hari_ini'
                          ") or die("Query error: " . mysqli_error($conn));

                          $data_total = mysqli_fetch_assoc($query_total);
                          $total_hari_ini = $data_total['total_setelah_diskon'] ?? 0;
                        ?>
                        <h5 class="text-purple mb-0">Rp <?= number_format($total_hari_ini, 0, ',', '.'); ?></h5>
                        <small class="text-muted">
                          <?php
                            // Tanggal hari ini
                            $tanggal_hari_ini = date('Y-m-d');

                            // Ambil hari dalam bahasa Inggris
                            $hariInggris = date('l', strtotime($tanggal_hari_ini));
                            // Ubah ke Bahasa Indonesia
                            $namaHari = [
                              'Sunday' => 'Minggu',
                              'Monday' => 'Senin',
                              'Tuesday' => 'Selasa',
                              'Wednesday' => 'Rabu',
                              'Thursday' => 'Kamis',
                              'Friday' => 'Jumat',
                              'Saturday' => 'Sabtu'
                            ][$hariInggris];

                            // Ambil bulan (1-12)
                            $bulan = date('n', strtotime($tanggal_hari_ini));
                            // Ubah ke Bahasa Indonesia
                            $namaBulan = [
                              1 => 'Januari', 2 => 'Februari', 3 => 'Maret', 4 => 'April',
                              5 => 'Mei', 6 => 'Juni', 7 => 'Juli', 8 => 'Agustus',
                              9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Desember'
                            ][$bulan];

                            // Tanggal dan tahun
                            $tanggal = date('j', strtotime($tanggal_hari_ini));
                            $tahun = date('Y', strtotime($tanggal_hari_ini));

                            echo "$namaHari, $tanggal $namaBulan $tahun";
                          ?>
                        </small>
                      </div>
                    </div>
                  </div>
                </div>
         </div>
    </div>
  </div>
  
  