journal: account directive: parse and store a numeric account code also
This commit is contained in:
		
							parent
							
								
									88ef586480
								
							
						
					
					
						commit
						d420a8b534
					
				| @ -254,7 +254,7 @@ journalAccountNamesImplied = expandAccountNames . journalAccountNamesUsed | ||||
| 
 | ||||
| -- | Sorted unique account names declared by account directives in this journal. | ||||
| journalAccountNamesDeclared :: Journal -> [AccountName] | ||||
| journalAccountNamesDeclared = nub . sort . jaccounts | ||||
| journalAccountNamesDeclared = nub . sort . map fst . jaccounts | ||||
| 
 | ||||
| -- | Sorted unique account names declared by account directives or posted to | ||||
| -- by transactions in this journal. | ||||
|  | ||||
| @ -104,6 +104,7 @@ instance Default Interval where def = NoInterval | ||||
| instance NFData Interval | ||||
| 
 | ||||
| type AccountName = Text | ||||
| type AccountCode = Int | ||||
| 
 | ||||
| data AccountAlias = BasicAlias AccountName AccountName | ||||
|                   | RegexAlias Regexp Replacement | ||||
| @ -299,7 +300,7 @@ data Journal = Journal { | ||||
|   -- ,jparsetransactioncount :: Integer                               -- ^ the current count of transactions parsed so far (only journal format txns, currently) | ||||
|   ,jparsetimeclockentries :: [TimeclockEntry]                   -- ^ timeclock sessions which have not been clocked out | ||||
|   -- principal data | ||||
|   ,jaccounts              :: [AccountName]                         -- ^ accounts that have been declared by account directives | ||||
|   ,jaccounts              :: [(AccountName, Maybe AccountCode)]     -- ^ accounts that have been declared by account directives | ||||
|   ,jcommodities           :: M.Map CommoditySymbol Commodity        -- ^ commodities and formats declared by commodity directives | ||||
|   ,jinferredcommodities   :: M.Map CommoditySymbol AmountStyle      -- ^ commodities and formats inferred from journal amounts | ||||
|   ,jmarketprices          :: [MarketPrice] | ||||
|  | ||||
| @ -167,7 +167,7 @@ getAmountStyle commodity = do | ||||
|     return effectiveStyle | ||||
| 
 | ||||
| pushAccount :: AccountName -> JournalParser m () | ||||
| pushAccount acct = modify' (\j -> j{jaccounts = acct : jaccounts j}) | ||||
| pushAccount acct = modify' (\j -> j{jaccounts = (acct, Nothing) : jaccounts j}) | ||||
| 
 | ||||
| pushParentAccount :: AccountName -> JournalParser m () | ||||
| pushParentAccount acct = modify' (\j -> j{jparseparentaccounts = acct : jparseparentaccounts j}) | ||||
|  | ||||
| @ -234,11 +234,18 @@ accountdirectivep :: JournalParser m () | ||||
| accountdirectivep = do | ||||
|   string "account" | ||||
|   lift (some spacenonewline) | ||||
|   acct <- lift accountnamep | ||||
|   acct <- lift accountnamep  -- eats single spaces | ||||
|   macode' :: Maybe String <- (optional $ lift $ some spacenonewline >> some digitChar) | ||||
|   let macode :: Maybe AccountCode = read <$> macode' | ||||
|   newline | ||||
|   many indentedlinep | ||||
|   modify' (\j -> j{jaccounts = acct : jaccounts j}) | ||||
| 
 | ||||
|   _tags <- many $ do | ||||
|     startpos <- getPosition | ||||
|     l <- indentedlinep | ||||
|     case runTextParser (setPosition startpos >> tagsp) $ T.pack l of | ||||
|       Right ts -> return ts | ||||
|       Left _e   -> return [] -- TODO throwError $ parseErrorPretty e | ||||
|      | ||||
|   modify' (\j -> j{jaccounts = (acct, macode) : jaccounts j}) | ||||
| 
 | ||||
| indentedlinep :: JournalParser m String | ||||
| indentedlinep = lift (some spacenonewline) >> (rstrip <$> lift restofline) | ||||
|  | ||||
| @ -65,7 +65,7 @@ accounts CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do | ||||
|   let q = queryFromOpts d ropts | ||||
|       nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q | ||||
|       depth    = dbg1 "depth" $ queryDepth $ filterQuery queryIsDepth q | ||||
|       matcheddeclaredaccts = dbg1 "matcheddeclaredaccts" $ nub $ sort $ filter (matchesAccount q) $ jaccounts j | ||||
|       matcheddeclaredaccts = dbg1 "matcheddeclaredaccts" $ nub $ sort $ filter (matchesAccount q) $ map fst $ jaccounts j | ||||
|       matchedps = dbg1 "ps" $ journalPostings $ filterJournalPostings nodepthq j | ||||
|       matchedusedaccts = dbg1 "matchedusedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps | ||||
|       used     = boolopt "used"   rawopts | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user