hledger-lib 1.17.1 → 1.18
raw patch · 38 files changed
+1581/−1163 lines, 38 filesdep +aeson-prettydep ~aesondep ~doctestPVP ok
version bump matches the API change (PVP)
Dependencies added: aeson-pretty
Dependency ranges changed: aeson, doctest
API changes (from Hackage documentation)
- Hledger.Data.Amount: amountToCost :: Map CommoditySymbol AmountStyle -> Amount -> Amount
- Hledger.Data.Amount: costOfAmount :: Amount -> Amount
- Hledger.Data.Amount: costOfMixedAmount :: MixedAmount -> MixedAmount
- Hledger.Data.Amount: isReallyZeroAmount :: Amount -> Bool
- Hledger.Data.Amount: isReallyZeroMixedAmount :: MixedAmount -> Bool
- Hledger.Data.Amount: isReallyZeroMixedAmountCost :: MixedAmount -> Bool
- Hledger.Data.Amount: isZeroAmount :: Amount -> Bool
- Hledger.Data.Amount: isZeroMixedAmount :: MixedAmount -> Bool
- Hledger.Data.Amount: mixedAmountToCost :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
- Hledger.Data.Transaction: transactionPostingBalances :: Transaction -> (MixedAmount, MixedAmount, MixedAmount)
- Hledger.Read.Common: finaliseJournal :: InputOpts -> FilePath -> Text -> Journal -> ExceptT String IO Journal
- Hledger.Read.Common: fixedlotpricep :: JournalParser m (Maybe Amount)
+ Hledger.Data.Amount: amountCost :: Amount -> Amount
+ Hledger.Data.Amount: amountIsZero :: Amount -> Bool
+ Hledger.Data.Amount: amountLooksZero :: Amount -> Bool
+ Hledger.Data.Amount: mixedAmountCost :: MixedAmount -> MixedAmount
+ Hledger.Data.Amount: mixedAmountIsZero :: MixedAmount -> Bool
+ Hledger.Data.Amount: mixedAmountLooksZero :: MixedAmount -> Bool
+ Hledger.Data.Journal: journalInferMarketPricesFromTransactions :: Journal -> Journal
+ Hledger.Data.Json: toJsonText :: ToJSON a => a -> Text
+ Hledger.Data.Types: [jtransactionimpliedmarketprices] :: Journal -> [MarketPrice]
+ Hledger.Query: prefixes :: [Text]
+ Hledger.Read.Common: journalFinalise :: InputOpts -> FilePath -> Text -> Journal -> ExceptT String IO Journal
+ Hledger.Read.Common: lotpricep :: JournalParser m ()
+ Hledger.Reports.ReportOptions: forecastPeriodFromRawOpts :: Day -> RawOpts -> Maybe DateSpan
- Hledger.Data.Types: Journal :: Maybe Year -> Maybe (CommoditySymbol, AmountStyle) -> [AccountName] -> [AccountAlias] -> [TimeclockEntry] -> [FilePath] -> [(AccountName, AccountDeclarationInfo)] -> Map AccountType [AccountName] -> Map CommoditySymbol Commodity -> Map CommoditySymbol AmountStyle -> [PriceDirective] -> [TransactionModifier] -> [PeriodicTransaction] -> [Transaction] -> Text -> [(FilePath, Text)] -> ClockTime -> Journal
+ Hledger.Data.Types: Journal :: Maybe Year -> Maybe (CommoditySymbol, AmountStyle) -> [AccountName] -> [AccountAlias] -> [TimeclockEntry] -> [FilePath] -> [(AccountName, AccountDeclarationInfo)] -> Map AccountType [AccountName] -> Map CommoditySymbol Commodity -> Map CommoditySymbol AmountStyle -> [PriceDirective] -> [MarketPrice] -> [TransactionModifier] -> [PeriodicTransaction] -> [Transaction] -> Text -> [(FilePath, Text)] -> ClockTime -> Journal
- Hledger.Read.Common: priceamountp :: JournalParser m (Maybe AmountPrice)
+ Hledger.Read.Common: priceamountp :: JournalParser m AmountPrice
- Hledger.Reports.MultiBalanceReport: multiBalanceReport :: ReportOpts -> Query -> Journal -> MultiBalanceReport
+ Hledger.Reports.MultiBalanceReport: multiBalanceReport :: Day -> ReportOpts -> Journal -> MultiBalanceReport
- Hledger.Reports.ReportOptions: ReportOpts :: Maybe Day -> Period -> Interval -> [Status] -> Maybe ValuationType -> Maybe Int -> Maybe DisplayExp -> Bool -> Bool -> Bool -> Bool -> Maybe FormatStr -> String -> Bool -> Bool -> BalanceType -> AccountListMode -> Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe NormalSign -> Bool -> Bool -> Bool -> ReportOpts
+ Hledger.Reports.ReportOptions: ReportOpts :: Maybe Day -> Period -> Interval -> [Status] -> Maybe ValuationType -> Maybe Int -> Maybe DisplayExp -> Bool -> Bool -> Bool -> Bool -> Maybe FormatStr -> String -> Bool -> Bool -> BalanceType -> AccountListMode -> Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Maybe NormalSign -> Bool -> Maybe DateSpan -> Bool -> ReportOpts
- Hledger.Reports.ReportOptions: [forecast_] :: ReportOpts -> Bool
+ Hledger.Reports.ReportOptions: [forecast_] :: ReportOpts -> Maybe DateSpan
Files
- CHANGES.md +29/−1
- Hledger/Data/Amount.hs +58/−63
- Hledger/Data/Dates.hs +44/−42
- Hledger/Data/Journal.hs +30/−1
- Hledger/Data/Json.hs +43/−10
- Hledger/Data/Period.hs +8/−8
- Hledger/Data/Posting.hs +2/−2
- Hledger/Data/Transaction.hs +69/−40
- Hledger/Data/Types.hs +2/−2
- Hledger/Data/Valuation.hs +84/−57
- Hledger/Query.hs +3/−2
- Hledger/Read.hs +1/−1
- Hledger/Read/Common.hs +84/−48
- Hledger/Read/CsvReader.hs +58/−28
- Hledger/Read/JournalReader.hs +30/−16
- Hledger/Read/TimeclockReader.hs +1/−1
- Hledger/Read/TimedotReader.hs +1/−1
- Hledger/Reports/BalanceReport.hs +7/−7
- Hledger/Reports/BudgetReport.hs +4/−5
- Hledger/Reports/MultiBalanceReport.hs +10/−8
- Hledger/Reports/PostingsReport.hs +1/−1
- Hledger/Reports/ReportOptions.hs +15/−2
- Hledger/Utils/Regex.hs +12/−11
- README +0/−3
- README.md +9/−0
- hledger-lib.cabal +21/−16
- hledger_csv.5 +45/−18
- hledger_csv.info +104/−87
- hledger_csv.txt +137/−119
- hledger_journal.5 +99/−58
- hledger_journal.info +268/−232
- hledger_journal.txt +294/−265
- hledger_timeclock.5 +1/−1
- hledger_timeclock.info +2/−2
- hledger_timeclock.txt +1/−1
- hledger_timedot.5 +1/−1
- hledger_timedot.info +2/−2
- hledger_timedot.txt +1/−1
CHANGES.md view
@@ -1,12 +1,40 @@ Internal/api/developer-ish changes in the hledger-lib (and hledger) packages. For user-visible changes, see the hledger package changelog. +# 1.18 2020-06-07++- added: getHledgerCliOpts', takes an explicit argument list++- added: toJsonText++- changed: isNegativeMixedAmount now gives an answer for+ multi-commodity amounts which are all negative++- changed: multiBalanceReport now gets the query from ReportOpts (Dmitry Astapov)++- renamed:+ isZeroAmount -> amountLooksZero+ isReallyZeroAmount -> amountIsZero+ isZeroMixedAmount -> mixedAmountLooksZero+ isReallyZeroMixedAmount -> mixedAmountIsZero+ isReallyZeroMixedAmountCost dropped++- renamed: finaliseJournal -> journalFinalise++- renamed: fixedlotpricep -> lotpricep, now also parses non-fixed lot prices++- dropped: transactionPostingBalances++- dropped: outputflags no longer exported by Hledger.Cli.CliOptions++- fixed: documentation for journalExpenseAccountQuery (Pavan Rikhi)+ # 1.17.1 2020-03-19 - require newer Decimal, math-functions libs to ensure consistent rounding behaviour, even when built with old GHCs/snapshots. hledger uses banker's rounding (rounds to nearest even number, eg- 0.5 with with zero decimal places is "0").+ 0.5 displayed with zero decimal places is "0"). - added: debug helpers traceAt, traceAtWith
Hledger/Data/Amount.hs view
@@ -61,8 +61,9 @@ (@@), amountWithCommodity, -- ** arithmetic- costOfAmount,- amountToCost,+ amountCost,+ amountIsZero,+ amountLooksZero, divideAmount, multiplyAmount, divideAmountAndPrice,@@ -101,8 +102,7 @@ normaliseMixedAmount, mixedAmountStripPrices, -- ** arithmetic- costOfMixedAmount,- mixedAmountToCost,+ mixedAmountCost, divideMixedAmount, multiplyMixedAmount, divideMixedAmountAndPrice,@@ -110,11 +110,8 @@ averageMixedAmounts, isNegativeAmount, isNegativeMixedAmount,- isZeroAmount,- isReallyZeroAmount,- isZeroMixedAmount,- isReallyZeroMixedAmount,- isReallyZeroMixedAmountCost,+ mixedAmountIsZero,+ mixedAmountLooksZero, mixedAmountTotalPriceToUnitPrice, -- ** rendering styleMixedAmount,@@ -212,22 +209,21 @@ amountWithCommodity :: CommoditySymbol -> Amount -> Amount amountWithCommodity c a = a{acommodity=c, aprice=Nothing} --- | Convert an amount to the commodity of its assigned price, if any. Notes:+-- | Convert a amount to its "cost" or "selling price" in another commodity,+-- using its attached transaction price if it has one. Notes: ----- - price amounts must be MixedAmounts with exactly one component Amount (or there will be a runtime error) XXX+-- - price amounts must be MixedAmounts with exactly one component Amount+-- (or there will be a runtime error XXX) ----- - price amounts should be positive, though this is not currently enforced-costOfAmount :: Amount -> Amount-costOfAmount a@Amount{aquantity=q, aprice=mp} =+-- - price amounts should be positive+-- (though this is currently not enforced)+amountCost :: Amount -> Amount+amountCost a@Amount{aquantity=q, aprice=mp} = case mp of Nothing -> a Just (UnitPrice p@Amount{aquantity=pq}) -> p{aquantity=pq * q} Just (TotalPrice p@Amount{aquantity=pq}) -> p{aquantity=pq * signum q} --- | Convert this amount to cost, and apply the appropriate amount style.-amountToCost :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount-amountToCost styles = styleAmount styles . costOfAmount- -- | Replace an amount's TotalPrice, if it has one, with an equivalent UnitPrice. -- Has no effect on amounts without one. -- Also increases the unit price's display precision to show one extra decimal place,@@ -269,14 +265,14 @@ digits = "123456789" :: String --- | Does this amount appear to be zero when displayed with its given precision ?-isZeroAmount :: Amount -> Bool-isZeroAmount -- a==missingamt = False- = not . any (`elem` digits) . showAmountWithoutPriceOrCommodity+-- | Does mixed amount appear to be zero when rendered with its+-- display precision ?+amountLooksZero :: Amount -> Bool+amountLooksZero = not . any (`elem` digits) . showAmountWithoutPriceOrCommodity --- | Is this amount "really" zero, regardless of the display precision ?-isReallyZeroAmount :: Amount -> Bool-isReallyZeroAmount Amount{aquantity=q} = q == 0+-- | Is this amount exactly zero, ignoring its display precision ?+amountIsZero :: Amount -> Bool+amountIsZero Amount{aquantity=q} = q == 0 -- | Get the string representation of an amount, based on its commodity's -- display settings except using the specified precision.@@ -371,8 +367,9 @@ showAmountPriceDebug (Just (UnitPrice pa)) = " @ " ++ showAmountDebug pa showAmountPriceDebug (Just (TotalPrice pa)) = " @@ " ++ showAmountDebug pa --- | Given a map of standard amount display styles, apply the appropriate one to this amount.--- If there's no standard style for this amount's commodity, return the amount unchanged.+-- | Given a map of standard commodity display styles, apply the+-- appropriate one to this amount. If there's no standard style for+-- this amount's commodity, return the amount unchanged. styleAmount :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount styleAmount styles a = case M.lookup (acommodity a) styles of@@ -520,7 +517,7 @@ newzero = case filter (/= "") (map acommodity zeros) of _:_ -> last zeros _ -> nullamt- (zeros, nonzeros) = partition isReallyZeroAmount $+ (zeros, nonzeros) = partition amountIsZero $ map sumSimilarAmountsUsingFirstPrice $ groupBy groupfn $ sortBy sortfn@@ -577,14 +574,10 @@ mapMixedAmount :: (Amount -> Amount) -> MixedAmount -> MixedAmount mapMixedAmount f (Mixed as) = Mixed $ map f as --- | Convert a mixed amount's component amounts to the commodity of their--- assigned price, if any.-costOfMixedAmount :: MixedAmount -> MixedAmount-costOfMixedAmount (Mixed as) = Mixed $ map costOfAmount as---- | Convert all component amounts to cost, and apply the appropriate amount styles.-mixedAmountToCost :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount-mixedAmountToCost styles (Mixed as) = Mixed $ map (amountToCost styles) as+-- | Convert all component amounts to cost/selling price where+-- possible (see amountCost).+mixedAmountCost :: MixedAmount -> MixedAmount+mixedAmountCost (Mixed as) = Mixed $ map amountCost as -- | Divide a mixed amount's quantities by a constant. divideMixedAmount :: Quantity -> MixedAmount -> MixedAmount@@ -609,34 +602,36 @@ averageMixedAmounts [] = 0 averageMixedAmounts as = fromIntegral (length as) `divideMixedAmount` sum as --- | Is this mixed amount negative, if it can be normalised to a single commodity ?+-- | Is this mixed amount negative, if we can tell that unambiguously?+-- Ie when normalised, are all individual commodity amounts negative ? isNegativeMixedAmount :: MixedAmount -> Maybe Bool-isNegativeMixedAmount m = case as of [a] -> Just $ isNegativeAmount a- _ -> Nothing- where as = amounts $ normaliseMixedAmountSquashPricesForDisplay m---- | Does this mixed amount appear to be zero when displayed with its given precision ?-isZeroMixedAmount :: MixedAmount -> Bool-isZeroMixedAmount = all isZeroAmount . amounts . normaliseMixedAmountSquashPricesForDisplay+isNegativeMixedAmount m =+ case amounts $ normaliseMixedAmountSquashPricesForDisplay m of+ [] -> Just False+ [a] -> Just $ isNegativeAmount a+ as | all isNegativeAmount as -> Just True+ as | not (any isNegativeAmount as) -> Just False+ _ -> Nothing -- multiple amounts with different signs --- | Is this mixed amount "really" zero ? See isReallyZeroAmount.-isReallyZeroMixedAmount :: MixedAmount -> Bool-isReallyZeroMixedAmount = all isReallyZeroAmount . amounts . normaliseMixedAmountSquashPricesForDisplay+-- | Does this mixed amount appear to be zero when rendered with its+-- display precision ?+mixedAmountLooksZero :: MixedAmount -> Bool+mixedAmountLooksZero = all amountLooksZero . amounts . normaliseMixedAmountSquashPricesForDisplay --- | Is this mixed amount "really" zero, after converting to cost--- commodities where possible ?-isReallyZeroMixedAmountCost :: MixedAmount -> Bool-isReallyZeroMixedAmountCost = isReallyZeroMixedAmount . costOfMixedAmount+-- | Is this mixed amount exactly zero, ignoring display precisions ?+mixedAmountIsZero :: MixedAmount -> Bool+mixedAmountIsZero = all amountIsZero . amounts . normaliseMixedAmountSquashPricesForDisplay -- -- | MixedAmount derived Eq instance in Types.hs doesn't know that we -- -- want $0 = EUR0 = 0. Yet we don't want to drag all this code over there. -- -- For now, use this when cross-commodity zero equality is important. -- mixedAmountEquals :: MixedAmount -> MixedAmount -> Bool--- mixedAmountEquals a b = amounts a' == amounts b' || (isZeroMixedAmount a' && isZeroMixedAmount b')+-- mixedAmountEquals a b = amounts a' == amounts b' || (mixedAmountLooksZero a' && mixedAmountLooksZero b') -- where a' = normaliseMixedAmountSquashPricesForDisplay a -- b' = normaliseMixedAmountSquashPricesForDisplay b --- | Given a map of standard amount display styles, apply the appropriate ones to each individual amount.+-- | Given a map of standard commodity display styles, apply the+-- appropriate one to each individual amount. styleMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount styleMixedAmount styles (Mixed as) = Mixed $ map (styleAmount styles) as @@ -743,15 +738,15 @@ tests_Amount = tests "Amount" [ tests "Amount" [ - test "costOfAmount" $ do- costOfAmount (eur 1) @?= eur 1- costOfAmount (eur 2){aprice=Just $ UnitPrice $ usd 2} @?= usd 4- costOfAmount (eur 1){aprice=Just $ TotalPrice $ usd 2} @?= usd 2- costOfAmount (eur (-1)){aprice=Just $ TotalPrice $ usd 2} @?= usd (-2)+ test "amountCost" $ do+ amountCost (eur 1) @?= eur 1+ amountCost (eur 2){aprice=Just $ UnitPrice $ usd 2} @?= usd 4+ amountCost (eur 1){aprice=Just $ TotalPrice $ usd 2} @?= usd 2+ amountCost (eur (-1)){aprice=Just $ TotalPrice $ usd 2} @?= usd (-2) - ,test "isZeroAmount" $ do- assertBool "" $ isZeroAmount amount- assertBool "" $ isZeroAmount $ usd 0+ ,test "amountLooksZero" $ do+ assertBool "" $ amountLooksZero amount+ assertBool "" $ amountLooksZero $ usd 0 ,test "negating amounts" $ do negate (usd 1) @?= (usd 1){aquantity= -1}@@ -766,7 +761,7 @@ asprecision (astyle $ sum [usd 1 `withPrecision` 1, usd 1 `withPrecision` 3]) @?= 3 asprecision (astyle $ sum [usd 1 `withPrecision` 3, usd 1 `withPrecision` 1]) @?= 3 -- adding different commodities assumes conversion rate 1- assertBool "" $ isZeroAmount (usd 1.23 - eur 1.23)+ assertBool "" $ amountLooksZero (usd 1.23 - eur 1.23) ,test "showAmount" $ do showAmount (usd 0 + gbp 0) @?= "0"@@ -819,7 +814,7 @@ ,test "normaliseMixedAmountSquashPricesForDisplay" $ do normaliseMixedAmountSquashPricesForDisplay (Mixed []) @?= Mixed [nullamt]- assertBool "" $ isZeroMixedAmount $ normaliseMixedAmountSquashPricesForDisplay+ assertBool "" $ mixedAmountLooksZero $ normaliseMixedAmountSquashPricesForDisplay (Mixed [usd 10 ,usd 10 @@ eur 7 ,usd (-10)
Hledger/Data/Dates.hs view
@@ -167,31 +167,31 @@ -- >>> t NoInterval "2008/01/01" "2009/01/01" -- [DateSpan 2008] -- >>> t (Quarters 1) "2008/01/01" "2009/01/01"--- [DateSpan 2008q1,DateSpan 2008q2,DateSpan 2008q3,DateSpan 2008q4]+-- [DateSpan 2008Q1,DateSpan 2008Q2,DateSpan 2008Q3,DateSpan 2008Q4] -- >>> splitSpan (Quarters 1) nulldatespan--- [DateSpan -]+-- [DateSpan ..] -- >>> t (Days 1) "2008/01/01" "2008/01/01" -- an empty datespan -- [] -- >>> t (Quarters 1) "2008/01/01" "2008/01/01" -- [] -- >>> t (Months 1) "2008/01/01" "2008/04/01"--- [DateSpan 2008/01,DateSpan 2008/02,DateSpan 2008/03]+-- [DateSpan 2008-01,DateSpan 2008-02,DateSpan 2008-03] -- >>> t (Months 2) "2008/01/01" "2008/04/01"--- [DateSpan 2008-01-01-2008-02-29,DateSpan 2008-03-01-2008-04-30]+-- [DateSpan 2008-01-01..2008-02-29,DateSpan 2008-03-01..2008-04-30] -- >>> t (Weeks 1) "2008/01/01" "2008/01/15"--- [DateSpan 2007-12-31w01,DateSpan 2008-01-07w02,DateSpan 2008-01-14w03]+-- [DateSpan 2007-12-31W01,DateSpan 2008-01-07W02,DateSpan 2008-01-14W03] -- >>> t (Weeks 2) "2008/01/01" "2008/01/15"--- [DateSpan 2007-12-31-2008-01-13,DateSpan 2008-01-14-2008-01-27]+-- [DateSpan 2007-12-31..2008-01-13,DateSpan 2008-01-14..2008-01-27] -- >>> t (DayOfMonth 2) "2008/01/01" "2008/04/01"--- [DateSpan 2007-12-02-2008-01-01,DateSpan 2008-01-02-2008-02-01,DateSpan 2008-02-02-2008-03-01,DateSpan 2008-03-02-2008-04-01]+-- [DateSpan 2007-12-02..2008-01-01,DateSpan 2008-01-02..2008-02-01,DateSpan 2008-02-02..2008-03-01,DateSpan 2008-03-02..2008-04-01] -- >>> t (WeekdayOfMonth 2 4) "2011/01/01" "2011/02/15"--- [DateSpan 2010-12-09-2011-01-12,DateSpan 2011-01-13-2011-02-09,DateSpan 2011-02-10-2011-03-09]+-- [DateSpan 2010-12-09..2011-01-12,DateSpan 2011-01-13..2011-02-09,DateSpan 2011-02-10..2011-03-09] -- >>> t (DayOfWeek 2) "2011/01/01" "2011/01/15"--- [DateSpan 2010-12-28-2011-01-03,DateSpan 2011-01-04-2011-01-10,DateSpan 2011-01-11-2011-01-17]+-- [DateSpan 2010-12-28..2011-01-03,DateSpan 2011-01-04..2011-01-10,DateSpan 2011-01-11..2011-01-17] -- >>> t (DayOfYear 11 29) "2011/10/01" "2011/10/15"--- [DateSpan 2010-11-29-2011-11-28]+-- [DateSpan 2010-11-29..2011-11-28] -- >>> t (DayOfYear 11 29) "2011/12/01" "2012/12/15"--- [DateSpan 2011-11-29-2012-11-28,DateSpan 2012-11-29-2013-11-28]+-- [DateSpan 2011-11-29..2012-11-28,DateSpan 2012-11-29..2013-11-28] -- splitSpan :: Interval -> DateSpan -> [DateSpan] splitSpan _ (DateSpan Nothing Nothing) = [DateSpan Nothing Nothing]@@ -259,7 +259,7 @@ -- -- For non-intersecting spans, gives an empty span beginning on the second's start date: -- >>> mkdatespan "2018-01-01" "2018-01-03" `spanIntersect` mkdatespan "2018-01-03" "2018-01-05"--- DateSpan 2018-01-03-2018-01-02+-- DateSpan 2018-01-03..2018-01-02 spanIntersect (DateSpan b1 e1) (DateSpan b2 e2) = DateSpan b e where b = latest b1 b2@@ -912,49 +912,51 @@ -- resolving any relative start/end dates (only; it is not needed for -- parsing the reporting interval). ----- >>> let p = parsePeriodExpr (parsedate "2008/11/26")+-- >>> let p = parsePeriodExpr (parsedate "2008-11-26") -- >>> p "from Aug to Oct"--- Right (NoInterval,DateSpan 2008-08-01-2008-09-30)+-- Right (NoInterval,DateSpan 2008-08-01..2008-09-30) -- >>> p "aug to oct"--- Right (NoInterval,DateSpan 2008-08-01-2008-09-30)+-- Right (NoInterval,DateSpan 2008-08-01..2008-09-30) -- >>> p "every 3 days in Aug"--- Right (Days 3,DateSpan 2008/08)+-- Right (Days 3,DateSpan 2008-08) -- >>> p "daily from aug"--- Right (Days 1,DateSpan 2008-08-01-)+-- Right (Days 1,DateSpan 2008-08-01..) -- >>> p "every week to 2009"--- Right (Weeks 1,DateSpan -2008-12-31)+-- Right (Weeks 1,DateSpan ..2008-12-31) -- >>> p "every 2nd day of month"--- Right (DayOfMonth 2,DateSpan -)+-- Right (DayOfMonth 2,DateSpan ..) -- >>> p "every 2nd day"--- Right (DayOfMonth 2,DateSpan -)+-- Right (DayOfMonth 2,DateSpan ..)+-- >>> p "every 2nd day 2009.."+-- Right (DayOfMonth 2,DateSpan 2009-01-01..) -- >>> p "every 2nd day 2009-"--- Right (DayOfMonth 2,DateSpan 2009-01-01-)+-- Right (DayOfMonth 2,DateSpan 2009-01-01..) -- >>> p "every 29th Nov"--- Right (DayOfYear 11 29,DateSpan -)--- >>> p "every 29th nov -2009"--- Right (DayOfYear 11 29,DateSpan -2008-12-31)+-- Right (DayOfYear 11 29,DateSpan ..)+-- >>> p "every 29th nov ..2009"+-- Right (DayOfYear 11 29,DateSpan ..2008-12-31) -- >>> p "every nov 29th"--- Right (DayOfYear 11 29,DateSpan -)--- >>> p "every Nov 29th 2009-"--- Right (DayOfYear 11 29,DateSpan 2009-01-01-)+-- Right (DayOfYear 11 29,DateSpan ..)+-- >>> p "every Nov 29th 2009.."+-- Right (DayOfYear 11 29,DateSpan 2009-01-01..) -- >>> p "every 11/29 from 2009"--- Right (DayOfYear 11 29,DateSpan 2009-01-01-)+-- Right (DayOfYear 11 29,DateSpan 2009-01-01..) -- >>> p "every 2nd Thursday of month to 2009"--- Right (WeekdayOfMonth 2 4,DateSpan -2008-12-31)+-- Right (WeekdayOfMonth 2 4,DateSpan ..2008-12-31) -- >>> p "every 1st monday of month to 2009"--- Right (WeekdayOfMonth 1 1,DateSpan -2008-12-31)+-- Right (WeekdayOfMonth 1 1,DateSpan ..2008-12-31) -- >>> p "every tue"--- Right (DayOfWeek 2,DateSpan -)+-- Right (DayOfWeek 2,DateSpan ..) -- >>> p "every 2nd day of week"--- Right (DayOfWeek 2,DateSpan -)+-- Right (DayOfWeek 2,DateSpan ..) -- >>> p "every 2nd day of month"--- Right (DayOfMonth 2,DateSpan -)+-- Right (DayOfMonth 2,DateSpan ..) -- >>> p "every 2nd day"--- Right (DayOfMonth 2,DateSpan -)--- >>> p "every 2nd day 2009-"--- Right (DayOfMonth 2,DateSpan 2009-01-01-)--- >>> p "every 2nd day of month 2009-"--- Right (DayOfMonth 2,DateSpan 2009-01-01-)+-- Right (DayOfMonth 2,DateSpan ..)+-- >>> p "every 2nd day 2009.."+-- Right (DayOfMonth 2,DateSpan 2009-01-01..)+-- >>> p "every 2nd day of month 2009.."+-- Right (DayOfMonth 2,DateSpan 2009-01-01..) periodexprp :: Day -> TextParser m (Interval, DateSpan) periodexprp rdate = do skipMany spacenonewline@@ -1066,13 +1068,13 @@ -- | -- -- >>> parsewith (doubledatespan (parsedate "2018/01/01") <* eof) "20180101-201804"--- Right DateSpan 2018-01-01-2018-04-01+-- Right DateSpan 2018-01-01..2018-04-01 doubledatespanp :: Day -> TextParser m DateSpan doubledatespanp rdate = do optional (string' "from" >> skipMany spacenonewline) b <- smartdate skipMany spacenonewline- optional (choice [string' "to", string' "-"] >> skipMany spacenonewline)+ optional (choice [string' "to", string "..", string' "-"] >> skipMany spacenonewline) DateSpan (Just $ fixSmartDate rdate b) . Just . fixSmartDate rdate <$> smartdate fromdatespanp :: Day -> TextParser m DateSpan@@ -1084,14 +1086,14 @@ , do d <- smartdate- string' "-"+ choice [string "..", string' "-"] return d ] return $ DateSpan (Just $ fixSmartDate rdate b) Nothing todatespanp :: Day -> TextParser m DateSpan todatespanp rdate = do- choice [string' "to", string' "-"] >> skipMany spacenonewline+ choice [string' "to", string' "until", string "..", string' "-"] >> skipMany spacenonewline DateSpan Nothing . Just . fixSmartDate rdate <$> smartdate justdatespanp :: Day -> TextParser m DateSpan
Hledger/Data/Journal.hs view
@@ -21,6 +21,7 @@ addPeriodicTransaction, addTransaction, journalBalanceTransactions,+ journalInferMarketPricesFromTransactions, journalApplyCommodityStyles, commodityStylesFromAmounts, journalCommodityStyles,@@ -185,6 +186,7 @@ ,jcommodities = jcommodities j1 <> jcommodities j2 ,jinferredcommodities = jinferredcommodities j1 <> jinferredcommodities j2 ,jpricedirectives = jpricedirectives j1 <> jpricedirectives j2+ ,jtransactionimpliedmarketprices = jtransactionimpliedmarketprices j1 <> jtransactionimpliedmarketprices j2 ,jtxnmodifiers = jtxnmodifiers j1 <> jtxnmodifiers j2 ,jperiodictxns = jperiodictxns j1 <> jperiodictxns j2 ,jtxns = jtxns j1 <> jtxns j2@@ -210,6 +212,7 @@ ,jcommodities = M.empty ,jinferredcommodities = M.empty ,jpricedirectives = []+ ,jtransactionimpliedmarketprices = [] ,jtxnmodifiers = [] ,jperiodictxns = [] ,jtxns = []@@ -347,7 +350,7 @@ -- | A query for accounts in this journal which have been -- declared as Expense by account directives, or otherwise for -- accounts with names matched by the case-insensitive regular expression--- @^(income|revenue)s?(:|$)@.+-- @^expenses?(:|$)@. journalExpenseAccountQuery :: Journal -> Query journalExpenseAccountQuery = journalAccountTypeQuery Expense "^expenses?(:|$)" @@ -1035,6 +1038,32 @@ -- let ps = reverse $ filter ((<= d).pddate) $ filter ((s==).hsymbol) $ sortBy (comparing pddate) $ jpricedirectives j -- case ps of (PriceDirective{pdamount=a}:_) -> Just a -- _ -> Nothing++-- | Infer transaction-implied market prices from commodity-exchanging+-- transactions, if any. It's best to call this after transactions have+-- been balanced and posting amounts have appropriate prices attached.+journalInferMarketPricesFromTransactions :: Journal -> Journal+journalInferMarketPricesFromTransactions j =+ j{jtransactionimpliedmarketprices =+ dbg4 "jtransactionimpliedmarketprices" $+ mapMaybe postingImpliedMarketPrice $ journalPostings j+ }++-- | Make a market price equivalent to this posting's amount's unit+-- price, if any. If the posting amount is multicommodity, only the+-- first commodity amount is considered.+postingImpliedMarketPrice :: Posting -> Maybe MarketPrice+postingImpliedMarketPrice p@Posting{pamount} =+ -- convert any total prices to unit prices+ case mixedAmountTotalPriceToUnitPrice pamount of+ Mixed ( Amount{acommodity=fromcomm, aprice = Just (UnitPrice Amount{acommodity=tocomm, aquantity=rate})} : _) ->+ Just MarketPrice {+ mpdate = postingDate p+ ,mpfrom = fromcomm+ ,mpto = tocomm+ ,mprate = rate+ }+ _ -> Nothing -- | Convert all this journal's amounts to cost using the transaction prices, if any. -- The journal's commodity styles are applied to the resulting amounts.
Hledger/Data/Json.hs view
@@ -4,7 +4,7 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} ---{-# LANGUAGE CPP #-}+{-# LANGUAGE CPP #-} --{-# LANGUAGE DataKinds #-} --{-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-}@@ -28,15 +28,23 @@ module Hledger.Data.Json ( -- * Instances -- * Utilities- readJsonFile+ toJsonText ,writeJsonFile+ ,readJsonFile ) where +#if !(MIN_VERSION_base(4,13,0))+import Data.Semigroup ((<>))+#endif import Data.Aeson+import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder) --import Data.Aeson.TH import qualified Data.ByteString.Lazy as BL import Data.Decimal import Data.Maybe+import qualified Data.Text.Lazy as TL+import qualified Data.Text.Lazy.IO as TL+import Data.Text.Lazy.Builder (toLazyText) import GHC.Generics (Generic) import System.Time (ClockTime) @@ -198,20 +206,45 @@ -- --And of course you can avoid `StandAloneDeriving` entirely if you’re willing to wrap `Decimal` in your own `newtype`. +-- XXX these will allow reading a Journal, but currently the+-- jdeclaredaccounttypes Map gets serialised as a JSON list, which+-- can't be read back.+--+-- instance FromJSON AccountAlias+-- instance FromJSONKey AccountType where fromJSONKey = genericFromJSONKey defaultJSONKeyOptions+-- instance FromJSON AccountType+-- instance FromJSON ClockTime+-- instance FromJSON Commodity+-- instance FromJSON DateSpan+-- instance FromJSON Interval+-- instance FromJSON PeriodicTransaction+-- instance FromJSON PriceDirective+-- instance FromJSON TimeclockCode+-- instance FromJSON TimeclockEntry+-- instance FromJSON TransactionModifier+-- instance FromJSON Journal + -- Utilities --- | Read a json from a file and decode/parse it as the target type, if we can.--- Example: >>> readJsonFile "in.json" :: IO MixedAmount+-- | Show a JSON-convertible haskell value as pretty-printed JSON text.+toJsonText :: ToJSON a => a -> TL.Text+toJsonText = (<>"\n") . toLazyText . encodePrettyToTextBuilder++-- | Write a JSON-convertible haskell value to a pretty-printed JSON file.+-- Eg: writeJsonFile "a.json" nulltransaction+writeJsonFile :: ToJSON a => FilePath -> a -> IO ()+writeJsonFile f = TL.writeFile f . toJsonText+-- we write with Text and read with ByteString, is that fine ?++-- | Read a JSON file and decode it to the target type, or raise an error if we can't.+-- Eg: readJsonFile "a.json" :: IO Transaction readJsonFile :: FromJSON a => FilePath -> IO a readJsonFile f = do- bs <- BL.readFile f- let v = fromMaybe (error "could not decode bytestring as json value") (decode bs :: Maybe Value)+ bl <- BL.readFile f+ let v = fromMaybe (error $ "could not decode JSON in "++show f++" to target value")+ (decode bl :: Maybe Value) case fromJSON v :: FromJSON a => Result a of Error e -> error e Success t -> return t --- | Write some to-JSON-convertible haskell value to a json file, if we can.--- Example: >>> writeJsonFile "out.json" nullmixedamt-writeJsonFile :: ToJSON a => FilePath -> a -> IO ()-writeJsonFile f v = BL.writeFile f (encode v)
Hledger/Data/Period.hs view
@@ -154,17 +154,17 @@ -- | Render a period as a compact display string suitable for user output. -- -- >>> showPeriod (WeekPeriod (fromGregorian 2016 7 25))--- "2016-07-25w30"+-- "2016-07-25W30" showPeriod (DayPeriod b) = formatTime defaultTimeLocale "%F" b -- DATE-showPeriod (WeekPeriod b) = formatTime defaultTimeLocale "%Fw%V" b -- STARTDATEwYEARWEEK-showPeriod (MonthPeriod y m) = printf "%04d/%02d" y m -- YYYY/MM-showPeriod (QuarterPeriod y q) = printf "%04dq%d" y q -- YYYYqN+showPeriod (WeekPeriod b) = formatTime defaultTimeLocale "%FW%V" b -- STARTDATEWYEARWEEK+showPeriod (MonthPeriod y m) = printf "%04d-%02d" y m -- YYYY-MM+showPeriod (QuarterPeriod y q) = printf "%04dQ%d" y q -- YYYYQN showPeriod (YearPeriod y) = printf "%04d" y -- YYYY showPeriod (PeriodBetween b e) = formatTime defaultTimeLocale "%F" b- ++ formatTime defaultTimeLocale "-%F" (addDays (-1) e) -- STARTDATE-INCLUSIVEENDDATE-showPeriod (PeriodFrom b) = formatTime defaultTimeLocale "%F-" b -- STARTDATE--showPeriod (PeriodTo e) = formatTime defaultTimeLocale "-%F" (addDays (-1) e) -- -INCLUSIVEENDDATE-showPeriod PeriodAll = "-"+ ++ formatTime defaultTimeLocale "..%F" (addDays (-1) e) -- STARTDATE..INCLUSIVEENDDATE+showPeriod (PeriodFrom b) = formatTime defaultTimeLocale "%F.." b -- STARTDATE..+showPeriod (PeriodTo e) = formatTime defaultTimeLocale "..%F" (addDays (-1) e) -- ..INCLUSIVEENDDATE+showPeriod PeriodAll = ".." -- | Like showPeriod, but if it's a month period show just -- the 3 letter month name abbreviation for the current locale.
Hledger/Data/Posting.hs view
@@ -253,7 +253,7 @@ isPostingInDateSpan' SecondaryDate s = spanContainsDate s . postingDate2 isEmptyPosting :: Posting -> Bool-isEmptyPosting = isZeroMixedAmount . pamount+isEmptyPosting = mixedAmountLooksZero . pamount -- AccountName stuff that depends on PostingType @@ -331,7 +331,7 @@ -- | Convert this posting's amount to cost, and apply the appropriate amount styles. postingToCost :: M.Map CommoditySymbol AmountStyle -> Posting -> Posting-postingToCost styles p@Posting{pamount=a} = p{pamount=mixedAmountToCost styles a}+postingToCost styles p@Posting{pamount=a} = p{pamount=styleMixedAmount styles $ mixedAmountCost a} -- | Convert this posting's amount to market value in the given commodity, -- or the default valuation commodity, at the given valuation date,
Hledger/Data/Transaction.hs view
@@ -36,8 +36,6 @@ -- nonzerobalanceerror, -- * date operations transactionDate2,- -- * arithmetic- transactionPostingBalances, -- * transaction description parts transactionPayee, transactionNote,@@ -59,6 +57,7 @@ ) where import Data.List+import Data.List.Extra (nubSort) import Data.Maybe import Data.Text (Text) import qualified Data.Text as T@@ -333,27 +332,58 @@ transactionsPostings :: [Transaction] -> [Posting] transactionsPostings = concatMap tpostings --- | Get the sums of a transaction's real, virtual, and balanced virtual postings.-transactionPostingBalances :: Transaction -> (MixedAmount,MixedAmount,MixedAmount)-transactionPostingBalances t = (sumPostings $ realPostings t- ,sumPostings $ virtualPostings t- ,sumPostings $ balancedVirtualPostings t)+-- | Check that this transaction would appear balanced to a human when displayed.+-- On success, returns the empty list, otherwise one or more error messages.+--+-- In more detail:+-- For the real postings, and separately for the balanced virtual postings:+--+-- 1. Convert amounts to cost where possible+--+-- 2. When there are two or more non-zero amounts+-- (appearing non-zero when displayed, using the given display styles if provided),+-- are they a mix of positives and negatives ?+-- This is checked separately to give a clearer error message.+-- (Best effort; could be confused by postings with multicommodity amounts.)+--+-- 3. Does the amounts' sum appear non-zero when displayed ?+-- (using the given display styles if provided)+--+transactionCheckBalanced :: Maybe (M.Map CommoditySymbol AmountStyle) -> Transaction -> [String]+transactionCheckBalanced mstyles t = errs+ where+ (rps, bvps) = (realPostings t, balancedVirtualPostings t) --- | Does this transaction appear balanced when rendered, optionally with the--- given commodity display styles ? More precisely:--- after converting amounts to cost using explicit transaction prices if any;--- and summing the real postings, and summing the balanced virtual postings;--- and applying the given display styles if any (maybe affecting decimal places);--- do both totals appear to be zero when rendered ?+ -- check for mixed signs, detecting nonzeros at display precision+ canonicalise = maybe id canonicaliseMixedAmount mstyles+ signsOk ps = + case filter (not.mixedAmountLooksZero) $ map (canonicalise.mixedAmountCost.pamount) ps of+ nonzeros | length nonzeros >= 2+ -> length (nubSort $ mapMaybe isNegativeMixedAmount nonzeros) > 1+ _ -> True+ (rsignsok, bvsignsok) = (signsOk rps, signsOk bvps)++ -- check for zero sum, at display precision+ (rsum, bvsum) = (sumPostings rps, sumPostings bvps)+ (rsumcost, bvsumcost) = (mixedAmountCost rsum, mixedAmountCost bvsum)+ (rsumdisplay, bvsumdisplay) = (canonicalise rsumcost, canonicalise bvsumcost)+ (rsumok, bvsumok) = (mixedAmountLooksZero rsumdisplay, mixedAmountLooksZero bvsumdisplay)++ -- generate error messages, showing amounts with their original precision+ errs = filter (not.null) [rmsg, bvmsg]+ where+ rmsg+ | not rsignsok = "real postings all have the same sign"+ | not rsumok = "real postings' sum should be 0 but is: " ++ showMixedAmount rsumcost+ | otherwise = ""+ bvmsg+ | not bvsignsok = "balanced virtual postings all have the same sign"+ | not bvsumok = "balanced virtual postings' sum should be 0 but is: " ++ showMixedAmount bvsumcost+ | otherwise = ""++-- | Legacy form of transactionCheckBalanced. isTransactionBalanced :: Maybe (M.Map CommoditySymbol AmountStyle) -> Transaction -> Bool-isTransactionBalanced styles t =- -- isReallyZeroMixedAmountCost rsum && isReallyZeroMixedAmountCost bvsum- isZeroMixedAmount rsum' && isZeroMixedAmount bvsum'- where- (rsum, _, bvsum) = transactionPostingBalances t- rsum' = canonicalise $ costOfMixedAmount rsum- bvsum' = canonicalise $ costOfMixedAmount bvsum- canonicalise = maybe id canonicaliseMixedAmount styles+isTransactionBalanced mstyles = null . transactionCheckBalanced mstyles -- | Balance this transaction, ensuring that its postings -- (and its balanced virtual postings) sum to 0,@@ -384,25 +414,20 @@ balanceTransactionHelper mstyles t = do (t', inferredamtsandaccts) <- inferBalancingAmount (fromMaybe M.empty mstyles) $ inferBalancingPrices t- if isTransactionBalanced mstyles t'- then Right (txnTieKnot t', inferredamtsandaccts)- else Left $ annotateErrorWithTransaction t' $ nonzerobalanceerror t'+ case transactionCheckBalanced mstyles t' of+ [] -> Right (txnTieKnot t', inferredamtsandaccts)+ errs -> Left $ transactionBalanceError t' errs - where- nonzerobalanceerror :: Transaction -> String- nonzerobalanceerror tt = printf "could not balance this transaction (%s%s%s)" rmsg sep bvmsg- where- (rsum, _, bvsum) = transactionPostingBalances tt- rmsg | isReallyZeroMixedAmountCost rsum = ""- | otherwise = "real postings are off by "- ++ showMixedAmount (costOfMixedAmount rsum)- bvmsg | isReallyZeroMixedAmountCost bvsum = ""- | otherwise = "balanced virtual postings are off by "- ++ showMixedAmount (costOfMixedAmount bvsum)- sep = if not (null rmsg) && not (null bvmsg) then "; " else "" :: String+-- | Generate a transaction balancing error message, given the transaction+-- and one or more suberror messages.+transactionBalanceError :: Transaction -> [String] -> String+transactionBalanceError t errs =+ annotateErrorWithTransaction t $+ intercalate "\n" $ "could not balance this transaction:" : errs annotateErrorWithTransaction :: Transaction -> String -> String-annotateErrorWithTransaction t s = intercalate "\n" [showGenericSourcePos $ tsourcepos t, s, showTransaction t]+annotateErrorWithTransaction t s =+ unlines [showGenericSourcePos $ tsourcepos t, s, rstrip $ showTransaction t] -- | Infer up to one missing amount for this transactions's real postings, and -- likewise for its balanced virtual postings, if needed; or return an error@@ -418,9 +443,13 @@ -> Either String (Transaction, [(AccountName, MixedAmount)]) inferBalancingAmount styles t@Transaction{tpostings=ps} | length amountlessrealps > 1- = Left $ annotateErrorWithTransaction t "could not balance this transaction - can't have more than one real posting with no amount (remember to put 2 or more spaces before amounts)"+ = Left $ transactionBalanceError t+ ["can't have more than one real posting with no amount"+ ,"(remember to put two or more spaces between account and amount)"] | length amountlessbvps > 1- = Left $ annotateErrorWithTransaction t "could not balance this transaction - can't have more than one balanced virtual posting with no amount (remember to put 2 or more spaces before amounts)"+ = Left $ transactionBalanceError t+ ["can't have more than one balanced virtual posting with no amount"+ ,"(remember to put two or more spaces between account and amount)"] | otherwise = let psandinferredamts = map inferamount ps inferredacctsandamts = [(paccount p, amt) | (p, Just amt) <- psandinferredamts]@@ -446,7 +475,7 @@ -- Inferred amounts are converted to cost. -- Also ensure the new amount has the standard style for its commodity -- (since the main amount styling pass happened before this balancing pass);- a' = styleMixedAmount styles $ normaliseMixedAmount $ costOfMixedAmount (-a)+ a' = styleMixedAmount styles $ normaliseMixedAmount $ mixedAmountCost (-a) -- | Infer prices for this transaction's posting amounts, if needed to make -- the postings balance, and if possible. This is done once for the real
Hledger/Data/Types.hs view
@@ -471,8 +471,8 @@ ,jdeclaredaccounttypes :: M.Map AccountType [AccountName] -- ^ Accounts whose type has been declared in account directives (usually 5 top-level accounts) ,jcommodities :: M.Map CommoditySymbol Commodity -- ^ commodities and formats declared by commodity directives ,jinferredcommodities :: M.Map CommoditySymbol AmountStyle -- ^ commodities and formats inferred from journal amounts TODO misnamed - jusedstyles- ,jpricedirectives :: [PriceDirective] -- ^ All market price declarations (P directives), in parse order (after journal finalisation).- -- These will be converted to a Prices db for looking up prices by date.+ ,jpricedirectives :: [PriceDirective] -- ^ Declarations of market prices by P directives, in parse order (after journal finalisation)+ ,jtransactionimpliedmarketprices :: [MarketPrice] -- ^ Market prices implied by transactions, in parse order (after journal finalisation) ,jtxnmodifiers :: [TransactionModifier] ,jperiodictxns :: [PeriodicTransaction] ,jtxns :: [Transaction]
Hledger/Data/Valuation.hs view
@@ -31,7 +31,7 @@ import Control.DeepSeq (NFData) import Data.Data import Data.Decimal (roundTo)-import Data.Function (on)+import Data.Function ((&), on) import Data.Graph.Inductive (Gr, Node, NodeMap, mkMapGraph, mkNode, lab, out, sp) import Data.List import Data.List.Extra (nubSortBy)@@ -58,17 +58,22 @@ prGraph :: Gr CommoditySymbol Quantity -- ^ A directed graph of exchange rates between commodity pairs. -- Node labels are commodities and edge labels are exchange rates,- -- either explicitly declared (preferred) or inferred by reversing a declared rate.+ -- which were either:+ -- declared by P directives,+ -- implied by transaction prices,+ -- inferred by reversing a declared rate,+ -- or inferred by reversing a transaction-implied rate. -- There will be at most one edge between each directed pair of commodities, -- eg there can be one USD->EUR and one EUR->USD. ,prNodemap :: NodeMap CommoditySymbol -- ^ Mapping of graph node ids to commodity symbols.- ,prDeclaredPairs :: [(Node,Node)]- -- ^ Which of the edges in this graph are declared rates,- -- rather than inferred reverse rates.- -- A bit ugly. We could encode this in the edges,- -- but those have to be Real for shortest path finding,- -- so we'd have to transform them all first.+ ,prDefaultValuationCommodities :: M.Map CommoditySymbol CommoditySymbol+ -- ^ The default valuation commodity for each source commodity.+ -- These are used when a valuation commodity is not specified+ -- (-V). They are the destination commodity of the latest+ -- (declared or transaction-implied, but not reverse) each+ -- source commodity's latest market price (on the date of this+ -- graph). } deriving (Show,Generic) @@ -136,8 +141,8 @@ amountApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Maybe Day -> Day -> Bool -> ValuationType -> Amount -> Amount amountApplyValuation priceoracle styles periodlast mreportlast today ismultiperiod v a = case v of- AtCost Nothing -> amountToCost styles a- AtCost mc -> amountValueAtDate priceoracle styles mc periodlast $ amountToCost styles a+ AtCost Nothing -> styleAmount styles $ amountCost a+ AtCost mc -> amountValueAtDate priceoracle styles mc periodlast $ styleAmount styles $ amountCost a AtThen _mc -> error' unsupportedValueThenError -- TODO -- amountValueAtDate priceoracle styles mc periodlast a -- posting date unknown, handle like AtEnd AtEnd mc -> amountValueAtDate priceoracle styles mc periodlast a@@ -184,17 +189,18 @@ ------------------------------------------------------------------------------ -- Market price lookup --- From a journal's market price directives, generate a memoising function--- that efficiently looks up exchange rates between commodities on any date.--- For best results, you should generate this only once per journal, reusing it--- across reports if there are more than one (as in compoundBalanceCommand).+-- From a journal's directive-declared and transaction-implied market+-- prices, generate a memoising function that efficiently looks up+-- exchange rates between commodities on any date. For best performance,+-- you should generate this only once per journal, reusing it across+-- reports if there are more than one (as in compoundBalanceCommand). journalPriceOracle :: Journal -> PriceOracle-journalPriceOracle Journal{jpricedirectives} =+journalPriceOracle Journal{jpricedirectives, jtransactionimpliedmarketprices} = -- traceStack "journalPriceOracle" $ let pricesatdate = memo $- pricesAtDate jpricedirectives+ pricesAtDate jpricedirectives jtransactionimpliedmarketprices in memo $ uncurry3 $@@ -205,21 +211,32 @@ -- a different specified valuation commodity, or a default valuation -- commodity. ----- When the valuation commodity is specified, this looks for, in order:+-- When the valuation commodity is specified, this looks for an+-- exchange rate (market price) calculated in any of the following+-- ways, in order of preference: ----- - a price declaration giving the exchange rate from source--- commodity to valuation commodity ("declared price").+-- 1. a declared market price (DMP) - a P directive giving the+-- exchange rate from source commodity to valuation commodity ----- - a price declaration from valuation to source commodity, which--- gets inverted ("reverse price").+-- 2. a transaction-implied market price (TMP) - a market price+-- equivalent to the transaction price used in the latest+-- transaction from source commodity to valuation commodity+-- (on or before the valuation date) ----- - the shortest chain of prices (declared or reverse) leading from--- source commodity to valuation commodity, which gets collapsed--- into a single synthetic exchange rate ("indirect price").+-- 3. a reverse declared market price (RDMP) - calculated by inverting+-- a DMP --+-- 4. a reverse transaction-implied market price (RTMP) - calculated+-- by inverting a TMP+--+-- 5. an indirect market price (IMP) - calculated by combining the+-- shortest chain of market prices (any of the above types) leading+-- from source commodity to valuation commodity.+-- -- When the valuation commodity is not specified, this looks for the--- latest applicable declared price, and converts to the commodity--- mentioned in that price (the default valuation commodity).+-- latest applicable declared or transaction-implied price, and+-- converts to the commodity mentioned in that price (the default+-- valuation commodity). -- -- Note this default valuation commodity can vary across successive -- calls for different dates, since it depends on the price@@ -237,17 +254,12 @@ let -- build a graph of the commodity exchange rates in effect on this day -- XXX should hide these fgl details better- PriceGraph{prGraph=g, prNodemap=m, prDeclaredPairs=dps} = pricesatdate d+ PriceGraph{prGraph=g, prNodemap=m, prDefaultValuationCommodities=defaultdests} = pricesatdate d fromnode = node m from mto' = mto <|> mdefaultto where- -- If to is unspecified, try to pick a default valuation commodity from declared prices (only).- -- XXX how to choose ? Take lowest sorted ?- -- Take first, hoping current order is useful ? <-- -- Keep parse order in label and take latest parsed ?- mdefaultto =- dbg4 ("default valuation commodity for "++T.unpack from) $- headMay [t | (f,t,_) <- out g fromnode, (f,t) `elem` dps] >>= lab g+ mdefaultto = dbg4 ("default valuation commodity for "++T.unpack from) $+ M.lookup from defaultdests in case mto' of Nothing -> Nothing@@ -283,7 +295,7 @@ ,p "2000/01/01" "E" 2 "D" ,p "2001/01/01" "A" 11 "B" ]- pricesatdate = pricesAtDate ps1+ pricesatdate = pricesAtDate ps1 [] in test "priceLookup" $ do priceLookup pricesatdate (d "1999/01/01") "A" Nothing @?= Nothing priceLookup pricesatdate (d "2000/01/01") "A" Nothing @?= Just ("B",10)@@ -293,20 +305,21 @@ ------------------------------------------------------------------------------ -- Building the price graph (network of commodity conversions) on a given day. --- | Convert a list of market price directives in parse order to a--- graph of all prices in effect on a given day, allowing efficient--- lookup of exchange rates between commodity pairs.-pricesAtDate :: [PriceDirective] -> Day -> PriceGraph-pricesAtDate pricedirectives d =+-- | Convert a list of market price directives in parse order, and a+-- list of transaction-implied market prices in parse order, to a+-- graph of the effective exchange rates between commodity pairs on+-- the given day.+pricesAtDate :: [PriceDirective] -> [MarketPrice] -> Day -> PriceGraph+pricesAtDate pricedirectives transactionimpliedmarketprices d = -- trace ("pricesAtDate ("++show d++")") $- PriceGraph{prGraph=g, prNodemap=m, prDeclaredPairs=dps}+ PriceGraph{prGraph=g, prNodemap=m, prDefaultValuationCommodities=defaultdests} where- declaredprices = latestPriceForEachPairOn pricedirectives d+ declaredandimpliedprices = latestPriceForEachPairOn pricedirectives transactionimpliedmarketprices d - -- infer additional reverse prices where not already declared+ -- infer any additional reverse prices not already declared or implied reverseprices = dbg5 "reverseprices" $- map marketPriceReverse declaredprices \\ declaredprices+ map marketPriceReverse declaredandimpliedprices \\ declaredandimpliedprices -- build the graph and associated node map (g, m) =@@ -315,23 +328,37 @@ (dbg5 "g edges" $ [(mpfrom, mpto, mprate) | MarketPrice{..} <- prices]) :: (Gr CommoditySymbol Quantity, NodeMap CommoditySymbol) where- prices = declaredprices ++ reverseprices+ prices = declaredandimpliedprices ++ reverseprices allcomms = map mpfrom prices - -- remember which edges correspond to declared prices- dps = [(node m mpfrom, node m mpto) | MarketPrice{..} <- declaredprices ]+ -- save the forward prices' destinations as the default valuation+ -- commodity for those source commodities+ defaultdests = M.fromList [(mpfrom,mpto) | MarketPrice{..} <- declaredandimpliedprices] --- From a list of price directives in parse order, get the latest--- price declared on or before date d for each commodity pair.-latestPriceForEachPairOn :: [PriceDirective] -> Day -> [MarketPrice]-latestPriceForEachPairOn pricedirectives d =+-- From a list of price directives in parse order, and a list of+-- transaction-implied market prices in parse order, get the effective+-- price on the given date for each commodity pair. That is, the+-- latest declared or transaction-implied price dated on or before+-- that day, with declared prices taking precedence.+latestPriceForEachPairOn :: [PriceDirective] -> [MarketPrice] -> Day -> [MarketPrice]+latestPriceForEachPairOn pricedirectives transactionimpliedmarketprices d = dbg5 "latestPriceForEachPairOn" $- nubSortBy (compare `on` (\(MarketPrice{..})->(mpfrom,mpto))) $ -- keep only the first (ie newest and latest parsed) price for each pair- map snd $ -- discard the parse order label- sortBy (flip compare `on` (\(parseorder,mp)->(mpdate mp,parseorder))) $ -- sort with newest dates and latest parse order first- zip [1..] $ -- label with parse order- map priceDirectiveToMarketPrice $- filter ((<=d).pddate) pricedirectives -- consider only price declarations up to the valuation date+ let+ -- consider only declarations/transactions before the valuation date+ declaredprices = map priceDirectiveToMarketPrice $ filter ((<=d).pddate) pricedirectives+ transactionimpliedmarketprices' = filter ((<=d).mpdate) transactionimpliedmarketprices+ -- label the items with their precedence and then their parse order+ declaredprices' = [(1, i, p) | (i,p) <- zip [1..] declaredprices]+ transactionimpliedmarketprices'' = [(0, i, p) | (i,p) <- zip [1..] transactionimpliedmarketprices']+ in+ -- combine+ declaredprices' ++ transactionimpliedmarketprices''+ -- sort by newest date then highest precedence then latest parse order+ & sortBy (flip compare `on` (\(precedence,parseorder,mp)->(mpdate mp,precedence,parseorder)))+ -- discard the sorting labels+ & map third3+ -- keep only the first (ie the newest, highest precedence and latest parsed) price for each pair+ & nubSortBy (compare `on` (\(MarketPrice{..})->(mpfrom,mpto))) priceDirectiveToMarketPrice :: PriceDirective -> MarketPrice priceDirectiveToMarketPrice PriceDirective{..} =
Hledger/Query.hs view
@@ -49,6 +49,7 @@ matchesCommodity, matchesPriceDirective, words'',+ prefixes, -- * tests tests_Query )@@ -605,9 +606,9 @@ matchesPosting q@(Depth _) Posting{paccount=a} = q `matchesAccount` a matchesPosting q@(Amt _ _) Posting{pamount=amt} = q `matchesMixedAmount` amt -- matchesPosting q@(Amt _ _) Posting{pamount=amt} = q `matchesMixedAmount` amt--- matchesPosting (Empty v) Posting{pamount=a} = v == isZeroMixedAmount a+-- matchesPosting (Empty v) Posting{pamount=a} = v == mixedAmountLooksZero a -- matchesPosting (Empty False) Posting{pamount=a} = True--- matchesPosting (Empty True) Posting{pamount=a} = isZeroMixedAmount a+-- matchesPosting (Empty True) Posting{pamount=a} = mixedAmountLooksZero a matchesPosting (Empty _) _ = True matchesPosting (Sym r) Posting{pamount=Mixed as} = any (matchesCommodity (Sym r)) $ map acommodity as matchesPosting (Tag n v) p = case (n, v) of
Hledger/Read.hs view
@@ -1,4 +1,4 @@---- * -*- eval: (orgstruct-mode 1); orgstruct-heading-prefix-regexp:"--- "; -*-+--- * -*- outline-regexp:"--- \\*"; -*- --- ** doc -- In Emacs, use TAB on lines beginning with "-- *" to collapse/expand sections. {-|
Hledger/Read/Common.hs view
@@ -1,4 +1,4 @@---- * -*- eval: (orgstruct-mode 1); orgstruct-heading-prefix-regexp:"--- "; -*-+--- * -*- outline-regexp:"--- \\*"; -*- --- ** doc -- In Emacs, use TAB on lines beginning with "-- *" to collapse/expand sections. {-|@@ -45,7 +45,7 @@ journalSourcePos, parseAndFinaliseJournal, parseAndFinaliseJournal',- finaliseJournal,+ journalFinalise, setYear, getYear, setDefaultCommodityAndStyle,@@ -84,7 +84,7 @@ commoditysymbolp, priceamountp, balanceassertionp,- fixedlotpricep,+ lotpricep, numberp, fromRawNumber, rawnumberp,@@ -137,6 +137,7 @@ import Text.Megaparsec.Char import Text.Megaparsec.Char.Lexer (decimal) import Text.Megaparsec.Custom+import Control.Applicative.Permutations import Hledger.Data import Hledger.Utils@@ -259,7 +260,7 @@ Left finalParseError -> throwError $ finalErrorBundlePretty $ attachSource f txt finalParseError Right ep -> case ep of Left e -> throwError $ customErrorBundlePretty e- Right pj -> finaliseJournal iopts f txt pj+ Right pj -> journalFinalise iopts f txt pj -- | Like parseAndFinaliseJournal but takes a (non-Erroring) JournalParser. -- Used for timeclock/timedot.@@ -275,7 +276,7 @@ -- see notes above case ep of Left e -> throwError $ customErrorBundlePretty e- Right pj -> finaliseJournal iopts f txt pj+ Right pj -> journalFinalise iopts f txt pj -- | Post-process a Journal that has just been parsed or generated, in this order: --@@ -289,8 +290,10 @@ -- -- - check balance assertions if enabled. ---finaliseJournal :: InputOpts -> FilePath -> Text -> Journal -> ExceptT String IO Journal-finaliseJournal iopts f txt pj = do+-- - infer transaction-implied market prices from transaction prices+--+journalFinalise :: InputOpts -> FilePath -> Text -> Journal -> ExceptT String IO Journal+journalFinalise iopts f txt pj = do t <- liftIO getClockTime -- Infer and apply canonical styles for each commodity (or fail). -- This affects transaction balancing/assertions/assignments, so needs to be done early.@@ -304,23 +307,25 @@ & journalAddFile (f, txt) -- save the file path and content & journalSetLastReadTime t -- save the last read time & journalReverse -- convert all lists to parse order- & if not (auto_ iopts) || null (jtxnmodifiers pj)- then- -- Auto postings are not active.- -- Balance all transactions and maybe check balance assertions.- journalBalanceTransactions (not $ ignore_assertions_ iopts)- else \j -> do -- Either monad- -- Auto postings are active.- -- Balance all transactions without checking balance assertions,- j' <- journalBalanceTransactions False j- -- then add the auto postings- -- (Note adding auto postings after balancing means #893b fails;- -- adding them before balancing probably means #893a, #928, #938 fail.)- let j'' = journalModifyTransactions j'- -- then apply commodity styles once more, to style the auto posting amounts. (XXX inefficient ?)- j''' <- journalApplyCommodityStyles j''- -- then check balance assertions.- journalBalanceTransactions (not $ ignore_assertions_ iopts) j'''+ & (if not (auto_ iopts) || null (jtxnmodifiers pj)+ then+ -- Auto postings are not active.+ -- Balance all transactions and maybe check balance assertions.+ journalBalanceTransactions (not $ ignore_assertions_ iopts)+ else \j -> do -- Either monad+ -- Auto postings are active.+ -- Balance all transactions without checking balance assertions,+ j' <- journalBalanceTransactions False j+ -- then add the auto postings+ -- (Note adding auto postings after balancing means #893b fails;+ -- adding them before balancing probably means #893a, #928, #938 fail.)+ let j'' = journalModifyTransactions j'+ -- then apply commodity styles once more, to style the auto posting amounts. (XXX inefficient ?)+ j''' <- journalApplyCommodityStyles j''+ -- then check balance assertions.+ journalBalanceTransactions (not $ ignore_assertions_ iopts) j'''+ )+ & fmap journalInferMarketPricesFromTransactions -- infer market prices from commodity-exchanging transactions setYear :: Year -> JournalParser m () setYear y = modify' (\j -> j{jparsedefaultyear=Just y})@@ -603,14 +608,27 @@ lift $ skipSome spacenonewline Mixed . (:[]) <$> amountp --- | Parse a single-commodity amount, with optional symbol on the left or--- right, optional unit or total price, and optional (ignored)--- ledger-style balance assertion or fixed lot price declaration.+-- | Parse a single-commodity amount, with optional symbol on the left+-- or right, followed by, in any order: an optional transaction price,+-- an optional ledger-style lot price, and/or an optional ledger-style+-- lot date. A lot price and lot date will be ignored. amountp :: JournalParser m Amount amountp = label "amount" $ do+ let spaces = lift $ skipMany spacenonewline+ amount <- amountwithoutpricep <* spaces+ (mprice, _elotprice, _elotdate) <- runPermutation $+ (,,) <$> toPermutationWithDefault Nothing (Just <$> priceamountp <* spaces)+ <*> toPermutationWithDefault Nothing (Just <$> lotpricep <* spaces)+ <*> toPermutationWithDefault Nothing (Just <$> lotdatep <* spaces)+ pure $ amount { aprice = mprice }++-- XXX Just like amountp but don't allow lot prices. Needed for balanceassertionp.+amountpnolotprices :: JournalParser m Amount+amountpnolotprices = label "amount" $ do+ let spaces = lift $ skipMany spacenonewline amount <- amountwithoutpricep- lift $ skipMany spacenonewline- mprice <- priceamountp+ spaces+ mprice <- optional $ priceamountp <* spaces pure $ amount { aprice = mprice } amountwithoutpricep :: JournalParser m Amount@@ -688,8 +706,10 @@ mamountp' :: String -> MixedAmount mamountp' = Mixed . (:[]) . amountp' +-- | Parse a minus or plus sign followed by zero or more spaces,+-- or nothing, returning a function that negates or does nothing. signp :: Num a => TextParser m (a -> a)-signp = char '-' *> pure negate <|> char '+' *> pure id <|> pure id+signp = ((char '-' *> pure negate <|> char '+' *> pure id) <* many spacenonewline) <|> pure id multiplierp :: TextParser m Bool multiplierp = option False $ char '*' *> pure True@@ -718,15 +738,18 @@ simplecommoditysymbolp :: TextParser m CommoditySymbol simplecommoditysymbolp = takeWhile1P Nothing (not . isNonsimpleCommodityChar) -priceamountp :: JournalParser m (Maybe AmountPrice)-priceamountp = option Nothing $ do+priceamountp :: JournalParser m AmountPrice+priceamountp = label "transaction price" $ do+ -- https://www.ledger-cli.org/3.0/doc/ledger3.html#Virtual-posting-costs+ parenthesised <- option False $ char '(' >> pure True char '@' priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice+ when parenthesised $ void $ char ')' lift (skipMany spacenonewline)- priceAmount <- amountwithoutpricep <?> "unpriced amount (specifying a price)"+ priceAmount <- amountwithoutpricep -- <?> "unpriced amount (specifying a price)" - pure $ Just $ priceConstructor priceAmount+ pure $ priceConstructor priceAmount balanceassertionp :: JournalParser m BalanceAssertion balanceassertionp = do@@ -737,7 +760,7 @@ lift (skipMany spacenonewline) -- this amount can have a price; balance assertions ignore it, -- but balance assignments will use it- a <- amountp <?> "amount (for a balance assertion or assignment)"+ a <- amountpnolotprices <?> "amount (for a balance assertion or assignment)" return BalanceAssertion { baamount = a , batotal = istotal@@ -745,23 +768,34 @@ , baposition = sourcepos } --- Parse a Ledger-style fixed lot price: {=PRICE}+-- Parse a Ledger-style fixed {=UNITPRICE} or non-fixed {UNITPRICE}+-- or fixed {{=TOTALPRICE}} or non-fixed {{TOTALPRICE}} lot price,+-- and ignore it. -- https://www.ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices .--- Currently we ignore these (hledger's @ PRICE is equivalent),--- and we don't parse a Ledger-style {PRICE} (equivalent to Ledger's @ PRICE).-fixedlotpricep :: JournalParser m (Maybe Amount)-fixedlotpricep = optional $ do- try $ do- lift (skipMany spacenonewline)- char '{'- lift (skipMany spacenonewline)- char '='+lotpricep :: JournalParser m ()+lotpricep = label "ledger-style lot price" $ do+ char '{'+ doublebrace <- option False $ char '{' >> pure True+ _fixed <- fmap isJust $ optional $ lift (skipMany spacenonewline) >> char '=' lift (skipMany spacenonewline)- a <- amountwithoutpricep <?> "unpriced amount (for an ignored ledger-style fixed lot price)"+ _a <- amountwithoutpricep lift (skipMany spacenonewline) char '}'- return a+ when (doublebrace) $ void $ char '}'+ return () +-- Parse a Ledger-style lot date [DATE], and ignore it.+-- https://www.ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices .+lotdatep :: JournalParser m ()+lotdatep = (do+ char '['+ lift (skipMany spacenonewline)+ _d <- datep+ lift (skipMany spacenonewline)+ char ']'+ return ()+ ) <?> "ledger-style lot date"+ -- | Parse a string representation of a number for its value and display -- attributes. --@@ -1335,7 +1369,9 @@ ,astyle=amountstyle{asprecision=0, asdecimalpoint=Nothing} } }- ]+ ,test "unit price, parenthesised" $ assertParse amountp "$10 (@) €0.5"+ ,test "total price, parenthesised" $ assertParse amountp "$10 (@@) €0.5"+ ] ,let p = lift (numberp Nothing) :: JournalParser IO (Quantity, Int, Maybe Char, Maybe DigitGroupStyle) in test "numberp" $ do
Hledger/Read/CsvReader.hs view
@@ -1,4 +1,4 @@---- * -*- eval: (orgstruct-mode 1); orgstruct-heading-prefix-regexp:"--- "; -*-+--- * -*- outline-regexp:"--- \\*"; -*- --- ** doc -- In Emacs, use TAB on lines beginning with "-- *" to collapse/expand sections. {-|@@ -81,7 +81,7 @@ import Hledger.Data import Hledger.Utils-import Hledger.Read.Common (Reader(..),InputOpts(..),amountp, statusp, genericSourcePos, finaliseJournal)+import Hledger.Read.Common (Reader(..),InputOpts(..),amountp, statusp, genericSourcePos, journalFinalise) --- ** doctest setup -- $setup@@ -111,9 +111,9 @@ let rulesfile = mrules_file_ iopts r <- liftIO $ readJournalFromCsv rulesfile f t case r of Left e -> throwError e- Right pj -> finaliseJournal iopts{ignore_assertions_=True} f t pj'+ Right pj -> journalFinalise iopts{ignore_assertions_=True} f t pj' where- -- finaliseJournal assumes the journal's items are+ -- journalFinalise assumes the journal's items are -- reversed, as produced by JournalReader's parser. -- But here they are already properly ordered. So we'd -- better preemptively reverse them once more. XXX inefficient@@ -457,7 +457,7 @@ lift (dbgparse 2 "trying journalfieldnamep") T.unpack <$> choiceInState (map (lift . string . T.pack) journalfieldnames) -maxpostings = 9+maxpostings = 99 -- Transaction fields and pseudo fields for CSV conversion. -- Names must precede any other name they contain, for the parser@@ -470,7 +470,7 @@ ,"balance" ++ i ,"comment" ++ i ,"currency" ++ i- ] | x <- [1..maxpostings], let i = show x]+ ] | x <- [maxpostings, (maxpostings-1)..1], let i = show x] ++ ["amount-in" ,"amount-out"@@ -859,37 +859,63 @@ } -- | Figure out the amount specified for posting N, if any.--- Looks for a non-zero amount assigned to one of "amountN", "amountN-in", "amountN-out".--- Postings 1 or 2 also look at "amount", "amount-in", "amount-out".--- Throws an error if more than one of these has a non-zero amount assigned. -- A currency symbol to prepend to the amount, if any, is provided, -- and whether posting 1 requires balancing or not.+-- This looks for a non-empty amount value assigned to "amountN", "amountN-in", or "amountN-out".+-- For postings 1 or 2 it also looks at "amount", "amount-in", "amount-out".+-- If more than one of these has a value, it looks for one that is non-zero.+-- If there's multiple non-zeros, or no non-zeros but multiple zeros, it throws an error. getAmount :: CsvRules -> CsvRecord -> String -> Bool -> Int -> Maybe MixedAmount getAmount rules record currency p1IsVirtual n =+ -- Warning, many tricky corner cases here.+ -- docs: hledger_csv.m4.md #### amount+ -- tests: tests/csv.test ~ 13, 31-34 let unnumberedfieldnames = ["amount","amount-in","amount-out"]++ -- amount field names which can affect this posting fieldnames = map (("amount"++show n)++) ["","-in","-out"] -- For posting 1, also recognise the old amount/amount-in/amount-out names. -- For posting 2, the same but only if posting 1 needs balancing. ++ if n==1 || n==2 && not p1IsVirtual then unnumberedfieldnames else []- nonzeroamounts = [(f,a') | f <- fieldnames- , Just v@(_:_) <- [strip . renderTemplate rules record <$> hledgerField rules record f]- , let a = parseAmount rules record currency v- , not $ isZeroMixedAmount a- -- With amount/amount-in/amount-out, in posting 2,- -- flip the sign and convert to cost, as they did before 1.17- , let a' = if f `elem` unnumberedfieldnames && n==2 then costOfMixedAmount (-a) else a- ]- in case nonzeroamounts of++ -- assignments to any of these field names with non-empty values+ assignments = [(f,a') | f <- fieldnames+ , Just v@(_:_) <- [strip . renderTemplate rules record <$> hledgerField rules record f]+ , let a = parseAmount rules record currency v+ -- With amount/amount-in/amount-out, in posting 2,+ -- flip the sign and convert to cost, as they did before 1.17+ , let a' = if f `elem` unnumberedfieldnames && n==2 then mixedAmountCost (-a) else a+ ]++ -- if any of the numbered field names are present, discard all the unnumbered ones+ assignments' | any isnumbered assignments = filter isnumbered assignments+ | otherwise = assignments+ where+ isnumbered (f,_) = any (flip elem ['0'..'9']) f++ -- if there's more than one value and only some are zeros, discard the zeros+ assignments''+ | length assignments' > 1 && not (null nonzeros) = nonzeros+ | otherwise = assignments'+ where nonzeros = filter (not . mixedAmountLooksZero . snd) assignments'++ in case -- dbg0 ("amounts for posting "++show n)+ assignments'' of [] -> Nothing [(f,a)] | "-out" `isSuffixOf` f -> Just (-a) -- for -out fields, flip the sign [(_,a)] -> Just a- fs -> error' $- "more than one non-zero amount for this record, please ensure just one\n"- ++ unlines [" " ++ padright 11 f ++ ": " ++ showMixedAmount a- ++ " from rule: " ++ fromMaybe "" (hledgerField rules record f)- | (f,a) <- fs]- ++ " " ++ showRecord record ++ "\n"+ fs -> error' $ unlines $ [+ "multiple non-zero amounts or multiple zero amounts assigned,"+ ,"please ensure just one. (https://hledger.org/csv.html#amount)"+ ," " ++ showRecord record+ ," for posting: " ++ show n+ ]+ ++ [" assignment: " ++ f ++ " " +++ fromMaybe "" (hledgerField rules record f) +++ "\t=> value: " ++ showMixedAmount a -- XXX not sure this is showing all the right info+ | (f,a) <- fs]+ where -- | Given a non-empty amount string to parse, along with a possibly -- non-empty currency symbol to prepend, parse as a hledger amount (as@@ -1049,11 +1075,15 @@ where -- does this individual matcher match the current csv record ? matcherMatches :: Matcher -> Bool- matcherMatches (RecordMatcher pat) = regexMatchesCI pat wholecsvline+ matcherMatches (RecordMatcher pat) = regexMatchesCI pat' wholecsvline where- -- a synthetic whole CSV record to match against; note, it has- -- no quotes enclosing fields, and is always comma-separated,- -- so may differ from the actual record, and may not be valid CSV.+ pat' = dbg3 "regex" pat+ -- A synthetic whole CSV record to match against. Note, this can be+ -- different from the original CSV data:+ -- - any whitespace surrounding field values is preserved+ -- - any quotes enclosing field values are removed+ -- - and the field separator is always comma+ -- which means that a field containing a comma will look like two fields. wholecsvline = dbg3 "wholecsvline" $ intercalate "," record matcherMatches (FieldMatcher csvfieldref pat) = regexMatchesCI pat csvfieldvalue where
Hledger/Read/JournalReader.hs view
@@ -1,4 +1,4 @@---- * -*- eval: (orgstruct-mode 1); orgstruct-heading-prefix-regexp:"--- "; -*-+--- * -*- outline-regexp:"--- *"; -*- --- ** doc -- In Emacs, use TAB on lines beginning with "-- *" to collapse/expand sections. {-|@@ -82,6 +82,7 @@ import Control.Monad.Except (ExceptT(..), runExceptT) import Control.Monad.State.Strict (get,modify',put) import Control.Monad.Trans.Class (lift)+import Data.Char (toLower) import Data.Either (isRight) import qualified Data.Map.Strict as M #if !(MIN_VERSION_base(4,11,0))@@ -144,7 +145,7 @@ Nothing -> headMay [r | r <- readers', ext `elem` rExtensions r] where (prefix,path') = splitReaderPrefix path- ext = drop 1 $ takeExtension path'+ ext = map toLower $ drop 1 $ takeExtension path' -- | A file path optionally prefixed by a reader name and colon -- (journal:, csv:, timedot:, etc.).@@ -239,19 +240,23 @@ ] ) <?> "directive" +-- | Parse an include directive. include's argument is an optionally+-- file-format-prefixed file path or glob pattern. In the latter case,+-- the prefix is applied to each matched path. Examples:+-- foo.j, foo/bar.j, timedot:foo/2020*.md includedirectivep :: MonadIO m => ErroringJournalParser m () includedirectivep = do string "include" lift (skipSome spacenonewline)- filename <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet-+ prefixedglob <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet parentoff <- getOffset parentpos <- getSourcePos-- filepaths <- getFilePaths parentoff parentpos filename-- forM_ filepaths $ parseChild parentpos-+ let (mprefix,glob) = splitReaderPrefix prefixedglob+ paths <- getFilePaths parentoff parentpos glob+ let prefixedpaths = case mprefix of+ Nothing -> paths+ Just fmt -> map ((fmt++":")++) paths+ forM_ prefixedpaths $ parseChild parentpos void newline where@@ -274,10 +279,11 @@ else customFailure $ parseErrorAt parseroff $ "No existing files match pattern: " ++ filename - parseChild :: MonadIO m => SourcePos -> FilePath -> ErroringJournalParser m ()- parseChild parentpos filepath = do- parentj <- get+ parseChild :: MonadIO m => SourcePos -> PrefixedFilePath -> ErroringJournalParser m ()+ parseChild parentpos prefixedpath = do+ let (_mprefix,filepath) = splitReaderPrefix prefixedpath + parentj <- get let parentfilestack = jincludefilestack parentj when (filepath `elem` parentfilestack) $ Fail.fail ("Cyclic include: " ++ filepath)@@ -288,7 +294,7 @@ -- Choose a reader/format based on the file path, or fall back -- on journal. Duplicating readJournal a bit here.- let r = fromMaybe reader $ findReader Nothing (Just filepath)+ let r = fromMaybe reader $ findReader Nothing (Just prefixedpath) parser = rParser r dbg1IO "trying reader" (rFormat r) updatedChildj <- journalAddFile (filepath, childInput) <$>@@ -716,8 +722,7 @@ lift (skipMany spacenonewline) amount <- option missingmixedamt $ Mixed . (:[]) <$> amountp lift (skipMany spacenonewline)- massertion <- optional $ balanceassertionp- _ <- fixedlotpricep+ massertion <- optional balanceassertionp lift (skipMany spacenonewline) (comment,tags,mdate,mdate2) <- lift $ postingcommentp mTransactionYear return posting@@ -856,7 +861,16 @@ ,test "quoted commodity symbol with digits" $ assertParse (postingp Nothing) " a 1 \"DE123\"\n" - ,test "balance assertion and fixed lot price" $ assertParse (postingp Nothing) " a 1 \"DE123\" =$1 { =2.2 EUR} \n"+ ,test "only lot price" $ assertParse (postingp Nothing) " a 1A {1B}\n"+ ,test "fixed lot price" $ assertParse (postingp Nothing) " a 1A {=1B}\n"+ ,test "total lot price" $ assertParse (postingp Nothing) " a 1A {{1B}}\n"+ ,test "fixed total lot price, and spaces" $ assertParse (postingp Nothing) " a 1A {{ = 1B }}\n"+ ,test "lot price before transaction price" $ assertParse (postingp Nothing) " a 1A {1B} @ 1B\n"+ ,test "lot price after transaction price" $ assertParse (postingp Nothing) " a 1A @ 1B {1B}\n"+ ,test "lot price after balance assertion not allowed" $ assertParseError (postingp Nothing) " a 1A @ 1B = 1A {1B}\n" "unexpected '{'"+ ,test "only lot date" $ assertParse (postingp Nothing) " a 1A [2000-01-01]\n"+ ,test "transaction price, lot price, lot date" $ assertParse (postingp Nothing) " a 1A @ 1B {1B} [2000-01-01]\n"+ ,test "lot date, lot price, transaction price" $ assertParse (postingp Nothing) " a 1A [2000-01-01] {1B} @ 1B\n" ,test "balance assertion over entire contents of account" $ assertParse (postingp Nothing) " a $1 == $1\n" ]
Hledger/Read/TimeclockReader.hs view
@@ -1,4 +1,4 @@---- * -*- eval: (orgstruct-mode 1); orgstruct-heading-prefix-regexp:"--- "; -*-+--- * -*- outline-regexp:"--- \\*"; -*- --- ** doc -- In Emacs, use TAB on lines beginning with "-- *" to collapse/expand sections. {-|
Hledger/Read/TimedotReader.hs view
@@ -1,4 +1,4 @@---- * -*- eval: (orgstruct-mode 1); orgstruct-heading-prefix-regexp:"--- "; -*-+--- * -*- outline-regexp:"--- \\*"; -*- --- ** doc -- In Emacs, use TAB on lines beginning with "-- *" to collapse/expand sections. {-|
Hledger/Reports/BalanceReport.hs view
@@ -110,9 +110,9 @@ clipAccounts (queryDepth q) valuedaccttree where balance = if flat_ ropts then aebalance else aibalance- filterzeros = if empty_ then id else filter (not . isZeroMixedAmount . balance)- filterempty = filter (\a -> anumpostings a > 0 || not (isZeroMixedAmount (balance a)))- prunezeros = if empty_ then id else fromMaybe nullacct . pruneAccounts (isZeroMixedAmount . balance)+ filterzeros = if empty_ then id else filter (not . mixedAmountLooksZero . balance)+ filterempty = filter (\a -> anumpostings a > 0 || not (mixedAmountLooksZero (balance a)))+ prunezeros = if empty_ then id else fromMaybe nullacct . pruneAccounts (mixedAmountLooksZero . balance) markboring = if no_elide_ then id else markBoringParentAccounts -- Make a report row for each account.@@ -165,7 +165,7 @@ markBoringParentAccounts :: Account -> Account markBoringParentAccounts = tieAccountParents . mapAccounts mark where- mark a | length (asubs a) == 1 && isZeroMixedAmount (aebalance a) = a{aboring=True}+ mark a | length (asubs a) == 1 && mixedAmountLooksZero (aebalance a) = a{aboring=True} | otherwise = a balanceReportItem :: ReportOpts -> Query -> Account -> BalanceReportItem@@ -204,9 +204,9 @@ unifyMixedAmount mixedAmount = foldl combine (num 0) (amounts mixedAmount) where combine amount result =- if isReallyZeroAmount amount+ if amountIsZero amount then result- else if isReallyZeroAmount result+ else if amountIsZero result then amount else if acommodity amount == acommodity result then amount + result@@ -218,7 +218,7 @@ perdivide a b = let a' = unifyMixedAmount a b' = unifyMixedAmount b- in if isReallyZeroAmount a' || isReallyZeroAmount b' || acommodity a' == acommodity b'+ in if amountIsZero a' || amountIsZero b' || acommodity a' == acommodity b' then mixed [per $ if aquantity b' == 0 then 0 else (aquantity a' / abs (aquantity b') * 100)] else error' "Cannot calculate percentages if accounts have different commodities. (Hint: Try --cost, -V or similar flags.)"
Hledger/Reports/BudgetReport.hs view
@@ -61,7 +61,6 @@ -- and that reports with and without --empty make sense when compared side by side ropts = ropts' { accountlistmode_ = ALTree } showunbudgeted = empty_ ropts- q = queryFromOpts d ropts budgetedaccts = dbg2 "budgetedacctsinperiod" $ nub $@@ -73,9 +72,9 @@ actualj = dbg1With (("actualj"++).show.jtxns) $ budgetRollUp budgetedaccts showunbudgeted j budgetj = dbg1With (("budgetj"++).show.jtxns) $ budgetJournal assrt ropts reportspan j actualreport@(PeriodicReport actualspans _ _) =- dbg1 "actualreport" $ multiBalanceReport ropts q actualj+ dbg1 "actualreport" $ multiBalanceReport d ropts actualj budgetgoalreport@(PeriodicReport _ budgetgoalitems budgetgoaltotals) =- dbg1 "budgetgoalreport" $ multiBalanceReport (ropts{empty_=True}) q budgetj+ dbg1 "budgetgoalreport" $ multiBalanceReport d (ropts{empty_=True}) budgetj budgetgoalreport' -- If no interval is specified: -- budgetgoalreport's span might be shorter actualreport's due to periodic txns;@@ -292,12 +291,12 @@ percentage :: Change -> BudgetGoal -> Maybe Percentage percentage actual budget = case (maybecost $ normaliseMixedAmount actual, maybecost $ normaliseMixedAmount budget) of- (Mixed [a], Mixed [b]) | (acommodity a == acommodity b || isZeroAmount a) && not (isZeroAmount b)+ (Mixed [a], Mixed [b]) | (acommodity a == acommodity b || amountLooksZero a) && not (amountLooksZero b) -> Just $ 100 * aquantity a / aquantity b _ -> -- trace (pshow $ (maybecost actual, maybecost budget)) -- debug missing percentage Nothing where- maybecost = if valuationTypeIsCost ropts then costOfMixedAmount else id+ maybecost = if valuationTypeIsCost ropts then mixedAmountCost else id showamt :: MixedAmount -> String showamt | color_ = cshowMixedAmountOneLineWithoutPrice | otherwise = showMixedAmountOneLineWithoutPrice
Hledger/Reports/MultiBalanceReport.hs view
@@ -71,13 +71,15 @@ -- (see ReportOpts and CompoundBalanceCommand). -- hledger's most powerful and useful report, used by the balance -- command (in multiperiod mode) and (via multiBalanceReport') by the bs/cf/is commands.-multiBalanceReport :: ReportOpts -> Query -> Journal -> MultiBalanceReport-multiBalanceReport ropts q j = multiBalanceReportWith ropts q j (journalPriceOracle j)+multiBalanceReport :: Day -> ReportOpts -> Journal -> MultiBalanceReport+multiBalanceReport today ropts j = multiBalanceReportWith ropts (queryFromOpts today ropts) j (journalPriceOracle j) --- | A helper for multiBalanceReport. This one takes an extra argument, a+-- | A helper for multiBalanceReport. This one takes an explicit Query+-- instead of deriving one from ReportOpts, and an extra argument, a -- PriceOracle to be used for looking up market prices. Commands which--- run multiple reports (bs etc.) can generate the price oracle just once--- for efficiency, passing it to each report by calling this function directly.+-- run multiple reports (bs etc.) can generate the price oracle just+-- once for efficiency, passing it to each report by calling this+-- function directly. multiBalanceReportWith :: ReportOpts -> Query -> Journal -> PriceOracle -> MultiBalanceReport multiBalanceReportWith ropts@ReportOpts{..} q j priceoracle = (if invert_ then prNegate else id) $@@ -247,7 +249,7 @@ -- Total for a cumulative/historical report is always zero. , let rowtot = if balancetype_==PeriodChange then sum valuedrowbals else 0 , let rowavg = averageMixedAmounts valuedrowbals- , empty_ || depth == 0 || any (not . isZeroMixedAmount) valuedrowbals+ , empty_ || depth == 0 || any (not . mixedAmountLooksZero) valuedrowbals ] where avalue periodlast =@@ -358,7 +360,7 @@ balanceReportFromMultiBalanceReport :: ReportOpts -> Query -> Journal -> BalanceReport balanceReportFromMultiBalanceReport opts q j = (rows', total) where- PeriodicReport _ rows (PeriodicReportRow _ _ totals _ _) = multiBalanceReport opts q j+ PeriodicReport _ rows (PeriodicReportRow _ _ totals _ _) = multiBalanceReportWith opts q j (journalPriceOracle j) rows' = [( a , if flat_ opts then a else accountLeafName a -- BalanceReport expects full account name here with --flat , if tree_ opts then d-1 else 0 -- BalanceReport uses 0-based account depths@@ -391,7 +393,7 @@ amt0 = Amount {acommodity="$", aquantity=0, aprice=Nothing, astyle=AmountStyle {ascommodityside = L, ascommodityspaced = False, asprecision = 2, asdecimalpoint = Just '.', asdigitgroups = Nothing}, aismultiplier=False} (opts,journal) `gives` r = do let (eitems, etotal) = r- (PeriodicReport _ aitems atotal) = multiBalanceReport opts (queryFromOpts nulldate opts) journal+ (PeriodicReport _ aitems atotal) = multiBalanceReport nulldate opts journal showw (PeriodicReportRow acct indent lAmt amt amt') = (acct, accountLeafName acct, indent, map showMixedAmountDebug lAmt, showMixedAmountDebug amt, showMixedAmountDebug amt') (map showw aitems) @?= (map showw eitems)
Hledger/Reports/PostingsReport.hs view
@@ -253,7 +253,7 @@ | otherwise = ["..."] summaryps | depth > 0 = [summaryp{paccount=a,pamount=balance a} | a <- clippedanames] | otherwise = [summaryp{paccount="...",pamount=sum $ map pamount ps}]- summarypes = map (, e') $ (if showempty then id else filter (not . isZeroMixedAmount . pamount)) summaryps+ summarypes = map (, e') $ (if showempty then id else filter (not . mixedAmountLooksZero . pamount)) summaryps anames = nubSort $ map paccount ps -- aggregate balances by account, like ledgerFromJournal, then do depth-clipping accts = accountsFromPostings ps
Hledger/Reports/ReportOptions.hs view
@@ -22,6 +22,7 @@ whichDateFromOpts, journalSelectingAmountFromOpts, intervalFromRawOpts,+ forecastPeriodFromRawOpts, queryFromOpts, queryFromOptsOnly, queryOptsFromOpts,@@ -124,7 +125,7 @@ -- sign normalisation, converting normally negative subreports to -- normally positive for a more conventional display. ,color_ :: Bool- ,forecast_ :: Bool+ ,forecast_ :: Maybe DateSpan ,transpose_ :: Bool } deriving (Show, Data, Typeable) @@ -192,7 +193,7 @@ ,invert_ = boolopt "invert" rawopts' ,pretty_tables_ = boolopt "pretty-tables" rawopts' ,color_ = color- ,forecast_ = boolopt "forecast" rawopts'+ ,forecast_ = forecastPeriodFromRawOpts d rawopts' ,transpose_ = boolopt "transpose" rawopts' } @@ -313,6 +314,18 @@ | n == "yearly" = Just $ Years 1 | otherwise = Nothing +-- | get period expression from --forecast option+forecastPeriodFromRawOpts :: Day -> RawOpts -> Maybe DateSpan+forecastPeriodFromRawOpts d opts =+ case + dbg2 "forecastopt" $ maybestringopt "forecast" opts+ of+ Nothing -> Nothing+ Just "" -> Just nulldatespan+ Just str ->+ either (\e -> usageError $ "could not parse forecast period : "++customErrorBundlePretty e) (Just . snd) $ + parsePeriodExpr d $ stripquotes $ T.pack str+ -- | Extract the interval from the parsed -p/--period expression. -- Return Nothing if an interval is not explicitly defined. extractIntervalOrNothing :: (Interval, DateSpan) -> Maybe Interval
Hledger/Utils/Regex.hs view
@@ -50,13 +50,13 @@ import Data.Array import Data.Char import Data.List (foldl')+import Data.Maybe (fromMaybe) import Data.MemoUgly (memo) import Text.Regex.TDFA ( Regex, CompOption(..), ExecOption(..), defaultCompOpt, defaultExecOpt,- makeRegexOpts, AllMatches(getAllMatches), match, (=~), MatchText+ makeRegexOptsM, AllMatches(getAllMatches), match, (=~), MatchText ) --- import Hledger.Utils.Debug import Hledger.Utils.UTF8IOCompat (error') @@ -66,19 +66,20 @@ -- | A replacement pattern. May include numeric backreferences (\N). type Replacement = String --- | Convert our string-based regexps to real ones. Can fail if the--- string regexp is malformed.+-- | Convert our string-based Regexp to a real Regex.+-- Or if it's not well formed, call error with a "malformed regexp" message. toRegex :: Regexp -> Regex-toRegex = memo (makeRegexOpts compOpt execOpt)+toRegex = memo (compileRegexOrError defaultCompOpt defaultExecOpt) +-- | Like toRegex but make a case-insensitive Regex. toRegexCI :: Regexp -> Regex-toRegexCI = memo (makeRegexOpts compOpt{caseSensitive=False} execOpt)--compOpt :: CompOption-compOpt = defaultCompOpt+toRegexCI = memo (compileRegexOrError defaultCompOpt{caseSensitive=False} defaultExecOpt) -execOpt :: ExecOption-execOpt = defaultExecOpt+compileRegexOrError :: CompOption -> ExecOption -> Regexp -> Regex+compileRegexOrError compopt execopt r =+ fromMaybe+ (errorWithoutStackTrace $ "this regular expression could not be compiled: " ++ show r) $+ makeRegexOptsM compopt execopt r -- regexMatch' :: RegexContext Regexp String a => Regexp -> String -> a -- regexMatch' r s = s =~ (toRegex r)
− README
@@ -1,3 +0,0 @@-A reusable library containing hledger's core functionality.-This is used by most hledger* packages for common data parsing,-command line option handling, reporting etc.
+ README.md view
@@ -0,0 +1,9 @@+# hledger-lib++A reusable library containing hledger's core functionality.+This is used by most hledger* packages so that they support the same+common file formats, command line options, reports etc.++See also:+the [project README](https://hledger.org/README.html)+and [home page](https://hledger.org).
hledger-lib.cabal view
@@ -1,22 +1,24 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack ----- hash: 2280d91d2a756a6b17f33e15453b491d8945496a3876f4df74683110a0cc5d08+-- hash: 20f17b4cb289218f7b75159b42ad69840906c54c555a2191679edd3842b72e7b name: hledger-lib-version: 1.17.1-synopsis: Core data types, parsers and functionality for the hledger accounting tools-description: This is a reusable library containing hledger's core functionality.+version: 1.18+synopsis: A reusable library providing the core functionality of hledger+description: A reusable library containing hledger's core functionality.+ This is used by most hledger* packages so that they support the same+ common file formats, command line options, reports etc. .- hledger is a cross-platform program for tracking money, time, or- any other commodity, using double-entry accounting and a simple,- editable file format. It is inspired by and largely compatible- with ledger(1). hledger provides command-line, terminal and web- interfaces, and aims to be a reliable, practical tool for daily- use.+ hledger is a robust, cross-platform set of tools for tracking money,+ time, or any other commodity, using double-entry accounting and a+ simple, editable file format, with command-line, terminal and web+ interfaces. It is a Haskell rewrite of Ledger, and one of the leading+ implementations of Plain Text Accounting. Read more at:+ <https://hledger.org> category: Finance stability: stable homepage: http://hledger.org@@ -25,11 +27,11 @@ maintainer: Simon Michael <simon@joyful.com> license: GPL-3 license-file: LICENSE-tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.3, GHC==8.6.5, GHC==8.8.2, GHC==8.10+tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.5, GHC==8.8.3, GHC==8.10.0.20200123 build-type: Simple extra-source-files: CHANGES.md- README+ README.md test/unittest.hs test/doctests.hs hledger_csv.5@@ -109,6 +111,7 @@ Decimal >=0.5.1 , Glob >=0.9 , aeson+ , aeson-pretty , ansi-terminal >=0.6.2.3 , array , base >=4.9 && <4.15@@ -160,6 +163,7 @@ Decimal >=0.5.1 , Glob >=0.7 , aeson+ , aeson-pretty , ansi-terminal >=0.6.2.3 , array , base >=4.9 && <4.15@@ -174,7 +178,7 @@ , data-default >=0.5 , deepseq , directory- , doctest >=0.16+ , doctest >=0.16.3 , extra >=1.6.3 , fgl >=5.5.4.0 , file-embed >=0.0.10@@ -199,8 +203,7 @@ , transformers >=0.2 , uglymemo , utf8-string >=0.3.5- buildable: True- if (impl(ghc < 8.2) || impl(ghc >= 8.10))+ if (impl(ghc < 8.2)) buildable: False default-language: Haskell2010 @@ -215,6 +218,7 @@ Decimal >=0.5.1 , Glob >=0.9 , aeson+ , aeson-pretty , ansi-terminal >=0.6.2.3 , array , base >=4.9 && <4.15@@ -254,4 +258,5 @@ , transformers >=0.2 , uglymemo , utf8-string >=0.3.5+ buildable: True default-language: Haskell2010
hledger_csv.5 view
@@ -1,6 +1,6 @@ .\"t -.TH "hledger_csv" "5" "March 2020" "hledger 1.17.1" "hledger User Manuals"+.TH "hledger_csv" "5" "June 2020" "hledger 1.18" "hledger User Manuals" @@ -19,7 +19,7 @@ By default this is named like the CSV file with a \f[C].rules\f[R] extension added. Eg when reading \f[C]FILE.csv\f[R], hledger also looks for-\f[C]FILE.csv.rules\f[R] in the same directory.+\f[C]FILE.csv.rules\f[R] in the same directory as \f[C]FILE.csv\f[R]. You can specify a different rules file with the \f[C]--rules-file\f[R] option. If a rules file is not found, hledger will create a sample rules file,@@ -81,6 +81,11 @@ T}@T{ inline another CSV rules file T}+T{+\f[B]\f[CB]balance-type\f[B]\f[R]+T}@T{+choose which type of balance assignments to use+T} .TE .PP Note, for best error messages when reading CSV files, use a@@ -489,8 +494,8 @@ .SS Posting field names .SS account .PP-\f[C]accountN\f[R], where N is 1 to 9, causes a posting to be generated,-with that account name.+\f[C]accountN\f[R], where N is 1 to 99, causes a posting to be+generated, with that account name. .PP Most often there are two postings, so you\[aq]ll want to set \f[C]account1\f[R] and \f[C]account2\f[R].@@ -504,14 +509,30 @@ .SS amount .PP \f[C]amountN\f[R] sets posting N\[aq]s amount.-If the CSV uses separate fields for debit and credit amounts, you can-use \f[C]amountN-in\f[R] and \f[C]amountN-out\f[R] instead.+If the CSV uses separate fields for inflows and outflows, you can use+\f[C]amountN-in\f[R] and \f[C]amountN-out\f[R] instead.+By assigning to \f[C]amount1\f[R], \f[C]amount2\f[R], ...+etc.+you can generate anywhere from 0 to 99 postings. .PP-Also, for compatibility with hledger <1.17: \f[C]amount\f[R] or-\f[C]amount-in\f[R]/\f[C]amount-out\f[R] with no number sets the amount-for postings 1 and 2.-For posting 2 the amount is negated, and converted to cost if-there\[aq]s a transaction price.+There is also an older, unnumbered form of these names, suitable for+2-posting transactions, which sets both posting 1\[aq]s and (negated)+posting 2\[aq]s amount: \f[C]amount\f[R], or \f[C]amount-in\f[R] and+\f[C]amount-out\f[R].+This is still supported because it keeps pre-hledger-1.17 csv rules+files working, and because it can be more succinct, and because it+converts posting 2\[aq]s amount to cost if there\[aq]s a transaction+price, which can be useful.+.PP+If you have an existing rules file using the unnumbered form, you might+want to use the numbered form in certain conditional blocks, without+having to update and retest all the old rules.+To facilitate this, posting 1 ignores+\f[C]amount\f[R]/\f[C]amount-in\f[R]/\f[C]amount-out\f[R] if any of+\f[C]amount1\f[R]/\f[C]amount1-in\f[R]/\f[C]amount1-out\f[R] are+assigned, and posting 2 ignores them if any of+\f[C]amount2\f[R]/\f[C]amount2-in\f[R]/\f[C]amount2-out\f[R] are+assigned, avoiding conflicts. .SS currency .PP If the CSV has the currency symbol in a separate field (ie, not part of@@ -620,13 +641,19 @@ .PP REGEX is a case-insensitive regular expression which tries to match anywhere within the CSV record.-It is a POSIX extended regular expressions with some additions (see-Regular expressions in the hledger manual).-Note: the \[dq]CSV record\[dq] it is matched against is not the original-record, but a synthetic one, with enclosing double quotes or whitespace-removed, and always comma-separated.-(Eg, an SSV record \f[C]2020-01-01; \[dq]Acme, Inc.\[dq]; 1,000\f[R]-appears to REGEX as \f[C]2020-01-01,Acme, Inc.,1,000\f[R]).+It is a POSIX ERE (extended regular expression) that also supports GNU+word boundaries (\f[C]\[rs]b\f[R], \f[C]\[rs]B\f[R], \f[C]\[rs]<\f[R],+\f[C]\[rs]>\f[R]), and nothing else.+If you have trouble, be sure to check our+https://hledger.org/hledger.html#regular-expressions doc.+.PP+Important note: the record that is matched is not the original record,+but a synthetic one, with any enclosing double quotes (but not enclosing+whitespace) removed, and always comma-separated (which means that a+field containing a comma will appear like two fields).+Eg, if the original record is+\f[C]2020-01-01; \[dq]Acme, Inc.\[dq]; 1,000\f[R], the REGEX will+actually see \f[C]2020-01-01,Acme, Inc., 1,000\f[R]). .PP Or, MATCHER can be a field matcher, like this: .IP
hledger_csv.info view
@@ -3,8 +3,8 @@ File: hledger_csv.info, Node: Top, Next: EXAMPLES, Up: (dir) -hledger_csv(5) hledger 1.17.1-*****************************+hledger_csv(5) hledger 1.18+*************************** CSV - how hledger reads CSV data, and the CSV rules file format @@ -16,9 +16,9 @@ We describe each CSV file's format with a corresponding _rules file_. By default this is named like the CSV file with a '.rules' extension added. Eg when reading 'FILE.csv', hledger also looks for-'FILE.csv.rules' in the same directory. You can specify a different-rules file with the '--rules-file' option. If a rules file is not-found, hledger will create a sample rules file, which you'll need to+'FILE.csv.rules' in the same directory as 'FILE.csv'. You can specify a+different rules file with the '--rules-file' option. If a rules file is+not found, hledger will create a sample rules file, which you'll need to adjust. This file contains rules describing the CSV data (header line, fields@@ -38,6 +38,7 @@ *'date-format'* describe the format of CSV dates *'newest-first'* disambiguate record order when there's only one date *'include'* inline another CSV rules file+*'balance-type'* choose which type of balance assignments to use Note, for best error messages when reading CSV files, use a '.csv', '.tsv' or '.ssv' file extension or file prefix - see File Extension@@ -465,7 +466,7 @@ 2.2.2.1 account ............... -'accountN', where N is 1 to 9, causes a posting to be generated, with+'accountN', where N is 1 to 99, causes a posting to be generated, with that account name. Most often there are two postings, so you'll want to set 'account1'@@ -484,14 +485,26 @@ .............. 'amountN' sets posting N's amount. If the CSV uses separate fields for-debit and credit amounts, you can use 'amountN-in' and 'amountN-out'-instead.+inflows and outflows, you can use 'amountN-in' and 'amountN-out'+instead. By assigning to 'amount1', 'amount2', ... etc. you can+generate anywhere from 0 to 99 postings. - Also, for compatibility with hledger <1.17: 'amount' or-'amount-in'/'amount-out' with no number sets the amount for postings 1-and 2. For posting 2 the amount is negated, and converted to cost if-there's a transaction price.+ There is also an older, unnumbered form of these names, suitable for+2-posting transactions, which sets both posting 1's and (negated)+posting 2's amount: 'amount', or 'amount-in' and 'amount-out'. This is+still supported because it keeps pre-hledger-1.17 csv rules files+working, and because it can be more succinct, and because it converts+posting 2's amount to cost if there's a transaction price, which can be+useful. + If you have an existing rules file using the unnumbered form, you+might want to use the numbered form in certain conditional blocks,+without having to update and retest all the old rules. To facilitate+this, posting 1 ignores 'amount'/'amount-in'/'amount-out' if any of+'amount1'/'amount1-in'/'amount1-out' are assigned, and posting 2 ignores+them if any of 'amount2'/'amount2-in'/'amount2-out' are assigned,+avoiding conflicts.+ File: hledger_csv.info, Node: currency, Next: balance, Prev: amount, Up: Posting field names @@ -599,14 +612,18 @@ REGEX REGEX is a case-insensitive regular expression which tries to match-anywhere within the CSV record. It is a POSIX extended regular-expressions with some additions (see Regular expressions in the hledger-manual). Note: the "CSV record" it is matched against is not the-original record, but a synthetic one, with enclosing double quotes or-whitespace removed, and always comma-separated. (Eg, an SSV record-'2020-01-01; "Acme, Inc."; 1,000' appears to REGEX as '2020-01-01,Acme,-Inc.,1,000').+anywhere within the CSV record. It is a POSIX ERE (extended regular+expression) that also supports GNU word boundaries ('\b', '\B', '\<',+'\>'), and nothing else. If you have trouble, be sure to check our+https://hledger.org/hledger.html#regular-expressions doc. + Important note: the record that is matched is not the original+record, but a synthetic one, with any enclosing double quotes (but not+enclosing whitespace) removed, and always comma-separated (which means+that a field containing a comma will appear like two fields). Eg, if+the original record is '2020-01-01; "Acme, Inc."; 1,000', the REGEX will+actually see '2020-01-01,Acme, Inc., 1,000').+ Or, MATCHER can be a field matcher, like this: %CSVFIELD REGEX@@ -1019,74 +1036,74 @@ Tag Table: Node: Top72-Node: EXAMPLES2097-Ref: #examples2203-Node: Basic2411-Ref: #basic2511-Node: Bank of Ireland3053-Ref: #bank-of-ireland3188-Node: Amazon4650-Ref: #amazon4768-Node: Paypal6487-Ref: #paypal6581-Node: CSV RULES14225-Ref: #csv-rules14334-Node: skip14610-Ref: #skip14703-Node: fields15078-Ref: #fields15200-Node: Transaction field names16365-Ref: #transaction-field-names16525-Node: Posting field names16636-Ref: #posting-field-names16788-Node: account16858-Ref: #account16974-Node: amount17510-Ref: #amount17641-Node: currency18022-Ref: #currency18157-Node: balance18363-Ref: #balance18497-Node: comment18814-Ref: #comment18931-Node: field assignment19094-Ref: #field-assignment19237-Node: separator20055-Ref: #separator20184-Node: if20595-Ref: #if20697-Node: end22616-Ref: #end22722-Node: date-format22946-Ref: #date-format23078-Node: newest-first23827-Ref: #newest-first23965-Node: include24648-Ref: #include24777-Node: balance-type25221-Ref: #balance-type25341-Node: TIPS26041-Ref: #tips26123-Node: Rapid feedback26379-Ref: #rapid-feedback26496-Node: Valid CSV26956-Ref: #valid-csv27086-Node: File Extension27278-Ref: #file-extension27430-Node: Reading multiple CSV files27840-Ref: #reading-multiple-csv-files28025-Node: Valid transactions28266-Ref: #valid-transactions28444-Node: Deduplicating importing29072-Ref: #deduplicating-importing29251-Node: Setting amounts30284-Ref: #setting-amounts30453-Node: Setting currency/commodity31439-Ref: #setting-currencycommodity31631-Node: Referencing other fields32434-Ref: #referencing-other-fields32634-Node: How CSV rules are evaluated33531-Ref: #how-csv-rules-are-evaluated33704+Node: EXAMPLES2174+Ref: #examples2280+Node: Basic2488+Ref: #basic2588+Node: Bank of Ireland3130+Ref: #bank-of-ireland3265+Node: Amazon4727+Ref: #amazon4845+Node: Paypal6564+Ref: #paypal6658+Node: CSV RULES14302+Ref: #csv-rules14411+Node: skip14687+Ref: #skip14780+Node: fields15155+Ref: #fields15277+Node: Transaction field names16442+Ref: #transaction-field-names16602+Node: Posting field names16713+Ref: #posting-field-names16865+Node: account16935+Ref: #account17051+Node: amount17588+Ref: #amount17719+Node: currency18826+Ref: #currency18961+Node: balance19167+Ref: #balance19301+Node: comment19618+Ref: #comment19735+Node: field assignment19898+Ref: #field-assignment20041+Node: separator20859+Ref: #separator20988+Node: if21399+Ref: #if21501+Node: end23657+Ref: #end23763+Node: date-format23987+Ref: #date-format24119+Node: newest-first24868+Ref: #newest-first25006+Node: include25689+Ref: #include25818+Node: balance-type26262+Ref: #balance-type26382+Node: TIPS27082+Ref: #tips27164+Node: Rapid feedback27420+Ref: #rapid-feedback27537+Node: Valid CSV27997+Ref: #valid-csv28127+Node: File Extension28319+Ref: #file-extension28471+Node: Reading multiple CSV files28881+Ref: #reading-multiple-csv-files29066+Node: Valid transactions29307+Ref: #valid-transactions29485+Node: Deduplicating importing30113+Ref: #deduplicating-importing30292+Node: Setting amounts31325+Ref: #setting-amounts31494+Node: Setting currency/commodity32480+Ref: #setting-currencycommodity32672+Node: Referencing other fields33475+Ref: #referencing-other-fields33675+Node: How CSV rules are evaluated34572+Ref: #how-csv-rules-are-evaluated34745 End Tag Table
hledger_csv.txt view
@@ -15,9 +15,9 @@ We describe each CSV file's format with a corresponding rules file. By default this is named like the CSV file with a .rules extension added. Eg when reading FILE.csv, hledger also looks for FILE.csv.rules in the- same directory. You can specify a different rules file with the- --rules-file option. If a rules file is not found, hledger will create- a sample rules file, which you'll need to adjust.+ same directory as FILE.csv. You can specify a different rules file+ with the --rules-file option. If a rules file is not found, hledger+ will create a sample rules file, which you'll need to adjust. This file contains rules describing the CSV data (header line, fields layout, date format etc.), and how to construct hledger journal entries@@ -45,20 +45,22 @@ when there's only one date include inline another CSV rules file+ balance-type choose which type of bal-+ ance assignments to use - Note, for best error messages when reading CSV files, use a .csv, .tsv+ Note, for best error messages when reading CSV files, use a .csv, .tsv or .ssv file extension or file prefix - see File Extension below. There's an introductory Convert CSV files tutorial on hledger.org. EXAMPLES- Here are some sample hledger CSV rules files. See also the full col-+ Here are some sample hledger CSV rules files. See also the full col- lection at: https://github.com/simonmichael/hledger/tree/master/examples/csv Basic- At minimum, the rules file must identify the date and amount fields,- and often it also specifies the date format and how many header lines+ At minimum, the rules file must identify the date and amount fields,+ and often it also specifies the date format and how many header lines there are. Here's a simple CSV file and a rules file for it: Date, Description, Id, Amount@@ -77,8 +79,8 @@ Default account names are chosen, since we didn't set them. Bank of Ireland- Here's a CSV with two amount fields (Debit and Credit), and a balance- field, which we can use to add balance assertions, which is not neces-+ Here's a CSV with two amount fields (Debit and Credit), and a balance+ field, which we can use to add balance assertions, which is not neces- sary but provides extra error checking: Date,Details,Debit,Credit,Balance@@ -120,13 +122,13 @@ assets:bank:boi:checking EUR-5.0 = EUR126.0 expenses:unknown EUR5.0 - The balance assertions don't raise an error above, because we're read-- ing directly from CSV, but they will be checked if these entries are+ The balance assertions don't raise an error above, because we're read-+ ing directly from CSV, but they will be checked if these entries are imported into a journal file. Amazon Here we convert amazon.com order history, and use an if block to gener-- ate a third posting if there's a fee. (In practice you'd probably get+ ate a third posting if there's a fee. (In practice you'd probably get this data from your bank instead, but it's an example.) "Date","Type","To/From","Name","Status","Amount","Fees","Transaction ID"@@ -178,7 +180,7 @@ expenses:fees $1.00 Paypal- Here's a real-world rules file for (customised) Paypal CSV, with some+ Here's a real-world rules file for (customised) Paypal CSV, with some Paypal-specific rules, and a second rules file included: "Date","Time","TimeZone","Name","Type","Status","Currency","Gross","Fee","Net","From Email Address","To Email Address","Transaction ID","Item Title","Item ID","Reference Txn ID","Receipt ID","Balance","Note"@@ -333,9 +335,9 @@ skip skip N - The word "skip" followed by a number (or no number, meaning 1) tells- hledger to ignore this many non-empty lines preceding the CSV data.- (Empty/blank lines are skipped automatically.) You'll need this when-+ The word "skip" followed by a number (or no number, meaning 1) tells+ hledger to ignore this many non-empty lines preceding the CSV data.+ (Empty/blank lines are skipped automatically.) You'll need this when- ever your CSV data contains header lines. It also has a second purpose: it can be used inside if blocks to ignore@@ -344,27 +346,27 @@ fields fields FIELDNAME1, FIELDNAME2, ... - A fields list (the word "fields" followed by comma-separated field- names) is the quick way to assign CSV field values to hledger fields.+ A fields list (the word "fields" followed by comma-separated field+ names) is the quick way to assign CSV field values to hledger fields. It does two things: - 1. it names the CSV fields. This is optional, but can be convenient+ 1. it names the CSV fields. This is optional, but can be convenient later for interpolating them. 2. when you use a standard hledger field name, it assigns the CSV value to that part of the hledger transaction. - Here's an example that says "use the 1st, 2nd and 4th fields as the- transaction's date, description and amount; name the last two fields+ Here's an example that says "use the 1st, 2nd and 4th fields as the+ transaction's date, description and amount; name the last two fields for later reference; and ignore the others": fields date, description, , amount, , , somefield, anotherfield - Field names may not contain whitespace. Fields you don't care about- can be left unnamed. Currently there must be least two items (there+ Field names may not contain whitespace. Fields you don't care about+ can be left unnamed. Currently there must be least two items (there must be at least one comma). - Note, always use comma in the fields list, even if your CSV uses an-+ Note, always use comma in the fields list, even if your CSV uses an- other separator character. Here are the standard hledger field/pseudo-field names. For more about@@ -377,28 +379,39 @@ Posting field names account- accountN, where N is 1 to 9, causes a posting to be generated, with+ accountN, where N is 1 to 99, causes a posting to be generated, with that account name. - Most often there are two postings, so you'll want to set account1 and- account2. Typically account1 is associated with the CSV file, and is- set once with a top-level assignment, while account2 is set based on+ Most often there are two postings, so you'll want to set account1 and+ account2. Typically account1 is associated with the CSV file, and is+ set once with a top-level assignment, while account2 is set based on each transaction's description, and in conditional blocks. - If a posting's account name is left unset but its amount is set (see- below), a default account name will be chosen (like "expenses:unknown"+ If a posting's account name is left unset but its amount is set (see+ below), a default account name will be chosen (like "expenses:unknown" or "income:unknown"). amount- amountN sets posting N's amount. If the CSV uses separate fields for- debit and credit amounts, you can use amountN-in and amountN-out in-- stead.+ amountN sets posting N's amount. If the CSV uses separate fields for+ inflows and outflows, you can use amountN-in and amountN-out instead.+ By assigning to amount1, amount2, ... etc. you can generate anywhere+ from 0 to 99 postings. - Also, for compatibility with hledger <1.17: amount or amount-in/amount-- out with no number sets the amount for postings 1 and 2. For posting 2- the amount is negated, and converted to cost if there's a transaction- price.+ There is also an older, unnumbered form of these names, suitable for+ 2-posting transactions, which sets both posting 1's and (negated) post-+ ing 2's amount: amount, or amount-in and amount-out. This is still+ supported because it keeps pre-hledger-1.17 csv rules files working,+ and because it can be more succinct, and because it converts posting+ 2's amount to cost if there's a transaction price, which can be useful. + If you have an existing rules file using the unnumbered form, you might+ want to use the numbered form in certain conditional blocks, without+ having to update and retest all the old rules. To facilitate this,+ posting 1 ignores amount/amount-in/amount-out if any of+ amount1/amount1-in/amount1-out are assigned, and posting 2 ignores them+ if any of amount2/amount2-in/amount2-out are assigned, avoiding con-+ flicts.+ currency If the CSV has the currency symbol in a separate field (ie, not part of the amount field), you can use currencyN to prepend it to posting N's@@ -474,27 +487,32 @@ REGEX REGEX is a case-insensitive regular expression which tries to match- anywhere within the CSV record. It is a POSIX extended regular expres-- sions with some additions (see Regular expressions in the hledger man-- ual). Note: the "CSV record" it is matched against is not the original- record, but a synthetic one, with enclosing double quotes or whitespace- removed, and always comma-separated. (Eg, an SSV record 2020-01-01;- "Acme, Inc."; 1,000 appears to REGEX as 2020-01-01,Acme, Inc.,1,000).+ anywhere within the CSV record. It is a POSIX ERE (extended regular+ expression) that also supports GNU word boundaries (\b, \B, \<, \>),+ and nothing else. If you have trouble, be sure to check our+ https://hledger.org/hledger.html#regular-expressions doc. + Important note: the record that is matched is not the original record,+ but a synthetic one, with any enclosing double quotes (but not enclos-+ ing whitespace) removed, and always comma-separated (which means that a+ field containing a comma will appear like two fields). Eg, if the+ original record is 2020-01-01; "Acme, Inc."; 1,000, the REGEX will ac-+ tually see 2020-01-01,Acme, Inc., 1,000).+ Or, MATCHER can be a field matcher, like this: %CSVFIELD REGEX - which matches just the content of a particular CSV field. CSVFIELD is- a percent sign followed by the field's name or column number, like+ which matches just the content of a particular CSV field. CSVFIELD is+ a percent sign followed by the field's name or column number, like %date or %1. A single matcher can be written on the same line as the "if"; or multi- ple matchers can be written on the following lines, non-indented. Mul- tiple matchers are OR'd (any one of them can match). - After the patterns there should be one or more rules to apply, all in-- dented by at least one space. Three kinds of rule are allowed in con-+ After the patterns there should be one or more rules to apply, all in-+ dented by at least one space. Three kinds of rule are allowed in con- ditional blocks: o field assignments (to set a hledger field)@@ -518,7 +536,7 @@ comment XXX deductible ? check it end- This rule can be used inside if blocks (only), to make hledger stop+ This rule can be used inside if blocks (only), to make hledger stop reading this CSV file and move on to the next input file, or to command execution. Eg: @@ -529,10 +547,10 @@ date-format date-format DATEFMT - This is a helper for the date (and date2) fields. If your CSV dates- are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll- need to add a date-format rule describing them with a strptime date- parsing pattern, which must parse the CSV date value completely. Some+ This is a helper for the date (and date2) fields. If your CSV dates+ are not formatted like YYYY-MM-DD, YYYY/MM/DD or YYYY.MM.DD, you'll+ need to add a date-format rule describing them with a strptime date+ parsing pattern, which must parse the CSV date value completely. Some examples: # MM/DD/YY@@ -554,15 +572,15 @@ mat.html#v:formatTime newest-first- hledger always sorts the generated transactions by date. Transactions- on the same date should appear in the same order as their CSV records,- as hledger can usually auto-detect whether the CSV's normal order is+ hledger always sorts the generated transactions by date. Transactions+ on the same date should appear in the same order as their CSV records,+ as hledger can usually auto-detect whether the CSV's normal order is oldest first or newest first. But if all of the following are true: - o the CSV might sometimes contain just one day of data (all records+ o the CSV might sometimes contain just one day of data (all records having the same date) - o the CSV records are normally in reverse chronological order (newest+ o the CSV records are normally in reverse chronological order (newest at the top) o and you care about preserving the order of same-day transactions@@ -575,9 +593,9 @@ include include RULESFILE - This includes the contents of another CSV rules file at this point.- RULESFILE is an absolute file path or a path relative to the current- file's directory. This can be useful for sharing common rules between+ This includes the contents of another CSV rules file at this point.+ RULESFILE is an absolute file path or a path relative to the current+ file's directory. This can be useful for sharing common rules between several rules files, eg: # someaccount.csv.rules@@ -592,10 +610,10 @@ balance-type Balance assertions generated by assigning to balanceN are of the simple- = type by default, which is a single-commodity, subaccount-excluding+ = type by default, which is a single-commodity, subaccount-excluding assertion. You may find the subaccount-including variants more useful,- eg if you have created some virtual subaccounts of checking to help- with budgeting. You can select a different type of assertion with the+ eg if you have created some virtual subaccounts of checking to help+ with budgeting. You can select a different type of assertion with the balance-type rule: # balance assertions will consider all commodities and all subaccounts@@ -610,19 +628,19 @@ TIPS Rapid feedback- It's a good idea to get rapid feedback while creating/troubleshooting+ It's a good idea to get rapid feedback while creating/troubleshooting CSV rules. Here's a good way, using entr from http://eradman.com/entr- project : $ ls foo.csv* | entr bash -c 'echo ----; hledger -f foo.csv print desc:SOMEDESC' - A desc: query (eg) is used to select just one, or a few, transactions- of interest. "bash -c" is used to run multiple commands, so we can- echo a separator each time the command re-runs, making it easier to+ A desc: query (eg) is used to select just one, or a few, transactions+ of interest. "bash -c" is used to run multiple commands, so we can+ echo a separator each time the command re-runs, making it easier to read the output. Valid CSV- hledger accepts CSV conforming to RFC 4180. When CSV values are en-+ hledger accepts CSV conforming to RFC 4180. When CSV values are en- closed in quotes, note: o they must be double quotes (not single quotes)@@ -630,9 +648,9 @@ o spaces outside the quotes are not allowed File Extension- CSV ("Character Separated Values") files should be named with one of- these filename extensions: .csv, .ssv, .tsv. Or, the file path should- be prefixed with one of csv:, ssv:, tsv:. This helps hledger identify+ CSV ("Character Separated Values") files should be named with one of+ these filename extensions: .csv, .ssv, .tsv. Or, the file path should+ be prefixed with one of csv:, ssv:, tsv:. This helps hledger identify the format and show the right error messages. For example: $ hledger -f foo.ssv print@@ -644,44 +662,44 @@ More about this: Input files in the hledger manual. Reading multiple CSV files- If you use multiple -f options to read multiple CSV files at once,- hledger will look for a correspondingly-named rules file for each CSV- file. But if you use the --rules-file option, that rules file will be+ If you use multiple -f options to read multiple CSV files at once,+ hledger will look for a correspondingly-named rules file for each CSV+ file. But if you use the --rules-file option, that rules file will be used for all the CSV files. Valid transactions After reading a CSV file, hledger post-processes and validates the gen- erated journal entries as it would for a journal file - balancing them,- applying balance assignments, and canonicalising amount styles. Any- errors at this stage will be reported in the usual way, displaying the+ applying balance assignments, and canonicalising amount styles. Any+ errors at this stage will be reported in the usual way, displaying the problem entry. There is one exception: balance assertions, if you have generated them,- will not be checked, since normally these will work only when the CSV- data is part of the main journal. If you do need to check balance as-+ will not be checked, since normally these will work only when the CSV+ data is part of the main journal. If you do need to check balance as- sertions generated from CSV right away, pipe into another hledger: $ hledger -f file.csv print | hledger -f- print Deduplicating, importing- When you download a CSV file periodically, eg to get your latest bank- transactions, the new file may overlap with the old one, containing+ When you download a CSV file periodically, eg to get your latest bank+ transactions, the new file may overlap with the old one, containing some of the same records. The import command will (a) detect the new transactions, and (b) append just those transactions to your main journal. It is idempotent, so you- don't have to remember how many times you ran it or with which version- of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This+ don't have to remember how many times you ran it or with which version+ of the CSV. (It keeps state in a hidden .latest.FILE.csv file.) This is the easiest way to import CSV data. Eg: # download the latest CSV files, then run this command. # Note, no -f flags needed here. $ hledger import *.csv [--dry] - This method works for most CSV files. (Where records have a stable+ This method works for most CSV files. (Where records have a stable chronological order, and new records appear only at the new end.) - A number of other tools and workflows, hledger-specific and otherwise,+ A number of other tools and workflows, hledger-specific and otherwise, exist for converting, deduplicating, classifying and managing CSV data. See: @@ -692,43 +710,43 @@ Setting amounts A posting amount can be set in one of these ways: - o by assigning (with a fields list or field assigment) to amountN+ o by assigning (with a fields list or field assigment) to amountN (posting N's amount) or amount (posting 1's amount) - o by assigning to amountN-in and amountN-out (or amount-in and amount-- out). For each CSV record, whichever of these has a non-zero value- will be used, with appropriate sign. If both contain a non-zero+ o by assigning to amountN-in and amountN-out (or amount-in and amount-+ out). For each CSV record, whichever of these has a non-zero value+ will be used, with appropriate sign. If both contain a non-zero value, this may not work. - o by assigning to balanceN (or balance) instead of the above, setting- the amount indirectly via a balance assignment. If you do this the+ o by assigning to balanceN (or balance) instead of the above, setting+ the amount indirectly via a balance assignment. If you do this the default account name may be wrong, so you should set that explicitly. There is some special handling for an amount's sign: - o If an amount value is parenthesised, it will be de-parenthesised and+ o If an amount value is parenthesised, it will be de-parenthesised and sign-flipped. - o If an amount value begins with a double minus sign, those cancel out+ o If an amount value begins with a double minus sign, those cancel out and are removed. o If an amount value begins with a plus sign, that will be removed Setting currency/commodity- If the currency/commodity symbol is included in the CSV's amount+ If the currency/commodity symbol is included in the CSV's amount field(s), you don't have to do anything special. If the currency is provided as a separate CSV field, you can either: - o assign that to currency, which adds it to all posting amounts. The- symbol will prepended to the amount quantity (on the left side). If- you write a trailing space after the symbol, there will be a space- between symbol and amount (an exception to the usual whitespace+ o assign that to currency, which adds it to all posting amounts. The+ symbol will prepended to the amount quantity (on the left side). If+ you write a trailing space after the symbol, there will be a space+ between symbol and amount (an exception to the usual whitespace stripping). o or assign it to currencyN which adds it to posting N's amount only. - o or for more control, construct the amount from symbol and quantity+ o or for more control, construct the amount from symbol and quantity using field assignment, eg: fields date,description,currency,quantity@@ -736,9 +754,9 @@ amount %quantity %currency Referencing other fields- In field assignments, you can interpolate only CSV fields, not hledger- fields. In the example below, there's both a CSV field and a hledger- field named amount1, but %amount1 always means the CSV field, not the+ In field assignments, you can interpolate only CSV fields, not hledger+ fields. In the example below, there's both a CSV field and a hledger+ field named amount1, but %amount1 always means the CSV field, not the hledger field: # Name the third CSV field "amount1"@@ -750,7 +768,7 @@ # Set comment to the CSV amount1 (not the amount1 assigned above) comment %amount1 - Here, since there's no CSV amount1 field, %amount1 will produce a lit-+ Here, since there's no CSV amount1 field, %amount1 will produce a lit- eral "amount1": fields date,description,csvamount@@ -758,7 +776,7 @@ # Can't interpolate amount1 here comment %amount1 - When there are multiple field assignments to the same hledger field,+ When there are multiple field assignments to the same hledger field, only the last one takes effect. Here, comment's value will be be B, or C if "something" is matched, but never A: @@ -768,14 +786,14 @@ comment C How CSV rules are evaluated- Here's how to think of CSV rules being evaluated (if you really need+ Here's how to think of CSV rules being evaluated (if you really need to). First, - o include - all includes are inlined, from top to bottom, depth first.- (At each include point the file is inlined and scanned for further+ o include - all includes are inlined, from top to bottom, depth first.+ (At each include point the file is inlined and scanned for further includes, recursively, before proceeding.) - Then "global" rules are evaluated, top to bottom. If a rule is re-+ Then "global" rules are evaluated, top to bottom. If a rule is re- peated, the last one wins: o skip (at top level)@@ -789,30 +807,30 @@ Then for each CSV record in turn: - o test all if blocks. If any of them contain a end rule, skip all re-- maining CSV records. Otherwise if any of them contain a skip rule,- skip that many CSV records. If there are multiple matched skip+ o test all if blocks. If any of them contain a end rule, skip all re-+ maining CSV records. Otherwise if any of them contain a skip rule,+ skip that many CSV records. If there are multiple matched skip rules, the first one wins. - o collect all field assignments at top level and in matched if blocks.- When there are multiple assignments for a field, keep only the last+ o collect all field assignments at top level and in matched if blocks.+ When there are multiple assignments for a field, keep only the last one. - o compute a value for each hledger field - either the one that was as-+ o compute a value for each hledger field - either the one that was as- signed to it (and interpolate the %CSVFIELDNAME references), or a de- fault o generate a synthetic hledger transaction from these values. - This is all part of the CSV reader, one of several readers hledger can- use to parse input files. When all files have been read successfully,- the transactions are passed as input to whichever hledger command the+ This is all part of the CSV reader, one of several readers hledger can+ use to parse input files. When all files have been read successfully,+ the transactions are passed as input to whichever hledger command the user specified. REPORTING BUGS- Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel+ Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel or hledger mail list) @@ -826,7 +844,7 @@ SEE ALSO- hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1),+ hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1), hledger_csv(5), hledger_journal(5), hledger_timeclock(5), hledger_time- dot(5), ledger(1) @@ -834,4 +852,4 @@ -hledger 1.17.1 March 2020 hledger_csv(5)+hledger 1.18 June 2020 hledger_csv(5)
hledger_journal.5 view
@@ -1,6 +1,6 @@ .\"t -.TH "hledger_journal" "5" "March 2020" "hledger 1.17.1" "hledger User Manuals"+.TH "hledger_journal" "5" "June 2020" "hledger 1.18" "hledger User Manuals" @@ -63,7 +63,8 @@ and any following indented lines beginning with a semicolon) .IP \[bu] 2 0 or more indented \f[I]posting\f[R] lines, describing what was-transferred and the accounts involved.+transferred and the accounts involved (indented comment lines are also+allowed, but not blank lines or non-indented lines). .PP Here\[aq]s a simple journal file containing one transaction: .IP@@ -409,7 +410,7 @@ This makes it easy to write account names containing spaces. But if you accidentally leave only one space (or tab) before the amount, the amount will be considered part of the account name.-.SS Virtual Postings+.SS Virtual postings .PP A posting with a parenthesised account name is called a \f[I]virtual posting\f[R] or \f[I]unbalanced posting\f[R], which means it is exempt@@ -504,9 +505,9 @@ \f[R] .fi .PP-Amounts can be negative.-The minus sign can be written before or after a left-side commodity-symbol:+Amounts can be preceded by a minus sign (or a plus sign, though plus is+the default), The sign can be written before or after a left-side+commodity symbol: .IP .nf \f[C]@@ -515,6 +516,16 @@ \f[R] .fi .PP+One or more spaces between the sign and the number are acceptable when+parsing (but they won\[aq]t be displayed in output):+.IP+.nf+\f[C]++ $1+$- 1+\f[R]+.fi+.PP Scientific E notation is allowed: .IP .nf@@ -586,7 +597,7 @@ Otherwise the format of the first posting amount in that commodity seen in the journal is used. But the number of decimal places (\[dq]precision\[dq]) will be the-maximum from all posting amounts in that commmodity.+maximum from all posting amounts in that commodity. .IP \[bu] 2 Or if there are no such amounts in the journal, a default format is used (like \f[C]$1000.00\f[R]).@@ -601,6 +612,12 @@ journal, with the max observed number of decimal places. If you want to see fewer decimal places in reports, use a commodity directive to override that.+.PP+hledger uses banker\[aq]s rounding: it rounds to the nearest even+number, eg 0.5 displayed with zero decimal places is \[dq]0\[dq]).+(Note, prior to hledger 1.17.1 this could vary if hledger happened to be+built with an old version of Decimal (<0.5.1); since 1.17.1 it\[aq]s+guaranteed.) .SS Transaction prices .PP Within a transaction, you can note an amount\[aq]s price in another@@ -653,9 +670,10 @@ \f[R] .fi .RE-.PP-(Ledger users: Ledger uses a different syntax for fixed prices,-\f[C]{=UNITPRICE}\f[R], which hledger currently ignores).+.IP "5." 3+Like 1 and 2, but the \f[C]\[at]\f[R] or \f[C]\[at]\[at]\f[R] is+parenthesised; this is for compatibility with Ledger journals (Virtual+posting costs), and in hledger is equivalent to 1 and 2. .PP Use the \f[C]-B/--cost\f[R] flag to convert amounts to their transaction price\[aq]s commodity, if any.@@ -694,8 +712,19 @@ \[Eu]100 assets:euros \f[R] .fi-.SS Balance Assertions+.SS Lot prices and lot dates .PP+Ledger allows another kind of price, lot price (four variants:+\f[C]{UNITPRICE}\f[R], \f[C]{{TOTALPRICE}}\f[R],+\f[C]{=FIXEDUNITPRICE}\f[R], \f[C]{{=FIXEDTOTALPRICE}}\f[R]), and/or a+lot date (\f[C][DATE]\f[R]) to be specified.+These are normally used to select a lot when selling investments.+hledger will parse these, for compatibility with Ledger journals, but+currently ignores them.+A transaction price, lot price and/or lot date may appear in any order,+after the posting amount and before the balance assertion if any.+.SS Balance assertions+.PP hledger supports Ledger-style balance assertions in journal files. These look like, for example, \f[C]= EXPECTEDBALANCE\f[R] following a posting\[aq]s amount.@@ -850,7 +879,7 @@ Eg a commodity directive may limit the display precision, but this will not affect balance assertions. Balance assertion failure messages show exact amounts.-.SS Balance Assignments+.SS Balance assignments .PP Ledger-style balance assignments are also supported. These are like balance assertions, but with no posting amount on the@@ -1104,17 +1133,25 @@ .IP .nf \f[C]-include path/to/file.journal+include FILEPATH \f[R] .fi .PP-If the path does not begin with a slash, it is relative to the current-file.-The include file path may contain common glob patterns (e.g.-\f[C]*\f[R]).+Only journal files can include, and only journal, timeclock or timedot+files can be included (not CSV files, currently). .PP-The \f[C]include\f[R] directive can only be used in journal files.-It can include journal, timeclock or timedot files, but not CSV files.+If the file path does not begin with a slash, it is relative to the+current file\[aq]s folder.+.PP+It may contain glob patterns to match multiple files, eg:+\f[C]include *.journal\f[R].+.PP+Or a tilde, meaning home directory:+\f[C]include \[ti]/main.journal\f[R].+.PP+It may also be prefixed to force a specific file format, overriding the+file extension (as described in hledger.1 -> Input files):+\f[C]include timedot:\[ti]/notes/2020*.md\f[R]. .SS Default year .PP You can set a default year to be used for subsequent dates which@@ -1197,6 +1234,10 @@ significant. The number must include a decimal mark: either a period or a comma, followed by 0 or more decimal digits.+.PP+Note hledger normally uses banker\[aq]s rounding, so 0.5 displayed with+zero decimal digits is \[dq]0\[dq].+(More at Amount display style.) .SS Default commodity .PP The \f[C]D\f[R] directive sets a default commodity, to be used for@@ -1227,7 +1268,7 @@ b \f[R] .fi-.SS Market prices+.SS Declaring market prices .PP The \f[C]P\f[R] directive declares a market price, which is an exchange rate between two commodities on a certain date.@@ -1260,8 +1301,9 @@ \f[R] .fi .PP-The \f[C]-V/--value\f[R] flag can be used to convert reported amounts to-another commodity using these prices.+The \f[C]-V\f[R], \f[C]-X\f[R] and \f[C]--value\f[R] flags use these+market prices to show amount values in another commodity.+See Valuation. .SS Declaring accounts .PP \f[C]account\f[R] directives can be used to pre-declare accounts.@@ -1755,25 +1797,25 @@ expression. .SS Forecasting with periodic transactions .PP-With the \f[C]--forecast\f[R] flag, each periodic transaction rule-generates future transactions recurring at the specified interval.-These are not saved in the journal, but appear in all reports.-They will look like normal transactions, but with an extra tag:-.IP \[bu] 2-\f[C]generated-transaction:\[ti] PERIODICEXPR\f[R] - shows that this was-generated by a periodic transaction rule, and the period-.PP-There is also a hidden tag, with an underscore prefix, which does not-appear in hledger\[aq]s output:-.IP \[bu] 2-\f[C]_generated-transaction:\[ti] PERIODICEXPR\f[R]+The \f[C]--forecast\f[R] flag activates any periodic transaction rules+in the journal.+They will generate temporary recurring transactions, which are not saved+in the journal, but will appear in all reports (eg print).+This can be useful for estimating balances into the future, or+experimenting with different scenarios.+Or, it can be used as a data entry aid: describe recurring transactions,+and every so often copy the output of \f[C]print --forecast\f[R] into+the journal. .PP-This can be used to match transactions generated \[dq]just now\[dq],-rather than generated in the past and saved to the journal.+These transactions will have an extra tag indicating which periodic rule+generated them: \f[C]generated-transaction:\[ti] PERIODICEXPR\f[R].+And a similar, hidden tag (beginning with an underscore) which, because+it\[aq]s never displayed by print, can be used to match transactions+generated \[dq]just now\[dq]:+\f[C]_generated-transaction:\[ti] PERIODICEXPR\f[R]. .PP-Forecast transactions start on the first occurrence, and end on the last-occurrence, of their interval within the forecast period.-The forecast period:+Periodic transactions are generated within some forecast period.+By default, this .IP \[bu] 2 begins on the later of .RS 2@@ -1784,27 +1826,26 @@ journal, or today if there are no normal transactions. .RE .IP \[bu] 2-ends on the report end date if specified with -e/-p/date:, or 180 days-from today.-.PP-where \[dq]today\[dq] means the current date at report time.-The \[dq]later of\[dq] rule ensures that forecast transactions do not-overlap normal transactions in time; they will begin only after normal-transactions end.-.PP-Forecasting can be useful for estimating balances into the future, and-experimenting with different scenarios.-Note the start date logic means that forecasted transactions are-automatically replaced by normal transactions as you add those.+ends on the report end date if specified with -e/-p/date:, or 6 months+(180 days) from today. .PP-Forecasting can also help with data entry: describe most of your-transactions with periodic rules, and every so often copy the output of-\f[C]print --forecast\f[R] to the journal.+This means that periodic transactions will begin only after the latest+recorded transaction.+And a recorded transaction dated in the future can prevent generation of+periodic transactions.+(You can avoid that by writing the future transaction as a one-time+periodic rule instead - put tilde before the date, eg+\f[C]\[ti] YYYY-MM-DD ...\f[R]). .PP-You can generate one-time transactions too: just write a period-expression specifying a date with no report interval.-(You could also write a normal transaction with a future date, but-remember this disables forecast transactions on previous dates.)+Or, you can set your own arbitrary \[dq]forecast period\[dq], which can+overlap recorded transactions, and need not be in the future, by+providing an option argument, like \f[C]--forecast=PERIODEXPR\f[R].+Note the equals sign is required, a space won\[aq]t work.+PERIODEXPR is a period expression, which can specify the start date, end+date, or both, like in a \f[C]date:\f[R] query.+(See also hledger.1 -> Report start & end date).+Some examples: \f[C]--forecast=202001-202004\f[R],+\f[C]--forecast=jan-\f[R], \f[C]--forecast=2020\f[R]. .SS Budgeting with periodic transactions .PP With the \f[C]--budget\f[R] flag, currently supported by the balance
hledger_journal.info view
@@ -4,8 +4,8 @@ File: hledger_journal.info, Node: Top, Up: (dir) -hledger_journal(5) hledger 1.17.1-*********************************+hledger_journal(5) hledger 1.18+******************************* Journal - hledger's default file format, representing a General Journal @@ -62,7 +62,8 @@ * a comment (any remaining text following a semicolon until end of line, and any following indented lines beginning with a semicolon) * 0 or more indented _posting_ lines, describing what was transferred- and the accounts involved.+ and the accounts involved (indented comment lines are also allowed,+ but not blank lines or non-indented lines). Here's a simple journal file containing one transaction: @@ -81,8 +82,9 @@ * Account names:: * Amounts:: * Transaction prices::-* Balance Assertions::-* Balance Assignments::+* Lot prices and lot dates::+* Balance assertions::+* Balance assignments:: * Directives:: * Periodic transactions:: * Auto postings::@@ -377,12 +379,12 @@ * Menu: -* Virtual Postings::+* Virtual postings:: -File: hledger_journal.info, Node: Virtual Postings, Up: Postings+File: hledger_journal.info, Node: Virtual postings, Up: Postings -1.6.1 Virtual Postings+1.6.1 Virtual postings ---------------------- A posting with a parenthesised account name is called a _virtual@@ -459,12 +461,19 @@ 3 "no. 42 green apples" - Amounts can be negative. The minus sign can be written before or-after a left-side commodity symbol:+ Amounts can be preceded by a minus sign (or a plus sign, though plus+is the default), The sign can be written before or after a left-side+commodity symbol: -$1 $-1 + One or more spaces between the sign and the number are acceptable+when parsing (but they won't be displayed in output):+++ $1+$- 1+ Scientific E notation is allowed: 1E-6@@ -529,7 +538,7 @@ * Otherwise the format of the first posting amount in that commodity seen in the journal is used. But the number of decimal places ("precision") will be the maximum from all posting amounts in that- commmodity.+ commodity. * Or if there are no such amounts in the journal, a default format is used (like '$1000.00').@@ -544,8 +553,13 @@ see fewer decimal places in reports, use a commodity directive to override that. + hledger uses banker's rounding: it rounds to the nearest even number,+eg 0.5 displayed with zero decimal places is "0"). (Note, prior to+hledger 1.17.1 this could vary if hledger happened to be built with an+old version of Decimal (<0.5.1); since 1.17.1 it's guaranteed.)+ -File: hledger_journal.info, Node: Transaction prices, Next: Balance Assertions, Prev: Amounts, Up: Transactions+File: hledger_journal.info, Node: Transaction prices, Next: Lot prices and lot dates, Prev: Amounts, Up: Transactions 1.9 Transaction prices ======================@@ -579,8 +593,9 @@ assets:euros €100 ; one hundred euros purchased assets:dollars $-135 ; for $135 - (Ledger users: Ledger uses a different syntax for fixed prices,-'{=UNITPRICE}', which hledger currently ignores).+ 4. 5. Like 1 and 2, but the '@' or '@@' is parenthesised; this is for+ compatibility with Ledger journals (Virtual posting costs), and in+ hledger is equivalent to 1 and 2. Use the '-B/--cost' flag to convert amounts to their transaction price's commodity, if any. (mnemonic: "B" is from "cost Basis", as in@@ -608,9 +623,24 @@ €100 assets:euros -File: hledger_journal.info, Node: Balance Assertions, Next: Balance Assignments, Prev: Transaction prices, Up: Transactions+File: hledger_journal.info, Node: Lot prices and lot dates, Next: Balance assertions, Prev: Transaction prices, Up: Transactions -1.10 Balance Assertions+1.10 Lot prices and lot dates+=============================++Ledger allows another kind of price, lot price (four variants:+'{UNITPRICE}', '{{TOTALPRICE}}', '{=FIXEDUNITPRICE}',+'{{=FIXEDTOTALPRICE}}'), and/or a lot date ('[DATE]') to be specified.+These are normally used to select a lot when selling investments.+hledger will parse these, for compatibility with Ledger journals, but+currently ignores them. A transaction price, lot price and/or lot date+may appear in any order, after the posting amount and before the balance+assertion if any.+++File: hledger_journal.info, Node: Balance assertions, Next: Balance assignments, Prev: Lot prices and lot dates, Up: Transactions++1.11 Balance assertions ======================= hledger supports Ledger-style balance assertions in journal files.@@ -646,9 +676,9 @@ * Assertions and precision:: -File: hledger_journal.info, Node: Assertions and ordering, Next: Assertions and included files, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and ordering, Next: Assertions and included files, Up: Balance assertions -1.10.1 Assertions and ordering+1.11.1 Assertions and ordering ------------------------------ hledger sorts an account's postings and assertions first by date and@@ -665,9 +695,9 @@ can assert intra-day balances. -File: hledger_journal.info, Node: Assertions and included files, Next: Assertions and multiple -f options, Prev: Assertions and ordering, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and included files, Next: Assertions and multiple -f options, Prev: Assertions and ordering, Up: Balance assertions -1.10.2 Assertions and included files+1.11.2 Assertions and included files ------------------------------------ With included files, things are a little more complicated. Including@@ -677,18 +707,18 @@ you'll have to put the assertion in the right file. -File: hledger_journal.info, Node: Assertions and multiple -f options, Next: Assertions and commodities, Prev: Assertions and included files, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and multiple -f options, Next: Assertions and commodities, Prev: Assertions and included files, Up: Balance assertions -1.10.3 Assertions and multiple -f options+1.11.3 Assertions and multiple -f options ----------------------------------------- Balance assertions don't work well across files specified with multiple -f options. Use include or concatenate the files instead. -File: hledger_journal.info, Node: Assertions and commodities, Next: Assertions and prices, Prev: Assertions and multiple -f options, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and commodities, Next: Assertions and prices, Prev: Assertions and multiple -f options, Up: Balance assertions -1.10.4 Assertions and commodities+1.11.4 Assertions and commodities --------------------------------- The asserted balance must be a simple single-commodity amount, and in@@ -734,9 +764,9 @@ a:euro 0 == 1€ -File: hledger_journal.info, Node: Assertions and prices, Next: Assertions and subaccounts, Prev: Assertions and commodities, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and prices, Next: Assertions and subaccounts, Prev: Assertions and commodities, Up: Balance assertions -1.10.5 Assertions and prices+1.11.5 Assertions and prices ---------------------------- Balance assertions ignore transaction prices, and should normally be@@ -752,9 +782,9 @@ _assignments_ do use them (see below). -File: hledger_journal.info, Node: Assertions and subaccounts, Next: Assertions and virtual postings, Prev: Assertions and prices, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and subaccounts, Next: Assertions and virtual postings, Prev: Assertions and prices, Up: Balance assertions -1.10.6 Assertions and subaccounts+1.11.6 Assertions and subaccounts --------------------------------- The balance assertions above ('=' and '==') do not count the balance@@ -769,9 +799,9 @@ checking 1 ==* 11 -File: hledger_journal.info, Node: Assertions and virtual postings, Next: Assertions and precision, Prev: Assertions and subaccounts, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and virtual postings, Next: Assertions and precision, Prev: Assertions and subaccounts, Up: Balance assertions -1.10.7 Assertions and virtual postings+1.11.7 Assertions and virtual postings -------------------------------------- Balance assertions are checked against all postings, both real and@@ -779,9 +809,9 @@ query. -File: hledger_journal.info, Node: Assertions and precision, Prev: Assertions and virtual postings, Up: Balance Assertions+File: hledger_journal.info, Node: Assertions and precision, Prev: Assertions and virtual postings, Up: Balance assertions -1.10.8 Assertions and precision+1.11.8 Assertions and precision ------------------------------- Balance assertions compare the exactly calculated amounts, which are not@@ -790,9 +820,9 @@ assertion failure messages show exact amounts. -File: hledger_journal.info, Node: Balance Assignments, Next: Directives, Prev: Balance Assertions, Up: Transactions+File: hledger_journal.info, Node: Balance assignments, Next: Directives, Prev: Balance assertions, Up: Transactions -1.11 Balance Assignments+1.12 Balance assignments ======================== Ledger-style balance assignments are also supported. These are like@@ -827,9 +857,9 @@ * Balance assignments and prices:: -File: hledger_journal.info, Node: Balance assignments and prices, Up: Balance Assignments+File: hledger_journal.info, Node: Balance assignments and prices, Up: Balance assignments -1.11.1 Balance assignments and prices+1.12.1 Balance assignments and prices ------------------------------------- A transaction price in a balance assignment will cause the calculated@@ -843,9 +873,9 @@ (a) $1 @ €2 = $1 @ €2 -File: hledger_journal.info, Node: Directives, Next: Periodic transactions, Prev: Balance Assignments, Up: Transactions+File: hledger_journal.info, Node: Directives, Next: Periodic transactions, Prev: Balance assignments, Up: Transactions -1.12 Directives+1.13 Directives =============== A directive is a line in the journal beginning with a special keyword,@@ -941,7 +971,7 @@ * Default year:: * Declaring commodities:: * Default commodity::-* Market prices::+* Declaring market prices:: * Declaring accounts:: * Rewriting accounts:: * Default parent account::@@ -949,7 +979,7 @@ File: hledger_journal.info, Node: Directives and multiple files, Next: Comment blocks, Up: Directives -1.12.1 Directives and multiple files+1.13.1 Directives and multiple files ------------------------------------ If you use multiple '-f'/'--file' options, or the 'include' directive,@@ -969,7 +999,7 @@ File: hledger_journal.info, Node: Comment blocks, Next: Including other files, Prev: Directives and multiple files, Up: Directives -1.12.2 Comment blocks+1.13.2 Comment blocks --------------------- A line containing just 'comment' starts a commented region of the file,@@ -979,25 +1009,33 @@ File: hledger_journal.info, Node: Including other files, Next: Default year, Prev: Comment blocks, Up: Directives -1.12.3 Including other files+1.13.3 Including other files ---------------------------- You can pull in the content of additional files by writing an include directive, like this: -include path/to/file.journal+include FILEPATH - If the path does not begin with a slash, it is relative to the-current file. The include file path may contain common glob patterns-(e.g. '*').+ Only journal files can include, and only journal, timeclock or+timedot files can be included (not CSV files, currently). - The 'include' directive can only be used in journal files. It can-include journal, timeclock or timedot files, but not CSV files.+ If the file path does not begin with a slash, it is relative to the+current file's folder. + It may contain glob patterns to match multiple files, eg: 'include+*.journal'.++ Or a tilde, meaning home directory: 'include ~/main.journal'.++ It may also be prefixed to force a specific file format, overriding+the file extension (as described in hledger.1 -> Input files): 'include+timedot:~/notes/2020*.md'.+ File: hledger_journal.info, Node: Default year, Next: Declaring commodities, Prev: Including other files, Up: Directives -1.12.4 Default year+1.13.4 Default year ------------------- You can set a default year to be used for subsequent dates which don't@@ -1023,7 +1061,7 @@ File: hledger_journal.info, Node: Declaring commodities, Next: Default commodity, Prev: Default year, Up: Directives -1.12.5 Declaring commodities+1.13.5 Declaring commodities ---------------------------- The 'commodity' directive has several functions:@@ -1070,10 +1108,13 @@ significant. The number must include a decimal mark: either a period or a comma, followed by 0 or more decimal digits. + Note hledger normally uses banker's rounding, so 0.5 displayed with+zero decimal digits is "0". (More at Amount display style.)+ -File: hledger_journal.info, Node: Default commodity, Next: Market prices, Prev: Declaring commodities, Up: Directives+File: hledger_journal.info, Node: Default commodity, Next: Declaring market prices, Prev: Declaring commodities, Up: Directives -1.12.6 Default commodity+1.13.6 Default commodity ------------------------ The 'D' directive sets a default commodity, to be used for amounts@@ -1098,10 +1139,10 @@ b -File: hledger_journal.info, Node: Market prices, Next: Declaring accounts, Prev: Default commodity, Up: Directives+File: hledger_journal.info, Node: Declaring market prices, Next: Declaring accounts, Prev: Default commodity, Up: Directives -1.12.7 Market prices---------------------+1.13.7 Declaring market prices+------------------------------ The 'P' directive declares a market price, which is an exchange rate between two commodities on a certain date. (In Ledger, they are called@@ -1124,13 +1165,13 @@ P 2009/1/1 € $1.35 P 2010/1/1 € $1.40 - The '-V/--value' flag can be used to convert reported amounts to-another commodity using these prices.+ The '-V', '-X' and '--value' flags use these market prices to show+amount values in another commodity. See Valuation. -File: hledger_journal.info, Node: Declaring accounts, Next: Rewriting accounts, Prev: Market prices, Up: Directives+File: hledger_journal.info, Node: Declaring accounts, Next: Rewriting accounts, Prev: Declaring market prices, Up: Directives -1.12.8 Declaring accounts+1.13.8 Declaring accounts ------------------------- 'account' directives can be used to pre-declare accounts. Though not@@ -1163,7 +1204,7 @@ File: hledger_journal.info, Node: Account comments, Next: Account subdirectives, Up: Declaring accounts -1.12.8.1 Account comments+1.13.8.1 Account comments ......................... Comments, beginning with a semicolon, can be added:@@ -1183,7 +1224,7 @@ File: hledger_journal.info, Node: Account subdirectives, Next: Account types, Prev: Account comments, Up: Declaring accounts -1.12.8.2 Account subdirectives+1.13.8.2 Account subdirectives .............................. We also allow (and ignore) Ledger-style indented subdirectives, just for@@ -1201,7 +1242,7 @@ File: hledger_journal.info, Node: Account types, Next: Account display order, Prev: Account subdirectives, Up: Declaring accounts -1.12.8.3 Account types+1.13.8.3 Account types ...................... hledger recognises five types (or classes) of account: Asset, Liability,@@ -1246,7 +1287,7 @@ File: hledger_journal.info, Node: Account display order, Prev: Account types, Up: Declaring accounts -1.12.8.4 Account display order+1.13.8.4 Account display order .............................. Account directives also set the order in which accounts are displayed,@@ -1292,7 +1333,7 @@ File: hledger_journal.info, Node: Rewriting accounts, Next: Default parent account, Prev: Declaring accounts, Up: Directives -1.12.9 Rewriting accounts+1.13.9 Rewriting accounts ------------------------- You can define account alias rules which rewrite your account names, or@@ -1322,7 +1363,7 @@ File: hledger_journal.info, Node: Basic aliases, Next: Regex aliases, Up: Rewriting accounts -1.12.9.1 Basic aliases+1.13.9.1 Basic aliases ...................... To set an account alias, use the 'alias' directive in your journal file.@@ -1345,7 +1386,7 @@ File: hledger_journal.info, Node: Regex aliases, Next: Combining aliases, Prev: Basic aliases, Up: Rewriting accounts -1.12.9.2 Regex aliases+1.13.9.2 Regex aliases ...................... There is also a more powerful variant that uses a regular expression,@@ -1370,7 +1411,7 @@ File: hledger_journal.info, Node: Combining aliases, Next: Aliases and multiple files, Prev: Regex aliases, Up: Rewriting accounts -1.12.9.3 Combining aliases+1.13.9.3 Combining aliases .......................... You can define as many aliases as you like, using journal directives@@ -1407,7 +1448,7 @@ File: hledger_journal.info, Node: Aliases and multiple files, Next: end aliases, Prev: Combining aliases, Up: Rewriting accounts -1.12.9.4 Aliases and multiple files+1.13.9.4 Aliases and multiple files ................................... As explained at Directives and multiple files, 'alias' directives do not@@ -1439,7 +1480,7 @@ File: hledger_journal.info, Node: end aliases, Prev: Aliases and multiple files, Up: Rewriting accounts -1.12.9.5 'end aliases'+1.13.9.5 'end aliases' ...................... You can clear (forget) all currently defined aliases with the 'end@@ -1450,7 +1491,7 @@ File: hledger_journal.info, Node: Default parent account, Prev: Rewriting accounts, Up: Directives -1.12.10 Default parent account+1.13.10 Default parent account ------------------------------ You can specify a parent account which will be prepended to all accounts@@ -1491,7 +1532,7 @@ File: hledger_journal.info, Node: Periodic transactions, Next: Auto postings, Prev: Directives, Up: Transactions -1.13 Periodic transactions+1.14 Periodic transactions ========================== Periodic transaction rules describe transactions that recur. They allow@@ -1536,7 +1577,7 @@ File: hledger_journal.info, Node: Periodic rule syntax, Next: Two spaces between period expression and description!, Up: Periodic transactions -1.13.1 Periodic rule syntax+1.14.1 Periodic rule syntax --------------------------- A periodic transaction rule looks like a normal journal entry, with the@@ -1559,7 +1600,7 @@ File: hledger_journal.info, Node: Two spaces between period expression and description!, Next: Forecasting with periodic transactions, Prev: Periodic rule syntax, Up: Periodic transactions -1.13.2 Two spaces between period expression and description!+1.14.2 Two spaces between period expression and description! ------------------------------------------------------------ If the period expression is followed by a transaction description, these@@ -1584,60 +1625,53 @@ File: hledger_journal.info, Node: Forecasting with periodic transactions, Next: Budgeting with periodic transactions, Prev: Two spaces between period expression and description!, Up: Periodic transactions -1.13.3 Forecasting with periodic transactions+1.14.3 Forecasting with periodic transactions --------------------------------------------- -With the '--forecast' flag, each periodic transaction rule generates-future transactions recurring at the specified interval. These are not-saved in the journal, but appear in all reports. They will look like-normal transactions, but with an extra tag:-- * 'generated-transaction:~ PERIODICEXPR' - shows that this was- generated by a periodic transaction rule, and the period-- There is also a hidden tag, with an underscore prefix, which does not-appear in hledger's output:-- * '_generated-transaction:~ PERIODICEXPR'+The '--forecast' flag activates any periodic transaction rules in the+journal. They will generate temporary recurring transactions, which are+not saved in the journal, but will appear in all reports (eg print).+This can be useful for estimating balances into the future, or+experimenting with different scenarios. Or, it can be used as a data+entry aid: describe recurring transactions, and every so often copy the+output of 'print --forecast' into the journal. - This can be used to match transactions generated "just now", rather-than generated in the past and saved to the journal.+ These transactions will have an extra tag indicating which periodic+rule generated them: 'generated-transaction:~ PERIODICEXPR'. And a+similar, hidden tag (beginning with an underscore) which, because it's+never displayed by print, can be used to match transactions generated+"just now": '_generated-transaction:~ PERIODICEXPR'. - Forecast transactions start on the first occurrence, and end on the-last occurrence, of their interval within the forecast period. The-forecast period:+ Periodic transactions are generated within some forecast period. By+default, this * begins on the later of * the report start date if specified with -b/-p/date: * the day after the latest normal (non-periodic) transaction in the journal, or today if there are no normal transactions. - * ends on the report end date if specified with -e/-p/date:, or 180- days from today.-- where "today" means the current date at report time. The "later of"-rule ensures that forecast transactions do not overlap normal-transactions in time; they will begin only after normal transactions-end.-- Forecasting can be useful for estimating balances into the future,-and experimenting with different scenarios. Note the start date logic-means that forecasted transactions are automatically replaced by normal-transactions as you add those.+ * ends on the report end date if specified with -e/-p/date:, or 6+ months (180 days) from today. - Forecasting can also help with data entry: describe most of your-transactions with periodic rules, and every so often copy the output of-'print --forecast' to the journal.+ This means that periodic transactions will begin only after the+latest recorded transaction. And a recorded transaction dated in the+future can prevent generation of periodic transactions. (You can avoid+that by writing the future transaction as a one-time periodic rule+instead - put tilde before the date, eg '~ YYYY-MM-DD ...'). - You can generate one-time transactions too: just write a period-expression specifying a date with no report interval. (You could also-write a normal transaction with a future date, but remember this-disables forecast transactions on previous dates.)+ Or, you can set your own arbitrary "forecast period", which can+overlap recorded transactions, and need not be in the future, by+providing an option argument, like '--forecast=PERIODEXPR'. Note the+equals sign is required, a space won't work. PERIODEXPR is a period+expression, which can specify the start date, end date, or both, like in+a 'date:' query. (See also hledger.1 -> Report start & end date). Some+examples: '--forecast=202001-202004', '--forecast=jan-',+'--forecast=2020'. File: hledger_journal.info, Node: Budgeting with periodic transactions, Prev: Forecasting with periodic transactions, Up: Periodic transactions -1.13.4 Budgeting with periodic transactions+1.14.4 Budgeting with periodic transactions ------------------------------------------- With the '--budget' flag, currently supported by the balance command,@@ -1653,7 +1687,7 @@ File: hledger_journal.info, Node: Auto postings, Prev: Periodic transactions, Up: Transactions -1.14 Auto postings+1.15 Auto postings ================== "Automated postings" or "auto postings" are extra postings which get@@ -1731,7 +1765,7 @@ File: hledger_journal.info, Node: Auto postings and multiple files, Next: Auto postings and dates, Up: Auto postings -1.14.1 Auto postings and multiple files+1.15.1 Auto postings and multiple files --------------------------------------- An auto posting rule can affect any transaction in the current file, or@@ -1741,7 +1775,7 @@ File: hledger_journal.info, Node: Auto postings and dates, Next: Auto postings and transaction balancing / inferred amounts / balance assertions, Prev: Auto postings and multiple files, Up: Auto postings -1.14.2 Auto postings and dates+1.15.2 Auto postings and dates ------------------------------ A posting date (or secondary date) in the matched posting, or (taking@@ -1751,7 +1785,7 @@ File: hledger_journal.info, Node: Auto postings and transaction balancing / inferred amounts / balance assertions, Next: Auto posting tags, Prev: Auto postings and dates, Up: Auto postings -1.14.3 Auto postings and transaction balancing / inferred amounts /+1.15.3 Auto postings and transaction balancing / inferred amounts / ------------------------------------------------------------------- balance assertions Currently, auto postings are added:@@ -1767,7 +1801,7 @@ File: hledger_journal.info, Node: Auto posting tags, Prev: Auto postings and transaction balancing / inferred amounts / balance assertions, Up: Auto postings -1.14.4 Auto posting tags+1.15.4 Auto posting tags ------------------------ Automated postings will have some extra tags:@@ -1789,122 +1823,124 @@ Tag Table: Node: Top76-Node: Transactions1873-Ref: #transactions1965-Node: Dates3130-Ref: #dates3229-Node: Simple dates3294-Ref: #simple-dates3420-Node: Secondary dates3929-Ref: #secondary-dates4083-Node: Posting dates5419-Ref: #posting-dates5548-Node: Status6920-Ref: #status7041-Node: Description8749-Ref: #description8883-Node: Payee and note9203-Ref: #payee-and-note9317-Node: Comments9652-Ref: #comments9778-Node: Tags10972-Ref: #tags11087-Node: Postings12480-Ref: #postings12608-Node: Virtual Postings13634-Ref: #virtual-postings13751-Node: Account names15056-Ref: #account-names15197-Node: Amounts15684-Ref: #amounts15823-Node: Digit group marks16737-Ref: #digit-group-marks16885-Node: Amount display style17823-Ref: #amount-display-style17977-Node: Transaction prices19138-Ref: #transaction-prices19304-Node: Balance Assertions21570-Ref: #balance-assertions21750-Node: Assertions and ordering22783-Ref: #assertions-and-ordering22971-Node: Assertions and included files23671-Ref: #assertions-and-included-files23914-Node: Assertions and multiple -f options24247-Ref: #assertions-and-multiple--f-options24503-Node: Assertions and commodities24635-Ref: #assertions-and-commodities24867-Node: Assertions and prices26024-Ref: #assertions-and-prices26238-Node: Assertions and subaccounts26678-Ref: #assertions-and-subaccounts26907-Node: Assertions and virtual postings27231-Ref: #assertions-and-virtual-postings27473-Node: Assertions and precision27615-Ref: #assertions-and-precision27808-Node: Balance Assignments28075-Ref: #balance-assignments28249-Node: Balance assignments and prices29413-Ref: #balance-assignments-and-prices29585-Node: Directives29809-Ref: #directives29968-Node: Directives and multiple files35649-Ref: #directives-and-multiple-files35832-Node: Comment blocks36496-Ref: #comment-blocks36679-Node: Including other files36855-Ref: #including-other-files37035-Node: Default year37443-Ref: #default-year37612-Node: Declaring commodities38019-Ref: #declaring-commodities38202-Node: Default commodity39875-Ref: #default-commodity40051-Node: Market prices40940-Ref: #market-prices41105-Node: Declaring accounts41946-Ref: #declaring-accounts42122-Node: Account comments43047-Ref: #account-comments43210-Node: Account subdirectives43634-Ref: #account-subdirectives43829-Node: Account types44142-Ref: #account-types44326-Node: Account display order45965-Ref: #account-display-order46135-Node: Rewriting accounts47286-Ref: #rewriting-accounts47471-Node: Basic aliases48228-Ref: #basic-aliases48374-Node: Regex aliases49078-Ref: #regex-aliases49250-Node: Combining aliases49968-Ref: #combining-aliases50161-Node: Aliases and multiple files51437-Ref: #aliases-and-multiple-files51646-Node: end aliases52225-Ref: #end-aliases52382-Node: Default parent account52483-Ref: #default-parent-account52651-Node: Periodic transactions53535-Ref: #periodic-transactions53710-Node: Periodic rule syntax55582-Ref: #periodic-rule-syntax55788-Node: Two spaces between period expression and description!56492-Ref: #two-spaces-between-period-expression-and-description56811-Node: Forecasting with periodic transactions57495-Ref: #forecasting-with-periodic-transactions57800-Node: Budgeting with periodic transactions59826-Ref: #budgeting-with-periodic-transactions60065-Node: Auto postings60514-Ref: #auto-postings60654-Node: Auto postings and multiple files62833-Ref: #auto-postings-and-multiple-files63037-Node: Auto postings and dates63246-Ref: #auto-postings-and-dates63520-Node: Auto postings and transaction balancing / inferred amounts / balance assertions63695-Ref: #auto-postings-and-transaction-balancing-inferred-amounts-balance-assertions64046-Node: Auto posting tags64388-Ref: #auto-posting-tags64603+Node: Transactions1869+Ref: #transactions1961+Node: Dates3245+Ref: #dates3344+Node: Simple dates3409+Ref: #simple-dates3535+Node: Secondary dates4044+Ref: #secondary-dates4198+Node: Posting dates5534+Ref: #posting-dates5663+Node: Status7035+Ref: #status7156+Node: Description8864+Ref: #description8998+Node: Payee and note9318+Ref: #payee-and-note9432+Node: Comments9767+Ref: #comments9893+Node: Tags11087+Ref: #tags11202+Node: Postings12595+Ref: #postings12723+Node: Virtual postings13749+Ref: #virtual-postings13866+Node: Account names15171+Ref: #account-names15312+Node: Amounts15799+Ref: #amounts15938+Node: Digit group marks17046+Ref: #digit-group-marks17194+Node: Amount display style18132+Ref: #amount-display-style18286+Node: Transaction prices19723+Ref: #transaction-prices19895+Node: Lot prices and lot dates22227+Ref: #lot-prices-and-lot-dates22424+Node: Balance assertions22912+Ref: #balance-assertions23098+Node: Assertions and ordering24131+Ref: #assertions-and-ordering24319+Node: Assertions and included files25019+Ref: #assertions-and-included-files25262+Node: Assertions and multiple -f options25595+Ref: #assertions-and-multiple--f-options25851+Node: Assertions and commodities25983+Ref: #assertions-and-commodities26215+Node: Assertions and prices27372+Ref: #assertions-and-prices27586+Node: Assertions and subaccounts28026+Ref: #assertions-and-subaccounts28255+Node: Assertions and virtual postings28579+Ref: #assertions-and-virtual-postings28821+Node: Assertions and precision28963+Ref: #assertions-and-precision29156+Node: Balance assignments29423+Ref: #balance-assignments29597+Node: Balance assignments and prices30761+Ref: #balance-assignments-and-prices30933+Node: Directives31157+Ref: #directives31316+Node: Directives and multiple files37007+Ref: #directives-and-multiple-files37190+Node: Comment blocks37854+Ref: #comment-blocks38037+Node: Including other files38213+Ref: #including-other-files38393+Node: Default year39044+Ref: #default-year39213+Node: Declaring commodities39620+Ref: #declaring-commodities39803+Node: Default commodity41609+Ref: #default-commodity41795+Node: Declaring market prices42684+Ref: #declaring-market-prices42879+Node: Declaring accounts43736+Ref: #declaring-accounts43922+Node: Account comments44847+Ref: #account-comments45010+Node: Account subdirectives45434+Ref: #account-subdirectives45629+Node: Account types45942+Ref: #account-types46126+Node: Account display order47765+Ref: #account-display-order47935+Node: Rewriting accounts49086+Ref: #rewriting-accounts49271+Node: Basic aliases50028+Ref: #basic-aliases50174+Node: Regex aliases50878+Ref: #regex-aliases51050+Node: Combining aliases51768+Ref: #combining-aliases51961+Node: Aliases and multiple files53237+Ref: #aliases-and-multiple-files53446+Node: end aliases54025+Ref: #end-aliases54182+Node: Default parent account54283+Ref: #default-parent-account54451+Node: Periodic transactions55335+Ref: #periodic-transactions55510+Node: Periodic rule syntax57382+Ref: #periodic-rule-syntax57588+Node: Two spaces between period expression and description!58292+Ref: #two-spaces-between-period-expression-and-description58611+Node: Forecasting with periodic transactions59295+Ref: #forecasting-with-periodic-transactions59600+Node: Budgeting with periodic transactions61655+Ref: #budgeting-with-periodic-transactions61894+Node: Auto postings62343+Ref: #auto-postings62483+Node: Auto postings and multiple files64662+Ref: #auto-postings-and-multiple-files64866+Node: Auto postings and dates65075+Ref: #auto-postings-and-dates65349+Node: Auto postings and transaction balancing / inferred amounts / balance assertions65524+Ref: #auto-postings-and-transaction-balancing-inferred-amounts-balance-assertions65875+Node: Auto posting tags66217+Ref: #auto-posting-tags66432 End Tag Table
hledger_journal.txt view
@@ -57,7 +57,8 @@ line, and any following indented lines beginning with a semicolon) o 0 or more indented posting lines, describing what was transferred and- the accounts involved.+ the accounts involved (indented comment lines are also allowed, but+ not blank lines or non-indented lines). Here's a simple journal file containing one transaction: @@ -67,35 +68,35 @@ Dates Simple dates- Dates in the journal file use simple dates format: YYYY-MM-DD or+ Dates in the journal file use simple dates format: YYYY-MM-DD or YYYY/MM/DD or YYYY.MM.DD, with leading zeros optional. The year may be- omitted, in which case it will be inferred from the context: the cur-- rent transaction, the default year set with a default year directive,- or the current date when the command is run. Some examples:+ omitted, in which case it will be inferred from the context: the cur-+ rent transaction, the default year set with a default year directive,+ or the current date when the command is run. Some examples: 2010-01-31, 2010/01/31, 2010.1.31, 1/31. - (The UI also accepts simple dates, as well as the more flexible smart+ (The UI also accepts simple dates, as well as the more flexible smart dates documented in the hledger manual.) Secondary dates- Real-life transactions sometimes involve more than one date - eg the+ Real-life transactions sometimes involve more than one date - eg the date you write a cheque, and the date it clears in your bank. When you- want to model this, for more accurate daily balances, you can specify+ want to model this, for more accurate daily balances, you can specify individual posting dates. - Or, you can use the older secondary date feature (Ledger calls it aux-- iliary date or effective date). Note: we support this for compatibil-- ity, but I usually recommend avoiding this feature; posting dates are+ Or, you can use the older secondary date feature (Ledger calls it aux-+ iliary date or effective date). Note: we support this for compatibil-+ ity, but I usually recommend avoiding this feature; posting dates are almost always clearer and simpler. A secondary date is written after the primary date, following an equals- sign. If the year is omitted, the primary date's year is assumed.- When running reports, the primary (left) date is used by default, but- with the --date2 flag (or --aux-date or --effective), the secondary+ sign. If the year is omitted, the primary date's year is assumed.+ When running reports, the primary (left) date is used by default, but+ with the --date2 flag (or --aux-date or --effective), the secondary (right) date will be used instead. - The meaning of secondary dates is up to you, but it's best to follow a- consistent rule. Eg "primary = the bank's clearing date, secondary =+ The meaning of secondary dates is up to you, but it's best to follow a+ consistent rule. Eg "primary = the bank's clearing date, secondary = date the transaction was initiated, if different", as shown here: 2010/2/23=2/19 movie ticket@@ -109,11 +110,11 @@ 2010-02-19 movie ticket assets:checking $-10 $-10 Posting dates- You can give individual postings a different date from their parent- transaction, by adding a posting comment containing a tag (see below)+ You can give individual postings a different date from their parent+ transaction, by adding a posting comment containing a tag (see below) like date:DATE. This is probably the best way to control posting dates- precisely. Eg in this example the expense should appear in May re-- ports, and the deduction from checking should be reported on 6/1 for+ precisely. Eg in this example the expense should appear in May re-+ ports, and the deduction from checking should be reported on 6/1 for easy bank reconciliation: 2015/5/30@@ -126,22 +127,22 @@ $ hledger -f t.j register checking 2015-06-01 assets:checking $-10 $-10 - DATE should be a simple date; if the year is not specified it will use- the year of the transaction's date. You can set the secondary date- similarly, with date2:DATE2. The date: or date2: tags must have a- valid simple date value if they are present, eg a date: tag with no+ DATE should be a simple date; if the year is not specified it will use+ the year of the transaction's date. You can set the secondary date+ similarly, with date2:DATE2. The date: or date2: tags must have a+ valid simple date value if they are present, eg a date: tag with no value is not allowed. Ledger's earlier, more compact bracketed date syntax is also supported:- [DATE], [DATE=DATE2] or [=DATE2]. hledger will attempt to parse any+ [DATE], [DATE=DATE2] or [=DATE2]. hledger will attempt to parse any square-bracketed sequence of the 0123456789/-.= characters in this way.- With this syntax, DATE infers its year from the transaction and DATE2+ With this syntax, DATE infers its year from the transaction and DATE2 infers its year from DATE. Status- Transactions, or individual postings within a transaction, can have a- status mark, which is a single character before the transaction de-- scription or posting account name, separated from it by a space, indi-+ Transactions, or individual postings within a transaction, can have a+ status mark, which is a single character before the transaction de-+ scription or posting account name, separated from it by a space, indi- cating one of three statuses: mark status@@ -150,23 +151,23 @@ ! pending * cleared - When reporting, you can filter by status with the -U/--unmarked,- -P/--pending, and -C/--cleared flags; or the status:, status:!, and+ When reporting, you can filter by status with the -U/--unmarked,+ -P/--pending, and -C/--cleared flags; or the status:, status:!, and status:* queries; or the U, P, C keys in hledger-ui. - Note, in Ledger and in older versions of hledger, the "unmarked" state- is called "uncleared". As of hledger 1.3 we have renamed it to un-+ Note, in Ledger and in older versions of hledger, the "unmarked" state+ is called "uncleared". As of hledger 1.3 we have renamed it to un- marked for clarity. - To replicate Ledger and old hledger's behaviour of also matching pend-+ To replicate Ledger and old hledger's behaviour of also matching pend- ing, combine -U and -P. - Status marks are optional, but can be helpful eg for reconciling with+ Status marks are optional, but can be helpful eg for reconciling with real-world accounts. Some editor modes provide highlighting and short-- cuts for working with status. Eg in Emacs ledger-mode, you can toggle+ cuts for working with status. Eg in Emacs ledger-mode, you can toggle transaction status with C-c C-e, or posting status with C-c C-c. - What "uncleared", "pending", and "cleared" actually mean is up to you.+ What "uncleared", "pending", and "cleared" actually mean is up to you. Here's one suggestion: status meaning@@ -177,34 +178,34 @@ cleared complete, reconciled as far as possible, and considered cor- rect - With this scheme, you would use -PC to see the current balance at your+ With this scheme, you would use -PC to see the current balance at your bank, -U to see things which will probably hit your bank soon (like un-- cashed checks), and no flags to see the most up-to-date state of your+ cashed checks), and no flags to see the most up-to-date state of your finances. Description- A transaction's description is the rest of the line following the date- and status mark (or until a comment begins). Sometimes called the+ A transaction's description is the rest of the line following the date+ and status mark (or until a comment begins). Sometimes called the "narration" in traditional bookkeeping, it can be used for whatever you- wish, or left blank. Transaction descriptions can be queried, unlike+ wish, or left blank. Transaction descriptions can be queried, unlike comments. Payee and note You can optionally include a | (pipe) character in descriptions to sub- divide the description into separate fields for payee/payer name on the left (up to the first |) and an additional note field on the right (af-- ter the first |). This may be worthwhile if you need to do more pre-+ ter the first |). This may be worthwhile if you need to do more pre- cise querying and pivoting by payee or by note. Comments Lines in the journal beginning with a semicolon (;) or hash (#) or star- (*) are comments, and will be ignored. (Star comments cause org-mode- nodes to be ignored, allowing emacs users to fold and navigate their+ (*) are comments, and will be ignored. (Star comments cause org-mode+ nodes to be ignored, allowing emacs users to fold and navigate their journals with org-mode or orgstruct-mode.) - You can attach comments to a transaction by writing them after the de-+ You can attach comments to a transaction by writing them after the de- scription and/or indented on the following lines (before the postings).- Similarly, you can attach comments to an individual posting by writing+ Similarly, you can attach comments to an individual posting by writing them after the amount and/or indented on the following lines. Transac- tion and posting comments must begin with a semicolon (;). @@ -228,24 +229,24 @@ ; another comment line for posting 2 ; a file comment (because not indented) - You can also comment larger regions of a file using comment and end+ You can also comment larger regions of a file using comment and end comment directives. Tags- Tags are a way to add extra labels or labelled data to postings and+ Tags are a way to add extra labels or labelled data to postings and transactions, which you can then search or pivot on. - A simple tag is a word (which may contain hyphens) followed by a full+ A simple tag is a word (which may contain hyphens) followed by a full colon, written inside a transaction or posting comment line: 2017/1/16 bought groceries ; sometag: - Tags can have a value, which is the text after the colon, up to the+ Tags can have a value, which is the text after the colon, up to the next comma or end of line, with leading/trailing whitespace removed: expenses:food $10 ; a-posting-tag: the tag value - Note this means hledger's tag values can not contain commas or new-+ Note this means hledger's tag values can not contain commas or new- lines. Ending at commas means you can write multiple short tags on one line, comma separated: @@ -259,57 +260,57 @@ o "tag2" is another tag, whose value is "some value ..." - Tags in a transaction comment affect the transaction and all of its- postings, while tags in a posting comment affect only that posting.- For example, the following transaction has three tags (A, TAG2, third-+ Tags in a transaction comment affect the transaction and all of its+ postings, while tags in a posting comment affect only that posting.+ For example, the following transaction has three tags (A, TAG2, third- tag) and the posting has four (those plus posting-tag): 1/1 a transaction ; A:, TAG2: ; third-tag: a third transaction tag, <- with a value (a) $1 ; posting-tag: - Tags are like Ledger's metadata feature, except hledger's tag values+ Tags are like Ledger's metadata feature, except hledger's tag values are simple strings. Postings- A posting is an addition of some amount to, or removal of some amount- from, an account. Each posting line begins with at least one space or+ A posting is an addition of some amount to, or removal of some amount+ from, an account. Each posting line begins with at least one space or tab (2 or 4 spaces is common), followed by: o (optional) a status character (empty, !, or *), followed by a space - o (required) an account name (any text, optionally containing single+ o (required) an account name (any text, optionally containing single spaces, until end of line or a double space) o (optional) two or more spaces or tabs followed by an amount. - Positive amounts are being added to the account, negative amounts are+ Positive amounts are being added to the account, negative amounts are being removed. The amounts within a transaction must always sum up to zero. As a con-- venience, one amount may be left blank; it will be inferred so as to+ venience, one amount may be left blank; it will be inferred so as to balance the transaction. - Be sure to note the unusual two-space delimiter between account name- and amount. This makes it easy to write account names containing spa-- ces. But if you accidentally leave only one space (or tab) before the+ Be sure to note the unusual two-space delimiter between account name+ and amount. This makes it easy to write account names containing spa-+ ces. But if you accidentally leave only one space (or tab) before the amount, the amount will be considered part of the account name. - Virtual Postings+ Virtual postings A posting with a parenthesised account name is called a virtual posting- or unbalanced posting, which means it is exempt from the usual rule+ or unbalanced posting, which means it is exempt from the usual rule that a transaction's postings must balance add up to zero. - This is not part of double entry accounting, so you might choose to- avoid this feature. Or you can use it sparingly for certain special- cases where it can be convenient. Eg, you could set opening balances+ This is not part of double entry accounting, so you might choose to+ avoid this feature. Or you can use it sparingly for certain special+ cases where it can be convenient. Eg, you could set opening balances without using a balancing equity account: 1/1 opening balances (assets:checking) $1000 (assets:savings) $2000 - A posting with a bracketed account name is called a balanced virtual+ A posting with a bracketed account name is called a balanced virtual posting. The balanced virtual postings in a transaction must add up to zero (separately from other postings). Eg: @@ -321,34 +322,34 @@ [assets:checking:available] $10 ; <- (something:else) $5 ; <- not required to balance - Ordinary non-parenthesised, non-bracketed postings are called real- postings. You can exclude virtual postings from reports with the+ Ordinary non-parenthesised, non-bracketed postings are called real+ postings. You can exclude virtual postings from reports with the -R/--real flag or real:1 query. Account names- Account names typically have several parts separated by a full colon,- from which hledger derives a hierarchical chart of accounts. They can- be anything you like, but in finance there are traditionally five top-+ Account names typically have several parts separated by a full colon,+ from which hledger derives a hierarchical chart of accounts. They can+ be anything you like, but in finance there are traditionally five top- level accounts: assets, liabilities, income, expenses, and equity. - Account names may contain single spaces, eg: assets:accounts receiv-- able. Because of this, they must always be followed by two or more+ Account names may contain single spaces, eg: assets:accounts receiv-+ able. Because of this, they must always be followed by two or more spaces (or newline). Account names can be aliased. Amounts- After the account name, there is usually an amount. (Important: be-+ After the account name, there is usually an amount. (Important: be- tween account name and amount, there must be two or more spaces.) - hledger's amount format is flexible, supporting several international- formats. Here are some examples. Amounts have a number (the "quan-+ hledger's amount format is flexible, supporting several international+ formats. Here are some examples. Amounts have a number (the "quan- tity"): 1 - ..and usually a currency or commodity name (the "commodity"). This is- a symbol, word, or phrase, to the left or right of the quantity, with+ ..and usually a currency or commodity name (the "commodity"). This is+ a symbol, word, or phrase, to the left or right of the quantity, with or without a separating space: $1@@ -359,12 +360,19 @@ 3 "no. 42 green apples" - Amounts can be negative. The minus sign can be written before or after- a left-side commodity symbol:+ Amounts can be preceded by a minus sign (or a plus sign, though plus is+ the default), The sign can be written before or after a left-side com-+ modity symbol: -$1 $-1 + One or more spaces between the sign and the number are acceptable when+ parsing (but they won't be displayed in output):++ + $1+ $- 1+ Scientific E notation is allowed: 1E-6@@ -376,8 +384,8 @@ 1,23456780000009 Digit group marks- In the integer part of the quantity (left of the decimal mark), groups- of digits can optionally be separated by a "digit group mark" - a+ In the integer part of the quantity (left of the decimal mark), groups+ of digits can optionally be separated by a "digit group mark" - a space, comma, or period (different from the decimal mark): $1,000,000.00@@ -385,7 +393,7 @@ INR 9,99,99,999.00 1 000 000.9455 - Note, a number containing a single group mark and no decimal mark is+ Note, a number containing a single group mark and no decimal mark is ambiguous. Are these group marks or decimal marks ? 1,000@@ -393,9 +401,9 @@ hledger will treat them both as decimal marks by default (cf #793). If you use digit group marks, to prevent confusion and undetected typos we- recommend you write commodity directives at the top of the file to ex-- plicitly declare the decimal mark (and optionally a digit group mark).- Note, these formats ("amount styles") are specific to each commodity,+ recommend you write commodity directives at the top of the file to ex-+ plicitly declare the decimal mark (and optionally a digit group mark).+ Note, these formats ("amount styles") are specific to each commodity, so if your data uses multiple formats, hledger can handle it: commodity $1,000.00@@ -404,31 +412,36 @@ commodity 1 000 000.9455 Amount display style- For each commodity, hledger chooses a consistent format to use when- displaying amounts. (Except price amounts, which are always displayed+ For each commodity, hledger chooses a consistent format to use when+ displaying amounts. (Except price amounts, which are always displayed as written). The display style is chosen as follows: - o If there is a commodity directive (or default commodity directive)+ o If there is a commodity directive (or default commodity directive) for the commodity, that format is used (see examples above). - o Otherwise the format of the first posting amount in that commodity+ o Otherwise the format of the first posting amount in that commodity seen in the journal is used. But the number of decimal places ("pre-- cision") will be the maximum from all posting amounts in that comm-- modity.+ cision") will be the maximum from all posting amounts in that commod-+ ity. - o Or if there are no such amounts in the journal, a default format is+ o Or if there are no such amounts in the journal, a default format is used (like $1000.00). - Transaction prices don't affect the amount display style directly, but- occasionally they can do so indirectly (eg when an posting's amount is- inferred using a transaction price). If you find this causing prob-+ Transaction prices don't affect the amount display style directly, but+ occasionally they can do so indirectly (eg when an posting's amount is+ inferred using a transaction price). If you find this causing prob- lems, use a commodity directive to fix the display style. In summary: amounts will be displayed much as they appear in your jour-- nal, with the max observed number of decimal places. If you want to+ nal, with the max observed number of decimal places. If you want to see fewer decimal places in reports, use a commodity directive to over- ride that. + hledger uses banker's rounding: it rounds to the nearest even number,+ eg 0.5 displayed with zero decimal places is "0"). (Note, prior to+ hledger 1.17.1 this could vary if hledger happened to be built with an+ old version of Decimal (<0.5.1); since 1.17.1 it's guaranteed.)+ Transaction prices Within a transaction, you can note an amount's price in another commod- ity. This can be used to document the cost (in a purchase) or selling@@ -459,10 +472,11 @@ assets:euros EUR100 ; one hundred euros purchased assets:dollars $-135 ; for $135 - (Ledger users: Ledger uses a different syntax for fixed prices, {=UNIT-- PRICE}, which hledger currently ignores).+ 5. Like 1 and 2, but the @ or @@ is parenthesised; this is for compati-+ bility with Ledger journals (Virtual posting costs), and in hledger+ is equivalent to 1 and 2. - Use the -B/--cost flag to convert amounts to their transaction price's+ Use the -B/--cost flag to convert amounts to their transaction price's commodity, if any. (mnemonic: "B" is from "cost Basis", as in Ledger). Eg here is how -B affects the balance report for the example above: @@ -473,8 +487,8 @@ $-135 assets:dollars $135 assets:euros # <- the euros' cost - Note -B is sensitive to the order of postings when a transaction price- is inferred: the inferred price will be in the commodity of the last+ Note -B is sensitive to the order of postings when a transaction price+ is inferred: the inferred price will be in the commodity of the last amount. So if example 3's postings are reversed, while the transaction is equivalent, -B shows something different: @@ -486,10 +500,19 @@ EUR-100 assets:dollars # <- the dollars' selling price EUR100 assets:euros - Balance Assertions- hledger supports Ledger-style balance assertions in journal files.- These look like, for example, = EXPECTEDBALANCE following a posting's- amount. Eg here we assert the expected dollar balance in accounts a+ Lot prices and lot dates+ Ledger allows another kind of price, lot price (four variants: {UNIT-+ PRICE}, {{TOTALPRICE}}, {=FIXEDUNITPRICE}, {{=FIXEDTOTALPRICE}}),+ and/or a lot date ([DATE]) to be specified. These are normally used to+ select a lot when selling investments. hledger will parse these, for+ compatibility with Ledger journals, but currently ignores them. A+ transaction price, lot price and/or lot date may appear in any order,+ after the posting amount and before the balance assertion if any.++ Balance assertions+ hledger supports Ledger-style balance assertions in journal files.+ These look like, for example, = EXPECTEDBALANCE following a posting's+ amount. Eg here we assert the expected dollar balance in accounts a and b after each posting: 2013/1/1@@ -501,32 +524,32 @@ b $-1 =$-2 After reading a journal file, hledger will check all balance assertions- and report an error if any of them fail. Balance assertions can pro-- tect you from, eg, inadvertently disrupting reconciled balances while- cleaning up old entries. You can disable them temporarily with the+ and report an error if any of them fail. Balance assertions can pro-+ tect you from, eg, inadvertently disrupting reconciled balances while+ cleaning up old entries. You can disable them temporarily with the -I/--ignore-assertions flag, which can be useful for troubleshooting or- for reading Ledger files. (Note: this flag currently does not disable+ for reading Ledger files. (Note: this flag currently does not disable balance assignments, below). Assertions and ordering- hledger sorts an account's postings and assertions first by date and- then (for postings on the same day) by parse order. Note this is dif-+ hledger sorts an account's postings and assertions first by date and+ then (for postings on the same day) by parse order. Note this is dif- ferent from Ledger, which sorts assertions only by parse order. (Also,- Ledger assertions do not see the accumulated effect of repeated post-+ Ledger assertions do not see the accumulated effect of repeated post- ings to the same account within a transaction.) So, hledger balance assertions keep working if you reorder differently-- dated transactions within the journal. But if you reorder same-dated- transactions or postings, assertions might break and require updating.+ dated transactions within the journal. But if you reorder same-dated+ transactions or postings, assertions might break and require updating. This order dependence does bring an advantage: precise control over the order of postings and assertions within a day, so you can assert intra- day balances. Assertions and included files- With included files, things are a little more complicated. Including- preserves the ordering of postings and assertions. If you have multi-- ple postings to an account on the same day, split across different- files, and you also want to assert the account's balance on the same+ With included files, things are a little more complicated. Including+ preserves the ordering of postings and assertions. If you have multi-+ ple postings to an account on the same day, split across different+ files, and you also want to assert the account's balance on the same day, you'll have to put the assertion in the right file. Assertions and multiple -f options@@ -534,15 +557,15 @@ -f options. Use include or concatenate the files instead. Assertions and commodities- The asserted balance must be a simple single-commodity amount, and in- fact the assertion checks only this commodity's balance within the- (possibly multi-commodity) account balance. This is how assertions+ The asserted balance must be a simple single-commodity amount, and in+ fact the assertion checks only this commodity's balance within the+ (possibly multi-commodity) account balance. This is how assertions work in Ledger also. We could call this a "partial" balance assertion. To assert the balance of more than one commodity in an account, you can write multiple postings, each asserting one commodity's balance. - You can make a stronger "total" balance assertion by writing a double+ You can make a stronger "total" balance assertion by writing a double equals sign (== EXPECTEDBALANCE). This asserts that there are no other unasserted commodities in the account (or, that their balance is 0). @@ -562,7 +585,7 @@ a 0 == $1 It's not yet possible to make a complete assertion about a balance that- has multiple commodities. One workaround is to isolate each commodity+ has multiple commodities. One workaround is to isolate each commodity into its own subaccount: 2013/1/1@@ -576,21 +599,21 @@ a:euro 0 == 1EUR Assertions and prices- Balance assertions ignore transaction prices, and should normally be+ Balance assertions ignore transaction prices, and should normally be written without one: 2019/1/1 (a) $1 @ EUR1 = $1 - We do allow prices to be written there, however, and print shows them,- even though they don't affect whether the assertion passes or fails.- This is for backward compatibility (hledger's close command used to- generate balance assertions with prices), and because balance assign-+ We do allow prices to be written there, however, and print shows them,+ even though they don't affect whether the assertion passes or fails.+ This is for backward compatibility (hledger's close command used to+ generate balance assertions with prices), and because balance assign- ments do use them (see below). Assertions and subaccounts- The balance assertions above (= and ==) do not count the balance from- subaccounts; they check the account's exclusive balance only. You can+ The balance assertions above (= and ==) do not count the balance from+ subaccounts; they check the account's exclusive balance only. You can assert the balance including subaccounts by writing =* or ==*, eg: 2019/1/1@@ -604,16 +627,16 @@ tual. They are not affected by the --real/-R flag or real: query. Assertions and precision- Balance assertions compare the exactly calculated amounts, which are- not always what is shown by reports. Eg a commodity directive may- limit the display precision, but this will not affect balance asser-+ Balance assertions compare the exactly calculated amounts, which are+ not always what is shown by reports. Eg a commodity directive may+ limit the display precision, but this will not affect balance asser- tions. Balance assertion failure messages show exact amounts. - Balance Assignments- Ledger-style balance assignments are also supported. These are like- balance assertions, but with no posting amount on the left side of the- equals sign; instead it is calculated automatically so as to satisfy- the assertion. This can be a convenience during data entry, eg when+ Balance assignments+ Ledger-style balance assignments are also supported. These are like+ balance assertions, but with no posting amount on the left side of the+ equals sign; instead it is calculated automatically so as to satisfy+ the assertion. This can be a convenience during data entry, eg when setting opening balances: ; starting a new journal, set asset account balances@@ -631,14 +654,14 @@ expenses:misc The calculated amount depends on the account's balance in the commodity- at that point (which depends on the previously-dated postings of the- commodity to that account since the last balance assertion or assign-+ at that point (which depends on the previously-dated postings of the+ commodity to that account since the last balance assertion or assign- ment). Note that using balance assignments makes your journal a little less explicit; to know the exact amount posted, you have to run hledger or do the calculations yourself, instead of just reading it. Balance assignments and prices- A transaction price in a balance assignment will cause the calculated+ A transaction price in a balance assignment will cause the calculated amount to have that price attached: 2019/1/1@@ -649,85 +672,87 @@ (a) $1 @ EUR2 = $1 @ EUR2 Directives- A directive is a line in the journal beginning with a special keyword,+ A directive is a line in the journal beginning with a special keyword, that influences how the journal is processed. hledger's directives are based on a subset of Ledger's, but there are many differences (and also some differences between hledger versions). Directives' behaviour and interactions can get a little bit complex, so- here is a table summarising the directives and their effects, with+ here is a table summarising the directives and their effects, with links to more detailed docs. - direc- end di- subdi- purpose can affect (as of+ direc- end di- subdi- purpose can affect (as of tive rective rec- 2018/06) tives ------------------------------------------------------------------------------------- account any document account names, de- all entries in all- text clare account types & dis- files, before or+ account any document account names, de- all entries in all+ text clare account types & dis- files, before or play order after alias end rewrite account names following in- aliases line/included en-- tries until end of+ tries until end of current file or end directive- apply end apply prepend a common parent to following in-+ apply end apply prepend a common parent to following in- account account account names line/included en-- tries until end of+ tries until end of current file or end directive comment end com- ignore part of journal following in- ment line/included en-- tries until end of+ tries until end of current file or end directive- commod- format declare a commodity and its number notation:+ commod- format declare a commodity and its number notation: ity number notation & display following entries style in that commodity- in all files; dis-+ in all files; dis- play style: amounts of that commodity in reports- D declare a commodity to be default commodity:+ D declare a commodity to be default commodity: used for commodityless following commod-- amounts, and its number no- ityless entries un-- tation & display style til end of current- file; number nota-+ amounts, and its number no- ityless entries un-+ tation & display style til end of current+ file; number nota- tion: following en-- tries in that com-+ tries in that com- modity until end of- current file; dis-+ current file; dis- play style: amounts of that commodity in reports include include entries/directives what the included from another file directives affect P declare a market price for a amounts of that- commodity commodity in re-- ports, when -V is+ commodity commodity in re-+ ports, when -V is used- Y declare a year for yearless following in-++++ Y declare a year for yearless following in- dates line/included en-- tries until end of+ tries until end of current file- = declare an auto posting all entries in par-- rule, adding postings to ent/current/child+ = declare an auto posting all entries in par-+ rule, adding postings to ent/current/child other transactions files (but not sib- ling files, see #1212) And some definitions: - subdi- optional indented directive line immediately following a parent+ subdi- optional indented directive line immediately following a parent rec- directive tive number how to interpret numbers when parsing journal entries (the iden-- nota- tity of the decimal separator character). (Currently each com-+ nota- tity of the decimal separator character). (Currently each com- tion modity can have its own notation, even in the same file.)-- dis- how to display amounts of a commodity in reports (symbol side+ dis- how to display amounts of a commodity in reports (symbol side play and spacing, digit groups, decimal separator, decimal places) style- direc- which entries and (when there are multiple files) which files+ direc- which entries and (when there are multiple files) which files tive are affected by a directive scope @@ -736,41 +761,49 @@ ports). Some directives have multiple effects. Directives and multiple files- If you use multiple -f/--file options, or the include directive,- hledger will process multiple input files. But note that directives+ If you use multiple -f/--file options, or the include directive,+ hledger will process multiple input files. But note that directives which affect input (see above) typically last only until the end of the file in which they occur. This may seem inconvenient, but it's intentional; it makes reports sta-- ble and deterministic, independent of the order of input. Otherwise- you could see different numbers if you happened to write -f options in- a different order, or if you moved includes around while cleaning up+ ble and deterministic, independent of the order of input. Otherwise+ you could see different numbers if you happened to write -f options in+ a different order, or if you moved includes around while cleaning up your files. - It can be surprising though; for example, it means that alias direc-+ It can be surprising though; for example, it means that alias direc- tives do not affect parent or sibling files (see below). Comment blocks- A line containing just comment starts a commented region of the file,+ A line containing just comment starts a commented region of the file, and a line containing just end comment (or the end of the current file) ends it. See also comments. Including other files- You can pull in the content of additional files by writing an include+ You can pull in the content of additional files by writing an include directive, like this: - include path/to/file.journal+ include FILEPATH - If the path does not begin with a slash, it is relative to the current- file. The include file path may contain common glob patterns (e.g.- *).+ Only journal files can include, and only journal, timeclock or timedot+ files can be included (not CSV files, currently). - The include directive can only be used in journal files. It can in-- clude journal, timeclock or timedot files, but not CSV files.+ If the file path does not begin with a slash, it is relative to the+ current file's folder. + It may contain glob patterns to match multiple files, eg: include+ *.journal.++ Or a tilde, meaning home directory: include ~/main.journal.++ It may also be prefixed to force a specific file format, overriding the+ file extension (as described in hledger.1 -> Input files): include+ timedot:~/notes/2020*.md.+ Default year- You can set a default year to be used for subsequent dates which don't- specify a year. This is a line beginning with Y followed by the year.+ You can set a default year to be used for subsequent dates which don't+ specify a year. This is a line beginning with Y followed by the year. Eg: Y2009 ; set default year to 2009@@ -792,19 +825,19 @@ Declaring commodities The commodity directive has several functions: - 1. It declares commodities which may be used in the journal. This is+ 1. It declares commodities which may be used in the journal. This is currently not enforced, but can serve as documentation. - 2. It declares what decimal mark character (period or comma) to expect- when parsing input - useful to disambiguate international number- formats in your data. (Without this, hledger will parse both 1,000+ 2. It declares what decimal mark character (period or comma) to expect+ when parsing input - useful to disambiguate international number+ formats in your data. (Without this, hledger will parse both 1,000 and 1.000 as 1). - 3. It declares the amount display style to use in output - decimal and+ 3. It declares the amount display style to use in output - decimal and digit group marks, number of decimal places, symbol placement etc. - You are likely to run into one of the problems solved by commodity di-- rectives, sooner or later, so it's a good idea to just always use them+ You are likely to run into one of the problems solved by commodity di-+ rectives, sooner or later, so it's a good idea to just always use them to declare your commodities. A commodity directive is just the word commodity followed by an amount.@@ -817,8 +850,8 @@ ; separating thousands with comma. commodity 1,000.0000 AAAA - or on multiple lines, using the "format" subdirective. (In this case- the commodity symbol appears twice and should be the same in both+ or on multiple lines, using the "format" subdirective. (In this case+ the commodity symbol appears twice and should be the same in both places.): ; commodity SYMBOL@@ -831,9 +864,12 @@ format INR 1,00,00,000.00 The quantity of the amount does not matter; only the format is signifi-- cant. The number must include a decimal mark: either a period or a+ cant. The number must include a decimal mark: either a period or a comma, followed by 0 or more decimal digits. + Note hledger normally uses banker's rounding, so 0.5 displayed with+ zero decimal digits is "0". (More at Amount display style.)+ Default commodity The D directive sets a default commodity, to be used for amounts with- out a commodity symbol (ie, plain numbers). This commodity will be ap-@@ -856,7 +892,7 @@ a 5 ; <- commodity-less amount, parsed as $5 and displayed as $5.00 b - Market prices+ Declaring market prices The P directive declares a market price, which is an exchange rate be- tween two commodities on a certain date. (In Ledger, they are called "historical prices".) These are often obtained from a stock exchange,@@ -879,8 +915,8 @@ P 2009/1/1 EUR $1.35 P 2010/1/1 EUR $1.40 - The -V/--value flag can be used to convert reported amounts to another- commodity using these prices.+ The -V, -X and --value flags use these market prices to show amount+ values in another commodity. See Valuation. Declaring accounts account directives can be used to pre-declare accounts. Though not re-@@ -1257,68 +1293,61 @@ pression. Forecasting with periodic transactions- With the --forecast flag, each periodic transaction rule generates fu-- ture transactions recurring at the specified interval. These are not- saved in the journal, but appear in all reports. They will look like- normal transactions, but with an extra tag:-- o generated-transaction:~ PERIODICEXPR - shows that this was generated- by a periodic transaction rule, and the period-- There is also a hidden tag, with an underscore prefix, which does not- appear in hledger's output:-- o _generated-transaction:~ PERIODICEXPR+ The --forecast flag activates any periodic transaction rules in the+ journal. They will generate temporary recurring transactions, which+ are not saved in the journal, but will appear in all reports (eg+ print). This can be useful for estimating balances into the future, or+ experimenting with different scenarios. Or, it can be used as a data+ entry aid: describe recurring transactions, and every so often copy the+ output of print --forecast into the journal. - This can be used to match transactions generated "just now", rather- than generated in the past and saved to the journal.+ These transactions will have an extra tag indicating which periodic+ rule generated them: generated-transaction:~ PERIODICEXPR. And a simi-+ lar, hidden tag (beginning with an underscore) which, because it's+ never displayed by print, can be used to match transactions generated+ "just now": _generated-transaction:~ PERIODICEXPR. - Forecast transactions start on the first occurrence, and end on the- last occurrence, of their interval within the forecast period. The- forecast period:+ Periodic transactions are generated within some forecast period. By+ default, this o begins on the later of o the report start date if specified with -b/-p/date: - o the day after the latest normal (non-periodic) transaction in the+ o the day after the latest normal (non-periodic) transaction in the journal, or today if there are no normal transactions. - o ends on the report end date if specified with -e/-p/date:, or 180- days from today.-- where "today" means the current date at report time. The "later of"- rule ensures that forecast transactions do not overlap normal transac-- tions in time; they will begin only after normal transactions end.-- Forecasting can be useful for estimating balances into the future, and- experimenting with different scenarios. Note the start date logic- means that forecasted transactions are automatically replaced by normal- transactions as you add those.+ o ends on the report end date if specified with -e/-p/date:, or 6+ months (180 days) from today. - Forecasting can also help with data entry: describe most of your trans-- actions with periodic rules, and every so often copy the output of- print --forecast to the journal.+ This means that periodic transactions will begin only after the latest+ recorded transaction. And a recorded transaction dated in the future+ can prevent generation of periodic transactions. (You can avoid that+ by writing the future transaction as a one-time periodic rule instead -+ put tilde before the date, eg ~ YYYY-MM-DD ...). - You can generate one-time transactions too: just write a period expres-- sion specifying a date with no report interval. (You could also write- a normal transaction with a future date, but remember this disables- forecast transactions on previous dates.)+ Or, you can set your own arbitrary "forecast period", which can overlap+ recorded transactions, and need not be in the future, by providing an+ option argument, like --forecast=PERIODEXPR. Note the equals sign is+ required, a space won't work. PERIODEXPR is a period expression, which+ can specify the start date, end date, or both, like in a date: query.+ (See also hledger.1 -> Report start & end date). Some examples:+ --forecast=202001-202004, --forecast=jan-, --forecast=2020. Budgeting with periodic transactions- With the --budget flag, currently supported by the balance command,- each periodic transaction rule declares recurring budget goals for the- specified accounts. Eg the first example above declares a goal of- spending $2000 on rent (and also, a goal of depositing $2000 into- checking) every month. Goals and actual performance can then be com-+ With the --budget flag, currently supported by the balance command,+ each periodic transaction rule declares recurring budget goals for the+ specified accounts. Eg the first example above declares a goal of+ spending $2000 on rent (and also, a goal of depositing $2000 into+ checking) every month. Goals and actual performance can then be com- pared in budget reports. - For more details, see: balance: Budget report and Budgeting and Fore-+ For more details, see: balance: Budget report and Budgeting and Fore- casting. Auto postings- "Automated postings" or "auto postings" are extra postings which get- added automatically to transactions which match certain queries, de-+ "Automated postings" or "auto postings" are extra postings which get+ added automatically to transactions which match certain queries, de- fined by "auto posting rules", when you use the --auto flag. An auto posting rule looks a bit like a transaction:@@ -1328,27 +1357,27 @@ ... ACCOUNT [AMOUNT] - except the first line is an equals sign (mnemonic: = suggests match-- ing), followed by a query (which matches existing postings), and each- "posting" line describes a posting to be generated, and the posting+ except the first line is an equals sign (mnemonic: = suggests match-+ ing), followed by a query (which matches existing postings), and each+ "posting" line describes a posting to be generated, and the posting amounts can be: - o a normal amount with a commodity symbol, eg $2. This will be used+ o a normal amount with a commodity symbol, eg $2. This will be used as-is. o a number, eg 2. The commodity symbol (if any) from the matched post- ing will be added to this. - o a numeric multiplier, eg *2 (a star followed by a number N). The+ o a numeric multiplier, eg *2 (a star followed by a number N). The matched posting's amount (and total price, if any) will be multiplied by N. - o a multiplier with a commodity symbol, eg *$2 (a star, number N, and+ o a multiplier with a commodity symbol, eg *$2 (a star, number N, and symbol S). The matched posting's amount will be multiplied by N, and its commodity symbol will be replaced with S. - Any query term containing spaces must be enclosed in single or double- quotes, as on the command line. Eg, note the quotes around the second+ Any query term containing spaces must be enclosed in single or double+ quotes, as on the command line. Eg, note the quotes around the second query term below: = expenses:groceries 'expenses:dining out'@@ -1387,24 +1416,24 @@ Auto postings and multiple files An auto posting rule can affect any transaction in the current file, or- in any parent file or child file. Note, currently it will not affect+ in any parent file or child file. Note, currently it will not affect sibling files (when multiple -f/--file are used - see #1212). Auto postings and dates- A posting date (or secondary date) in the matched posting, or (taking- precedence) a posting date in the auto posting rule itself, will also+ A posting date (or secondary date) in the matched posting, or (taking+ precedence) a posting date in the auto posting rule itself, will also be used in the generated posting. Auto postings and transaction balancing / inferred amounts / balance asser- tions Currently, auto postings are added: - o after missing amounts are inferred, and transactions are checked for+ o after missing amounts are inferred, and transactions are checked for balancedness, o but before balance assertions are checked. - Note this means that journal entries must be balanced both before and+ Note this means that journal entries must be balanced both before and after auto postings are added. This changed in hledger 1.12+; see #893 for background. @@ -1414,11 +1443,11 @@ o generated-posting:= QUERY - shows this was generated by an auto post- ing rule, and the query - o _generated-posting:= QUERY - a hidden tag, which does not appear in+ o _generated-posting:= QUERY - a hidden tag, which does not appear in hledger's output. This can be used to match postings generated "just now", rather than generated in the past and saved to the journal. - Also, any transaction that has been changed by auto posting rules will+ Also, any transaction that has been changed by auto posting rules will have these tags added: o modified: - this transaction was modified@@ -1429,7 +1458,7 @@ REPORTING BUGS- Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel+ Report bugs at http://bugs.hledger.org (or on the #hledger IRC channel or hledger mail list) @@ -1443,7 +1472,7 @@ SEE ALSO- hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1),+ hledger(1), hledger-ui(1), hledger-web(1), hledger-api(1), hledger_csv(5), hledger_journal(5), hledger_timeclock(5), hledger_time- dot(5), ledger(1) @@ -1451,4 +1480,4 @@ -hledger 1.17.1 March 2020 hledger_journal(5)+hledger 1.18 June 2020 hledger_journal(5)
hledger_timeclock.5 view
@@ -1,5 +1,5 @@ -.TH "hledger_timeclock" "5" "March 2020" "hledger 1.17.1" "hledger User Manuals"+.TH "hledger_timeclock" "5" "June 2020" "hledger 1.18" "hledger User Manuals"
hledger_timeclock.info view
@@ -4,8 +4,8 @@ File: hledger_timeclock.info, Node: Top, Up: (dir) -hledger_timeclock(5) hledger 1.17.1-***********************************+hledger_timeclock(5) hledger 1.18+********************************* Timeclock - the time logging format of timeclock.el, as read by hledger
hledger_timeclock.txt view
@@ -78,4 +78,4 @@ -hledger 1.17.1 March 2020 hledger_timeclock(5)+hledger 1.18 June 2020 hledger_timeclock(5)
hledger_timedot.5 view
@@ -1,5 +1,5 @@ -.TH "hledger_timedot" "5" "March 2020" "hledger 1.17.1" "hledger User Manuals"+.TH "hledger_timedot" "5" "June 2020" "hledger 1.18" "hledger User Manuals"
hledger_timedot.info view
@@ -4,8 +4,8 @@ File: hledger_timedot.info, Node: Top, Up: (dir) -hledger_timedot(5) hledger 1.17.1-*********************************+hledger_timedot(5) hledger 1.18+******************************* Timedot - hledger's human-friendly time logging format
hledger_timedot.txt view
@@ -161,4 +161,4 @@ -hledger 1.17.1 March 2020 hledger_timedot(5)+hledger 1.18 June 2020 hledger_timedot(5)