const fs = require('fs');

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

js = js.replace(
    /document\.getElementById\('voucher-status'\)\.value = \(window\.currentLinkedInvoiceId\) \? 'posted' : 'draft';/g,
    "document.getElementById('voucher-status').value = 'posted';"
);

fs.writeFileSync('vouchers_returns.js', js, 'utf8');

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

console.log('Voucher default set to posted!');
