-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
import transaction from wechat pay billing file
- Loading branch information
Showing
11 changed files
with
481 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
pkg/converters/wechat/wechat_pay_transaction_data_csv_file_importer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package wechat | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/mayswind/ezbookkeeping/pkg/converters/datatable" | ||
"github.com/mayswind/ezbookkeeping/pkg/core" | ||
"github.com/mayswind/ezbookkeeping/pkg/models" | ||
) | ||
|
||
var wechatPayTransactionTypeNameMapping = map[models.TransactionType]string{ | ||
models.TRANSACTION_TYPE_INCOME: "收入", | ||
models.TRANSACTION_TYPE_EXPENSE: "支出", | ||
models.TRANSACTION_TYPE_TRANSFER: "/", | ||
} | ||
|
||
// wechatPayTransactionDataCsvImporter defines the structure of wechatPay csv importer for transaction data | ||
type wechatPayTransactionDataCsvImporter struct { | ||
fileHeaderLineBeginning string | ||
dataHeaderStartContentBeginning string | ||
} | ||
|
||
// Initialize a webchat pay transaction data csv file importer singleton instance | ||
var ( | ||
WeChatPayTransactionDataCsvImporter = &wechatPayTransactionDataCsvImporter{} | ||
) | ||
|
||
// ParseImportedData returns the imported data by parsing the wechat pay transaction csv data | ||
func (c *wechatPayTransactionDataCsvImporter) ParseImportedData(ctx core.Context, user *models.User, data []byte, defaultTimezoneOffset int16, accountMap map[string]*models.Account, expenseCategoryMap map[string]*models.TransactionCategory, incomeCategoryMap map[string]*models.TransactionCategory, transferCategoryMap map[string]*models.TransactionCategory, tagMap map[string]*models.TransactionTag) (models.ImportedTransactionSlice, []*models.Account, []*models.TransactionCategory, []*models.TransactionCategory, []*models.TransactionCategory, []*models.TransactionTag, error) { | ||
reader := bytes.NewReader(data) | ||
transactionDataTable, err := createNewWeChatPayTransactionDataTable(ctx, reader) | ||
|
||
if err != nil { | ||
return nil, nil, nil, nil, nil, nil, err | ||
} | ||
|
||
dataTableImporter := datatable.CreateNewSimpleImporter(wechatPayTransactionTypeNameMapping) | ||
|
||
return dataTableImporter.ParseImportedData(ctx, user, transactionDataTable, defaultTimezoneOffset, accountMap, expenseCategoryMap, incomeCategoryMap, transferCategoryMap, tagMap) | ||
} |
Oops, something went wrong.