document.addEventListener('DOMContentLoaded', function() { const addBillForm = document.getElementById('addBillForm'); if (addBillForm) { addBillForm.addEventListener('submit', function(e) { e.preventDefault(); const formData = new FormData(this); axios.post('/api/add-bill', formData) .then(function(response) { console.log('Bill added successfully'); loadBills(); }) .catch(function(error) { console.error('Error adding bill:', error); }); }); } // Load bills if on the dashboard page if (document.getElementById('billsTable')) { loadBills(); } // Event delegation for dynamically added "Mark as Paid" buttons document.addEventListener('click', function(e) { if (e.target && e.target.matches('.mark-bill-paid-btn')) { const billId = e.target.getAttribute('data-bill-id'); axios.post('/api/mark-bill-paid', { id: billId }) .then(function(response) { console.log('Bill marked as paid successfully'); loadBills(); }) .catch(function(error) { console.error('Error marking bill as paid:', error); }); } }); }); function loadBills() { const billsTableBody = document.querySelector('#billsTable tbody'); billsTableBody.innerHTML = '