From f3203456993eacb54371967c62aa7d35c0737a56 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 25 Jan 2019 10:23:01 -0800 Subject: [PATCH] close: refactor --- hledger/Hledger/Cli/Commands/Close.hs | 39 ++++++++++++++------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Close.hs b/hledger/Hledger/Cli/Commands/Close.hs index 517d3ce42..d785e2ba1 100755 --- a/hledger/Hledger/Cli/Commands/Close.hs +++ b/hledger/Hledger/Cli/Commands/Close.hs @@ -43,22 +43,25 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do -- amounts in opening/closing transactions should be too (#941) -- setprec = setFullPrecision setprec = setMinimalPrecision - ps = [posting{paccount=a - ,pamount=mixed [setprec b] - ,pbalanceassertion=Just assertion{ baamount=setprec b } - } - |(a,_,_,mb) <- acctbals - ,b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb - ] - ++ [posting{paccount="equity:opening balances", pamount=balancingamt}] - nps = [posting{paccount=a - ,pamount=mixed [setprec $ negate b] - ,pbalanceassertion=Just assertion{ baamount= setprec b{aquantity=0} } - } - |(a,_,_,mb) <- acctbals - ,b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb - ] - ++ [posting{paccount="equity:closing balances", pamount=negate balancingamt}] - when closing $ putStr $ showTransaction (nulltransaction{tdate=closingdate, tdescription="closing balances", tpostings=nps}) - when opening $ putStr $ showTransaction (nulltransaction{tdate=openingdate, tdescription="opening balances", tpostings=ps}) + + closingps = [posting{paccount=a + ,pamount=mixed [setprec $ negate b] + ,pbalanceassertion=Just assertion{baamount=setprec b{aquantity=0}} + } + | (a,_,_,mb) <- acctbals + , b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb + ] + ++ [posting{paccount="equity:closing balances", pamount=negate balancingamt}] + + openingps = [posting{paccount=a + ,pamount=mixed [setprec b] + ,pbalanceassertion=Just assertion{baamount=setprec b} + } + | (a,_,_,mb) <- acctbals + , b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb + ] + ++ [posting{paccount="equity:opening balances", pamount=balancingamt}] + + when closing $ putStr $ showTransaction (nulltransaction{tdate=closingdate, tdescription="closing balances", tpostings=closingps}) + when opening $ putStr $ showTransaction (nulltransaction{tdate=openingdate, tdescription="opening balances", tpostings=openingps})