web: inacctsubs: includes subs in an account register, with confusing balance
This commit is contained in:
		
							parent
							
								
									94208e44d5
								
							
						
					
					
						commit
						d35fbac422
					
				| @ -24,7 +24,7 @@ import Text.ParserCombinators.Parsec | |||||||
| 
 | 
 | ||||||
| import Hledger.Utils | import Hledger.Utils | ||||||
| import Hledger.Data.Types | import Hledger.Data.Types | ||||||
| -- import Hledger.Data.AccountName | import Hledger.Data.AccountName | ||||||
| -- import Hledger.Data.Amount | -- import Hledger.Data.Amount | ||||||
| -- import Hledger.Data.Commodity (canonicaliseCommodities) | -- import Hledger.Data.Commodity (canonicaliseCommodities) | ||||||
| import Hledger.Data.Dates | import Hledger.Data.Dates | ||||||
| @ -54,13 +54,22 @@ data Matcher = MatchAny                   -- ^ always match | |||||||
| 
 | 
 | ||||||
| -- XXX could use regular cli Opts ? | -- XXX could use regular cli Opts ? | ||||||
| data QueryOpt = QueryOptInAcct AccountName  -- ^ show an account register focussed on this account | data QueryOpt = QueryOptInAcct AccountName  -- ^ show an account register focussed on this account | ||||||
|  |               | QueryOptInAcctSubs AccountName -- ^ as above but include sub-accounts in the account register | ||||||
|            -- | QueryOptCostBasis      -- ^ show amounts converted to cost where possible |            -- | QueryOptCostBasis      -- ^ show amounts converted to cost where possible | ||||||
|            -- | QueryOptEffectiveDate  -- ^ show effective dates instead of actual dates |            -- | QueryOptEffectiveDate  -- ^ show effective dates instead of actual dates | ||||||
|     deriving (Show, Eq) |     deriving (Show, Eq) | ||||||
| 
 | 
 | ||||||
|  | -- | The account we are currently focussed on, if any. | ||||||
| inAccount :: [QueryOpt] -> Maybe AccountName | inAccount :: [QueryOpt] -> Maybe AccountName | ||||||
| inAccount []     = Nothing | inAccount []     = Nothing | ||||||
| inAccount (QueryOptInAcct a:_) = Just a | inAccount (QueryOptInAcct a:_) = Just a | ||||||
|  | inAccount (QueryOptInAcctSubs a:_) = Just a | ||||||
|  | 
 | ||||||
|  | -- | A matcher for the account(s) we are currently focussed on, if any. | ||||||
|  | inAccountMatcher :: [QueryOpt] -> Maybe Matcher | ||||||
|  | inAccountMatcher []     = Nothing | ||||||
|  | inAccountMatcher (QueryOptInAcct a:_) = Just $ MatchAcct True $ accountNameToAccountOnlyRegex a | ||||||
|  | inAccountMatcher (QueryOptInAcctSubs a:_) = Just $ MatchAcct True $ accountNameToAccountRegex a | ||||||
| 
 | 
 | ||||||
| -- | Convert a query expression containing zero or more space-separated | -- | Convert a query expression containing zero or more space-separated | ||||||
| -- terms to a matcher and zero or more query options. A query term is either: | -- terms to a matcher and zero or more query options. A query term is either: | ||||||
| @ -88,13 +97,14 @@ parseQuery d s = (m,qopts) | |||||||
| 
 | 
 | ||||||
| -- keep synced with patterns below, excluding "not" | -- keep synced with patterns below, excluding "not" | ||||||
| prefixes = map (++":") [ | prefixes = map (++":") [ | ||||||
|             "inacct" |             "inacct","subs", | ||||||
|            ,"desc","acct","date","edate","status","real","empty","depth" |             "desc","acct","date","edate","status","real","empty","depth" | ||||||
|            ] |            ] | ||||||
| defaultprefix = "acct" | defaultprefix = "acct" | ||||||
| 
 | 
 | ||||||
| -- | Parse a single query term as either a matcher or a query option. | -- | Parse a single query term as either a matcher or a query option. | ||||||
| parseMatcher :: Day -> String -> Either Matcher QueryOpt | parseMatcher :: Day -> String -> Either Matcher QueryOpt | ||||||
|  | parseMatcher _ ('i':'n':'a':'c':'c':'t':'s':'u':'b':'s':':':s) = Right $ QueryOptInAcctSubs s | ||||||
| parseMatcher _ ('i':'n':'a':'c':'c':'t':':':s) = Right $ QueryOptInAcct s | parseMatcher _ ('i':'n':'a':'c':'c':'t':':':s) = Right $ QueryOptInAcct s | ||||||
| parseMatcher d ('n':'o':'t':':':s) = case parseMatcher d $ quoteIfSpaced s of | parseMatcher d ('n':'o':'t':':':s) = case parseMatcher d $ quoteIfSpaced s of | ||||||
|                                        Left m  -> Left $ negateMatcher m |                                        Left m  -> Left $ negateMatcher m | ||||||
|  | |||||||
| @ -97,8 +97,8 @@ postRegisterOnlyR = handlePost | |||||||
| -- temporary helper - use the new account register report when in:ACCT is specified. | -- temporary helper - use the new account register report when in:ACCT is specified. | ||||||
| accountOrJournalRegisterReport :: ViewData -> Journal -> RegisterReport | accountOrJournalRegisterReport :: ViewData -> Journal -> RegisterReport | ||||||
| accountOrJournalRegisterReport VD{opts=opts,m=m,qopts=qopts} j = | accountOrJournalRegisterReport VD{opts=opts,m=m,qopts=qopts} j = | ||||||
|     case inAccount qopts of Just a  -> accountRegisterReport opts j m a |     case inAccountMatcher qopts of Just m'  -> accountRegisterReport opts j m m' | ||||||
|                             Nothing -> registerReport opts nullfilterspec $ filterJournalPostings2 m j |                                    Nothing -> registerReport opts nullfilterspec $ filterJournalPostings2 m j | ||||||
| 
 | 
 | ||||||
| -- | A simple accounts view, like hledger balance. If the Accept header | -- | A simple accounts view, like hledger balance. If the Accept header | ||||||
| -- specifies json, returns the chart of accounts as json. | -- specifies json, returns the chart of accounts as json. | ||||||
| @ -129,14 +129,13 @@ balanceReportAsHtml :: [Opt] -> ViewData -> BalanceReport -> Hamlet AppRoute | |||||||
| balanceReportAsHtml _ vd@VD{here=here,q=q,m=m,qopts=qopts,j=j} (items,total) = $(Settings.hamletFile "balancereport") | balanceReportAsHtml _ vd@VD{here=here,q=q,m=m,qopts=qopts,j=j} (items,total) = $(Settings.hamletFile "balancereport") | ||||||
|  where |  where | ||||||
|    filtering = not $ null q |    filtering = not $ null q | ||||||
|    inacct = inAccount qopts |    inacctmatcher = inAccountMatcher qopts | ||||||
|    itemAsHtml :: ViewData -> BalanceReportItem -> Hamlet AppRoute |    itemAsHtml :: ViewData -> BalanceReportItem -> Hamlet AppRoute | ||||||
|    itemAsHtml VD{here=here,q=q} (acct, adisplay, aindent, abal) = $(Settings.hamletFile "balancereportitem") |    itemAsHtml VD{here=here,q=q} (acct, adisplay, aindent, abal) = $(Settings.hamletFile "balancereportitem") | ||||||
|      where |      where | ||||||
|        depthclass = "depth"++show aindent |        depthclass = "depth"++show aindent | ||||||
|        inclass | Just acct == inacct = "inacct" |        inclass = case inacctmatcher of Just m -> if m `matchesAccount` acct then "inacct" else "notinacct" | ||||||
|                | isJust inacct       = "notinacct" |                                        Nothing -> "" :: String | ||||||
|                | otherwise           = "" :: String |  | ||||||
|        indent = preEscapedString $ concat $ replicate (2 * aindent) " " |        indent = preEscapedString $ concat $ replicate (2 * aindent) " " | ||||||
|        accturl = (here, [("q", pack $ accountUrl acct)]) |        accturl = (here, [("q", pack $ accountUrl acct)]) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -113,15 +113,13 @@ registerReport opts fspec j = (totallabel,postingsToRegisterReportItems ps nullp | |||||||
| -- | -- | ||||||
| -- Does not handle reporting intervals. | -- Does not handle reporting intervals. | ||||||
| -- | -- | ||||||
| accountRegisterReport :: [Opt] -> Journal -> Matcher -> AccountName -> RegisterReport | accountRegisterReport :: [Opt] -> Journal -> Matcher -> Matcher -> RegisterReport | ||||||
| accountRegisterReport opts j m a = (label, postingsToRegisterReportItems displayps nullposting startbal sumfn) | accountRegisterReport opts j m thisacctmatcher = (label, postingsToRegisterReportItems displayps nullposting startbal sumfn) | ||||||
|  where |  where | ||||||
|       -- displayps' | interval == NoInterval = displayps |       -- displayps' | interval == NoInterval = displayps | ||||||
|       --            | otherwise              = summarisePostingsByInterval interval depth empty filterspan displayps |       --            | otherwise              = summarisePostingsByInterval interval depth empty filterspan displayps | ||||||
| 
 | 
 | ||||||
|      -- transactions affecting this account |      -- transactions affecting this account | ||||||
|      a' = accountNameToAccountOnlyRegex a |  | ||||||
|      thisacctmatcher = MatchAcct True a' |  | ||||||
|      ts = filter (matchesTransaction thisacctmatcher) $ jtxns j |      ts = filter (matchesTransaction thisacctmatcher) $ jtxns j | ||||||
| 
 | 
 | ||||||
|      -- all postings in these transactions |      -- all postings in these transactions | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user