query($query); $data['today_transactions'] = ($result->num_rows > 0) ? $result->fetch_assoc()['count'] : 0; // Today's items sold $query = "SELECT SUM(total_item) as count FROM transaksi WHERE DATE(tanggal) = '$today'"; $result = $conn->query($query); $data['today_items'] = ($result->num_rows > 0) ? $result->fetch_assoc()['count'] : 0; if ($data['today_items'] === NULL) $data['today_items'] = 0; // This week's transactions $startOfWeek = date('Y-m-d', strtotime('this week monday')); $query = "SELECT COUNT(*) as count FROM transaksi WHERE tanggal BETWEEN '$startOfWeek' AND '$today'"; $result = $conn->query($query); $data['week_transactions'] = ($result->num_rows > 0) ? $result->fetch_assoc()['count'] : 0; // Total products in inventory $query = "SELECT COUNT(*) as count FROM barang"; $result = $conn->query($query); $data['total_products'] = ($result->num_rows > 0) ? $result->fetch_assoc()['count'] : 0; // Count low stock items (stok <= 10) $query = "SELECT COUNT(*) as count FROM barang WHERE stok <= 10"; $result = $conn->query($query); $data['low_stock_count'] = ($result->num_rows > 0) ? $result->fetch_assoc()['count'] : 0; return $data; } // Function to get recent transactions function getRecentTransactions($conn, $limit = 5) { $query = "SELECT t.kode_transaksi, t.tanggal, t.total_item, t.status FROM transaksi t ORDER BY t.tanggal DESC LIMIT $limit"; $result = $conn->query($query); $transactions = array(); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $transactions[] = $row; } } return $transactions; } // Function to get popular products - FIXED to ensure it gets the most recent data function getPopularProducts($conn, $limit = 10) { // Use current date to ensure we get the latest data $today = date('Y-m-d'); $startOfWeek = date('Y-m-d', strtotime('this week monday')); // Modified query to join with detail_transaksi directly on id_transaksi $query = "SELECT b.kode_barang, b.nama_barang, SUM(dt.jumlah) as total_quantity FROM detail_transaksi dt JOIN transaksi t ON dt.id_transaksi = t.id_transaksi JOIN barang b ON dt.id_barang = b.id_barang WHERE t.tanggal BETWEEN '$startOfWeek' AND NOW() GROUP BY b.id_barang ORDER BY total_quantity DESC LIMIT $limit"; $result = $conn->query($query); $products = array(); if ($result && $result->num_rows > 0) { while($row = $result->fetch_assoc()) { $products[] = $row; } } return $products; } // Function to get low stock items function getLowStockItems($conn, $threshold = 10, $limit = 5) { $query = "SELECT kode_barang, nama_barang, stok FROM barang WHERE stok <= $threshold ORDER BY stok ASC LIMIT $limit"; $result = $conn->query($query); $lowStockItems = array(); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $lowStockItems[] = $row; } } return $lowStockItems; } // Get dashboard data $dashboardData = getEmployeeDashboardData($conn); $recentTransactions = getRecentTransactions($conn); $popularProducts = getPopularProducts($conn); $lowStockItems = getLowStockItems($conn); // Get user activity count (simplified) $userActivityQuery = "SELECT COUNT(*) as count FROM transaksi WHERE tanggal > DATE_SUB(NOW(), INTERVAL 30 DAY)"; $userActivityResult = $conn->query($userActivityQuery); $userActivity = ($userActivityResult->num_rows > 0) ? $userActivityResult->fetch_assoc()['count'] : 0; // Recent products $recentProductsQuery = "SELECT kode_barang, nama_barang, harga FROM barang ORDER BY created_at DESC LIMIT 5"; $recentProductsResult = $conn->query($recentProductsQuery); $recentProducts = array(); if ($recentProductsResult->num_rows > 0) { while($row = $recentProductsResult->fetch_assoc()) { $recentProducts[] = $row; } } // Close database connection $conn->close(); ?> Ayula Store - Dashboard

Selamat Datang, !

Ringkasan aktivitas toko hari ini,

Transaksi Hari Ini

Item Terjual Hari Ini

Total unit terjual

Transaksi Minggu Ini

Produk Stok Menipis

Perlu perhatian

Transaksi Terbaru
Lihat Semua
0): ?>

item

Belum ada transaksi hari ini

Transaksi baru akan muncul di sini

Stok Menipis
Lihat Semua
0): ?>
Kode Nama Produk Stok Status
Kritis Menipis
Semua Produk Memiliki Stok Memadai

Tidak ada produk yang stoknya menipis saat ini

10 Produk Terlaris Minggu Ini
Detail Lengkap
0): ?>

#
Total Terjual: unit
0): ?>

#
Total Terjual: unit
Belum Ada Data Penjualan

Produk terlaris akan ditampilkan saat ada penjualan