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

支付宝账单中交易状态关闭的订单,标记为未入账 #51

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion pkg/compiler/beancount/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (b *BeanCount) writeBill(file *os.File, index int) error {
case ir.OrderTypeNormal:
err = normalOrderTemplate.Execute(&buf, &NormalOrderVars{
PayTime: o.PayTime,
Pending: o.Pending,
Peer: o.Peer,
Item: o.Item,
Note: o.Note,
Expand All @@ -171,8 +172,8 @@ func (b *BeanCount) writeBill(file *os.File, index int) error {
MinusAccount: o.MinusAccount,
PnlAccount: o.ExtraAccounts[ir.PnlAccount],
CommissionAccount: o.ExtraAccounts[ir.CommissionAccount],
Metadata: o.Metadata,
Currency: b.Config.DefaultCurrency,
Metadata: o.Metadata,
})
case ir.OrderTypeHuobiTrade: // Huobi trades
switch o.TxType {
Expand Down
6 changes: 4 additions & 2 deletions pkg/compiler/beancount/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// 普通账单的模版(消费账)
var normalOrder = `{{ .PayTime.Format "2006-01-02" }} * "{{ .Peer }}" "{{ .Item }}"{{ if .Note }} ; {{ .Note }}{{ end }}
var normalOrder = `{{ .PayTime.Format "2006-01-02" }} {{ if .Pending }}!{{ else }}*{{ end }} "{{ .Peer }}" "{{ .Item }}"{{ if .Note }} ; {{ .Note }}{{ end }}
{{ .PlusAccount }} {{ .Money | printf "%.2f" }} {{ .Currency }}
{{ .MinusAccount }} -{{ .Money | printf "%.2f" }} {{ .Currency }}
{{- if .CommissionAccount }}{{ printf "\n" }} {{ .CommissionAccount }} {{ .Commission | printf "%.2f" }} {{ .Currency }}{{ end }}
Expand All @@ -17,7 +17,9 @@ var normalOrder = `{{ .PayTime.Format "2006-01-02" }} * "{{ .Peer }}" "{{ .Item
`

type NormalOrderVars struct {
PayTime time.Time
PayTime time.Time
// 未入账标记
Pending bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释可以写在代码行后面。

Pending bool  // comment

Peer string
Item string
Note string
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ type Config struct {
Title string `yaml:"title,omitempty"`
DefaultMinusAccount string `yaml:"defaultMinusAccount,omitempty"`
DefaultPlusAccount string `yaml:"defaultPlusAccount,omitempty"`
DefaultCashAccount string `yaml:"defaultCashAccount,omitempty`
DefaultPositionAccount string `yaml:"defaultPositionAccount,omitempty`
DefaultCommissionAccount string `yaml:"defaultCommissionAccount,omitempty`
DefaultPnlAccount string `yaml:"defaultPnlAccount,omitempty`
DefaultCashAccount string `yaml:"defaultCashAccount,omitempty"`
DefaultPositionAccount string `yaml:"defaultPositionAccount,omitempty"`
DefaultCommissionAccount string `yaml:"defaultCommissionAccount,omitempty"`
DefaultPnlAccount string `yaml:"defaultPnlAccount,omitempty"`
DefaultCurrency string `yaml:"defaultCurrency,omitempty"`
Alipay *alipay.Config `yaml:"alipay,omitempty"`
Wechat *wechat.Config `yaml:"wechat,omitempty"`
Huobi *huobi.Config `yaml:"huobi,omitempty`
Huobi *huobi.Config `yaml:"huobi,omitempty"`
}
10 changes: 6 additions & 4 deletions pkg/ir/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ type IR struct {

// Order is the intermediate representation for the order.
type Order struct {
OrderType OrderType
Peer string
Item string
Category string
OrderType OrderType
Peer string
Item string
Category string
// 是否未入账
Pending bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释可以写在代码行后面。

MerchantOrderID *string
OrderID *string
Money float64
Expand Down
7 changes: 4 additions & 3 deletions pkg/provider/alipay/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ func (a *Alipay) convertToIR() *ir.IR {
Peer: o.Peer,
Item: o.ItemName,
Category: o.Category,
Method: o.Method,
PayTime: o.PayTime,
Money: o.Money,
Pending: o.Status == "交易关闭",
OrderID: &o.DealNo,
Money: o.Money,
PayTime: o.PayTime,
TxType: conevertType(o.TxType),
TxTypeOriginal: o.TxTypeOriginal,
Method: o.Method,
}
irO.Metadata = getMetadata(o)
if o.MerchantId != "" {
Expand Down