
# 1. Simple case
<
2016/1/1 open
    assets:bank         $100
    assets:cash         $20
    equity:opening

2016/1/15 spend
    expenses:sweets     $5
    assets:cash

2016/1/19 withdraw
    assets:cash         $20
    assets:bank

2016/1/20 lend
    liabilities         $25
    assets:cash

$ hledger close -f- -e 2017-01-01 assets liabilities
2016-12-31 closing balances
    assets:bank                                $-80 = $0
    assets:cash                                $-10 = $0
    liabilities                                $-25 = $0
    equity:opening/closing balances

2017-01-01 opening balances
    assets:bank                                 $80 = $80
    assets:cash                                 $10 = $10
    liabilities                                 $25 = $25
    equity:opening/closing balances

>=0

# 2. A begin date should be ignored
$ hledger close -f- -e 2017-01-01 assets liabilities -b 2016-12-01
2016-12-31 closing balances
    assets:bank                                $-80 = $0
    assets:cash                                $-10 = $0
    liabilities                                $-25 = $0
    equity:opening/closing balances

2017-01-01 opening balances
    assets:bank                                 $80 = $80
    assets:cash                                 $10 = $10
    liabilities                                 $25 = $25
    equity:opening/closing balances

>=0

# 3. Print just the opening transaction
<
2016/1/1 open
    assets:bank         $100
    assets:cash         $20
    equity:opening

2016/1/15 spend
    expenses:sweets     $5
    assets:cash

2016/1/19 withdraw
    assets:cash         $20
    assets:bank

2016/1/20 lend
    liabilities         $25
    assets:cash

$ hledger close -f- -p 2016 assets liabilities --open
2017-01-01 opening balances
    assets:bank                                 $80 = $80
    assets:cash                                 $10 = $10
    liabilities                                 $25 = $25
    equity:opening/closing balances

>=0

# 4. Print just the closing transaction. 
$ hledger close -f- -p 2016 assets liabilities --close
2016-12-31 closing balances
    assets:bank                                $-80 = $0
    assets:cash                                $-10 = $0
    liabilities                                $-25 = $0
    equity:opening/closing balances

>=0

# 5. Supplying --open --close is the same as just "close"
# Also -x makes it show the equity amounts.
$ hledger close -f- -p 2016 assets liabilities --open --close -x
2016-12-31 closing balances
    assets:bank                                $-80 = $0
    assets:cash                                $-10 = $0
    liabilities                                $-25 = $0
    equity:opening/closing balances            $115

2017-01-01 opening balances
    assets:bank                                 $80 = $80
    assets:cash                                 $10 = $10
    liabilities                                 $25 = $25
    equity:opening/closing balances           $-115

>=0

# 6. Closing a multi-priced balance. By default the transaction prices are ignored.
<
2019/01/01
    assets                          1A @ 1B
    assets                          1A @ 1C
    equity

$ hledger -f- close assets -p 2019 -x
2019-12-31 closing balances
    assets                                      -2A = 0A
    equity:opening/closing balances              2A

2020-01-01 opening balances
    assets                                       2A = 2A
    equity:opening/closing balances             -2A

>=0

# 7. With --show-costs, the transaction prices are preserved.
# Only the last posting in each commodity gets a balance assertion (#1035).
# Balance assertion amounts do not have a price.
$ hledger -f- close assets -p 2019 --show-costs -x
2019-12-31 closing balances
    assets                                 -1A @ 1B
    assets                                 -1A @ 1C = 0A
    equity:opening/closing balances         1A @ 1B
    equity:opening/closing balances         1A @ 1C

2020-01-01 opening balances
    assets                                  1A @ 1B
    assets                                  1A @ 1C = 2A
    equity:opening/closing balances        -1A @ 1B
    equity:opening/closing balances        -1A @ 1C

>=0

# 8. Closing a multi-priced balance, slightly more complex
# (different price in each transaction).
<
2019/01/01
    (assets)                        1A @ 1B

2019/01/02
    (assets)                        1A @ 2B

$ hledger -f- close assets -p 2019 -x
2019-12-31 closing balances
    assets                                      -2A = 0A
    equity:opening/closing balances              2A

2020-01-01 opening balances
    assets                                       2A = 2A
    equity:opening/closing balances             -2A

>=0

# 9. The same, with costs.
$ hledger -f- close assets -p 2019 --show-costs -x
2019-12-31 closing balances
    assets                                 -1A @ 1B
    assets                                 -1A @ 2B = 0A
    equity:opening/closing balances         1A @ 1B
    equity:opening/closing balances         1A @ 2B

2020-01-01 opening balances
    assets                                  1A @ 1B
    assets                                  1A @ 2B = 2A
    equity:opening/closing balances        -1A @ 1B
    equity:opening/closing balances        -1A @ 2B

>=0

# 10. Closing a multi-priced balance, a more complex example.
# Decimal places specified by the amount display style should not be stripped
# even if they are zeros (#1137).
<
2016/01/31
    liabilities:employer                      $5,000.00
    income:salary

2016/02/05
    liabilities:employer                     $-5,000.00 @ 0.95 EUR
    expenses:tax                               1,852.50 EUR
    assets:bank                                2,897.00 EUR
    liabilities:employer

2016/02/29
    liabilities:employer                      $5,000.00
    income:salary

2016/03/04
    liabilities:employer                     $-5,000.00 @ 0.93 EUR
    expenses:tax                               1,813.50 EUR
    assets:bank                                2,836.00 EUR
    liabilities:employer

$ hledger -f- close -p 2016 assets liabilities --show-costs -x
2016-12-31 closing balances
    assets:bank                                -5,733.00 EUR = 0.00 EUR
    liabilities:employer                         $-10,000.00
    liabilities:employer                $5,000.00 @ 0.93 EUR
    liabilities:employer                $5,000.00 @ 0.95 EUR = $0.00
    liabilities:employer                           -1.00 EUR = 0.00 EUR
    equity:opening/closing balances               $10,000.00
    equity:opening/closing balances    $-5,000.00 @ 0.93 EUR
    equity:opening/closing balances    $-5,000.00 @ 0.95 EUR
    equity:opening/closing balances             5,734.00 EUR

2017-01-01 opening balances
    assets:bank                                 5,733.00 EUR = 5,733.00 EUR
    liabilities:employer                          $10,000.00
    liabilities:employer               $-5,000.00 @ 0.93 EUR
    liabilities:employer               $-5,000.00 @ 0.95 EUR = $0.00
    liabilities:employer                            1.00 EUR = 1.00 EUR
    equity:opening/closing balances              $-10,000.00
    equity:opening/closing balances     $5,000.00 @ 0.93 EUR
    equity:opening/closing balances     $5,000.00 @ 0.95 EUR
    equity:opening/closing balances            -5,734.00 EUR

>=0

# 11. With --interleaved, each transfer's postings are adjacent.
# (And balances with the same cost are not necessarily combined into
# a single posting. Eg the 5734 EUR above is 5733 EUR and 1 EUR below.)
$ hledger -f- close -p 2016 assets liabilities --interleaved --show-costs -x
2016-12-31 closing balances
    assets:bank                                -5,733.00 EUR = 0.00 EUR
    equity:opening/closing balances             5,733.00 EUR
    liabilities:employer                         $-10,000.00
    equity:opening/closing balances               $10,000.00
    liabilities:employer                $5,000.00 @ 0.93 EUR
    equity:opening/closing balances    $-5,000.00 @ 0.93 EUR
    liabilities:employer                $5,000.00 @ 0.95 EUR = $0.00
    equity:opening/closing balances    $-5,000.00 @ 0.95 EUR
    liabilities:employer                           -1.00 EUR = 0.00 EUR
    equity:opening/closing balances                 1.00 EUR

2017-01-01 opening balances
    assets:bank                                 5,733.00 EUR = 5,733.00 EUR
    equity:opening/closing balances            -5,733.00 EUR
    liabilities:employer                          $10,000.00
    equity:opening/closing balances              $-10,000.00
    liabilities:employer               $-5,000.00 @ 0.93 EUR
    equity:opening/closing balances     $5,000.00 @ 0.93 EUR
    liabilities:employer               $-5,000.00 @ 0.95 EUR = $0.00
    equity:opening/closing balances     $5,000.00 @ 0.95 EUR
    liabilities:employer                            1.00 EUR = 1.00 EUR
    equity:opening/closing balances                -1.00 EUR

>=0

# 12. A tricky case where a closing posting was rounded and failed to balance (#1164)
<
commodity $0.00
commodity AAA 0.00000000

2019-01-01 opening balance
    (assets:usd)                                 $49.50

2019-01-02 buy some AAA
    assets:usd                                  -$49.2619200
    assets:aaa                               AAA 510
    assets:usd                                   -$0.1280810
    expenses:banking                              $0.1280810

$ hledger -f- close -p 2019 assets --show-costs -x
2019-12-31 closing balances
    assets:aaa                                       AAA -510.00000000 = AAA 0.00000000
    assets:usd                                                 $-49.50
    assets:usd                          $49.390001 @ AAA 10.3528242505 = $0.00
    equity:opening/closing balances                             $49.50
    equity:opening/closing balances    $-49.390001 @ AAA 10.3528242505
    equity:opening/closing balances                   AAA 510.00000000

2020-01-01 opening balances
    assets:aaa                                        AAA 510.00000000 = AAA 510.00000000
    assets:usd                                                  $49.50
    assets:usd                         $-49.390001 @ AAA 10.3528242505 = $0.109999
    equity:opening/closing balances                            $-49.50
    equity:opening/closing balances     $49.390001 @ AAA 10.3528242505
    equity:opening/closing balances                  AAA -510.00000000

>=0

# 13. The same, without costs and with --interleaved.
$ hledger -f- close -p 2019 assets --interleaved -x
2019-12-31 closing balances
    assets:aaa                         AAA -510.00000000 = AAA 0.00000000
    equity:opening/closing balances     AAA 510.00000000
    assets:usd                                $-0.109999 = $0.00
    equity:opening/closing balances            $0.109999

2020-01-01 opening balances
    assets:aaa                          AAA 510.00000000 = AAA 510.00000000
    equity:opening/closing balances    AAA -510.00000000
    assets:usd                                 $0.109999 = $0.109999
    equity:opening/closing balances           $-0.109999

>=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/
>=
