diff --git a/pkg/converters/transaction_data_converters.go b/pkg/converters/transaction_data_converters.go index a9279de3..c3e064e0 100644 --- a/pkg/converters/transaction_data_converters.go +++ b/pkg/converters/transaction_data_converters.go @@ -69,6 +69,8 @@ func GetTransactionDataImporter(fileType string) (converter.TransactionDataImpor return alipay.AlipayAppTransactionDataCsvFileImporter, nil } else if fileType == "alipay_web_csv" { return alipay.AlipayWebTransactionDataCsvFileImporter, nil + } else if fileType == "wechat_pay_app_xlsx" { + return wechat.WeChatPayTransactionDataXlsxFileImporter, nil } else if fileType == "wechat_pay_app_csv" { return wechat.WeChatPayTransactionDataCsvFileImporter, nil } else { diff --git a/pkg/converters/wechat/wechat_pay_transaction_data_csv_file_importer.go b/pkg/converters/wechat/wechat_pay_transaction_data_csv_file_importer.go index 77eb2f79..a9fa537d 100644 --- a/pkg/converters/wechat/wechat_pay_transaction_data_csv_file_importer.go +++ b/pkg/converters/wechat/wechat_pay_transaction_data_csv_file_importer.go @@ -15,22 +15,6 @@ import ( "github.com/mayswind/ezbookkeeping/pkg/models" ) -var wechatPayTransactionSupportedColumns = map[datatable.TransactionDataTableColumn]bool{ - datatable.TRANSACTION_DATA_TABLE_TRANSACTION_TIME: true, - datatable.TRANSACTION_DATA_TABLE_TRANSACTION_TYPE: true, - datatable.TRANSACTION_DATA_TABLE_SUB_CATEGORY: true, - datatable.TRANSACTION_DATA_TABLE_ACCOUNT_NAME: true, - datatable.TRANSACTION_DATA_TABLE_AMOUNT: true, - datatable.TRANSACTION_DATA_TABLE_RELATED_ACCOUNT_NAME: true, - datatable.TRANSACTION_DATA_TABLE_DESCRIPTION: true, -} - -var wechatPayTransactionTypeNameMapping = map[models.TransactionType]string{ - models.TRANSACTION_TYPE_INCOME: "收入", - models.TRANSACTION_TYPE_EXPENSE: "支出", - models.TRANSACTION_TYPE_TRANSFER: "/", -} - // wechatPayTransactionDataCsvFileImporter defines the structure of wechatPay csv importer for transaction data type wechatPayTransactionDataCsvFileImporter struct { fileHeaderLineBeginning string diff --git a/pkg/converters/wechat/wechat_pay_transaction_data_row_parser.go b/pkg/converters/wechat/wechat_pay_transaction_data_row_parser.go index 75b8934e..5d85ee1d 100644 --- a/pkg/converters/wechat/wechat_pay_transaction_data_row_parser.go +++ b/pkg/converters/wechat/wechat_pay_transaction_data_row_parser.go @@ -29,6 +29,22 @@ const wechatPayTransactionDataCategoryTransferFromWeChatWallet = "零钱提现" const wechatPayTransactionDataStatusRefundName = "退款" +var wechatPayTransactionSupportedColumns = map[datatable.TransactionDataTableColumn]bool{ + datatable.TRANSACTION_DATA_TABLE_TRANSACTION_TIME: true, + datatable.TRANSACTION_DATA_TABLE_TRANSACTION_TYPE: true, + datatable.TRANSACTION_DATA_TABLE_SUB_CATEGORY: true, + datatable.TRANSACTION_DATA_TABLE_ACCOUNT_NAME: true, + datatable.TRANSACTION_DATA_TABLE_AMOUNT: true, + datatable.TRANSACTION_DATA_TABLE_RELATED_ACCOUNT_NAME: true, + datatable.TRANSACTION_DATA_TABLE_DESCRIPTION: true, +} + +var wechatPayTransactionTypeNameMapping = map[models.TransactionType]string{ + models.TRANSACTION_TYPE_INCOME: "收入", + models.TRANSACTION_TYPE_EXPENSE: "支出", + models.TRANSACTION_TYPE_TRANSFER: "/", +} + // weChatPayTransactionDataRowParser defines the structure of wechat pay transaction data row parser type weChatPayTransactionDataRowParser struct { existedOriginalDataColumns map[string]bool diff --git a/pkg/converters/wechat/wechat_pay_transaction_data_xlsx_file_importer.go b/pkg/converters/wechat/wechat_pay_transaction_data_xlsx_file_importer.go new file mode 100644 index 00000000..dc7c2448 --- /dev/null +++ b/pkg/converters/wechat/wechat_pay_transaction_data_xlsx_file_importer.go @@ -0,0 +1,53 @@ +package wechat + +import ( + "github.com/mayswind/ezbookkeeping/pkg/converters/converter" + "github.com/mayswind/ezbookkeeping/pkg/converters/datatable" + "github.com/mayswind/ezbookkeeping/pkg/converters/excel" + "github.com/mayswind/ezbookkeeping/pkg/core" + "github.com/mayswind/ezbookkeeping/pkg/errs" + "github.com/mayswind/ezbookkeeping/pkg/log" + "github.com/mayswind/ezbookkeeping/pkg/models" +) + +// wechatPayTransactionDataXlsxFileImporter defines the structure of wechatPay xlsx importer for transaction data +type wechatPayTransactionDataXlsxFileImporter struct { + dataHeaderStartContentBeginning string +} + +// Initialize a webchat pay transaction data xlsx file importer singleton instance +var ( + WeChatPayTransactionDataXlsxFileImporter = &wechatPayTransactionDataXlsxFileImporter{} +) + +// ParseImportedData returns the imported data by parsing the wechat pay transaction csv data +func (c *wechatPayTransactionDataXlsxFileImporter) ParseImportedData(ctx core.Context, user *models.User, data []byte, defaultTimezoneOffset int16, accountMap map[string]*models.Account, expenseCategoryMap map[string]map[string]*models.TransactionCategory, incomeCategoryMap map[string]map[string]*models.TransactionCategory, transferCategoryMap map[string]map[string]*models.TransactionCategory, tagMap map[string]*models.TransactionTag) (models.ImportedTransactionSlice, []*models.Account, []*models.TransactionCategory, []*models.TransactionCategory, []*models.TransactionCategory, []*models.TransactionTag, error) { + xlsxDataTable, err := excel.CreateNewExcelOOXMLFileBasicDataTable(data, false) + + if err != nil { + return nil, nil, nil, nil, nil, nil, err + } + + dataTable, err := createNewWeChatPayTransactionBasicDataTable(ctx, xlsxDataTable) + + if err != nil { + return nil, nil, nil, nil, nil, nil, err + } + + commonDataTable := datatable.CreateNewCommonDataTableFromBasicDataTable(dataTable) + + if !commonDataTable.HasColumn(wechatPayTransactionTimeColumnName) || + !commonDataTable.HasColumn(wechatPayTransactionCategoryColumnName) || + !commonDataTable.HasColumn(wechatPayTransactionTypeColumnName) || + !commonDataTable.HasColumn(wechatPayTransactionAmountColumnName) || + !commonDataTable.HasColumn(wechatPayTransactionStatusColumnName) { + log.Errorf(ctx, "[wechat_pay_transaction_data_xlsx_file_importer.ParseImportedData] cannot parse wechat pay xlsx data, because missing essential columns in header row") + return nil, nil, nil, nil, nil, nil, errs.ErrMissingRequiredFieldInHeaderRow + } + + transactionRowParser := createWeChatPayTransactionDataRowParser(dataTable.HeaderColumnNames()) + transactionDataTable := datatable.CreateNewTransactionDataTableFromCommonDataTable(commonDataTable, wechatPayTransactionSupportedColumns, transactionRowParser) + dataTableImporter := converter.CreateNewSimpleImporterWithTypeNameMapping(wechatPayTransactionTypeNameMapping) + + return dataTableImporter.ParseImportedData(ctx, user, transactionDataTable, defaultTimezoneOffset, accountMap, expenseCategoryMap, incomeCategoryMap, transferCategoryMap, tagMap) +} diff --git a/src/consts/file.ts b/src/consts/file.ts index 8f5c847c..24128503 100644 --- a/src/consts/file.ts +++ b/src/consts/file.ts @@ -241,9 +241,21 @@ export const SUPPORTED_IMPORT_FILE_TYPES: ImportFileType[] = [ } }, { - type: 'wechat_pay_app_csv', + type: 'wechat_pay_app', name: 'WeChat Pay Billing File', - extensions: '.csv', + extensions: '.xlsx,.csv', + subTypes: [ + { + type: 'wechat_pay_app_xlsx', + name: 'Excel Workbook File', + extensions: '.xlsx', + }, + { + type: 'wechat_pay_app_csv', + name: 'CSV (Comma-separated values) File', + extensions: '.csv', + } + ], document: { supportMultiLanguages: 'zh-Hans', anchor: '如何获取微信支付账单文件' diff --git a/src/locales/de.json b/src/locales/de.json index d6fb8b80..56f62535 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "Wie exportiere ich diese Datei?", "ezbookkeeping Data Export File": "ezBookkeeping-Datenexportdatei", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Open Financial Exchange (OFX)-Datei", "Quicken Financial Exchange (QFX) File": "Quicken Financial Exchange (QFX)-Datei", "Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF)-Datei", diff --git a/src/locales/en.json b/src/locales/en.json index 3d388ccd..46fce381 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "How to export this file?", "ezbookkeeping Data Export File": "ezbookkeeping Data Export File", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Open Financial Exchange (OFX) File", "Quicken Financial Exchange (QFX) File": "Quicken Financial Exchange (QFX) File", "Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) File", diff --git a/src/locales/es.json b/src/locales/es.json index 526f6d43..533c8576 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "¿Cómo exportar este archivo?", "ezbookkeeping Data Export File": "Archivo de exportación de datos de ezBookkeeping", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Abrir archivo de intercambio financiero (OFX)", "Quicken Financial Exchange (QFX) File": "Archivo Quicken Financial Exchange (QFX)", "Quicken Interchange Format (QIF) File": "Archivo de formato de intercambio Quicken (QIF)", diff --git a/src/locales/it.json b/src/locales/it.json index 9d1a1944..0dbb688b 100644 --- a/src/locales/it.json +++ b/src/locales/it.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "Come esportare questo file?", "ezbookkeeping Data Export File": "File esportazione dati ezBookkeeping", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "File Open Financial Exchange (OFX)", "Quicken Financial Exchange (QFX) File": "File Quicken Financial Exchange (QFX)", "Quicken Interchange Format (QIF) File": "File Quicken Interchange Format (QIF)", diff --git a/src/locales/ja.json b/src/locales/ja.json index ac41a0eb..e9009d71 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "このファイルをエクスポートする方法", "ezbookkeeping Data Export File": "ezbookkeepingデータエクスポートファイル", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Open Financial Exchange (OFX) ファイル", "Quicken Financial Exchange (QFX) File": "Quicken Financial Exchange (QFX) ファイル", "Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) ファイル", diff --git a/src/locales/pt_BR.json b/src/locales/pt_BR.json index 023aa724..cff4ff52 100644 --- a/src/locales/pt_BR.json +++ b/src/locales/pt_BR.json @@ -1722,6 +1722,7 @@ "How to import this file?": "Como importar este arquivo?", "How to export this file?": "Como exportar este arquivo?", "ezbookkeeping Data Export File": "Arquivo de Exportação de Dados ezbookkeeping", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Arquivo Open Financial Exchange (OFX)", "Quicken Financial Exchange (QFX) File": "Arquivo Quicken Financial Exchange (QFX)", "Quicken Interchange Format (QIF) File": "Arquivo Quicken Interchange Format (QIF)", diff --git a/src/locales/ru.json b/src/locales/ru.json index 379c3705..399db6fc 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "Как экспортировать этот файл?", "ezbookkeeping Data Export File": "Файл экспорта данных ezbookkeeping", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Файл Open Financial Exchange (OFX)", "Quicken Financial Exchange (QFX) File": "Файл Quicken Financial Exchange (QFX)", "Quicken Interchange Format (QIF) File": "Файл Quicken Interchange Format (QIF)", diff --git a/src/locales/uk.json b/src/locales/uk.json index 35af98c0..a5a7400f 100644 --- a/src/locales/uk.json +++ b/src/locales/uk.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "Як експортувати цей файл?", "ezbookkeeping Data Export File": "Файл експорту даних ezbookkeeping", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Файл Open Financial Exchange (OFX)", "Quicken Financial Exchange (QFX) File": "Файл Quicken Financial Exchange (QFX)", "Quicken Interchange Format (QIF) File": "Файл Quicken Interchange Format (QIF)", diff --git a/src/locales/vi.json b/src/locales/vi.json index c2fdec72..c8292279 100644 --- a/src/locales/vi.json +++ b/src/locales/vi.json @@ -1722,6 +1722,7 @@ "How to import this file?": "How to import this file?", "How to export this file?": "Làm thế nào để xuất tệp này?", "ezbookkeeping Data Export File": "Tệp xuất dữ liệu ezbookkeeping", + "Excel Workbook File": "Excel Workbook File", "Open Financial Exchange (OFX) File": "Tệp Open Financial Exchange (OFX)", "Quicken Financial Exchange (QFX) File": "Tệp Quicken Financial Exchange (QFX)", "Quicken Interchange Format (QIF) File": "Tệp Quicken Interchange Format (QIF)", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 83023d14..48180c0e 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1722,6 +1722,7 @@ "How to import this file?": "如何导入该文件?", "How to export this file?": "如何导出该文件?", "ezbookkeeping Data Export File": "ezbookkeeping 数据导出文件", + "Excel Workbook File": "Excel 工作簿文件", "Open Financial Exchange (OFX) File": "开放式金融交换 (OFX) 文件", "Quicken Financial Exchange (QFX) File": "Quicken Financial Exchange (QFX) 文件", "Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) 文件", diff --git a/src/locales/zh_Hant.json b/src/locales/zh_Hant.json index a47dfc01..4d3d6e9b 100644 --- a/src/locales/zh_Hant.json +++ b/src/locales/zh_Hant.json @@ -1722,6 +1722,7 @@ "How to import this file?": "如何匯入此檔案?", "How to export this file?": "如何匯出此檔案?", "ezbookkeeping Data Export File": "ezbookkeeping 資料匯出檔案", + "Excel Workbook File": "Excel 工作簿檔案", "Open Financial Exchange (OFX) File": "開放式金融交換 (OFX) 檔案", "Quicken Financial Exchange (QFX) File": "Quicken Financial Exchange (QFX) 檔案", "Quicken Interchange Format (QIF) File": "Quicken Interchange Format (QIF) 檔案",