Added support for effective-date-field to the "convert" operation

This commit is contained in:
Dmitry Astapov 2011-01-23 20:48:28 +00:00
parent c78fe9dd5d
commit b9ae208bd5
2 changed files with 15 additions and 2 deletions

View File

@ -560,7 +560,7 @@ Notes:
- Definitions must come first, one per line, all in one
paragraph. Each is a name and a value separated by whitespace.
Supported names are: base-account, date-field, date-format, status-field,
Supported names are: base-account, date-field, effective-date-field, date-format, status-field,
code-field, description-field, amount-field, currency-field, account-field,
currency. All are optional and will use defaults if not specified.

View File

@ -43,6 +43,7 @@ data CsvRules = CsvRules {
currencyField :: Maybe FieldPosition,
baseCurrency :: Maybe String,
accountField :: Maybe FieldPosition,
effectiveDateField :: Maybe FieldPosition,
baseAccount :: AccountName,
accountRules :: [AccountRule]
} deriving (Show, Eq)
@ -57,6 +58,7 @@ nullrules = CsvRules {
currencyField=Nothing,
baseCurrency=Nothing,
accountField=Nothing,
effectiveDateField=Nothing,
baseAccount="unknown",
accountRules=[]
}
@ -114,6 +116,7 @@ maxFieldIndex r = maximumDef (-1) $ catMaybes [
,amountField r
,currencyField r
,accountField r
,effectiveDateField r
]
rulesFileFor :: FilePath -> FilePath
@ -177,6 +180,7 @@ definitions = do
,amountfield
,currencyfield
,accountfield
,effectivedatefield
,basecurrency
,baseaccount
,commentline
@ -190,6 +194,13 @@ datefield = do
r <- getState
setState r{dateField=readMay v}
effectivedatefield = do
string "effective-date-field"
many1 spacenonewline
v <- restofline
r <- getState
setState r{effectiveDateField=readMay v}
dateformat = do
string "date-format"
many1 spacenonewline
@ -294,6 +305,8 @@ transactionFromCsvRecord :: CsvRules -> CsvRecord -> Transaction
transactionFromCsvRecord rules fields =
let
date = parsedate $ normaliseDate (dateFormat rules) $ maybe "1900/1/1" (atDef "" fields) (dateField rules)
effectivedate = do idx <- effectiveDateField rules
return $ parsedate $ normaliseDate (dateFormat rules) $ (atDef "" fields) idx
status = maybe False (null . strip . (atDef "" fields)) (statusField rules)
code = maybe "" (atDef "" fields) (codeField rules)
desc = maybe "" (atDef "" fields) (descriptionField rules)
@ -315,7 +328,7 @@ transactionFromCsvRecord rules fields =
(acct,newdesc) = identify (accountRules rules) unknownacct desc
t = Transaction {
tdate=date,
teffectivedate=Nothing,
teffectivedate=effectivedate,
tstatus=status,
tcode=code,
tdescription=newdesc,