Re: Reducing repetition/duplication of amount value in entries

2023-06-18 Thread Viraj Alankar
Just a followup, there is now an example in the manual:

https://ledger-cli.org/doc/ledger3.html#Credit-Card-Cashback

Thanks to my pull request reviewer Alexis for helping clean it up.

On Sat, Jun 10, 2023 at 9:36 PM John Wiegley  wrote:

> > "VA" == Viraj Alankar  writes:
>
> VA> Something I was a bit confused about. If I change the automated
> VA> transaction to:
>
> VA> = "Liabilities:Apple Card" and has_tag("cashback")
>
> This is a bug in the query parser, which you can see by running:
>
>   ledger query '"Liabilities:Apple Card" and has_tag("cashback")'
>
> It seems that %cashback also has a bug, but it’s harmless and so you don’t
> notice the problem.
>
> The query parser needs an overhaul.
>
> John
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAM502dNdQg34-zD5MDwUvZBkYVn%2BJB_2Em-XKO9aEkqvejJAdw%40mail.gmail.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-10 Thread John Wiegley
> "VA" == Viraj Alankar  writes:

VA> Something I was a bit confused about. If I change the automated
VA> transaction to:

VA> = "Liabilities:Apple Card" and has_tag("cashback")

This is a bug in the query parser, which you can see by running:

  ledger query '"Liabilities:Apple Card" and has_tag("cashback")'

It seems that %cashback also has a bug, but it’s harmless and so you don’t
notice the problem.

The query parser needs an overhaul.

John

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/m2pm63w1s0.fsf%40newartisans.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-10 Thread Viraj Alankar
Sure, I'll make a pull request.

Something I was a bit confused about. If I change the automated transaction
to:

= "Liabilities:Apple Card" and has_tag("cashback")

It doesn't seem to work. There is no error, it just doesn't apply the
transaction. Do you happen to know the right way to use has_tag() here?

Thanks,

Viraj.





On Fri, Jun 9, 2023 at 9:14 PM John Wiegley  wrote:

> > "VA" == Viraj Alankar  writes:
>
> VA> I found one way that I think should work:
> VA> = "Liabilities:Apple Card" and %cashback
> VA> Assets:Apple Cash   (-tag("cashback"))
> VA> Income:Credit Card Rewards   (tag("cashback"))
>
> VA> 2023/06/06 McDonalds
> VA> ; cashback:: 0.02
> VA> Expenses:Food:Restaurants   $23.98
> VA> Liabilities:Apple Card
> VA> 2023/06/07 Transfer
> VA> Liabilities:Apple Card  $23.98
> VA> Assets:Some bank
>
> VA> Mainly found by searching bugs. The manual would really benefit with
> some
> VA> more realistic examples in the Automated Transactions section.
>
> Interesting example! Please feel free to submit it as an addition to the
> docs,
> if you’d be willing.
>
> John
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAM502dPODwCWuNWjM9bx0xt4UU2_pdp5BkdCxDitsDbmoULyUQ%40mail.gmail.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-09 Thread John Wiegley
> "VA" == Viraj Alankar  writes:

VA> I found one way that I think should work:
VA> = "Liabilities:Apple Card" and %cashback
VA> Assets:Apple Cash   (-tag("cashback"))
VA> Income:Credit Card Rewards   (tag("cashback"))

VA> 2023/06/06 McDonalds
VA> ; cashback:: 0.02
VA> Expenses:Food:Restaurants   $23.98
VA> Liabilities:Apple Card
VA> 2023/06/07 Transfer
VA> Liabilities:Apple Card  $23.98
VA> Assets:Some bank

VA> Mainly found by searching bugs. The manual would really benefit with some
VA> more realistic examples in the Automated Transactions section.

Interesting example! Please feel free to submit it as an addition to the docs,
if you’d be willing.

John

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/m2o7lompl5.fsf%40newartisans.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-09 Thread Viraj Alankar
I found one way that I think should work:

= "Liabilities:Apple Card" and %cashback
Assets:Apple Cash   (-tag("cashback"))
Income:Credit Card Rewards   (tag("cashback"))

2023/06/06 McDonalds
; cashback:: 0.02
Expenses:Food:Restaurants   $23.98
Liabilities:Apple Card
2023/06/07 Transfer
Liabilities:Apple Card  $23.98
Assets:Some bank

Mainly found by searching bugs
.
The manual would really benefit with some more realistic examples in
the Automated
Transactions
 section.

Thanks,

Viraj.


On Thu, Jun 8, 2023 at 4:55 PM Yuri Khan  wrote:

> On Thu, 8 Jun 2023 at 21:28, Viraj Alankar  wrote:
>
> > What would be right way to do apply the automatic transaction only when
> there is also an Expenses entry? I could not figure out the proper syntax.
> I tried something like:
> >
> > = expr "any(account =~ /^Liabilities:Apple Card/) and any(account =~
> /^Expenses/)"
> >
> > but this does not seem to work. I get some errors if I try removing the
> quotes, but I'm likely doing it wrong.
>
> You might instead apply cashback only where the amount is negative.
> But I’m struggling with complex condition syntax too, so maybe someone
> else will chime in.
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Ledger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ledger-cli/tqXZGjJbZSo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ledger-cli+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ledger-cli/CAP_d_8VuMoRwog1834ZnuXzQayrf074sx7_hApctjxEc%2BgcrEw%40mail.gmail.com
> .
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAM502dPsEMoLEv5uDvJHLpGCjXtVY5_15hWxB7EgX1uS-_Q5VA%40mail.gmail.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-08 Thread Yuri Khan
On Thu, 8 Jun 2023 at 21:28, Viraj Alankar  wrote:

> What would be right way to do apply the automatic transaction only when there 
> is also an Expenses entry? I could not figure out the proper syntax. I tried 
> something like:
>
> = expr "any(account =~ /^Liabilities:Apple Card/) and any(account =~ 
> /^Expenses/)"
>
> but this does not seem to work. I get some errors if I try removing the 
> quotes, but I'm likely doing it wrong.

You might instead apply cashback only where the amount is negative.
But I’m struggling with complex condition syntax too, so maybe someone
else will chime in.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAP_d_8VuMoRwog1834ZnuXzQayrf074sx7_hApctjxEc%2BgcrEw%40mail.gmail.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-08 Thread Viraj Alankar
Nice, that is even cleaner. One thing however is if I then later add a
transaction to pay the card, the automatic transaction still applies.

What would be right way to do apply the automatic transaction only when
there is also an Expenses entry? I could not figure out the proper syntax.
I tried something like:

= expr "any(account =~ /^Liabilities:Apple Card/) and any(account =~
/^Expenses/)"

but this does not seem to work. I get some errors if I try removing the
quotes, but I'm likely doing it wrong.

Thanks,

Viraj.

On Thu, Jun 8, 2023 at 3:19 PM Yuri Khan  wrote:

> On Thu, 8 Jun 2023 at 18:53, Alexis  wrote:
>
> > I know of two options to reduce the duplication of the amount value:>
> > 1. Using transaction typed metadata
> >
> >   2023/06/06 McDonalds
> >   ; amount_spent:: $23.98
> >   Expenses:Food:Restaurants(tag("amount_spent"))
> >   Liabilities:Apple Card  (-tag("amount_spent"))
> >   Income:Credit Card Rewards (-(tag("amount_spent")) * 0.02)
> >   Assets:Apple Cash
> >
> >   See https://ledger-cli.org/doc/ledger3.html#Typed-metadata
>
> One might try to combine typed metadata with automated transactions:
>
> = Liabilities:Apple Card
> Assets:Apple Cash   (-tag("cashback"))
> Income:Credit Card Rewards   (tag("cashback"))
>
> 2023-06-06 McDonalds
> ; cashback:: 0.02
> Expenses:Food:Restaurants$23.98
> Liabilities:Apple Card
>
> $ ledger bal -f test_cashback.ledger
>$0.48  Assets:Apple Cash
>   $23.98  Expenses:Food:Restaurants
>   $-0.48  Income:Credit Card Rewards
>  $-23.98  Liabilities:Apple Card
>   
> 0
>
> I do not know off the bat how to apply a default 0.02 value if the tag
> is not present, but that is probably possible.
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Ledger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ledger-cli/tqXZGjJbZSo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ledger-cli+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ledger-cli/CAP_d_8W_G-iTxw1XykVCdcpuabu2wQ%3DQZaitAfmx%2BZRR9x6x0w%40mail.gmail.com
> .
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAM502dMxL4Z%2BJmQh2ai7qA_CH-J4oJ2hBZkPdj-ETjaY%3DRMqWg%40mail.gmail.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-08 Thread Yuri Khan
On Thu, 8 Jun 2023 at 18:53, Alexis  wrote:

> I know of two options to reduce the duplication of the amount value:>
> 1. Using transaction typed metadata
>
>   2023/06/06 McDonalds
>   ; amount_spent:: $23.98
>   Expenses:Food:Restaurants(tag("amount_spent"))
>   Liabilities:Apple Card  (-tag("amount_spent"))
>   Income:Credit Card Rewards (-(tag("amount_spent")) * 0.02)
>   Assets:Apple Cash
>
>   See https://ledger-cli.org/doc/ledger3.html#Typed-metadata

One might try to combine typed metadata with automated transactions:

= Liabilities:Apple Card
Assets:Apple Cash   (-tag("cashback"))
Income:Credit Card Rewards   (tag("cashback"))

2023-06-06 McDonalds
; cashback:: 0.02
Expenses:Food:Restaurants$23.98
Liabilities:Apple Card

$ ledger bal -f test_cashback.ledger
   $0.48  Assets:Apple Cash
  $23.98  Expenses:Food:Restaurants
  $-0.48  Income:Credit Card Rewards
 $-23.98  Liabilities:Apple Card
  
0

I do not know off the bat how to apply a default 0.02 value if the tag
is not present, but that is probably possible.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAP_d_8W_G-iTxw1XykVCdcpuabu2wQ%3DQZaitAfmx%2BZRR9x6x0w%40mail.gmail.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-08 Thread Viraj Alankar
Ah, these are great. Thanks!

On Thu, Jun 8, 2023 at 1:53 PM Alexis  wrote:

> Hello Viraj,
>
> I know of two options to reduce the duplication of the amount value:
>
> 1. Using transaction typed metadata
>
>   2023/06/06 McDonalds
>   ; amount_spent:: $23.98
>   Expenses:Food:Restaurants(tag("amount_spent"))
>   Liabilities:Apple Card  (-tag("amount_spent"))
>   Income:Credit Card Rewards (-(tag("amount_spent")) * 0.02)
>   Assets:Apple Cash
>
>   See https://ledger-cli.org/doc/ledger3.html#Typed-metadata
>
>
> 2. Using a define
>
>   define spent_amount=$23.98
>   2023/06/06 McDonalds
>   Expenses:Food:Restaurants   (spent_amount)
>   Liabilities:Apple Card (-spent_amount)
>   Income:Credit Card Rewards(-(spent_amount) * 0.02)
>   Assets:Apple Cash
>
>   See https://ledger-cli.org/doc/ledger3.html#index-define
>
>
> Hope this helps,
> Alexis
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "Ledger" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ledger-cli/tqXZGjJbZSo/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ledger-cli+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ledger-cli/ty4szlg6plx7c4ty4ixuf6gohf4hyx4yjqnpct4xeetpkj5rcs%40fgfvyi2zrlm5
> .
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAM502dOfEXP6yPO81stTxHW-yRvia6KdeHopA--ZxG6itkFwOQ%40mail.gmail.com.


Re: Reducing repetition/duplication of amount value in entries

2023-06-08 Thread Alexis
Hello Viraj,

I know of two options to reduce the duplication of the amount value:

1. Using transaction typed metadata

  2023/06/06 McDonalds
  ; amount_spent:: $23.98
  Expenses:Food:Restaurants(tag("amount_spent"))
  Liabilities:Apple Card  (-tag("amount_spent"))
  Income:Credit Card Rewards (-(tag("amount_spent")) * 0.02)
  Assets:Apple Cash

  See https://ledger-cli.org/doc/ledger3.html#Typed-metadata


2. Using a define 

  define spent_amount=$23.98
  2023/06/06 McDonalds
  Expenses:Food:Restaurants   (spent_amount)
  Liabilities:Apple Card (-spent_amount)
  Income:Credit Card Rewards(-(spent_amount) * 0.02)
  Assets:Apple Cash

  See https://ledger-cli.org/doc/ledger3.html#index-define


Hope this helps,
Alexis

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/ty4szlg6plx7c4ty4ixuf6gohf4hyx4yjqnpct4xeetpkj5rcs%40fgfvyi2zrlm5.


Reducing repetition/duplication of amount value in entries

2023-06-08 Thread Viraj Alankar
Hello,

I was wondering if there is a way to reduce the duplication of the amount 
value in an entry such as the following:

2023/06/06 McDonalds
Expenses:Food:Restaurants   $23.98
Liabilities:Apple Card -$23.98
Income:Credit Card Rewards  (-$23.98 * 0.02)
Assets:Apple Cash

i.e. can I replace 23.98 with some string? I see there is some way to do 
this with automated transactions, but perhaps not with regular ones?

I considered using automated transactions for this, but in that case I 
would like to override the 0.02 multipler in certain cases (some rewards 
are different percentages). I'm not sure how to do that or whether it is 
possible.

Thanks,

Viraj.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ledger-cli+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/7feaa2a8-6861-46b3-856b-755a83054887n%40googlegroups.com.