Created
October 19, 2021 14:43
-
-
Save aceakash/942f7e3e040c536d785d40754131820f to your computer and use it in GitHub Desktop.
Extract payments by IBAN from UFX
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
/* | |
xq is from here: https://github.com/kislyuk/yq | |
xq '.' ./input-ufx.xml > input-ufx.json && node index.js | |
*/ | |
const fs = require('fs') | |
const ufxJsonFileName = "input-ufx.json" | |
const ufxJson = fs.readFileSync(ufxJsonFileName).toString() | |
const ufx = JSON.parse(ufxJson) | |
// console.log(ufx.DocFile.DocList.Doc.length) | |
const res = extractInfoByIBAN(ufx, ['SK8756000000000595036001', 'HU09107000246653035051100005', 'HU44101027183208810000000002']) | |
console.log(res) | |
function extractInfoByIBAN(ufx, ibans) { | |
const docList = ufx.DocFile.DocList.Doc | |
// console.log(docList[0]) | |
const mid = docList[0].Originator.ContractNumber | |
// console.log(docList[0].d.Transaction.Extra.AddData.Parm.ParmCode) | |
// console.log(d.Transaction.Extra.AddData.Parm.Value) | |
const filt = docList | |
.filter(d => { | |
const parms = d.Transaction.Extra.AddData.Parm | |
const matchedParms = parms.filter(p => p.ParmCode === 'IBAN' && inIBans(ibans, p.Value)) | |
return matchedParms.length > 0 | |
}) | |
.map(d => ({ | |
mid: d.Originator.ContractNumber, | |
currency: { | |
isoCode: d.Billing.Currency | |
}, | |
amount: d.Billing.Amount, | |
iban: extractIban(d.Transaction.Extra.AddData.Parm) | |
})) | |
return filt.sort(function(a, b) { | |
if (a.iban < b.iban) return -1 | |
if (a.iban > b.iban) return 1 | |
return 0 | |
}) | |
} | |
function inIBans(ibans, str) { | |
return ibans.filter(i => i == str).length > 0 | |
} | |
function extractIban(parms) { | |
return parms.filter(p => p.ParmCode === 'IBAN')[0].Value // todo what if not present | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment