use yew::prelude::*; use crate::components::accounting::models::*; #[derive(Properties, PartialEq)] pub struct OverviewTabProps { pub state: UseStateHandle, } #[function_component(OverviewTab)] pub fn overview_tab(props: &OverviewTabProps) -> Html { let state = &props.state; // Calculate totals let total_revenue: f64 = state.revenue_entries.iter().map(|r| r.total_amount).sum(); let total_expenses: f64 = state.expense_entries.iter().map(|e| e.total_amount).sum(); let net_profit = total_revenue - total_expenses; let pending_revenue: f64 = state.revenue_entries.iter() .filter(|r| r.payment_status == PaymentStatus::Pending) .map(|r| r.total_amount) .sum(); let pending_expenses: f64 = state.expense_entries.iter() .filter(|e| e.payment_status == PaymentStatus::Pending) .map(|e| e.total_amount) .sum(); html! {
// Key Statistics Cards
{"Pending Items"}

{format!("${:.2}", pending_revenue + pending_expenses)}

{format!("${:.2} revenue, ${:.2} expenses", pending_revenue, pending_expenses)}
{"Avg Invoice Value"}

{format!("${:.2}", total_revenue / state.revenue_entries.len() as f64)}

{format!("{} invoices total", state.revenue_entries.len())}
{"Tax Deductible"}

{format!("${:.2}", state.expense_entries.iter().filter(|e| e.is_deductible).map(|e| e.total_amount).sum::())}

{"100% of expenses deductible"}
{"Collection Rate"}

{"85.2%"}

{"Above industry avg"}
// Recent Transactions
{"Recent Transactions"}
{"Latest payments made and received"}
{if state.payment_transactions.is_empty() { html! {
{"No transactions recorded yet"}

{"Transactions will appear here once you record payments"}

} } else { html! {
{for state.payment_transactions.iter().take(10).map(|transaction| { let (transaction_type, reference, amount_color) = if let Some(invoice_id) = &transaction.invoice_id { ("Revenue", invoice_id.clone(), "text-success") } else if let Some(expense_id) = &transaction.expense_id { ("Expense", expense_id.clone(), "text-danger") } else { ("Unknown", "N/A".to_string(), "text-muted") }; html! { } })}
{"Date"} {"Type"} {"Reference"} {"Amount"} {"Method"} {"Status"} {"Notes"}
{&transaction.date}
{&transaction.id}
{transaction_type}
{&reference}
{if let Some(hash) = &transaction.transaction_hash { html! { {&hash[..12]}{"..."} } } else if let Some(ref_num) = &transaction.reference_number { html! { {ref_num} } } else { html! {} }}
{if transaction_type == "Revenue" { "+" } else { "-" }} {format!("${:.2}", transaction.amount)}
{transaction.payment_method.to_string()}
{transaction.status.to_string()} {&transaction.notes}
} }}
} }