hledger-lib-1.5: Core data types, parsers and functionality for the hledger accounting tools

Safe HaskellNone
LanguageHaskell2010

Hledger.Data.AutoTransaction

Contents

Description

This module provides utilities for applying automated transactions like ModifierTransaction and PeriodicTransaction.

Synopsis

Transaction processors

runModifierTransaction :: Query -> ModifierTransaction -> Transaction -> Transaction Source #

Builds a Transaction transformer based on ModifierTransaction.

Query parameter allows injection of additional restriction on posting match. Don't forget to call txnTieKnot.

>>> runModifierTransaction Any (ModifierTransaction "" ["pong" `post` usd 2]) nulltransaction{tpostings=["ping" `post` usd 1]}
0000/01/01
    ping           $1.00
    pong           $2.00


>>> runModifierTransaction Any (ModifierTransaction "miss" ["pong" `post` usd 2]) nulltransaction{tpostings=["ping" `post` usd 1]}
0000/01/01
    ping           $1.00


>>> runModifierTransaction None (ModifierTransaction "" ["pong" `post` usd 2]) nulltransaction{tpostings=["ping" `post` usd 1]}
0000/01/01
    ping           $1.00


>>> runModifierTransaction Any (ModifierTransaction "ping" ["pong" `post` amount{amultiplier=True, aquantity=3}]) nulltransaction{tpostings=["ping" `post` usd 2]}
0000/01/01
    ping           $2.00
    pong           $6.00


runPeriodicTransaction :: PeriodicTransaction -> DateSpan -> [Transaction] Source #

Generate transactions from PeriodicTransaction within a DateSpan

Note that new transactions require txnTieKnot post-processing.

>>> let gen str = mapM_ (putStr . show) $ runPeriodicTransaction (PeriodicTransaction str ["hi" `post` usd 1]) nulldatespan
>>> gen "monthly from 2017/1 to 2017/4"
2017/01/01
    hi           $1.00

2017/02/01
    hi           $1.00

2017/03/01
    hi           $1.00

>>> gen "monthly from 2017/1 to 2017/5"
2017/01/01
    hi           $1.00

2017/02/01
    hi           $1.00

2017/03/01
    hi           $1.00

2017/04/01
    hi           $1.00

>>> gen "every 2nd day of month from 2017/02 to 2017/04"
2017/01/02
    hi           $1.00

2017/02/02
    hi           $1.00

2017/03/02
    hi           $1.00

>>> gen "monthly from 2017/1 to 2017/4"
2017/01/01
    hi           $1.00

2017/02/01
    hi           $1.00

2017/03/01
    hi           $1.00

>>> gen "every 30th day of month from 2017/1 to 2017/5"
2016/12/30
    hi           $1.00

2017/01/30
    hi           $1.00

2017/02/28
    hi           $1.00

2017/03/30
    hi           $1.00

2017/04/30
    hi           $1.00

>>> gen "every 2nd Thursday of month from 2017/1 to 2017/4"
2016/12/08
    hi           $1.00

2017/01/12
    hi           $1.00

2017/02/09
    hi           $1.00

2017/03/09
    hi           $1.00

>>> gen "every nov 29th from 2017 to 2019"
2016/11/29
    hi           $1.00

2017/11/29
    hi           $1.00

2018/11/29
    hi           $1.00

>>> gen "2017/1"
2017/01/01
    hi           $1.00

>>> gen ""
... Failed to parse ...
>>> gen "weekly from 2017"
*** Exception: Unable to generate transactions according to "weekly from 2017" as 2017-01-01 is not a first day of the week
>>> gen "monthly from 2017/5/4"
*** Exception: Unable to generate transactions according to "monthly from 2017/5/4" as 2017-05-04 is not a first day of the month        
>>> gen "every quarter from 2017/1/2"
*** Exception: Unable to generate transactions according to "every quarter from 2017/1/2" as 2017-01-02 is not a first day of the quarter        
>>> gen "yearly from 2017/1/14"
*** Exception: Unable to generate transactions according to "yearly from 2017/1/14" as 2017-01-14 is not a first day of the year        

Accessors

mtvaluequery :: ModifierTransaction -> Day -> Query Source #

Extract Query equivalent of mtvalueexpr from ModifierTransaction

>>> mtvaluequery (ModifierTransaction "" []) undefined
Any
>>> mtvaluequery (ModifierTransaction "ping" []) undefined
Acct "ping"
>>> mtvaluequery (ModifierTransaction "date:2016" []) undefined
Date (DateSpan 2016)
>>> mtvaluequery (ModifierTransaction "date:today" []) (read "2017-01-01")
Date (DateSpan 2017/01/01)

jdatespan :: Journal -> DateSpan Source #

DateSpan of all dates mentioned in Journal

>>> jdatespan nulljournal
DateSpan -
>>> jdatespan nulljournal{jtxns=[nulltransaction{tdate=read "2016-01-01"}] }
DateSpan 2016/01/01
>>> jdatespan nulljournal{jtxns=[nulltransaction{tdate=read "2016-01-01", tpostings=[nullposting{pdate=Just $ read "2016-02-01"}]}] }
DateSpan 2016/01/01-2016/02/01