ADD comment and tags to txgetter

This commit is contained in:
Nathan Dwarshuis 2023-06-17 00:16:01 -04:00
parent 5858e2f8ce
commit c18750d600
4 changed files with 109 additions and 99 deletions

View File

@ -483,31 +483,24 @@ let TxSubGetter =
{- {-
A means for transforming one row in a statement to a transaction A means for transforming one row in a statement to a transaction
-} -}
{ tsgFromAcnt : { Type =
{- { tsgFromAcnt : EntryAcntGetter
-} , tsgToAcnt : EntryAcntGetter
EntryAcntGetter , tsgValue : EntryNumGetter
, tsgToAcnt : , tsgCurrency : EntryCurGetter
{- , tsgFromEntries : List EntryGetter.Type
-} , tsgFromComment : Text
EntryAcntGetter , tsgToComment : Text
, tsgValue : , tsgFromTags : List TagID
{- , tsgToTags : List TagID
-} , tsgToEntries : List EntryGetter.Type
EntryNumGetter }
, tsgCurrency : , default =
{- { tsgFromTags = [] : List TagID
-} , tsgToTags = [] : List TagID
EntryCurGetter , tsgFromComment = ""
, tsgFromEntries : , tsgToComment = ""
{- }
-}
List EntryGetter.Type
, tsgToEntries :
{-
A means of getting entries for this transaction (minimum 1)
-}
List EntryGetter.Type
} }
let TxGetter = let TxGetter =
@ -531,48 +524,61 @@ let TxGetter =
rules for this type regarding balancing and splitting value. rules for this type regarding balancing and splitting value.
-} -}
{ tgFromAcnt : { Type =
{- { tgFromAcnt :
Account from which this transaction will be balanced. The value of {-
the transaction will be assigned to this account unless other from Account from which this transaction will be balanced. The value of
entries are specified (see below). the transaction will be assigned to this account unless other from
-} entries are specified (see below).
EntryAcntGetter -}
, tgToAcnt : EntryAcntGetter
{- , tgToAcnt :
Account from which this transaction will be balanced. The value of {-
the transaction will be assigned to this account unless other from Account from which this transaction will be balanced. The value of
entries are specified (see below). the transaction will be assigned to this account unless other from
-} entries are specified (see below).
EntryAcntGetter -}
, tgCurrency : EntryAcntGetter
{- , tgFromComment : Text
Currency to assign to the account/value denoted by 'tgFromAcnt' , tgToComment : Text
above. , tgFromTags : List TagID
-} , tgToTags : List TagID
EntryCurGetter , tgCurrency :
, tgFromEntries : {-
{- Currency to assign to the account/value denoted by 'tgFromAcnt'
Means of getting additional entries from which this transaction will above.
be balanced (minimum 0). If this list is empty, the total value of the -}
transaction will be assigned to the value defined by 'tgFromAcnt'. EntryCurGetter
Otherwise, the entries specified here will be added to the credit side , tgFromEntries :
of this transaction, and their sum value will be subtracted from the {-
total value of the transaction and assigned to 'tgFromAcnt'. Means of getting additional entries from which this transaction will
be balanced (minimum 0). If this list is empty, the total value of the
transaction will be assigned to the value defined by 'tgFromAcnt'.
Otherwise, the entries specified here will be added to the credit side
of this transaction, and their sum value will be subtracted from the
total value of the transaction and assigned to 'tgFromAcnt'.
This is useful for situations where a particular transaction denotes This is useful for situations where a particular transaction denotes
values that come from multiple subaccounts. values that come from multiple subaccounts.
-} -}
List EntryGetter.Type List EntryGetter.Type
, tgToEntries : , tgToEntries :
{- {-
A means of getting entries for this transaction A means of getting entries for this transaction
-} -}
List EntryGetter.Type List EntryGetter.Type
, tgOtherEntries : , tgOtherEntries :
{- {-
-} -}
List TxSubGetter List TxSubGetter.Type
}
, default =
{ tgOtherEntries = [] : List TxSubGetter.Type
, tgFromTags = [] : List TagID
, tgToTags = [] : List TagID
, tgFromComment = ""
, tgToComment = ""
}
} }
let StatementParser_ = let StatementParser_ =
@ -612,7 +618,7 @@ let StatementParser_ =
a transaction. If none, don't make a transaction (eg 'skip' a transaction. If none, don't make a transaction (eg 'skip'
this row in the statement). this row in the statement).
-} -}
Optional TxGetter Optional TxGetter.Type
, spTimes : , spTimes :
{- {-
Match at most this many rows; if none there is no limit Match at most this many rows; if none there is no limit
@ -629,7 +635,7 @@ let StatementParser_ =
, spVal = ValMatcher::{=} , spVal = ValMatcher::{=}
, spDesc = None Text , spDesc = None Text
, spOther = [] : List (FieldMatcher_ re) , spOther = [] : List (FieldMatcher_ re)
, spTx = None TxGetter , spTx = None TxGetter.Type
, spTimes = None Natural , spTimes = None Natural
, spPriority = +0 , spPriority = +0
} }

View File

@ -36,12 +36,14 @@ let cron1 =
let matchInf_ = nullMatch let matchInf_ = nullMatch
let matchInf = \(x : T.TxGetter) -> nullMatch // { spTx = Some x } let matchInf = \(x : T.TxGetter.Type) -> nullMatch // { spTx = Some x }
let matchN_ = \(n : Natural) -> nullMatch // { spTimes = Some n } let matchN_ = \(n : Natural) -> nullMatch // { spTimes = Some n }
let matchN = let matchN =
\(n : Natural) -> \(x : T.TxGetter) -> matchInf x // { spTimes = Some n } \(n : Natural) ->
\(x : T.TxGetter.Type) ->
matchInf x // { spTimes = Some n }
let match1_ = matchN_ 1 let match1_ = matchN_ 1

View File

@ -505,6 +505,10 @@ data TxSubGetter = TxSubGetter
data TxGetter = TxGetter data TxGetter = TxGetter
{ tgFromAcnt :: !EntryAcnt { tgFromAcnt :: !EntryAcnt
, tgToAcnt :: !EntryAcnt , tgToAcnt :: !EntryAcnt
, tgFromComment :: !T.Text
, tgToComment :: !T.Text
, tgFromTags :: ![TagID]
, tgToTags :: ![TagID]
, tgCurrency :: !EntryCur , tgCurrency :: !EntryCur
, tgFromEntries :: ![EntryGetter] , tgFromEntries :: ![EntryGetter]
, tgToEntries :: ![EntryGetter] , tgToEntries :: ![EntryGetter]

View File

@ -309,37 +309,34 @@ matches
toTx :: TxGetter -> TxRecord -> InsertExceptT CurrencyM DeferredTx toTx :: TxGetter -> TxRecord -> InsertExceptT CurrencyM DeferredTx
toTx toTx
TxGetter {tgFromAcnt, tgToAcnt, tgCurrency, tgFromEntries, tgToEntries, tgOtherEntries} TxGetter
{ tgFromAcnt
, tgToAcnt
, tgFromComment
, tgToComment
, tgFromTags
, tgToTags
, tgCurrency
, tgFromEntries
, tgToEntries
, tgOtherEntries
}
r@TxRecord {trAmount, trDate, trDesc} = do r@TxRecord {trAmount, trDate, trDesc} = do
combineError3 acntRes curRes subRes $ \(fa, ta) (cur, fe, te) ss -> do combineError3 acntRes curRes subRes $ \(fa, ta) (cur, fe, te) ss ->
let fromEntry = Tx
Entry { dtxDate = trDate
{ eAcnt = fa , dtxDescr = trDesc
, eValue = () , dtxEntries =
, eComment = "" -- TODO actually fill this in EntrySet
, eTags = [] -- TODO what goes here? { desTotalValue = trAmount
, desCurrency = cur
, desFromEntry0 = entry0 fa tgFromComment tgFromTags
, desFromEntries = fe
, desToEntries = te
, desToEntryBal = entry0 ta tgToComment tgToTags
} }
toEntry = : ss
Entry }
{ eAcnt = ta
, eValue = ()
, eComment = ""
, eTags = []
}
in Tx
{ dtxDate = trDate
, dtxDescr = trDesc
, dtxEntries =
EntrySet
{ desTotalValue = trAmount
, desCurrency = cur
, desFromEntry0 = fromEntry
, desFromEntries = fe
, desToEntries = te
, desToEntryBal = toEntry
}
: ss
}
where where
resolveAcnt_ = liftInner . resolveAcnt r resolveAcnt_ = liftInner . resolveAcnt r
acntRes = acntRes =
@ -353,6 +350,7 @@ toTx
let teRes = mapErrors (resolveEntry cur r) tgToEntries let teRes = mapErrors (resolveEntry cur r) tgToEntries
combineError feRes teRes (cur,,) combineError feRes teRes (cur,,)
subRes = mapErrors (resolveSubGetter r) tgOtherEntries subRes = mapErrors (resolveSubGetter r) tgOtherEntries
entry0 a c ts = Entry {eAcnt = a, eValue = (), eComment = c, eTags = ts}
resolveSubGetter resolveSubGetter
:: TxRecord :: TxRecord