Skip to content

Commit

Permalink
Fix alipay format change (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
wchen9 committed Mar 1, 2023
1 parent d765283 commit da0c4e7
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 229 deletions.
4 changes: 2 additions & 2 deletions example/alipay/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ alipay:
- method: 余额宝
fullMatch: true
methodAccount: Assets:Alipay
- method: 招商银行(9876)
- method: 交通银行信用卡(7449)
fullMatch: true
methodAccount: Assets:Bank:CN:CMB-9876:Savings
methodAccount: Liabilities:CC:COMM:7449

# 交易类型为其他
- type: 其他
Expand Down
203 changes: 39 additions & 164 deletions example/alipay/example-alipay-output.beancount
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ option "operating_currency" "CNY"
1970-01-01 open Assets:Alipay
1970-01-01 open Assets:Alipay:Invest:Fund
1970-01-01 open Assets:Alipay:Invest:Gold
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
Expand All @@ -16,187 +15,63 @@ option "operating_currency" "CNY"
1970-01-01 open Income:Alipay:ShouKuanMa
1970-01-01 open Income:Alipay:YuEBao:PnL
1970-01-01 open Income:FIXME
1970-01-01 open Liabilities:CC:COMM:7449

2020-06-02 * "蚂蚁财富-蚂蚁(杭州)基金销售有限公司" "蚂蚁财富-ABCD-卖出至余额宝"
category: "投资理财"
method: "余额宝"
orderId: "123456"
payTime: "2020-06-02 15:34:06 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "其他"
Assets:Alipay 15.40 CNY
Assets:Alipay:Invest:Fund -15.40 CNY
Income:Alipay:Invest:PnL

2020-06-09 * "广发基金管理有限公司" "余额宝-2020.06.08-收益发放"
category: "投资理财"
method: "余额宝"
orderId: "123456"
payTime: "2020-06-09 02:57:13 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "其他"
Assets:Alipay 0.11 CNY
Income:Alipay:YuEBao:PnL -0.11 CNY

2020-06-14 * "东莞肯德基有限公司" "KFCAPIDGB012345"
category: "餐饮美食"
merchantId: "ABC9876"
method: "余额宝"
orderId: "123456"
payTime: "2020-06-14 12:43:26 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "支出"
Expenses:Food:Lunch 79.00 CNY
Assets:Alipay -79.00 CNY

2021-05-19 * "蚂蚁财富-蚂蚁(杭州)基金销售有限公司" "蚂蚁财富-XZY指数C-买入"
category: "投资理财"
orderId: "123456"
payTime: "2021-05-19 09:42:54 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "其他"
Assets:Alipay:Invest:Fund 50.00 CNY
Assets:Alipay -50.00 CNY

2021-05-20 * "苏宁易购官方旗舰店" "【礼遇价】三星128g内存卡microSD存储卡tf卡行车记录仪卡switch监控摄像头"
category: "数码电器"
merchantId: "ABC9876"
method: "招商银行(9876)"
orderId: "123456"
payTime: "2021-05-20 12:34:34 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "支出"
Expenses:Electronics 87.90 CNY
Assets:Bank:CN:CMB-9876:Savings -87.90 CNY

2021-05-30 * "广发基金管理有限公司" "余额宝-单次转入"
category: "投资理财"
merchantId: "ABC9876"
method: "余额"
orderId: "123456"
payTime: "2021-05-30 23:43:37 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "其他"
Assets:Alipay 2.00 CNY
Assets:Alipay -2.00 CNY

2021-06-01 * "dettol滴露官方旗舰店" "【直接下单付款】滴露消毒液1.2L*2家用杀菌消毒水衣物地板宠物"
category: "日用百货"
merchantId: "ABC9876"
method: "招商银行(9876)"
orderId: "123456"
payTime: "2021-06-01 00:10:22 +0800 CST"
source: "支付宝"
status: "交易关闭"
txType: "支出"
Expenses:Groceries 109.90 CNY
Assets:Bank:CN:CMB-9876:Savings -109.90 CNY

2021-06-01 * "dettol滴露官方旗舰店" "退款-【直接下单付款】滴露消毒液1.2L*2家用杀菌消毒水衣物地板宠物"
category: "退款"
merchantId: "ABC9876"
method: "招商银行(9876)"
orderId: "123456"
payTime: "2021-06-01 00:13:56 +0800 CST"
source: "支付宝"
status: "退款成功"
txType: "其他"
Assets:Bank:CN:CMB-9876:Savings 109.90 CNY
Expenses:Groceries -109.90 CNY

2021-06-01 * "dettol滴露官方旗舰店" "退款-【直接下单付款】滴露消毒液1.2L*2家用杀菌消毒水衣物地板宠物"
category: "退款"
merchantId: "ABC9876"
method: "招商银行(9876)"
orderId: "123456"
payTime: "2021-06-01 00:13:56 +0800 CST"
source: "支付宝"
status: "退款成功"
txType: "收入"
Assets:Bank:CN:CMB-9876:Savings 109.90 CNY
Expenses:Groceries -109.90 CNY

2021-06-14 * "蚂蚁会员(北京)网络技术服务有限公司" "相互宝分摊-6月第1期-*"
category: "互助保障"
merchantId: "ABC9876"
method: "招商银行(9876)"
orderId: "123456"
payTime: "2021-06-14 14:00:38 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "支出"
Expenses:Insurance 6.51 CNY
Assets:Bank:CN:CMB-9876:Savings -6.51 CNY

2021-06-24 * "*三" "商品"
category: "收入"
merchantId: "123456"
orderId: "123456"
payTime: "2021-06-24 00:00:00 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "收入"
Assets:Alipay 10.00 CNY
Income:Alipay:ShouKuanMa -10.00 CNY

2021-06-25 * "*三" "我就随便转着玩"
2023-01-18 * "xxxx" "转账"
category: "转账红包"
method: "余额"
orderId: "123456"
payTime: "2021-06-25 00:00:00 +0800 CST"
orderId: "2xxxxxxxxxxxxxxxxxxxxxxxxx9"
payTime: "2023-01-18 10:17:29 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "收入"
Assets:Alipay 42.00 CNY
Income:FIXME -42.00 CNY
Assets:Alipay 222228.50 CNY
Income:FIXME -222228.50 CNY

2021-09-29 * "蚂蚁财富-蚂蚁(杭州)基金销售有限公司" "蚂蚁财富-财通资管鸿达纯债债券E-买入"
2023-02-02 * "蚂蚁财富-蚂蚁(杭州)基金销售有限公司" "蚂蚁财富-交银定期支付双息平衡混合-卖出至余额宝"
category: "投资理财"
orderId: "2021092900108"
payTime: "2021-09-29 09:35:12 +0800 CST"
method: "余额宝"
orderId: "2xxxxxxxxxxxxxxxxxxxxxxxxxx8"
payTime: "2023-02-02 15:24:35 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "其他"
Assets:Alipay:Invest:Fund 20.00 CNY
Assets:Alipay -20.00 CNY
txType: "不计收支"
Expenses:FIXME 99.34 CNY
Assets:Alipay -99.34 CNY

2021-09-29 * "易方达黄金-蚂蚁(杭州)基金销售有限公司" "易方达黄金-买入"
category: "投资理财"
orderId: "2021092900108"
payTime: "2021-09-29 10:31:41 +0800 CST"
2023-02-04 * "xxxxxxx" "退款-亲情卡"
category: "退款"
merchantId: "20xxxxxxxxxxxxxxxx5"
method: "交通银行信用卡(7449)"
orderId: "2xxxxxxxxxxxxxxxx8"
payTime: "2023-02-04 18:21:04 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "其他"
Assets:Alipay:Invest:Fund 3000.00 CNY
Assets:Alipay -3000.00 CNY
status: "退款成功"
txType: "不计收支"
Liabilities:CC:COMM:7449 16.03 CNY
Expenses:FIXME -16.03 CNY

2021-12-09 * "好邻居连锁便利店" "好邻居订单"
2023-02-08 * "x4***6" "商品示例"
category: "日用百货"
merchantId: "10000891202112098830044"
method: "招商银行(9876)"
orderId: "2021120922001468815735046417"
payTime: "2021-12-09 09:25:42 +0800 CST"
merchantId: "Txxxxxxxxxxxxx0"
method: "余额"
orderId: "2xxxxxxxxxxxxxx0"
payTime: "2023-02-08 14:16:52 +0800 CST"
source: "支付宝"
status: "交易成功"
status: "等待确认收货"
txType: "支出"
Expenses:Groceries 7.50 CNY
Assets:Bank:CN:CMB-9876:Savings -7.50 CNY
Expenses:Groceries 20.00 CNY
Assets:Alipay -20.00 CNY

2021-12-11 * "北京稻香村食品有限责任公司" "北京稻香村食品有限责任公司"
category: "餐饮美食"
merchantId: "322017092208872157020004030330000032112115225418"
method: "招商银行(9876)"
orderId: "2021121122001468815736847417"
payTime: "2021-12-11 16:53:51 +0800 CST"
2023-02-12 * "xxxxxxxxxxxx" "亲情卡"
category: "亲友代付"
merchantId: "20230xxxxxxx014741014xxxxxx"
method: "交通银行信用卡(7449)"
orderId: "202302xxxxxx0011000103xxxxxx"
payTime: "2023-02-12 21:32:14 +0800 CST"
source: "支付宝"
status: "交易成功"
txType: "支出"
Expenses:Food:Dinner 31.00 CNY
Assets:Bank:CN:CMB-9876:Savings -31.00 CNY
Expenses:FIXME 49.74 CNY
Liabilities:CC:COMM:7449 -49.74 CNY

47 changes: 19 additions & 28 deletions example/alipay/example-alipay-records.csv
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
------------------------֧�������й������缼�����޹�˾ ���ӿͻ��ص�------------------------
��/֧ ,���׶Է� ,�Է��˺� ,��Ʒ˵�� ,��/���ʽ ,��� ,����״̬ ,���׷��� ,���׶����� ,�̼Ҷ����� ,����ʱ�� ,
֧�� ,���ϻ�Ա�����������缼���������޹�˾ , ,�໥����̯-6�µ�1��-* ,��������(9876) ,6.51 ,���׳ɹ� ,�������� ,123456 ,ABC9876 ,2021-06-14 14:00:38 ,
���� ,dettol��¶�ٷ��콢�� ,zhi***@hkmanon.com ,�˿�-��ֱ���µ������¶����Һ1.2L*2����ɱ������ˮ����ذ����,��������(9876) ,109.90 ,�˿�ɹ� ,�˿� ,123456 ,ABC9876 ,2021-06-01 00:13:56 ,
���� ,dettol��¶�ٷ��콢�� ,zhi***@hkmanon.com ,�˿�-��ֱ���µ������¶����Һ1.2L*2����ɱ������ˮ����ذ����,��������(9876) ,109.90 ,�˿�ɹ� ,�˿� ,123456 ,ABC9876 ,2021-06-01 00:13:56 ,
֧�� ,dettol��¶�ٷ��콢�� ,zhi***@hkmanon.com ,��ֱ���µ������¶����Һ1.2L*2����ɱ������ˮ����ذ����,��������(9876) ,109.90 ,���׹ر� ,���ðٻ� ,123456 ,ABC9876 ,2021-06-01 00:10:22 ,
���� ,�㷢����������޹�˾ ,e-f***@gffunds.com.cn,��-����ת�� ,��� ,2.00 ,���׳ɹ� ,Ͷ������ ,123456 ,ABC9876 ,2021-05-30 23:43:37 ,
���� ,�㷢����������޹�˾ , ,��-2020.06.08-���淢�� ,�� ,0.11 ,���׳ɹ� ,Ͷ������ ,123456 , ,2020-06-09 02:57:13 ,
֧�� ,�����׹��ٷ��콢�� ,sns***@cnsuning.com ,�������ۡ�����128g�ڴ濨microSD�洢��tf���г���¼�ǿ�switch�������ͷ,��������(9876) ,87.90 ,���׳ɹ� ,������� ,123456 ,ABC9876 ,2021-05-20 12:34:34 ,
���� ,���ϲƸ�-���ϣ����ݣ������������޹�˾ , ,���ϲƸ�-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 ,
֧�� ,���������ʳƷ�������ι�˾ , ,���������ʳƷ�������ι�˾ ,��������(9876) ,31.00 ,���׳ɹ� ,������ʳ ,2021121122001468815736847417 ,322017092208872157020004030330000032112115225418 ,2021-12-11 16:53:51 ,
֧�� ,���ھ����������� ,hao***@qq.com ,���ھӶ��� ,��������(9876) ,7.50 ,���׳ɹ� ,���ðٻ� ,2021120922001468815735046417 ,10000891202112098830044 ,2021-12-09 09:25:42 ,
���� ,�׷���ƽ�-���ϣ����ݣ������������޹�˾, ,�׷���ƽ�-���� , ,3000.00 ,���׳ɹ� ,Ͷ������ ,2021092900108 , ,2021-09-29 10:31:41 ,
���� ,���ϲƸ�-���ϣ����ݣ������������޹�˾ , ,���ϲƸ�-��ͨ�ʹܺ�﴿ծծȯE-���� , ,20.00 ,���׳ɹ� ,Ͷ������ ,2021092900108 , ,2021-09-29 09:35:12 ,
------------------------------------------------------------------------------------
������Ϣ��
������TripleZ
֧�����˻���[email protected]
��ʼʱ�䣺[2021-05-19 00:00:00] ��ֹʱ�䣺[2021-06-19 23:59:59]
����ʱ�䣺[2021-06-19 03:10:16]
��21�ʼ�¼
���룺0��,0.00Ԫ
֧����x��,1234.56Ԫ
������x��,9876.54Ԫ
������xx
֧�����˻���[email protected]
��ʼʱ�䣺[2023-02-10 00:00:00] ��ֹʱ�䣺[2023-02-13 23:59:59]
�����������ͣ�[ȫ��]
����ʱ�䣺[2023-02-13 09:12:52]
��66�ʼ�¼
���룺1�� 28.50Ԫ
֧����63�� 16.54Ԫ
������֧��2�� 16.37Ԫ

�ر���ʾ��
1.���ص����ݿɱ���֧������������Ӧ֧���������룬��ϵͳԭ���ͨѶ���ϵ�ż�����ص��±��ص���ʵ�ʽ��׽������ʱ����ʵ�ʽ������Ϊ׼��
2.���𽫱��ص���Ϊ�տ������ƾ��ʹ�ã����֤�˻�ʵ�ʵ���������ٽ��з���������
3.֧�������֧���ȷ����֧����ʽ���ܼȲ���֧��������Ҳͬ���������н��ף��������ʹ�ñ��ص������ظ����ˣ�
4.���ص��羭����Ϳ�ġ����죬������ʧȥЧ����
5.�����˵��磺��ֵ���֡��˻�ת����߸���������֧�Ȳ�����Ϊ�������֧������Ϊ�����ࣻ
4.���ص��羭�κ�Ϳ�ġ����죬������ʧȥЧ����
5.�����˵��磺��ֵ���֡��˻�ת����߸���������֧�Ȳ�����Ϊ�������֧������Ϊ������֧�
6.��ͳ���߼���ͬ����ϸ���ֱ���ۼӺ󣬿��ܻ���·�ͳ�ƽ�һ�£�����ʵ�ʽ��׽��Ϊ׼��
7.��ֹ�����ص����ڷǷ���;��
8.����ϸ��չʾ��ǰ�˵��еĽ��ף���������ɾ���ļ�¼��
9.����ϸ�������˶���ʹ�á�

------------------------֧�������й������缼�����޹�˾ ���ӿͻ��ص�------------------------
����ʱ�� ,���׷��� ,���׶Է� ,�Է��˺� ,��Ʒ˵�� ,��/֧ ,��� ,��/���ʽ ,����״̬ ,���׶����� ,�̼Ҷ����� ,��ע ,
2023-02-12 21:32:14 ,���Ѵ��� ,xxxxxxxxxxxx ,/ ,���鿨 ,֧�� ,49.74 ,��ͨ�������ÿ�(7449) ,���׳ɹ� ,202302xxxxxx0011000103xxxxxx ,20230xxxxxxx014741014xxxxxx , ,
2023-02-08 14:16:52 ,���ðٻ� ,x4***6 ,rim***@qq.com ,��Ʒʾ�� ,֧�� ,20.00 ,��� ,�ȴ�ȷ���ջ� ,2xxxxxxxxxxxxxx0 ,Txxxxxxxxxxxxx0 , ,
2023-02-04 18:21:04 ,�˿� ,xxxxxxx ,/ ,�˿�-���鿨 ,������֧ ,16.03 ,��ͨ�������ÿ�(7449) ,�˿�ɹ� ,2xxxxxxxxxxxxxxxx8 ,20xxxxxxxxxxxxxxxx5 , ,
2023-02-02 15:24:35 ,Ͷ������ ,���ϲƸ�-���ϣ����ݣ������������޹�˾ ,/ ,���ϲƸ�-��������֧��˫Ϣƽ����-��������,������֧ ,99.34 ,�� ,���׳ɹ� ,2xxxxxxxxxxxxxxxxxxxxxxxxxx8 , , ,
2023-01-18 10:17:29 ,ת�˺�� ,xxxx ,xxx***@163.com ,ת�� ,���� ,222228.50 ,��� ,���׳ɹ� ,2xxxxxxxxxxxxxxxxxxxxxxxxx9 , , ,
17 changes: 11 additions & 6 deletions pkg/provider/alipay/alipay.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package alipay
import (
"encoding/csv"
"fmt"
"io"
"log"

"github.com/deb-sig/double-entry-generator/pkg/io/reader"
"github.com/deb-sig/double-entry-generator/pkg/ir"
"io"
"log"
"strings"
)

// Alipay is the provider for alipay.
Expand Down Expand Up @@ -70,9 +70,14 @@ func (a *Alipay) Translate(filename string) (*ir.IR, error) {
return nil, err
}

if len(line) != 12 {
// TODO(gaocegege): Support statistics.
a.LineNum++
if a.LineNum == 0 && strings.Contains(line[0], "支付宝") {
return nil, fmt.Errorf("可能为支付宝老版本 csv 账单,请使用 1.7.0 及之前的版本尝试转换")
}

a.LineNum++

if a.LineNum <= 23 {
// bypass the useless
continue
}

Expand Down
Loading

0 comments on commit da0c4e7

Please sign in to comment.