Safe Haskell | None |
---|
Essential data types used to make Transactions and Postings.
- newtype SubAccount = SubAccount {
- unSubAccount :: Text
- newtype Account = Account {
- unAccount :: [SubAccount]
- data Amount = Amount {
- qty :: Qty
- commodity :: Commodity
- side :: Maybe Side
- spaceBetween :: Maybe SpaceBetween
- newtype Commodity = Commodity {
- unCommodity :: Text
- data TimeZoneOffset
- minsToOffset :: Int -> Maybe TimeZoneOffset
- noOffset :: TimeZoneOffset
- data Hours
- intToHours :: Int -> Maybe Hours
- zeroHours :: Hours
- data Minutes
- intToMinutes :: Int -> Maybe Minutes
- zeroMinutes :: Minutes
- midnight :: (Hours, Minutes, Seconds)
- data Seconds
- intToSeconds :: Int -> Maybe Seconds
- zeroSeconds :: Seconds
- data DateTime = DateTime {}
- dateTimeMidnightUTC :: Day -> DateTime
- toUTC :: DateTime -> UTCTime
- toZonedTime :: DateTime -> ZonedTime
- fromZonedTime :: ZonedTime -> Maybe DateTime
- sameInstant :: DateTime -> DateTime -> Bool
- showDateTime :: DateTime -> String
- data DrCr
- opposite :: DrCr -> DrCr
- data Entry = Entry {}
- newtype Flag = Flag {}
- newtype Memo = Memo {}
- newtype Number = Number {}
- newtype Payee = Payee {}
- newtype From = From {}
- newtype To = To {}
- newtype CountPerUnit = CountPerUnit {}
- data Price
- convert :: Price -> Amount -> Maybe Amount
- newPrice :: From -> To -> CountPerUnit -> Maybe Price
- data PricePoint = PricePoint {}
- data Qty
- data NumberStr
- toQty :: NumberStr -> Maybe Qty
- mantissa :: Qty -> Integer
- places :: Qty -> Integer
- add :: Qty -> Qty -> Qty
- mult :: Qty -> Qty -> Qty
- difference :: Qty -> Qty -> Difference
- equivalent :: Qty -> Qty -> Bool
- newQty :: Mantissa -> Places -> Maybe Qty
- type Mantissa = Integer
- type Places = Integer
- data Difference
- = LeftBiggerBy Qty
- | RightBiggerBy Qty
- | Equal
- allocate :: Qty -> NonEmpty Qty -> NonEmpty Qty
- newtype Tag = Tag {}
- newtype Tags = Tags {}
- newtype TopLineLine = TopLineLine {
- unTopLineLine :: Int
- newtype TopMemoLine = TopMemoLine {
- unTopMemoLine :: Int
- data Side
- data SpaceBetween
- newtype Filename = Filename {
- unFilename :: Text
- newtype PriceLine = PriceLine {
- unPriceLine :: Int
- newtype PostingLine = PostingLine {
- unPostingLine :: Int
- newtype GlobalPosting = GlobalPosting {}
- newtype FilePosting = FilePosting {}
- newtype GlobalTransaction = GlobalTransaction {}
- newtype FileTransaction = FileTransaction {}
Accounts
newtype SubAccount Source
Account | |
|
Amounts
Commodities
DateTime
data TimeZoneOffset Source
The number of minutes that this timezone is offset from UTC. Can be positive, negative, or zero.
minsToOffset :: Int -> Maybe TimeZoneOffsetSource
Convert minutes to a time zone offset. I'm having a hard time deciding whether to be liberal or strict in what to accept here. Currently it is somewhat strict in that it will fail if absolute value is greater than 840 minutes; currently the article at http:en.wikipedia.orgwikiList_of_time_zones_by_UTC_offset says there is no offset greater than 14 hours, or 840 minutes.
intToHours :: Int -> Maybe HoursSource
succeeds if 0 <= x < 24
intToMinutes :: Int -> Maybe MinutesSource
succeeds if 0 <= x < 60
intToSeconds :: Int -> Maybe SecondsSource
succeeds if 0 <= x < 61 (to allow for leap seconds)
A DateTime is a a local date and time, along with a time zone
offset. The Eq and Ord instances are derived; therefore, two
DateTime instances will not be equivalent if the time zone offsets
are different, even if they are the same instant. To compare one
DateTime to another, you probably want to use toUTC
and compare
those. To see if two DateTime are the same instant, use
sameInstant
.
sameInstant :: DateTime -> DateTime -> BoolSource
Are these DateTimes the same instant in time, after adjusting for local timezones?
showDateTime :: DateTime -> StringSource
Shows a DateTime in a pretty way.
Debits and Credits
Entries
Flag
Memos
There is one item in the list for each line of the memo. Do not include newlines in the texts themselves. However there is nothing to enforce this convention.
Number
Payee
Prices and price points
newtype CountPerUnit Source
convert :: Price -> Amount -> Maybe AmountSource
Convert an amount from the From price to the To price. Fails if the From commodity in the Price is not the same as the commodity in the Amount.
newPrice :: From -> To -> CountPerUnit -> Maybe PriceSource
Succeeds only if From and To are different commodities.
Quantities
A quantity is always greater than zero. Various odd questions happen if quantities can be zero. For instance, what if you have a debit whose quantity is zero? Does it require a balancing credit that is also zero? And how can you have a debit of zero anyway?
I can imagine situations where a quantity of zero might be useful; for instance maybe you want to specifically indicate that a particular posting in a transaction did not happen (for instance, that a paycheck deduction did not take place). I think the better way to handle that though would be through an addition to DebitCredit - maybe DebitCredit/Zero. Barring the addition of that, though, the best way to indicate a situation such as this would be through transaction memos.
The Eq instance is derived. Therefore q1 == q2 only if q1 and q2
have both the same mantissa and the same exponent. You may instead
want equivalent
.
Whole String | A whole number only. No radix point. |
WholeRad String | A whole number and a radix point, but nothing after the radix point. |
WholeRadFrac String String | A whole number and something after the radix point. |
RadFrac String | A radix point and a fractional value after it, but nothing before the radix point. |
toQty :: NumberStr -> Maybe QtySource
Converts strings to Qty. Fails if any of the strings have non-digits, or if any are negative, or if the result is not greater than zero, or if the strings are empty.
difference :: Qty -> Qty -> DifferenceSource
Subtract the second Qty from the first, after equalizing their exponents.
equivalent :: Qty -> Qty -> BoolSource
Compares Qty after equalizing their exponents.
:: Qty | The result will add up to this Qty. |
-> NonEmpty Qty | Allocate using this list of Qty. |
-> NonEmpty Qty | The length of this list will be equal to the length of the list of allocations. Each item will correspond to the original allocation. |
Allocate a Qty proportionally so that the sum of the results adds up to a given Qty. Fails if the allocation cannot be made (e.g. if it is impossible to allocate without overflowing Decimal.) The result will always add up to the given sum.
Tags
Metadata
newtype TopLineLine Source
The line number that the TopLine starts on (excluding the memo accompanying the TopLine).
newtype TopMemoLine Source
The line number that the memo accompanying the TopLine starts on.
The commodity and and the quantity may appear with the commodity on the left (e.g. USD 2.14) or with the commodity on the right (e.g. 2.14 USD).
data SpaceBetween Source
There may or may not be a space in between the commodity and the quantity.
The name of the file in which a transaction appears.
The line number on which a price appears.
newtype PostingLine Source
The line number on which a posting appears.
newtype GlobalPosting Source
All postings are numbered in order, beginning with the first posting in the first file and ending with the last posting in the last file.
newtype FilePosting Source
The postings in each file are numbered in order.
newtype GlobalTransaction Source
All transactions are numbered in order, beginning with the first transaction in the first file and ending with the last transaction in the last file.
newtype FileTransaction Source
The transactions in each file are numbered in order.