print: csv: show proper txn index, rename to "txnidx"
This commit is contained in:
parent
2585c1eedf
commit
332a19ccd8
@ -14,7 +14,6 @@ module Hledger.Cli.Print (
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
import Data.List
|
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import System.Console.CmdArgs.Explicit
|
import System.Console.CmdArgs.Explicit
|
||||||
@ -106,16 +105,18 @@ entriesReportAsText items = concatMap showTransactionUnelided items
|
|||||||
-- ]
|
-- ]
|
||||||
|
|
||||||
entriesReportAsCsv :: EntriesReport -> CSV
|
entriesReportAsCsv :: EntriesReport -> CSV
|
||||||
entriesReportAsCsv items =
|
entriesReportAsCsv txns =
|
||||||
concat $
|
["txnidx","date","date2","status","code","description","comment","account","amount","commodity","credit","debit","status","posting-comment"] :
|
||||||
([["nth","date","date2","status","code","description","comment","account","amount","commodity","credit","debit","status","posting-comment"]]:).snd $
|
concatMap transactionToCSV txns
|
||||||
mapAccumL (\n e -> (n + 1, transactionToCSV n e)) 0 items
|
|
||||||
|
|
||||||
transactionToCSV :: Integer -> Transaction -> CSV
|
-- | Generate one CSV record per posting, duplicating the common transaction fields.
|
||||||
transactionToCSV n t =
|
-- The txnidx field (transaction index) allows postings to be grouped back into transactions.
|
||||||
map (\p -> show n:date:date2:status:code:description:comment:p)
|
transactionToCSV :: Transaction -> CSV
|
||||||
|
transactionToCSV t =
|
||||||
|
map (\p -> show idx:date:date2:status:code:description:comment:p)
|
||||||
(concatMap postingToCSV $ tpostings t)
|
(concatMap postingToCSV $ tpostings t)
|
||||||
where
|
where
|
||||||
|
idx = tindex t
|
||||||
description = T.unpack $ tdescription t
|
description = T.unpack $ tdescription t
|
||||||
date = showDate (tdate t)
|
date = showDate (tdate t)
|
||||||
date2 = maybe "" showDate (tdate2 t)
|
date2 = maybe "" showDate (tdate2 t)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user