mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 16:54:25 +08:00
auto set transaction type in transaction adding page according to the category id
This commit is contained in:
@@ -4,6 +4,8 @@ import uaParser from 'ua-parser-js';
|
|||||||
|
|
||||||
import dateTimeConstants from '../consts/datetime.js';
|
import dateTimeConstants from '../consts/datetime.js';
|
||||||
import accountConstants from '../consts/account.js';
|
import accountConstants from '../consts/account.js';
|
||||||
|
import categoryConstants from '../consts/category.js';
|
||||||
|
import transactionConstants from '../consts/transaction.js';
|
||||||
import settings from './settings.js';
|
import settings from './settings.js';
|
||||||
|
|
||||||
function isFunction(val) {
|
function isFunction(val) {
|
||||||
@@ -559,6 +561,30 @@ function parseUserAgent(ua) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transactionTypeToCategroyType(transactionType) {
|
||||||
|
if (transactionType === transactionConstants.allTransactionTypes.Income) {
|
||||||
|
return categoryConstants.allCategoryTypes.Income;
|
||||||
|
} else if (transactionType === transactionConstants.allTransactionTypes.Expense) {
|
||||||
|
return categoryConstants.allCategoryTypes.Expense;
|
||||||
|
} else if (transactionType === transactionConstants.allTransactionTypes.Transfer) {
|
||||||
|
return categoryConstants.allCategoryTypes.Transfer;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function categroyTypeToTransactionType(categoryType) {
|
||||||
|
if (categoryType === categoryConstants.allCategoryTypes.Income) {
|
||||||
|
return transactionConstants.allTransactionTypes.Income;
|
||||||
|
} else if (categoryType === categoryConstants.allCategoryTypes.Expense) {
|
||||||
|
return transactionConstants.allTransactionTypes.Expense;
|
||||||
|
} else if (categoryType === categoryConstants.allCategoryTypes.Transfer) {
|
||||||
|
return transactionConstants.allTransactionTypes.Transfer;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getCategoryInfo(categoryId) {
|
function getCategoryInfo(categoryId) {
|
||||||
for (let i = 0; i < accountConstants.allCategories.length; i++) {
|
for (let i = 0; i < accountConstants.allCategories.length; i++) {
|
||||||
if (accountConstants.allCategories[i].id === categoryId) {
|
if (accountConstants.allCategories[i].id === categoryId) {
|
||||||
@@ -700,6 +726,8 @@ export default {
|
|||||||
stringToArrayBuffer,
|
stringToArrayBuffer,
|
||||||
generateRandomString,
|
generateRandomString,
|
||||||
parseUserAgent,
|
parseUserAgent,
|
||||||
|
transactionTypeToCategroyType,
|
||||||
|
categroyTypeToTransactionType,
|
||||||
getCategoryInfo,
|
getCategoryInfo,
|
||||||
getCategorizedAccounts,
|
getCategorizedAccounts,
|
||||||
getAllFilteredAccountsBalance,
|
getAllFilteredAccountsBalance,
|
||||||
|
|||||||
@@ -458,6 +458,9 @@ export default {
|
|||||||
allCategories() {
|
allCategories() {
|
||||||
return this.$store.state.allTransactionCategories;
|
return this.$store.state.allTransactionCategories;
|
||||||
},
|
},
|
||||||
|
allCategoriesMap() {
|
||||||
|
return this.$store.state.allTransactionCategoriesMap;
|
||||||
|
},
|
||||||
allTags() {
|
allTags() {
|
||||||
return this.$store.state.allTransactionTags;
|
return this.$store.state.allTransactionTags;
|
||||||
},
|
},
|
||||||
@@ -601,6 +604,15 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((!query.type || query.type === '0') && query.categoryId && query.categoryId !== '0' && self.allCategoriesMap[query.categoryId]) {
|
||||||
|
const category = self.allCategoriesMap[query.categoryId];
|
||||||
|
const type = self.$utilities.categroyTypeToTransactionType(category.type);
|
||||||
|
|
||||||
|
if (self.$utilities.isNumber(type)) {
|
||||||
|
self.transaction.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (self.allCategories[self.$constants.category.allCategoryTypes.Expense] &&
|
if (self.allCategories[self.$constants.category.allCategoryTypes.Expense] &&
|
||||||
self.allCategories[self.$constants.category.allCategoryTypes.Expense].length) {
|
self.allCategories[self.$constants.category.allCategoryTypes.Expense].length) {
|
||||||
if (query.categoryId && query.categoryId !== '0' && self.isCategoryIdAvailable(self.allCategories[self.$constants.category.allCategoryTypes.Expense], query.categoryId)) {
|
if (query.categoryId && query.categoryId !== '0' && self.isCategoryIdAvailable(self.allCategories[self.$constants.category.allCategoryTypes.Expense], query.categoryId)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user