diff --git a/extra/hledger-balance-csv.hs b/extra/hledger-balance-csv.hs deleted file mode 100755 index 511de2ae7..000000000 --- a/extra/hledger-balance-csv.hs +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env runhaskell -{-| -hledger-balance-csv [OPTIONS] [ARGS] - -Show a balance report as CSV. --} - -import Hledger.Cli -import Text.CSV - - -argsmode = - (defCommandMode ["balance-csv"]) { - modeHelp = "show matched postings accounts and their balances as CSV" - ,modeGroupFlags = Group { - groupNamed = [] - ,groupUnnamed = inputflags ++ reportflags ++ helpflags - ,groupHidden = [] - } - } - -main = getCliOpts argsmode >>= printBalanceCsv - -printBalanceCsv opts = withJournalDo opts $ - \CliOpts{reportopts_=ropts} j -> do - d <- getCurrentDay - let (items,_) = balanceReport ropts (queryFromOpts d ropts) j - putStrLn $ printCSV $ - ["account","balance"] : - [[a, showMixedAmountWithoutPrice b] | ((a, _, _), b) <- items] diff --git a/extra/hledger-print-csv.hs b/extra/hledger-print-csv.hs deleted file mode 100755 index cac402abc..000000000 --- a/extra/hledger-print-csv.hs +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env runhaskell -{-| -hledger-print-csv [-f JOURNALFILE] - -Print matched journal entries as CSV -Reads the default or specified journal. -|-} - -import Hledger.Cli -import Text.CSV -import Data.Char (isSpace) -import Data.List (mapAccumL) - -argsmode :: Mode RawOpts -argsmode = (defCommandMode ["print-csv"]) - { modeHelp = "print matched journal entries as CSV" - , modeGroupFlags = Group - { groupNamed = - [ ("Input",inputflags) - , ("Reporting",reportflags) - , ("Misc",helpflags) - ] - , groupUnnamed = [] - , groupHidden = [] - } - } - -chomp :: String -> String -chomp = reverse . dropWhile isSpace . reverse . dropWhile isSpace - -postingToCSV :: Posting -> CSV -postingToCSV p = - map (\(a@(Amount {aquantity=q,acommodity=c})) -> - let a_ = a{acommodity=""} in - let amount = showAmount a_ in - let commodity = c in - let credit = if q < 0 then showAmount $ negate a_ else "" in - let debit = if q > 0 then showAmount a_ else "" in - account:amount:commodity:credit:debit:status:comment:[]) - amounts - where - Mixed amounts = pamount p - status = if pstatus p then "*" else "" - account = showAccountName Nothing (ptype p) (paccount p) - comment = chomp $ pcomment p - -postingsToCSV :: [Posting] -> CSV -postingsToCSV ps = - concatMap postingToCSV ps - -transactionToCSV :: Integer -> Transaction -> CSV -transactionToCSV n t = - map (\p -> show n:date:date2:status:code:description:comment:p) - (postingsToCSV (tpostings t)) - where - description = tdescription t - date = showDate (tdate t) - date2 = maybe "" showDate (tdate2 t) - status = if tstatus t then "*" else "" - code = tcode t - comment = chomp $ tcomment t - -main :: IO () -main = do - opts <- getCliOpts argsmode - withJournalDo opts $ - \CliOpts{reportopts_=ropts} j -> do - d <- getCurrentDay - let ropts_ = ropts{flat_=True} - let q = queryFromOpts d ropts_ - putStrLn $ printCSV $ concat $ - ([["nth","date","date2","status","code","description","comment","account","amount","commodity","credit","debit","status","posting-comment"]]:).snd $ - mapAccumL (\n e -> (n + 1, transactionToCSV n e)) 0 $ - entriesReport ropts_ q j