diff --git a/extra/accountnames.hs b/extra/accountnames.hs deleted file mode 100755 index 85a4a8b2d..000000000 --- a/extra/accountnames.hs +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env runhaskell --- list the default journal's chart of accounts in --flat style -import Hledger -main = do - j <- myJournal - let l = journalToLedger nullfilterspec{empty=True} j - mapM_ putStrLn (accountnames l) diff --git a/extra/equity.hs b/extra/equity.hs deleted file mode 100755 index 491520962..000000000 --- a/extra/equity.hs +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env runhaskell -{- -Print an entry posting the total balance of the specified account and -subaccounts, or all accounts, from the default journal. Like ledger's -equity command. Useful when starting a new journal or closing the books. - -Usage: equity.hs [ACCTPAT] --} -import Hledger -import Hledger.Cli -import System.Environment - -main = do - j <- myJournal - d <- getCurrentDay - args <- getArgs - let acctpat = head $ args ++ [""] - (acctbals,_) = balanceReport [Flat] (optsToFilterSpec [] [acctpat] d) j - txn = nulltransaction{ - tdate=d, - tpostings=[nullposting{paccount=a,pamount=b} | (a,_,_,b) <- acctbals] - ++ [nullposting{paccount="equity:opening balances",pamount=missingamt}]} - putStr $ show txn diff --git a/extra/hledger-accountnames.hs b/extra/hledger-accountnames.hs new file mode 100755 index 000000000..5349075b3 --- /dev/null +++ b/extra/hledger-accountnames.hs @@ -0,0 +1,9 @@ +#!/usr/bin/env runhaskell +-- Show all account names used in the default journal. + +import Hledger + +main = do + j <- defaultJournal + let l = ledgerFromJournal Any j + mapM_ putStrLn $ ledgerAccountNames l diff --git a/extra/hledger-equity.hs b/extra/hledger-equity.hs new file mode 100755 index 000000000..afa61370b --- /dev/null +++ b/extra/hledger-equity.hs @@ -0,0 +1,30 @@ +#!/usr/bin/env runhaskell +{- + +Like ledger's equity command, print a journal entry posting the total +balance of all accounts (or the specified account and its subaccounts) +in the default journal. + +An entry like this is useful in the transition to a new journal file, +to zero out asset/liability balances in the old file and initialise +them in the new one. This way you get correct balances when reporting +on either file, and when including both files at once. + +Usage: hledger-equity [ACCTPAT] +-} +import Hledger +import Hledger.Cli +import System.Environment + +main = do + j <- defaultJournal + d <- getCurrentDay + args <- getArgs + let query = Or $ map Acct args + ropts = defreportopts{flat_=True} + (acctbals,_) = accountsReport ropts query j + balancingamt = negate $ sum $ map (\(_,_,_,b) -> b) acctbals + ps = [posting{paccount=a, pamount=b} | (a,_,_,b) <- acctbals] + ++ [posting{paccount="equity:opening balances", pamount=balancingamt}] + txn = nulltransaction{tdate=d, tpostings=ps} + putStr $ showTransactionUnelided txn diff --git a/extra/hledger-print-unique.hs b/extra/hledger-print-unique.hs new file mode 100755 index 000000000..182a898be --- /dev/null +++ b/extra/hledger-print-unique.hs @@ -0,0 +1,24 @@ +#!/usr/bin/env runhaskell +{-| +hledger-print-unique [-f JOURNALFILE | -f-] + +Print only journal entries which are unique by description (or +something else). Reads the default or specified journal, or stdin. + +|-} + +import Data.List +import Data.Ord +import Hledger +import Hledger.Cli +import Hledger.Cli.Print (print') + +main = do + opts <- getHledgerCliOpts [] + withJournalDo opts $ + \opts j@Journal{jtxns=ts} -> print' opts j{jtxns=uniquify ts} + where + uniquify = nubBy (\t1 t2 -> thingToCompare t1 == thingToCompare t2) . sortBy (comparing thingToCompare) + +thingToCompare = tdescription +-- thingToCompare = tdate diff --git a/extra/uniquify.hs b/extra/uniquify.hs deleted file mode 100755 index af838bce0..000000000 --- a/extra/uniquify.hs +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env runhaskell -{-| -Uniquify journal entries based on some id in the description. Reads the -default or specified journal, or stdin. - -Usage: uniquify.hs [-f JOURNALFILE | -f-] -|-} - -import Data.List -import Hledger -import Hledger.Cli - -main = do - opts <- getHledgerOpts - withJournalDo opts uniquifyAndPrint - -uniquifyAndPrint :: CliOpts -> Journal -> IO () -uniquifyAndPrint opts j@Journal{jtxns=ts} = print' opts j{jtxns=uniquify ts} - where - uniquify = nubBy (\t1 t2 -> extractId (tdescription t1) == extractId (tdescription t2)) - extractId desc = desc -- extract some part that's supposed to be unique