Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provider, analyser): support jd new bill format, Set plusaccount to methodaccount for refund records in jd bills #136

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- 中国工商银行
- Toronto-Dominion Bank
- Bank of Montreal
- 京东

目前记账语言支持:

Expand Down Expand Up @@ -908,13 +909,16 @@ jd:

2. 特殊情况:`交易说明`(即`item`匹配的字段)的前缀为`冻结-`或`解冻-`时为`不计收支`的特殊情况。`冻结-`情形下, `收/付款方式`为支出账户; `解冻-`情形下 `收/付款方式`为收入账户但是金额为 0。目前所有和`冻结` , `解冻` 相关的交易会被忽略。

3. 对于京东账单中的退款记录,`plusAccount` 为 `methodAccount`,`minusAccount` 为 `targetAccount`,即退款的资金原路返回。

`targetAccount` 与 `methodAccount` 的增减账户关系如下表:

| 收/支 | minusAccount | plusAccount |
| -------- | ------------- | ------------- |
| 收入 | targetAccount | methodAccount |
| 支出 | methodAccount | targetAccount |
| 不计收支 | methodAccount | targetAccount |
| 不计收支(退款)| targetAccount | methodAccount |

## Special Thanks

Expand Down
3 changes: 3 additions & 0 deletions pkg/analyser/jd/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,8 @@ func (a JD) GetAccountsAndTags(o *ir.Order, cfg *config.Config, target, provider
strings.HasPrefix(o.Item, "解冻-")) {
ignore = true
}
if o.TypeOriginal == "不计收支" && (strings.HasPrefix(o.Item, "退款-")) {
return ignore, resPlus, resMinus, extraAccounts, tags
}
return ignore, resMinus, resPlus, extraAccounts, tags
}
21 changes: 14 additions & 7 deletions pkg/provider/jd/jd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"log"
"regexp"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -129,17 +130,17 @@ func (c *JD) translateLine(row []string) error {
if err != nil {
return err
}
bill.Category = row[1]
bill.PeerType = row[2]
bill.ItemName = row[3]
bill.Category = row[7]
bill.PeerType = row[1]
bill.ItemName = row[2]

bill.Type = c.translateType(row[4])
bill.Money, err = c.translateValue(row[5])
bill.Type = c.translateType(row[6])
bill.Money, err = c.translateValue(row[3])
if err != nil {
return err
}
bill.Method = row[6]
bill.Status = row[7]
bill.Method = row[4]
bill.Status = row[5]
bill.DealNo = row[8]
bill.MerchantId = row[9]
bill.Notes = row[10]
Expand Down Expand Up @@ -187,6 +188,12 @@ func (c *JD) convertToIRType(s Type) ir.Type {
}

func (c *JD) translateValue(s string) (int64, error) {

re := regexp.MustCompile(`\(已退款[0-9]+(\.[0-9]+)?\)|\(已全额退款\)$`)

// 检查金额是否以 '(已全额退款)' 或者 '(已退款xx.xx)' 结尾
// 如果是,去掉后缀
s = re.ReplaceAllString(s, "")
s = strings.ReplaceAll(s, ".", "")
return strconv.ParseInt(s, 10, 64)
}
Expand Down
Loading