module Penny.Lincoln.Bits.Open where
import Data.List (sort)
import Data.Monoid ((<>))
import Data.Text (Text)
import qualified Data.Text as X
import qualified Penny.Lincoln.Equivalent as Ev
import Penny.Lincoln.Equivalent ((==~))
import qualified Penny.Lincoln.Serial as S
newtype SubAccount =
SubAccount { unSubAccount :: Text }
deriving (Eq, Ord, Show)
newtype Account = Account { unAccount :: [SubAccount] }
deriving (Eq, Show, Ord)
data Amount q = Amount
{ qty :: q
, commodity :: Commodity }
deriving (Eq, Show, Ord)
instance Functor Amount where
fmap f (Amount q c) = Amount (f q) c
instance Ev.Equivalent q => Ev.Equivalent (Amount q) where
equivalent (Amount q1 c1) (Amount q2 c2) =
q1 ==~ q2 && c1 == c2
compareEv (Amount q1 c1) (Amount q2 c2) =
Ev.compareEv q1 q2 <> c1 `compare` c2
newtype Commodity =
Commodity { unCommodity :: Text }
deriving (Eq, Ord, Show)
data DrCr = Debit | Credit deriving (Eq, Show, Ord)
opposite :: DrCr -> DrCr
opposite d = case d of
Debit -> Credit
Credit -> Debit
data Entry q = Entry
{ drCr :: DrCr
, amount :: Amount q }
deriving (Eq, Show, Ord)
instance Functor Entry where
fmap f (Entry d a) = Entry d (fmap f a)
instance Ev.Equivalent q => Ev.Equivalent (Entry q) where
equivalent (Entry d1 a1) (Entry d2 a2) =
d1 == d2 && a1 ==~ a2
compareEv (Entry d1 a1) (Entry d2 a2) =
d1 `compare` d2 <> Ev.compareEv a1 a2
newtype Flag = Flag { unFlag :: Text }
deriving (Eq, Show, Ord)
newtype Memo = Memo { unMemo :: [Text] }
deriving (Eq, Show, Ord)
newtype Number = Number { unNumber :: Text }
deriving (Eq, Show, Ord)
newtype Payee = Payee { unPayee :: Text }
deriving (Eq, Show, Ord)
newtype Tag = Tag { unTag :: Text }
deriving (Eq, Show, Ord)
newtype Tags = Tags { unTags :: [Tag] }
deriving (Eq, Show, Ord)
instance Ev.Equivalent Tags where
equivalent (Tags t1) (Tags t2) = sort t1 == sort t2
compareEv (Tags t1) (Tags t2) =
compare (sort t1) (sort t2)
newtype TopLineLine = TopLineLine { unTopLineLine :: Int }
deriving (Eq, Show)
newtype TopMemoLine = TopMemoLine { unTopMemoLine :: Int }
deriving (Eq, Show)
data Side
= CommodityOnLeft
| CommodityOnRight
deriving (Eq, Show, Ord)
instance Ev.Equivalent Side where
equivalent = (==)
compareEv = compare
data SpaceBetween
= SpaceBetween
| NoSpaceBetween
deriving (Eq, Show, Ord)
instance Ev.Equivalent SpaceBetween where
equivalent = (==)
compareEv = compare
newtype Filename = Filename { unFilename :: X.Text }
deriving (Eq, Show)
newtype PriceLine = PriceLine { unPriceLine :: Int }
deriving (Eq, Show)
newtype PostingLine = PostingLine { unPostingLine :: Int }
deriving (Eq, Show)
newtype GlobalPosting =
GlobalPosting { unGlobalPosting :: S.Serial }
deriving (Eq, Show)
newtype FilePosting =
FilePosting { unFilePosting :: S.Serial }
deriving (Eq, Show)
newtype GlobalTransaction =
GlobalTransaction { unGlobalTransaction :: S.Serial }
deriving (Eq, Show)
newtype FileTransaction =
FileTransaction { unFileTransaction :: S.Serial }
deriving (Eq, Show)