Sisällytä desimaalitieto rahan Money-tietotyyppiin
This commit is contained in:
parent
24fe93cd90
commit
c7a512175c
@ -19,7 +19,8 @@
|
||||
#:recursive? #t
|
||||
#:select? vcs-file?))
|
||||
(build-system haskell-build-system)
|
||||
(inputs (list ghc-megaparsec))
|
||||
(inputs (list ghc-megaparsec
|
||||
ghc-decimal))
|
||||
(home-page "https://git.olarinmaensamoojat.fi/OMS/tito")
|
||||
(synopsis "TITO parsing library")
|
||||
(description "")
|
||||
|
@ -9,6 +9,7 @@ import Data.Maybe
|
||||
import Control.Monad
|
||||
|
||||
import Data.Char (isSpace)
|
||||
import Data.Decimal (DecimalRaw(Decimal))
|
||||
import Data.Text (Text)
|
||||
import Data.Void (Void)
|
||||
import Text.Megaparsec ((<|>))
|
||||
@ -80,7 +81,7 @@ money = do
|
||||
sign <- P.label "+ or -" $ P.oneOf [43, 45] -- +, -
|
||||
let setSign | sign == 43 = id
|
||||
| sign == 45 = negate
|
||||
Money . setSign <$> numeric 18
|
||||
Money . Decimal 2 . setSign <$> numeric 18
|
||||
|
||||
optional :: Int -> Parser a -> Parser (Maybe a)
|
||||
optional n p = P.try (P.count n (P.char 32) *> pure Nothing) <|> (Just <$> p)
|
||||
@ -133,7 +134,7 @@ accountStatement = do
|
||||
_records <- optional' numeric 6
|
||||
currency <- optional' alphaNumeric 3
|
||||
accountName <- optional' alphaNumeric 30
|
||||
accountLimit <- fmap Money <$> optional' numeric 18
|
||||
accountLimit <- fmap (Money . Decimal 2) <$> optional' numeric 18
|
||||
accountOwnerName <- alphaNumeric 35
|
||||
bankName <- alphaNumeric 40
|
||||
contactInformation <- optional' alphaNumeric 40
|
||||
|
@ -7,6 +7,7 @@ import Data.ByteString (ByteString)
|
||||
import Data.Text (Text)
|
||||
import Data.Time (Day, LocalTime)
|
||||
import Data.List.NonEmpty (NonEmpty)
|
||||
import Data.Decimal (Decimal)
|
||||
|
||||
data AccountStatement = AccountStatement
|
||||
{ account :: Text
|
||||
@ -28,7 +29,7 @@ data AccountStatement = AccountStatement
|
||||
, events :: [Event]
|
||||
} deriving (Show, Eq)
|
||||
|
||||
newtype Money = Money Integer deriving (Eq, Show)
|
||||
newtype Money = Money Decimal deriving (Eq, Show)
|
||||
|
||||
data Event = BasicTransaction Transaction -- T10
|
||||
| TransactionNotification Transaction -- T80
|
||||
|
@ -12,6 +12,7 @@ library
|
||||
base,
|
||||
bytestring,
|
||||
containers,
|
||||
Decimal,
|
||||
megaparsec,
|
||||
text,
|
||||
time
|
||||
|
Loading…
Reference in New Issue
Block a user