penny-lib-0.12.0.0: Extensible double-entry accounting system - library

Safe HaskellNone

Penny.Lincoln.Bits

Contents

Description

Essential data types used to make Transactions and Postings.

Synopsis

Accounts

newtype Account Source

Constructors

Account 

Fields

unAccount :: [SubAccount]
 

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.

data Hours Source

Instances

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)

data DateTime Source

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.

Constructors

DateTime 

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

data DrCr Source

Constructors

Debit 
Credit 

Instances

opposite :: DrCr -> DrCrSource

Debit returns Credit; Credit returns Debit

Entries

data Entry Source

Constructors

Entry 

Fields

drCr :: DrCr
 
amount :: Amount
 

Instances

Flag

newtype Flag Source

Constructors

Flag 

Fields

unFlag :: Text
 

Memos

newtype Memo Source

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.

Constructors

Memo 

Fields

unMemo :: [Text]
 

Number

newtype Number Source

Constructors

Number 

Fields

unNumber :: Text
 

Payee

newtype Payee Source

Constructors

Payee 

Fields

unPayee :: Text
 

Prices and price points

newtype From Source

Constructors

From 

Fields

unFrom :: Commodity
 

Instances

newtype To Source

Constructors

To 

Fields

unTo :: Commodity
 

Instances

data Price Source

Instances

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

data Qty Source

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.

Instances

Eq Qty 
Ord Qty

Compares Qty after equalizing their exponents.

 compare (newQty 15 1) (newQty 1500 3) == EQ
Show Qty

Shows a quantity, nicely formatted after accounting for both the mantissa and decimal places, e.g. 0.232 or 232.12 or whatever.

data NumberStr Source

Constructors

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.

Instances

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.

add :: Qty -> Qty -> QtySource

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.

allocateSource

Arguments

:: 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

newtype Tag Source

Constructors

Tag 

Fields

unTag :: Text
 

Instances

newtype Tags Source

Constructors

Tags 

Fields

unTags :: [Tag]
 

Metadata

newtype TopLineLine Source

The line number that the TopLine starts on (excluding the memo accompanying the TopLine).

Constructors

TopLineLine 

Fields

unTopLineLine :: Int
 

newtype TopMemoLine Source

The line number that the memo accompanying the TopLine starts on.

Constructors

TopMemoLine 

Fields

unTopMemoLine :: Int
 

data Side Source

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).

Instances

data SpaceBetween Source

There may or may not be a space in between the commodity and the quantity.

newtype Filename Source

The name of the file in which a transaction appears.

Constructors

Filename 

Fields

unFilename :: Text
 

newtype PriceLine Source

The line number on which a price appears.

Constructors

PriceLine 

Fields

unPriceLine :: Int
 

newtype PostingLine Source

The line number on which a posting appears.

Constructors

PostingLine 

Fields

unPostingLine :: Int
 

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.

Constructors

GlobalPosting 

newtype FilePosting Source

The postings in each file are numbered in order.

Constructors

FilePosting 

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.

Constructors

FileTransaction