;close: dedent (#1165)
This commit is contained in:
parent
98b90a8a7b
commit
42840dd4c2
@ -38,93 +38,93 @@ closemode = hledgerCommandMode
|
|||||||
close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
|
close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
|
||||||
today <- getCurrentDay
|
today <- getCurrentDay
|
||||||
let
|
let
|
||||||
-- interleave equity postings next to the corresponding closing posting, or put them all at the end ?
|
-- interleave equity postings next to the corresponding closing posting, or put them all at the end ?
|
||||||
interleaved = boolopt "interleaved" rawopts
|
interleaved = boolopt "interleaved" rawopts
|
||||||
(opening, closing) =
|
(opening, closing) =
|
||||||
case (boolopt "opening" rawopts, boolopt "closing" rawopts) of
|
case (boolopt "opening" rawopts, boolopt "closing" rawopts) of
|
||||||
(False, False) -> (True, True) -- by default show both opening and closing
|
(False, False) -> (True, True) -- by default show both opening and closing
|
||||||
(o, c) -> (o, c)
|
(o, c) -> (o, c)
|
||||||
closingacct = T.pack $ fromMaybe defclosingacct $ maybestringopt "close-to" rawopts
|
closingacct = T.pack $ fromMaybe defclosingacct $ maybestringopt "close-to" rawopts
|
||||||
openingacct = T.pack $ fromMaybe defopeningacct $ maybestringopt "open-from" rawopts
|
openingacct = T.pack $ fromMaybe defopeningacct $ maybestringopt "open-from" rawopts
|
||||||
ropts_ = ropts{balancetype_=HistoricalBalance, accountlistmode_=ALFlat}
|
ropts_ = ropts{balancetype_=HistoricalBalance, accountlistmode_=ALFlat}
|
||||||
q = queryFromOpts today ropts_
|
q = queryFromOpts today ropts_
|
||||||
openingdate = fromMaybe today $ queryEndDate False q
|
openingdate = fromMaybe today $ queryEndDate False q
|
||||||
closingdate = addDays (-1) openingdate
|
closingdate = addDays (-1) openingdate
|
||||||
(acctbals,_) = balanceReportFromMultiBalanceReport ropts_ q j
|
(acctbals,_) = balanceReportFromMultiBalanceReport ropts_ q j
|
||||||
totalbalancingamt = sum $ map (\(_,_,_,b) -> normaliseMixedAmount b) acctbals
|
totalbalancingamt = sum $ map (\(_,_,_,b) -> normaliseMixedAmount b) acctbals
|
||||||
|
|
||||||
-- since balance assertion amounts are required to be exact, the
|
-- since balance assertion amounts are required to be exact, the
|
||||||
-- amounts in opening/closing transactions should be too (#941, #1137)
|
-- amounts in opening/closing transactions should be too (#941, #1137)
|
||||||
setprec = setFullPrecision
|
setprec = setFullPrecision
|
||||||
closingps = concat
|
closingps = concat
|
||||||
[[posting{paccount = a
|
[[posting{paccount = a
|
||||||
,pamount = mixed [setprec $ negate b]
|
,pamount = mixed [setprec $ negate b]
|
||||||
-- after each commodity's last posting, assert 0 balance (#1035)
|
-- after each commodity's last posting, assert 0 balance (#1035)
|
||||||
-- balance assertion amounts are unpriced (#824)
|
-- balance assertion amounts are unpriced (#824)
|
||||||
,pbalanceassertion =
|
,pbalanceassertion =
|
||||||
if islast
|
if islast
|
||||||
then Just nullassertion{baamount=setprec b{aquantity=0, aprice=Nothing}}
|
then Just nullassertion{baamount=setprec b{aquantity=0, aprice=Nothing}}
|
||||||
else Nothing
|
else Nothing
|
||||||
}
|
}
|
||||||
] ++
|
] ++
|
||||||
if interleaved then
|
if interleaved then
|
||||||
-- a corresponding posting transferring the above balance to equity
|
-- a corresponding posting transferring the above balance to equity
|
||||||
[posting{paccount = closingacct
|
[posting{paccount = closingacct
|
||||||
,pamount = Mixed [setprec b]
|
,pamount = Mixed [setprec b]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
else []
|
else []
|
||||||
| (a,_,_,mb) <- acctbals
|
| (a,_,_,mb) <- acctbals
|
||||||
-- the balances in each commodity, and for each transaction price
|
-- the balances in each commodity, and for each transaction price
|
||||||
, let bs = amounts $ normaliseMixedAmount mb
|
, let bs = amounts $ normaliseMixedAmount mb
|
||||||
-- mark the last balance in each commodity
|
-- mark the last balance in each commodity
|
||||||
, let bs' = concat [reverse $ zip (reverse bs) (True : repeat False)
|
, let bs' = concat [reverse $ zip (reverse bs) (True : repeat False)
|
||||||
| bs <- groupBy ((==) `on` acommodity) bs]
|
| bs <- groupBy ((==) `on` acommodity) bs]
|
||||||
, (b, islast) <- bs'
|
, (b, islast) <- bs'
|
||||||
]
|
]
|
||||||
++
|
++
|
||||||
if interleaved then []
|
if interleaved then []
|
||||||
else
|
else
|
||||||
-- a final posting transferring all the balances to equity
|
-- a final posting transferring all the balances to equity
|
||||||
-- (print will show it as multiple single-commodity postings)
|
-- (print will show it as multiple single-commodity postings)
|
||||||
[posting{paccount = closingacct
|
[posting{paccount = closingacct
|
||||||
,pamount = mapMixedAmount setprec totalbalancingamt
|
,pamount = mapMixedAmount setprec totalbalancingamt
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
openingps = concat
|
openingps = concat
|
||||||
[[posting{paccount = a
|
[[posting{paccount = a
|
||||||
,pamount = mixed [setprec b]
|
,pamount = mixed [setprec b]
|
||||||
,pbalanceassertion = case mcommoditysum of
|
,pbalanceassertion = case mcommoditysum of
|
||||||
Just s -> Just nullassertion{baamount=setprec s{aprice=Nothing}}
|
Just s -> Just nullassertion{baamount=setprec s{aprice=Nothing}}
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
}
|
}
|
||||||
] ++
|
] ++
|
||||||
if interleaved then
|
if interleaved then
|
||||||
-- a corresponding posting transferring the above balance from equity
|
-- a corresponding posting transferring the above balance from equity
|
||||||
[posting{paccount = openingacct
|
[posting{paccount = openingacct
|
||||||
,pamount = Mixed [setprec $ negate b]
|
,pamount = Mixed [setprec $ negate b]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
else []
|
else []
|
||||||
| (a,_,_,mb) <- acctbals
|
| (a,_,_,mb) <- acctbals
|
||||||
-- the balances in each commodity, and for each transaction price
|
-- the balances in each commodity, and for each transaction price
|
||||||
, let bs = amounts $ normaliseMixedAmount mb
|
, let bs = amounts $ normaliseMixedAmount mb
|
||||||
-- mark the last balance in each commodity, with the unpriced sum in that commodity
|
-- mark the last balance in each commodity, with the unpriced sum in that commodity
|
||||||
, let bs' = concat [reverse $ zip (reverse bs) (Just commoditysum : repeat Nothing)
|
, let bs' = concat [reverse $ zip (reverse bs) (Just commoditysum : repeat Nothing)
|
||||||
| bs <- groupBy ((==) `on` acommodity) bs
|
| bs <- groupBy ((==) `on` acommodity) bs
|
||||||
, let commoditysum = (sum bs)]
|
, let commoditysum = (sum bs)]
|
||||||
, (b, mcommoditysum) <- bs'
|
, (b, mcommoditysum) <- bs'
|
||||||
]
|
]
|
||||||
++
|
++
|
||||||
if interleaved then []
|
if interleaved then []
|
||||||
else
|
else
|
||||||
-- a final posting transferring all the balances from equity
|
-- a final posting transferring all the balances from equity
|
||||||
-- (print will show it as multiple single-commodity postings)
|
-- (print will show it as multiple single-commodity postings)
|
||||||
[posting{paccount = openingacct
|
[posting{paccount = openingacct
|
||||||
,pamount = mapMixedAmount setprec $ negate totalbalancingamt
|
,pamount = mapMixedAmount setprec $ negate totalbalancingamt
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
when closing $ putStr $ showTransaction (nulltransaction{tdate=closingdate, tdescription="closing balances", tpostings=closingps})
|
when closing $ putStr $ showTransaction (nulltransaction{tdate=closingdate, tdescription="closing balances", tpostings=closingps})
|
||||||
when opening $ putStr $ showTransaction (nulltransaction{tdate=openingdate, tdescription="opening balances", tpostings=openingps})
|
when opening $ putStr $ showTransaction (nulltransaction{tdate=openingdate, tdescription="opening balances", tpostings=openingps})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user