Skip to content

Commit

Permalink
show the result amount in ledger export with closures
Browse files Browse the repository at this point in the history
  • Loading branch information
hrj committed May 11, 2019
1 parent 91b7e6b commit 733b85c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions base/src/main/scala/co/uproot/abandon/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ case class BalanceReport(leftEntries:Seq[BalanceReportEntry], rightEntries:Seq[B
case class RegisterReportEntry(accountName: String, txns: Seq[DetailedPost], render: String)
case class RegisterReportGroup(groupTitle: String, entries: Seq[RegisterReportEntry])

case class LedgerExportEntry(accountName: AccountName, amount: BigDecimal)
case class LedgerExportEntry(accountName: AccountName, amount: BigDecimal, comment: Option[String] = None)
case class LedgerExportData(date: Date, ledgerEntries: Seq[LedgerExportEntry]) {
val maxNameLength = maxElseZero(ledgerEntries.map(_.accountName.toString.length))
val maxAmountWidth = maxElseZero(ledgerEntries.map(_.amount.toString.length))
Expand Down Expand Up @@ -269,8 +269,10 @@ object Reports {
} else {
val destClosure = destEntry match {
case (accountName, amount) =>
val srcTotal = srcClosure.map(_.amount).sum
LedgerExportEntry(accountName, -(srcTotal))
val srcTotalNeg = srcClosure.map(_.amount).sum
val srcTotal = -srcTotalNeg
val resultAmt = srcTotal + amount
LedgerExportEntry(accountName, srcTotal, Some(" result: " + resultAmt.toString))
}
LedgerExportData(latestDate, srcClosureSorted :+ destClosure)
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/main/scala/co/uproot/abandon/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ object CLIApp {

ledgerRep foreach { reportGroup =>
reportWriter.println(reportGroup.date.formatCompactYYYYMMDD)
val formatStr = "%-" + (reportGroup.maxNameLength + 4) + "s %s"
val formatStr = "%-" + (reportGroup.maxNameLength + 4) + "s %s%s"
reportGroup.ledgerEntries foreach { e =>
val render = formatStr format (e.accountName, e.amount.toString())
val render = formatStr format (e.accountName, e.amount.toString(), e.comment.map(" ; " + _).getOrElse(""))
reportWriter.println(" " + render)
}
reportWriter.println("")
Expand Down
2 changes: 1 addition & 1 deletion tests/sclT0002-ledger/all02.ref.closing.ledger
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
Expenses:Rent 4500
Expenses:Salaries 3100
Income:Receipts -35000
Capital:Reserves_And_Surplus 22214.10
Capital:Reserves_And_Surplus 22214.10 ; result: 20714.10

0 comments on commit 733b85c

Please sign in to comment.