Sisällytä erittelyt siirtoihin
This commit is contained in:
parent
f03829a294
commit
0b5dbbd133
@ -1,5 +1,6 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
|
|
||||||
module Data.TITO.Parser where
|
module Data.TITO.Parser where
|
||||||
|
|
||||||
@ -143,18 +144,20 @@ titoRoot = record "00" $ do
|
|||||||
return TITORoot {..}
|
return TITORoot {..}
|
||||||
|
|
||||||
titoRecord :: Parser TITORecord
|
titoRecord :: Parser TITORecord
|
||||||
titoRecord = P.try (transaction' False)
|
titoRecord = P.try (transaction False)
|
||||||
<|> P.try (transactionDetail' False)
|
|
||||||
<|> P.try balance
|
<|> P.try balance
|
||||||
<|> P.try summary
|
<|> P.try summary
|
||||||
<|> P.try fixSummary
|
<|> P.try fixSummary
|
||||||
<|> P.try special
|
<|> P.try special
|
||||||
<|> P.try info
|
<|> P.try info
|
||||||
<|> P.try (transaction' True)
|
<|> P.try (transaction True)
|
||||||
<|> P.try (transactionDetail' True)
|
|
||||||
|
|
||||||
transaction' :: Bool -> Parser TITORecord
|
transaction :: Bool -> Parser TITORecord
|
||||||
transaction' isInformational = record (if isInformational then "80" else "10") $ do
|
transaction = fmap . TransactionRecord <*> transaction' 0
|
||||||
|
|
||||||
|
transaction' :: Int -> Bool -> Parser Transaction
|
||||||
|
transaction' minimumDepth isInformational = do
|
||||||
|
(depth, transaction) <- record (if isInformational then "80" else "10") $ do
|
||||||
transactionNumber <- numeric 6
|
transactionNumber <- numeric 6
|
||||||
archiveId <- optional' alphaNumeric 18
|
archiveId <- optional' alphaNumeric 18
|
||||||
parsedDate <- date
|
parsedDate <- date
|
||||||
@ -172,15 +175,19 @@ transaction' isInformational = record (if isInformational then "80" else "10") $
|
|||||||
accountChanged <- optional' alphaNumeric 1
|
accountChanged <- optional' alphaNumeric 1
|
||||||
reference <- optional' numeric 20
|
reference <- optional' numeric 20
|
||||||
formNumber <- optional' alphaNumeric 8
|
formNumber <- optional' alphaNumeric 8
|
||||||
depth <- alphaNumeric 1
|
depth <- fromIntegral <$> numeric 1 <|> const 0 <$> P.char 32 -- space
|
||||||
return Transaction {date = parsedDate, ..}
|
guard $ depth >= minimumDepth
|
||||||
|
return (depth, Transaction {details = [], itemisation = [], date = parsedDate, ..})
|
||||||
|
details <- P.many $ P.try $ transactionDetail' isInformational
|
||||||
|
itemisation <- P.many $ P.try $ transaction' (depth + 1) isInformational
|
||||||
|
pure $ transaction {details, itemisation}
|
||||||
|
|
||||||
transactionDetail' :: Bool -> Parser TITORecord
|
transactionDetail' :: Bool -> Parser TransactionDetail
|
||||||
transactionDetail' isInformational =
|
transactionDetail' isInformational =
|
||||||
record' (if isInformational then "81" else "11") $ \recordLength -> do
|
record' (if isInformational then "81" else "11") $ \recordLength -> do
|
||||||
let detailLength = recordLength - 8
|
let detailLength = recordLength - 8
|
||||||
detailType <- optional' alphaNumeric 2
|
detailType <- optional' alphaNumeric 2
|
||||||
detail <- case detailType of
|
case detailType of
|
||||||
Just "00" -> do
|
Just "00" -> do
|
||||||
first <- alphaNumeric 35
|
first <- alphaNumeric 35
|
||||||
rest <- P.count' 0 11 (optional' alphaNumeric 35)
|
rest <- P.count' 0 11 (optional' alphaNumeric 35)
|
||||||
@ -220,7 +227,6 @@ transactionDetail' isInformational =
|
|||||||
archiveId <- optional' alphaNumeric 35
|
archiveId <- optional' alphaNumeric 35
|
||||||
pure SEPA {..}
|
pure SEPA {..}
|
||||||
_ -> Unknown <$> alphaNumeric detailLength
|
_ -> Unknown <$> alphaNumeric detailLength
|
||||||
pure TransactionDetail {..}
|
|
||||||
|
|
||||||
balance :: Parser TITORecord
|
balance :: Parser TITORecord
|
||||||
balance = record "40" $ do
|
balance = record "40" $ do
|
||||||
|
@ -34,31 +34,9 @@ data TITORoot = TITORoot -- T00
|
|||||||
, ibanAndBic :: Maybe (Text, Text)
|
, ibanAndBic :: Maybe (Text, Text)
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
data TITORecord = Transaction -- T80 if isInformational, else T10
|
data TITORecord = TransactionRecord -- T80 if isInformational, else T10
|
||||||
{ isInformational :: Bool
|
{ isInformational :: Bool
|
||||||
, transactionNumber :: Integer
|
, transaction :: Transaction
|
||||||
, archiveId :: Maybe Text
|
|
||||||
, date :: Day
|
|
||||||
, valueDate :: Maybe Day
|
|
||||||
, paymentDate :: Maybe Day
|
|
||||||
, transactionType :: TransactionType
|
|
||||||
, descriptionCode :: Text
|
|
||||||
, descriptionText :: Text
|
|
||||||
, amount :: Money
|
|
||||||
, receiptCode :: Text
|
|
||||||
, transferMethod :: Text
|
|
||||||
, payeeName :: Maybe Text
|
|
||||||
, nameSource :: Maybe NameSource
|
|
||||||
, recipientAccount :: Maybe Text
|
|
||||||
, accountChanged :: Maybe Text
|
|
||||||
, reference :: Maybe Integer
|
|
||||||
, formNumber :: Maybe Text
|
|
||||||
, depth :: Text
|
|
||||||
}
|
|
||||||
| TransactionDetail -- T81 if isInformational, else T11
|
|
||||||
{ isInformational :: Bool
|
|
||||||
, detailType :: Maybe Text
|
|
||||||
, detail :: TransactionDetail
|
|
||||||
}
|
}
|
||||||
| Balance -- T40
|
| Balance -- T40
|
||||||
{ date :: Day
|
{ date :: Day
|
||||||
@ -91,6 +69,28 @@ data TITORecord = Transaction -- T80 if isInformational, else T10
|
|||||||
}
|
}
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
data Transaction = Transaction
|
||||||
|
{ transactionNumber :: Integer
|
||||||
|
, archiveId :: Maybe Text
|
||||||
|
, date :: Day
|
||||||
|
, valueDate :: Maybe Day
|
||||||
|
, paymentDate :: Maybe Day
|
||||||
|
, transactionType :: TransactionType
|
||||||
|
, descriptionCode :: Text
|
||||||
|
, descriptionText :: Text
|
||||||
|
, amount :: Money
|
||||||
|
, receiptCode :: Text
|
||||||
|
, transferMethod :: Text
|
||||||
|
, payeeName :: Maybe Text
|
||||||
|
, nameSource :: Maybe NameSource
|
||||||
|
, recipientAccount :: Maybe Text
|
||||||
|
, accountChanged :: Maybe Text
|
||||||
|
, reference :: Maybe Integer
|
||||||
|
, formNumber :: Maybe Text
|
||||||
|
, details :: [TransactionDetail]
|
||||||
|
, itemisation :: [Transaction]
|
||||||
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
data TransactionDetail = Freeform (NonEmpty Text) -- 00
|
data TransactionDetail = Freeform (NonEmpty Text) -- 00
|
||||||
| Number Integer -- 01
|
| Number Integer -- 01
|
||||||
| Invoice -- 02
|
| Invoice -- 02
|
||||||
|
Loading…
Reference in New Issue
Block a user