Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QUESTION: how to break up a transaction/payment? #107

Open
ketzacoatl opened this issue Mar 22, 2022 · 12 comments
Open

QUESTION: how to break up a transaction/payment? #107

ketzacoatl opened this issue Mar 22, 2022 · 12 comments

Comments

@ketzacoatl
Copy link

I have a question about how to use hledger-flow with this situation:

For some of my transactions, I would like to break them down into a group of transactions that are together. For example, if I shop at the hardware store and purchase some tools, and then some supplies for different projects, I'd like to be able to see the high-level transaction for all of those items, the taxes, etc, with the hardware store, but then also be able to see that $X was spent for project1 and $Y was spent for project2 while $Z was spent on tools.

AFAICT, this is possible to do in the PTA journal, but is there a way to do this with hledger-flow's csv imports?

If this is a new feature, I'd be happy to help contribute code to make it work, but would greatly appreciate some guidance / feedback on the best way to extend hledger-flow for this new feature.

@apauley
Copy link
Owner

apauley commented Mar 22, 2022

Hi @ketzacoatl

This sounds like something that you would structure with hledger subaccounts, using the normal hledger rules files.

And I think tags could also be useful here.

@ketzacoatl
Copy link
Author

Thanks for the super fast reply @apauley!

If I may ask, could you clarify what that would look like with a small example?

@apauley
Copy link
Owner

apauley commented Mar 22, 2022

Sure, I was just looking through my own rules files.

This contrived example can be put in a rules file. It has both a subaccount and a tag for ProjectA - you may not need both though. It all depends on how you'd want to query it.

if
someregex
  account2 expenses:Supplies:ProjectA
  comment project: ProjectA

@ketzacoatl
Copy link
Author

One thing I'm not understanding is what the csv entries would look like. Using my example above, ATM I have only one transaction for the top-level interaction with the hardware store, but I'm not sure how to tell hledger-flow about the breakdown for that one transaction into the several smaller ones that make it up.

@apauley
Copy link
Owner

apauley commented Mar 22, 2022

You can specify multiple accounts and amounts when you want to do a breakdown of one transaction:

if
someregex
  comment project: ProjectA
  account2 expenses:Supplies:ProjectA
  amount2 80
  account3 expenses:Supplies:ProjectA:Tax
  amount3 20

@ketzacoatl
Copy link
Author

That's in the rules file?

Ok, that seems a little odd though, no?

Eg for each trx that gets a breakdown like this, I'd need to add a unique ID or something, and then add an entry in the rules file.. or am I missing something?

@apauley
Copy link
Owner

apauley commented Mar 23, 2022

Yes, this is in the rules file. There are lots of cool options:
https://hledger.org/hledger.html#csv-rules

I don't understand what you mean by "unique ID", are you talking about the regex/matcher?
In your example you may need a regex/matcher that uniquely matches your transaction, and then you need to specify the breakdown.

In my rules files I mostly have matchers that match multiple transactions, e.g. one matcher for groceries. And in a few specific cases I match just one unique transaction when I want to do something different with it.

I do this kind of multi-account breakdown on my salary, to specify which is spent on taxes and which is allocated to the retirement benefit etc.

@ketzacoatl
Copy link
Author

I don't understand what you mean by "unique ID", are you talking about the regex/matcher?
In your example you may need a regex/matcher that uniquely matches your transaction, and then you need to specify the breakdown.

Yes

I do this kind of multi-account breakdown on my salary, to specify which is spent on taxes and which is allocated to the retirement benefit etc.

Nice, can you share a redacted/example csv entry and rule pair that demonstrate this? That would help me understand what pieces are in this puzzle.

Thank you!

@ketzacoatl
Copy link
Author

hledger seems to have support for accountN/amountN, for 1..9 - simonmichael/hledger#1095. Could that be exposed/used from hledge-flow import csv processing?

@apauley
Copy link
Owner

apauley commented Apr 3, 2022

Hi @ketzacoatl - hledger-flow already exposes all of the hledger functionality you mention. hledger-flow just runs hledger with a specific rules file.

Here is a fuller example, where someone gets paid 100 gold pieces in total, but just 40 of those gold pieces are paid into the bank account after taxes and benefits are kept back.

Given a csv line from the bank:

"20220125","MyCompany 1234-XYZ Salary","40"

And a rules file:

fields date, description, amount

date-format %Y%m%d

currency XAU

account1 assets:Liquid:MyBankAccount

if
MyCompany.*Salary
  account2 income:Salary:Gross
  amount2  -100.00
  account3 assets:Fixed:Pension
  amount3  20
  account4 expenses:Tax:Income:Salary
  amount4  40

You'll get the following generated journal:

$ hledger print --rules-file /tmp/t.rules -f /tmp/t.csv
2022-01-25 MyCompany 1234-XYZ Salary
    assets:Liquid:MyBankAccount        XAU40.00
    income:Salary:Gross              XAU-100.00
    assets:Fixed:Pension               XAU20.00
    expenses:Tax:Income:Salary         XAU40.00

Note that this example is 100% hledger, nothing specific to hledger-flow.

hledger-flow will guide you into where you should place your rules files for which account etc, but inside the rules file it is just normal hledger stuff.

@ketzacoatl
Copy link
Author

@apauley,

Thank you for taking the time to explain these details to me.

hledger-flow already exposes all of the hledger functionality you mention. hledger-flow just runs hledger with a specific rules file.

Does this mean the account2...N and such are also available in the csv file, if specified as a field in the rules file? I think one thing I've been confused about in your examples have been the 2nd/etc amounts down in the rules file instead of being in the csv data.

@apauley
Copy link
Owner

apauley commented Apr 4, 2022

If you are lucky enough to have the information needed for a breakdown in your CSV files, then you can match on that for your accountN and amountN postings.

In practice I've only seen that when some institutions report a transaction fee in one of the fields, in addition to the amount.

What is in your CSV files?

Usually only the net amount is present in my CSV lines.
So in the salary example, I only see "40 gold pieces" in the CSV line, but I know this isn't the gross salary, and I know that there are benefits and taxes that aren't reported in the CSV data.
So I manually put the extra information in my rules file.

The hledger docs point to some examples.:
https://github.com/simonmichael/hledger/tree/master/examples/csv
https://github.com/simonmichael/hledger/blob/master/examples/csv/amazon-orders.csv.rules
https://github.com/simonmichael/hledger/blob/master/examples/csv/stripe.csv.rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants