37Rb / nextcloud-hledger

Plain Text Accounting on Nextcloud
GNU Affero General Public License v3.0
13 stars 2 forks source link

Make reports more flexible #8

Open 37Rb opened 3 years ago

37Rb commented 3 years ago

Let the user change dates, add filter criteria, etc...

thecount2a commented 3 years ago

One idea to avoid having to make a super complex UI while allowing flexible reporting would be to allow custom reports to be defined by "argument files." To see what an "argument file" is, browse to the hledger manual https://hledger.org/hledger.html and string search the page for the string "argument file". If you put @FILENAME as a command-line argument to hledger, it will read command-line arguments from FILENAME, in addition to any that you manually pass.

My idea would go something like this: allow users to to define a particular "custom reports" directory in their nextcloud, just as the journal file and budget file is currently defined. Any files inside the custom reports folder would be scanned by this extension code and each one would be listed in the UI as a custom report, using the file name as a label. For instance, I could define a file inside my custom reports directory called "Monthly Food Expenses this year" and that file would contain:

balance -pthis year -M -T Expenses:Food

The nextcloud report runner would simply need to add the CSV output argument onto the command and then run it, since the nextcloud report runner parses CSV to turn it into a HTML table.

Additionally, if this idea works out well, we could even make the pre-canned reports be defined in a similar way, to allow users to customize the pre-canned reports or use them as a model for understanding how reports are defined.

37Rb commented 3 years ago

@thecount2a I just saw this. Apparently notifications were disabled by default in my new github account. Good idea!

thecount2a commented 3 years ago

Hi @37Rb, do you have a branch where you've done any more work on this? I saw your most recent commit and I'd be willing to help out, since I know you've been busy lately with a new job. I just don't want to miss out on any in-progress code you might have. Thanks!

37Rb commented 3 years ago

@thecount2a I don't. Everything I've done is in master. The new job and life have been crazy for the past couple months.

I have been using the nextcloud app 100% for my personal accounting. I can honestly say it's easier than using hledger-ui to enter transactions! At least for my personal workflow.

I started working on this issue and got stuck on how to implement it. I think your idea of using argument files is good but I ran into some mental blocks thinking through it. Honestly it's been so long I forget what they were.

If you want to take this one over, by all means please do. :) Maybe I can move on to one of the others.

thecount2a commented 3 years ago

Just did a commit 5f95201d87cff017f48f67eba5cea853b600924a which implements this. All you need to do is add a file to an Hledger folder in nextcloud that ends in .args.txt or .report.txt and it will display it as a "custom report" in the UI. Balance_Sheet.args.txt, Income_Statement.args.txt, and/or Budget.args.txt can all be created and can override the behavior of the canned default reports. The new custom report functionality will detect whether any ledger files have been defined using "--file=" or "-f=" options within the custom reports and if not, it will use the default ledger files.

Here is an example of how the UI has changed: 2021-08-25-141035_1236x387_scrot

Here are how some of the reports were defined to get this behavior: 2021-08-25-141135_746x206_scrot 2021-08-25-141221_713x273_scrot 2021-08-25-141329_668x222_scrot