packages feed

bookkeeping 0.3.3.0 → 0.4.0.0

raw patch · 2 files changed

+21/−34 lines, 2 filesdep +mono-traversabledep +transactiondep −dlistdep −mtl

Dependencies added: mono-traversable, transaction

Dependencies removed: dlist, mtl

Files

bookkeeping.cabal view
@@ -1,5 +1,5 @@ name:                bookkeeping-version:             0.3.3.0+version:             0.4.0.0 synopsis:            A module for bookkeeping by double entry. description:     A module for bookkeeping by double entry. This module provides a way to do bookkeeping programmatically.@@ -18,10 +18,10 @@   hs-source-dirs:      src   exposed-modules:     Business.Bookkeeping   build-depends:       base >= 4.9 && < 5-                     , dlist >= 0.8.0.2 && < 0.9-                     , mtl >= 2.2.1 && < 2.3+                     , mono-traversable >= 1.0.0.1 && < 1.1                      , text >= 1.2.2.1 && < 1.3                      , time >= 1.6+                     , transaction >= 0.1 && < 0.2   default-language:    Haskell2010   default-extensions:  OverloadedStrings                      , RecordWildCards
src/Business/Bookkeeping.hs view
@@ -37,7 +37,7 @@   , YearTransactions   , MonthTransactions   , DateTransactions-  , Transaction(..)+  , Journal(..)   , Year   , Month   , Date@@ -56,9 +56,6 @@   , CreditCategory(..)   ) where -import Control.Monad.State (State, execState, modify)-import qualified Data.DList as DList-import Data.DList (DList) import Data.Monoid ((<>)) import qualified Data.Semigroup as Sem import Data.String (IsString(..))@@ -66,6 +63,7 @@ import qualified Data.Text as T import qualified Data.Text.IO as T import Data.Time.Calendar (Day, fromGregorian)+import Data.Transaction (Transaction, action, tMap, toList)  {- $setup >>> :{@@ -90,20 +88,16 @@ {-| Convert from 'YearTransactions' to 'Transactions'. -} year :: Year -> YearTransactions -> Transactions-year y =-  modify . flip mappend . fmap ($ y) . toDList+year y = tMap ($ y) -{-| Convert from 'MonthTransactions' to 'YearTransactions'.--}+{-| Convert from 'MonthTransactions' to 'YearTransactions'.  -} month :: Month -> MonthTransactions -> YearTransactions-month m =-  modify . flip mappend . fmap ($ m) . toDList+month m = tMap ($ m)  {-| Convert from 'DateTransactions' to 'MonthTransactions'. -} activity :: Date -> Description -> DateTransactions -> MonthTransactions-activity d desc =-  modify . flip mappend . fmap (($ desc) . ($ d)) . toDList+activity d desc = tMap (($ desc) . ($ d))  dateTrans :: DebitCategory           -> CreditCategory@@ -111,8 +105,8 @@           -> Amount           -> DateTransactions dateTrans debit credit subdesc amount =-  modify . flip mappend . DList.singleton $ \d desc m y ->-    Transaction+  action $ \d desc m y ->+    Journal     { tDay = fromGregorian (unYear y) (unMonth m) (unDate d)     , tDescription = desc     , tSubDescription = subdesc@@ -121,13 +115,10 @@     , tAmount = amount     } -{-| Take list of `Transaction` out from 'Transactions'.+{-| Take list of `Journal` out from 'Transactions'. -}-runTransactions :: Transactions -> [Transaction]-runTransactions = DList.toList . toDList--toDList :: Trans a -> DList a-toDList ts = execState ts mempty+runTransactions :: Transactions -> [Journal]+runTransactions = toList  {-| A pretty printer for `Transactions`. @@ -164,8 +155,8 @@ ppr :: Transactions -> IO () ppr = T.putStr . T.unlines . map format . runTransactions   where-    format :: Transaction -> T.Text-    format Transaction {..} =+    format :: Journal -> T.Text+    format Journal {..} =       T.unlines         [ "tDay: " <> (T.pack . show) tDay         , "tDescription: " <> unDescription tDescription@@ -196,21 +187,17 @@  -     Types  - ============== -} -type Trans a = State (DList a) ()--{-| A type for handling `Transaction` values.- -}-type Transactions = Trans Transaction+type Transactions = Transaction Journal -type YearTransactions = Trans (Year -> Transaction)+type YearTransactions = Transaction (Year -> Journal) -type MonthTransactions = Trans (Month -> Year -> Transaction)+type MonthTransactions = Transaction (Month -> Year -> Journal) -type DateTransactions = Trans (Date -> Description -> Month -> Year -> Transaction)+type DateTransactions = Transaction (Date -> Description -> Month -> Year -> Journal)  {-| A type representing a transaction.  -}-data Transaction = Transaction+data Journal = Journal   { tDay :: Day   , tDescription :: Description   , tSubDescription :: SubDescription