bkper / bkper-issues

Feature requests and enhancements to existing bkper modules can also be filed here.
https://bkper.com/
2 stars 0 forks source link

API Query Issue #23

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The following query works inside of the Bkper application:

'after:$m before:$m+1'

However, when attempting to use the same query for making a balance report, an 
error is thrown:

TypeError: Cannot read property "length" from null. (line 137, file "Report", 
project "BkperApp")

The code that generated the above error:

q = "=after:$m before:$m+1"
r = ledger.getBalanceReport(q)

Original issue reported on code.google.com by jmgil...@google.com on 17 Mar 2015 at 1:28

GoogleCodeExporter commented 8 years ago
I'm not able to reproduce the bug with the current version (167) of BkperApp. 
Are you using the latest one? If not, could you please upgrade to see if its 
already fixed?

Original comment by m...@nimbustecnologia.com.br on 19 Mar 2015 at 7:29

GoogleCodeExporter commented 8 years ago

Original comment by m...@nimbustecnologia.com.br on 19 Mar 2015 at 7:39

GoogleCodeExporter commented 8 years ago
The update seems to have fixed the original error. My current implementation 
looks like so:

report = ledger.getBalanceReport("=after:$m before:$m+1");
data = 
report.createDataTable().setBalanceType(BkperApp.BalanceType.TOTAL).build();

The result is an empty array (except the column names). Am I understanding this 
wrong? I would of expected the result to return the balance of all accounts for 
the current month.

Original comment by jmgil...@google.com on 19 Mar 2015 at 9:26

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
This is the expected behaviour. I don't know if it makes sense to return 
balances of all accounts.

If you get the groups balances, the accounts balances should come also.

You're trying to minimize the round trips, right? Maybe it makes more sense to 
create a method that supports many queries at once and keep the queries as 
simple as possible. What about that?

Original comment by kris...@nimbustecnologia.com.br on 19 Mar 2015 at 10:16

GoogleCodeExporter commented 8 years ago
Basically I'm just trying to reproduce what you guys have on the sidebar on the 
Bkper navigation where it lists all 'real' accounts and their respective 
balances. 

As far as I can tell the only way to do that currently is by making multiple 
queries which isn't terribly efficient.

Original comment by jmgil...@google.com on 19 Mar 2015 at 11:54

GoogleCodeExporter commented 8 years ago
Actually you can access all Account objects, and query its balances. Here is 
the code to reproduce the sidebar:

{{{
function listAccountBalances() {

  //Change your ledger id
  var ledger = BkperApp.openLedgerById("agtzfmJrcGVyLWhyZHIOCxIGTGVkZ2VyGNKJAgw");

  var accounts = ledger.getAccounts();
  for (var i=0; i < accounts.length; i++) {
    var account = accounts[i];
    if (account.isPermanent() && account.isActive()) {
      Logger.log(account.getName() + ": " + account.getBalance());
    } 
  }  
}

}}}

Here is the Script to play:

https://script.google.com/a/nimbustecnologia.com.br/d/1sRC0GV0AbWG_kpp1D4QOoK0qH
UMFur7sHbB7AbcTf84ge-UvEsrZF75i/edit

By the way, did you try the new Update and Auto-Update feature on Google Sheets 
Add-on? Now every fetch statement keeps connected to bkper, and you can update 
it anytime, or turn on auto update to keep its synchronized hourly. All data 
comes in a way to easily create charts. You can create advanced dashboards, its 
a way cool! 
We will publish a video about it soon.

Original comment by m...@nimbustecnologia.com.br on 20 Mar 2015 at 11:45

GoogleCodeExporter commented 8 years ago
Thank you, I had forgotten about that function.

Original comment by jmgil...@google.com on 24 Mar 2015 at 6:29

GoogleCodeExporter commented 8 years ago
I just updated the documentation to include this example:

http://about.bkper.com/api_appsScript.html#listAccountsBalances

I will close this Issue now.

Original comment by m...@nimbustecnologia.com.br on 24 Mar 2015 at 2:15