async function getBalanceActivity(balanceId, startDate, endDate) {
// Get debits (as source)
const debits = await fetch('/transactions/filter', {
method: 'POST',
body: JSON.stringify({
filters: [
{ field: 'source', operator: 'eq', value: balanceId },
{ field: 'status', operator: 'eq', value: 'APPLIED' },
{ field: 'created_at', operator: 'between', values: [startDate, endDate] }
],
include_count: true
})
}).then(r => r.json());
// Get credits (as destination)
const credits = await fetch('/transactions/filter', {
method: 'POST',
body: JSON.stringify({
filters: [
{ field: 'destination', operator: 'eq', value: balanceId },
{ field: 'status', operator: 'eq', value: 'APPLIED' },
{ field: 'created_at', operator: 'between', values: [startDate, endDate] }
],
include_count: true
})
}).then(r => r.json());
return {
balance_id: balanceId,
period: { start: startDate, end: endDate },
debits: {
count: debits.total_count,
total: debits.data.reduce((sum, t) => sum + t.amount, 0),
transactions: debits.data
},
credits: {
count: credits.total_count,
total: credits.data.reduce((sum, t) => sum + t.amount, 0),
transactions: credits.data
}
};
}