mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 01:04:25 +08:00
use the sub-category according to the primary category name if there are duplicated sub-category names when importing transactions (#119)
This commit is contained in:
@@ -448,22 +448,59 @@ func (s *TransactionCategoryService) GetCategoryMapByList(categories []*models.T
|
||||
return categoryMap
|
||||
}
|
||||
|
||||
// GetCategoryNameMapByList returns a transaction category map by a list
|
||||
func (s *TransactionCategoryService) GetCategoryNameMapByList(categories []*models.TransactionCategory) (expenseCategoryMap map[string]*models.TransactionCategory, incomeCategoryMap map[string]*models.TransactionCategory, transferCategoryMap map[string]*models.TransactionCategory) {
|
||||
expenseCategoryMap = make(map[string]*models.TransactionCategory)
|
||||
incomeCategoryMap = make(map[string]*models.TransactionCategory)
|
||||
transferCategoryMap = make(map[string]*models.TransactionCategory)
|
||||
// GetSubCategoryNameMapByList returns a sub transaction category map by a list
|
||||
func (s *TransactionCategoryService) GetSubCategoryNameMapByList(categories []*models.TransactionCategory) (expenseCategoryMap map[string]map[string]*models.TransactionCategory, incomeCategoryMap map[string]map[string]*models.TransactionCategory, transferCategoryMap map[string]map[string]*models.TransactionCategory) {
|
||||
categoryMap := make(map[int64]*models.TransactionCategory, len(categories))
|
||||
expenseCategoryMap = make(map[string]map[string]*models.TransactionCategory)
|
||||
incomeCategoryMap = make(map[string]map[string]*models.TransactionCategory)
|
||||
transferCategoryMap = make(map[string]map[string]*models.TransactionCategory)
|
||||
|
||||
for i := 0; i < len(categories); i++ {
|
||||
category := categories[i]
|
||||
categoryMap[category.CategoryId] = category
|
||||
}
|
||||
|
||||
for i := 0; i < len(categories); i++ {
|
||||
category := categories[i]
|
||||
|
||||
if category.Type == models.CATEGORY_TYPE_INCOME {
|
||||
incomeCategoryMap[category.Name] = category
|
||||
} else if category.Type == models.CATEGORY_TYPE_EXPENSE {
|
||||
expenseCategoryMap[category.Name] = category
|
||||
} else if category.Type == models.CATEGORY_TYPE_TRANSFER {
|
||||
transferCategoryMap[category.Name] = category
|
||||
if category.ParentCategoryId == models.LevelOneTransactionParentId {
|
||||
continue
|
||||
}
|
||||
|
||||
parentCategory, exists := categoryMap[category.ParentCategoryId]
|
||||
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
|
||||
var categories map[string]*models.TransactionCategory
|
||||
|
||||
if category.Type == models.CATEGORY_TYPE_INCOME {
|
||||
categories, exists = incomeCategoryMap[category.Name]
|
||||
|
||||
if !exists {
|
||||
categories = make(map[string]*models.TransactionCategory)
|
||||
incomeCategoryMap[category.Name] = categories
|
||||
}
|
||||
} else if category.Type == models.CATEGORY_TYPE_EXPENSE {
|
||||
categories, exists = expenseCategoryMap[category.Name]
|
||||
|
||||
if !exists {
|
||||
categories = make(map[string]*models.TransactionCategory)
|
||||
expenseCategoryMap[category.Name] = categories
|
||||
}
|
||||
} else if category.Type == models.CATEGORY_TYPE_TRANSFER {
|
||||
categories, exists = transferCategoryMap[category.Name]
|
||||
|
||||
if !exists {
|
||||
categories = make(map[string]*models.TransactionCategory)
|
||||
transferCategoryMap[category.Name] = categories
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
categories[parentCategory.Name] = category
|
||||
}
|
||||
|
||||
return expenseCategoryMap, incomeCategoryMap, transferCategoryMap
|
||||
|
||||
Reference in New Issue
Block a user