/* ============================================================ EMPRESA > FINANCEIRO > GASTOS (categoria + recorrência) ============================================================ */ function PageGastos({ gastos, onSave, onDelete, onGerarRecorrentes }){ const [editing, setEditing] = useState(null); const editingObj = editing ? gastos.find(g=>g.id===editing) : null; const [busca, setBusca] = useState(''); const [desc,setDesc] = useState(''); const [valor,setValor] = useState(''); const [vencimento,setVencimento] = useState(''); const [categoria,setCategoria] = useState('Fixo'); const [recorrente,setRecorrente] = useState(false); useEffect(()=>{ if(editingObj){ setDesc(editingObj.desc); setValor(String(editingObj.valor)); setVencimento(editingObj.vencimento); setCategoria(editingObj.categoria||'Fixo'); setRecorrente(!!editingObj.recorrente); } else { setDesc(''); setValor(''); setVencimento(''); setCategoria('Fixo'); setRecorrente(false); } }, [editing]); function submit(e){ e.preventDefault(); if(!desc || valor==='' || !vencimento) return; onSave({ desc, valor:parseFloat(valor), vencimento, categoria, recorrente }, editing); setEditing(null); } const totalFixo = gastos.filter(g=>g.categoria==='Fixo').reduce((s,g)=>s+g.valor,0); const totalVariavel = gastos.filter(g=>g.categoria==='Variável').reduce((s,g)=>s+g.valor,0); return (

{editing?'Editar Gasto':'Novo Gasto'}

setDesc(e.target.value)} placeholder="Ex: Aluguel do escritório" required/>
setValor(e.target.value)} placeholder="0,00" required/>
setVencimento(e.target.value)} required/>
{editing && }

Gastos Cadastrados ({gastos.length})

setBusca(e.target.value)}/>
{[...gastos].filter(g=>!busca || g.desc.toLowerCase().includes(busca.toLowerCase())).sort((a,b)=>b.vencimento.localeCompare(a.vencimento)).map(g=>( ))} {gastos.length===0 && } {gastos.length>0 && busca && ![...gastos].some(g=>g.desc.toLowerCase().includes(busca.toLowerCase())) && }
DescriçãoValorVencimentoCategoria
{g.desc}{g.recorrente && recorrente} {fmtBRL(g.valor)} {new Date(g.vencimento+'T00:00:00').toLocaleDateString('pt-BR')} {g.categoria}
Nenhum gasto cadastrado.
Nenhum gasto encontrado com essa busca.
); }