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. | -- | Sorted unique account names declared by account directives in this journal. | ||||||
| journalAccountNamesDeclared :: Journal -> [AccountName] | journalAccountNamesDeclared :: Journal -> [AccountName] | ||||||
| journalAccountNamesDeclared = nub . sort . jaccounts | journalAccountNamesDeclared = nub . sort . map fst . jaccounts | ||||||
| 
 | 
 | ||||||
| -- | Sorted unique account names declared by account directives or posted to | -- | Sorted unique account names declared by account directives or posted to | ||||||
| -- by transactions in this journal. | -- by transactions in this journal. | ||||||
|  | |||||||
| @ -104,6 +104,7 @@ instance Default Interval where def = NoInterval | |||||||
| instance NFData Interval | instance NFData Interval | ||||||
| 
 | 
 | ||||||
| type AccountName = Text | type AccountName = Text | ||||||
|  | type AccountCode = Int | ||||||
| 
 | 
 | ||||||
| data AccountAlias = BasicAlias AccountName AccountName | data AccountAlias = BasicAlias AccountName AccountName | ||||||
|                   | RegexAlias Regexp Replacement |                   | 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) |   -- ,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 |   ,jparsetimeclockentries :: [TimeclockEntry]                   -- ^ timeclock sessions which have not been clocked out | ||||||
|   -- principal data |   -- 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 |   ,jcommodities           :: M.Map CommoditySymbol Commodity        -- ^ commodities and formats declared by commodity directives | ||||||
|   ,jinferredcommodities   :: M.Map CommoditySymbol AmountStyle      -- ^ commodities and formats inferred from journal amounts |   ,jinferredcommodities   :: M.Map CommoditySymbol AmountStyle      -- ^ commodities and formats inferred from journal amounts | ||||||
|   ,jmarketprices          :: [MarketPrice] |   ,jmarketprices          :: [MarketPrice] | ||||||
|  | |||||||
| @ -167,7 +167,7 @@ getAmountStyle commodity = do | |||||||
|     return effectiveStyle |     return effectiveStyle | ||||||
| 
 | 
 | ||||||
| pushAccount :: AccountName -> JournalParser m () | 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 :: AccountName -> JournalParser m () | ||||||
| pushParentAccount acct = modify' (\j -> j{jparseparentaccounts = acct : jparseparentaccounts j}) | pushParentAccount acct = modify' (\j -> j{jparseparentaccounts = acct : jparseparentaccounts j}) | ||||||
|  | |||||||
| @ -234,11 +234,18 @@ accountdirectivep :: JournalParser m () | |||||||
| accountdirectivep = do | accountdirectivep = do | ||||||
|   string "account" |   string "account" | ||||||
|   lift (some spacenonewline) |   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 |   newline | ||||||
|   many indentedlinep |   _tags <- many $ do | ||||||
|   modify' (\j -> j{jaccounts = acct : jaccounts j}) |     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 :: JournalParser m String | ||||||
| indentedlinep = lift (some spacenonewline) >> (rstrip <$> lift restofline) | indentedlinep = lift (some spacenonewline) >> (rstrip <$> lift restofline) | ||||||
|  | |||||||
| @ -65,7 +65,7 @@ accounts CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do | |||||||
|   let q = queryFromOpts d ropts |   let q = queryFromOpts d ropts | ||||||
|       nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q |       nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q | ||||||
|       depth    = dbg1 "depth" $ queryDepth $ filterQuery 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 |       matchedps = dbg1 "ps" $ journalPostings $ filterJournalPostings nodepthq j | ||||||
|       matchedusedaccts = dbg1 "matchedusedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps |       matchedusedaccts = dbg1 "matchedusedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps | ||||||
|       used     = boolopt "used"   rawopts |       used     = boolopt "used"   rawopts | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user