const fs = require('fs');

let accountingCode = fs.readFileSync('d:/برنامج مخازن/accounting_module.js', 'utf8');

const setupStart = accountingCode.indexOf('function setupUserUI() {');
const setupEnd = accountingCode.indexOf('// --- ACCOUNTING & JOURNALS LOGIC ---');

if (setupStart !== -1 && setupEnd !== -1) {
    accountingCode = accountingCode.substring(0, setupStart) + accountingCode.substring(setupEnd);
    fs.writeFileSync('d:/برنامج مخازن/accounting_module.js', accountingCode);
    console.log("Removed duplicate setupUserUI from accounting_module.js");
} else {
    console.log("Could not find setupUserUI in accounting_module.js");
}

let indexCode = fs.readFileSync('d:/برنامج مخازن/index.html', 'utf8');
const ts = Date.now();
indexCode = indexCode.replace(/src="accounting_module\.js(\?v=[^"]*)?"/, `src="accounting_module.js?v=${ts}"`);
fs.writeFileSync('d:/برنامج مخازن/index.html', indexCode);
console.log("Cache busted for accounting_module.js");
