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.Data.Types | ||||
| -- import Hledger.Data.AccountName | ||||
| import Hledger.Data.AccountName | ||||
| -- import Hledger.Data.Amount | ||||
| -- import Hledger.Data.Commodity (canonicaliseCommodities) | ||||
| import Hledger.Data.Dates | ||||
| @ -54,13 +54,22 @@ data Matcher = MatchAny                   -- ^ always match | ||||
| 
 | ||||
| -- XXX could use regular cli Opts ? | ||||
| 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 | ||||
|            -- | QueryOptEffectiveDate  -- ^ show effective dates instead of actual dates | ||||
|     deriving (Show, Eq) | ||||
| 
 | ||||
| -- | The account we are currently focussed on, if any. | ||||
| inAccount :: [QueryOpt] -> Maybe AccountName | ||||
| inAccount []     = Nothing | ||||
| 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 | ||||
| -- 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" | ||||
| prefixes = map (++":") [ | ||||
|             "inacct" | ||||
|            ,"desc","acct","date","edate","status","real","empty","depth" | ||||
|             "inacct","subs", | ||||
|             "desc","acct","date","edate","status","real","empty","depth" | ||||
|            ] | ||||
| defaultprefix = "acct" | ||||
| 
 | ||||
| -- | Parse a single query term as either a matcher or a query option. | ||||
| 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 d ('n':'o':'t':':':s) = case parseMatcher d $ quoteIfSpaced s of | ||||
|                                        Left m  -> Left $ negateMatcher m | ||||
|  | ||||
| @ -97,7 +97,7 @@ postRegisterOnlyR = handlePost | ||||
| -- temporary helper - use the new account register report when in:ACCT is specified. | ||||
| accountOrJournalRegisterReport :: ViewData -> Journal -> RegisterReport | ||||
| 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 | ||||
| 
 | ||||
| -- | A simple accounts view, like hledger balance. If the Accept header | ||||
| @ -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") | ||||
|  where | ||||
|    filtering = not $ null q | ||||
|    inacct = inAccount qopts | ||||
|    inacctmatcher = inAccountMatcher qopts | ||||
|    itemAsHtml :: ViewData -> BalanceReportItem -> Hamlet AppRoute | ||||
|    itemAsHtml VD{here=here,q=q} (acct, adisplay, aindent, abal) = $(Settings.hamletFile "balancereportitem") | ||||
|      where | ||||
|        depthclass = "depth"++show aindent | ||||
|        inclass | Just acct == inacct = "inacct" | ||||
|                | isJust inacct       = "notinacct" | ||||
|                | otherwise           = "" :: String | ||||
|        inclass = case inacctmatcher of Just m -> if m `matchesAccount` acct then "inacct" else "notinacct" | ||||
|                                        Nothing -> "" :: String | ||||
|        indent = preEscapedString $ concat $ replicate (2 * aindent) " " | ||||
|        accturl = (here, [("q", pack $ accountUrl acct)]) | ||||
| 
 | ||||
|  | ||||
| @ -113,15 +113,13 @@ registerReport opts fspec j = (totallabel,postingsToRegisterReportItems ps nullp | ||||
| -- | ||||
| -- Does not handle reporting intervals. | ||||
| -- | ||||
| accountRegisterReport :: [Opt] -> Journal -> Matcher -> AccountName -> RegisterReport | ||||
| accountRegisterReport opts j m a = (label, postingsToRegisterReportItems displayps nullposting startbal sumfn) | ||||
| accountRegisterReport :: [Opt] -> Journal -> Matcher -> Matcher -> RegisterReport | ||||
| accountRegisterReport opts j m thisacctmatcher = (label, postingsToRegisterReportItems displayps nullposting startbal sumfn) | ||||
|  where | ||||
|       -- displayps' | interval == NoInterval = displayps | ||||
|       --            | otherwise              = summarisePostingsByInterval interval depth empty filterspan displayps | ||||
| 
 | ||||
|      -- transactions affecting this account | ||||
|      a' = accountNameToAccountOnlyRegex a | ||||
|      thisacctmatcher = MatchAcct True a' | ||||
|      ts = filter (matchesTransaction thisacctmatcher) $ jtxns j | ||||
| 
 | ||||
|      -- all postings in these transactions | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user