Skip to content

Commit

Permalink
Fix alipay example of ShouKuanMa (收款码) and normalize outputs (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxalica authored Jun 25, 2021
1 parent 690e52b commit 608ad73
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 38 deletions.
10 changes: 9 additions & 1 deletion example/alipay/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ alipay:
- method: 招商银行(9876)
methodAccount: Assets:Bank:CN:CMB-9876:Savings

- type: 收入 # 其他转账收款
targetAccount: Income:FIXME
methodAccount: Assets:Alipay
- type: 收入 # 收款码收款
item: 商品
targetAccount: Income:Alipay:ShouKuanMa
methodAccount: Assets:Alipay

# 交易类型为其他
- type: 其他
item: 收益发放
Expand All @@ -38,4 +46,4 @@ alipay:
- type: 其他
item: 余额宝-单次转入
targetAccount: Assets:Alipay
methodAccount: Assets:Alipay
methodAccount: Assets:Alipay
40 changes: 25 additions & 15 deletions example/alipay/example-alipay-output.beancount
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
option "title" "测试"
option "operating_currency" "CNY"

1970-01-01 open Expenses:FIXME
1970-01-01 open Assets:FIXME
1970-01-01 open Assets:Alipay
1970-01-01 open Assets:Bank:CN:CMB-9876:Savings
1970-01-01 open Assets:Alipay:Invest
1970-01-01 open Expenses:Insurance
1970-01-01 open Income:Alipay:YuEBao:PnL
1970-01-01 open Income:Alipay:Invest:PnL
1970-01-01 open Assets:Bank:CN:CMB-9876:Savings
1970-01-01 open Assets:FIXME
1970-01-01 open Expenses:Electronics
1970-01-01 open Expenses:FIXME
1970-01-01 open Expenses:Food
1970-01-01 open Expenses:Groceries
1970-01-01 open Expenses:Electronics
1970-01-01 open Expenses:Insurance
1970-01-01 open Income:Alipay:Invest:PnL
1970-01-01 open Income:Alipay:ShouKuanMa
1970-01-01 open Income:Alipay:YuEBao:PnL
1970-01-01 open Income:FIXME

2020-06-02 * "蚂蚁财富-蚂蚁(杭州)基金销售有限公司" "蚂蚁财富-ABCD-卖出至余额宝" ; 其他-交易成功-投资理财
Assets:Alipay 15.40 CNY
Expand All @@ -21,32 +23,40 @@ option "operating_currency" "CNY"
2020-06-09 * "广发基金管理有限公司" "余额宝-2020.06.08-收益发放" ; 其他-交易成功-投资理财
Assets:Alipay 0.11 CNY
Income:Alipay:YuEBao:PnL -0.11 CNY

2020-06-14 * "东莞肯德基有限公司" "KFCAPIDGB012345" ; 支出-交易成功-餐饮美食
Expenses:Food 79.00 CNY
Assets:Alipay -79.00 CNY

2021-05-19 * "蚂蚁财富-蚂蚁(杭州)基金销售有限公司" "蚂蚁财富-XZY指数C-买入" ; 其他-交易成功-投资理财
Assets:Alipay:Invest 50.00 CNY
Assets:Alipay -50.00 CNY

2021-05-20 * "苏宁易购官方旗舰店" "【礼遇价】三星128g内存卡microSD存储卡tf卡行车记录仪卡switch监控摄像头" ; 支出-交易成功-数码电器
Expenses:Electronics 87.90 CNY
Assets:Bank:CN:CMB-9876:Savings -87.90 CNY

2021-05-30 * "广发基金管理有限公司" "余额宝-单次转入" ; 其他-交易成功-投资理财
Assets:Alipay 2.00 CNY
Assets:Alipay -2.00 CNY

2021-06-01 * "dettol滴露官方旗舰店" "【直接下单付款】滴露消毒液1.2L*2家用杀菌消毒水衣物地板宠物" ; 支出-交易关闭-日用百货
Expenses:Groceries 109.90 CNY
Assets:Bank:CN:CMB-9876:Savings -109.90 CNY

2021-06-01 * "dettol滴露官方旗舰店" "退款-【直接下单付款】滴露消毒液1.2L*2家用杀菌消毒水衣物地板宠物" ; 其他-退款成功-退款
Assets:Bank:CN:CMB-9876:Savings 109.90 CNY
Expenses:Groceries -109.90 CNY

2021-06-14 * "蚂蚁会员(北京)网络技术服务有限公司" "相互宝分摊-6月第1期-*" ; 支出-交易成功-互助保障
Expenses:Insurance 6.51 CNY
Assets:Bank:CN:CMB-9876:Savings -6.51 CNY


2021-06-24 * "*三" "商品" ; 收入-交易成功-收入
Assets:Alipay 10.00 CNY
Income:Alipay:ShouKuanMa -10.00 CNY

2021-06-25 * "*三" "我就随便转着玩" ; 收入-交易成功-转账红包
Assets:Alipay 42.00 CNY
Income:FIXME -42.00 CNY

2 changes: 2 additions & 0 deletions example/alipay/example-alipay-records.csv
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
���� ,���ϲƸ�-���ϣ����ݣ������������޹�˾ , ,���ϲƸ�-XZYָ��C-����, ,50.00 ,���׳ɹ� ,Ͷ������ ,123456 , ,2021-05-19 09:42:54 ,
���� ,���ϲƸ�-���ϣ����ݣ������������޹�˾ , ,���ϲƸ�-ABCD-��������,�� ,15.40 ,���׳ɹ� ,Ͷ������ ,123456 , ,2020-06-02 15:34:06 ,
֧�� ,��ݸ�ϵ»����޹�˾ ,dgb***@yum.com ,KFCAPIDGB012345,�� ,79.00 ,���׳ɹ� ,������ʳ ,123456 ,ABC9876 ,2020-06-14 12:43:26 ,
���� ,*�� ,111******11 ,��Ʒ , ,10.00,���׳ɹ� ,���� ,123456 ,123456 ,2021-06-24 00:00:00 ,
���� ,*�� ,111******11 ,�Ҿ����ת���� ,��� ,42.00 ,���׳ɹ� ,ת�˺�� ,123456 , ,2021-06-25 00:00:00 ,
------------------------------------------------------------------------------------
������Ϣ��
������TripleZ
Expand Down
26 changes: 13 additions & 13 deletions example/huobi/example-huobi-output.beancount
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
option "title" "测试"
option "operating_currency" "CNY"

1970-01-01 open Income:Huobi:PnL
1970-01-01 open Assets:Rule1:Cash
1970-01-01 open Assets:Rule1:Positions
1970-01-01 open Income:Rule1:PnL
1970-01-01 open Expenses:Rule1:Commission
1970-01-01 open Assets:Huobi:Cash
1970-01-01 open Assets:Huobi:Positions
1970-01-01 open Assets:Rule1:Cash
1970-01-01 open Assets:Rule1:Positions
1970-01-01 open Expenses:Huobi:Commission
1970-01-01 open Expenses:Rule1:Commission
1970-01-01 open Income:Huobi:PnL
1970-01-01 open Income:Rule1:PnL

2021-02-23 * "Huobi-币币交易" "买入-BTC/USDT"
Assets:Huobi:Cash -13.98369600 USDT
Assets:Huobi:Positions 0.00030400 BTC {45999.00000000 USDT} @@ 13.98369600 USDT
Assets:Huobi:Cash -0.00000060 BTC @ 45999.00000000 USDT
Expenses:Huobi:Commission 0.00000060 BTC @ 45999.00000000 USDT
Assets:Rule1:Cash -13.98369600 USDT
Assets:Rule1:Positions 0.00030400 BTC {45999.00000000 USDT} @@ 13.98369600 USDT
Assets:Rule1:Cash -0.00000060 BTC @ 45999.00000000 USDT
Expenses:Rule1:Commission 0.00000060 BTC @ 45999.00000000 USDT

2021-02-23 * "Huobi-币币交易" "买入-BTC1S/USDT"
Assets:Huobi:Cash -5.60652159 USDT
Assets:Huobi:Positions 4.57600000 BTC1S {1.22520000 USDT} @@ 5.60652159 USDT
Assets:Huobi:Cash -0.00915201 BTC1S @ 1.22520000 USDT
Expenses:Huobi:Commission 0.00915201 BTC1S @ 1.22520000 USDT
Assets:Rule1:Cash -5.60652159 USDT
Assets:Rule1:Positions 4.57600000 BTC1S {1.22520000 USDT} @@ 5.60652159 USDT
Assets:Rule1:Cash -0.00915201 BTC1S @ 1.22520000 USDT
Expenses:Rule1:Commission 0.00915201 BTC1S @ 1.22520000 USDT

2021-02-24 * "Huobi-币币交易" "卖出-BTC/USDT"
Assets:Huobi:Positions -0.00010800 BTC {} @ 49850.00000000 USDT
Expand Down
12 changes: 6 additions & 6 deletions example/wechat/example-wechat-output.beancount
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
option "title" "测试"
option "operating_currency" "CNY"

1970-01-01 open Assets:Bank:CN:BOC:Savings
1970-01-01 open Assets:Bank:CN:ICBC:Savings
1970-01-01 open Assets:Digital:WeChat:Cash
1970-01-01 open Income:Service
1970-01-01 open Expenses:FIXME
1970-01-01 open Assets:Digital:Wechat:Cash
1970-01-01 open Assets:FIXME
1970-01-01 open Assets:Bank:CN:BOC:Savings
1970-01-01 open Income:Wechat:RedPacket
1970-01-01 open Expenses:FIXME
1970-01-01 open Expenses:Food:Meal
1970-01-01 open Expenses:Housing:Rent
1970-01-01 open Assets:Digital:Wechat:Cash
1970-01-01 open Assets:Bank:CN:ICBC:Savings
1970-01-01 open Income:Service
1970-01-01 open Income:Wechat:RedPacket

2019-09-24 * "同性好友" "/"
Assets:Digital:Wechat:Cash 0.35 CNY
Expand Down
9 changes: 7 additions & 2 deletions pkg/compiler/beancount/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,15 @@ func (b *BeanCount) writeHeader(file *os.File) error {
}

accounts := b.GetAllCandidateAccounts(b.Config)
var sortedAccounts []string
for k := range accounts {
if k == "" {
continue
if k != "" {
sortedAccounts = append(sortedAccounts, k)
}
}
sort.Strings(sortedAccounts)

for _, k := range sortedAccounts {
_, err = io.WriteString(file, "1970-01-01 open "+k+"\n")
if err != nil {
return fmt.Errorf("write open account error: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/beancount/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
var normalOrder = `{{ .PayTime.Format "2006-01-02" }} * "{{ .Peer }}" "{{ .Item }}"{{ if .Note }} ; {{ .Note }}{{ end }}
{{ .PlusAccount }} {{ .Money | printf "%.2f" }} {{ .Currency }}
{{ .MinusAccount }} -{{ .Money | printf "%.2f" }} {{ .Currency }}
{{ if .PnlAccount }}{{ .PnlAccount }}{{ printf "\n" }}{{ end }}
{{ if .PnlAccount }} {{ .PnlAccount }}{{ printf "\n" }}{{ end }}
`

type NormalOrderVars struct {
Expand Down

0 comments on commit 608ad73

Please sign in to comment.