How could you calculate tax in your transaction?

87 views
Skip to first unread message

Jimi Damon

unread,
Dec 23, 2020, 11:28:14 AM12/23/20
to ledge...@googlegroups.com
Hi,

I was just trying out an example where I bought pizza for friends and then was just going to have them venmo me for the cost of the pizza plus the tax added.

I had something like this


2020/12/20 * Woodstocks Pizza
    ; tag: FriendA
    Pizza:Cheese    $21.04
    Pizza:Salad       $7.54
    Pizza:Drink        $10.00
    ; Pizza:Taxes    (PizzaCurrentTransaction * 0.0775 )  My ideal
    CreditCard


But I'd really like to add in the taxes as well with some line saying  

0.0775 * this current transaction without having to calculate it manually and then add it in.

I know about how you can set up a matcher like 
= /Pizza/
   (taxes )  0.0775

to calculate the taxes but in my case I really want to have the taxes stay with the transaction that can be looked up with tag FriendA.  

Is there a way to calculate the taxes on the current transaction using a math expression ? 

Thanks,


Martin Michlmayr

unread,
Dec 24, 2020, 12:43:14 AM12/24/20
to ledge...@googlegroups.com
* Jimi Damon <jda...@gmail.com> [2020-12-23 08:28]:
> I know about how you can set up a matcher like
> = /Pizza/
> (taxes ) 0.0775

= /^Pizza:/
Pizza:Taxes (roundto(amount * 0.0775, 2))
CreditCard (roundto(-amount * 0.0775, 2))

This does what you want.

Unfortunately, it leads to an error due to a bug, but if you e.g.
change the tax rate from 0.0775 to 0.0774 it works.

P.S. Please use top-level accounts like Assets: and Liabilities:
--
Martin Michlmayr
https://www.cyrius.com/

the.so...@gmail.com

unread,
Dec 28, 2020, 9:30:40 AM12/28/20
to Ledger
Just FYI, top-level accounts like Assets: and Liabilities: in this case would look something like this:

2020-12-28 * Woodstocks Pizza
    Assets:Receivable:Person:FriendA          $21.04  ; Cheese Pizza
    Assets:Receivable:Person:FriendA           $7.54  ; Salad
    Assets:Receivable:Person:FriendA          $10.00  ; Drink
    Assets:Receivable:Person:FriendA           $2.99  ; Taxes @ 7.75%
    Liabilities:Credit Card:Amex             $-41.57

Martin Michlmayr

unread,
Dec 29, 2020, 8:18:50 AM12/29/20
to ledge...@googlegroups.com
* Martin Michlmayr <t...@cyrius.com> [2020-12-24 13:43]:
> = /^Pizza:/
> Pizza:Taxes (roundto(amount * 0.0775, 2))
> CreditCard (roundto(-amount * 0.0775, 2))
>
> This does what you want.

> Unfortunately, it leads to an error due to a bug, but if you e.g.
> change the tax rate from 0.0775 to 0.0774 it works.

I've now reported that issue:
https://github.com/ledger/ledger/issues/1983

the.so...@gmail.com

unread,
Dec 29, 2020, 2:22:29 PM12/29/20
to Ledger
The problem is the ceil() function that roundto() in turn uses.  That is a positive biased rounding function, which rounds up towards +∞, instead of rounding away from/toward zero.

Yuri Khan

unread,
Dec 29, 2020, 2:26:59 PM12/29/20
to Ledger
On Wed, 30 Dec 2020 at 02:22, the.so...@gmail.com
<the.so...@gmail.com> wrote:

>> * Martin Michlmayr <t...@cyrius.com> [2020-12-24 13:43]:
>> > = /^Pizza:/
>> > Pizza:Taxes (roundto(amount * 0.0775, 2))
>> > CreditCard (roundto(-amount * 0.0775, 2))

> The problem is the ceil() function that roundto() in turn uses. That is a positive biased rounding function, which rounds up towards +∞, instead of rounding away from/toward zero.

Then maybe round first, negate second?

= /^Pizza:/
Pizza:Taxes (roundto(amount * 0.0775, 2))
CreditCard (-roundto(amount * 0.0775, 2))

Martin Michlmayr

unread,
Dec 29, 2020, 10:32:33 PM12/29/20
to ledge...@googlegroups.com
* Yuri Khan <yuri....@gmail.com> [2020-12-30 02:26]:
> Then maybe round first, negate second?
>
> = /^Pizza:/
> Pizza:Taxes (roundto(amount * 0.0775, 2))
> CreditCard (-roundto(amount * 0.0775, 2))

Good idea!
Reply all
Reply to author
Forward
0 new messages