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 || '');
// Default to current month for a better overview
const [startDate, setStartDate] = useState(new Date(new Date().getFullYear(), new Date().getMonth(), 1).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.today_income || 0, // Using today's actual income
total_expenses: data.monthly_expense || 0, // Using monthly actual expenses
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 */}
{/* Stats Grid */}
{/* Quick Actions */}
{/* Recent Transactions Table */}
| Date & Time |
Description |
Type |
Amount |
{transactions.length > 0 ? (
transactions.slice(0, 10).map((tx, idx) => (
|
{tx.date}
{tx.time}
|
{tx.description}
|
{tx.type === 'Expense' ? 'DEBITED' : 'RECEIVED'}
|
{tx.type === 'Expense' ? '-' : '+'}
{(tx.amount || 0).toLocaleString('en-AE', { minimumFractionDigits: 2 })}
AED
|
))
) : (
|
|
)}
);
}