
// Filter
function bwdcvFilterOrders() {
    const monthFilter = document.getElementById('bwdcv-month-filter').value.toLowerCase();
    const yearFilter = document.getElementById('bwdcv-year-filter').value;
    const rows = document.querySelectorAll('#bwdcv-order-table tbody tr');
    rows.forEach(row => {
        const dateCell = row.cells[3].textContent;
        const orderDate = new Date(dateCell);
        const month = orderDate.toLocaleString('default', { month: 'long' }).toLowerCase();
        const year = orderDate.getFullYear();
        const matchesMonth = monthFilter ? month.includes(monthFilter) : true;
        const matchesYear = yearFilter ? year.toString() === yearFilter : true;
        if (matchesMonth && matchesYear) {
            row.style.display = '';
        } else {
            row.style.display = 'none';
        }
    });
}
function bwdcvDownloadXLSX() {
    const table = document.getElementById('bwdcv-order-table');
    const wb = XLSX.utils.table_to_book(table, { sheet: "Orders" });
    XLSX.writeFile(wb, 'export-orders.xlsx');
}
document.getElementById('bwdcv-month-filter').addEventListener('change', bwdcvFilterOrders);
document.getElementById('bwdcv-year-filter').addEventListener('change', bwdcvFilterOrders);
document.getElementById('bwdcv-download-button').addEventListener('click', bwdcvDownloadXLSX);

// Export revenue
document.getElementById("bwdcv-popupBtn").addEventListener("click", function() {
    document.getElementById("bwdcv-popup").style.display = "flex";
});
function closePopup() {
    document.getElementById("bwdcv-popup").style.display = "none";
}
