Skip to content

Commit

Permalink
Add register
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Apr 14, 2013
1 parent a0a3fc2 commit a1b316f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,26 @@ func printLedger(w io.Writer, generalLedger []*Transaction, columns int) {
}
}

func printRegister(generalLedger []*Transaction, filter string, columns int) {
runningBalance := new(big.Rat)
for _, trans := range generalLedger {
for _, accChange := range trans.AccountChanges {
if strings.Contains(accChange.Name, filter) {
runningBalance.Add(runningBalance, accChange.Balance)
writtenBytes, _ := fmt.Printf("%s %s", trans.Date.Format(TransactionDateFormat), trans.Payee)
outBalanceString := accChange.Balance.FloatString(2)
outRunningBalanceString := runningBalance.FloatString(2)
spaceCount := columns - writtenBytes - 2 - len(outBalanceString) - len(outRunningBalanceString)
if spaceCount < 0 {
spaceCount = 0
}
fmt.Printf("%s%s %s", strings.Repeat(" ", spaceCount), outBalanceString, outRunningBalanceString)
fmt.Println("")
}
}
}
}

func balanceTransaction(input *Transaction) error {
balance := new(big.Rat)
var emptyAccPtr *Account
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ func main() {
printBalances(getBalances(generalLedger, containsFilter), showEmptyAccounts, transactionDepth, columnWidth)
case "print":
printLedger(os.Stdout, generalLedger, columnWidth)
case "register":
printRegister(generalLedger, containsFilter, columnWidth)
}
}

0 comments on commit a1b316f

Please sign in to comment.