packages feed

national-australia-bank-0.0.10: src/Data/Bank/NationalAustraliaBank/Report.hs

{-# OPTIONS_GHC -Wall #-}

module Data.Bank.NationalAustraliaBank.Report where

import Data.Bank.NationalAustraliaBank.Transaction
    ( Transaction,
      Amount,
      Date,
      diffDates,
      realAmount,
      date',
      amount' )
import Data.Ratio ( Ratio )

cumulativeSumTransactions ::
  [Transaction]
  -> [Amount]
cumulativeSumTransactions [] =
  []
cumulativeSumTransactions (h:t) =
  scanl (\a t' -> amount' t' <> a) (amount' h) t

cumulativeDays ::
  [Transaction]
  -> [Integer]
cumulativeDays [] =
  []
cumulativeDays r@(h:_) =
  cumulativeDays' (date' h) r

cumulativeDays' ::
  Date
  -> [Transaction]
  -> [Integer]
cumulativeDays' d =
  fmap (\t -> d `diffDates` date' t + 1)

cumulativePerDay ::
  [Transaction]
  -> [Ratio Integer]
cumulativePerDay [] =
  []
cumulativePerDay r@(h:_) =
  cumulativePerDay' (date' h) r

cumulativePerDay' ::
  Date
  -> [Transaction]
  -> [Ratio Integer]
cumulativePerDay' dt txs =
  zipWith (\a i -> realAmount a / fromInteger i) (cumulativeSumTransactions txs) (cumulativeDays' dt txs)