diff --git a/doc/MANUAL.md b/doc/MANUAL.md index 6c09c0c0b..af9590e98 100644 --- a/doc/MANUAL.md +++ b/doc/MANUAL.md @@ -751,17 +751,9 @@ The `--depth` option limits the amount of sub-account detail displayed: $ hledger register assets:bank:checking --depth 2 -With a [reporting interval](#reporting-interval) it shows aggregated -summary postings within each interval: - - $ hledger register --monthly rent - $ hledger register --monthly -E food --depth 4 - -Note that the report start/end dates will be "enlarged" in this case -so that they encompass the displayed intervals. This is so that the -first and last intervals will be "full" and comparable to the others. - -The `--average`/`-A` flag shows the running average posting amount instead of the running total. +The `--average`/`-A` flag shows the running average posting amount +instead of the running total (so, the final number displayed is the +average for the whole report period). This flag implies `--empty` (see below). The `--related`/`-r` flag shows the *other* postings in the transactions of the postings which would normally be shown. @@ -772,6 +764,22 @@ names, use `-w` to increase the width to 120 characters, or `-wN` to set any desired width (at least 50 recommended). Note, currently -w/--width can not have a space between flag and value ([#149](https://github.com/simonmichael/hledger/issues/149)). +With a [reporting interval](#reporting-interval) register shows +aggregated summary postings, within each interval: + + $ hledger register --monthly rent + $ hledger register --monthly -E food --depth 4 + +One summary posting will be shown for each account in each interval. +Summary postings with a zero amount are not shown; use the `--empty`/`-E` flag to show them. + +If necessary, use the `--depth` option to summarise the accounts. +It's often most useful to see just one line per interval. + +When using report intervals, the report's normal start/end dates are +"enlarged" to contain a whole number of intervals, so that the first +and last intervals will be "full" and comparable to the others. + #### balance The balance command displays accounts and their balances. diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index f00f842f1..76fa42e69 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -71,13 +71,13 @@ postingsReport opts q j = (totallabel, items) journalPostings $ journalSelectingAmountFromOpts opts j (precedingps, reportps) = dbg "precedingps, reportps" $ span (beforestartq `matchesPosting`) pstoend - empty = queryEmpty q + showempty = queryEmpty q || average_ opts -- displayexpr = display_ opts -- XXX interval = intervalFromOpts opts -- XXX whichdate = whichDateFromOpts opts itemps | interval == NoInterval = reportps - | otherwise = summarisePostingsByInterval interval whichdate depth empty reportspan reportps + | otherwise = summarisePostingsByInterval interval whichdate depth showempty reportspan reportps items = postingsReportItems itemps nullposting whichdate depth startbal runningcalc 1 where startbal = if balancetype_ opts == HistoricalBalance then sumPostings precedingps else 0 @@ -117,9 +117,9 @@ mkpostingsReportItem showdate showdesc wd p b = (if showdate then Just date else -- are one per account per interval and aggregated to the specified depth -- if any. summarisePostingsByInterval :: Interval -> WhichDate -> Int -> Bool -> DateSpan -> [Posting] -> [Posting] -summarisePostingsByInterval interval wd depth empty reportspan ps = concatMap summarisespan $ splitSpan interval reportspan +summarisePostingsByInterval interval wd depth showempty reportspan ps = concatMap summarisespan $ splitSpan interval reportspan where - summarisespan s = summarisePostingsInDateSpan s wd depth empty (postingsinspan s) + summarisespan s = summarisePostingsInDateSpan s wd depth showempty (postingsinspan s) postingsinspan s = filter (isPostingInDateSpan' wd s) ps tests_summarisePostingsByInterval = [ diff --git a/hledger/Hledger/Cli/Register.hs b/hledger/Hledger/Cli/Register.hs index b6cade419..d4b4eca1f 100644 --- a/hledger/Hledger/Cli/Register.hs +++ b/hledger/Hledger/Cli/Register.hs @@ -29,7 +29,7 @@ registermode = (defCommandMode $ ["register"] ++ aliases) { ,modeGroupFlags = Group { groupUnnamed = [ flagNone ["historical","H"] (\opts -> setboolopt "historical" opts) "include prior postings in the running total" - ,flagNone ["average","A"] (\opts -> setboolopt "average" opts) "show a running average instead of the running total" + ,flagNone ["average","A"] (\opts -> setboolopt "average" opts) "show a running average instead of the running total (implies --empty)" ,flagNone ["related","r"] (\opts -> setboolopt "related" opts) "show postings' siblings instead" ,flagReq ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N" "set output width (default: 80)" ]