transaction list page supports displaying transaction of specific account

This commit is contained in:
MaysWind
2021-01-02 15:48:45 +08:00
parent 7d3e05c548
commit b3eb239478
7 changed files with 104 additions and 33 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ func (a *DataManagementsApi) ExportDataHandler(c *core.Context) ([]byte, string,
var allTransactions []*models.Transaction var allTransactions []*models.Transaction
for maxTime > 0 { for maxTime > 0 {
transactions, err := a.transactions.GetTransactionsByMaxTime(uid, maxTime, nil, 0, 0, pageCountForDataExport) transactions, err := a.transactions.GetAllTransactionsByMaxTime(uid, maxTime, pageCountForDataExport)
if err != nil { if err != nil {
log.ErrorfWithRequestId(c, "[data_managements.ExportDataHandler] failed to get transactions earlier than \"%d\" for user \"uid:%d\", because %s", maxTime, uid, err.Error()) log.ErrorfWithRequestId(c, "[data_managements.ExportDataHandler] failed to get transactions earlier than \"%d\" for user \"uid:%d\", because %s", maxTime, uid, err.Error())
+2 -2
View File
@@ -36,7 +36,7 @@ func (a *TransactionsApi) TransactionListHandler(c *core.Context) (interface{},
} }
uid := c.GetCurrentUid() uid := c.GetCurrentUid()
transactions, err := a.transactions.GetTransactionsByMaxTime(uid, transactionListReq.MaxTime, nil, 0, 0, transactionListReq.Count+1) transactions, err := a.transactions.GetTransactionsByMaxTime(uid, transactionListReq.MaxTime, transactionListReq.Type, transactionListReq.CategoryId, transactionListReq.AccountId, transactionListReq.Count+1)
if err != nil { if err != nil {
log.ErrorfWithRequestId(c, "[transactions.TransactionListHandler] failed to get transactions earlier than \"%d\" for user \"uid:%d\", because %s", transactionListReq.MaxTime, uid, err.Error()) log.ErrorfWithRequestId(c, "[transactions.TransactionListHandler] failed to get transactions earlier than \"%d\" for user \"uid:%d\", because %s", transactionListReq.MaxTime, uid, err.Error())
@@ -96,7 +96,7 @@ func (a *TransactionsApi) TransactionMonthListHandler(c *core.Context) (interfac
} }
uid := c.GetCurrentUid() uid := c.GetCurrentUid()
transactions, err := a.transactions.GetTransactionsInMonthByPage(uid, transactionListReq.Year, transactionListReq.Month, nil, 0, 0, transactionListReq.Page, transactionListReq.Count) transactions, err := a.transactions.GetTransactionsInMonthByPage(uid, transactionListReq.Year, transactionListReq.Month, transactionListReq.Type, transactionListReq.CategoryId, transactionListReq.AccountId, transactionListReq.Page, transactionListReq.Count)
if err != nil { if err != nil {
log.ErrorfWithRequestId(c, "[transactions.TransactionMonthListHandler] failed to get transactions in month \"%d-%d\" for user \"uid:%d\", because %s", transactionListReq.Year, transactionListReq.Month, uid, err.Error()) log.ErrorfWithRequestId(c, "[transactions.TransactionMonthListHandler] failed to get transactions in month \"%d-%d\" for user \"uid:%d\", because %s", transactionListReq.Year, transactionListReq.Month, uid, err.Error())
+12 -6
View File
@@ -72,16 +72,22 @@ type TransactionModifyRequest struct {
// TransactionListByMaxTimeRequest represents all parameters of transaction listing by max time request // TransactionListByMaxTimeRequest represents all parameters of transaction listing by max time request
type TransactionListByMaxTimeRequest struct { type TransactionListByMaxTimeRequest struct {
MaxTime int64 `form:"max_time" binding:"min=0"` Type TransactionDbType `form:"type" binding:"min=0,max=4"`
Count int `form:"count" binding:"required,min=1,max=50"` CategoryId int64 `form:"category_id" binding:"min=0"`
AccountId int64 `form:"account_id" binding:"min=0"`
MaxTime int64 `form:"max_time" binding:"min=0"`
Count int `form:"count" binding:"required,min=1,max=50"`
} }
// TransactionListInMonthByPageRequest represents all parameters of transaction listing by month request // TransactionListInMonthByPageRequest represents all parameters of transaction listing by month request
type TransactionListInMonthByPageRequest struct { type TransactionListInMonthByPageRequest struct {
Year int `form:"year" binding:"required,min=1"` Year int `form:"year" binding:"required,min=1"`
Month int `form:"month" binding:"required,min=1"` Month int `form:"month" binding:"required,min=1"`
Page int `form:"page" binding:"required,min=1"` Type TransactionDbType `form:"type" binding:"min=0,max=4"`
Count int `form:"count" binding:"required,min=1,max=50"` CategoryId int64 `form:"category_id" binding:"min=0"`
AccountId int64 `form:"account_id" binding:"min=0"`
Page int `form:"page" binding:"required,min=1"`
Count int `form:"count" binding:"required,min=1,max=50"`
} }
// TransactionGetRequest represents all parameters of transaction getting request // TransactionGetRequest represents all parameters of transaction getting request
+43 -16
View File
@@ -31,8 +31,13 @@ var (
} }
) )
// GetAllTransactionsByMaxTime returns all transactions before given time
func (s *TransactionService) GetAllTransactionsByMaxTime(uid int64, maxTime int64, count int) ([]*models.Transaction, error) {
return s.GetTransactionsByMaxTime(uid, maxTime, 0, 0, 0, count)
}
// GetTransactionsByMaxTime returns transactions before given time // GetTransactionsByMaxTime returns transactions before given time
func (s *TransactionService) GetTransactionsByMaxTime(uid int64, maxTime int64, transactionType *models.TransactionDbType, categoryId int64, accountId int64, count int) ([]*models.Transaction, error) { func (s *TransactionService) GetTransactionsByMaxTime(uid int64, maxTime int64, transactionType models.TransactionDbType, categoryId int64, accountId int64, count int) ([]*models.Transaction, error) {
if uid <= 0 { if uid <= 0 {
return nil, errs.ErrUserIdInvalid return nil, errs.ErrUserIdInvalid
} }
@@ -49,15 +54,26 @@ func (s *TransactionService) GetTransactionsByMaxTime(uid int64, maxTime int64,
conditionParams = append(conditionParams, uid) conditionParams = append(conditionParams, uid)
conditionParams = append(conditionParams, false) conditionParams = append(conditionParams, false)
if transactionType != nil { if models.TRANSACTION_DB_TYPE_MODIFY_BALANCE <= transactionType && transactionType <= models.TRANSACTION_DB_TYPE_EXPENSE {
condition = condition + " AND type=?" condition = condition + " AND type=?"
conditionParams = append(conditionParams, transactionType) conditionParams = append(conditionParams, transactionType)
} else if accountId == 0 { } else if transactionType == models.TRANSACTION_DB_TYPE_TRANSFER_OUT || transactionType == models.TRANSACTION_DB_TYPE_TRANSFER_IN {
condition = condition + " AND (type=? OR type=? OR type=? OR type=?)" if accountId == 0 {
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_MODIFY_BALANCE) condition = condition + " AND type=?"
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_INCOME) conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_EXPENSE) } else {
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT) condition = condition + " AND (type=? OR type=?)"
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_IN)
}
} else {
if accountId == 0 {
condition = condition + " AND (type=? OR type=? OR type=? OR type=?)"
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_MODIFY_BALANCE)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_INCOME)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_EXPENSE)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT)
}
} }
if categoryId > 0 { if categoryId > 0 {
@@ -81,7 +97,7 @@ func (s *TransactionService) GetTransactionsByMaxTime(uid int64, maxTime int64,
} }
// GetTransactionsInMonthByPage returns transactions in given year and month // GetTransactionsInMonthByPage returns transactions in given year and month
func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, month int, transactionType *models.TransactionDbType, categoryId int64, accountId int64, page int, count int) ([]*models.Transaction, error) { func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, month int, transactionType models.TransactionDbType, categoryId int64, accountId int64, page int, count int) ([]*models.Transaction, error) {
if uid <= 0 { if uid <= 0 {
return nil, errs.ErrUserIdInvalid return nil, errs.ErrUserIdInvalid
} }
@@ -114,15 +130,26 @@ func (s *TransactionService) GetTransactionsInMonthByPage(uid int64, year int, m
conditionParams = append(conditionParams, startUnixTime) conditionParams = append(conditionParams, startUnixTime)
conditionParams = append(conditionParams, endUnixTime) conditionParams = append(conditionParams, endUnixTime)
if transactionType != nil { if models.TRANSACTION_DB_TYPE_MODIFY_BALANCE <= transactionType && transactionType <= models.TRANSACTION_DB_TYPE_EXPENSE {
condition = condition + " AND type=?" condition = condition + " AND type=?"
conditionParams = append(conditionParams, transactionType) conditionParams = append(conditionParams, transactionType)
} else if accountId == 0 { } else if transactionType == models.TRANSACTION_DB_TYPE_TRANSFER_OUT || transactionType == models.TRANSACTION_DB_TYPE_TRANSFER_IN {
condition = condition + " AND (type=? OR type=? OR type=? OR type=?)" if accountId == 0 {
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_MODIFY_BALANCE) condition = condition + " AND type=?"
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_INCOME) conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_EXPENSE) } else {
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT) condition = condition + " AND (type=? OR type=?)"
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_IN)
}
} else {
if accountId == 0 {
condition = condition + " AND (type=? OR type=? OR type=? OR type=?)"
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_MODIFY_BALANCE)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_INCOME)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_EXPENSE)
conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_TRANSFER_OUT)
}
} }
if categoryId > 0 { if categoryId > 0 {
+2 -2
View File
@@ -219,8 +219,8 @@ export default {
id id
}); });
}, },
getTransactions: ({ maxTime }) => { getTransactions: ({ maxTime, type, categoryId, accountId }) => {
return axios.get('v1/transactions/list.json?max_time=' + maxTime + '&count=20'); return axios.get(`v1/transactions/list.json?max_time=${maxTime}&type=${type}&category_id=${categoryId}&account_id=${accountId}&count=20`);
}, },
getTransaction: ({ id }) => { getTransaction: ({ id }) => {
return axios.get('v1/transactions/get.json?id=' + id); return axios.get('v1/transactions/get.json?id=' + id);
+2 -2
View File
@@ -129,7 +129,7 @@
:key="account.id" :id="account | accountDomId" :key="account.id" :id="account | accountDomId"
:class="{ 'nested-list-item': true, 'has-child-list-item': account.type === $constants.account.allAccountTypes.MultiSubAccounts }" :class="{ 'nested-list-item': true, 'has-child-list-item': account.type === $constants.account.allAccountTypes.MultiSubAccounts }"
:after="accountBalance(account) | currency(account.currency)" :after="accountBalance(account) | currency(account.currency)"
:link="account.type === $constants.account.allAccountTypes.SingleAccount ? '#' : null" :link="account.type === $constants.account.allAccountTypes.SingleAccount ? '/transaction/list?accountId=' + account.id : null"
swipeout @taphold.native="setSortable()" swipeout @taphold.native="setSortable()"
> >
<f7-block slot="title" class="no-padding"> <f7-block slot="title" class="no-padding">
@@ -147,7 +147,7 @@
<f7-list-item class="no-sortable nested-list-item-child" v-for="subAccount in account.subAccounts" v-show="showHidden || !subAccount.hidden" <f7-list-item class="no-sortable nested-list-item-child" v-for="subAccount in account.subAccounts" v-show="showHidden || !subAccount.hidden"
:key="subAccount.id" :id="subAccount | accountDomId" :key="subAccount.id" :id="subAccount | accountDomId"
:title="subAccount.name" :after="accountBalance(subAccount) | currency(subAccount.currency)" :title="subAccount.name" :after="accountBalance(subAccount) | currency(subAccount.currency)"
link="#" :link="'/transaction/list?accountId=' + subAccount.id"
> >
<f7-icon slot="media" :icon="subAccount.icon | accountIcon" <f7-icon slot="media" :icon="subAccount.icon | accountIcon"
:style="subAccount.color | accountIconStyle('var(--default-icon-color)')"> :style="subAccount.color | accountIconStyle('var(--default-icon-color)')">
+42 -4
View File
@@ -130,7 +130,7 @@
<f7-list-item class="transaction-info" chevron-center <f7-list-item class="transaction-info" chevron-center
v-for="(transaction, idx) in transactionMonthList.items" v-for="(transaction, idx) in transactionMonthList.items"
:key="transaction.id" :id="transaction | transactionDomId" :key="transaction.id" :id="transaction | transactionDomId"
:link="'/transaction/detail?id=' + transaction.id" :link="transaction.type !== $constants.transaction.allTransactionTypes.ModifyBalance ? '/transaction/detail?id=' + transaction.id : null"
swipeout swipeout
> >
<div slot="media" class="display-flex no-padding-horizontal"> <div slot="media" class="display-flex no-padding-horizontal">
@@ -147,6 +147,9 @@
:icon="transaction.category.icon | categoryIcon" :icon="transaction.category.icon | categoryIcon"
:style="transaction.category.color | categoryIconStyle('var(--category-icon-color)')"> :style="transaction.category.color | categoryIconStyle('var(--category-icon-color)')">
</f7-icon> </f7-icon>
<f7-icon v-else-if="!transaction.category || !transaction.category.color"
f7="pencil_ellipsis_rectangle">
</f7-icon>
</div> </div>
</div> </div>
<div slot="title" class="no-padding"> <div slot="title" class="no-padding">
@@ -176,7 +179,10 @@
</span> </span>
</div> </div>
<f7-swipeout-actions right> <f7-swipeout-actions right>
<f7-swipeout-button color="orange" close :text="$t('Edit')" @click="edit(transaction)"></f7-swipeout-button> <f7-swipeout-button color="orange" close
:text="$t('Edit')"
v-if="transaction.type !== $constants.transaction.allTransactionTypes.ModifyBalance"
@click="edit(transaction)"></f7-swipeout-button>
<f7-swipeout-button color="red" class="padding-left padding-right" @click="remove(transaction, false)"> <f7-swipeout-button color="red" class="padding-left padding-right" @click="remove(transaction, false)">
<f7-icon f7="trash"></f7-icon> <f7-icon f7="trash"></f7-icon>
</f7-swipeout-button> </f7-swipeout-button>
@@ -215,6 +221,11 @@ export default {
data() { data() {
return { return {
transactions: [], transactions: [],
query: {
type: 0,
categoryId: 0,
accountId: 0
},
allAccounts: {}, allAccounts: {},
allCategories: {}, allCategories: {},
allTags: {}, allTags: {},
@@ -245,6 +256,21 @@ export default {
} }
}, },
created() { created() {
const self = this;
const query = self.$f7route.query;
if (query.type) {
self.query.type = query.type;
}
if (query.categoryId) {
self.query.categoryId = query.categoryId;
}
if (query.accountId) {
self.query.accountId = query.accountId;
}
this.reload(null); this.reload(null);
}, },
methods: { methods: {
@@ -263,7 +289,10 @@ export default {
self.$services.getAllTransactionCategories({}), self.$services.getAllTransactionCategories({}),
self.$services.getAllTransactionTags(), self.$services.getAllTransactionTags(),
self.$services.getTransactions({ self.$services.getTransactions({
maxTime: self.maxTime maxTime: self.maxTime,
type: self.query.type,
categoryId: self.query.categoryId,
accountId: self.query.accountId
}) })
]; ];
@@ -384,7 +413,10 @@ export default {
self.loadingMore = true; self.loadingMore = true;
self.$services.getTransactions({ self.$services.getTransactions({
maxTime: self.maxTime maxTime: self.maxTime,
type: self.query.type,
categoryId: self.query.categoryId,
accountId: self.query.accountId
}).then(response => { }).then(response => {
self.loadingMore = false; self.loadingMore = false;
@@ -595,6 +627,12 @@ export default {
totalExpense += amount; totalExpense += amount;
} else if (transaction.type === this.$constants.transaction.allTransactionTypes.Income) { } else if (transaction.type === this.$constants.transaction.allTransactionTypes.Income) {
totalIncome += amount; totalIncome += amount;
} else if (transaction.type === this.$constants.transaction.allTransactionTypes.Transfer && this.query.accountId) {
if (this.query.accountId === transaction.sourceAccountId) {
totalExpense += amount;
} else if (this.query.accountId === transaction.destinationAccountId) {
totalIncome += amount;
}
} }
} }