<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Mengatur Resep</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600&display=swap" rel="stylesheet">
<style>
        body { font-family: 'Poppins', sans-serif; background-color: #fcfcfc; margin: 0; }
        .main-wrapper { display: flex; height: 100vh; overflow: hidden; }

        /* SIDEBAR */
        .sidebar { 
            width: 240px; 
            background: #fff;
            border-right: 1px solid #eee; 
            display: flex; 
            flex-direction: column; 
            padding: 25px 0;
            flex-shrink: 0;
            height: 100vh;
        }
        
        .brand { font-size: 22px; font-weight: 700; padding: 0 25px 30px; letter-spacing: -0.5px; }
        
        .nav-menu { list-style: none; padding: 0; flex-grow: 1; }
        .nav-item { padding: 2px 25px; }
        
        /* LINK DEFAULT (Warna hitam, bukan abu-abu) */
        .nav-link { 
            text-decoration: none; 
            color: #333 !important; 
            font-size: 14px; 
            padding: 12px 15px; 
            border-radius: 8px; 
            display: flex; 
            align-items: center; 
            transition: 0.2s;
        }

        /* KOTAK HIJAU SAAT AKTIF */
        .nav-link.active { 
            background: #28a745 !important; /* Hijau Solid */
            color: #fff !important;         /* Teks Putih agar kontras */
            font-weight: 600; 
        }

        /* Mencegah warna biru bawaan bootstrap saat diklik/focus */
        .nav-link:hover { background: #f8f9fa; }
        .nav-link:focus { background: transparent; }
        .nav-link.active:hover { background: #28a745 !important; }

        .nav-link i { margin-right: 12px; width: 18px; font-size: 15px; }
        
        .sidebar-footer { padding: 0 25px; }
        .logout-btn { 
            background: none; border: none; color: #dc3545; font-size: 14px; 
            padding: 10px 15px; cursor: pointer; display: flex; align-items: center; width: 100%;
        }
        .logout-btn i { margin-right: 12px; }

        .content { flex-grow: 1; padding: 20px 40px; overflow-y: auto; height: 100vh; }

        .card-stat { border: 1px solid #eee; border-radius: 8px; padding: 15px; background: #fff; }
        .table-card { border: 1px solid #eee; border-radius: 8px; background: #fff; }
        .btn-outline-secondary { border-color: #dee2e6; color: #6c757d; }
        .btn-outline-secondary.active { background-color: #e9ecef; color: #000; }

        /* Styling Header yang rapi */
        .top-header { 
            display: flex; 
            justify-content: space-between; 
            align-items: center; 
            margin-bottom: 30px; 
            padding-bottom: 20px;
            border-bottom: 2px solid #eee;
            /* Menarik garis ke kiri dan kanan agar menembus padding konten */
            margin-left: -40px;  
            margin-right: -40px; 
            
            /* Memberi padding agar isi header tidak ikut menempel ke pinggir */
            padding-left: 40px;  
            padding-right: 40px;
        }
        .search-bar { 
            width: 350px; 
            padding: 8px 15px; 
            border: 1px solid #ddd; 
            border-radius: 8px; 
            font-size: 14px;
            background: #fdfdfd;
        }
        .user-panel { display: flex; align-items: center; gap: 20px; }
        
    </style>
</head>
<body>

    <div class="main-wrapper">
    <div class="sidebar">
        <div class="brand">TEH TARIK 99</div>
        
        <ul class="nav-menu">
            <li class="nav-item">
                <a href="/admin/dashboard" class="nav-link <?php echo e(request()->is('admin/dashboard') ? 'active' : ''); ?>">
                    <i class="fa fa-home"></i> Dashboard
                </a>
            </li>
            <li class="nav-item">
                <a href="/admin/produk" class="nav-link <?php echo e(request()->is('admin/produk') ? 'active' : ''); ?>">
                    <i class="fa fa-box"></i> Produk
                </a>
            </li>
            <li class="nav-item">
                <a href="/admin/resep" class="nav-link <?php echo e(request()->is('admin/resep') ? 'active' : ''); ?>">
                    <i class="fa fa-cubes"></i> Atur Resep
                </a>
            </li>
            <li class="nav-item">
                <a href="/admin/kontrol-stok" class="nav-link <?php echo e(request()->is('admin/kontrol-stok') ? 'active' : ''); ?>">
                    <i class="fa fa-list-check"></i> Kontrol Stok
                </a>
            </li>
            <li class="nav-item">
                <a href="/admin/laporan" class="nav-link <?php echo e(request()->is('admin/laporan') ? 'active' : ''); ?>">
                    <i class="fa fa-chart-line"></i> Laporan
                </a>
            </li>
        </ul>

        <div class="sidebar-footer">
            <a href="#" class="nav-link"><i class="fa-solid fa-user"></i> Profil</a>
            <form action="<?php echo e(route('logout')); ?>" method="POST">
                <?php echo csrf_field(); ?>
                <button type="submit" class="logout-btn"><i class="fa-solid fa-right-from-bracket"></i> Keluar</button>
            </form>
        </div>
    </div>

    <div class="content">
        <div class="top-header">
            <form id="formSearch" action="/admin/laporan" method="GET" class="d-flex">
                <input type="hidden" name="tab" value="<?php echo e(request('tab', 'pendapatan')); ?>">
                <?php if(request('tgl_mulai')): ?><input type="hidden" name="tgl_mulai" value="<?php echo e(request('tgl_mulai')); ?>"><?php endif; ?>
                <?php if(request('tgl_selesai')): ?><input type="hidden" name="tgl_selesai" value="<?php echo e(request('tgl_selesai')); ?>"><?php endif; ?>
                <?php if(request('pembayaran')): ?><input type="hidden" name="pembayaran" value="<?php echo e(request('pembayaran')); ?>"><?php endif; ?>
                <input type="text" id="inputSearch" name="search" class="search-bar" 
                    placeholder="Cari no. transaksi, produk, kasir..." 
                    value="<?php echo e(request('search')); ?>">
            </form>
            <div class="user-panel d-flex align-items-center gap-3">
                <i class="fa-solid fa-bell fs-5"></i>
                <div class="text-end" style="line-height: 1.2;">
                    <div class="fw-bold small"><?php echo e(auth()->user()->name); ?></div>
                    <div class="text-muted" style="font-size: 0.7rem;">Kasir</div>
                </div>
                <img src="https://ui-avatars.com/api/?name=<?php echo e(urlencode(auth()->user()->name)); ?>&background=448b39&color=fff" 
                    class="user-avatar" style="width: 40px; height: 40px; border-radius: 50%;">
            </div>
        </div>

        <div class="main-scroll">
            <?php if(session('success')): ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <?php echo e(session('success')); ?>

                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            <?php endif; ?>

    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h4 class="fw-bold m-0">Laporan Penjualan</h4>
            <?php
                date_default_timezone_set('Asia/Jakarta');
                $jam = (int)date('H');
                if ($jam >= 18) { $ucapan = "Selamat Malam"; }
                elseif ($jam >= 15) { $ucapan = "Selamat Sore"; }
                elseif ($jam >= 11) { $ucapan = "Selamat Siang"; }
                else { $ucapan = "Selamat Pagi"; }

                $hari = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu'];
                $bulan = ['', 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
                $tanggalLengkap = $hari[date('w')] . ', ' . date('d') . ' ' . $bulan[date('n')] . ' ' . date('Y');
            ?>
            <p class="text-muted small m-0">
                <?php echo e($tanggalLengkap); ?> | <?php echo e($ucapan); ?>, <?php echo e(auth()->user()->name); ?>

            </p>
        </div>

        <form method="GET" action="/admin/laporan" class="d-flex align-items-end gap-2">
            <input type="hidden" name="tab" value="<?php echo e(request('tab', 'pendapatan')); ?>">
            
            <div style="width: 150px;">
                <label class="small fw-bold text-muted mb-1">MULAI</label>
                <input type="date" name="tgl_mulai" class="form-control" value="<?php echo e(request('tgl_mulai')); ?>">
            </div>
            <div style="width: 150px;">
                <label class="small fw-bold text-muted mb-1">SELESAI</label>
                <input type="date" name="tgl_selesai" class="form-control" value="<?php echo e(request('tgl_selesai')); ?>">
            </div>

            <?php if(request('tab') == 'barang'): ?>
                <div style="width: 180px;">
                    <label class="small fw-bold text-muted mb-1">PILIH PRODUK</label>
                    <select name="produk_id" class="form-control">
                        <option value="">Semua Produk ▽</option>
                        <?php $__currentLoopData = $semuaProduk; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($p->nama_produk); ?>"><?php echo e($p->nama_produk); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
            <?php else: ?>
                <div style="width: 180px;">
                    <label class="small fw-bold text-muted mb-1">PEMBAYARAN</label>
                    <select name="pembayaran" class="form-select">
                        <option value="">Semua Pembayaran</option>
                        <option value="Tunai" <?php echo e(request('pembayaran') == 'Tunai' ? 'selected' : ''); ?>>Tunai</option>
                        <option value="QRIS" <?php echo e(request('pembayaran') == 'QRIS' ? 'selected' : ''); ?>>QRIS</option>
                    </select>
                </div>
            <?php endif; ?>

            <button type="submit" class="btn btn-success" style="height: 38px;">
                <i class="fa-solid fa-filter"></i>
            </button>
        </form>
    </div>

    <div class="row mb-4">
        <?php if(request('tab') == 'barang'): ?>
            <div class="col-md-4">
                <div class="card p-3 shadow-sm border-0" style="border-radius: 12px;">
                    <small class="text-muted">TOTAL TERJUAL</small>
                    <h4 class="fw-bold m-0"><?php echo e($totalTerjual ?? 0); ?> Item</h4>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card p-3 shadow-sm border-0 " style="border-radius: 12px; ">
                    <small class="text-muted ">PRODUK TERLARIS</small>
                    <h4 class="fw-bold m-0 " title="<?php echo e($namaProdukTerlaris); ?>">
                        <?php echo e($namaProdukTerlaris ?? '-'); ?>

                    </h4>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card p-3 shadow-sm border-0" style="border-radius: 12px;">
                    <small class="text-muted">TOTAL PENDAPATAN</small>
                    <h4 class="fw-bold m-0">Rp <?php echo e(number_format($totalPendapatan, 0, ',', '.')); ?></h4>
                </div>
            </div>
        <?php else: ?>
            <div class="col-md-4">
                <div class="card p-3 shadow-sm border-0" style="border-radius: 12px;">
                    <small class="text-muted">TOTAL PENDAPATAN</small>
                    <h4 class="fw-bold m-0">Rp <?php echo e(number_format($totalPendapatan, 0, ',', '.')); ?></h4>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card p-3 shadow-sm border-0" style="border-radius: 12px;">
                    <small class="text-muted">TOTAL TRANSAKSI</small>
                    <h4 class="fw-bold m-0"><?php echo e($totalTransaksi); ?></h4>
                </div>
            </div>
            <div class="col-md-4">
                <div class="card p-3 shadow-sm border-0" style="border-radius: 12px;">
                    <small class="text-muted">RATA-RATA PER TRANSAKSI</small>
                    <h4 class="fw-bold m-0">Rp <?php echo e(number_format($rataRata, 0, ',', '.')); ?></h4>
                </div>
            </div>
        <?php endif; ?>
    </div>

    <div class="card p-4 shadow-sm border-0" style="border-radius: 12px;">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div class="d-flex gap-2">
                <a href="<?php echo e(route('admin.laporan', array_merge(request()->query(), ['tab' => 'pendapatan']))); ?>" class="btn <?php echo e(request('tab', 'pendapatan') == 'pendapatan' ? 'btn-success' : 'btn-outline-secondary'); ?>">
                    Laporan Pendapatan
                </a>
                <a href="<?php echo e(route('admin.laporan', array_merge(request()->query(), ['tab' => 'barang']))); ?>" class="btn <?php echo e(request('tab') == 'barang' ? 'btn-success' : 'btn-outline-secondary'); ?>">
                    Laporan Per Barang
                </a>
            </div>
            <div class="d-flex gap-2">
                <a href="<?php echo e(route('admin.laporan.export_excel', request()->query())); ?>" class="btn btn-outline-success">
                    <i class="fa-solid fa-file-excel me-1"></i> Ekspor Excel
                </a>
                <a href="<?php echo e(route('admin.laporan.export_pdf', request()->query())); ?>" class="btn btn-outline-danger">
                    <i class="fa-solid fa-file-pdf me-1"></i> Ekspor PDF
                </a>
            </div>
        </div>

        <table class="table table-hover">
            <thead>
                <tr>
                    <th>NO</th>
                    <th>TANGGAL & WAKTU</th>
                    <?php if(request('tab') == 'barang'): ?>
                        <th>NAMA PRODUK</th>
                        <th>JUMLAH ITEM</th>
                        <th>HARGA SATUAN</th>
                        <th>TOTAL PENDAPATAN</th>
                    <?php else: ?>
                        <th>NO. TRANSAKSI</th>
                        <th>JUMLAH ITEM</th>
                        <th>METODE PEMBAYARAN</th>
                        <th>TOTAL BAYAR</th>
                    <?php endif; ?>
                    <th>AKSI</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $semuaDetail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td><?php echo e($index + 1); ?></td>
                    <td><?php echo e(($item->transaksi ? $item->transaksi->created_at : $item->created_at)->format('d M Y, H:i')); ?></td>
                    
                    <?php if(request('tab') == 'barang'): ?>
                        <td><?php echo e($item->nama_produk); ?></td>
                        <td><?php echo e($item->qty); ?></td>
                        <td>Rp <?php echo e(number_format($item->harga_satuan, 0, ',', '.')); ?></td>
                    <?php else: ?>
                        <td>TRX-<?php echo e(str_pad($item->transaksi_id, 5, '0', STR_PAD_LEFT)); ?></td>
                        <td><?php echo e($item->qty); ?></td>
                        <td><?php echo e($item->transaksi->metode_pembayaran ?? 'Tunai'); ?></td>
                    <?php endif; ?>
                    
                    <td class="fw-bold text-primary">Rp <?php echo e(number_format($item->qty * $item->harga_satuan, 0, ',', '.')); ?></td>
                    <td>
                        <button class="btn btn-sm btn-outline-primary btn-detail" 
                                data-id="<?php echo e($item->transaksi_id); ?>">
                            <i class="fa fa-eye"></i>
                        </button>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
        <div class="d-flex justify-content-between align-items-center mt-3">
            <div class="text-muted small">
                Menampilkan <?php echo e($semuaDetail->firstItem() ?? 0); ?> sampai <?php echo e($semuaDetail->lastItem() ?? 0); ?> dari <?php echo e($semuaDetail->total()); ?> data
            </div>
            <div>
                <?php echo e($semuaDetail->appends(request()->input())->links('pagination::bootstrap-4')); ?>

            </div>
        </div>
    </div>

    <div class="modal fade" id="detailModal" tabindex="-1">
        <div class="modal-dialog modal-lg">
            <div class="modal-content" id="modalContent">
                </div>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
    $(document).on('click', '.btn-detail', function() {
        let id = $(this).data('id');
        console.log("ID yang dikirim: " + id); // Cek di Inspect Element > Console
        
        $('#modalContent').html('<div class="modal-body text-center">Memuat data...</div>');
        $('#detailModal').modal('show');
        
        $.ajax({
            url: '/admin/laporan/detail/' + id,
            type: 'GET',
            success: function(data) {
                $('#modalContent').html(data);
            },
            error: function(xhr, status, error) {
                console.error(xhr.responseText); // Cek error di Console
                $('#modalContent').html('<div class="modal-body text-danger">Gagal memuat data. Error: ' + error + '</div>');
            }
        });
    });
    </script>
</body>
</html><?php /**PATH C:\xampp\htdocs\tehtarik\resources\views/admin/laporan.blade.php ENDPATH**/ ?>