Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #61 Minor formatting glitch #140

Merged
merged 2 commits into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/src/main/scala/co/uproot/abandon/Process.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ case class AccountTreeState(name: AccountName, amount: BigDecimal, childStates:
assert(amount != null)
assert(childStates != null)
lazy val total: BigDecimal = amount + childStates.foldLeft(Zero)(_ + _.total)
lazy val childrenNonZero: Int = childStates.count(c => (!(c.total equals Zero)) || (c.childrenNonZero != 0))
lazy val childrenNonZero: Seq[AccountTreeState] = childStates.filter(c => (!(c.total equals Zero)) || c.childrenNonZero.nonEmpty)
def countRenderableChildren(isRenderable: (AccountTreeState) => Boolean): Int = {
childStates.count(c => (!(c.total equals Zero)) || (c.countRenderableChildren(isRenderable) != 0))
}
Expand Down
13 changes: 6 additions & 7 deletions base/src/main/scala/co/uproot/abandon/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object Reports {
val amountIsZero = a.amount equals Zero
val hideAccount = (!reportSettings.showZeroAmountAccounts) && amountIsZero
val renderableChildren = a.childrenNonZero
val onlyChildren = (renderableChildren == 1) && hideAccount
val onlyChildren = (renderableChildren.length == 1) && hideAccount

val myPrefix = treePrefix + (
if (indent <= 1) {
Expand All @@ -49,20 +49,19 @@ object Reports {
})

val children = a.childStates
val lastChildIndex = children.length - 1
val renderedChildren = children.sortBy(_.name.toString).zipWithIndex.flatMap {
case (c, i) =>
show(width, c, maxNameLength, childTreePrefix, i == lastChildIndex, isLastChild || (prefix.isDefined && isParentLastChild),
val lastRenderable = renderableChildren.sortBy(_.name.toString).lastOption
val renderedChildren = children.sortBy(_.name.toString).flatMap { c =>
show(width, c, maxNameLength, childTreePrefix, lastRenderable.contains(c), isLastChild || (prefix.isDefined && isParentLastChild),
if (onlyChildren) Some(prefix.map(_ + ":").getOrElse("") + a.name.name) else None,
if (onlyChildren) Some(indent) else None)
}
val selfAmount = if (a.amount != 0 && !a.childStates.isEmpty) { " (" + a.amount + ")" } else { "" }
val selfAmount = if (!amountIsZero && a.childStates.nonEmpty) { " (" + a.amount + ")" } else { "" }
lazy val selfRender =
BalanceReportEntry(Some(a.name),
("%" + width + ".2f %-" + maxNameLength + "s") format (
a.total, myPrefix + (prefix.map(_ + ":").getOrElse("") + a.name.name) + selfAmount))

if (renderableChildren == 0) {
if (renderableChildren.isEmpty) {
if (hideAccount) {
Nil
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/sclT0002-ledger/reports01.ref.all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All
-600.00 ├╴Clothing -21000.00 └╴Current
-400.00 └╴Food -21000.00 ├╴Bank
1000.00 Liabilities:ProfessionalTax 400.00 ├╴Branch
-400.00 ╴Cash
-400.00 ╴Cash
1000.00 Income
─────────────────────────────────────────────────────────────────────────────────────
30000.00 -30000.00 = Zero
2 changes: 1 addition & 1 deletion tests/sclT0002-ledger/reports01.ref.balSheet.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Balance Sheet
-21000.00 └╴Current
-21000.00 ├╴Bank
400.00 ├╴Branch
-400.00 ╴Cash
-400.00 ╴Cash
─────────────────────────────────────────────────────────────────────────────────────
31000.00 -31000.00 = Zero