const fs = require('fs');

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

// Fix saveAbstract
const badSaveLine = "gross_value: getNumText('ab-total-works'),";
const goodSaveLine = "gross_value: getNumText('ab-current-works'),\n            curr_works: getNumText('ab-current-works'),";

code = code.replace(badSaveLine, goodSaveLine);

// Fix generateSubcontractAbstractJournal
const badGrossLine = "const gross = parseFloat(a.gross_value) || 0;";
const goodGrossLine = "const gross = parseFloat(a.curr_works) || parseFloat(a.gross_value) || 0;";

code = code.replace(badGrossLine, goodGrossLine);

fs.writeFileSync('subcontracts.js', code, 'utf8');

let indexHtml = fs.readFileSync('index.html', 'utf8');
indexHtml = indexHtml.replace(/v=20260610u/g, 'v=20260610v');
fs.writeFileSync('index.html', indexHtml, 'utf8');

console.log('Fixed gross value for subcontract journals');
