const fs = require('fs');

if (fs.existsSync('app_final.js')) {
    let js = fs.readFileSync('app_final.js', 'utf8');
    
    // Add exclusion for financial transactions in renderInvoices
    const oldFilter = `if ((t.type === 'sales' || t.type === 'purchases') && (t.status === 'draft' || t.status === 'pending_store')) return false;
        return true;`;
        
    const newFilter = `if ((t.type === 'sales' || t.type === 'purchases') && (t.status === 'draft' || t.status === 'pending_store')) return false;
        if (t.type === 'receipt' || t.type === 'payment' || t.type === 'money_transfer') return false;
        return true;`;

    js = js.replace(oldFilter, newFilter);
    fs.writeFileSync('app_final.js', js, 'utf8');
    console.log('Patched app_final.js successfully');
}

// Cache buster
let html = fs.readFileSync('index.html', 'utf8');
html = html.replace(/v=\d+/g, 'v=' + Date.now());
fs.writeFileSync('index.html', html, 'utf8');
