From 563e328ce3ebc476e91cbcb43837da5eb11b43a8 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 11 Dec 2024 23:53:01 +0800 Subject: [PATCH] sub account cannot set statement date --- pkg/api/accounts.go | 50 +++++++++---------- pkg/errs/account.go | 1 + pkg/models/account.go | 2 +- src/locales/en.json | 1 + src/locales/vi.json | 1 + src/locales/zh_Hans.json | 1 + src/stores/account.js | 5 -- .../accounts/list/dialogs/EditDialog.vue | 6 +-- src/views/mobile/accounts/EditPage.vue | 14 ------ 9 files changed, 33 insertions(+), 48 deletions(-) diff --git a/pkg/api/accounts.go b/pkg/api/accounts.go index b14b7cf4..6cdd0fbc 100644 --- a/pkg/api/accounts.go +++ b/pkg/api/accounts.go @@ -159,6 +159,11 @@ func (a *AccountsApi) AccountCreateHandler(c *core.WebContext) (any, *errs.Error return nil, errs.ErrAccountCategoryInvalid } + if accountCreateReq.Category != models.ACCOUNT_CATEGORY_CREDIT_CARD && accountCreateReq.CreditCardStatementDate != 0 { + log.Warnf(c, "[accounts.AccountCreateHandler] cannot set statement date with category \"%d\"", accountCreateReq.Category) + return nil, errs.ErrCannotSetStatementDateForNonCreditCard + } + if accountCreateReq.Type == models.ACCOUNT_TYPE_SINGLE_ACCOUNT { if len(accountCreateReq.SubAccounts) > 0 { log.Warnf(c, "[accounts.AccountCreateHandler] account cannot have any sub-accounts") @@ -174,11 +179,6 @@ func (a *AccountsApi) AccountCreateHandler(c *core.WebContext) (any, *errs.Error log.Warnf(c, "[accounts.AccountCreateHandler] account balance time is not set") return nil, errs.ErrAccountBalanceTimeNotSet } - - if accountCreateReq.Category != models.ACCOUNT_CATEGORY_CREDIT_CARD && accountCreateReq.CreditCardStatementDate != 0 { - log.Warnf(c, "[accounts.AccountCreateHandler] cannot set statement date with category \"%d\"", accountCreateReq.Category) - return nil, errs.ErrCannotSetStatementDateForNonCreditCard - } } else if accountCreateReq.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS { if len(accountCreateReq.SubAccounts) < 1 { log.Warnf(c, "[accounts.AccountCreateHandler] account does not have any sub-accounts") @@ -218,9 +218,9 @@ func (a *AccountsApi) AccountCreateHandler(c *core.WebContext) (any, *errs.Error return nil, errs.ErrAccountBalanceTimeNotSet } - if subAccount.Category != models.ACCOUNT_CATEGORY_CREDIT_CARD && subAccount.CreditCardStatementDate != 0 { - log.Warnf(c, "[accounts.AccountCreateHandler] sub-account#%d cannot set statement date with category \"%d\"", i, subAccount.Category) - return nil, errs.ErrCannotSetStatementDateForNonCreditCard + if subAccount.CreditCardStatementDate != 0 { + log.Warnf(c, "[accounts.AccountCreateHandler] sub-account#%d cannot set statement date", i) + return nil, errs.ErrCannotSetStatementDateForSubAccount } } } else { @@ -236,7 +236,7 @@ func (a *AccountsApi) AccountCreateHandler(c *core.WebContext) (any, *errs.Error return nil, errs.Or(err, errs.ErrOperationFailed) } - mainAccount := a.createNewAccountModel(uid, &accountCreateReq, maxOrderId+1) + mainAccount := a.createNewAccountModel(uid, &accountCreateReq, false, maxOrderId+1) childrenAccounts, childrenAccountBalanceTimes := a.createSubAccountModels(uid, &accountCreateReq) if a.CurrentConfig().EnableDuplicateSubmissionsCheck && accountCreateReq.ClientSessionId != "" { @@ -332,18 +332,18 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error return nil, errs.ErrCannotAddOrDeleteSubAccountsWhenModify } - if mainAccount.Type == models.ACCOUNT_TYPE_SINGLE_ACCOUNT { - if accountModifyReq.Category != models.ACCOUNT_CATEGORY_CREDIT_CARD && accountModifyReq.CreditCardStatementDate != 0 { - log.Warnf(c, "[accounts.AccountModifyHandler] cannot set statement date with category \"%d\"", accountModifyReq.Category) - return nil, errs.ErrCannotSetStatementDateForNonCreditCard - } - } else if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS { + if accountModifyReq.Category != models.ACCOUNT_CATEGORY_CREDIT_CARD && accountModifyReq.CreditCardStatementDate != 0 { + log.Warnf(c, "[accounts.AccountModifyHandler] cannot set statement date with category \"%d\"", accountModifyReq.Category) + return nil, errs.ErrCannotSetStatementDateForNonCreditCard + } + + if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS { for i := 0; i < len(accountModifyReq.SubAccounts); i++ { subAccount := accountModifyReq.SubAccounts[i] - if subAccount.Category != models.ACCOUNT_CATEGORY_CREDIT_CARD && subAccount.CreditCardStatementDate != 0 { - log.Warnf(c, "[accounts.AccountModifyHandler] sub-account#%d cannot set statement date with category \"%d\"", i, subAccount.Category) - return nil, errs.ErrCannotSetStatementDateForNonCreditCard + if subAccount.CreditCardStatementDate != 0 { + log.Warnf(c, "[accounts.AccountModifyHandler] sub-account#%d cannot set statement date", i) + return nil, errs.ErrCannotSetStatementDateForSubAccount } } } @@ -351,7 +351,7 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error anythingUpdate := false var toUpdateAccounts []*models.Account - toUpdateAccount := a.getToUpdateAccount(uid, &accountModifyReq, mainAccount) + toUpdateAccount := a.getToUpdateAccount(uid, &accountModifyReq, mainAccount, false) if toUpdateAccount != nil { anythingUpdate = true @@ -365,7 +365,7 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error return nil, errs.ErrAccountNotFound } - toUpdateSubAccount := a.getToUpdateAccount(uid, subAccountReq, accountMap[subAccountReq.Id]) + toUpdateSubAccount := a.getToUpdateAccount(uid, subAccountReq, accountMap[subAccountReq.Id], true) if toUpdateSubAccount != nil { anythingUpdate = true @@ -505,10 +505,10 @@ func (a *AccountsApi) AccountDeleteHandler(c *core.WebContext) (any, *errs.Error return true, nil } -func (a *AccountsApi) createNewAccountModel(uid int64, accountCreateReq *models.AccountCreateRequest, order int32) *models.Account { +func (a *AccountsApi) createNewAccountModel(uid int64, accountCreateReq *models.AccountCreateRequest, isSubAccount bool, order int32) *models.Account { accountExtend := &models.AccountExtend{} - if accountCreateReq.Category == models.ACCOUNT_CATEGORY_CREDIT_CARD { + if !isSubAccount && accountCreateReq.Category == models.ACCOUNT_CATEGORY_CREDIT_CARD { accountExtend.CreditCardStatementDate = &accountCreateReq.CreditCardStatementDate } @@ -536,17 +536,17 @@ func (a *AccountsApi) createSubAccountModels(uid int64, accountCreateReq *models childrenAccountBalanceTimes := make([]int64, len(accountCreateReq.SubAccounts)) for i := int32(0); i < int32(len(accountCreateReq.SubAccounts)); i++ { - childrenAccounts[i] = a.createNewAccountModel(uid, accountCreateReq.SubAccounts[i], i+1) + childrenAccounts[i] = a.createNewAccountModel(uid, accountCreateReq.SubAccounts[i], true, i+1) childrenAccountBalanceTimes[i] = accountCreateReq.SubAccounts[i].BalanceTime } return childrenAccounts, childrenAccountBalanceTimes } -func (a *AccountsApi) getToUpdateAccount(uid int64, accountModifyReq *models.AccountModifyRequest, oldAccount *models.Account) *models.Account { +func (a *AccountsApi) getToUpdateAccount(uid int64, accountModifyReq *models.AccountModifyRequest, oldAccount *models.Account, isSubAccount bool) *models.Account { newAccountExtend := &models.AccountExtend{} - if accountModifyReq.Category == models.ACCOUNT_CATEGORY_CREDIT_CARD { + if !isSubAccount && accountModifyReq.Category == models.ACCOUNT_CATEGORY_CREDIT_CARD { newAccountExtend.CreditCardStatementDate = &accountModifyReq.CreditCardStatementDate } diff --git a/pkg/errs/account.go b/pkg/errs/account.go index c685504f..4ccc638e 100644 --- a/pkg/errs/account.go +++ b/pkg/errs/account.go @@ -21,4 +21,5 @@ var ( ErrAccountCategoryInvalid = NewNormalError(NormalSubcategoryAccount, 14, http.StatusBadRequest, "account category is invalid") ErrAccountBalanceTimeNotSet = NewNormalError(NormalSubcategoryAccount, 15, http.StatusBadRequest, "account balance time is not set") ErrCannotSetStatementDateForNonCreditCard = NewNormalError(NormalSubcategoryAccount, 16, http.StatusBadRequest, "cannot set statement date for non credit card account") + ErrCannotSetStatementDateForSubAccount = NewNormalError(NormalSubcategoryAccount, 17, http.StatusBadRequest, "cannot set statement date for sub account") ) diff --git a/pkg/models/account.go b/pkg/models/account.go index 291a437e..03f9e0c0 100644 --- a/pkg/models/account.go +++ b/pkg/models/account.go @@ -168,7 +168,7 @@ type AccountInfoResponse struct { func (a *Account) ToAccountInfoResponse() *AccountInfoResponse { var creditCardStatementDate *int - if a.Category == ACCOUNT_CATEGORY_CREDIT_CARD { + if a.ParentAccountId == LevelOneAccountParentId && a.Category == ACCOUNT_CATEGORY_CREDIT_CARD { if a.Extend != nil { creditCardStatementDate = a.Extend.CreditCardStatementDate } else { diff --git a/src/locales/en.json b/src/locales/en.json index b41b1682..275c7790 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1062,6 +1062,7 @@ "account category is invalid": "Account category is invalid", "account balance time is not set": "Account balance time is not set", "cannot set statement date for non credit card account": "Cannot set statement date for non credit card account", + "cannot set statement date for sub account": "Cannot set statement date for sub-account", "transaction id is invalid": "Transaction ID is invalid", "transaction not found": "Transaction is not found", "transaction type is invalid": "Transaction type is invalid", diff --git a/src/locales/vi.json b/src/locales/vi.json index 8dbf2de9..f7447dd5 100644 --- a/src/locales/vi.json +++ b/src/locales/vi.json @@ -1062,6 +1062,7 @@ "account category is invalid": "Danh mục tài khoản không hợp lệ", "account balance time is not set": "Thời gian số dư tài khoản chưa được đặt", "cannot set statement date for non credit card account": "Cannot set statement date for non credit card account", + "cannot set statement date for sub account": "Cannot set statement date for sub-account", "transaction id is invalid": "ID giao dịch không hợp lệ", "transaction not found": "Không tìm thấy giao dịch", "transaction type is invalid": "Loại giao dịch không hợp lệ", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 6385df5b..7b082670 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1062,6 +1062,7 @@ "account category is invalid": "账户分类无效", "account balance time is not set": "账户余额时间没有设置", "cannot set statement date for non credit card account": "非信用卡账户不能设置账单日期", + "cannot set statement date for sub account": "子账户不能设置账单日期", "transaction id is invalid": "交易ID无效", "transaction not found": "交易不存在", "transaction type is invalid": "交易类型无效", diff --git a/src/stores/account.js b/src/stores/account.js index 306fec51..7344db56 100644 --- a/src/stores/account.js +++ b/src/stores/account.js @@ -285,7 +285,6 @@ export const useAccountsStore = defineStore('accounts', { balance: 0, balanceTime: now, comment: '', - creditCardStatementDate: parentAccount.creditCardStatementDate, visible: true }; }, @@ -762,10 +761,6 @@ export const useAccountsStore = defineStore('accounts', { comment: subAccount.comment }; - if (account.category === accountConstants.creditCardCategoryType) { - submitAccount.creditCardStatementDate = subAccount.creditCardStatementDate; - } - if (isEdit) { submitAccount.id = subAccount.id; submitAccount.hidden = !subAccount.visible; diff --git a/src/views/desktop/accounts/list/dialogs/EditDialog.vue b/src/views/desktop/accounts/list/dialogs/EditDialog.vue index 44057475..f8196111 100644 --- a/src/views/desktop/accounts/list/dialogs/EditDialog.vue +++ b/src/views/desktop/accounts/list/dialogs/EditDialog.vue @@ -108,7 +108,7 @@ :disabled="loading || submitting" v-model="selectedAccount.color" /> - + - + - - - -