packages feed

hledger-interest 1.5.3 → 1.5.4

raw patch · 4 files changed

+58/−43 lines, 4 files

Files

Hledger/Interest/Rate.hs view
@@ -1,8 +1,9 @@-module Hledger.Interest.Rate ( Rate, perAnno, constant, bgb288, ingDiba, db24 ) where+module Hledger.Interest.Rate ( Rate, perAnno, perAnnoSchedule, constant, bgb288, ingDiba, db24 ) where  import Data.Time.Calendar import Data.Time.Calendar.OrdinalDate import Data.Decimal+import Data.List (sortOn)  type Rate = Day -> (Day,Decimal) @@ -10,10 +11,19 @@ constant rate _ = (day 999999 12 31, rate)  perAnno :: Decimal -> Rate-perAnno rate date = (day (fst (toOrdinalDate date)) 12 31, rate)+perAnno rate date = (yearEnd date, rate) +perAnnoSchedule :: [(Day,Decimal)] -> Rate+perAnnoSchedule schedule date = (yearEnd date, effectiveRate)+  where+    (_, effectiveRate) = last $ takeWhile (\(fromDate, _) -> fromDate<date) sortedSchedule+    sortedSchedule = sortOn fst schedule+         day :: Integer -> Int -> Int -> Day day = fromGregorian++yearEnd :: Day -> Day+yearEnd date = day (fst (toOrdinalDate date)) 12 31  bgb288 :: Rate bgb288 = basiszins (5/100)
Main.hs view
@@ -8,7 +8,6 @@ import Control.Monad import Data.List import Data.Maybe-import Data.Ord import qualified Data.Text as T import Data.Version import System.Console.GetOpt@@ -52,7 +51,7 @@  , Option ['v'] ["verbose"]           (NoArg (\o -> o { optVerbose = True }))                              "echo input ledger to stdout (default)"  , Option ['q'] ["quiet"]             (NoArg (\o -> o { optVerbose = False }))                             "don't echo input ledger to stdout"  , Option []    ["today"]             (NoArg (\o -> o { optBalanceToday = True }))                         "compute interest up until today"- , Option ['f'] ["file"]              (ReqArg (\f o -> o { optInput = f : (optInput o) }) "FILE")          "input ledger file (pass '-' for stdin)"+ , Option ['f'] ["file"]              (ReqArg (\f o -> o { optInput = f : optInput o }) "FILE")          "input ledger file (pass '-' for stdin)"  , Option ['s'] ["source"]            (ReqArg (\a o -> o { optSourceAcc = a }) "ACCOUNT")                  "interest source account"  , Option ['t'] ["target"]            (ReqArg (\a o -> o { optTargetAcc = a }) "ACCOUNT")                  "interest target account"  , Option ['I'] ["ignore-assertions"] (NoArg (\o -> o { optIgnoreAssertions = True }))                     "ignore any failing balance assertions"@@ -62,6 +61,7 @@  , Option []    ["30E-360isda"]       (NoArg (\o -> o { optDCC = Just diff30E_360isda }))                  "use '30E/360isda' day counting convention"  , Option []    ["constant"]          (ReqArg (\r o -> o { optRate = Just (constant (read r)) }) "RATE")   "constant interest rate"  , Option []    ["annual"]            (ReqArg (\r o -> o { optRate = Just (perAnno (read r)) }) "RATE")    "annual interest rate"+ , Option []    ["annual-schedule"]   (ReqArg (\r o -> o { optRate = Just (perAnnoSchedule (read r)) })    "SCHEDULE")    "schedule of annual interest rates.\nsyntax: '[(Date1,Rate1),(Date2,Rate2),...]'"  , Option []    ["bgb288"]            (NoArg (\o -> o { optRate = Just bgb288, optDCC = Just diffAct }))   "compute interest according to German BGB288"  , Option []    ["db24"]              (NoArg (\o -> o { optRate = Just db24, optDCC = Just diff30E_360 })) "HACK: Deutsche Bank 24"  , Option []    ["ing-diba"]          (NoArg (\o -> o { optRate = Just ingDiba, optDCC = Just diffAct }))  "HACK: compute interest according for Ing-Diba Tagesgeld account"@@ -90,13 +90,14 @@   when (null (optTargetAcc opts)) (commandLineError "required --target option is missing\n")   when (isNothing (optDCC opts)) (commandLineError "no day counting convention specified\n")   when (isNothing (optRate opts)) (commandLineError "no interest rate specified\n")-  when (length args < 1) (commandLineError "required argument ACCOUNT is missing\n")-  when (length args > 1) (commandLineError "only one interest ACCOUNT may be specified\n")   let ledgerInputOptions = definputopts { ignore_assertions_ = optIgnoreAssertions opts }   jnl' <- readJournalFiles ledgerInputOptions (reverse (optInput opts)) >>= either fail return-  let [interestAcc] = args-      jnl = filterJournalTransactions (Acct interestAcc) jnl'-      ts  = sortBy (comparing tdate) (jtxns jnl)+  interestAcc <- case args of+                   []    -> commandLineError "required argument ACCOUNT is missing\n"+                   [acc] -> return acc+                   _     -> commandLineError "only one interest ACCOUNT may be specified\n"+  let jnl = filterJournalTransactions (Acct interestAcc) jnl'+      ts  = sortOn tdate (jtxns jnl)       cfg = Config             { interestAccount = T.pack interestAcc             , sourceAccount = T.pack (optSourceAcc opts)@@ -112,4 +113,4 @@       result         | optVerbose opts = ts' ++ ts         | otherwise       = ts'-  mapM_ (putStr . showTransaction) (sortBy (comparing tdate) result)+  mapM_ (putStr . showTransactionUnelided) (sortOn tdate result)
README.md view
@@ -17,19 +17,21 @@ running "`hleder-interest --help`":      Usage: hledger-interest [OPTION...] ACCOUNT-      -v          --verbose         echo input ledger to stdout (default)-      -q          --quiet           don't echo input ledger to stdout-                  --today           compute interest up until today-      -f FILE     --file=FILE       input ledger file (pass '-' for stdin)-      -s ACCOUNT  --source=ACCOUNT  interest source account-      -t ACCOUNT  --target=ACCOUNT  interest target account-                  --act             use 'act' day counting convention-                  --30-360          use '30/360' day counting convention-                  --30E-360         use '30E/360' day counting convention-                  --30E-360isda     use '30E/360isda' day counting convention-                  --constant=RATE   constant interest rate-                  --annual=RATE     annual interest rate-                  --bgb288          compute interest according to German BGB288+      -v          --verbose                   echo input ledger to stdout (default)+      -q          --quiet                     don't echo input ledger to stdout+                  --today                     compute interest up until today+      -f FILE     --file=FILE                 input ledger file (pass '-' for stdin)+      -s ACCOUNT  --source=ACCOUNT            interest source account+      -t ACCOUNT  --target=ACCOUNT            interest target account+                  --act                       use 'act' day counting convention+                  --30-360                    use '30/360' day counting convention+                  --30E-360                   use '30E/360' day counting convention+                  --30E-360isda               use '30E/360isda' day counting convention+                  --constant=RATE             constant interest rate+                  --annual=RATE               annual interest rate+                  --annual-schedule=SCHEDULE  schedule of annual interest rates.+                                              syntax: '[(Date1,Rate1),(Date2,Rate2),...]'+                  --bgb288                    compute interest according to German BGB288  When run, hledger-interest reads the [ledger file](http://hledger.org/MANUAL.html#file-format) designated by the
hledger-interest.cabal view
@@ -1,17 +1,18 @@ Name:                   hledger-interest-Version:                1.5.3+Version:                1.5.4 Synopsis:               computes interest for a given account License:                BSD3 License-file:           LICENSE Author:                 Peter Simons <simons@cryp.to> Maintainer:             Peter Simons <simons@cryp.to>-Homepage:               http://github.com/peti/hledger-interest+Homepage:               https://github.com/peti/hledger-interest Category:               Finance Build-type:             Simple Cabal-version:          >= 1.6 Extra-source-files:     README.md Stability:              stable-tested-with:            GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.3, GHC == 8.6.1+tested-with:            GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5+                      , GHC == 8.8.3, GHC == 8.10.1  Description:  hledger-interest is a small command-line utility based on Simon@@ -92,22 +93,24 @@  available options:  .  > Usage: hledger-interest [OPTION...] ACCOUNT- >   -h          --help               print this message and exit- >   -V          --version            show version number and exit- >   -v          --verbose            echo input ledger to stdout (default)- >   -q          --quiet              don't echo input ledger to stdout- >               --today              compute interest up until today- >   -f FILE     --file=FILE          input ledger file (pass '-' for stdin)- >   -s ACCOUNT  --source=ACCOUNT     interest source account- >   -t ACCOUNT  --target=ACCOUNT     interest target account- >   -I          --ignore-assertions  ignore any failing balance assertions- >               --act                use 'act' day counting convention- >               --30-360             use '30/360' day counting convention- >               --30E-360            use '30E/360' day counting convention- >               --30E-360isda        use '30E/360isda' day counting convention- >               --constant=RATE      constant interest rate- >               --annual=RATE        annual interest rate- >               --bgb288             compute interest according to German BGB288+ >   -h          --help                      print this message and exit+ >   -V          --version                   show version number and exit+ >   -v          --verbose                   echo input ledger to stdout (default)+ >   -q          --quiet                     don't echo input ledger to stdout+ >               --today                     compute interest up until today+ >   -f FILE     --file=FILE                 input ledger file (pass '-' for stdin)+ >   -s ACCOUNT  --source=ACCOUNT            interest source account+ >   -t ACCOUNT  --target=ACCOUNT            interest target account+ >   -I          --ignore-assertions         ignore any failing balance assertions+ >               --act                       use 'act' day counting convention+ >               --30-360                    use '30/360' day counting convention+ >               --30E-360                   use '30E/360' day counting convention+ >               --30E-360isda               use '30E/360isda' day counting convention+ >               --constant=RATE             constant interest rate+ >               --annual-schedule=SCHEDULE  schedule of annual interest rates.+ >                                           syntax: '[(Date1,Rate1),(Date2,Rate2),...]'+ >               --annual=RATE               annual interest rate+ >               --bgb288                    compute interest according to German BGB288  Source-Repository head   Type:                 git@@ -120,4 +123,3 @@                         Hledger.Interest.DayCountConvention                         Hledger.Interest.Rate                         Paths_hledger_interest-  Ghc-Options:          -Wall