`;
tbody.appendChild(row);
});
}
// (Omiti as funções updateExpenses, updateRevenues, updateDRE e updateIndicators por brevidade,
// MAS ELAS DEVEM SER MANTIDAS NO CÓDIGO - apenas certifique-se de que elas usam a variável 'transactions' global
// e chamam formatCurrency sem passar o config.currency_symbol se ele for padrão 'R$')
// ... Certifique-se de manter as funções de renderização do DRE e Indicadores aqui ...
function updateAllViews() {
updateDashboard();
updateCashflowTable();
updateExpenses(); // Certifique-se que essa função existe no seu código original
updateRevenues(); // Certifique-se que essa função existe no seu código original
updateDRE(); // Certifique-se que essa função existe no seu código original
updateIndicators(); // Certifique-se que essa função existe no seu código original
}
function updateCurrentTabData() {
switch (currentTab) {
case 'dashboard': updateDashboard(); break;
case 'cashflow': updateCashflowTable(); break;
case 'expenses': updateExpenses(); break;
case 'revenues': updateRevenues(); break;
case 'dre': updateDRE(); break;
case 'indicators': updateIndicators(); break;
}
}
// Inicialização
function init() {
document.getElementById('trans-date').value = new Date().toISOString().split('T')[0];
document.getElementById('current-period').textContent = getCurrentPeriod();
document.getElementById('filter-month').value = new Date().toISOString().slice(0, 7);
const currentYear = new Date().getFullYear();
['dashboard-year', 'expense-year', 'revenue-year', 'indicators-year', 'dre-year'].forEach(id => {
const yearSelect = document.getElementById(id);
if (yearSelect) {
for (let i = currentYear - 5; i <= currentYear + 1; i++) {
const option = document.createElement('option');
option.value = i;
option.textContent = i;
if (i === currentYear) option.selected = true;
yearSelect.appendChild(option);
}
}
});
document.getElementById('dre-month').value = 'all';
// Listeners
document.getElementById('trans-type').addEventListener('change', updateCategories);
document.getElementById('trans-category').addEventListener('change', updateSubcategories);
document.getElementById('trans-payment').addEventListener('change', updateInstallmentsVisibility);
document.getElementById('transaction-form').addEventListener('submit', addTransaction);
document.getElementById('filter-month').addEventListener('change', updateCashflowTable);
// Filtros
['dashboard', 'expense', 'revenue', 'indicators'].forEach(prefix => {
document.getElementById(`${prefix}-month`)?.addEventListener('change', updateCurrentTabData);
document.getElementById(`${prefix}-year`)?.addEventListener('change', updateCurrentTabData);
});
document.getElementById('dre-month')?.addEventListener('change', updateDRE);
document.getElementById('dre-year')?.addEventListener('change', updateDRE);
}
init();