// Home / Dashboard — monthly totals, quick actions, recent pedidos function HomeScreen({ vendedora, pedidos, onNewOrder, onOpenPedido, onGoList, onOpenCatalog, onGoPagos, onLogout }) { const T = window.T; const { Icon, ProductTile, StatusPill } = window; // Debt — usa Supabase si está disponible (con fallback a loadBilling local) const billing = window.useBilling ? window.useBilling(vendedora?.id) : { state: window.loadBilling ? window.loadBilling() : { facturas: [], pagos: [] }, loading: false }; const state = billing.state; const mine = { f: state.facturas, p: state.pagos }; const deuda = window.totalDeuda ? window.totalDeuda(mine.f, mine.p) : 0; const vencida = window.totalDeudaVencida ? window.totalDeudaVencida(mine.f, mine.p) : 0; // stats const now = new Date(); const thisMonth = pedidos.filter(p => p.fechaCreacion.getMonth() === now.getMonth() && p.fechaCreacion.getFullYear() === now.getFullYear()); const totalMes = thisMonth.reduce((s, p) => s + p.productos.reduce((a, x) => a + x.precio * x.cantidad, 0), 0); const numMes = thisMonth.length; const commission = totalMes * 0.18; // mock commission const goal = 600; const pct = Math.min(100, Math.round((totalMes / goal) * 100)); const firstName = (vendedora?.nombre || '').split(' ')[0] || ''; const fmtMoney = (n) => '$' + n.toFixed(2); return (
{/* Header */}
Inova · {vendedora?.zona}
{firstName[0]?.toUpperCase() || 'M'}
Hola, {firstName}{vendedora?.badge === 'puntual' && 👑}
{new Date().toLocaleDateString('es', { weekday: 'long', day: 'numeric', month: 'long' })}
{/* Deuda banner — aparece si tiene deuda */} {deuda > 0 && (
)} {/* Hero metric card */}
{/* decorative serif mark */}
In
Total del mes
${totalMes.toFixed(2)}
{numMes} {numMes === 1 ? 'pedido' : 'pedidos'} · comisión est. {fmtMoney(commission)}
{/* Progress to goal */}
Meta {fmtMoney(goal)} {pct}%
{/* Quick actions */}
{/* Recent orders */}
Ver todo } />
{pedidos.slice(0, 3).map(p => { const total = p.productos.reduce((s, x) => s + x.precio * x.cantidad, 0); const items = p.productos.reduce((s, x) => s + x.cantidad, 0); return ( ); })}
{/* Insight strip */}
Vas 23% arriba de abril pasado
Esika lidera tus ventas este mes
); } window.HomeScreen = HomeScreen;