Thanks! Even with the issue you mention, when my income exceeds
$200,000, the paycheck that puts it over that amount isn't going to
put it over by a large amount, so I think I could live with that
margin of error or correct it manually later. I can't find anything
related to the `account()` function in the docs, is it not documented
or am I just missing it?
While this solution would probably be good enough, I've figured out an
improvement which allows me to calculate this exactly. The idea is
that if the account total before the transaction is greater than
-200,000, then we can apply the .9% tax as normal. But if the account
total before the transaction is greater than -200,000 and the total
after is less than -200,000, then we calculate the difference between
the total after and -200,000, and apply the .9% tax just to this
amount, and just for this one transaction.
```
account Assets:Bank
account Income:Hooli
account Liabilities:Taxes:Medicare
account Liabilities:Taxes:Medicare:Additional
define total_after(account_name) = account(account_name).total
define total_before(account_name, amount) = account(account_name).total - amount
define did_cross_threshold(low, high, threshold) = low < threshold and
high > threshold
define should_compute_additional_medicare(account_name, amount) =
did_cross_threshold(total_after(account_name),
total_before(account_name, amount), -200000)
= expr "account =~ /Income:Hooli/ and
should_compute_additional_medicare('Income:Hooli', O)"
(Liabilities:Taxes:Medicare:Additional)
((total_after('Income:Hooli') + 200000 USD) * {0.009})
= expr "account =~ /Income:Hooli/ and total_before('Income:Hooli', O)
<= -200000 USD"
(Liabilities:Taxes:Medicare:Additional) .009
= expr "account =~ /Income:Hooli/"
(Liabilities:Taxes:Medicare) .0145
2022-04-29 * Payroll
Income:Hooli -150,000 USD
Assets:Bank
2022-04-15 * Payroll
Income:Hooli -150,000 USD
Assets:Bank
2022-04-01 * Payroll
Income:Hooli -150,000 USD
Assets:Bank
```
The result is:
```
-8,775 USD Liabilities:Taxes:Medicare
-2,250 USD Additional
--------------------
-8,775 USD
```
Which shows that the additional tax was computed on the $250,000 that
was above $200,000, while the 1.45% tax was computed on the entire
$450,000 amount.
Thanks for putting me on the right track!
> --
>
> ---
> 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/VPXzQsto4KE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
ledger-cli+...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ledger-cli/Yl32BAzHYxErEudt%40jirafa.cyrius.com.