const fs = require('fs');
let js = fs.readFileSync('vouchers_returns.js', 'utf8');

const lines = js.split('\n');
for (let i = 0; i < lines.length; i++) {
    if (lines[i].includes('const cashParent = currentAccounts.find')) {
        lines[i] = "  const cashParent = currentAccounts.find(a => a.name.includes('صول') || a.name.includes('نقدية') || a.name.includes('خزن') || a.name.includes('بنك') || a.name.includes('اصول') || a.name.includes('أصول'));";
    }
}

fs.writeFileSync('vouchers_returns.js', lines.join('\n'), 'utf8');

// Also update cache buster in index.html to ensure the client gets the new js file
let html = fs.readFileSync('index.html', 'utf8');
html = html.replace(/v=\d+/g, 'v=' + Date.now());
fs.writeFileSync('index.html', html, 'utf8');

console.log('Fixed quickAddTreasury successfully');
