Sisällytä erittelyt siirtoihin

This commit is contained in:
Saku Laesvuori 2025-07-19 13:12:22 +03:00
parent f03829a294
commit 0b5dbbd133
Signed by: slaesvuo
GPG Key ID: 257D284A2A1D3A32
2 changed files with 97 additions and 91 deletions

View File

@ -1,5 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NamedFieldPuns #-}
module Data.TITO.Parser where
@ -143,18 +144,20 @@ titoRoot = record "00" $ do
return TITORoot {..}
titoRecord :: Parser TITORecord
titoRecord = P.try (transaction' False)
<|> P.try (transactionDetail' False)
titoRecord = P.try (transaction False)
<|> P.try balance
<|> P.try summary
<|> P.try fixSummary
<|> P.try special
<|> P.try info
<|> P.try (transaction' True)
<|> P.try (transactionDetail' True)
<|> P.try (transaction True)
transaction' :: Bool -> Parser TITORecord
transaction' isInformational = record (if isInformational then "80" else "10") $ do
transaction :: Bool -> Parser TITORecord
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
archiveId <- optional' alphaNumeric 18
parsedDate <- date
@ -172,15 +175,19 @@ transaction' isInformational = record (if isInformational then "80" else "10") $
accountChanged <- optional' alphaNumeric 1
reference <- optional' numeric 20
formNumber <- optional' alphaNumeric 8
depth <- alphaNumeric 1
return Transaction {date = parsedDate, ..}
depth <- fromIntegral <$> numeric 1 <|> const 0 <$> P.char 32 -- space
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 =
record' (if isInformational then "81" else "11") $ \recordLength -> do
let detailLength = recordLength - 8
detailType <- optional' alphaNumeric 2
detail <- case detailType of
case detailType of
Just "00" -> do
first <- alphaNumeric 35
rest <- P.count' 0 11 (optional' alphaNumeric 35)
@ -220,7 +227,6 @@ transactionDetail' isInformational =
archiveId <- optional' alphaNumeric 35
pure SEPA {..}
_ -> Unknown <$> alphaNumeric detailLength
pure TransactionDetail {..}
balance :: Parser TITORecord
balance = record "40" $ do

View File

@ -34,31 +34,9 @@ data TITORoot = TITORoot -- T00
, ibanAndBic :: Maybe (Text, Text)
} deriving (Show, Eq)
data TITORecord = Transaction -- T80 if isInformational, else T10
data TITORecord = TransactionRecord -- T80 if isInformational, else T10
{ isInformational :: Bool
, 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
, depth :: Text
}
| TransactionDetail -- T81 if isInformational, else T11
{ isInformational :: Bool
, detailType :: Maybe Text
, detail :: TransactionDetail
, transaction :: Transaction
}
| Balance -- T40
{ date :: Day
@ -91,6 +69,28 @@ data TITORecord = Transaction -- T80 if isInformational, else T10
}
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
| Number Integer -- 01
| Invoice -- 02