tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/7592-subaccount-balanceInfinite Kind: Discussion 2022-11-16T01:27:11Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/567342122022-11-11T20:06:17Z2022-11-11T20:06:17Zsubaccount balance<div><p>You have to get the transactions for that account/cat, filter them, and total the txns for the month in question to get the result.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/567342122022-11-11T20:17:51Z2022-11-11T20:34:09Zsubaccount balance<div><p>E.g.</p>
<pre>
<code>class MyTxnSearch(TxnSearch):
def __init__(self): pass
def matchesAll(self): return True
txnSet = book.getTransactionSet().getTransactions(MyTxnSearch())</code>
</pre>
<p>You can either put the search criteria in MyTxnSearch or just iterate the resulting txns.</p>
<p>E.g. for txn in txnSet..</p>
<p>You need to check txn.getDateInt()<br>
and total txn.getValue()</p>
<p>if you want balance, just total all within the date. If you wanted cleared balance, you need to check the cleared status too.</p>
<p>Hope this helps?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/567342122022-11-12T02:36:38Z2022-11-12T02:36:38Zsubaccount balance<div><p>Helps a great deal, thanks. For the next person, here's my <code>TxnSearch</code> in Java for searching by date:</p>
<pre>
<code>public class SearchByDate implements TxnSearch {
private Account acct;
private int startDate;
private int endDate;
public SearchByDate(Account acct, int start, int end) {
this.acct = acct;
this.startDate = start;
this.endDate = end;
}
@Override
public boolean matches(Txn arg0) {
if (arg0.getAccount().compareToAccount(this.acct) == 0) {
int d = arg0.getDateInt();
if (startDate <= d && d <= endDate) {
return true;
}
}
return false;
}
@Override
public boolean matchesAll() {
return false;
}
}</code>
</pre>
<p>And using it:</p>
<pre>
<code>SearchByDate txns = new SearchByDate(acct,startDate, endDate);
TxnSet txnset = acct.getBook().getTransactionSet().getTransactions(txns);
// iterate over txnset to sum `getValue()` for each transaction.</code>
</pre></div>andy