mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-20 18:58:23 +03:00
imp: close: clarify date logic, use journal last day if later (#1604)
This commit is contained in:
parent
a681e5329d
commit
0a66068ad1
@ -73,16 +73,37 @@ close CliOpts{rawopts_=rawopts, reportspec_=rspec} j = do
|
|||||||
(Nothing, Nothing) -> (T.pack defclosingacct, T.pack defopeningacct)
|
(Nothing, Nothing) -> (T.pack defclosingacct, T.pack defopeningacct)
|
||||||
|
|
||||||
-- dates of the closing and opening transactions
|
-- dates of the closing and opening transactions
|
||||||
rspec_ = rspec{rsOpts=ropts}
|
--
|
||||||
ropts = (rsOpts rspec){balancetype_=HistoricalBalance, accountlistmode_=ALFlat}
|
-- Close.md:
|
||||||
|
-- "The default closing date is yesterday, or the journal's end date, whichever is later.
|
||||||
|
--
|
||||||
|
-- Unless you are running `close` on exactly the first day of the new period,
|
||||||
|
-- you'll want to override the closing date.
|
||||||
|
-- This is done by specifying a [report period](#report-start--end-date),
|
||||||
|
-- where "last day of the report period" will be the closing date.
|
||||||
|
-- The opening date is always the following day.
|
||||||
|
-- So to close on 2020-12-31 and open on 2021-01-01, any of these work
|
||||||
|
--
|
||||||
|
-- - `-p 2020`
|
||||||
|
-- - `date:2020`
|
||||||
|
-- - `-e 2021-01-01` (remember `-e` specifies an exclusive report end date)
|
||||||
|
-- - `-e 2021`"
|
||||||
|
--
|
||||||
q = rsQuery rspec
|
q = rsQuery rspec
|
||||||
openingdate = fromMaybe today $ queryEndDate False q
|
yesterday = addDays (-1) today
|
||||||
closingdate = addDays (-1) openingdate
|
yesterdayorjournalend = case journalLastDay False j of
|
||||||
|
Just journalend -> max yesterday journalend
|
||||||
|
Nothing -> yesterday
|
||||||
|
mreportlastday = addDays (-1) <$> queryEndDate False q
|
||||||
|
closingdate = fromMaybe yesterdayorjournalend mreportlastday
|
||||||
|
openingdate = addDays 1 closingdate
|
||||||
|
|
||||||
-- should we show the amount(s) on the equity posting(s) ?
|
-- should we show the amount(s) on the equity posting(s) ?
|
||||||
explicit = boolopt "explicit" rawopts
|
explicit = boolopt "explicit" rawopts
|
||||||
|
|
||||||
-- the balances to close
|
-- the balances to close
|
||||||
|
ropts = (rsOpts rspec){balancetype_=HistoricalBalance, accountlistmode_=ALFlat}
|
||||||
|
rspec_ = rspec{rsOpts=ropts}
|
||||||
(acctbals',_) = balanceReport rspec_ j
|
(acctbals',_) = balanceReport rspec_ j
|
||||||
acctbals = map (\(a,_,_,b) -> (a, if show_costs_ ropts then b else mixedAmountStripPrices b)) acctbals'
|
acctbals = map (\(a,_,_,b) -> (a, if show_costs_ ropts then b else mixedAmountStripPrices b)) acctbals'
|
||||||
totalamt = maSum $ map snd acctbals
|
totalamt = maSum $ map snd acctbals
|
||||||
|
@ -303,3 +303,16 @@ $ hledger -f- close -p 2019 assets --interleaved -x
|
|||||||
equity:opening/closing balances $-0.109999
|
equity:opening/closing balances $-0.109999
|
||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
|
# 14. "The default closing date is yesterday, or the journal's end date, whichever is later."
|
||||||
|
<
|
||||||
|
999999-12-31
|
||||||
|
(a) 1
|
||||||
|
$ hledger -f- close
|
||||||
|
> /999999-12-31 closing balances/
|
||||||
|
>=
|
||||||
|
|
||||||
|
# 15. "override the closing date ... by specifying a report period, where last day of the report period will be the closing date"
|
||||||
|
$ hledger -f- close -e 100000-01-01
|
||||||
|
> /99999-12-31 closing balances/
|
||||||
|
>=
|
||||||
|
Loading…
Reference in New Issue
Block a user