@accounter/server
Version:
Accounter GraphQL server
24 lines • 886 B
JavaScript
export function identifyInterestTransactionIds(transactions, opts) {
const { getId, getChargeId, getAmount } = opts;
const chargeGroups = new Map();
for (const row of transactions) {
const chargeId = getChargeId(row);
if (!chargeId)
continue;
const arr = chargeGroups.get(chargeId) ?? [];
arr.push(row);
if (!chargeGroups.has(chargeId))
chargeGroups.set(chargeId, arr);
}
const interestIds = new Set();
for (const [, txs] of chargeGroups) {
if (txs.length > 1) {
const sorted = [...txs].sort((a, b) => Math.abs(getAmount(b)) - Math.abs(getAmount(a)));
for (let i = 1; i < sorted.length; i++) {
interestIds.add(getId(sorted[i]));
}
}
}
return interestIds;
}
//# sourceMappingURL=bank-deposit-ledger-generation.helper.js.map