Skip to content

Commit

Permalink
support tax sub accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Sep 28, 2023
1 parent ab151b6 commit 96bc28c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion docs/reference/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ explicitly specifying anything else.

Income tax paid to government should be credited to `#!ledger
Expenses:Tax` account. This is used to calculate your Net Income and
your Savings Rate.
your Savings Rate. If you want to track different types of taxes, you
can use sub accounts as well, for example `#!ledger Expenses:Tax:Income`
and `#!ledger Expenses:Tax:GST`.

### Expenses

Expand Down
4 changes: 2 additions & 2 deletions internal/server/cash_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func GetCurrentCashFlow(db *gorm.DB) []CashFlow {
func computeCashFlow(db *gorm.DB, q *query.Query, balance decimal.Decimal) []CashFlow {
var cashFlows []CashFlow

expenses := utils.GroupByMonth(q.Clone().Like("Expenses:%").NotLike("Expenses:Tax").All())
expenses := utils.GroupByMonth(q.Clone().Like("Expenses:%").NotAccountPrefix("Expenses:Tax").All())
incomes := utils.GroupByMonth(q.Clone().Like("Income:%").All())
liabilities := utils.GroupByMonth(q.Clone().Like("Liabilities:%").All())
investments := utils.GroupByMonth(q.Clone().Like("Assets:%").NotAccountPrefix("Assets:Checking").All())
taxes := utils.GroupByMonth(q.Clone().Like("Expenses:Tax").All())
taxes := utils.GroupByMonth(q.Clone().AccountPrefix("Expenses:Tax").All())
checkings := utils.GroupByMonth(q.Clone().AccountPrefix("Assets:Checking").All())
postings := q.Clone().All()

Expand Down
6 changes: 3 additions & 3 deletions internal/server/expense.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ type Graph struct {
}

func GetCurrentExpense(db *gorm.DB) map[string][]posting.Posting {
expenses := query.Init(db).LastNMonths(3).Like("Expenses:%").NotLike("Expenses:Tax").All()
expenses := query.Init(db).LastNMonths(3).Like("Expenses:%").NotAccountPrefix("Expenses:Tax").All()
return utils.GroupByMonth(expenses)
}

func GetExpense(db *gorm.DB) gin.H {
expenses := query.Init(db).Like("Expenses:%").NotLike("Expenses:Tax").All()
expenses := query.Init(db).Like("Expenses:%").NotAccountPrefix("Expenses:Tax").All()
incomes := query.Init(db).Like("Income:%").All()
investments := query.Init(db).Like("Assets:%").NotAccountPrefix("Assets:Checking").All()
taxes := query.Init(db).Like("Expenses:Tax").All()
taxes := query.Init(db).AccountPrefix("Expenses:Tax").All()
postings := query.Init(db).All()

graph := make(map[string]map[string]Graph)
Expand Down
2 changes: 1 addition & 1 deletion internal/server/income.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Tax struct {

func GetIncome(db *gorm.DB) gin.H {
incomePostings := query.Init(db).Like("Income:%").All()
taxPostings := query.Init(db).Like("Expenses:Tax").All()
taxPostings := query.Init(db).AccountPrefix("Expenses:Tax").All()
p := query.Init(db).First()

if p == nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/server/investment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func computeInvestmentYearlyCard(start time.Time, assets []posting.Posting, expe

for len(expenses) > 0 && utils.IsWithDate(expenses[0].Date, start, yearEnd) {
p, expenses = expenses[0], expenses[1:]
if p.Account == "Expenses:Tax" {
if utils.IsSameOrParent(p.Account, "Expenses:Tax") {
currentYearTaxes = append(currentYearTaxes, p)
} else {
currentYearExpenses = append(currentYearExpenses, p)
Expand Down
6 changes: 4 additions & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
<p class="is-size-4">I want to get started</p>
<ol class="ml-5 mt-2 mb-4">
<li>
Go to <a href="/more/config">config</a> page and set your default currency and locale.
Go to <a href="/more/config">configuration</a> page and set your default currency and
locale.
</li>
<li>
Go to <a href="/ledger/editor">editor</a> page and start adding transactions to your
Expand All @@ -120,7 +121,8 @@
> page and select all the content and delete them.
</li>
<li>
Go to <a href="/more/config">config</a> page and click the reset to defaults button.
Go to <a href="/more/config">configuration</a> page and click the reset to defaults
button.
</li>
</ol>

Expand Down

0 comments on commit 96bc28c

Please sign in to comment.