-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Core data types, parsers and utilities for the hledger accounting tool.
--   
--   hledger is a library and set of user tools for working with financial
--   data (or anything that can be tracked in a double-entry accounting
--   ledger.) It is a haskell port and friendly fork of John Wiegley's
--   Ledger. hledger provides command-line, curses and web interfaces, and
--   aims to be a reliable, practical tool for daily use.
@package hledger-lib
@version 0.17


-- | UTF-8 aware string IO functions that will work with GHC 6.10 or 6.12.
module Hledger.Utils.UTF8
readFile :: FilePath -> IO String
writeFile :: FilePath -> String -> IO ()
appendFile :: FilePath -> String -> IO ()
getContents :: IO String
hGetContents :: Handle -> IO String
putStr :: String -> IO ()
putStrLn :: String -> IO ()
hPutStr :: Handle -> String -> IO ()
hPutStrLn :: Handle -> String -> IO ()


-- | Most data types are defined here to avoid import cycles. Here is an
--   overview of the hledger data model:
--   
--   <pre>
--   Journal                  -- a journal is read from one or more data files. It contains..
--    [Transaction]           -- journal transactions (aka entries), which have date, status, code, description and..
--     [Posting]              -- multiple account postings, which have account name and amount
--    [HistoricalPrice]       -- historical commodity prices
--   
--   Ledger                   -- a ledger is derived from a journal, by applying a filter specification and doing some further processing. It contains..
--    Journal                 -- a filtered copy of the original journal, containing only the transactions and postings we are interested in
--    Tree AccountName        -- all accounts named by the journal's transactions, as a hierarchy
--    Map AccountName Account -- the postings, and resulting balances, in each account
--   </pre>
--   
--   For more detailed documentation on each type, see the corresponding
--   modules.
--   
--   Evolution of transaction/entry/posting terminology:
--   
--   <ul>
--   <li>ledger 2: entries contain transactions</li>
--   <li>hledger 0.4: Entrys contain RawTransactions (which are flattened
--   to Transactions)</li>
--   <li>ledger 3: transactions contain postings</li>
--   <li>hledger 0.5: LedgerTransactions contain Postings (which are
--   flattened to Transactions)</li>
--   <li>hledger 0.8: Transactions contain Postings (referencing
--   Transactions..)</li>
--   </ul>
module Hledger.Data.Types
type SmartDate = (String, String, String)
data WhichDate
ActualDate :: WhichDate
EffectiveDate :: WhichDate
data DateSpan
DateSpan :: (Maybe Day) -> (Maybe Day) -> DateSpan
data Interval
NoInterval :: Interval
Days :: Int -> Interval
Weeks :: Int -> Interval
Months :: Int -> Interval
Quarters :: Int -> Interval
Years :: Int -> Interval
DayOfMonth :: Int -> Interval
DayOfWeek :: Int -> Interval
type AccountName = String
data Side
L :: Side
R :: Side
data Commodity
Commodity :: String -> Side -> Bool -> Int -> Char -> Char -> [Int] -> Commodity

-- | the commodity's symbol display preferences for amounts of this
--   commodity
symbol :: Commodity -> String

-- | should the symbol appear on the left or the right
side :: Commodity -> Side

-- | should there be a space between symbol and quantity
spaced :: Commodity -> Bool

-- | number of decimal places to display XXX these three might be better
--   belonging to Journal
precision :: Commodity -> Int

-- | character to use as decimal point
decimalpoint :: Commodity -> Char

-- | character to use for separating digit groups (eg thousands)
separator :: Commodity -> Char

-- | positions of separators, counting leftward from decimal point
separatorpositions :: Commodity -> [Int]

-- | An amount's price in another commodity may be written as @ unit price
--   or @@ total price. Note although a MixedAmount is used, it should be
--   in a single commodity, also the amount should be positive; these are
--   not enforced currently.
data Price
UnitPrice :: MixedAmount -> Price
TotalPrice :: MixedAmount -> Price
data Amount
Amount :: Commodity -> Double -> Maybe Price -> Amount
commodity :: Amount -> Commodity
quantity :: Amount -> Double

-- | the price for this amount at posting time
price :: Amount -> Maybe Price
newtype MixedAmount
Mixed :: [Amount] -> MixedAmount
data PostingType
RegularPosting :: PostingType
VirtualPosting :: PostingType
BalancedVirtualPosting :: PostingType
data Posting
Posting :: Bool -> AccountName -> MixedAmount -> String -> PostingType -> [(String, String)] -> Maybe Transaction -> Posting
pstatus :: Posting -> Bool
paccount :: Posting -> AccountName
pamount :: Posting -> MixedAmount
pcomment :: Posting -> String
ptype :: Posting -> PostingType
pmetadata :: Posting -> [(String, String)]

-- | this posting's parent transaction (co-recursive types). Tying this
--   knot gets tedious, Maybe makes it easier/optional.
ptransaction :: Posting -> Maybe Transaction
data Transaction
Transaction :: Day -> Maybe Day -> Bool -> String -> String -> String -> [(String, String)] -> [Posting] -> String -> Transaction
tdate :: Transaction -> Day
teffectivedate :: Transaction -> Maybe Day
tstatus :: Transaction -> Bool
tcode :: Transaction -> String
tdescription :: Transaction -> String
tcomment :: Transaction -> String
tmetadata :: Transaction -> [(String, String)]

-- | this transaction's postings (co-recursive types).
tpostings :: Transaction -> [Posting]
tpreceding_comment_lines :: Transaction -> String
data ModifierTransaction
ModifierTransaction :: String -> [Posting] -> ModifierTransaction
mtvalueexpr :: ModifierTransaction -> String
mtpostings :: ModifierTransaction -> [Posting]
data PeriodicTransaction
PeriodicTransaction :: String -> [Posting] -> PeriodicTransaction
ptperiodicexpr :: PeriodicTransaction -> String
ptpostings :: PeriodicTransaction -> [Posting]
data TimeLogCode
SetBalance :: TimeLogCode
SetRequiredHours :: TimeLogCode
In :: TimeLogCode
Out :: TimeLogCode
FinalOut :: TimeLogCode
data TimeLogEntry
TimeLogEntry :: TimeLogCode -> LocalTime -> String -> TimeLogEntry
tlcode :: TimeLogEntry -> TimeLogCode
tldatetime :: TimeLogEntry -> LocalTime
tlcomment :: TimeLogEntry -> String
data HistoricalPrice
HistoricalPrice :: Day -> String -> MixedAmount -> HistoricalPrice
hdate :: HistoricalPrice -> Day
hsymbol :: HistoricalPrice -> String
hamount :: HistoricalPrice -> MixedAmount
type Year = Integer

-- | A journal <a>context</a> is some data which can change in the course
--   of parsing a journal. An example is the default year, which changes
--   when a Y directive is encountered. At the end of parsing, the final
--   context is saved for later use by eg the add command.
data JournalContext
Ctx :: !Maybe Year -> !Maybe Commodity -> ![AccountName] -> ![(AccountName, AccountName)] -> JournalContext

-- | the default year most recently specified with Y
ctxYear :: JournalContext -> !Maybe Year

-- | the default commodity most recently specified with D
ctxCommodity :: JournalContext -> !Maybe Commodity

-- | the current stack of parent accounts/account name components specified
--   with <a>account</a> directive(s). Concatenated, these are the account
--   prefix prepended to parsed account names.
ctxAccount :: JournalContext -> ![AccountName]

-- | the current list of account name aliases in effect
ctxAliases :: JournalContext -> ![(AccountName, AccountName)]
data Journal
Journal :: [ModifierTransaction] -> [PeriodicTransaction] -> [Transaction] -> [TimeLogEntry] -> [HistoricalPrice] -> String -> JournalContext -> [(FilePath, String)] -> ClockTime -> Journal
jmodifiertxns :: Journal -> [ModifierTransaction]
jperiodictxns :: Journal -> [PeriodicTransaction]
jtxns :: Journal -> [Transaction]
open_timelog_entries :: Journal -> [TimeLogEntry]
historical_prices :: Journal -> [HistoricalPrice]

-- | any trailing comments from the journal file
final_comment_lines :: Journal -> String

-- | the context (parse state) at the end of parsing
jContext :: Journal -> JournalContext

-- | the file path and raw text of the main and any included journal files.
--   The main file is first followed by any included files in the order
--   encountered.
files :: Journal -> [(FilePath, String)]

-- | when this journal was last read from its file(s)
filereadtime :: Journal -> ClockTime

-- | A JournalUpdate is some transformation of a Journal. It can do I/O or
--   raise an error.
type JournalUpdate = ErrorT String IO (Journal -> Journal)

-- | A hledger journal reader is a triple of format name, format-detecting
--   predicate, and a parser to Journal.
data Reader
Reader :: String -> (FilePath -> String -> Bool) -> (FilePath -> String -> ErrorT String IO Journal) -> Reader
rFormat :: Reader -> String
rDetector :: Reader -> FilePath -> String -> Bool
rParser :: Reader -> FilePath -> String -> ErrorT String IO Journal
data Ledger
Ledger :: Journal -> Tree AccountName -> Map AccountName Account -> Ledger
journal :: Ledger -> Journal
accountnametree :: Ledger -> Tree AccountName
accountmap :: Ledger -> Map AccountName Account
data Account
Account :: AccountName -> [Posting] -> MixedAmount -> Account
aname :: Account -> AccountName

-- | postings in this account
apostings :: Account -> [Posting]

-- | sum of postings in this account and subaccounts
abalance :: Account -> MixedAmount

-- | A generic, pure specification of how to filter (or search)
--   transactions and postings.
data FilterSpec
FilterSpec :: DateSpan -> Maybe Bool -> Bool -> Bool -> [String] -> [String] -> Maybe Int -> FilterSpec

-- | only include if in this date span
datespan :: FilterSpec -> DateSpan

-- | only include if cleared/uncleared/don't care
cleared :: FilterSpec -> Maybe Bool

-- | only include if real/don't care
real :: FilterSpec -> Bool

-- | include if empty (ie amount is zero)
empty :: FilterSpec -> Bool

-- | only include if matching these account patterns
acctpats :: FilterSpec -> [String]

-- | only include if matching these description patterns
descpats :: FilterSpec -> [String]
depth :: FilterSpec -> Maybe Int
instance Typeable Journal
instance Eq WhichDate
instance Show WhichDate
instance Eq DateSpan
instance Show DateSpan
instance Ord DateSpan
instance Eq Interval
instance Show Interval
instance Ord Interval
instance Eq Side
instance Show Side
instance Read Side
instance Ord Side
instance Eq Commodity
instance Ord Commodity
instance Show Commodity
instance Read Commodity
instance Eq MixedAmount
instance Ord MixedAmount
instance Eq Amount
instance Ord Amount
instance Eq Price
instance Ord Price
instance Eq PostingType
instance Show PostingType
instance Eq Transaction
instance Eq ModifierTransaction
instance Eq PeriodicTransaction
instance Eq TimeLogCode
instance Ord TimeLogCode
instance Eq TimeLogEntry
instance Ord TimeLogEntry
instance Eq HistoricalPrice
instance Read JournalContext
instance Show JournalContext
instance Eq JournalContext
instance Eq Journal
instance Show FilterSpec
instance Eq Posting


-- | Standard imports and utilities which are useful everywhere, or needed
--   low in the module hierarchy. This is the bottom of hledger's module
--   graph.
module Hledger.Utils
lowercase :: [Char] -> [Char]
uppercase :: [Char] -> [Char]
strip :: [Char] -> [Char]
lstrip :: [Char] -> [Char]
rstrip :: [Char] -> [Char]
elideLeft :: Int -> [Char] -> [Char]
elideRight :: Int -> [Char] -> [Char]
underline :: String -> String

-- | Wrap a string in single quotes, and -prefix any embedded single
--   quotes, if it contains whitespace and is not already single- or
--   double-quoted.
quoteIfSpaced :: String -> String

-- | Quote-aware version of words - don't split on spaces which are inside
--   quotes. NB correctly handles <a>a'b</a> but not <a>''a''</a>.
words' :: String -> [String]

-- | Quote-aware version of unwords - single-quote strings which contain
--   whitespace
unwords' :: [String] -> String
singleQuoteIfNeeded :: [Char] -> [Char]
whitespacechars :: [Char]

-- | Strip one matching pair of single or double quotes on the ends of a
--   string.
stripquotes :: String -> String
isSingleQuoted :: [Char] -> Bool
isDoubleQuoted :: [Char] -> Bool
unbracket :: String -> String

-- | Join multi-line strings as side-by-side rectangular strings of the
--   same height, top-padded.
concatTopPadded :: [String] -> String

-- | Join multi-line strings as side-by-side rectangular strings of the
--   same height, bottom-padded.
concatBottomPadded :: [String] -> String

-- | Compose strings vertically and right-aligned.
vConcatRightAligned :: [String] -> String

-- | Convert a multi-line string to a rectangular string top-padded to the
--   specified height.
padtop :: Int -> String -> String

-- | Convert a multi-line string to a rectangular string bottom-padded to
--   the specified height.
padbottom :: Int -> String -> String

-- | Convert a multi-line string to a rectangular string left-padded to the
--   specified width.
padleft :: Int -> String -> String

-- | Convert a multi-line string to a rectangular string right-padded to
--   the specified width.
padright :: Int -> String -> String

-- | Clip a multi-line string to the specified width and height from the
--   top left.
cliptopleft :: Int -> Int -> String -> String

-- | Clip and pad a multi-line string to fill the specified width and
--   height.
fitto :: Int -> Int -> String -> String

-- | A platform string is a string value from or for the operating system,
--   such as a file path or command-line argument (or environment
--   variable's name or value ?). On some platforms (such as unix) these
--   are not real unicode strings but have some encoding such as UTF-8.
--   This alias does no type enforcement but aids code clarity.
type PlatformString = String

-- | Convert a possibly encoded platform string to a real unicode string.
--   We decode the UTF-8 encoding recommended for unix systems (cf
--   http:<i></i>www.dwheeler.com<i>essays</i>fixing-unix-linux-filenames.html)
--   and leave anything else unchanged.
fromPlatformString :: PlatformString -> String

-- | Convert a unicode string to a possibly encoded platform string. On
--   unix we encode with the recommended UTF-8 (cf
--   http:<i></i>www.dwheeler.com<i>essays</i>fixing-unix-linux-filenames.html)
--   and elsewhere we leave it unchanged.
toPlatformString :: String -> PlatformString

-- | A version of error that's better at displaying unicode.
error' :: String -> a

-- | A version of userError that's better at displaying unicode.
userError' :: String -> IOError
difforzero :: (Num a, Ord a) => a -> a -> a
regexMatch :: String -> String -> Maybe (RegexResult, MatchList)
regexMatchCI :: String -> String -> Maybe (RegexResult, MatchList)
regexMatches :: String -> String -> Bool
regexMatchesCI :: String -> String -> Bool
containsRegex :: String -> String -> Bool
regexReplace :: String -> String -> String -> String
regexReplaceCI :: String -> String -> String -> String
regexReplaceBy :: String -> (String -> String) -> String -> String
regexToCaseInsensitive :: String -> String
splitAtElement :: Eq a => a -> [a] -> [[a]]
root :: Tree a -> a
subs :: Tree a -> Forest a
branches :: Tree a -> Forest a

-- | List just the leaf nodes of a tree
leaves :: Tree a -> [a]

-- | get the sub-tree rooted at the first (left-most, depth-first)
--   occurrence of the specified node value
subtreeat :: Eq a => a -> Tree a -> Maybe (Tree a)

-- | get the sub-tree for the specified node value in the first tree in
--   forest in which it occurs.
subtreeinforest :: Eq a => a -> [Tree a] -> Maybe (Tree a)

-- | remove all nodes past a certain depth
treeprune :: Int -> Tree a -> Tree a

-- | apply f to all tree nodes
treemap :: (a -> b) -> Tree a -> Tree b

-- | remove all subtrees whose nodes do not fulfill predicate
treefilter :: (a -> Bool) -> Tree a -> Tree a

-- | is predicate true in any node of tree ?
treeany :: (a -> Bool) -> Tree a -> Bool

-- | show a compact ascii representation of a tree
showtree :: Show a => Tree a -> String

-- | show a compact ascii representation of a forest
showforest :: Show a => Forest a -> String

-- | trace (print on stdout at runtime) a showable expression (for easily
--   tracing in the middle of a complex expression)
strace :: Show a => a -> a

-- | labelled trace - like strace, with a label prepended
ltrace :: Show a => String -> a -> a

-- | monadic trace - like strace, but works as a standalone line in a monad
mtrace :: (Monad m, Show a) => a -> m a

-- | trace an expression using a custom show function
tracewith :: (a -> String) -> a -> a

-- | Backtracking choice, use this when alternatives share a prefix.
--   Consumes no input if all choices fail.
choice' :: [GenParser tok st a] -> GenParser tok st a
parsewith :: Parser a -> String -> Either ParseError a
parseWithCtx :: b -> GenParser Char b a -> String -> Either ParseError a
fromparse :: Either ParseError a -> a
parseerror :: ParseError -> a
showParseError :: ParseError -> String
showDateParseError :: ParseError -> String
nonspace :: GenParser Char st Char
spacenonewline :: GenParser Char st Char
restofline :: GenParser Char st String
getCurrentLocalTime :: IO LocalTime

-- | Get a Test's label, or the empty string.
tname :: Test -> String

-- | Flatten a Test containing TestLists into a list of single tests.
tflatten :: Test -> [Test]

-- | Filter TestLists in a Test, recursively, preserving the structure.
tfilter :: (Test -> Bool) -> Test -> Test

-- | Simple way to assert something is some expected value, with no label.
is :: (Eq a, Show a) => a -> a -> Assertion

-- | Assert a parse result is successful, printing the parse error on
--   failure.
assertParse :: (Either ParseError a) -> Assertion

-- | Assert a parse result is successful, printing the parse error on
--   failure.
assertParseFailure :: (Either ParseError a) -> Assertion

-- | Assert a parse result is some expected value, printing the parse error
--   on failure.
assertParseEqual :: (Show a, Eq a) => (Either ParseError a) -> a -> Assertion
printParseError :: Show a => a -> IO ()
isLeft :: Either a b -> Bool
isRight :: Either a b -> Bool

-- | Apply a function the specified number of times. Possibly uses O(n)
--   stack ?
applyN :: Int -> (a -> a) -> a -> a

-- | The <a>trace</a> function outputs the trace message given as its first
--   argument, before returning the second argument as its result.
--   
--   For example, this returns the value of <tt>f x</tt> but first outputs
--   the message.
--   
--   <pre>
--   trace ("calling f with x = " ++ show x) (f x)
--   </pre>
--   
--   The <a>trace</a> function should <i>only</i> be used for debugging, or
--   for monitoring execution. The function is not referentially
--   transparent: its type indicates that it is a pure function but it has
--   the side effect of outputting the trace message.
trace :: String -> a -> a


-- | <a>AccountName</a>s are strings like <tt>assets:cash:petty</tt>, with
--   multiple components separated by <tt>:</tt>. From a set of these we
--   derive the account hierarchy.
module Hledger.Data.AccountName
acctsepchar :: Char
accountNameComponents :: AccountName -> [String]
accountNameFromComponents :: [String] -> AccountName
accountLeafName :: AccountName -> String
accountNameLevel :: AccountName -> Int
accountNameDrop :: Int -> AccountName -> AccountName

-- | <ul>
--   <li><i><a>a:b:c</a>,<a>d:e</a></i> -&gt;
--   [<a>a</a>,<a>a:b</a>,<a>a:b:c</a>,<a>d</a>,<a>d:e</a>]</li>
--   </ul>
expandAccountNames :: [AccountName] -> [AccountName]

-- | <ul>
--   <li><i><a>a:b:c</a>,<a>d:e</a></i> -&gt; [<a>a</a>,<a>d</a>]</li>
--   </ul>
topAccountNames :: [AccountName] -> [AccountName]
parentAccountName :: AccountName -> AccountName
parentAccountNames :: AccountName -> [AccountName]
isAccountNamePrefixOf :: AccountName -> AccountName -> Bool
isSubAccountNameOf :: AccountName -> AccountName -> Bool

-- | From a list of account names, select those which are direct
--   subaccounts of the given account name.
subAccountNamesFrom :: [AccountName] -> AccountName -> [AccountName]

-- | Convert a list of account names to a tree.
accountNameTreeFrom :: [AccountName] -> Tree AccountName
accountNameTreeFrom1 :: [AccountName] -> Tree [Char]
nullaccountnametree :: Tree [Char]
accountNameTreeFrom2 :: [AccountName] -> Tree [Char]
accountNameTreeFrom3 :: [AccountName] -> Tree [Char]
newtype Tree' a
T :: (Map a (Tree' a)) -> Tree' a
mergeTrees :: Ord a => Tree' a -> Tree' a -> Tree' a
emptyTree :: Tree' a
pathtree :: [a] -> Tree' a
fromPaths :: Ord a => [[a]] -> Tree' a
converttree :: Tree' AccountName -> [Tree AccountName]
expandTreeNames :: Tree AccountName -> Tree AccountName
accountNameTreeFrom4 :: [AccountName] -> Tree AccountName

-- | Elide an account name to fit in the specified width. From the ledger
--   2.6 news:
--   
--   <pre>
--      What Ledger now does is that if an account name is too long, it will
--      start abbreviating the first parts of the account name down to two
--      letters in length.  If this results in a string that is still too
--      long, the front will be elided -- not the end.  For example:
--   
--   Expenses:Cash           ; OK, not too long
--        Ex:Wednesday:Cash       ; <a>Expenses</a> was abbreviated to fit
--        Ex:We:Afternoon:Cash    ; <a>Expenses</a> and <a>Wednesday</a> abbreviated
--        ; Expenses:Wednesday:Afternoon:Lunch:Snack:Candy:Chocolate:Cash
--        ..:Af:Lu:Sn:Ca:Ch:Cash  ; Abbreviated and elided!
--   </pre>
elideAccountName :: Int -> AccountName -> AccountName
clipAccountName :: Int -> AccountName -> AccountName

-- | Convert an account name to a regular expression matching it and its
--   subaccounts.
accountNameToAccountRegex :: String -> String

-- | Convert an account name to a regular expression matching it and its
--   subaccounts.
accountNameToAccountOnlyRegex :: String -> String

-- | Convert an exact account-matching regular expression to a plain
--   account name.
accountRegexToAccountName :: String -> String

-- | Does this string look like an exact account-matching regular
--   expression ?
isAccountRegex :: String -> Bool
tests_Hledger_Data_AccountName :: Test
instance Show a => Show (Tree' a)
instance Eq a => Eq (Tree' a)
instance Ord a => Ord (Tree' a)


-- | A <a>Commodity</a> is a symbol representing a currency or some other
--   kind of thing we are tracking, and some display preferences that tell
--   how to display <a>Amount</a>s of the commodity - is the symbol on the
--   left or right, are thousands separated by comma, significant decimal
--   places and so on.
module Hledger.Data.Commodity
nonsimplecommoditychars :: [Char]
quoteCommoditySymbolIfNeeded :: [Char] -> [Char]
unknown :: Commodity
dollar :: Commodity
euro :: Commodity
pound :: Commodity
hour :: Commodity
dollars :: Double -> Amount
euros :: Double -> Amount
pounds :: Double -> Amount
hours :: Double -> Amount
defaultcommodities :: [Commodity]

-- | Look up one of the hard-coded default commodities. For use in tests.
comm :: String -> Commodity

-- | Find the conversion rate between two commodities. Currently returns 1.
conversionRate :: Commodity -> Commodity -> Double

-- | Convert a list of commodities to a map from commodity symbols to
--   unique, display-preference-canonicalised commodities.
canonicaliseCommodities :: [Commodity] -> Map String Commodity
tests_Hledger_Data_Commodity :: Test


-- | A simple <a>Amount</a> is some quantity of money, shares, or anything
--   else. It has a (possibly null) <a>Commodity</a> and a numeric
--   quantity:
--   
--   <pre>
--   $1 
--   £-50
--   EUR 3.44 
--   GOOG 500
--   1.5h
--   90 apples
--   0 
--   </pre>
--   
--   It may also have an assigned <a>Price</a>, representing this amount's
--   per-unit or total cost in a different commodity. If present, this is
--   rendered like so:
--   
--   <pre>
--   EUR 2 @ $1.50  (unit price)
--   EUR 2 @@ $3   (total price)
--   </pre>
--   
--   A <a>MixedAmount</a> is zero or more simple amounts, so can represent
--   multiple commodities; this is the type most often used:
--   
--   <pre>
--   0
--   $50 + EUR 3
--   16h + $13.55 + AAPL 500 + 6 oranges
--   </pre>
--   
--   When a mixed amount has been "normalised", it has no more than one
--   amount in each commodity and no zero amounts; or it has just a single
--   zero amount and no others.
--   
--   Limited arithmetic with simple and mixed amounts is supported, best
--   used with similar amounts since it mostly ignores assigned prices and
--   commodity exchange rates.
module Hledger.Data.Amount

-- | The empty simple amount.
nullamt :: Amount

-- | Convert an amount to the specified commodity, ignoring and discarding
--   any assigned prices and assuming an exchange rate of 1.
amountWithCommodity :: Commodity -> Amount -> Amount

-- | Replace an amount's commodity with the canonicalised version from the
--   provided commodity map.
canonicaliseAmountCommodity :: Maybe (Map String Commodity) -> Amount -> Amount

-- | Set the display precision in the amount's commodity.
setAmountPrecision :: Int -> Amount -> Amount

-- | Convert an amount to the commodity of its assigned price, if any.
--   Notes:
--   
--   <ul>
--   <li>price amounts must be MixedAmounts with exactly one component
--   Amount (or there will be a runtime error)</li>
--   <li>price amounts should be positive, though this is not currently
--   enforced</li>
--   </ul>
costOfAmount :: Amount -> Amount

-- | Divide an amount's quantity by a constant.
divideAmount :: Amount -> Double -> Amount

-- | Get the string representation of an amount, based on its commodity's
--   display settings. String representations equivalent to zero are
--   converted to just "0".
showAmount :: Amount -> String

-- | Get the unambiguous string representation of an amount, for debugging.
showAmountDebug :: Amount -> String

-- | Get the string representation of an amount, without any @ price.
showAmountWithoutPrice :: Amount -> String

-- | For rendering: a special precision value which means show all
--   available digits.
maxprecision :: Int

-- | For rendering: a special precision value which forces display of a
--   decimal point.
maxprecisionwithpoint :: Int

-- | The empty mixed amount.
nullmixedamt :: MixedAmount

-- | A temporary value for parsed transactions which had no amount
--   specified.
missingamt :: MixedAmount

-- | Get a mixed amount's component amounts.
amounts :: MixedAmount -> [Amount]

-- | Simplify a mixed amount's component amounts: combine amounts with the
--   same commodity, using the first amount's price for subsequent amounts
--   in each commodity (ie, this function alters the amount and is best
--   used as a rendering helper.). Also remove any zero amounts and replace
--   an empty amount list with a single zero amount.
normaliseMixedAmountPreservingFirstPrice :: MixedAmount -> MixedAmount

-- | Replace a mixed amount's commodity with the canonicalised version from
--   the provided commodity map.
canonicaliseMixedAmountCommodity :: Maybe (Map String Commodity) -> MixedAmount -> MixedAmount
mixedAmountWithCommodity :: Commodity -> MixedAmount -> Amount

-- | Set the display precision in the amount's commodities.
setMixedAmountPrecision :: Int -> MixedAmount -> MixedAmount

-- | Convert a mixed amount's component amounts to the commodity of their
--   assigned price, if any.
costOfMixedAmount :: MixedAmount -> MixedAmount

-- | Divide a mixed amount's quantities by a constant.
divideMixedAmount :: MixedAmount -> Double -> MixedAmount

-- | Is this mixed amount negative, if it can be normalised to a single
--   commodity ?
isNegativeMixedAmount :: MixedAmount -> Maybe Bool

-- | Does this mixed amount appear to be zero when displayed with its given
--   precision ?
isZeroMixedAmount :: MixedAmount -> Bool

-- | Is this mixed amount <a>really</a> zero, after converting to cost
--   commodities where possible ?
isReallyZeroMixedAmountCost :: MixedAmount -> Bool

-- | Get the string representation of a mixed amount, showing each of its
--   component amounts. NB a mixed amount can have an empty amounts list in
--   which case it shows as "".
showMixedAmount :: MixedAmount -> String

-- | Get an unambiguous string representation of a mixed amount for
--   debugging.
showMixedAmountDebug :: MixedAmount -> String

-- | Get the string representation of a mixed amount, but without any @
--   prices.
showMixedAmountWithoutPrice :: MixedAmount -> String

-- | Get the string representation of a mixed amount, showing each of its
--   component amounts with the specified precision, ignoring their
--   commoditys' display precision settings.
showMixedAmountWithPrecision :: Int -> MixedAmount -> String
tests_Hledger_Data_Amount :: Test
instance Show HistoricalPrice
instance Num MixedAmount
instance Show MixedAmount
instance Num Amount
instance Show Amount


-- | An <a>Account</a> stores
--   
--   <ul>
--   <li>an <a>AccountName</a>,</li>
--   <li>all <a>Posting</a>s in the account, excluding subaccounts</li>
--   <li>a <a>MixedAmount</a> representing the account balance, including
--   subaccounts.</li>
--   </ul>
module Hledger.Data.Account
nullacct :: Account
tests_Hledger_Data_Account :: Test
instance Eq Account
instance Show Account


-- | Date parsing and utilities for hledger.
--   
--   For date and time values, we use the standard Day and UTCTime types.
--   
--   A <a>SmartDate</a> is a date which may be partially-specified or
--   relative. Eg 2008/12/31, but also 2008/12, 12/31, tomorrow, last week,
--   next year. We represent these as a triple of strings like
--   ("2008","12",""), ("","","tomorrow"), ("","last","week").
--   
--   A <a>DateSpan</a> is the span of time between two specific calendar
--   dates, or an open-ended span where one or both dates are unspecified.
--   (A date span with both ends unspecified matches all dates.)
--   
--   An <a>Interval</a> is ledger's "reporting interval" - weekly, monthly,
--   quarterly, etc.
module Hledger.Data.Dates
showDate :: Day -> String

-- | Get the current local date.
getCurrentDay :: IO Day

-- | Get the current local month number.
getCurrentMonth :: IO Int

-- | Get the current local year.
getCurrentYear :: IO Integer
elapsedSeconds :: Fractional a => UTCTime -> UTCTime -> a

-- | Split a DateSpan into one or more consecutive spans at the specified
--   interval.
splitSpan :: Interval -> DateSpan -> [DateSpan]
splitspan :: (Day -> Day) -> (Day -> Day) -> DateSpan -> [DateSpan]

-- | Count the days in a DateSpan, or if it is open-ended return Nothing.
daysInSpan :: DateSpan -> Maybe Integer

-- | Does the span include the given date ?
spanContainsDate :: DateSpan -> Day -> Bool

-- | Combine two datespans, filling any unspecified dates in the first with
--   dates from the second.
orDatesFrom :: DateSpan -> DateSpan -> DateSpan

-- | Calculate the intersection of two datespans.
spanIntersect :: DateSpan -> DateSpan -> DateSpan
latest :: Ord a => Maybe a -> Maybe a -> Maybe a
earliest :: Ord a => Maybe a -> Maybe a -> Maybe a

-- | Parse a period expression to an Interval and overall DateSpan using
--   the provided reference date, or return a parse error.
parsePeriodExpr :: Day -> String -> Either ParseError (Interval, DateSpan)
maybePeriod :: Day -> String -> Maybe (Interval, DateSpan)

-- | Show a DateSpan as a human-readable pseudo-period-expression string.
dateSpanAsText :: DateSpan -> String

-- | Convert a single smart date string to a date span using the provided
--   reference date, or raise an error.
spanFromSmartDateString :: Day -> String -> DateSpan
spanFromSmartDate :: Day -> SmartDate -> DateSpan
showDay :: Day -> String

-- | Convert a smart date string to an explicit yyyy/mm/dd string using the
--   provided reference date, or raise an error.
fixSmartDateStr :: Day -> String -> String

-- | A safe version of fixSmartDateStr.
fixSmartDateStrEither :: Day -> String -> Either ParseError String
fixSmartDateStrEither' :: Day -> String -> Either ParseError Day

-- | Convert a SmartDate to an absolute date using the provided reference
--   date.
fixSmartDate :: Day -> SmartDate -> Day
prevday :: Day -> Day
nextday :: Day -> Day
startofday :: a -> a
thisweek :: Day -> Day
prevweek :: Day -> Day
nextweek :: Day -> Day
startofweek :: Day -> Day
thismonth :: Day -> Day
prevmonth :: Day -> Day
nextmonth :: Day -> Day
startofmonth :: Day -> Day
thisquarter :: Day -> Day
prevquarter :: Day -> Day
nextquarter :: Day -> Day
startofquarter :: Day -> Day
thisyear :: Day -> Day
prevyear :: Day -> Day
nextyear :: Day -> Day
startofyear :: Day -> Day
nthdayofmonthcontaining :: Integral a => a -> Day -> Day
nthdayofweekcontaining :: Integral a => a -> Day -> Day
firstJust :: Eq a => [Maybe a] -> Maybe a

-- | Parse a couple of date-time string formats to a time type.
parsedatetimeM :: String -> Maybe LocalTime

-- | Parse a couple of date string formats to a time type.
parsedateM :: String -> Maybe Day

-- | Parse a date-time string to a time type, or raise an error.
parsedatetime :: String -> LocalTime

-- | Parse a date string to a time type, or raise an error.
parsedate :: String -> Day

-- | Parse a time string to a time type using the provided pattern, or
--   return the default.
parsetimewith :: ParseTime t => String -> String -> t -> t

-- | Parse a date in any of the formats allowed in ledger's period
--   expressions, and maybe some others:
--   
--   <pre>
--   2004
--   2004/10
--   2004/10/1
--   10/1
--   21
--   october, oct
--   yesterday, today, tomorrow
--   this/next/last week/day/month/quarter/year
--   </pre>
--   
--   Returns a SmartDate, to be converted to a full date later (see
--   fixSmartDate). Assumes any text in the parse stream has been
--   lowercased.
smartdate :: GenParser Char st SmartDate

-- | Like smartdate, but there must be nothing other than whitespace after
--   the date.
smartdateonly :: GenParser Char st SmartDate
datesepchars :: [Char]
datesepchar :: ParsecT [Char] u Identity Char
validYear :: String -> Bool
validDay :: String -> Bool
validMonth :: String -> Bool
failIfInvalidYear :: Monad m => String -> m ()
failIfInvalidDay :: Monad m => String -> m ()
failIfInvalidMonth :: Monad m => String -> m ()
yyyymmdd :: GenParser Char st SmartDate
ymd :: GenParser Char st SmartDate
ym :: GenParser Char st SmartDate
y :: GenParser Char st SmartDate
d :: GenParser Char st SmartDate
md :: GenParser Char st SmartDate
months :: [[Char]]
monthabbrevs :: [[Char]]
weekdays :: [[Char]]
weekdayabbrevs :: [[Char]]
monthIndex :: [Char] -> Int
monIndex :: [Char] -> Int
month :: GenParser Char st SmartDate
mon :: GenParser Char st SmartDate
today :: GenParser Char st SmartDate
tomorrow :: GenParser Char st SmartDate
yesterday :: GenParser Char st SmartDate
lastthisnextthing :: GenParser Char st SmartDate
periodexpr :: Day -> GenParser Char st (Interval, DateSpan)
intervalanddateperiodexpr :: Day -> GenParser Char st (Interval, DateSpan)
intervalperiodexpr :: GenParser Char st (Interval, DateSpan)
dateperiodexpr :: Day -> GenParser Char st (Interval, DateSpan)
reportinginterval :: GenParser Char st Interval
periodexprdatespan :: Day -> GenParser Char st DateSpan
doubledatespan :: Day -> GenParser Char st DateSpan
fromdatespan :: Day -> GenParser Char st DateSpan
todatespan :: Day -> GenParser Char st DateSpan
justdatespan :: Day -> GenParser Char st DateSpan

-- | Make a datespan from two valid date strings parseable by parsedate (or
--   raise an error). Eg: mkdatespan "2011<i>1</i>1" "2011<i>12</i>31".
mkdatespan :: String -> String -> DateSpan
nulldatespan :: DateSpan
nulldate :: Day
tests_Hledger_Data_Dates :: Test


-- | A <a>Posting</a> represents a <a>MixedAmount</a> being added to or
--   subtracted from a single <a>Account</a>. Each <a>Transaction</a>
--   contains two or more postings which should add up to 0. Postings also
--   reference their parent transaction, so we can get a date or
--   description for a posting (from the transaction). Strictly speaking,
--   "entry" is probably a better name for these.
module Hledger.Data.Posting
nullposting :: Posting
showPosting :: Posting -> String
showPostingForRegister :: Posting -> String
isReal :: Posting -> Bool
isVirtual :: Posting -> Bool
isBalancedVirtual :: Posting -> Bool
hasAmount :: Posting -> Bool
accountNamesFromPostings :: [Posting] -> [AccountName]
sumPostings :: [Posting] -> MixedAmount
postingDate :: Posting -> Day

-- | Is this posting cleared? If this posting was individually marked as
--   cleared, returns True. Otherwise, return the parent transaction's
--   cleared status or, if there is no parent transaction, return False.
postingCleared :: Posting -> Bool

-- | Does this posting fall within the given date span ?
isPostingInDateSpan :: DateSpan -> Posting -> Bool
isEmptyPosting :: Posting -> Bool

-- | Get the minimal date span which contains all the postings, or DateSpan
--   Nothing Nothing if there are none.
postingsDateSpan :: [Posting] -> DateSpan
accountNamePostingType :: AccountName -> PostingType
accountNameWithoutPostingType :: AccountName -> AccountName
accountNameWithPostingType :: PostingType -> AccountName -> AccountName

-- | Prefix one account name to another, preserving posting type indicators
--   like concatAccountNames.
joinAccountNames :: AccountName -> AccountName -> AccountName

-- | Join account names into one. If any of them has () or [] posting type
--   indicators, these (the first type encountered) will also be applied to
--   the resulting account name.
concatAccountNames :: [AccountName] -> AccountName

-- | Rewrite an account name using the first applicable alias from the
--   given list, if any.
accountNameApplyAliases :: [(AccountName, AccountName)] -> AccountName -> AccountName
tests_Hledger_Data_Posting :: Test
instance Show Posting


-- | A <a>Transaction</a> consists of two or more related <a>Posting</a>s
--   which balance to zero, representing a movement of some commodity(ies)
--   between accounts, plus a date and optional metadata like description
--   and cleared status.
module Hledger.Data.Transaction
nulltransaction :: Transaction

-- | Show a journal transaction, formatted for the print command. ledger
--   2.x's standard format looks like this:
--   
--   <pre>
--   yyyy<i>mm</i>dd[ *][ CODE] description.........          [  ; comment...............]
--       account name 1.....................  ...$amount1[  ; comment...............]
--       account name 2.....................  ..$-amount1[  ; comment...............]
--   
--   pcodewidth    = no limit -- 10          -- mimicking ledger layout.
--   pdescwidth    = no limit -- 20          -- I don't remember what these mean,
--   pacctwidth    = 35 minimum, no maximum  -- they were important at the time.
--   pamtwidth     = 11
--   pcommentwidth = no limit -- 22
--   </pre>
showTransaction :: Transaction -> String
showTransactionUnelided :: Transaction -> String
showTransaction' :: Bool -> Transaction -> String

-- | Show an account name, clipped to the given width if any, and
--   appropriately bracketed/parenthesised for the given posting type.
showAccountName :: Maybe Int -> PostingType -> AccountName -> String
hasRealPostings :: Transaction -> Bool
realPostings :: Transaction -> [Posting]
virtualPostings :: Transaction -> [Posting]
balancedVirtualPostings :: Transaction -> [Posting]
transactionsPostings :: [Transaction] -> [Posting]

-- | Get the sums of a transaction's real, virtual, and balanced virtual
--   postings.
transactionPostingBalances :: Transaction -> (MixedAmount, MixedAmount, MixedAmount)

-- | Is this transaction balanced ? A balanced transaction's real
--   (non-virtual) postings sum to 0, and any balanced virtual postings
--   also sum to 0.
isTransactionBalanced :: Maybe (Map String Commodity) -> Transaction -> Bool

-- | Ensure this transaction is balanced, possibly inferring a missing
--   amount or conversion price, or return an error message.
--   
--   Balancing is affected by commodity display precisions, so those may be
--   provided.
--   
--   We can infer a missing real amount when there are multiple real
--   postings and exactly one of them is amountless (likewise for balanced
--   virtual postings). Inferred amounts are converted to cost basis when
--   possible.
--   
--   We can infer a conversion price when all real amounts are specified
--   and the sum of real postings' amounts is exactly two
--   non-explicitly-priced amounts in different commodities (likewise for
--   balanced virtual postings).
balanceTransaction :: Maybe (Map String Commodity) -> Transaction -> Either String Transaction
nonzerobalanceerror :: Transaction -> String
transactionActualDate :: Transaction -> Day
transactionEffectiveDate :: Transaction -> Day

-- | Once we no longer need both, set the main transaction date to either
--   the actual or effective date. A bit hacky.
journalTransactionWithDate :: WhichDate -> Transaction -> Transaction

-- | Ensure a transaction's postings refer back to it.
txnTieKnot :: Transaction -> Transaction

-- | Set a posting's parent transaction.
settxn :: Transaction -> Posting -> Posting
tests_Hledger_Data_Transaction :: Test
instance Show PeriodicTransaction
instance Show ModifierTransaction
instance Show Transaction


-- | More generic matching, done in one step, unlike FilterSpec and
--   filterJournal*. Currently used only by hledger-web.
module Hledger.Data.Matching

-- | A matcher is a single, or boolean composition of, search criteria,
--   which can be used to match postings, transactions, accounts and more.
--   Currently used by hledger-web, will likely replace FilterSpec at some
--   point.
data Matcher

-- | always match
MatchAny :: Matcher

-- | never match
MatchNone :: Matcher

-- | negate this match
MatchNot :: Matcher -> Matcher

-- | match if any of these match
MatchOr :: [Matcher] -> Matcher

-- | match if all of these match
MatchAnd :: [Matcher] -> Matcher

-- | match if description matches this regexp
MatchDesc :: String -> Matcher

-- | match postings whose account matches this regexp
MatchAcct :: String -> Matcher

-- | match if actual date in this date span
MatchDate :: DateSpan -> Matcher

-- | match if effective date in this date span
MatchEDate :: DateSpan -> Matcher

-- | match if cleared status has this value
MatchStatus :: Bool -> Matcher

-- | match if <a>realness</a> (involves a real non-virtual account ?) has
--   this value
MatchReal :: Bool -> Matcher

-- | match if <a>emptiness</a> (from the --empty command-line flag) has
--   this value. Currently this means a posting with zero amount.
MatchEmpty :: Bool -> Matcher

-- | match if account depth is less than or equal to this value
MatchDepth :: Int -> Matcher

-- | A query option changes a query's/report's behaviour and output in some
--   way.
data QueryOpt

-- | show an account register focussed on this account
QueryOptInAcctOnly :: AccountName -> QueryOpt

-- | 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
QueryOptInAcct :: AccountName -> QueryOpt

-- | The account we are currently focussed on, if any, and whether
--   subaccounts are included. Just looks at the first query option.
inAccount :: [QueryOpt] -> Maybe (AccountName, Bool)

-- | A matcher for the account(s) we are currently focussed on, if any.
--   Just looks at the first query option.
inAccountMatcher :: [QueryOpt] -> Maybe Matcher

-- | 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:
--   
--   <ol>
--   <li>a search criteria, used to match transactions. This is usually a
--   prefixed pattern such as: acct:REGEXP date:PERIODEXP
--   not:desc:REGEXP</li>
--   <li>a query option, which changes behaviour in some way. There is
--   currently one of these: inacct:FULLACCTNAME - should appear only
--   once</li>
--   </ol>
--   
--   Multiple search criteria are AND'ed together. When a pattern contains
--   spaces, it or the whole term should be enclosed in single or double
--   quotes. A reference date is required to interpret relative dates in
--   period expressions.
parseQuery :: Day -> String -> (Matcher, [QueryOpt])

-- | Quote-and-prefix-aware version of words - don't split on spaces which
--   are inside quotes, including quotes which may have one of the
--   specified prefixes in front, and maybe an additional not: prefix in
--   front of that.
words'' :: [String] -> String -> [String]
prefixes :: [[Char]]
defaultprefix :: [Char]

-- | Parse a single query term as either a matcher or a query option.
parseMatcher :: Day -> String -> Either Matcher QueryOpt

-- | Parse the boolean value part of a <a>status:</a> matcher, allowing
--   <a>*</a> as another way to spell True, similar to the journal file
--   format.
parseStatus :: String -> Bool

-- | Parse the boolean value part of a <a>status:</a> matcher. A true value
--   can be spelled as <a>1</a>, <a>t</a> or <a>true</a>.
parseBool :: String -> Bool
truestrings :: [String]

-- | Convert a match expression to its inverse.
negateMatcher :: Matcher -> Matcher

-- | Does the match expression match this posting ?
matchesPosting :: Matcher -> Posting -> Bool

-- | Does the match expression match this transaction ?
matchesTransaction :: Matcher -> Transaction -> Bool
postingEffectiveDate :: Posting -> Maybe Day

-- | Does the match expression match this account ? A matching in: clause
--   is also considered a match.
matchesAccount :: Matcher -> AccountName -> Bool

-- | What start date does this matcher specify, if any ? If the matcher is
--   an OR expression, returns the earliest of the alternatives. When the
--   flag is true, look for a starting effective date instead.
matcherStartDate :: Bool -> Matcher -> Maybe Day

-- | Does this matcher specify a start date and nothing else (that would
--   filter postings prior to the date) ? When the flag is true, look for a
--   starting effective date instead.
matcherIsStartDateOnly :: Bool -> Matcher -> Bool

-- | Does this matcher match everything ?
matcherIsNull :: Matcher -> Bool

-- | What is the earliest of these dates, where Nothing is earliest ?
earliestMaybeDate :: [Maybe Day] -> Maybe Day

-- | What is the latest of these dates, where Nothing is earliest ?
latestMaybeDate :: [Maybe Day] -> Maybe Day

-- | Compare two maybe dates, Nothing is earliest.
compareMaybeDates :: Maybe Day -> Maybe Day -> Ordering
tests_Hledger_Data_Matching :: Test
instance Show Matcher
instance Eq Matcher
instance Show QueryOpt
instance Eq QueryOpt


-- | A <a>TimeLogEntry</a> is a clock-in, clock-out, or other directive in
--   a timelog file (see timeclock.el or the command-line version). These
--   can be converted to <tt>Transactions</tt> and queried like a ledger.
module Hledger.Data.TimeLog

-- | Convert time log entries to journal transactions. When there is no
--   clockout, add one with the provided current time. Sessions crossing
--   midnight are split into days to give accurate per-day totals.
timeLogEntriesToTransactions :: LocalTime -> [TimeLogEntry] -> [Transaction]

-- | Convert a timelog clockin and clockout entry to an equivalent journal
--   transaction, representing the time expenditure. Note this entry is not
--   balanced, since we omit the "assets:time" transaction for simpler
--   output.
entryFromTimeLogInOut :: TimeLogEntry -> TimeLogEntry -> Transaction
tests_Hledger_Data_TimeLog :: Test
instance Read TimeLogCode
instance Show TimeLogCode
instance Show TimeLogEntry


-- | A <a>Journal</a> is a set of <a>Transaction</a>s and related data,
--   usually parsed from a hledger/ledger journal file or timelog. This is
--   the primary hledger data object.
module Hledger.Data.Journal
showJournalDebug :: Journal -> String
nulljournal :: Journal
nullctx :: JournalContext
nullfilterspec :: FilterSpec
journalFilePath :: Journal -> FilePath
journalFilePaths :: Journal -> [FilePath]
mainfile :: Journal -> (FilePath, String)
addTransaction :: Transaction -> Journal -> Journal
addModifierTransaction :: ModifierTransaction -> Journal -> Journal
addPeriodicTransaction :: PeriodicTransaction -> Journal -> Journal
addHistoricalPrice :: HistoricalPrice -> Journal -> Journal
addTimeLogEntry :: TimeLogEntry -> Journal -> Journal
journalPostings :: Journal -> [Posting]
journalAccountNamesUsed :: Journal -> [AccountName]
journalAccountNames :: Journal -> [AccountName]
journalAccountNameTree :: Journal -> Tree AccountName

-- | Keep only postings matching the query expression. This can leave
--   unbalanced transactions.
filterJournalPostings2 :: Matcher -> Journal -> Journal

-- | Keep only transactions matching the query expression.
filterJournalTransactions2 :: Matcher -> Journal -> Journal

-- | Keep only transactions we are interested in, as described by the
--   filter specification.
filterJournalTransactions :: FilterSpec -> Journal -> Journal

-- | Keep only postings we are interested in, as described by the filter
--   specification. This can leave unbalanced transactions.
filterJournalPostings :: FilterSpec -> Journal -> Journal

-- | Keep only transactions whose description matches the description
--   patterns.
filterJournalTransactionsByDescription :: [String] -> Journal -> Journal

-- | Keep only transactions which fall between begin and end dates. We
--   include transactions on the begin date and exclude transactions on the
--   end date, like ledger. An empty date string means no restriction.
filterJournalTransactionsByDate :: DateSpan -> Journal -> Journal

-- | Keep only transactions which have the requested cleared/uncleared
--   status, if there is one.
filterJournalTransactionsByClearedStatus :: Maybe Bool -> Journal -> Journal

-- | Keep only postings which have the requested cleared/uncleared status,
--   if there is one.
filterJournalPostingsByClearedStatus :: Maybe Bool -> Journal -> Journal

-- | Strip out any virtual postings, if the flag is true, otherwise do no
--   filtering.
filterJournalPostingsByRealness :: Bool -> Journal -> Journal

-- | Strip out any postings with zero amount, unless the flag is true.
filterJournalPostingsByEmpty :: Bool -> Journal -> Journal

-- | Keep only transactions which affect accounts deeper than the specified
--   depth.
filterJournalTransactionsByDepth :: Maybe Int -> Journal -> Journal

-- | Strip out any postings to accounts deeper than the specified depth
--   (and any transactions which have no postings as a result).
filterJournalPostingsByDepth :: Maybe Int -> Journal -> Journal

-- | Keep only transactions which affect accounts matched by the account
--   patterns. More precisely: each positive account pattern excludes
--   transactions which do not contain a posting to a matched account, and
--   each negative account pattern excludes transactions containing a
--   posting to a matched account.
filterJournalTransactionsByAccount :: [String] -> Journal -> Journal

-- | Keep only postings which affect accounts matched by the account
--   patterns. This can leave transactions unbalanced.
filterJournalPostingsByAccount :: [String] -> Journal -> Journal

-- | Convert this journal's transactions' primary date to either the actual
--   or effective date.
journalSelectingDate :: WhichDate -> Journal -> Journal

-- | Apply additional account aliases (eg from the command-line) to all
--   postings in a journal.
journalApplyAliases :: [(AccountName, AccountName)] -> Journal -> Journal

-- | Do post-parse processing on a journal, to make it ready for use.
journalFinalise :: ClockTime -> LocalTime -> FilePath -> String -> JournalContext -> Journal -> Either String Journal

-- | Fill in any missing amounts and check that all journal transactions
--   balance, or return an error message. This is done after parsing all
--   amounts and working out the canonical commodities, since balancing
--   depends on display precision. Reports only the first error
--   encountered.
journalBalanceTransactions :: Journal -> Either String Journal

-- | Convert all the journal's posting amounts (not price amounts) to their
--   canonical display settings. Ie, all amounts in a given commodity will
--   use (a) the display settings of the first, and (b) the greatest
--   precision, of the posting amounts in that commodity.
journalCanonicaliseAmounts :: Journal -> Journal

-- | Apply this journal's historical price records to unpriced amounts
--   where possible.
journalApplyHistoricalPrices :: Journal -> Journal

-- | Get the price for a commodity on the specified day from the price
--   database, if known. Does only one lookup step, ie will not look up the
--   price of a price.
journalHistoricalPriceFor :: Journal -> Day -> Commodity -> Maybe MixedAmount

-- | Close any open timelog sessions in this journal using the provided
--   current time.
journalCloseTimeLogEntries :: LocalTime -> Journal -> Journal

-- | Convert all this journal's amounts to cost by applying their prices,
--   if any.
journalConvertAmountsToCost :: Journal -> Journal

-- | Get this journal's unique, display-preference-canonicalised
--   commodities, by symbol.
journalCanonicalCommodities :: Journal -> Map String Commodity

-- | Get all this journal's amounts' commodities, in the order parsed.
journalAmountCommodities :: Journal -> [Commodity]

-- | Get all this journal's amount and price commodities, in the order
--   parsed.
journalAmountAndPriceCommodities :: Journal -> [Commodity]

-- | Get this amount's commodity and any commodities referenced in its
--   price.
amountCommodities :: Amount -> [Commodity]

-- | Get all this journal's amounts, in the order parsed.
journalAmounts :: Journal -> [MixedAmount]

-- | The (fully specified) date span containing this journal's
--   transactions, or DateSpan Nothing Nothing if there are none.
journalDateSpan :: Journal -> DateSpan

-- | Check if a set of hledger account/description filter patterns matches
--   the given account name or entry description. Patterns are
--   case-insensitive regular expressions. Prefixed with not:, they become
--   anti-patterns.
matchpats :: [String] -> String -> Bool
negateprefix :: [Char]
isnegativepat :: [Char] -> Bool
abspat :: [Char] -> [Char]

-- | Calculate the account tree and all account balances from a journal's
--   postings, returning the results for efficient lookup.
journalAccountInfo :: Journal -> (Tree AccountName, Map AccountName Account)

-- | Given a list of postings, return an account name tree and three query
--   functions that fetch postings, subaccount-excluding-balance and
--   subaccount-including-balance by account name.
groupPostings :: [Posting] -> (Tree AccountName, AccountName -> [Posting], AccountName -> MixedAmount, AccountName -> MixedAmount)

-- | Add subaccount-excluding and subaccount-including balances to a tree
--   of account names somewhat efficiently, given a function that looks up
--   transactions by account name.
calculateBalances :: Tree AccountName -> (AccountName -> [Posting]) -> Tree (AccountName, (MixedAmount, MixedAmount))

-- | Convert a list of postings to a map from account name to that
--   account's postings.
postingsByAccount :: [Posting] -> Map AccountName [Posting]
traceAmountPrecision :: MixedAmount -> MixedAmount
tracePostingsCommodities :: [Posting] -> [Posting]
tests_Hledger_Data_Journal :: Test
instance Show Journal


-- | A <a>Ledger</a> is derived from a <a>Journal</a> by applying a filter
--   specification to select <a>Transaction</a>s and <a>Posting</a>s of
--   interest. It contains the filtered journal and knows the resulting
--   chart of accounts, account balances, and postings in each account.
module Hledger.Data.Ledger
nullledger :: Ledger

-- | Filter a journal's transactions as specified, and then process them to
--   derive a ledger containing all balances, the chart of accounts,
--   canonicalised commodities etc.
journalToLedger :: FilterSpec -> Journal -> Ledger

-- | Filter a journal's transactions as specified, and then process them to
--   derive a ledger containing all balances, the chart of accounts,
--   canonicalised commodities etc. Like journalToLedger but uses the new
--   matchers.
journalToLedger2 :: Matcher -> Journal -> Ledger

-- | List a ledger's account names.
ledgerAccountNames :: Ledger -> [AccountName]

-- | Get the named account from a ledger.
ledgerAccount :: Ledger -> AccountName -> Account

-- | List a ledger's accounts, in tree order
ledgerAccounts :: Ledger -> [Account]

-- | List a ledger's top-level accounts, in tree order
ledgerTopAccounts :: Ledger -> [Account]

-- | List a ledger's bottom-level (subaccount-less) accounts, in tree order
ledgerLeafAccounts :: Ledger -> [Account]

-- | Accounts in ledger whose name matches the pattern, in tree order.
ledgerAccountsMatching :: [String] -> Ledger -> [Account]

-- | List a ledger account's immediate subaccounts
ledgerSubAccounts :: Ledger -> Account -> [Account]

-- | List a ledger's postings, in the order parsed.
ledgerPostings :: Ledger -> [Posting]

-- | Get a ledger's tree of accounts to the specified depth.
ledgerAccountTree :: Int -> Ledger -> Tree Account

-- | Get a ledger's tree of accounts rooted at the specified account.
ledgerAccountTreeAt :: Ledger -> Account -> Maybe (Tree Account)

-- | The (fully specified) date span containing all the ledger's (filtered)
--   transactions, or DateSpan Nothing Nothing if there are none.
ledgerDateSpan :: Ledger -> DateSpan

-- | Convenience aliases.
accountnames :: Ledger -> [AccountName]
account :: Ledger -> AccountName -> Account
accounts :: Ledger -> [Account]
topaccounts :: Ledger -> [Account]
accountsmatching :: [String] -> Ledger -> [Account]
subaccounts :: Ledger -> Account -> [Account]
postings :: Ledger -> [Posting]
commodities :: Ledger -> Map String Commodity
accounttree :: Int -> Ledger -> Tree Account
accounttreeat :: Ledger -> Account -> Maybe (Tree Account)
rawdatespan :: Ledger -> DateSpan
ledgeramounts :: Ledger -> [MixedAmount]
tests_Hledger_Data_Ledger :: Test
instance Show Ledger


-- | Utilities common to hledger journal readers.
module Hledger.Read.Utils
juSequence :: [JournalUpdate] -> JournalUpdate

-- | Given a JournalUpdate-generating parsec parser, file path and data
--   string, parse and post-process a Journal so that it's ready to use, or
--   give an error.
parseJournalWith :: (GenParser Char JournalContext (JournalUpdate, JournalContext)) -> FilePath -> String -> ErrorT String IO Journal
setYear :: Integer -> GenParser tok JournalContext ()
getYear :: GenParser tok JournalContext (Maybe Integer)
setCommodity :: Commodity -> GenParser tok JournalContext ()
getCommodity :: GenParser tok JournalContext (Maybe Commodity)
pushParentAccount :: String -> GenParser tok JournalContext ()
popParentAccount :: GenParser tok JournalContext ()
getParentAccount :: GenParser tok JournalContext String
addAccountAlias :: (AccountName, AccountName) -> GenParser tok JournalContext ()
getAccountAliases :: GenParser tok JournalContext [(AccountName, AccountName)]
clearAccountAliases :: GenParser tok JournalContext ()

-- | Convert a possibly relative, possibly tilde-containing file path to an
--   absolute one. using the current directory from a parsec source
--   position. ~username is not supported.
expandPath :: MonadIO m => SourcePos -> FilePath -> m FilePath
fileSuffix :: FilePath -> String


-- | The Hledger.Data library allows parsing and querying of C++
--   ledger-style journal files. It generally provides a compatible subset
--   of C++ ledger's functionality. This package re-exports all the
--   Hledger.Data.* modules (except UTF8, which requires an explicit
--   import.)
module Hledger.Data
tests_Hledger_Data :: Test


-- | Generate several common kinds of report from a journal, as "*Report" -
--   simple intermediate data structures intended to be easily rendered as
--   text, html, json, csv etc. by hledger commands, hamlet templates,
--   javascript, or whatever. This is under Hledger.Cli since it depends on
--   the command-line options, should move to hledger-lib later.
module Hledger.Reports
data ReportOpts
ReportOpts :: Maybe Day -> Maybe Day -> Maybe (Interval, DateSpan) -> Bool -> Bool -> Bool -> Maybe Int -> Maybe DisplayExp -> Bool -> Bool -> Bool -> Bool -> Bool -> Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe FormatStr -> [String] -> ReportOpts
begin_ :: ReportOpts -> Maybe Day
end_ :: ReportOpts -> Maybe Day
period_ :: ReportOpts -> Maybe (Interval, DateSpan)
cleared_ :: ReportOpts -> Bool
uncleared_ :: ReportOpts -> Bool
cost_ :: ReportOpts -> Bool
depth_ :: ReportOpts -> Maybe Int
display_ :: ReportOpts -> Maybe DisplayExp
effective_ :: ReportOpts -> Bool
empty_ :: ReportOpts -> Bool
no_elide_ :: ReportOpts -> Bool
real_ :: ReportOpts -> Bool
flat_ :: ReportOpts -> Bool
drop_ :: ReportOpts -> Int
no_total_ :: ReportOpts -> Bool
daily_ :: ReportOpts -> Bool
weekly_ :: ReportOpts -> Bool
monthly_ :: ReportOpts -> Bool
quarterly_ :: ReportOpts -> Bool
yearly_ :: ReportOpts -> Bool
format_ :: ReportOpts -> Maybe FormatStr
patterns_ :: ReportOpts -> [String]
type DisplayExp = String
type FormatStr = String
defreportopts :: ReportOpts

-- | Figure out the date span we should report on, based on any
--   begin<i>end</i>period options provided. A period option will cause
--   begin and end options to be ignored.
dateSpanFromOpts :: Day -> ReportOpts -> DateSpan

-- | Figure out the reporting interval, if any, specified by the options.
--   --period overrides --daily overrides --weekly overrides --monthly etc.
intervalFromOpts :: ReportOpts -> Interval

-- | Get a maybe boolean representing the last cleared/uncleared option if
--   any.
clearedValueFromOpts :: ReportOpts -> Maybe Bool

-- | Report which date we will report on based on --effective.
whichDateFromOpts :: ReportOpts -> WhichDate

-- | Convert this journal's transactions' primary date to either the actual
--   or effective date, as per options.
journalSelectingDateFromOpts :: ReportOpts -> Journal -> Journal

-- | Convert this journal's postings' amounts to the cost basis amounts if
--   specified by options.
journalSelectingAmountFromOpts :: ReportOpts -> Journal -> Journal

-- | Convert application options to the library's generic filter
--   specification.
optsToFilterSpec :: ReportOpts -> Day -> FilterSpec

-- | A journal entries report is a list of whole transactions as originally
--   entered in the journal (mostly). Used by eg hledger's print command
--   and hledger-web's journal entries view.
type EntriesReport = [EntriesReportItem]
type EntriesReportItem = Transaction

-- | Select transactions for an entries report.
entriesReport :: ReportOpts -> FilterSpec -> Journal -> EntriesReport

-- | A postings report is a list of postings with a running total, a label
--   for the total field, and a little extra transaction info to help with
--   rendering.
type PostingsReport = (String, [PostingsReportItem])
type PostingsReportItem = (Maybe (Day, String), Posting, MixedAmount)

-- | Select postings from the journal and add running balance and other
--   information to make a postings report. Used by eg hledger's register
--   command.
postingsReport :: ReportOpts -> FilterSpec -> Journal -> PostingsReport

-- | Generate one postings report line item, from a flag indicating whether
--   to include transaction info, a posting, and the current running
--   balance.
mkpostingsReportItem :: Bool -> Posting -> MixedAmount -> PostingsReportItem

-- | A transactions report includes a list of transactions
--   (posting-filtered and unfiltered variants), a running balance, and
--   some other information helpful for rendering a register view (a flag
--   indicating multiple other accounts and a display string describing
--   them) with or without a notion of current account(s).
type TransactionsReport = (String, [TransactionsReportItem])
type TransactionsReportItem = (Transaction, Transaction, Bool, String, MixedAmount, MixedAmount)
triDate :: (Transaction, t, t1, t2, t3, t4) -> Day
triBalance :: (t, t1, t2, t3, t4, MixedAmount) -> [Char]

-- | Select transactions from the whole journal for a transactions report,
--   with no "current" account. The end result is similar to
--   <a>postingsReport</a> except it uses matchers and transaction-based
--   report items and the items are most recent first. Used by eg
--   hledger-web's journal view.
journalTransactionsReport :: ReportOpts -> Journal -> Matcher -> TransactionsReport

-- | Select transactions within one or more "current" accounts, and make a
--   transactions report relative to those account(s). This means:
--   
--   <ol>
--   <li>it shows transactions from the point of view of the current
--   account(s). The transaction amount is the amount posted to the current
--   account(s). The other accounts' names are provided.</li>
--   <li>With no transaction filtering in effect other than a start date,
--   it shows the accurate historical running balance for the current
--   account(s). Otherwise it shows a running total starting at 0.</li>
--   </ol>
--   
--   Currently, reporting intervals are not supported, and report items are
--   most recent first. Used by eg hledger-web's account register view.
accountTransactionsReport :: ReportOpts -> Journal -> Matcher -> Matcher -> TransactionsReport

-- | An accounts report is a list of account names (full and short
--   variants) with their balances, appropriate indentation for rendering
--   as a hierarchy, and grand total.
type AccountsReport = ([AccountsReportItem], MixedAmount)
type AccountsReportItem = (AccountName, AccountName, Int, MixedAmount)

-- | Select accounts, and get their balances at the end of the selected
--   period, and misc. display information, for an accounts report. Used by
--   eg hledger's balance command.
accountsReport :: ReportOpts -> FilterSpec -> Journal -> AccountsReport

-- | Select accounts, and get their balances at the end of the selected
--   period, and misc. display information, for an accounts report. Like
--   <a>accountsReport</a> but uses the new matchers. Used by eg
--   hledger-web's accounts sidebar.
accountsReport2 :: ReportOpts -> Matcher -> Journal -> AccountsReport

-- | Is the named account considered interesting for this ledger's accounts
--   report, following the eliding style of ledger's balance command ?
isInteresting :: ReportOpts -> Ledger -> AccountName -> Bool
tests_Hledger_Reports :: Test
instance Show ReportOpts
instance Default ReportOpts


-- | A reader for hledger's (and c++ ledger's) journal file format.
--   
--   From the ledger 2.5 manual:
--   
--   <pre>
--   The ledger file format is quite simple, but also very flexible. It supports
--   many options, though typically the user can ignore most of them. They are
--   summarized below.  The initial character of each line determines what the
--   line means, and how it should be interpreted. Allowable initial characters
--   are:
--   
--   NUMBER      A line beginning with a number denotes an entry. It may be followed by any
--               number of lines, each beginning with whitespace, to denote the entry’s account
--               transactions. The format of the first line is:
--   
--   DATE[=EDATE] [*|!] [(CODE)] DESC
--   
--   If ‘*’ appears after the date (with optional eﬀective date), it indicates the entry
--               is “cleared”, which can mean whatever the user wants it t omean. If ‘!’ appears
--               after the date, it indicates d the entry is “pending”; i.e., tentatively cleared from
--               the user’s point of view, but not yet actually cleared. If a ‘CODE’ appears in
--               parentheses, it may be used to indicate a check number, or the type of the
--               transaction. Following these is the payee, or a description of the transaction.
--               The format of each following transaction is:
--   
--   ACCOUNT     AMOUNT    [; NOTE]
--   
--   The ‘ACCOUNT’ may be surrounded by parentheses if it is a virtual
--               transactions, or square brackets if it is a virtual transactions that must
--               balance. The ‘AMOUNT’ can be followed by a per-unit transaction cost,
--               by specifying ‘ AMOUNT’, or a complete transaction cost with ‘@ AMOUNT’.
--               Lastly, the ‘NOTE’ may specify an actual and/or eﬀective date for the
--               transaction by using the syntax ‘[ACTUAL_DATE]’ or ‘[=EFFECTIVE_DATE]’ or
--               ‘[ACTUAL_DATE=EFFECtIVE_DATE]’.
--   
--   =           An automated entry. A value expression must appear after the equal sign.
--               After this initial line there should be a set of one or more transactions, just as
--               if it were normal entry. If the amounts of the transactions have no commodity,
--               they will be applied as modifiers to whichever real transaction is matched by
--               the value expression.
--   
--   ~           A period entry. A period expression must appear after the tilde.
--               After this initial line there should be a set of one or more transactions, just as
--               if it were normal entry.
--   
--   !           A line beginning with an exclamation mark denotes a command directive. It
--               must be immediately followed by the command word. The supported commands
--               are:
--   
--   ‘!include’
--                           Include the stated ledger file.
--              ‘!account’
--                           The account name is given is taken to be the parent of all transac-
--                           tions that follow, until ‘!end’ is seen.
--              ‘!end’       Ends an account block.
--   
--   ;          A line beginning with a colon indicates a comment, and is ignored.
--   
--   Y          If a line begins with a capital Y, it denotes the year used for all subsequent
--              entries that give a date without a year. The year should appear immediately
--              after the Y, for example: ‘Y2004’. This is useful at the beginning of a file, to
--              specify the year for that file. If all entries specify a year, however, this command
--              has no eﬀect.
--   
--   P          Specifies a historical price for a commodity. These are usually found in a pricing
--              history file (see the ‘-Q’ option). The syntax is:
--   
--   P DATE SYMBOL PRICE
--   
--   N SYMBOL   Indicates that pricing information is to be ignored for a given symbol, nor will
--              quotes ever be downloaded for that symbol. Useful with a home currency, such
--              as the dollar ($). It is recommended that these pricing options be set in the price
--              database file, which defaults to ‘~/.pricedb’. The syntax for this command is:
--   
--   N SYMBOL
--   
--   D AMOUNT   Specifies the default commodity to use, by specifying an amount in the expected
--              format. The entry command will use this commodity as the default when none
--              other can be determined. This command may be used multiple times, to set
--              the default flags for diﬀerent commodities; whichever is seen last is used as the
--              default commodity. For example, to set US dollars as the default commodity,
--              while also setting the thousands flag and decimal flag for that commodity, use:
--   
--   D $1,000.00
--   
--   C AMOUNT1 = AMOUNT2
--              Specifies a commodity conversion, where the first amount is given to be equiv-
--              alent to the second amount. The first amount should use the decimal precision
--              desired during reporting:
--   
--   C 1.00 Kb = 1024 bytes
--   
--   i, o, b, h
--              These four relate to timeclock support, which permits ledger to read timelog
--              files. See the timeclock’s documentation for more info on the syntax of its
--              timelog files.
--   </pre>
module Hledger.Read.JournalReader
emptyLine :: GenParser Char JournalContext ()
journalAddFile :: (FilePath, String) -> Journal -> Journal

-- | Top-level journal parser. Returns a single composite, I/O performing,
--   error-raising <a>JournalUpdate</a> (and final <a>JournalContext</a>)
--   which can be applied to an empty journal to get the final result.
journalFile :: GenParser Char JournalContext (JournalUpdate, JournalContext)

-- | Parse an account name. Account names may have single spaces inside
--   them, and are terminated by two or more spaces. They should have one
--   or more components of at least one character, separated by the account
--   separator char.
ledgeraccountname :: GenParser Char st AccountName

-- | Parse a date and time in YYYY<i>MM</i>DD HH:MM[:SS][+-ZZZZ] format.
--   Any timezone will be ignored; the time is treated as local time. Fewer
--   digits are allowed, except in the timezone. The year may be omitted if
--   a default year has already been set.
ledgerdatetime :: GenParser Char JournalContext LocalTime
ledgerDefaultYear :: GenParser Char JournalContext JournalUpdate
ledgerDirective :: GenParser Char JournalContext JournalUpdate
ledgerHistoricalPrice :: GenParser Char JournalContext HistoricalPrice
reader :: Reader
someamount :: GenParser Char JournalContext MixedAmount
tests_Hledger_Read_JournalReader :: Test


-- | A reader for the timelog file format generated by timeclock.el.
--   
--   From timeclock.el 2.6:
--   
--   <pre>
--   A timelog contains data in the form of a single entry per line.
--   Each entry has the form:
--   
--   CODE YYYY<i>MM</i>DD HH:MM:SS [COMMENT]
--   
--   CODE is one of: b, h, i, o or O.  COMMENT is optional when the code is
--   i, o or O.  The meanings of the codes are:
--   
--   b  Set the current time balance, or "time debt".  Useful when
--        archiving old log data, when a debt must be carried forward.
--        The COMMENT here is the number of seconds of debt.
--   
--   h  Set the required working time for the given day.  This must
--        be the first entry for that day.  The COMMENT in this case is
--        the number of hours in this workday.  Floating point amounts
--        are allowed.
--   
--   i  Clock in.  The COMMENT in this case should be the name of the
--        project worked on.
--   
--   o  Clock out.  COMMENT is unnecessary, but can be used to provide
--        a description of how the period went, for example.
--   
--   O  Final clock out.  Whatever project was being worked on, it is
--        now finished.  Useful for creating summary reports.
--   </pre>
--   
--   Example:
--   
--   <pre>
--   i 2007<i>03</i>10 12:26:00 hledger
--   o 2007<i>03</i>10 17:26:02
--   </pre>
module Hledger.Read.TimelogReader
reader :: Reader
tests_Hledger_Read_TimelogReader :: Test


-- | Read hledger data from various data formats, and related utilities.
module Hledger.Read
tests_Hledger_Read :: Test

-- | Read a journal from this file, using the specified data format or
--   trying all known formats, or give an error string; also create the
--   file if it doesn't exist.
readJournalFile :: Maybe String -> FilePath -> IO (Either String Journal)

-- | Read a Journal from this string, using the specified data format or
--   trying all known formats, or give an error string.
readJournal :: Maybe String -> String -> IO (Either String Journal)

-- | Read a Journal from this string (and file path), auto-detecting the
--   data format, or give a useful error string. Tries to parse each known
--   data format in turn. If none succeed, gives the error message specific
--   to the intended data format, which if not specified is guessed from
--   the file suffix and possibly the data.
journalFromPathAndString :: Maybe String -> FilePath -> String -> IO (Either String Journal)

-- | Parse an account name. Account names may have single spaces inside
--   them, and are terminated by two or more spaces. They should have one
--   or more components of at least one character, separated by the account
--   separator char.
ledgeraccountname :: GenParser Char st AccountName

-- | Get the user's journal file path. Like ledger, we look first for the
--   LEDGER_FILE environment variable, and if that does not exist, for the
--   legacy LEDGER environment variable. If neither is set, or the value is
--   blank, return the default journal file path, which is
--   <a>.hledger.journal</a> in the users's home directory, or if we cannot
--   determine that, in the current directory.
myJournalPath :: IO String

-- | Read the user's default journal file, or give an error.
myJournal :: IO Journal
someamount :: GenParser Char JournalContext MixedAmount
journalenvvar :: [Char]
journaldefaultfilename :: [Char]

-- | If the specified journal file does not exist, give a helpful error and
--   quit.
requireJournalFile :: FilePath -> IO ()

-- | Ensure there is a journal file at the given path, creating an empty
--   one if needed.
ensureJournalFile :: FilePath -> IO ()

module Hledger
