{{-- Notification Dropdown Component --}} @php use App\Models\Order; $user = auth()->user(); $notifications = collect(); // Get recent activities based on user role if ($user->isDeveloper() || $user->isOwner()) { // Owner/Developer sees all recent activities $recentOrders = Order::with(['designer', 'cashier', 'operator']) ->latest() ->take(10) ->get(); foreach ($recentOrders as $order) { if ($order->finished_at && $order->finished_at->isToday()) { $notifications->push([ 'id' => 'prod-' . $order->id, 'icon' => 'check', 'color' => 'success', 'title' => 'Produksi Selesai', 'message' => $order->file_name . ' telah selesai diproduksi', 'time' => $order->finished_at->diffForHumans(), 'link' => route('orders.show', $order), ]); } elseif ($order->paid_at && $order->paid_at->isToday()) { $notifications->push([ 'id' => 'pay-' . $order->id, 'icon' => 'money', 'color' => 'success', 'title' => 'Pembayaran Diterima', 'message' => $order->invoice_number . ' - Rp ' . number_format($order->total_price, 0, ',', '.'), 'time' => $order->paid_at->diffForHumans(), 'link' => route('orders.show', $order), ]); } elseif ($order->created_at->isToday()) { $notifications->push([ 'id' => 'new-' . $order->id, 'icon' => 'plus', 'color' => 'brand', 'title' => 'Order Baru', 'message' => $order->file_name . ' dari ' . $order->customer_name, 'time' => $order->created_at->diffForHumans(), 'link' => route('orders.show', $order), ]); } } } elseif ($user->isDesigner()) { // Designer sees their orders that got paid $paidOrders = Order::where('designer_id', $user->id) ->whereNotNull('paid_at') ->whereDate('paid_at', today()) ->latest('paid_at') ->take(10) ->get(); foreach ($paidOrders as $order) { $notifications->push([ 'id' => 'pay-' . $order->id, 'icon' => 'money', 'color' => 'success', 'title' => 'Order Lunas', 'message' => $order->file_name . ' telah dibayar', 'time' => $order->paid_at->diffForHumans(), 'link' => route('orders.show', $order), ]); } } elseif ($user->isKasir()) { // Kasir sees pending payments $pendingOrders = Order::whereNull('paid_at') ->latest() ->take(10) ->get(); foreach ($pendingOrders as $order) { $notifications->push([ 'id' => 'pending-' . $order->id, 'icon' => 'money', 'color' => 'warning', 'title' => 'Menunggu Pembayaran', 'message' => $order->invoice_number . ' - Rp ' . number_format($order->total_price, 0, ',', '.'), 'time' => $order->created_at->diffForHumans(), 'link' => route('kasir.show', $order), ]); } } elseif ($user->isOperator()) { // Operator sees orders ready for production $pendingProduction = Order::whereNotNull('paid_at') ->where('production_status', 'pending') ->latest('paid_at') ->take(10) ->get(); foreach ($pendingProduction as $order) { $notifications->push([ 'id' => 'queue-' . $order->id, 'icon' => 'printer', 'color' => 'warning', 'title' => 'Antrian Cetak', 'message' => $order->file_name . ' - ' . $order->size, 'time' => $order->paid_at->diffForHumans(), 'link' => route('produksi.index'), ]); } // Also show in-progress orders $inProgress = Order::where('operator_id', $user->id) ->whereIn('production_status', ['proses_cetak', 'finishing']) ->latest('updated_at') ->take(5) ->get(); foreach ($inProgress as $order) { $notifications->push([ 'id' => 'prog-' . $order->id, 'icon' => 'printer', 'color' => 'brand', 'title' => $order->production_status === 'proses_cetak' ? 'Sedang Dicetak' : 'Finishing', 'message' => $order->file_name, 'time' => $order->updated_at->diffForHumans(), 'link' => route('produksi.index'), ]); } } // Sort by most recent and take max 8 $notifications = $notifications->take(8); $hasNotifications = $notifications->count() > 0; @endphp