From 6cd0c1aa56743f5377a1d7fbdf7d2f9fd73b2787 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 13 Jun 2011 23:29:12 +0000 Subject: [PATCH] scripts: equity.hs, a test of the scripting api --- examples/equity.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/equity.hs diff --git a/examples/equity.hs b/examples/equity.hs new file mode 100644 index 000000000..491520962 --- /dev/null +++ b/examples/equity.hs @@ -0,0 +1,23 @@ +#!/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