From 65a20c6870b6cf0da0a8c044f59c99cd810f70e8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 16 Apr 2012 16:55:30 +0000 Subject: [PATCH] separate account types in balancesheet, show totals with consistent layout --- hledger/Hledger/Cli/Balancesheet.hs | 27 ++++++++++++++++++++++---- hledger/Hledger/Cli/Incomestatement.hs | 4 +++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/hledger/Hledger/Cli/Balancesheet.hs b/hledger/Hledger/Cli/Balancesheet.hs index 656a4101e..fc0ccbb0b 100644 --- a/hledger/Hledger/Cli/Balancesheet.hs +++ b/hledger/Hledger/Cli/Balancesheet.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE QuasiQuotes #-} {-| The @balancesheet@ command prints a fairly standard balance sheet. @@ -10,7 +11,9 @@ module Hledger.Cli.Balancesheet ( ) where import Data.List +import qualified Data.Text.Lazy.IO as LT import Test.HUnit +import Text.Shakespeare.Text import Hledger import Prelude hiding (putStr) @@ -22,10 +25,26 @@ import Hledger.Cli.Balance -- | Print a standard balancesheet. balancesheet :: CliOpts -> Journal -> IO () balancesheet CliOpts{reportopts_=ropts} j = do - let lines = case formatFromOpts ropts of - Left err -> [err] - Right _ -> accountsReportAsText ropts $ accountsReport2 ropts (journalBalanceSheetAccountQuery j) j - putStr $ unlines lines + -- let lines = case formatFromOpts ropts of Left err, Right ... + d <- getCurrentDay + let m = queryFromOpts ropts d + assetreport@(_,assets) = accountsReport2 ropts (And [m, journalAssetAccountQuery j]) j + liabilityreport@(_,liabilities) = accountsReport2 ropts (And [m, journalLiabilityAccountQuery j]) j + equityreport@(_,equity) = accountsReport2 ropts (And [m, journalEquityAccountQuery j]) j + total = assets + liabilities + equity + LT.putStr $ [lt|Balance Sheet + +Assets: +#{unlines $ accountsReportAsText ropts assetreport} +Liabilities: +#{unlines $ accountsReportAsText ropts liabilityreport} +Equity: +#{unlines $ accountsReportAsText ropts equityreport} + +Total: +-------------------- +#{padleft 20 $ showMixedAmountWithoutPrice total} +|] tests_Hledger_Cli_Balancesheet = TestList [ diff --git a/hledger/Hledger/Cli/Incomestatement.hs b/hledger/Hledger/Cli/Incomestatement.hs index fd2d6278e..f3142c2c8 100644 --- a/hledger/Hledger/Cli/Incomestatement.hs +++ b/hledger/Hledger/Cli/Incomestatement.hs @@ -33,7 +33,9 @@ Revenues: Expenses: #{unlines $ accountsReportAsText ropts expensereport} -Total: #{show total} +Total: +-------------------- +#{padleft 20 $ showMixedAmountWithoutPrice total} |] tests_Hledger_Cli_Incomestatement :: Test