From 64769443302f131abebcd94e7e0da38aad0d8178 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 29 Jun 2016 15:01:24 -0700 Subject: [PATCH] tools: update, rename cabal installation script --- buildSandbox.sh | 8 ------ cabal-install.sh | 16 +++++++++++ extra/hledger-equity.hs | 63 +++++++++++++++++++++++++++++++---------- 3 files changed, 64 insertions(+), 23 deletions(-) delete mode 100755 buildSandbox.sh create mode 100755 cabal-install.sh diff --git a/buildSandbox.sh b/buildSandbox.sh deleted file mode 100755 index de1c029a0..000000000 --- a/buildSandbox.sh +++ /dev/null @@ -1,8 +0,0 @@ -cd hledger -cabal sandbox init -cabal sandbox add-source ../hledger-lib -cabal sandbox add-source ../hledger-web - -cabal install --dependencies-only -cabal configure -cabal build diff --git a/cabal-install.sh b/cabal-install.sh new file mode 100755 index 000000000..e03f0433b --- /dev/null +++ b/cabal-install.sh @@ -0,0 +1,16 @@ +# Run this script to install all hledger packages using cabal +# (if you prefer using cabal to stack) + +# use a sandbox in this directory to avoid build problems +cabal sandbox init + +# maybe useful for some developers.. +cabal sandbox add-source ./hledger-lib +cabal sandbox add-source ./hledger +cabal sandbox add-source ./hledger-ui +cabal sandbox add-source ./hledger-web +cabal sandbox add-source ./hledger-api + +# build and install +cabal install ./hledger-lib ./hledger ./hledger-ui ./hledger-web ./hledger-api \ + && echo "hledger executables successfully installed in ./.cabal-sandbox/bin" diff --git a/extra/hledger-equity.hs b/extra/hledger-equity.hs index daa868bc8..f70f124c4 100755 --- a/extra/hledger-equity.hs +++ b/extra/hledger-equity.hs @@ -1,19 +1,51 @@ -#!/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] +#!/usr/bin/env stack +{- stack runghc --verbosity info + --package hledger-lib + --package hledger + --package time -} +{- +hledger-equity [HLEDGEROPTS] [QUERY] + +Show a "closing balances" transaction that brings the balance of the +accounts matched by QUERY (or all accounts) to zero, and an opposite +"opening balances" transaction that restores the balances from zero. + +The opening balances transaction is useful to carry over +asset/liability balances if you choose to start a new journal file, +eg at the beginning of the year. + +The closing balances transaction is useful to zero out balances in +the old file, which gives you the option of reporting on both files +at once while still seeing correct balances. + +Balances are calculated, and the opening transaction is dated, as of +the report end date, which you should specify with -e or date: (and +the closing transaction is dated one day earlier). If a report end +date is not specified, it defaults to today. + +If any matched account directly contains multiple commodities, the +output may not be valid journal syntax, and will need some editing. + +Example: +$ hledger equity -f 2015.journal -e 2016/1/1 assets liabilities >>2015.journal +move opening balances txn to 2016.journal + +Open question: how to handle txns spanning a file boundary ? Eg: +2015/12/30 * food + expenses:food:dining $10 + assets:bank:checking -$10 ; date:2016/1/4 + +This might or might not have some connection to the concept of +"closing the books" in accounting. + +-} + +{-# LANGUAGE OverloadedStrings #-} + import Data.Maybe (fromMaybe) +import Data.Time.Calendar (addDays) import Hledger.Cli argsmode :: Mode RawOpts @@ -22,6 +54,7 @@ argsmode = (defCommandMode ["equity"]) ++ " (or the specified account and its subaccounts)" , modeGroupFlags = Group { groupNamed = + -- XXX update to match hledger [ ("Input",inputflags) , ("Reporting",reportflags) , ("Misc",helpflags) @@ -46,5 +79,5 @@ main = do 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}) + putStr $ showTransaction (nulltransaction{tdate=addDays (-1) enddate, tdescription="closing balances", tpostings=nps}) + putStr $ showTransaction (nulltransaction{tdate=enddate, tdescription="opening balances", tpostings=ps})