使用 Ledger 记帐

以前在用 Planner 的时候, 看到一个 Ledger 可以用来记帐, 当时拿下来看了一下, 没仔细研究. 昨天忘了在哪里看到, 又提起兴趣, 用这个来把自己的财产以及金融情况记录下来. 它是一个命令行程序, 以一个特定格式的文件作为输入, 进行相关的计算, 然后把结果显示给用户.

在 Windows 上编译有些麻烦, 需要 GMPpcre, 前者的 MinGW 版本可以在这里拿到, 后者有直接的链接. 另外一个出现的问题是 "strptime" 这个函数没有, Google 的结果是 M$ 没有实现这个函数, 接着 Google 看到 MapServer 种自己实现了一个, 所以直接拷贝出来, 添加到 ledger 的 datetime.[h|cc] 中就可以编译通过了.

Ledger 自带的手册比较详细, 不只是介绍了本身的用法, 而且详细介绍了基本的财务知识. 它所处理的文件格式比较简单, 每一项事务都是一条记录, 包括日期, 标记, 给谁付钱或者一些描述信息, 从哪个帐户用了多少钱, 用在了什么地方等等. 记帐的人只要把相关的信息填上就行了. 想要查询一些, 就运行 ledger, 并带着相关的参数, 就可以显示出结果.

举个简单的例子, 比如一下内容是在 ledger.dat 文件中:

  1. 2004/05/14 * Pay day
  2.   Assets:Bank:Checking          RMB 500.00
  3.   Income:Salary
  4.  
  5. 2004/05/14 Withdraw
  6.   Assets:Cash                   RMB 100.00
  7.   Assets:Bank:Checking
  8.  
  9. 2004/05/27 Book Store
  10.   Expenses:Books                 RMB 20.00
  11.   Assets:Cash

然后运行 ledger -f ledger.dat balance 就可以显示出当前各个帐户的情况, 结果如下:

  1.  RMB 480.00  Assets
  2.   RMB 20.00  Expenses
  3. RMB -500.00  Income

查看当前 Cash 的余额, ledger -f ledger.dat balance cash, 结果如下:

  1.       RMB 80.00  Assets:Cash
  2. ---------------
  3.       RMB 80.00

查看相关的事务, ledger -f ledger-temp.dat -r register cash, 结果如下:

  1. 2004/05/14 Withdraw             Assets:Bank:Checking     RMB 100.00   RMB 100.00
  2.  
  3. 2004/05/27 Book Store           Expenses:Books           RMB -20.00    RMB 80.00

还有很多其他的命令, 我也是在慢慢摸索, 慢慢学习中. 它自带了一个 ledger.el, 和Emacs 结合来很方便地编写帐本. 据说现在 CVS 里的加了很多功能.

就我这两天的使用来看, 还是有很多的问题, 有些问题都是莫名其妙地, 根本不知道错误在哪里, 报的都是 "Failed to parse date" 之类的错.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You can use BBCode tags in the text.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
 __   __  _     ____     ____  __        __  ____    ____    _____ 
\ \ / / | |_ |___ \ / ___| \ \ / / | _ \ | ___| |___ |
\ V / | __| __) | | | \ \ /\ / / | |_) | |___ \ / /
| | | |_ / __/ | |___ \ V V / | __/ ___) | / /
|_| \__| |_____| \____| \_/\_/ |_| |____/ /_/
Enter the code depicted in ASCII art style.