X-Git-Url: http://git.cyclocoop.org/?p=tool%2Fhledger.git;a=blobdiff_plain;f=hledger-equity.hs;fp=hledger-equity.hs;h=0000000000000000000000000000000000000000;hp=43ca0ffae6f94110a0cb5bbab3e6c48d5e812476;hb=707b0a621cd3c97d5d7e22e855272b3f865a2d56;hpb=30e9b83c521f5149836e1ef0b544676370721efe diff --git a/hledger-equity.hs b/hledger-equity.hs deleted file mode 100755 index 43ca0ff..0000000 --- a/hledger-equity.hs +++ /dev/null @@ -1,50 +0,0 @@ -#!/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 Data.Maybe (fromMaybe) -import Hledger.Cli - -argsmode :: Mode RawOpts -argsmode = (defCommandMode ["equity"]) - { modeHelp = "print a journal entry posting the total balance of all accounts" - ++ " (or the specified account and its subaccounts)" - , modeGroupFlags = Group - { groupNamed = - [ ("Input",inputflags) - , ("Reporting",reportflags) - , ("Misc",helpflags) - ] - , groupUnnamed = [] - , groupHidden = [] - } - } - -main :: IO () -main = do - opts <- getCliOpts argsmode - withJournalDo opts $ - \CliOpts{reportopts_=ropts} j -> do - today <- getCurrentDay - let ropts_ = ropts{flat_=True} - q = queryFromOpts today ropts_ - (acctbals,_) = balanceReport ropts_ q j - balancingamt = negate $ sum $ map (\((_,_,_),b) -> b) acctbals - ps = [posting{paccount=a, pamount=b} | ((a,_,_),b) <- acctbals] - ++ [posting{paccount="equity:opening balances", pamount=balancingamt}] - enddate = fromMaybe today $ queryEndDate (date2_ ropts_) q - nps = [posting{paccount=a, pamount=negate b} | ((a,_,_),b) <- acctbals] - ++ [posting{paccount="equity:closing balances", pamount=negate balancingamt}] - putStr $ showTransactionUnelided (nulltransaction{tdate=enddate, tpostings=nps}) - putStr $ showTransactionUnelided (nulltransaction{tdate=enddate, tpostings=ps})