Created
March 16, 2022 12:22
-
-
Save konijn/7f4d5538eebe37e42a3cdaef53c3cd91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Statement Date<input id="statementDate" type="date"></input> | |
Statement Start<input id="statementStart" type="number"></input> | |
<button id="go" >Go!</button> | |
<textarea id="mt940" cols="120" rows="50"> | |
:20:ACME2203100000001 | |
:28C:6789/1 | |
:60F:C220310USD0,00 | |
:61:2203100310C2000,00NTRF00000000//00000000 | |
0 | |
:86:00000000 0 | |
:62F:C220310USD2000,00 | |
:64:C220310USD2000,00 | |
- | |
:20:ACME2203100000002 | |
:28C:69/1 | |
:60F:C220310USD0,00 | |
:61:2203100310C2000,00NTRF00000000//00000000 | |
0 | |
</textarea> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reformatFile(){ | |
let start = statementStart.value; | |
let date = statementDate.value; | |
const lines = mt940.value.split("\n"); | |
//Fix the start number | |
if(start){ | |
for(let i= 0 ; i < lines.length; i++){ | |
if(lines[i].startsWith(':28C:')){ | |
lines[i] = `:28C:${(start++)}/${lines[i].split('/').pop()}`; | |
} | |
} | |
} | |
if(date){ | |
date = date.split("-").join("").substring(2); | |
for(let i= 0 ; i < lines.length; i++){ | |
if(lines[i].startsWith(':20:') || | |
lines[i].startsWith(':60F:') || | |
lines[i].startsWith(':61:') || | |
lines[i].startsWith(':62F:') || | |
lines[i].startsWith(':64:')){ | |
lines[i] = lines[i].replace(/\d{6}/,date); | |
} | |
} | |
} | |
mt940.value = lines.join("\n"); | |
console.log(mt940.value); | |
} | |
go.addEventListener("click", reformatFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment