linux · 2021年 6月 6日 0

hledger复式记账

在会计学中,复式记账法 是商业及其他组织上记录金融交易的标准系统。

会计恒等式之静态公式:资产=负债+所有者权益(这一等式反映了资产、负债和所有者权益之间的关系,也是复式记账的理论基础)

会计恒等式之动态公式:利润=收入+花销 (这一等式反映了 期间的收入、花销和利润之间的关系,也是统计利润的基础依据)

最终的利润还是要归属到所有者权益,因此结合上面两个公式,可以得出:

资产 = 负债 + 所有者权益 + (收入+花销)

  • 资产 Assets,记录现金current、银行存款、投资investment;
  • 负债 Liabilities,记录信用卡credit_card、房贷、车贷等;
  • 权益 Equity,净资产,存放在记账开始前已经有的权益。
  • 花销 Expenses,记录各种消费(衣食住行医通学娱)等;
  • 收入 Income,记录工资salary、奖金fee等;
2022-02-05  *  opening balances
  assets:current:cash:bank:CMB          0
  assets:current:cash:bank:CCB          0
  assets:current:cash:bank:ICBC                 100
  assets:current:investment:fund:天天基金               100
  assets:current:investment:fund:alipay:yu'ebao                 100
  assets:current:investment:stock:华泰证券              100
  assets:current:debit          0
  assets:fixed:housing          100
  expenses              0
  liabilities:credicard:CMB             -100
  liabilities:credicard:CCB             -100
  equity:opening/closing balances

用 hledger 来记账

初始化

hledger 默认文件是 家目录下的 .hledger.journal

liupei@t470:~$ ls .hledger.journal
.hledger.journal

当然,也可以通过更改 hledger 的环境变量,来重新指定默认文件,如图所示:

export LEDGER_FILE=oneT470/.hledger.journal
# or
ln -s oneT470/.hledger.journal .hledger.journal

接下来,我们来对现有的 资产 和 负债 做个初始输入:

2022-02-05  *  opening balances
  assets:current:cash:bank:CMB          0
  assets:current:cash:bank:CCB          0
  assets:current:cash:bank:ICBC                 100
  assets:current:investment:fund:天天基金               100
  assets:current:investment:fund:alipay:yuebao                 100
  assets:current:investment:stock:华泰证券              100
  assets:current:debit          0
  assets:fixed:housing          100
  expenses              0
  liabilities:credicard:CMB             -100
  liabilities:credicard:CCB             -100
  equity:opening/closing balances

从图中我们可以看到,我将所有的 资产 都归到了 assets 目录下,然后下面又分出 current assets(流动资产) 和 fixed assets(固定资产),而 current assets 下又分出了 cash(现金)和investment(投资),具体划分如下(可供参考):

$ hledger accounts
assets:current:cash:bank:CCB
assets:current:cash:bank:CMB
assets:current:cash:bank:ICBC
assets:current:debit
assets:current:investment:fund:alipay:yuebao
assets:current:investment:fund:天天基金
assets:current:investment:stock:华泰证券
assets:fixed:housing
equity:opening/closing balances
expenses
liabilities:credicard:CCB
liabilities:credicard:CMB
  • assets
  • current assets
    • cash
    • bank
      • CMB
      • CCB
      • ICBC
    • investment
    • fund
      • 天天基金
      • alipay
      • yu’e bao
    • stock
      • 华泰证券
  • fixed assets
    • housing
  • expenses
  • liabilities
  • credit_card
    • CMB
    • CCB

注意,equity:opening/closing balances 这句是表示 开启动态平衡。

为什么初始化的时候用动态平衡,这个和复式记账有关,复式记账讲究有输入必有输出,所以复式记账的原理和记账方式决定了,记账过程中所有的数字 相加之和 一定 为 0

比如上面的初始化资产和负债加起来等于 300,我们开启动态平衡后,我们看一下 平衡情况

$ hledger b
                 500  assets
                 400    current
                 100      cash:bank:ICBC
                 300      investment
                 200        fund
                 100          alipay:yu'ebao
                 100          天天基金
                 100        stock:华泰证券
                 100    fixed:housing
                -300  equity:opening/closing balances
                -200  liabilities:creditcard
                -100    CCB
                -100    CMB
--------------------
                   0

我们可以看到,自动将equity计算出来,值为300,这意味着我们的 assets 里面有300 是从 equity 给到 assets 的。

所有的数字之和为0,这个也可以作为你记账后有没有出错的判断依据之一。假如 balance 不是为0,那么证明你的记账肯定出现出错了。

开始记账

hledger add

$ hledger add
Adding transactions to journal file .hledger.test
Any command line arguments will be used as defaults.
Use tab key to complete, readline keys to edit, enter to accept defaults.
An optional (CODE) may follow transaction dates.
An optional ; COMMENT may follow descriptions or amounts.
If you make a mistake, enter < at any prompt to restart the transaction.
To end a transaction, enter . when prompted.
To quit, enter . at a date prompt or press control-d or control-c.
Date [2022/06/06]:
Description: breakfast
Account 1: expenses:food
Amount  1: 15
Account 2: liabilities:credicard:CMB
Amount  2 [-15]:
Account 3 (or . or enter to finish this transaction):
2022/06/06 breakfast
    expenses:food                          15
    liabilities:credicard:CMB

Save this transaction to the journal ? [y]:
Saved.
Starting the next transaction (. or ctrl-D/ctrl-C to quit)
Date [2022/06/06]:
Description:
Account 1: <
Restarting this transaction.
Date [2022/06/06]:
Description: clothing
Using this similar transaction for defaults:
2022/02/05 * opening balances
    assets:current:cash:bank:CMB                                0
    assets:current:cash:bank:CCB                                0
    assets:current:cash:bank:ICBC                             100
    assets:current:investment:fund:天天基金                   100
    assets:current:investment:fund:alipay:yu'ebao             100
    assets:current:investment:stock:华泰证券                  100
    assets:current:debit                                        0
    assets:fixed:housing                                      100
    expenses                                                    0
    liabilities:credicard:CMB                                -100
    liabilities:credicard:CCB                                -100
    equity:opening/closing balances

Account 1 [assets:current:cash:bank:CMB]: expenses:clothing
Amount  1 [0]: 600
Account 2 [assets:current:cash:bank:CCB]: liabilities
liabilities                liabilities:credicard      liabilities:credicard:CCB  liabilities:credicard:CMB
Account 2 [assets:current:cash:bank:CCB]: liabilities:credicard:CMB
Amount  2 [-600]:
Account 3 (or . to finish this transaction) [assets:current:cash:bank:ICBC]:

查看 balance

hledger balance/ b / bal
~$ hledger b
               480.5  assets
               380.5    current
                80.5      cash:bank:ICBC
               300.0      investment
               200.0        fund
               100.0          alipay:yu'ebao
               100.0          天天基金
               100.0        stock:华泰证券
               100.0    fixed:housing
              -300.0  equity:opening/closing balances
                34.5  expenses
                15.0    food
                19.5    taxi
              -215.0  liabilities:credicard
              -100.0    CCB
              -115.0    CMB
--------------------
                   0

查看一共花费多少钱

hledger bal expenses
$ hledger b expenses
                34.5  expenses
                15.0    food
                19.5    taxi
--------------------
                34.5

查看支出的详细信息

hledger reg expenses
$ hledger reg expenses
2022/02/05  opening balances   expenses         0             
02022/06/06 breakfast          expenses:food    15.0         
2022/06/06  taxi                 expenses:taxi    15.0

查看 2020-07-01 至今 所有详情

hledger reg -b 2020/7/1

查看 工商银行卡的资产变动详情:

hledger register assets:current:cash:bank:ICBC
$ hledger register assets:current:cash:bank:ICBC
2022/02/05 opening balances                                           assets:current:cash:bank:ICBC                                      100.0         100.0
2022/06/06 taxi                                                       assets:current:cash:bank:ICBC                                      -19.5          80.5

以每月为周期查看账户所有支收情况

hledger bal -M

以每月为周期查看 expenses 花费情况

hledger bal expenses -M
$ hledger bal -M
Balance changes in 2022/02/01-2022/06/30:

                                               ||    Feb  Mar  Apr  May    Jun
===============================================++==============================
 assets:current:cash:bank:ICBC                 ||  100.0    0    0    0  -19.5
 assets:current:investment:fund:alipay:yu'ebao ||  100.0    0    0    0      0
 assets:current:investment:fund:天天基金        ||  100.0    0    0    0      0
 assets:current:investment:stock:华泰证券       ||  100.0    0    0    0      0
 assets:fixed:housing                          ||  100.0    0    0    0      0
 equity:opening/closing balances               || -300.0    0    0    0      0
 expenses:food                                 ||      0    0    0    0   15.0
 expenses:taxi                                 ||      0    0    0    0   19.5
 liabilities:credicard:CCB                     || -100.0    0    0    0      0
 liabilities:credicard:CMB                     || -100.0    0    0    0  -15.0
-----------------------------------------------++------------------------------
                                               ||      0    0    0    0      0

查看当前的净资产(资产 – 负债):

 hledger balance assets liabilities
 $ hledger balance assets liabilities
               480.5  assets
               380.5    current
                80.5      cash:bank:ICBC
               300.0      investment
               200.0        fund
               100.0          alipay:yu'ebao
               100.0          天天基金
               100.0        stock:华泰证券
               100.0    fixed:housing
              -215.0  liabilities:credicard
              -100.0    CCB
              -115.0    CMB
--------------------
               265.5

查看总收入

hledger balance income
$ hledger balance income
--------------------
                   0

查看收入详情

hledger reg income
hledger print -b 5/9 -e 5/16
hledger bal -b 5/9 -e 5/16
hledger bal -W -b 5/9 -e 5/16
hledger bal -M

参考文献

TOC