import React, { useState, useEffect } from 'react'; // Header and SubHeader are now part of the global Layout import { DollarSign, TrendingUp, Calendar, ChevronDown, Activity, ShoppingCart, Package, AlertTriangle, Plus, History } from 'lucide-react'; export default function ReceptionistDashboard() { const [stats, setStats] = useState({ total_income: 0, total_expenses: 0, net_profit: 0, low_stock_count: 0 }); const [transactions, setTransactions] = useState([]); const [loading, setLoading] = useState(true); const [filterBranch, setFilterBranch] = useState(window.__APP_DATA__?.branch?.id || ''); const [startDate, setStartDate] = useState(new Date().toISOString().split('T')[0]); const [endDate, setEndDate] = useState(new Date().toISOString().split('T')[0]); const [branches, setBranches] = useState([]); useEffect(() => { // Fetch branches for the selector (even if disabled for receptionist) fetch('/api/branches?status=Active') .then(res => res.json()) .then(data => setBranches(data)) .catch(err => console.error("Error fetching branches:", err)); }, []); useEffect(() => { const fetchDashboardData = async () => { setLoading(true); try { const query = new URLSearchParams({ branch_id: filterBranch, start_date: startDate, end_date: endDate }); const response = await fetch(`/api/reports/profit?${query}`); const data = await response.json(); setStats({ total_income: data.total_income || 0, total_expenses: data.total_expense || 0, net_profit: data.net_profit || 0, low_stock_count: data.low_stock_count || 0 }); setTransactions(data.transactions || []); } catch (error) { console.error('Error fetching dashboard data:', error); } finally { setLoading(false); } }; fetchDashboardData(); }, [filterBranch, startDate, endDate]); const StatCard = ({ title, amount, icon: Icon, color, trend, iconColor, bgColor, textColor, label }) => (
{trend && (
{trend >= 0 ? : ''} {trend}%
)} {label && (
{label}
)}

{(amount || 0).toLocaleString('en-AE', { minimumFractionDigits: 0 })} {title === 'Low Stock Items' ? '' : 'AED'}

{title}

); const QuickAction = ({ icon: Icon, label, color, sublabel, path }) => ( ); if (loading) { return (
); } return (
{/* Welcome Section & Filters */}

Receptionist Dashboard

Branch Operations Overview

{/* Branch Selector (Hardcoded to their branch for receptionists) */}
{/* Date Range */}
From setStartDate(e.target.value)} className="bg-transparent border-none p-0 focus:ring-0 text-gray-700 outline-none w-28" />
To setEndDate(e.target.value)} className="bg-transparent border-none p-0 focus:ring-0 text-gray-700 outline-none w-28" />
{/* Stats Grid */}
{/* Quick Actions */}

Quick Actions

{/* Recent Transactions Table */}

Recent Transactions

{transactions.length > 0 ? ( transactions.slice(0, 10).map((tx, idx) => ( )) ) : ( )}
Date & Time Description Type Amount
{tx.date} {tx.time}

{tx.description}

{tx.type === 'Expense' ? 'DEBITED' : 'RECEIVED'} {tx.type === 'Expense' ? '-' : '+'} {(tx.amount || 0).toLocaleString('en-AE', { minimumFractionDigits: 2 })} AED

No transactions found

); }