bugfix for #514, is and cf are now period reports, and bs, as a snapshot report, is treated as a special case
This commit is contained in:
		
							parent
							
								
									3dab20c654
								
							
						
					
					
						commit
						f5a530d620
					
				| @ -27,11 +27,13 @@ import Hledger.Cli.CliOptions | |||||||
| -- | Describes a view for the balance, which can consist of multiple | -- | Describes a view for the balance, which can consist of multiple | ||||||
| -- separate named queries that are aggregated and totaled. | -- separate named queries that are aggregated and totaled. | ||||||
| data BalanceView = BalanceView { | data BalanceView = BalanceView { | ||||||
|       bvmode    :: String,                        -- ^ command line mode of the view |       bvmode     :: String,                        -- ^ command line mode of the view | ||||||
|       bvaliases :: [String],                      -- ^ command line aliases |       bvaliases  :: [String],                      -- ^ command line aliases | ||||||
|       bvhelp    :: String,                        -- ^ command line help message |       bvhelp     :: String,                        -- ^ command line help message | ||||||
|       bvtitle   :: String,                        -- ^ title of the view |       bvtitle    :: String,                        -- ^ title of the view | ||||||
|       bvqueries :: [(String, Journal -> Query)]   -- ^ named queries that make up the view |       bvqueries  :: [(String, Journal -> Query)],  -- ^ named queries that make up the view | ||||||
|  |       bvsnapshot :: Bool                           -- ^ whether or not the view is a snapshot, | ||||||
|  |                                                    --   ignoring begin date in reporting period | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| balanceviewmode :: BalanceView -> Mode RawOpts | balanceviewmode :: BalanceView -> Mode RawOpts | ||||||
| @ -52,14 +54,14 @@ balanceviewmode BalanceView{..} = (defCommandMode $ bvmode : bvaliases) { | |||||||
| 
 | 
 | ||||||
| balanceviewQueryReport | balanceviewQueryReport | ||||||
|     :: ReportOpts |     :: ReportOpts | ||||||
|     -> Day |     -> Query | ||||||
|     -> Journal |     -> Journal | ||||||
|     -> String |     -> String | ||||||
|     -> (Journal -> Query) |     -> (Journal -> Query) | ||||||
|     -> ([String], Sum MixedAmount) |     -> ([String], Sum MixedAmount) | ||||||
| balanceviewQueryReport ropts currDay j t q = ([view], Sum amt) | balanceviewQueryReport ropts q0 j t q = ([view], Sum amt) | ||||||
|     where |     where | ||||||
|       q' = And [queryFromOpts currDay (withoutBeginDate ropts), q j] |       q' = And [q0, q j] | ||||||
|       rep@(_ , amt) = balanceReport ropts q' j |       rep@(_ , amt) = balanceReport ropts q' j | ||||||
|       view = intercalate "\n" [t <> ":", balanceReportAsText ropts rep] |       view = intercalate "\n" [t <> ":", balanceReportAsText ropts rep] | ||||||
| 
 | 
 | ||||||
| @ -67,8 +69,10 @@ balanceviewQueryReport ropts currDay j t q = ([view], Sum amt) | |||||||
| balanceviewReport :: BalanceView -> CliOpts -> Journal -> IO () | balanceviewReport :: BalanceView -> CliOpts -> Journal -> IO () | ||||||
| balanceviewReport BalanceView{..} CliOpts{reportopts_=ropts} j = do | balanceviewReport BalanceView{..} CliOpts{reportopts_=ropts} j = do | ||||||
|   currDay   <- getCurrentDay |   currDay   <- getCurrentDay | ||||||
|   let (views, amt) = |   let q0 | bvsnapshot = queryFromOpts currDay (withoutBeginDate ropts) | ||||||
|         foldMap (uncurry (balanceviewQueryReport ropts currDay j)) |          | otherwise  = queryFromOpts currDay ropts | ||||||
|  |       (views, amt) = | ||||||
|  |         foldMap (uncurry (balanceviewQueryReport ropts q0 j)) | ||||||
|            bvqueries |            bvqueries | ||||||
|   mapM_ putStrLn (bvtitle : "" : views) |   mapM_ putStrLn (bvtitle : "" : views) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -19,13 +19,14 @@ import Hledger.Cli.CliOptions | |||||||
| import Hledger.Cli.BalanceView | import Hledger.Cli.BalanceView | ||||||
| 
 | 
 | ||||||
| bsBV = BalanceView { | bsBV = BalanceView { | ||||||
|          bvmode    = "balancesheet", |          bvmode     = "balancesheet", | ||||||
|          bvaliases = ["bs"], |          bvaliases  = ["bs"], | ||||||
|          bvhelp    = "show a balance sheet", |          bvhelp     = "show a balance sheet", | ||||||
|          bvtitle   = "Balance Sheet", |          bvtitle    = "Balance Sheet", | ||||||
|          bvqueries = [ ("Assets"     , journalAssetAccountQuery), |          bvqueries  = [ ("Assets"     , journalAssetAccountQuery), | ||||||
|                        ("Liabilities", journalLiabilityAccountQuery) |                         ("Liabilities", journalLiabilityAccountQuery) | ||||||
|                      ] |                       ], | ||||||
|  |          bvsnapshot = True | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
| balancesheetmode :: Mode RawOpts | balancesheetmode :: Mode RawOpts | ||||||
|  | |||||||
| @ -22,11 +22,12 @@ import Hledger.Cli.CliOptions | |||||||
| import Hledger.Cli.BalanceView | import Hledger.Cli.BalanceView | ||||||
| 
 | 
 | ||||||
| cfBV = BalanceView { | cfBV = BalanceView { | ||||||
|          bvmode    = "cashflow", |          bvmode     = "cashflow", | ||||||
|          bvaliases = ["cf"], |          bvaliases  = ["cf"], | ||||||
|          bvhelp    = "show a cashflow statement", |          bvhelp     = "show a cashflow statement", | ||||||
|          bvtitle   = "Cashflow Statement", |          bvtitle    = "Cashflow Statement", | ||||||
|          bvqueries = [("Cash flows", journalCashAccountQuery)] |          bvqueries  = [("Cash flows", journalCashAccountQuery)], | ||||||
|  |          bvsnapshot = False | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
| cashflowmode :: Mode RawOpts | cashflowmode :: Mode RawOpts | ||||||
|  | |||||||
| @ -19,13 +19,14 @@ import Hledger.Cli.CliOptions | |||||||
| import Hledger.Cli.BalanceView | import Hledger.Cli.BalanceView | ||||||
| 
 | 
 | ||||||
| isBV = BalanceView { | isBV = BalanceView { | ||||||
|          bvmode    = "incomestatement", |          bvmode     = "incomestatement", | ||||||
|          bvaliases = ["is"], |          bvaliases  = ["is"], | ||||||
|          bvhelp    = "show an income statement", |          bvhelp     = "show an income statement", | ||||||
|          bvtitle   = "Income Statement", |          bvtitle    = "Income Statement", | ||||||
|          bvqueries = [ ("Revenues", journalIncomeAccountQuery), |          bvqueries  = [ ("Revenues", journalIncomeAccountQuery), | ||||||
|                        ("Expenses", journalExpenseAccountQuery) |                         ("Expenses", journalExpenseAccountQuery) | ||||||
|                      ] |                       ], | ||||||
|  |          bvsnapshot = False | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
| incomestatementmode :: Mode RawOpts | incomestatementmode :: Mode RawOpts | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user