How to access account balance & transactions

Any issue about Cyclos 4 scripting and Webservices

Moderators: rmvanarkel, hugo, alexandre

Post Reply
jakob.schumann
Posts: 20
Joined: Thu Apr 23, 2020 5:37 pm

How to access account balance & transactions

Post by jakob.schumann »

Hello!

For a scipt to calculate an account fee I need to access the accounts (current) balance or better: The balance at the start or end of a given month (for the edge case when a transaction was already made in the new month, before the account fee was processed).
I only found account.getClosedAccountBalances(), but this does not seem to contain a usefule balance? Do I have to use setLastBalanceClosingDate() first to set it to the end of the month to get a new balance? Or do I need an instance of org.cyclos.entities.banking.AccountBalance, if so: how do I get one for the current account?

Also I need to access all transactions for the account, but there seems no method for this on the org.cyclos.entities.banking.UserAccount. So I tried to use TransactionQuery as shown below:

Code: Select all

import org.cyclos.model.banking.transactions.TransactionQuery
import org.cyclos.model.users.users.UserVO

def trFilter = new TransactionQuery()
trFilter.setUser(new UserVO(account.owner.id))
def transactions = transactionService.search(trFilter)
But with this I only receive transactions triggered by the Owner, no incoming transactions and there seems to be no TransactionQuery.setAccount() or ways to limit the transactions to a time frame. How can I get all transactions for a given account in a given month?

Side question: How can I write log entries from scripts, like progress/debug messages? I've seen no class in https://documentation.cyclos.org/4.13/s ... mmary.html which seems suited for this.

Thanks in advance,
J.Schumann
jakob.schumann
Posts: 20
Joined: Thu Apr 23, 2020 5:37 pm

Re: How to access account balance & transactions

Post by jakob.schumann »

I figured the main part out using the accountService (running this code in Eclipse: https://gist.github.com/j-schumann/66f8 ... c995252b09)

What I find curious is the behaviour of getAccountBalanceHistory (https://documentation.cyclos.org/4.13/s ... oryParams-)

The docu says only days in a month where the balance changed are returned, but I receive 32 datapoints for 2020-04-01 to 2020-04-31 (one for each day in the month + 1 extra).
Also when expanding the requested period over two months (2020-03-01 - 2020-05-01) it automatically returns datapoints only in 1-week intervals (Which is somewhat expected from "The maximum number of data points cannot exceed 61") but nevertheless here also data points show up where the balance is unchanged.

Also the question of how to write to the log is still open for me.

Best regards,
JS
Post Reply