mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 15:14:49 +03:00
prototypical incomestatement and balancesheet commands
This commit is contained in:
parent
b96e3ac85d
commit
ca5d5020e1
12
MANUAL.md
12
MANUAL.md
@ -734,6 +734,18 @@ Examples:
|
||||
|
||||
$ hledger activity -p weekly dining
|
||||
|
||||
#### incomestatement
|
||||
|
||||
This is intended to display a standard-looking
|
||||
[income statement](http://en.wikipedia.org/wiki/Income_statement). Currently
|
||||
it is similar to doing `hledger balance '^(income|expenses?|profits?|loss(es)?)(:|$)'`.
|
||||
|
||||
#### balancesheet
|
||||
|
||||
This is intended to display a standard-looking
|
||||
[balance sheet](http://en.wikipedia.org/wiki/Balance_sheet). Currently
|
||||
it is similar to doing `hledger balance '^(assets?|liabilit(y|ies)|equity)(:|$)'`.
|
||||
|
||||
#### stats
|
||||
|
||||
The stats command displays summary information for the whole journal, or
|
||||
|
@ -6,7 +6,9 @@ hledger command-line program.
|
||||
module Hledger.Cli (
|
||||
module Hledger.Cli.Add,
|
||||
module Hledger.Cli.Balance,
|
||||
module Hledger.Cli.Balancesheet,
|
||||
module Hledger.Cli.Histogram,
|
||||
module Hledger.Cli.Incomestatement,
|
||||
module Hledger.Cli.Print,
|
||||
module Hledger.Cli.Register,
|
||||
module Hledger.Cli.Stats,
|
||||
@ -25,7 +27,9 @@ import Test.HUnit
|
||||
import Hledger
|
||||
import Hledger.Cli.Add
|
||||
import Hledger.Cli.Balance
|
||||
import Hledger.Cli.Balancesheet
|
||||
import Hledger.Cli.Histogram
|
||||
import Hledger.Cli.Incomestatement
|
||||
import Hledger.Cli.Print
|
||||
import Hledger.Cli.Register
|
||||
import Hledger.Cli.Stats
|
||||
@ -42,7 +46,9 @@ tests_Hledger_Cli = TestList
|
||||
,tests_Hledger_Read
|
||||
-- ,tests_Hledger_Cli_Add
|
||||
-- ,tests_Hledger_Cli_Balance
|
||||
,tests_Hledger_Cli_Balancesheet
|
||||
-- ,tests_Hledger_Cli_Histogram
|
||||
,tests_Hledger_Cli_Incomestatement
|
||||
,tests_Hledger_Cli_Options
|
||||
-- ,tests_Hledger_Cli_Print
|
||||
,tests_Hledger_Cli_Register
|
||||
|
32
hledger/Hledger/Cli/Balancesheet.hs
Normal file
32
hledger/Hledger/Cli/Balancesheet.hs
Normal file
@ -0,0 +1,32 @@
|
||||
{-|
|
||||
|
||||
The @balancesheet@ command prints a fairly standard balance sheet.
|
||||
|
||||
-}
|
||||
|
||||
module Hledger.Cli.Balancesheet (
|
||||
balancesheet
|
||||
,tests_Hledger_Cli_Balancesheet
|
||||
) where
|
||||
|
||||
import Data.List
|
||||
import Test.HUnit
|
||||
|
||||
import Hledger
|
||||
import Prelude hiding (putStr)
|
||||
import Hledger.Utils.UTF8IOCompat (putStr)
|
||||
import Hledger.Cli.Options
|
||||
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 (journalBalanceSheetAccountMatcher j) j
|
||||
putStr $ unlines lines
|
||||
|
||||
tests_Hledger_Cli_Balancesheet = TestList
|
||||
[
|
||||
]
|
32
hledger/Hledger/Cli/Incomestatement.hs
Normal file
32
hledger/Hledger/Cli/Incomestatement.hs
Normal file
@ -0,0 +1,32 @@
|
||||
{-|
|
||||
|
||||
The @incomestatement@ command prints a fairly standard income statement (profit & loss) report.
|
||||
|
||||
-}
|
||||
|
||||
module Hledger.Cli.Incomestatement (
|
||||
incomestatement
|
||||
,tests_Hledger_Cli_Incomestatement
|
||||
) where
|
||||
|
||||
import Data.List
|
||||
import Test.HUnit
|
||||
|
||||
import Hledger
|
||||
import Prelude hiding (putStr)
|
||||
import Hledger.Utils.UTF8IOCompat (putStr)
|
||||
import Hledger.Cli.Options
|
||||
import Hledger.Cli.Balance
|
||||
|
||||
|
||||
-- | Print a standard income statement.
|
||||
incomestatement :: CliOpts -> Journal -> IO ()
|
||||
incomestatement CliOpts{reportopts_=ropts} j = do
|
||||
let lines = case formatFromOpts ropts of
|
||||
Left err -> [err]
|
||||
Right _ -> accountsReportAsText ropts $ accountsReport2 ropts (journalProfitAndLossAccountMatcher j) j
|
||||
putStr $ unlines lines
|
||||
|
||||
tests_Hledger_Cli_Incomestatement = TestList
|
||||
[
|
||||
]
|
@ -49,7 +49,9 @@ import Text.Printf
|
||||
import Hledger (ensureJournalFileExists)
|
||||
import Hledger.Cli.Add
|
||||
import Hledger.Cli.Balance
|
||||
import Hledger.Cli.Balancesheet
|
||||
import Hledger.Cli.Histogram
|
||||
import Hledger.Cli.Incomestatement
|
||||
import Hledger.Cli.Print
|
||||
import Hledger.Cli.Register
|
||||
import Hledger.Cli.Stats
|
||||
@ -78,6 +80,8 @@ main = do
|
||||
| any (cmd `isPrefixOf`) ["entries","print"] = showModeHelpOr entriesmode $ withJournalDo opts print'
|
||||
| any (cmd `isPrefixOf`) ["postings","register"] = showModeHelpOr postingsmode $ withJournalDo opts register
|
||||
| any (cmd `isPrefixOf`) ["activity","histogram"] = showModeHelpOr activitymode $ withJournalDo opts histogram
|
||||
| cmd `isPrefixOf` "incomestatement" = showModeHelpOr activitymode $ withJournalDo opts incomestatement
|
||||
| any (cmd `isPrefixOf`) ["balancesheet","bs"] = showModeHelpOr activitymode $ withJournalDo opts balancesheet
|
||||
| cmd `isPrefixOf` "stats" = showModeHelpOr statsmode $ withJournalDo opts stats
|
||||
| not (null matchedaddon) = do
|
||||
when (debug_ opts) $ printf "running %s\n" shellcmd
|
||||
|
@ -72,6 +72,8 @@ mainmode addons = defmode {
|
||||
,postingsmode
|
||||
-- ,transactionsmode
|
||||
,activitymode
|
||||
,incomestatementmode
|
||||
,balancesheetmode
|
||||
,statsmode
|
||||
])
|
||||
]
|
||||
@ -235,6 +237,26 @@ activitymode = (commandmode ["activity","histogram"]) {
|
||||
}
|
||||
}
|
||||
|
||||
incomestatementmode = (commandmode ["incomestatement"]) {
|
||||
modeHelp = "show a standard income statement"
|
||||
,modeArgs = ([], Just commandargsflag)
|
||||
,modeGroupFlags = Group {
|
||||
groupUnnamed = []
|
||||
,groupHidden = []
|
||||
,groupNamed = [(generalflagstitle, generalflags1)]
|
||||
}
|
||||
}
|
||||
|
||||
balancesheetmode = (commandmode ["balancesheet","bs"]) {
|
||||
modeHelp = "show a standard balance sheet"
|
||||
,modeArgs = ([], Just commandargsflag)
|
||||
,modeGroupFlags = Group {
|
||||
groupUnnamed = []
|
||||
,groupHidden = []
|
||||
,groupNamed = [(generalflagstitle, generalflags1)]
|
||||
}
|
||||
}
|
||||
|
||||
statsmode = (commandmode ["stats"]) {
|
||||
modeHelp = "show quick statistics for a journal (or part of it)"
|
||||
,modeArgs = ([], Just commandargsflag)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
bin/hledger -f- bal
|
||||
bin/hledger -f- balance
|
||||
<<<
|
||||
1/1
|
||||
a 1.00
|
||||
|
Loading…
Reference in New Issue
Block a user