mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
BalanceView system implemented for incomestatement and cashflow
This commit is contained in:
parent
a6f98f1170
commit
321ace107e
@ -2,22 +2,39 @@
|
||||
|
||||
module Hledger.Cli.BalanceView (
|
||||
BalanceView(..)
|
||||
,balanceviewmode
|
||||
,balanceviewReport
|
||||
) where
|
||||
|
||||
import Data.Time.Calendar
|
||||
import Data.List
|
||||
import Data.Time.Calendar (Day)
|
||||
import Data.List (intercalate)
|
||||
import Data.Monoid (Sum(..), (<>))
|
||||
import qualified Data.Text as T
|
||||
import System.Console.CmdArgs.Explicit
|
||||
|
||||
import Hledger
|
||||
import Hledger.Cli.Balance
|
||||
import Hledger.Cli.CliOptions
|
||||
|
||||
data BalanceView = BV { bvname :: String
|
||||
data BalanceView = BV { bvmode :: String
|
||||
, bvaliases :: [String]
|
||||
, bvhelp :: String
|
||||
, bvname :: String
|
||||
, bvqueries :: [(String, Journal -> Query)]
|
||||
}
|
||||
|
||||
balanceviewmode :: BalanceView -> Mode RawOpts
|
||||
balanceviewmode bv@BV{..} = (defCommandMode $ bvmode : bvaliases) {
|
||||
modeHelp = bvhelp `withAliases` bvaliases
|
||||
,modeGroupFlags = Group {
|
||||
groupUnnamed = [
|
||||
flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show accounts as a list"
|
||||
,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
|
||||
]
|
||||
,groupHidden = []
|
||||
,groupNamed = [generalflagsgroup1]
|
||||
}
|
||||
}
|
||||
|
||||
balanceviewQueryReport
|
||||
:: ReportOpts
|
||||
-> Day
|
||||
|
@ -11,39 +11,27 @@ module Hledger.Cli.Balancesheet (
|
||||
,tests_Hledger_Cli_Balancesheet
|
||||
) where
|
||||
|
||||
import qualified Data.Text.Lazy.IO as LT
|
||||
import System.Console.CmdArgs.Explicit
|
||||
import Test.HUnit
|
||||
import Text.Shakespeare.Text
|
||||
|
||||
import Hledger
|
||||
import Hledger.Cli.CliOptions
|
||||
import Hledger.Cli.Balance
|
||||
import Hledger.Cli.BalanceView
|
||||
|
||||
|
||||
balancesheetmode :: Mode RawOpts
|
||||
balancesheetmode = (defCommandMode $ ["balancesheet"]++aliases) {
|
||||
modeHelp = "show a balance sheet" `withAliases` aliases
|
||||
,modeGroupFlags = Group {
|
||||
groupUnnamed = [
|
||||
flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show accounts as a list"
|
||||
,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
|
||||
]
|
||||
,groupHidden = []
|
||||
,groupNamed = [generalflagsgroup1]
|
||||
}
|
||||
}
|
||||
where aliases = ["bs"]
|
||||
|
||||
balancesheet :: CliOpts -> Journal -> IO ()
|
||||
balancesheet = balanceviewReport bv
|
||||
where
|
||||
bv = BV "Balance Sheet"
|
||||
bsBV = BV "balancesheet"
|
||||
["bs"]
|
||||
"show a balance sheet"
|
||||
"Balance Sheet"
|
||||
[ ("Assets", journalAssetAccountQuery)
|
||||
, ("Liabilities", journalLiabilityAccountQuery)
|
||||
]
|
||||
|
||||
balancesheetmode :: Mode RawOpts
|
||||
balancesheetmode = balanceviewmode bsBV
|
||||
|
||||
balancesheet :: CliOpts -> Journal -> IO ()
|
||||
balancesheet = balanceviewReport bsBV
|
||||
|
||||
tests_Hledger_Cli_Balancesheet :: Test
|
||||
tests_Hledger_Cli_Balancesheet = TestList
|
||||
[
|
||||
|
@ -14,48 +14,25 @@ module Hledger.Cli.Cashflow (
|
||||
,tests_Hledger_Cli_Cashflow
|
||||
) where
|
||||
|
||||
import qualified Data.Text.Lazy.IO as LT
|
||||
import System.Console.CmdArgs.Explicit
|
||||
import Test.HUnit
|
||||
import Text.Shakespeare.Text
|
||||
|
||||
import Hledger
|
||||
import Hledger.Cli.CliOptions
|
||||
import Hledger.Cli.Balance
|
||||
import Hledger.Cli.BalanceView
|
||||
|
||||
cfBV = BV "cashflow"
|
||||
["cf"]
|
||||
"show a cashflow statement statement"
|
||||
"Cashflow Statement"
|
||||
[ ("Cash flows", journalCashAccountQuery)
|
||||
]
|
||||
|
||||
cashflowmode :: Mode RawOpts
|
||||
cashflowmode = (defCommandMode ["cashflow","cf"]) {
|
||||
modeHelp = "show a cashflow statement" `withAliases` ["cf"]
|
||||
,modeGroupFlags = Group {
|
||||
groupUnnamed = [
|
||||
flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show accounts as a list"
|
||||
,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
|
||||
]
|
||||
,groupHidden = []
|
||||
,groupNamed = [generalflagsgroup1]
|
||||
}
|
||||
}
|
||||
cashflowmode = balanceviewmode cfBV
|
||||
|
||||
-- | Print a simple cashflow statement.
|
||||
cashflow :: CliOpts -> Journal -> IO ()
|
||||
cashflow CliOpts{reportopts_=ropts} j = do
|
||||
-- let lines = case lineFormatFromOpts ropts of Left err, Right ...
|
||||
d <- getCurrentDay
|
||||
let q = queryFromOpts d ropts
|
||||
cashreport@(_,total) = balanceReport ropts (And [q, journalCashAccountQuery j]) j
|
||||
-- operatingreport@(_,operating) = balanceReport ropts (And [q, journalOperatingAccountMatcher j]) j
|
||||
-- investingreport@(_,investing) = balanceReport ropts (And [q, journalInvestingAccountMatcher j]) j
|
||||
-- financingreport@(_,financing) = balanceReport ropts (And [q, journalFinancingAccountMatcher j]) j
|
||||
-- total = operating + investing + financing
|
||||
LT.putStr $ [lt|Cashflow Statement
|
||||
|
||||
Cash flows:
|
||||
#{balanceReportAsText ropts cashreport}
|
||||
Total:
|
||||
--------------------
|
||||
#{padleft 20 $ showMixedAmountWithoutPrice total}
|
||||
|]
|
||||
cashflow = balanceviewReport cfBV
|
||||
|
||||
tests_Hledger_Cli_Cashflow :: Test
|
||||
tests_Hledger_Cli_Cashflow = TestList
|
||||
|
@ -11,48 +11,26 @@ module Hledger.Cli.Incomestatement (
|
||||
,tests_Hledger_Cli_Incomestatement
|
||||
) where
|
||||
|
||||
import qualified Data.Text.Lazy.IO as LT
|
||||
import System.Console.CmdArgs.Explicit
|
||||
import Test.HUnit
|
||||
import Text.Shakespeare.Text
|
||||
|
||||
import Hledger
|
||||
import Hledger.Cli.CliOptions
|
||||
import Hledger.Cli.Balance
|
||||
import Hledger.Cli.BalanceView
|
||||
|
||||
isBV = BV "incomestatement"
|
||||
["is"]
|
||||
"show an income statement"
|
||||
"Income Statement"
|
||||
[ ("Revenues", journalIncomeAccountQuery)
|
||||
, ("Expenses", journalExpenseAccountQuery)
|
||||
]
|
||||
|
||||
incomestatementmode :: Mode RawOpts
|
||||
incomestatementmode = (defCommandMode $ ["incomestatement"]++aliases) {
|
||||
modeHelp = "show an income statement" `withAliases` aliases
|
||||
,modeGroupFlags = Group {
|
||||
groupUnnamed = [
|
||||
flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show accounts as a list"
|
||||
,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
|
||||
]
|
||||
,groupHidden = []
|
||||
,groupNamed = [generalflagsgroup1]
|
||||
}
|
||||
}
|
||||
where aliases = ["is"]
|
||||
incomestatementmode = balanceviewmode isBV
|
||||
|
||||
-- | Print a simple income statement.
|
||||
incomestatement :: CliOpts -> Journal -> IO ()
|
||||
incomestatement CliOpts{reportopts_=ropts} j = do
|
||||
d <- getCurrentDay
|
||||
let q = queryFromOpts d ropts
|
||||
incomereport@(_,income) = balanceReport ropts (And [q, journalIncomeAccountQuery j]) j
|
||||
expensereport@(_,expenses) = balanceReport ropts (And [q, journalExpenseAccountQuery j]) j
|
||||
total = income + expenses
|
||||
LT.putStr $ [lt|Income Statement
|
||||
|
||||
Revenues:
|
||||
#{balanceReportAsText ropts incomereport}
|
||||
Expenses:
|
||||
#{balanceReportAsText ropts expensereport}
|
||||
Total:
|
||||
--------------------
|
||||
#{padleft 20 $ showMixedAmountWithoutPrice total}
|
||||
|]
|
||||
incomestatement = balanceviewReport isBV
|
||||
|
||||
tests_Hledger_Cli_Incomestatement :: Test
|
||||
tests_Hledger_Cli_Incomestatement = TestList
|
||||
|
Loading…
Reference in New Issue
Block a user