diff --git a/example/icbc/credit/example-icbc-credit-records.csv b/example/icbc/credit/example-icbc-credit-records.csv index 79c9930..d333273 100644 --- a/example/icbc/credit/example-icbc-credit-records.csv +++ b/example/icbc/credit/example-icbc-credit-records.csv @@ -5,13 +5,13 @@ 子账户类别: 交易日期,记账日期,摘要,交易场所,交易国家或地区简称,交易金额(收入),交易金额(支出),交易币种,记账金额(收入),记账金额(支出),记账币种,余额,对方户名 +2023-04-22 ,2023-04-22 ,"银联在线支付 ",XX旗舰店 ,"CHN "," ","0.01 ",人民币 ," ","0.01 ",人民币 ,"-6,086.11 "," ", 2023-05-05 ,2023-05-05 ,"消费 ","财付通-拼多多平台商户 ","CHN "," ","18.00 ",人民币 ," ","18.00 ",人民币 ,"-3,728.62 "," ", 2023-05-05 ,2023-05-05 ,"消费 ","支付宝-金拱门(中国)有限公司 ","CHN "," ","26.00 ",人民币 ," ","26.00 ",人民币 ,"-3,710.62 "," ", 2023-05-04 ,2023-05-04 ,"ETC ","广东联合电子收费股份 ","CHN "," ","12.35 ",人民币 ," ","12.35 ",人民币 ,"-3,684.62 "," ", 2023-05-02 ,2023-05-02 ,"消费 ","支付宝-北京百度网讯科技有限公司 ","CHN "," ","17.32 ",人民币 ," ","17.32 ",人民币 ,"-3,648.27 "," ", 2023-04-25 ,2023-04-25 ,"人民币自动转帐还款 ",XX分行银行卡中心 ,"CHN ","4,621.01 "," ",人民币 ,"4,621.01 "," ",人民币 ,"-1,971.63 "," ", 2023-04-22 ,2023-04-22 ,"消费 ","财付通-美团平台商户 ","CHN "," ","238.00 ",人民币 ," ","238.00 ",人民币 ,"-6,324.11 "," ", -2023-04-22 ,2023-04-22 ,"银联在线支付 ",XX旗舰店 ,"CHN "," ","0.01 ",人民币 ," ","0.01 ",人民币 ,"-6,086.11 "," ", 2023-03-20 ,2023-03-20 ,"消费 ",财付通-餐馆 ,"CHN "," ","22.00 ",人民币 ," ","22.00 ",人民币 ,"-16,064.73 "," ", 2023-03-20 ,2023-03-20 ,"******************** ","广东联合电子收费股份 ","CHN "," ","29.45 ",人民币 ," ","29.45 ",人民币 ,"-16,042.73 "," ", diff --git a/example/icbc/debit/config.yaml b/example/icbc/debit-v1/config.yaml similarity index 100% rename from example/icbc/debit/config.yaml rename to example/icbc/debit-v1/config.yaml diff --git a/example/icbc/debit/example-icbc-debit-output.beancount b/example/icbc/debit-v1/example-icbc-debit-v1-output.beancount similarity index 84% rename from example/icbc/debit/example-icbc-debit-output.beancount rename to example/icbc/debit-v1/example-icbc-debit-v1-output.beancount index d98f9c8..657efb8 100644 --- a/example/icbc/debit/example-icbc-debit-output.beancount +++ b/example/icbc/debit-v1/example-icbc-debit-v1-output.beancount @@ -67,3 +67,13 @@ option "operating_currency" "CNY" Assets:Bank:CN:ICBC 1234.56 CNY Assets:Borrow -1234.56 CNY +2023-05-02 * "广东三元麦当劳食品有 深圳市财付通支付科技有限公司" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "深圳市财付通支付科技有限公司" + source: "中国工商银行" + txType: "消费" + type: "支出" + Expenses:FIXME 13.40 CNY + Assets:Bank:CN:ICBC -13.40 CNY + diff --git a/example/icbc/debit/example-icbc-debit-output.ledger b/example/icbc/debit-v1/example-icbc-debit-v1-output.ledger similarity index 84% rename from example/icbc/debit/example-icbc-debit-output.ledger rename to example/icbc/debit-v1/example-icbc-debit-v1-output.ledger index f9320f9..c6eeba3 100644 --- a/example/icbc/debit/example-icbc-debit-output.ledger +++ b/example/icbc/debit-v1/example-icbc-debit-v1-output.ledger @@ -65,3 +65,13 @@ Assets:Bank:CN:ICBC 1234.56 CNY Assets:Borrow - 1234.56 CNY +2023/05/02 * 广东三元麦当劳食品有 深圳市财付通支付科技有限公司 + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "深圳市财付通支付科技有限公司" + ; source: "中国工商银行" + ; txType: "消费" + ; type: "支出" + Expenses:FIXME 13.40 CNY + Assets:Bank:CN:ICBC - 13.40 CNY + diff --git a/example/icbc/debit/example-icbc-debit-records.csv b/example/icbc/debit-v1/example-icbc-debit-v1-records.csv similarity index 92% rename from example/icbc/debit/example-icbc-debit-records.csv rename to example/icbc/debit-v1/example-icbc-debit-v1-records.csv index d3a1d9e..362b69e 100644 --- a/example/icbc/debit/example-icbc-debit-records.csv +++ b/example/icbc/debit-v1/example-icbc-debit-v1-records.csv @@ -5,7 +5,7 @@ 子账户序号: 00000,子账户类别: 活期,"子账户别名: " 交易日期,摘要,交易场所,交易国家或地区简称,钞/汇,交易金额(收入),交易金额(支出),交易币种,记账金额(收入),记账金额(支出),记账币种,余额,对方户名 -2023-05-02 ,"消费 ","财付通-广东三元麦当劳食品有 ","CHN ",钞 ,"- ","- ",- ," ","13.40 ",人民币 ,"xx,yyyy.zz ","深圳市财付通支付科技有限公司 ", +2023-05-02 ,"消费 ","广东三元麦当劳食品有 ","CHN ",钞 ,"- ","- ",- ," ","13.40 ",人民币 ,"xx,yyyy.zz ","深圳市财付通支付科技有限公司 ", 2023-04-25 ,"自动还款 ","广东XX分行银行卡中心 ","CHN ",钞 ,"- ","- ",- ," ","1,234.56 ",人民币 ,"xx,yyyy.zz ","张三 ", 2023-04-22 ,"他行汇入 "," ","CHN ",钞 ,"- ","- ",- ,"1,234.56 "," ",人民币 ,"xx,yyyy.zz ","李四 ", 2023-04-20 ,"银联消费 "," ","CHN ",钞 ,"- ","- ",- ," ","1,234.56 ",人民币 ,"xx,yyyy.zz ","银联无卡支付业务((特约)掌上生活还款) ", diff --git a/example/icbc/debit-v2/config.yaml b/example/icbc/debit-v2/config.yaml new file mode 100644 index 0000000..d534558 --- /dev/null +++ b/example/icbc/debit-v2/config.yaml @@ -0,0 +1,22 @@ +defaultMinusAccount: Assets:FIXME +defaultPlusAccount: Expenses:FIXME +defaultCashAccount: Assets:Bank:CN:ICBC +defaultCurrency: CNY +title: 测试 +icbc: + rules: + - peer: 财付通-,支付宝- + ignore: true + - peer: 支付宝 + txType: 蚂蚁基金赎回到银行 + ignore: true + - peer: 总行信用卡合伙人 + targetAccount: Income:Bank:ICBC:CreditCard + - peer: 掌上生活还款 + targetAccount: Liabilities:Bank:CMB:CreditCard + - txType: 自动还款 + peer: 广东XX分行银行卡中心 + ignore: true + - peer: 张三,李四,王五 + txTpe: 汇款,网转,汇入 + targetAccount: Assets:Borrow diff --git a/example/icbc/debit-v2/example-icbc-debit-v2-output.beancount b/example/icbc/debit-v2/example-icbc-debit-v2-output.beancount new file mode 100644 index 0000000..2b6cf62 --- /dev/null +++ b/example/icbc/debit-v2/example-icbc-debit-v2-output.beancount @@ -0,0 +1,86 @@ +option "title" "测试" +option "operating_currency" "CNY" + +1970-01-01 open Assets:Borrow +1970-01-01 open Assets:FIXME +1970-01-01 open Expenses:FIXME +1970-01-01 open Income:Bank:ICBC:CreditCard +1970-01-01 open Liabilities:Bank:CMB:CreditCard + +2023-02-10 * "总行信用卡合伙人" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "总行信用卡合伙人" + peerAccountNum: "1234****9876" + source: "中国工商银行" + txType: "合伙人返现" + type: "收入" + Assets:Bank:CN:ICBC 30.00 CNY + Income:Bank:ICBC:CreditCard -30.00 CNY + +2023-02-20 * "手机银行 张三" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "张三" + peerAccountNum: "1234****9876" + source: "中国工商银行" + txType: "跨行汇款" + type: "支出" + Assets:Borrow 1234.56 CNY + Assets:Bank:CN:ICBC -1234.56 CNY + +2023-04-14 * "ABC公司" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "ABC公司" + peerAccountNum: "1234****9876" + source: "中国工商银行" + txType: "工资" + type: "收入" + Assets:Bank:CN:ICBC 1234.56 CNY + Assets:FIXME -1234.56 CNY + +2023-04-14 * "手机银行 王五" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "王五" + peerAccountNum: "1234****9876" + source: "中国工商银行" + txType: "网转" + type: "支出" + Assets:Borrow 500.00 CNY + Assets:Bank:CN:ICBC -500.00 CNY + +2023-04-20 * "银联无卡支付业务((特约)掌上生活还款)" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "银联无卡支付业务((特约)掌上生活还款)" + peerAccountNum: "1234****9876" + source: "中国工商银行" + txType: "银联消费" + type: "支出" + Liabilities:Bank:CMB:CreditCard 1234.56 CNY + Assets:Bank:CN:ICBC -1234.56 CNY + +2023-04-22 * "李四" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "李四" + peerAccountNum: "1234****9876" + source: "中国工商银行" + txType: "他行汇入" + type: "收入" + Assets:Bank:CN:ICBC 1234.56 CNY + Assets:Borrow -1234.56 CNY + +2023-05-02 * "广东三元麦当劳食品有 深圳市财付通支付科技有限公司" + cardName: "这是卡别名" + currency: "人民币" + peerAccount: "深圳市财付通支付科技有限公司" + peerAccountNum: "1234****9876" + source: "中国工商银行" + txType: "消费" + type: "支出" + Expenses:FIXME 13.40 CNY + Assets:Bank:CN:ICBC -13.40 CNY + diff --git a/example/icbc/debit-v2/example-icbc-debit-v2-output.ledger b/example/icbc/debit-v2/example-icbc-debit-v2-output.ledger new file mode 100644 index 0000000..2fd9bde --- /dev/null +++ b/example/icbc/debit-v2/example-icbc-debit-v2-output.ledger @@ -0,0 +1,84 @@ +1970/01/01 * Open Balance + Assets:Borrow 0 CNY + Assets:FIXME 0 CNY + Expenses:FIXME 0 CNY + Income:Bank:ICBC:CreditCard 0 CNY + Liabilities:Bank:CMB:CreditCard 0 CNY + Equity:Opening Balances +2023/02/10 * 总行信用卡合伙人 + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "总行信用卡合伙人" + ; peerAccountNum: "1234****9876" + ; source: "中国工商银行" + ; txType: "合伙人返现" + ; type: "收入" + Assets:Bank:CN:ICBC 30.00 CNY + Income:Bank:ICBC:CreditCard - 30.00 CNY + +2023/02/20 * 手机银行 张三 + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "张三" + ; peerAccountNum: "1234****9876" + ; source: "中国工商银行" + ; txType: "跨行汇款" + ; type: "支出" + Assets:Borrow 1234.56 CNY + Assets:Bank:CN:ICBC - 1234.56 CNY + +2023/04/14 * ABC公司 + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "ABC公司" + ; peerAccountNum: "1234****9876" + ; source: "中国工商银行" + ; txType: "工资" + ; type: "收入" + Assets:Bank:CN:ICBC 1234.56 CNY + Assets:FIXME - 1234.56 CNY + +2023/04/14 * 手机银行 王五 + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "王五" + ; peerAccountNum: "1234****9876" + ; source: "中国工商银行" + ; txType: "网转" + ; type: "支出" + Assets:Borrow 500.00 CNY + Assets:Bank:CN:ICBC - 500.00 CNY + +2023/04/20 * 银联无卡支付业务((特约)掌上生活还款) + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "银联无卡支付业务((特约)掌上生活还款)" + ; peerAccountNum: "1234****9876" + ; source: "中国工商银行" + ; txType: "银联消费" + ; type: "支出" + Liabilities:Bank:CMB:CreditCard 1234.56 CNY + Assets:Bank:CN:ICBC - 1234.56 CNY + +2023/04/22 * 李四 + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "李四" + ; peerAccountNum: "1234****9876" + ; source: "中国工商银行" + ; txType: "他行汇入" + ; type: "收入" + Assets:Bank:CN:ICBC 1234.56 CNY + Assets:Borrow - 1234.56 CNY + +2023/05/02 * 广东三元麦当劳食品有 深圳市财付通支付科技有限公司 + ; cardName: "这是卡别名" + ; currency: "人民币" + ; peerAccount: "深圳市财付通支付科技有限公司" + ; peerAccountNum: "1234****9876" + ; source: "中国工商银行" + ; txType: "消费" + ; type: "支出" + Expenses:FIXME 13.40 CNY + Assets:Bank:CN:ICBC - 13.40 CNY + diff --git a/example/icbc/debit-v2/example-icbc-debit-v2-records.csv b/example/icbc/debit-v2/example-icbc-debit-v2-records.csv new file mode 100644 index 0000000..577f61f --- /dev/null +++ b/example/icbc/debit-v2/example-icbc-debit-v2-records.csv @@ -0,0 +1,20 @@ +明细查询文件下载 + +卡号: 1234****9876,"卡别名: 这是卡别名" + +子账户序号: 00000,子账户类别: 活期,"子账户别名: " + +交易日期,摘要,交易详情,交易场所,交易国家或地区简称,钞/汇,交易金额(收入),交易金额(支出),交易币种,记账金额(收入),记账金额(支出),记账币种,余额,对方户名,对方账户 +2023-05-02 ,"消费 "," ","广东三元麦当劳食品有 ","CHN ",钞 ,"- ","- ",- ," ","13.40 ",人民币 ,"xx,yyyy.zz ","深圳市财付通支付科技有限公司 ","1234****9876 ", +2023-04-25 ,"自动还款 "," ","广东XX分行银行卡中心 ","CHN ",钞 ,"- ","- ",- ," ","1,234.56 ",人民币 ,"xx,yyyy.zz ","张三 ","1234****9876 ", +2023-04-22 ,"他行汇入 "," "," ","CHN ",钞 ,"- ","- ",- ,"1,234.56 "," ",人民币 ,"xx,yyyy.zz ","李四 ","1234****9876 ", +2023-04-20 ,"银联消费 "," "," ","CHN ",钞 ,"- ","- ",- ," ","1,234.56 ",人民币 ,"xx,yyyy.zz ","银联无卡支付业务((特约)掌上生活还款) ","1234****9876 ", +2023-04-14 ,"工资 "," "," ","CHN ",钞 ,"- ","- ",- ,"1,234.56 "," ",人民币 ,"xx,yyyy.zz ","ABC公司 ","1234****9876 ", +2023-04-14 ,"网转 "," ","手机银行 ","CHN ",钞 ,"- ","- ",- ," ","500.00 ",人民币 ,"xx,yyyy.zz ","王五 ","1234****9876 ", +2023-02-28 ,"蚂蚁基金赎回到银行 "," ","支付宝 ","CHN ",钞 ,"- ","- ",- ,"341.58 "," ",人民币 ,"xx,yyyy.zz ","支付宝(中国)网络技术有限公司 ","1234****9876 ", +2023-02-20 ,"跨行汇款 "," ","手机银行 ","CHN ",钞 ,"- ","- ",- ," ","1,234.56 ",人民币 ,"xx,yyyy.zz ","张三 ","1234****9876 ", +2023-02-10 ,"合伙人返现 "," "," ","CHN ",钞 ,"- ","- ",- ,"30.00 "," ",人民币 ,"xx,yyyy.zz ","总行信用卡合伙人 ","1234****9876 ", +2023-02-09 ,"消费 "," ","财付通-群收款 ","CHN ",钞 ,"- ","- ",- ," ","24.00 ",人民币 ,"xx,yyyy.zz ","深圳市财付通支付科技有限公司 ","1234****9876 ", +2023-02-08 ,"退款 "," ","财付通-微信红包 ","CHN ",钞 ,"- ","- ",- ,"1.04 "," ",人民币 ,"xx,yyyy.zz ","深圳市财付通支付科技有限公司 ","1234****9876 ", + +人民币合计,,,,,,,,,"1,234.56 ","9,876.54 ", diff --git a/pkg/provider/icbc/convert.go b/pkg/provider/icbc/convert.go index 243c989..b9d6fb0 100644 --- a/pkg/provider/icbc/convert.go +++ b/pkg/provider/icbc/convert.go @@ -12,6 +12,7 @@ func (icbc *Icbc) convertToIR() *ir.IR { for _, o := range icbc.Orders { irO := ir.Order{ Peer: o.Peer, + Item: o.Item, Money: o.Money, PayTime: o.PayTime, Type: convertType(o.Type), @@ -36,11 +37,12 @@ func convertType(t OrderType) ir.Type { } // getMetadata get the metadata (e.g. status, method, category and so on.) -// from order. +// +// from order. func (icbc *Icbc) getMetadata(o Order) map[string]string { // FIXME(TripleZ): hard-coded, bad pattern source := "中国工商银行" - var txTypeOriginal, guessedType, currency, balances, peerAccount string + var txTypeOriginal, guessedType, currency, balances, peerAccount, peerAccountNum string if o.TxTypeOriginal != "" { txTypeOriginal = o.TxTypeOriginal @@ -62,13 +64,18 @@ func (icbc *Icbc) getMetadata(o Order) map[string]string { peerAccount = o.PeerAccountName } + if o.PeerAccountNum != "" { + peerAccountNum = o.PeerAccountNum + } + metadata := map[string]string{ - "source": source, - "txType": txTypeOriginal, - "type": guessedType, - "currency": currency, - "balances": balances, - "peerAccount": peerAccount, + "source": source, + "txType": txTypeOriginal, + "type": guessedType, + "currency": currency, + "balances": balances, + "peerAccount": peerAccount, + "peerAccountNum": peerAccountNum, } if icbc.CardName != "" { diff --git a/pkg/provider/icbc/icbc.go b/pkg/provider/icbc/icbc.go index f13bf37..4d4602e 100644 --- a/pkg/provider/icbc/icbc.go +++ b/pkg/provider/icbc/icbc.go @@ -69,8 +69,8 @@ func (icbc *Icbc) Translate(filename string) (*ir.IR, error) { } log.Printf("Now the ICBC provider is in `%s` mode", icbc.Mode) continue - } else if icbc.LineNum <= 5 { - // The first 5 non-empty lines are useless for us. + } else if icbc.LineNum <= 4 { + // The first 4 non-empty lines are useless for us. continue } @@ -81,7 +81,7 @@ func (icbc *Icbc) Translate(filename string) (*ir.IR, error) { err = icbc.translateToOrders(line) if err != nil { - return nil, fmt.Errorf("Failed to translate bill: line %d: %v", + return nil, fmt.Errorf("failed to translate bill: line %d: %v", icbc.LineNum, err) } } diff --git a/pkg/provider/icbc/parse.go b/pkg/provider/icbc/parse.go index d956cfd..4e38efc 100644 --- a/pkg/provider/icbc/parse.go +++ b/pkg/provider/icbc/parse.go @@ -53,33 +53,68 @@ func (icbc *Icbc) translateToOrders(array []string) error { bill.Balances, _ = strconv.ParseFloat(strings.ReplaceAll(array[11], ",", ""), 64) bill.PeerAccountName = array[12] case DebitMode: + var debitBillVersion int32 + if len(array) == 14 { + debitBillVersion = 1 + } else if len(array) == 16 { + debitBillVersion = 2 + } else { + return fmt.Errorf("cannot recognize this debit bill format, len()=%v", len(array)) + } + bill.PayTime, err = time.Parse(localTimeFmt, array[0]+" +0800 CST") if err != nil { return fmt.Errorf("parse create time %s error: %v", array[0], err) } - bill.TxTypeOriginal = array[1] - bill.Peer = array[2] - bill.Region = array[3] - a8 := strings.ReplaceAll(array[8], ",", "") - a9 := strings.ReplaceAll(array[9], ",", "") - if a8 == "" && a9 == "" { - bill.Type = OrderTypeUnknown - } else if a9 == "" { - bill.Type = OrderTypeRecv - bill.Money, err = strconv.ParseFloat(a8, 64) - } else { - bill.Type = OrderTypeSend - bill.Money, err = strconv.ParseFloat(a9, 64) - } - if err != nil { - return fmt.Errorf("parse money [%s,%s] error: %v", array[8], array[9], err) + switch debitBillVersion { + case 1: + bill.Peer = array[2] + bill.Region = array[3] + + a8 := strings.ReplaceAll(array[8], ",", "") + a9 := strings.ReplaceAll(array[9], ",", "") + if a8 == "" && a9 == "" { + bill.Type = OrderTypeUnknown + } else if a9 == "" { + bill.Type = OrderTypeRecv + bill.Money, err = strconv.ParseFloat(a8, 64) + } else { + bill.Type = OrderTypeSend + bill.Money, err = strconv.ParseFloat(a9, 64) + } + if err != nil { + return fmt.Errorf("parse money [%s,%s] error: %v", array[8], array[9], err) + } + bill.Currency = array[10] + bill.Balances, _ = strconv.ParseFloat(strings.ReplaceAll(array[11], ",", ""), 64) + bill.PeerAccountName = array[12] + case 2: + bill.Item = array[2] + bill.Peer = array[3] + bill.Region = array[4] + + _income := strings.ReplaceAll(array[9], ",", "") + _expense := strings.ReplaceAll(array[10], ",", "") + if _income == "" && _expense == "" { + bill.Type = OrderTypeUnknown + } else if _expense == "" { + bill.Type = OrderTypeRecv + bill.Money, err = strconv.ParseFloat(_income, 64) + } else { + bill.Type = OrderTypeSend + bill.Money, err = strconv.ParseFloat(_expense, 64) + } + if err != nil { + return fmt.Errorf("parse money [%s,%s] error: %v", array[8], array[9], err) + } + bill.Currency = array[11] + bill.Balances, _ = strconv.ParseFloat(strings.ReplaceAll(array[12], ",", ""), 64) + bill.PeerAccountName = array[13] + bill.PeerAccountNum = array[14] } - bill.Currency = array[10] - bill.Balances, _ = strconv.ParseFloat(strings.ReplaceAll(array[11], ",", ""), 64) - bill.PeerAccountName = array[12] } if bill.Peer == "" { diff --git a/pkg/provider/icbc/types.go b/pkg/provider/icbc/types.go index c3e82e7..537642d 100644 --- a/pkg/provider/icbc/types.go +++ b/pkg/provider/icbc/types.go @@ -20,12 +20,14 @@ type Order struct { PayTime time.Time // 记账日期 TxTypeOriginal string // 摘要 Peer string // 交易场所 + Item string // 交易详情 Region string // 交易国家或地区简称 Money float64 // 记账金额 (收入/支出) Type OrderType // 收/支 (数据中无该列,推测而来) Currency string // 记账币种 Balances float64 // 余额 PeerAccountName string // 对方户名 + PeerAccountNum string // 对方账户 } // localTimeFmt set time format to utc+8 diff --git a/pkg/provider/wechat/convert.go b/pkg/provider/wechat/convert.go index 3b2e85c..2794251 100644 --- a/pkg/provider/wechat/convert.go +++ b/pkg/provider/wechat/convert.go @@ -41,7 +41,8 @@ func convertType(t OrderType) ir.Type { } // getMetadata get the metadata (e.g. status, method, category and so on.) -// from order. +// +// from order. func getMetadata(o Order) map[string]string { // FIXME(TripleZ): hard-coded, bad pattern source := "微信支付" diff --git a/test/icbc-test-beancount.sh b/test/icbc-test-beancount.sh index 6b0130d..c30c146 100644 --- a/test/icbc-test-beancount.sh +++ b/test/icbc-test-beancount.sh @@ -27,19 +27,35 @@ if [ $? -ne 0 ]; then exit 1 fi -# generate icbc debit bills output in beancount format +# generate icbc debit bills (v1) output in beancount format "$ROOT_DIR/bin/double-entry-generator" translate \ --provider icbc \ - --config "$ROOT_DIR/example/icbc/debit/config.yaml" \ - --output "$ROOT_DIR/test/output/test-icbc-debit-output.beancount" \ - "$ROOT_DIR/example/icbc/debit/example-icbc-debit-records.csv" + --config "$ROOT_DIR/example/icbc/debit-v1/config.yaml" \ + --output "$ROOT_DIR/test/output/test-icbc-debit-v1-output.beancount" \ + "$ROOT_DIR/example/icbc/debit-v1/example-icbc-debit-v1-records.csv" diff -u --color \ - "$ROOT_DIR/example/icbc/debit/example-icbc-debit-output.beancount" \ - "$ROOT_DIR/test/output/test-icbc-debit-output.beancount" + "$ROOT_DIR/example/icbc/debit-v1/example-icbc-debit-v1-output.beancount" \ + "$ROOT_DIR/test/output/test-icbc-debit-v1-output.beancount" if [ $? -ne 0 ]; then - echo "[FAIL] ICBC provider (debit mode) output is different from expected output." + echo "[FAIL] ICBC provider (debit mode v1) output is different from expected output." + exit 1 +fi + +# generate icbc debit bills (v2) output in beancount format +"$ROOT_DIR/bin/double-entry-generator" translate \ + --provider icbc \ + --config "$ROOT_DIR/example/icbc/debit-v2/config.yaml" \ + --output "$ROOT_DIR/test/output/test-icbc-debit-v2-output.beancount" \ + "$ROOT_DIR/example/icbc/debit-v2/example-icbc-debit-v2-records.csv" + +diff -u --color \ + "$ROOT_DIR/example/icbc/debit-v2/example-icbc-debit-v2-output.beancount" \ + "$ROOT_DIR/test/output/test-icbc-debit-v2-output.beancount" + +if [ $? -ne 0 ]; then + echo "[FAIL] ICBC provider (debit mode v2) output is different from expected output." exit 1 fi diff --git a/test/icbc-test-ledger.sh b/test/icbc-test-ledger.sh index 93b5e67..4084eed 100644 --- a/test/icbc-test-ledger.sh +++ b/test/icbc-test-ledger.sh @@ -30,20 +30,37 @@ if [ $? -ne 0 ]; then exit 1 fi -# generate icbc debit bills output in beancount format +# generate icbc debit bills (v1) output in beancount format "$ROOT_DIR/bin/double-entry-generator" translate \ --provider icbc \ --target ledger \ - --config "$ROOT_DIR/example/icbc/debit/config.yaml" \ + --config "$ROOT_DIR/example/icbc/debit-v1/config.yaml" \ --output "$DEBIT_OUTPUT" \ - "$ROOT_DIR/example/icbc/debit/example-icbc-debit-records.csv" + "$ROOT_DIR/example/icbc/debit-v1/example-icbc-debit-v1-records.csv" diff -u --color \ - "$ROOT_DIR/example/icbc/debit/example-icbc-debit-output.ledger" \ + "$ROOT_DIR/example/icbc/debit-v1/example-icbc-debit-v1-output.ledger" \ "$DEBIT_OUTPUT" if [ $? -ne 0 ]; then - echo "[FAIL] ICBC provider (debit mode) output is different from expected output." + echo "[FAIL] ICBC provider (debit mode v1) output is different from expected output." + exit 1 +fi + +# generate icbc debit bills (v1) output in beancount format +"$ROOT_DIR/bin/double-entry-generator" translate \ + --provider icbc \ + --target ledger \ + --config "$ROOT_DIR/example/icbc/debit-v2/config.yaml" \ + --output "$DEBIT_OUTPUT" \ + "$ROOT_DIR/example/icbc/debit-v2/example-icbc-debit-v2-records.csv" + +diff -u --color \ + "$ROOT_DIR/example/icbc/debit-v2/example-icbc-debit-v2-output.ledger" \ + "$DEBIT_OUTPUT" + +if [ $? -ne 0 ]; then + echo "[FAIL] ICBC provider (debit mode v2) output is different from expected output." exit 1 fi