const fs = require('fs');

try {
    let spJs = fs.readFileSync('d:/برنامج مخازن/sales_purchases_module.js', 'utf8');

    // Replace window.balancesCache with balancesCache
    spJs = spJs.replace(/typeof window\.balancesCache/g, "typeof balancesCache");
    spJs = spJs.replace(/window\.balancesCache\[/g, "balancesCache[");

    fs.writeFileSync('d:/برنامج مخازن/sales_purchases_module.js', spJs, 'utf8');

    let html = fs.readFileSync('d:/برنامج مخازن/index.html', 'utf8');
    const version = Date.now().toString();
    html = html.replace(/v=\d+/g, 'v=' + version);
    fs.writeFileSync('d:/برنامج مخازن/index.html', html, 'utf8');

    console.log('Fixed balancesCache reference!');
} catch (e) {
    console.error(e);
}
