Skip to content

Commit

Permalink
add ability to search posting/transaction by note/comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ananthakumaran committed Dec 3, 2023
1 parent cf99847 commit cb6bba5
Show file tree
Hide file tree
Showing 56 changed files with 934 additions and 166 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ sample:
publish:
nix develop --command bash -c 'mkdocs build'

parser:
npm run parser-build-debug

lint:
./node_modules/.bin/prettier --check src
npm run check
Expand Down
8 changes: 4 additions & 4 deletions docs/reference/budget.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ can read more about [periodic expressions](https://ledger-cli.org/doc/ledger3.ht
[bug](https://github.com/ledger/ledger/issues/1625) in the ledger-cli, so you can't use `~ in 2023/08/01`,
instead you always have to specify some interval like `~ Monthly in 2023/08/01`.

![Initial Budget](/images/budget-1.png)
[Initial Budget](../images/budget-1.png)

Now you can see that you will have 5k left in your checking account at
the end of the month, if you spend as per your budget. Before you
Expand Down Expand Up @@ -79,7 +79,7 @@ Let's add some real transactions.
Assets:Checking
```

![Month end Budget](/images/budget-2.png)
![Month end Budget](../images/budget-2.png)

As the month progresses, you can see how much you have spent and how
much you have left. You notice that you have overspent on transport
Expand All @@ -99,7 +99,7 @@ and clothing budget to 0
Assets:Checking
```

![Budget Deficit Fixed](/images/budget-3.png)
![Budget Deficit Fixed](../images/budget-3.png)

You can go back and adjust your budget anytime. Let's move on to the
next month, assuming you haven't made any further transaction.
Expand All @@ -119,7 +119,7 @@ next month, assuming you haven't made any further transaction.
Assets:Checking
```

![Next month Budget](/images/budget-4.png)
![Next month Budget](../images/budget-4.png)

You can see a new element in the UI called Rollover[^1]. This is basically
the amount you have budgeted last month, but haven't spent. This will
Expand Down
29 changes: 15 additions & 14 deletions docs/reference/bulk-edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ insensitive search by using the modifier `i` like
#### Property

You can also search based on properties like account, commodity,
amount, total, filename, payee and date.
amount, total, filename, note, payee and date.

```
account = Expenses:Utilities:Electricity
Expand All @@ -69,22 +69,23 @@ filename = creditcard/2023/jan.ledger
The general format is `property operator value`. The property can be
any of the following:

- account (posting account)
- commodity (posting commodity)
- amount (posting amount)
- total (transaction total)
- filename (name of the file the transaction is in)
- payee (transaction payee)
- date (transaction date)
- **account** - posting account
- **commodity** - posting commodity
- **amount** - posting amount
- **total** - transaction total
- **filename** - name of the file the transaction is in
- **note** - posting or transaction note (comment)
- **payee** - transaction payee
- **date** - transaction date

The operator can be any of the following:

- = (equal)
- =~ (regular expression match)
- < (less than)
- <= (less than or equal)
- \> (greater than)
- \>= (greater than or equal)
- **=** equal
- **=~** regular expression match
- **<** less than
- **<=** less than or equal
- **\>** greater than
- **\>=** greater than or equal

Not all the combinations of property, operator and value would work,
if in doubt, just try it out, the UI will show you an error if the
Expand Down
8 changes: 5 additions & 3 deletions docs/reference/journal.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ is the per unit cost and `168.690` is the quantity you have bought.
##### Comment

```ledger
; This is a comment
2023/07/01 Rent
; This is a transaction comment
Expenses:Rent 15,000 INR
Assets:Checking
Assets:Checking ; This is a posting comment
```

Any text after `;` is treated as a comment
Any text after `;` is treated as a comment. Comment can be at whole
transaction level or individual posting level. Comment is also referred
as **note** in many places, both are same.

##### Tags

Expand Down
25 changes: 25 additions & 0 deletions docs/reference/ledger-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,28 @@ ledger_cli: hledger
Paisa ships with ledger binary. If you use hledger or beancount, make
sure that the binaries are installed.
## Unavailable Features
Some of the features that are available in Paisa are not supported
by **hledger** and **beancount**
### hledger
* [Recurring](./recurring.md) (partial) - hledger supports automated transactions,
but it doesn't allow to add **only** metadata to transaction. So
some of the examples in the recurring section will not work with
hledger. It's possible to add metadata to transactions manually.
### beancount
* [Budget](./budget.md) - budget is based on periodic transactions that is no
supported by beancount.
* [Recurring](./recurring.md) (partial) - beancount doesn't support automated
transactions. It's possible to add metadata to transactions
manually. Use lowercase for tag name.
* Search filter in Transactions and Postings pages doesn't support note
[property](./bulk-edit.md#property).
20 changes: 17 additions & 3 deletions internal/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,10 @@ func execLedgerCommand(journalPath string, flags []string) ([]*posting.Posting,
LotCommodity
TagRecurring
TagPeriod
Note
TransactionNote
)
args := append(append([]string{"--args-only", "-f", journalPath}, flags...), "csv", "--csv-format", "%(quoted(date)),%(quoted(payee)),%(quoted(display_account)),%(quoted(commodity(scrub(display_amount)))),%(quoted(quantity(scrub(display_amount)))),%(quoted(quantity(scrub(market(amount,date,'"+config.DefaultCurrency()+"') * 100000000)))),%(quoted(xact.filename)),%(quoted(xact.id)),%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))),%(quoted(xact.beg_line)),%(quoted(xact.end_line)),%(quoted(quantity(lot_price(amount)))),%(quoted(commodity(lot_price(amount)))),%(quoted(tag('Recurring'))),%(quoted(tag('Period')))\n")
args := append(append([]string{"--args-only", "-f", journalPath}, flags...), "csv", "--csv-format", "%(quoted(date)),%(quoted(payee)),%(quoted(display_account)),%(quoted(commodity(scrub(display_amount)))),%(quoted(quantity(scrub(display_amount)))),%(quoted(quantity(scrub(market(amount,date,'"+config.DefaultCurrency()+"') * 100000000)))),%(quoted(xact.filename)),%(quoted(xact.id)),%(quoted(cleared ? \"*\" : (pending ? \"!\" : \"\"))),%(quoted(xact.beg_line)),%(quoted(xact.end_line)),%(quoted(quantity(lot_price(amount)))),%(quoted(commodity(lot_price(amount)))),%(quoted(tag('Recurring'))),%(quoted(tag('Period'))),%(quoted(note)),%(quoted(xact.note))\n")

ledgerPath, err := binary.LedgerBinaryPath()
if err != nil {
Expand Down Expand Up @@ -673,6 +675,12 @@ func execLedgerCommand(journalPath string, flags []string) ([]*posting.Posting,
tagPeriod = record[TagPeriod]
}

note := record[Note]
transactionNote := record[TransactionNote]
if transactionNote != "" {
note = utils.ReplaceLast(note, transactionNote, "")
}

posting := posting.Posting{
Date: date,
Payee: record[Payee],
Expand All @@ -687,7 +695,9 @@ func execLedgerCommand(journalPath string, flags []string) ([]*posting.Posting,
TransactionBeginLine: transactionBeginLine,
TransactionEndLine: transactionEndLine,
Forecast: forecast,
FileName: fileName}
FileName: fileName,
Note: note,
TransactionNote: transactionNote}
postings = append(postings, &posting)

}
Expand Down Expand Up @@ -717,6 +727,7 @@ func execHLedgerCommand(journalPath string, prices []price.Price, flags []string
Description string `json:"tdescription"`
ID int64 `json:"tindex"`
Status string `json:"tstatus"`
Comment string `json:"tcomment"`
Tags [][]string `json:"ttags"`
TSourcePos []struct {
SourceColumn uint64 `json:"sourceColumn"`
Expand All @@ -725,6 +736,7 @@ func execHLedgerCommand(journalPath string, prices []price.Price, flags []string
} `json:"tsourcepos"`
Postings []struct {
Account string `json:"paccount"`
Comment string `json:"pcomment"`
Tags [][]string `json:"ptags"`
Amount []struct {
Commodity string `json:"acommodity"`
Expand Down Expand Up @@ -849,7 +861,9 @@ func execHLedgerCommand(journalPath string, prices []price.Price, flags []string
TransactionBeginLine: t.TSourcePos[0].SourceLine,
TransactionEndLine: t.TSourcePos[1].SourceLine,
Forecast: forecast,
FileName: fileName}
FileName: fileName,
Note: p.Comment,
TransactionNote: t.Comment}
postings = append(postings, &posting)

}
Expand Down
2 changes: 2 additions & 0 deletions internal/model/posting/posting.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Posting struct {
TransactionEndLine uint64 `json:"transaction_end_line"`
FileName string `json:"file_name"`
Forecast bool `json:"forecast"`
Note string `json:"note"`
TransactionNote string `json:"transaction_note"`

MarketAmount decimal.Decimal `gorm:"-:all" json:"market_amount"`
Balance decimal.Decimal `gorm:"-:all" json:"balance"`
Expand Down
2 changes: 2 additions & 0 deletions internal/model/transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Transaction struct {
BeginLine uint64 `json:"beginLine"`
EndLine uint64 `json:"endLine"`
FileName string `json:"fileName"`
Note string `json:"note"`
}

func Build(postings []posting.Posting) []Transaction {
Expand All @@ -43,6 +44,7 @@ func Build(postings []posting.Posting) []Transaction {
TagPeriod: tagPeriod,
BeginLine: sample.TransactionBeginLine,
EndLine: sample.TransactionEndLine,
Note: sample.TransactionNote,
FileName: sample.FileName,
}
})
Expand Down
8 changes: 8 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,11 @@ func OpenDB() (*gorm.DB, error) {
func Dos2Unix(str string) string {
return strings.ReplaceAll(str, "\r\n", "\n")
}

func ReplaceLast(haystack, needle, replacement string) string {
i := strings.LastIndex(haystack, needle)
if i == -1 {
return haystack
}
return haystack[:i] + replacement + haystack[i+len(needle):]
}
Loading

0 comments on commit cb6bba5

Please sign in to comment.