support adding / deleting sub account after account created (#77)
This commit is contained in:
+229
-19
@@ -311,11 +311,27 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
|
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if accountModifyReq.Id <= 0 {
|
||||||
|
return nil, errs.ErrAccountIdInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
utcOffset, err := c.GetClientTimezoneOffset()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf(c, "[accounts.AccountModifyHandler] cannot get client timezone offset, because %s", err.Error())
|
||||||
|
return nil, errs.ErrClientTimezoneOffsetInvalid
|
||||||
|
}
|
||||||
|
|
||||||
if accountModifyReq.Category < models.ACCOUNT_CATEGORY_CASH || accountModifyReq.Category > models.ACCOUNT_CATEGORY_CERTIFICATE_OF_DEPOSIT {
|
if accountModifyReq.Category < models.ACCOUNT_CATEGORY_CASH || accountModifyReq.Category > models.ACCOUNT_CATEGORY_CERTIFICATE_OF_DEPOSIT {
|
||||||
log.Warnf(c, "[accounts.AccountModifyHandler] account category invalid, category is %d", accountModifyReq.Category)
|
log.Warnf(c, "[accounts.AccountModifyHandler] account category invalid, category is %d", accountModifyReq.Category)
|
||||||
return nil, errs.ErrAccountCategoryInvalid
|
return nil, errs.ErrAccountCategoryInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
uid := c.GetCurrentUid()
|
uid := c.GetCurrentUid()
|
||||||
accountAndSubAccounts, err := a.accounts.GetAccountAndSubAccountsByAccountId(c, uid, accountModifyReq.Id)
|
accountAndSubAccounts, err := a.accounts.GetAccountAndSubAccountsByAccountId(c, uid, accountModifyReq.Id)
|
||||||
|
|
||||||
@@ -331,20 +347,81 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
return nil, errs.ErrAccountNotFound
|
return nil, errs.ErrAccountNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(accountModifyReq.SubAccounts)+1 != len(accountAndSubAccounts) {
|
if accountModifyReq.Currency != nil && mainAccount.Currency != *accountModifyReq.Currency {
|
||||||
return nil, errs.ErrCannotAddOrDeleteSubAccountsWhenModify
|
return nil, errs.ErrNotSupportedChangeCurrency
|
||||||
}
|
}
|
||||||
|
|
||||||
if accountModifyReq.Category != models.ACCOUNT_CATEGORY_CREDIT_CARD && accountModifyReq.CreditCardStatementDate != 0 {
|
if accountModifyReq.Balance != nil {
|
||||||
log.Warnf(c, "[accounts.AccountModifyHandler] cannot set statement date with category \"%d\"", accountModifyReq.Category)
|
return nil, errs.ErrNotSupportedChangeBalance
|
||||||
return nil, errs.ErrCannotSetStatementDateForNonCreditCard
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS {
|
if accountModifyReq.BalanceTime != nil {
|
||||||
|
return nil, errs.ErrNotSupportedChangeBalanceTime
|
||||||
|
}
|
||||||
|
|
||||||
|
if mainAccount.Type == models.ACCOUNT_TYPE_SINGLE_ACCOUNT {
|
||||||
|
if len(accountModifyReq.SubAccounts) > 0 {
|
||||||
|
log.Warnf(c, "[accounts.AccountModifyHandler] account cannot have any sub-accounts")
|
||||||
|
return nil, errs.ErrAccountCannotHaveSubAccounts
|
||||||
|
}
|
||||||
|
} else if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS {
|
||||||
|
if len(accountModifyReq.SubAccounts) < 1 {
|
||||||
|
log.Warnf(c, "[accounts.AccountModifyHandler] account does not have any sub-accounts")
|
||||||
|
return nil, errs.ErrAccountHaveNoSubAccount
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < len(accountModifyReq.SubAccounts); i++ {
|
for i := 0; i < len(accountModifyReq.SubAccounts); i++ {
|
||||||
subAccount := accountModifyReq.SubAccounts[i]
|
subAccountReq := accountModifyReq.SubAccounts[i]
|
||||||
|
|
||||||
if subAccount.CreditCardStatementDate != 0 {
|
if subAccountReq.Category != accountModifyReq.Category {
|
||||||
|
log.Warnf(c, "[accounts.AccountModifyHandler] category of sub-account#%d not equals to parent", i)
|
||||||
|
return nil, errs.ErrSubAccountCategoryNotEqualsToParent
|
||||||
|
}
|
||||||
|
|
||||||
|
if subAccountReq.Id == 0 { // create new sub-account
|
||||||
|
if subAccountReq.Currency == nil {
|
||||||
|
log.Warnf(c, "[accounts.AccountModifyHandler] sub-account#%d not set currency", i)
|
||||||
|
return nil, errs.ErrAccountCurrencyInvalid
|
||||||
|
} else if subAccountReq.Currency != nil && *subAccountReq.Currency == validators.ParentAccountCurrencyPlaceholder {
|
||||||
|
log.Warnf(c, "[accounts.AccountModifyHandler] sub-account#%d cannot set currency placeholder", i)
|
||||||
|
return nil, errs.ErrAccountCurrencyInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
if subAccountReq.Balance == nil {
|
||||||
|
defaultBalance := int64(0)
|
||||||
|
subAccountReq.Balance = &defaultBalance
|
||||||
|
}
|
||||||
|
|
||||||
|
if *subAccountReq.Balance == 0 {
|
||||||
|
defaultBalanceTime := int64(0)
|
||||||
|
subAccountReq.BalanceTime = &defaultBalanceTime
|
||||||
|
}
|
||||||
|
|
||||||
|
if *subAccountReq.Balance != 0 && (subAccountReq.BalanceTime == nil || *subAccountReq.BalanceTime <= 0) {
|
||||||
|
log.Warnf(c, "[accounts.AccountModifyHandler] sub-account#%d balance time is not set", i)
|
||||||
|
return nil, errs.ErrAccountBalanceTimeNotSet
|
||||||
|
}
|
||||||
|
} else { // modify existed sub-account
|
||||||
|
subAccount, exists := accountMap[subAccountReq.Id]
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
return nil, errs.ErrAccountNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
if subAccountReq.Currency != nil && subAccount.Currency != *subAccountReq.Currency {
|
||||||
|
return nil, errs.ErrNotSupportedChangeCurrency
|
||||||
|
}
|
||||||
|
|
||||||
|
if subAccountReq.Balance != nil {
|
||||||
|
return nil, errs.ErrNotSupportedChangeBalance
|
||||||
|
}
|
||||||
|
|
||||||
|
if subAccountReq.BalanceTime != nil {
|
||||||
|
return nil, errs.ErrNotSupportedChangeBalanceTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if subAccountReq.CreditCardStatementDate != 0 {
|
||||||
log.Warnf(c, "[accounts.AccountModifyHandler] sub-account#%d cannot set statement date", i)
|
log.Warnf(c, "[accounts.AccountModifyHandler] sub-account#%d cannot set statement date", i)
|
||||||
return nil, errs.ErrCannotSetStatementDateForSubAccount
|
return nil, errs.ErrCannotSetStatementDateForSubAccount
|
||||||
}
|
}
|
||||||
@@ -353,6 +430,9 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
|
|
||||||
anythingUpdate := false
|
anythingUpdate := false
|
||||||
var toUpdateAccounts []*models.Account
|
var toUpdateAccounts []*models.Account
|
||||||
|
var toAddAccounts []*models.Account
|
||||||
|
var toAddAccountBalanceTimes []int64
|
||||||
|
var toDeleteAccountIds []int64
|
||||||
|
|
||||||
toUpdateAccount := a.getToUpdateAccount(uid, &accountModifyReq, mainAccount, false)
|
toUpdateAccount := a.getToUpdateAccount(uid, &accountModifyReq, mainAccount, false)
|
||||||
|
|
||||||
@@ -361,18 +441,43 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
toUpdateAccounts = append(toUpdateAccounts, toUpdateAccount)
|
toUpdateAccounts = append(toUpdateAccounts, toUpdateAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toDeleteAccountIds = a.getToDeleteSubAccountIds(&accountModifyReq, mainAccount, accountAndSubAccounts)
|
||||||
|
|
||||||
|
if len(toDeleteAccountIds) > 0 {
|
||||||
|
anythingUpdate = true
|
||||||
|
}
|
||||||
|
|
||||||
|
maxOrderId := int32(0)
|
||||||
|
|
||||||
|
for i := 0; i < len(accountAndSubAccounts); i++ {
|
||||||
|
account := accountAndSubAccounts[i]
|
||||||
|
|
||||||
|
if account.AccountId != mainAccount.AccountId && account.DisplayOrder > maxOrderId {
|
||||||
|
maxOrderId = account.DisplayOrder
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < len(accountModifyReq.SubAccounts); i++ {
|
for i := 0; i < len(accountModifyReq.SubAccounts); i++ {
|
||||||
subAccountReq := accountModifyReq.SubAccounts[i]
|
subAccountReq := accountModifyReq.SubAccounts[i]
|
||||||
|
|
||||||
if _, exists := accountMap[subAccountReq.Id]; !exists {
|
if _, exists := accountMap[subAccountReq.Id]; !exists {
|
||||||
return nil, errs.ErrAccountNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
toUpdateSubAccount := a.getToUpdateAccount(uid, subAccountReq, accountMap[subAccountReq.Id], true)
|
|
||||||
|
|
||||||
if toUpdateSubAccount != nil {
|
|
||||||
anythingUpdate = true
|
anythingUpdate = true
|
||||||
toUpdateAccounts = append(toUpdateAccounts, toUpdateSubAccount)
|
maxOrderId = maxOrderId + 1
|
||||||
|
newSubAccount := a.createNewSubAccountModelForModify(uid, mainAccount.Type, subAccountReq, maxOrderId)
|
||||||
|
toAddAccounts = append(toAddAccounts, newSubAccount)
|
||||||
|
|
||||||
|
if subAccountReq.BalanceTime != nil {
|
||||||
|
toAddAccountBalanceTimes = append(toAddAccountBalanceTimes, *subAccountReq.BalanceTime)
|
||||||
|
} else {
|
||||||
|
toAddAccountBalanceTimes = append(toAddAccountBalanceTimes, 0)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toUpdateSubAccount := a.getToUpdateAccount(uid, subAccountReq, accountMap[subAccountReq.Id], true)
|
||||||
|
|
||||||
|
if toUpdateSubAccount != nil {
|
||||||
|
anythingUpdate = true
|
||||||
|
toUpdateAccounts = append(toUpdateAccounts, toUpdateSubAccount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +485,43 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
return nil, errs.ErrNothingWillBeUpdated
|
return nil, errs.ErrNothingWillBeUpdated
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.accounts.ModifyAccounts(c, uid, toUpdateAccounts)
|
if len(toAddAccounts) > 0 && a.CurrentConfig().EnableDuplicateSubmissionsCheck && accountModifyReq.ClientSessionId != "" {
|
||||||
|
found, remark := a.GetSubmissionRemark(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_SUBACCOUNT, uid, accountModifyReq.ClientSessionId)
|
||||||
|
|
||||||
|
if found {
|
||||||
|
log.Infof(c, "[accounts.AccountModifyHandler] another account \"id:%s\" modification has been created for user \"uid:%d\"", remark, uid)
|
||||||
|
accountId, err := utils.StringToInt64(remark)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
accountAndSubAccounts, err := a.accounts.GetAccountAndSubAccountsByAccountId(c, uid, accountId)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf(c, "[accounts.AccountModifyHandler] failed to get existed account \"id:%d\" for user \"uid:%d\", because %s", accountId, uid, err.Error())
|
||||||
|
return nil, errs.Or(err, errs.ErrOperationFailed)
|
||||||
|
}
|
||||||
|
|
||||||
|
accountMap := a.accounts.GetAccountMapByList(accountAndSubAccounts)
|
||||||
|
mainAccount, exists := accountMap[accountId]
|
||||||
|
|
||||||
|
if !exists {
|
||||||
|
return nil, errs.ErrOperationFailed
|
||||||
|
}
|
||||||
|
|
||||||
|
accountInfoResp := mainAccount.ToAccountInfoResponse()
|
||||||
|
|
||||||
|
for i := 0; i < len(accountAndSubAccounts); i++ {
|
||||||
|
if accountAndSubAccounts[i].ParentAccountId == mainAccount.AccountId {
|
||||||
|
subAccountResp := accountAndSubAccounts[i].ToAccountInfoResponse()
|
||||||
|
accountInfoResp.SubAccounts = append(accountInfoResp.SubAccounts, subAccountResp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return accountInfoResp, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.accounts.ModifyAccounts(c, mainAccount, toUpdateAccounts, toAddAccounts, toAddAccountBalanceTimes, toDeleteAccountIds, utcOffset)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(c, "[accounts.AccountModifyHandler] failed to update account \"id:%d\" for user \"uid:%d\", because %s", accountModifyReq.Id, uid, err.Error())
|
log.Errorf(c, "[accounts.AccountModifyHandler] failed to update account \"id:%d\" for user \"uid:%d\", because %s", accountModifyReq.Id, uid, err.Error())
|
||||||
@@ -389,6 +530,10 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
|
|
||||||
log.Infof(c, "[accounts.AccountModifyHandler] user \"uid:%d\" has updated account \"id:%d\" successfully", uid, accountModifyReq.Id)
|
log.Infof(c, "[accounts.AccountModifyHandler] user \"uid:%d\" has updated account \"id:%d\" successfully", uid, accountModifyReq.Id)
|
||||||
|
|
||||||
|
if len(toAddAccounts) > 0 {
|
||||||
|
a.SetSubmissionRemarkIfEnable(duplicatechecker.DUPLICATE_CHECKER_TYPE_NEW_SUBACCOUNT, uid, accountModifyReq.ClientSessionId, utils.Int64ToString(mainAccount.AccountId))
|
||||||
|
}
|
||||||
|
|
||||||
accountRespMap := make(map[int64]*models.AccountInfoResponse)
|
accountRespMap := make(map[int64]*models.AccountInfoResponse)
|
||||||
|
|
||||||
for i := 0; i < len(toUpdateAccounts); i++ {
|
for i := 0; i < len(toUpdateAccounts); i++ {
|
||||||
@@ -405,11 +550,23 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
accountRespMap[accountResp.Id] = accountResp
|
accountRespMap[accountResp.Id] = accountResp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(toAddAccounts); i++ {
|
||||||
|
account := toAddAccounts[i]
|
||||||
|
accountResp := account.ToAccountInfoResponse()
|
||||||
|
accountRespMap[accountResp.Id] = accountResp
|
||||||
|
}
|
||||||
|
|
||||||
|
deletedAccountIds := make(map[int64]bool)
|
||||||
|
|
||||||
|
for i := 0; i < len(toDeleteAccountIds); i++ {
|
||||||
|
deletedAccountIds[toDeleteAccountIds[i]] = true
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < len(accountAndSubAccounts); i++ {
|
for i := 0; i < len(accountAndSubAccounts); i++ {
|
||||||
oldAccount := accountAndSubAccounts[i]
|
oldAccount := accountAndSubAccounts[i]
|
||||||
_, exists := accountRespMap[oldAccount.AccountId]
|
_, exists := accountRespMap[oldAccount.AccountId]
|
||||||
|
|
||||||
if !exists {
|
if !exists && !deletedAccountIds[oldAccount.AccountId] {
|
||||||
oldAccountResp := oldAccount.ToAccountInfoResponse()
|
oldAccountResp := oldAccount.ToAccountInfoResponse()
|
||||||
accountRespMap[oldAccountResp.Id] = oldAccountResp
|
accountRespMap[oldAccountResp.Id] = oldAccountResp
|
||||||
}
|
}
|
||||||
@@ -418,8 +575,19 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error
|
|||||||
accountResp := accountRespMap[accountModifyReq.Id]
|
accountResp := accountRespMap[accountModifyReq.Id]
|
||||||
|
|
||||||
for i := 0; i < len(accountAndSubAccounts); i++ {
|
for i := 0; i < len(accountAndSubAccounts); i++ {
|
||||||
if accountAndSubAccounts[i].ParentAccountId == accountResp.Id {
|
account := accountAndSubAccounts[i]
|
||||||
subAccountResp := accountRespMap[accountAndSubAccounts[i].AccountId]
|
|
||||||
|
if account.ParentAccountId == accountResp.Id && !deletedAccountIds[account.AccountId] {
|
||||||
|
subAccountResp := accountRespMap[account.AccountId]
|
||||||
|
accountResp.SubAccounts = append(accountResp.SubAccounts, subAccountResp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(toAddAccounts); i++ {
|
||||||
|
account := toAddAccounts[i]
|
||||||
|
|
||||||
|
if account.ParentAccountId == accountResp.Id {
|
||||||
|
subAccountResp := accountRespMap[account.AccountId]
|
||||||
accountResp.SubAccounts = append(accountResp.SubAccounts, subAccountResp)
|
accountResp.SubAccounts = append(accountResp.SubAccounts, subAccountResp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,6 +720,24 @@ func (a *AccountsApi) createNewAccountModel(uid int64, accountCreateReq *models.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AccountsApi) createNewSubAccountModelForModify(uid int64, accountType models.AccountType, accountModifyReq *models.AccountModifyRequest, order int32) *models.Account {
|
||||||
|
accountExtend := &models.AccountExtend{}
|
||||||
|
|
||||||
|
return &models.Account{
|
||||||
|
Uid: uid,
|
||||||
|
Name: accountModifyReq.Name,
|
||||||
|
DisplayOrder: order,
|
||||||
|
Category: accountModifyReq.Category,
|
||||||
|
Type: accountType,
|
||||||
|
Icon: accountModifyReq.Icon,
|
||||||
|
Color: accountModifyReq.Color,
|
||||||
|
Currency: *accountModifyReq.Currency,
|
||||||
|
Balance: *accountModifyReq.Balance,
|
||||||
|
Comment: accountModifyReq.Comment,
|
||||||
|
Extend: accountExtend,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AccountsApi) createSubAccountModels(uid int64, accountCreateReq *models.AccountCreateRequest) ([]*models.Account, []int64) {
|
func (a *AccountsApi) createSubAccountModels(uid int64, accountCreateReq *models.AccountCreateRequest) ([]*models.Account, []int64) {
|
||||||
if len(accountCreateReq.SubAccounts) <= 0 {
|
if len(accountCreateReq.SubAccounts) <= 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@@ -609,3 +795,27 @@ func (a *AccountsApi) getToUpdateAccount(uid int64, accountModifyReq *models.Acc
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AccountsApi) getToDeleteSubAccountIds(accountModifyReq *models.AccountModifyRequest, mainAccount *models.Account, accountAndSubAccounts []*models.Account) []int64 {
|
||||||
|
newSubAccountIds := make(map[int64]bool, len(accountModifyReq.SubAccounts))
|
||||||
|
|
||||||
|
for i := 0; i < len(accountModifyReq.SubAccounts); i++ {
|
||||||
|
newSubAccountIds[accountModifyReq.SubAccounts[i].Id] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
toDeleteAccountIds := make([]int64, 0)
|
||||||
|
|
||||||
|
for i := 0; i < len(accountAndSubAccounts); i++ {
|
||||||
|
subAccount := accountAndSubAccounts[i]
|
||||||
|
|
||||||
|
if subAccount.AccountId == mainAccount.AccountId {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, exists := newSubAccountIds[subAccount.AccountId]; !exists {
|
||||||
|
toDeleteAccountIds = append(toDeleteAccountIds, subAccount.AccountId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toDeleteAccountIds
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ type DuplicateCheckerType uint8
|
|||||||
const (
|
const (
|
||||||
DUPLICATE_CHECKER_TYPE_BACKGROUND_CRON_JOB DuplicateCheckerType = 0
|
DUPLICATE_CHECKER_TYPE_BACKGROUND_CRON_JOB DuplicateCheckerType = 0
|
||||||
DUPLICATE_CHECKER_TYPE_NEW_ACCOUNT DuplicateCheckerType = 1
|
DUPLICATE_CHECKER_TYPE_NEW_ACCOUNT DuplicateCheckerType = 1
|
||||||
DUPLICATE_CHECKER_TYPE_NEW_CATEGORY DuplicateCheckerType = 2
|
DUPLICATE_CHECKER_TYPE_NEW_SUBACCOUNT DuplicateCheckerType = 2
|
||||||
DUPLICATE_CHECKER_TYPE_NEW_TRANSACTION DuplicateCheckerType = 3
|
DUPLICATE_CHECKER_TYPE_NEW_CATEGORY DuplicateCheckerType = 3
|
||||||
DUPLICATE_CHECKER_TYPE_NEW_TEMPLATE DuplicateCheckerType = 4
|
DUPLICATE_CHECKER_TYPE_NEW_TRANSACTION DuplicateCheckerType = 4
|
||||||
DUPLICATE_CHECKER_TYPE_NEW_PICTURE DuplicateCheckerType = 5
|
DUPLICATE_CHECKER_TYPE_NEW_TEMPLATE DuplicateCheckerType = 5
|
||||||
DUPLICATE_CHECKER_TYPE_IMPORT_TRANSACTIONS DuplicateCheckerType = 6
|
DUPLICATE_CHECKER_TYPE_NEW_PICTURE DuplicateCheckerType = 6
|
||||||
|
DUPLICATE_CHECKER_TYPE_IMPORT_TRANSACTIONS DuplicateCheckerType = 7
|
||||||
DUPLICATE_CHECKER_TYPE_FAILURE_CHECK DuplicateCheckerType = 255
|
DUPLICATE_CHECKER_TYPE_FAILURE_CHECK DuplicateCheckerType = 255
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-1
@@ -14,7 +14,6 @@ var (
|
|||||||
ErrParentAccountCannotSetBalance = NewNormalError(NormalSubcategoryAccount, 7, http.StatusBadRequest, "parent account cannot set balance")
|
ErrParentAccountCannotSetBalance = NewNormalError(NormalSubcategoryAccount, 7, http.StatusBadRequest, "parent account cannot set balance")
|
||||||
ErrSubAccountCategoryNotEqualsToParent = NewNormalError(NormalSubcategoryAccount, 8, http.StatusBadRequest, "sub-account category not equals to parent")
|
ErrSubAccountCategoryNotEqualsToParent = NewNormalError(NormalSubcategoryAccount, 8, http.StatusBadRequest, "sub-account category not equals to parent")
|
||||||
ErrSubAccountTypeInvalid = NewNormalError(NormalSubcategoryAccount, 9, http.StatusBadRequest, "sub-account type invalid")
|
ErrSubAccountTypeInvalid = NewNormalError(NormalSubcategoryAccount, 9, http.StatusBadRequest, "sub-account type invalid")
|
||||||
ErrCannotAddOrDeleteSubAccountsWhenModify = NewNormalError(NormalSubcategoryAccount, 10, http.StatusBadRequest, "cannot add or delete sub-accounts when modify account")
|
|
||||||
ErrSourceAccountNotFound = NewNormalError(NormalSubcategoryAccount, 11, http.StatusBadRequest, "source account not found")
|
ErrSourceAccountNotFound = NewNormalError(NormalSubcategoryAccount, 11, http.StatusBadRequest, "source account not found")
|
||||||
ErrDestinationAccountNotFound = NewNormalError(NormalSubcategoryAccount, 12, http.StatusBadRequest, "destination account not found")
|
ErrDestinationAccountNotFound = NewNormalError(NormalSubcategoryAccount, 12, http.StatusBadRequest, "destination account not found")
|
||||||
ErrAccountInUseCannotBeDeleted = NewNormalError(NormalSubcategoryAccount, 13, http.StatusBadRequest, "account is in use and cannot be deleted")
|
ErrAccountInUseCannotBeDeleted = NewNormalError(NormalSubcategoryAccount, 13, http.StatusBadRequest, "account is in use and cannot be deleted")
|
||||||
@@ -24,4 +23,7 @@ var (
|
|||||||
ErrCannotSetStatementDateForSubAccount = NewNormalError(NormalSubcategoryAccount, 17, http.StatusBadRequest, "cannot set statement date for sub account")
|
ErrCannotSetStatementDateForSubAccount = NewNormalError(NormalSubcategoryAccount, 17, http.StatusBadRequest, "cannot set statement date for sub account")
|
||||||
ErrSubAccountNotFound = NewNormalError(NormalSubcategoryAccount, 18, http.StatusBadRequest, "sub-account not found")
|
ErrSubAccountNotFound = NewNormalError(NormalSubcategoryAccount, 18, http.StatusBadRequest, "sub-account not found")
|
||||||
ErrSubAccountInUseCannotBeDeleted = NewNormalError(NormalSubcategoryAccount, 19, http.StatusBadRequest, "sub-account is in use and cannot be deleted")
|
ErrSubAccountInUseCannotBeDeleted = NewNormalError(NormalSubcategoryAccount, 19, http.StatusBadRequest, "sub-account is in use and cannot be deleted")
|
||||||
|
ErrNotSupportedChangeCurrency = NewNormalError(NormalSubcategoryAccount, 20, http.StatusBadRequest, "not supported to modify account currency")
|
||||||
|
ErrNotSupportedChangeBalance = NewNormalError(NormalSubcategoryAccount, 21, http.StatusBadRequest, "not supported to modify account balance")
|
||||||
|
ErrNotSupportedChangeBalanceTime = NewNormalError(NormalSubcategoryAccount, 22, http.StatusBadRequest, "not supported to modify account balance time")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -101,15 +101,19 @@ type AccountCreateRequest struct {
|
|||||||
|
|
||||||
// AccountModifyRequest represents all parameters of account modification request
|
// AccountModifyRequest represents all parameters of account modification request
|
||||||
type AccountModifyRequest struct {
|
type AccountModifyRequest struct {
|
||||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
Id int64 `json:"id,string" binding:"required,min=0"`
|
||||||
Name string `json:"name" binding:"required,notBlank,max=64"`
|
Name string `json:"name" binding:"required,notBlank,max=64"`
|
||||||
Category AccountCategory `json:"category" binding:"required"`
|
Category AccountCategory `json:"category" binding:"required"`
|
||||||
Icon int64 `json:"icon,string" binding:"min=1"`
|
Icon int64 `json:"icon,string" binding:"min=1"`
|
||||||
Color string `json:"color" binding:"required,len=6,validHexRGBColor"`
|
Color string `json:"color" binding:"required,len=6,validHexRGBColor"`
|
||||||
|
Currency *string `json:"currency" binding:"omitempty,len=3,validCurrency"`
|
||||||
|
Balance *int64 `json:"balance" binding:"omitempty"`
|
||||||
|
BalanceTime *int64 `json:"balanceTime" binding:"omitempty"`
|
||||||
Comment string `json:"comment" binding:"max=255"`
|
Comment string `json:"comment" binding:"max=255"`
|
||||||
CreditCardStatementDate int `json:"creditCardStatementDate" binding:"min=0,max=28"`
|
CreditCardStatementDate int `json:"creditCardStatementDate" binding:"min=0,max=28"`
|
||||||
Hidden bool `json:"hidden"`
|
Hidden bool `json:"hidden"`
|
||||||
SubAccounts []*AccountModifyRequest `json:"subAccounts" binding:"omitempty"`
|
SubAccounts []*AccountModifyRequest `json:"subAccounts" binding:"omitempty"`
|
||||||
|
ClientSessionId string `json:"clientSessionId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccountListRequest represents all parameters of account listing request
|
// AccountListRequest represents all parameters of account listing request
|
||||||
|
|||||||
+192
-8
@@ -334,21 +334,81 @@ func (s *AccountService) CreateAccounts(c core.Context, mainAccount *models.Acco
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ModifyAccounts saves an existed account model to database
|
// ModifyAccounts saves an existed account model to database
|
||||||
func (s *AccountService) ModifyAccounts(c core.Context, uid int64, accounts []*models.Account) error {
|
func (s *AccountService) ModifyAccounts(c core.Context, mainAccount *models.Account, updateAccounts []*models.Account, addSubAccounts []*models.Account, addSubAccountBalanceTimes []int64, removeSubAccountIds []int64, utcOffset int16) error {
|
||||||
if uid <= 0 {
|
if mainAccount.Uid <= 0 {
|
||||||
return errs.ErrUserIdInvalid
|
return errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needAccountUuidCount := uint16(len(addSubAccounts))
|
||||||
|
newAccountUuids := s.GenerateUuids(uuid.UUID_TYPE_ACCOUNT, needAccountUuidCount)
|
||||||
|
|
||||||
|
if len(newAccountUuids) < int(needAccountUuidCount) {
|
||||||
|
return errs.ErrSystemIsBusy
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
for i := 0; i < len(accounts); i++ {
|
var addInitTransactions []*models.Transaction
|
||||||
accounts[i].UpdatedUnixTime = now
|
|
||||||
|
for i := 0; i < len(updateAccounts); i++ {
|
||||||
|
updateAccounts[i].UpdatedUnixTime = now
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.UserDataDB(uid).DoTransaction(c, func(sess *xorm.Session) error {
|
if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS {
|
||||||
for i := 0; i < len(accounts); i++ {
|
defaultTransactionTime := utils.GetMinTransactionTimeFromUnixTime(now)
|
||||||
account := accounts[i]
|
|
||||||
updatedRows, err := sess.ID(account.AccountId).Cols("name", "category", "icon", "color", "comment", "extend", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", uid, false).Update(account)
|
for i := 0; i < len(addSubAccounts); i++ {
|
||||||
|
childAccount := addSubAccounts[i]
|
||||||
|
childAccount.AccountId = newAccountUuids[i]
|
||||||
|
childAccount.ParentAccountId = mainAccount.AccountId
|
||||||
|
childAccount.Uid = mainAccount.Uid
|
||||||
|
childAccount.Type = models.ACCOUNT_TYPE_SINGLE_ACCOUNT
|
||||||
|
childAccount.Deleted = false
|
||||||
|
childAccount.CreatedUnixTime = now
|
||||||
|
childAccount.UpdatedUnixTime = now
|
||||||
|
|
||||||
|
if childAccount.Balance != 0 {
|
||||||
|
transactionId := s.GenerateUuid(uuid.UUID_TYPE_TRANSACTION)
|
||||||
|
|
||||||
|
if transactionId < 1 {
|
||||||
|
return errs.ErrSystemIsBusy
|
||||||
|
}
|
||||||
|
|
||||||
|
transactionTime := defaultTransactionTime
|
||||||
|
|
||||||
|
if len(addSubAccountBalanceTimes) > i && addSubAccountBalanceTimes[i] > 0 {
|
||||||
|
transactionTime = utils.GetMinTransactionTimeFromUnixTime(addSubAccountBalanceTimes[i])
|
||||||
|
} else {
|
||||||
|
defaultTransactionTime++
|
||||||
|
}
|
||||||
|
|
||||||
|
newTransaction := &models.Transaction{
|
||||||
|
TransactionId: transactionId,
|
||||||
|
Uid: childAccount.Uid,
|
||||||
|
Deleted: false,
|
||||||
|
Type: models.TRANSACTION_DB_TYPE_MODIFY_BALANCE,
|
||||||
|
TransactionTime: transactionTime,
|
||||||
|
TimezoneUtcOffset: utcOffset,
|
||||||
|
AccountId: childAccount.AccountId,
|
||||||
|
Amount: childAccount.Balance,
|
||||||
|
RelatedAccountId: childAccount.AccountId,
|
||||||
|
RelatedAccountAmount: childAccount.Balance,
|
||||||
|
CreatedUnixTime: now,
|
||||||
|
UpdatedUnixTime: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
addInitTransactions = append(addInitTransactions, newTransaction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
userDataDb := s.UserDataDB(mainAccount.Uid)
|
||||||
|
|
||||||
|
return userDataDb.DoTransaction(c, func(sess *xorm.Session) error {
|
||||||
|
// update accounts
|
||||||
|
for i := 0; i < len(updateAccounts); i++ {
|
||||||
|
account := updateAccounts[i]
|
||||||
|
updatedRows, err := sess.ID(account.AccountId).Cols("name", "category", "icon", "color", "comment", "extend", "hidden", "updated_unix_time").Where("uid=? AND deleted=?", account.Uid, false).Update(account)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -357,6 +417,130 @@ func (s *AccountService) ModifyAccounts(c core.Context, uid int64, accounts []*m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add new sub accounts
|
||||||
|
for i := 0; i < len(addSubAccounts); i++ {
|
||||||
|
account := addSubAccounts[i]
|
||||||
|
_, err := sess.Insert(account)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add init transaction for new sub accounts
|
||||||
|
for i := 0; i < len(addInitTransactions); i++ {
|
||||||
|
transaction := addInitTransactions[i]
|
||||||
|
|
||||||
|
insertTransactionSavePointName := "insert_transaction"
|
||||||
|
err := userDataDb.SetSavePoint(sess, insertTransactionSavePointName)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf(c, "[accounts.ModifyAccounts] failed to set save point \"%s\", because %s", insertTransactionSavePointName, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
createdRows, err := sess.Insert(transaction)
|
||||||
|
|
||||||
|
if err != nil || createdRows < 1 { // maybe another transaction has same time
|
||||||
|
err = userDataDb.RollbackToSavePoint(sess, insertTransactionSavePointName)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf(c, "[accounts.ModifyAccounts] failed to rollback to save point \"%s\", because %s", insertTransactionSavePointName, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
sameSecondLatestTransaction := &models.Transaction{}
|
||||||
|
minTransactionTime := utils.GetMinTransactionTimeFromUnixTime(utils.GetUnixTimeFromTransactionTime(transaction.TransactionTime))
|
||||||
|
maxTransactionTime := utils.GetMaxTransactionTimeFromUnixTime(utils.GetUnixTimeFromTransactionTime(transaction.TransactionTime))
|
||||||
|
|
||||||
|
has, err := sess.Where("uid=? AND transaction_time>=? AND transaction_time<=?", transaction.Uid, minTransactionTime, maxTransactionTime).OrderBy("transaction_time desc").Limit(1).Get(sameSecondLatestTransaction)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if !has {
|
||||||
|
return errs.ErrDatabaseOperationFailed
|
||||||
|
} else if sameSecondLatestTransaction.TransactionTime == maxTransactionTime-1 {
|
||||||
|
return errs.ErrTooMuchTransactionInOneSecond
|
||||||
|
}
|
||||||
|
|
||||||
|
transaction.TransactionTime = sameSecondLatestTransaction.TransactionTime + 1
|
||||||
|
createdRows, err := sess.Insert(transaction)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if createdRows < 1 {
|
||||||
|
return errs.ErrDatabaseOperationFailed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove sub accounts
|
||||||
|
if len(removeSubAccountIds) > 0 {
|
||||||
|
subAccountsCount, err := sess.Where("uid=? AND deleted=? AND parent_account_id=?", mainAccount.Uid, false, mainAccount.AccountId).Count(&models.Account{})
|
||||||
|
|
||||||
|
if subAccountsCount <= int64(len(removeSubAccountIds)) {
|
||||||
|
return errs.ErrAccountHaveNoSubAccount
|
||||||
|
}
|
||||||
|
|
||||||
|
var relatedTransactionsByAccount []*models.Transaction
|
||||||
|
err = sess.Cols("transaction_id", "uid", "deleted", "account_id", "type").Where("uid=? AND deleted=?", mainAccount.Uid, false).In("account_id", removeSubAccountIds).Limit(len(removeSubAccountIds) + 1).Find(&relatedTransactionsByAccount)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if len(relatedTransactionsByAccount) > len(removeSubAccountIds) {
|
||||||
|
return errs.ErrSubAccountInUseCannotBeDeleted
|
||||||
|
} else if len(relatedTransactionsByAccount) > 0 {
|
||||||
|
accountTransactionExists := make(map[int64]bool)
|
||||||
|
|
||||||
|
for i := 0; i < len(relatedTransactionsByAccount); i++ {
|
||||||
|
transaction := relatedTransactionsByAccount[i]
|
||||||
|
|
||||||
|
if transaction.Type != models.TRANSACTION_DB_TYPE_MODIFY_BALANCE {
|
||||||
|
return errs.ErrAccountInUseCannotBeDeleted
|
||||||
|
} else if _, exists := accountTransactionExists[transaction.AccountId]; exists {
|
||||||
|
return errs.ErrAccountInUseCannotBeDeleted
|
||||||
|
}
|
||||||
|
|
||||||
|
accountTransactionExists[transaction.AccountId] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAccountUpdateModel := &models.Account{
|
||||||
|
Balance: 0,
|
||||||
|
Deleted: true,
|
||||||
|
DeletedUnixTime: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
deletedRows, err := sess.Cols("balance", "deleted", "deleted_unix_time").Where("uid=? AND deleted=?", mainAccount.Uid, false).In("account_id", removeSubAccountIds).Update(deleteAccountUpdateModel)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if deletedRows < 1 {
|
||||||
|
return errs.ErrSubAccountNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(relatedTransactionsByAccount) > 0 {
|
||||||
|
updateTransaction := &models.Transaction{
|
||||||
|
Deleted: true,
|
||||||
|
DeletedUnixTime: now,
|
||||||
|
}
|
||||||
|
|
||||||
|
transactionIds := make([]int64, len(relatedTransactionsByAccount))
|
||||||
|
|
||||||
|
for i := 0; i < len(relatedTransactionsByAccount); i++ {
|
||||||
|
transactionIds[i] = relatedTransactionsByAccount[i].TransactionId
|
||||||
|
}
|
||||||
|
|
||||||
|
deletedTransactionRows, err := sess.Cols("deleted", "deleted_unix_time").Where("uid=? AND deleted=?", mainAccount.Uid, false).In("transaction_id", transactionIds).Update(updateTransaction)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
} else if deletedTransactionRows < int64(len(transactionIds)) {
|
||||||
|
return errs.ErrDatabaseOperationFailed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "Übergeordnetes Konto kann keinen Saldo festlegen",
|
"parent account cannot set balance": "Übergeordnetes Konto kann keinen Saldo festlegen",
|
||||||
"sub-account category not equals to parent": "Teilkonto-Kategorie entspricht nicht der übergeordneten Kategorie",
|
"sub-account category not equals to parent": "Teilkonto-Kategorie entspricht nicht der übergeordneten Kategorie",
|
||||||
"sub-account type invalid": "Teilkontotyp ist ungültig",
|
"sub-account type invalid": "Teilkontotyp ist ungültig",
|
||||||
"cannot add or delete sub-accounts when modify account": "Unterkonten können beim Ändern des Kontos nicht hinzugefügt oder gelöscht werden",
|
|
||||||
"source account not found": "Quellkonto nicht gefunden",
|
"source account not found": "Quellkonto nicht gefunden",
|
||||||
"destination account not found": "Zielkonto nicht gefunden",
|
"destination account not found": "Zielkonto nicht gefunden",
|
||||||
"account is in use and cannot be deleted": "Konto wird verwendet und kann nicht gelöscht werden",
|
"account is in use and cannot be deleted": "Konto wird verwendet und kann nicht gelöscht werden",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "Abrechnungsdatum kann für Teilkonto nicht festgelegt werden",
|
"cannot set statement date for sub account": "Abrechnungsdatum kann für Teilkonto nicht festgelegt werden",
|
||||||
"sub-account not found": "Sub-account is not found",
|
"sub-account not found": "Sub-account is not found",
|
||||||
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "Transaktions-ID ist ungültig",
|
"transaction id is invalid": "Transaktions-ID ist ungültig",
|
||||||
"transaction not found": "Transaktion nicht gefunden",
|
"transaction not found": "Transaktion nicht gefunden",
|
||||||
"transaction type is invalid": "Transaktionstyp ist ungültig",
|
"transaction type is invalid": "Transaktionstyp ist ungültig",
|
||||||
|
|||||||
+3
-1
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "Parent account cannot set balance",
|
"parent account cannot set balance": "Parent account cannot set balance",
|
||||||
"sub-account category not equals to parent": "Sub-account category does not equal to parent",
|
"sub-account category not equals to parent": "Sub-account category does not equal to parent",
|
||||||
"sub-account type invalid": "Sub-account type is invalid",
|
"sub-account type invalid": "Sub-account type is invalid",
|
||||||
"cannot add or delete sub-accounts when modify account": "You cannot add or delete sub-accounts when modify account",
|
|
||||||
"source account not found": "Source account is not found",
|
"source account not found": "Source account is not found",
|
||||||
"destination account not found": "Destination account is not found",
|
"destination account not found": "Destination account is not found",
|
||||||
"account is in use and cannot be deleted": "Account is in use and it cannot be deleted",
|
"account is in use and cannot be deleted": "Account is in use and it cannot be deleted",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "Cannot set statement date for sub-account",
|
"cannot set statement date for sub account": "Cannot set statement date for sub-account",
|
||||||
"sub-account not found": "Sub-account is not found",
|
"sub-account not found": "Sub-account is not found",
|
||||||
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "Transaction ID is invalid",
|
"transaction id is invalid": "Transaction ID is invalid",
|
||||||
"transaction not found": "Transaction is not found",
|
"transaction not found": "Transaction is not found",
|
||||||
"transaction type is invalid": "Transaction type is invalid",
|
"transaction type is invalid": "Transaction type is invalid",
|
||||||
|
|||||||
+3
-1
@@ -1062,7 +1062,6 @@
|
|||||||
"parent account cannot set balance": "La cuenta principal no puede establecer el saldo",
|
"parent account cannot set balance": "La cuenta principal no puede establecer el saldo",
|
||||||
"sub-account category not equals to parent": "La categoría de subcuenta no es igual a la principal",
|
"sub-account category not equals to parent": "La categoría de subcuenta no es igual a la principal",
|
||||||
"sub-account type invalid": "El tipo de subcuenta no es válido",
|
"sub-account type invalid": "El tipo de subcuenta no es válido",
|
||||||
"cannot add or delete sub-accounts when modify account": "No puede agregar ni eliminar subcuentas cuando modifica la cuenta",
|
|
||||||
"source account not found": "No se encuentra la cuenta de origen",
|
"source account not found": "No se encuentra la cuenta de origen",
|
||||||
"destination account not found": "No se encuentra la cuenta de destino",
|
"destination account not found": "No se encuentra la cuenta de destino",
|
||||||
"account is in use and cannot be deleted": "La cuenta está en uso y no se puede eliminar",
|
"account is in use and cannot be deleted": "La cuenta está en uso y no se puede eliminar",
|
||||||
@@ -1072,6 +1071,9 @@
|
|||||||
"cannot set statement date for sub account": "No se puede establecer la fecha del estado de cuenta para la subcuenta",
|
"cannot set statement date for sub account": "No se puede establecer la fecha del estado de cuenta para la subcuenta",
|
||||||
"sub-account not found": "Sub-account is not found",
|
"sub-account not found": "Sub-account is not found",
|
||||||
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "El ID de transacción no es válido",
|
"transaction id is invalid": "El ID de transacción no es válido",
|
||||||
"transaction not found": "La transacción no se encuentra",
|
"transaction not found": "La transacción no se encuentra",
|
||||||
"transaction type is invalid": "El tipo de transacción no es válido",
|
"transaction type is invalid": "El tipo de transacción no es válido",
|
||||||
|
|||||||
+3
-1
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "Il conto principale non può impostare il saldo",
|
"parent account cannot set balance": "Il conto principale non può impostare il saldo",
|
||||||
"sub-account category not equals to parent": "La categoria del sotto-conto non corrisponde a quella principale",
|
"sub-account category not equals to parent": "La categoria del sotto-conto non corrisponde a quella principale",
|
||||||
"sub-account type invalid": "Tipo di sotto-conto non valido",
|
"sub-account type invalid": "Tipo di sotto-conto non valido",
|
||||||
"cannot add or delete sub-accounts when modify account": "Non è possibile aggiungere o eliminare sotto-conti durante la modifica del conto",
|
|
||||||
"source account not found": "Conto di origine non trovato",
|
"source account not found": "Conto di origine non trovato",
|
||||||
"destination account not found": "Conto di destinazione non trovato",
|
"destination account not found": "Conto di destinazione non trovato",
|
||||||
"account is in use and cannot be deleted": "Il conto è in uso e non può essere eliminato",
|
"account is in use and cannot be deleted": "Il conto è in uso e non può essere eliminato",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "Impossibile impostare la data dell'estratto conto per un sotto-conto",
|
"cannot set statement date for sub account": "Impossibile impostare la data dell'estratto conto per un sotto-conto",
|
||||||
"sub-account not found": "Sotto-conto non trovato",
|
"sub-account not found": "Sotto-conto non trovato",
|
||||||
"sub-account is in use and cannot be deleted": "Il sotto-conto è in uso e non può essere eliminato",
|
"sub-account is in use and cannot be deleted": "Il sotto-conto è in uso e non può essere eliminato",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "ID transazione non valido",
|
"transaction id is invalid": "ID transazione non valido",
|
||||||
"transaction not found": "Transazione non trovata",
|
"transaction not found": "Transazione non trovata",
|
||||||
"transaction type is invalid": "Tipo di transazione non valido",
|
"transaction type is invalid": "Tipo di transazione non valido",
|
||||||
|
|||||||
+3
-1
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "親口座は残高を設定できません",
|
"parent account cannot set balance": "親口座は残高を設定できません",
|
||||||
"sub-account category not equals to parent": "子口座のカテゴリが親と一致しません",
|
"sub-account category not equals to parent": "子口座のカテゴリが親と一致しません",
|
||||||
"sub-account type invalid": "子口座タイプは無効です",
|
"sub-account type invalid": "子口座タイプは無効です",
|
||||||
"cannot add or delete sub-accounts when modify account": "口座を変更するときに子口座を追加または削除できません",
|
|
||||||
"source account not found": "元口座が見つかりません",
|
"source account not found": "元口座が見つかりません",
|
||||||
"destination account not found": "宛先口座が見つかりません",
|
"destination account not found": "宛先口座が見つかりません",
|
||||||
"account is in use and cannot be deleted": "支払い方法は使用されており削除できません",
|
"account is in use and cannot be deleted": "支払い方法は使用されており削除できません",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "子口座の明細日を設定できません",
|
"cannot set statement date for sub account": "子口座の明細日を設定できません",
|
||||||
"sub-account not found": "Sub-account is not found",
|
"sub-account not found": "Sub-account is not found",
|
||||||
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "取引IDは無効です",
|
"transaction id is invalid": "取引IDは無効です",
|
||||||
"transaction not found": "取引が見つかりません",
|
"transaction not found": "取引が見つかりません",
|
||||||
"transaction type is invalid": "取引タイプは無効です",
|
"transaction type is invalid": "取引タイプは無効です",
|
||||||
|
|||||||
+3
-1
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "Родительский счет не может устанавливать баланс",
|
"parent account cannot set balance": "Родительский счет не может устанавливать баланс",
|
||||||
"sub-account category not equals to parent": "Категория субсчета не совпадает с родительской",
|
"sub-account category not equals to parent": "Категория субсчета не совпадает с родительской",
|
||||||
"sub-account type invalid": "Тип субсчета недействителен",
|
"sub-account type invalid": "Тип субсчета недействителен",
|
||||||
"cannot add or delete sub-accounts when modify account": "Нельзя добавлять или удалять субсчета при изменении счета",
|
|
||||||
"source account not found": "Исходный счет не найден",
|
"source account not found": "Исходный счет не найден",
|
||||||
"destination account not found": "Счет назначения не найден",
|
"destination account not found": "Счет назначения не найден",
|
||||||
"account is in use and cannot be deleted": "Счет используется и не может быть удален",
|
"account is in use and cannot be deleted": "Счет используется и не может быть удален",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "Нельзя установить дату выписки для субсчета",
|
"cannot set statement date for sub account": "Нельзя установить дату выписки для субсчета",
|
||||||
"sub-account not found": "Sub-account is not found",
|
"sub-account not found": "Sub-account is not found",
|
||||||
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "ID транзакции недействителен",
|
"transaction id is invalid": "ID транзакции недействителен",
|
||||||
"transaction not found": "Транзакция не найдена",
|
"transaction not found": "Транзакция не найдена",
|
||||||
"transaction type is invalid": "Тип транзакции недействителен",
|
"transaction type is invalid": "Тип транзакции недействителен",
|
||||||
|
|||||||
+3
-1
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "Батьківський рахунок не може встановити баланс",
|
"parent account cannot set balance": "Батьківський рахунок не може встановити баланс",
|
||||||
"sub-account category not equals to parent": "Категорія субрахунку не збігається з батьківською",
|
"sub-account category not equals to parent": "Категорія субрахунку не збігається з батьківською",
|
||||||
"sub-account type invalid": "Тип субрахунку недійсний",
|
"sub-account type invalid": "Тип субрахунку недійсний",
|
||||||
"cannot add or delete sub-accounts when modify account": "Неможливо додати або видалити субрахунки при зміні рахунку",
|
|
||||||
"source account not found": "Вихідний рахунок не знайдено",
|
"source account not found": "Вихідний рахунок не знайдено",
|
||||||
"destination account not found": "Рахунок призначення не знайдено",
|
"destination account not found": "Рахунок призначення не знайдено",
|
||||||
"account is in use and cannot be deleted": "Рахунок використовується і не може бути видалений",
|
"account is in use and cannot be deleted": "Рахунок використовується і не може бути видалений",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "Неможливо встановити дату виписки для субрахунку",
|
"cannot set statement date for sub account": "Неможливо встановити дату виписки для субрахунку",
|
||||||
"sub-account not found": "Субрахунок не знайдено",
|
"sub-account not found": "Субрахунок не знайдено",
|
||||||
"sub-account is in use and cannot be deleted": "Субрахунок використовується і не може бути видалений",
|
"sub-account is in use and cannot be deleted": "Субрахунок використовується і не може бути видалений",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "ID транзакції недійсний",
|
"transaction id is invalid": "ID транзакції недійсний",
|
||||||
"transaction not found": "Транзакцію не знайдено",
|
"transaction not found": "Транзакцію не знайдено",
|
||||||
"transaction type is invalid": "Тип транзакції недійсний",
|
"transaction type is invalid": "Тип транзакції недійсний",
|
||||||
|
|||||||
+3
-1
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "Tài khoản cha không thể đặt số dư",
|
"parent account cannot set balance": "Tài khoản cha không thể đặt số dư",
|
||||||
"sub-account category not equals to parent": "Danh mục tài khoản phụ không bằng tài khoản cha",
|
"sub-account category not equals to parent": "Danh mục tài khoản phụ không bằng tài khoản cha",
|
||||||
"sub-account type invalid": "Loại tài khoản phụ không hợp lệ",
|
"sub-account type invalid": "Loại tài khoản phụ không hợp lệ",
|
||||||
"cannot add or delete sub-accounts when modify account": "Bạn không thể thêm hoặc xóa tài khoản phụ khi sửa đổi tài khoản",
|
|
||||||
"source account not found": "Không tìm thấy tài khoản nguồn",
|
"source account not found": "Không tìm thấy tài khoản nguồn",
|
||||||
"destination account not found": "Không tìm thấy tài khoản đích",
|
"destination account not found": "Không tìm thấy tài khoản đích",
|
||||||
"account is in use and cannot be deleted": "Tài khoản đang được sử dụng và không thể xóa",
|
"account is in use and cannot be deleted": "Tài khoản đang được sử dụng và không thể xóa",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "Cannot set statement date for sub-account",
|
"cannot set statement date for sub account": "Cannot set statement date for sub-account",
|
||||||
"sub-account not found": "Sub-account is not found",
|
"sub-account not found": "Sub-account is not found",
|
||||||
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
"sub-account is in use and cannot be deleted": "Sub-account is in use and it cannot be deleted",
|
||||||
|
"not supported to modify account currency": "Not supported to modify account currency",
|
||||||
|
"not supported to modify account balance": "Not supported to modify account balance",
|
||||||
|
"not supported to modify account balance time": "Not supported to modify account balance time",
|
||||||
"transaction id is invalid": "ID giao dịch không hợp lệ",
|
"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 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ệ",
|
"transaction type is invalid": "Loại giao dịch không hợp lệ",
|
||||||
|
|||||||
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "父账户不能设置余额",
|
"parent account cannot set balance": "父账户不能设置余额",
|
||||||
"sub-account category not equals to parent": "子账户类别与父账户不同",
|
"sub-account category not equals to parent": "子账户类别与父账户不同",
|
||||||
"sub-account type invalid": "子账户类型无效",
|
"sub-account type invalid": "子账户类型无效",
|
||||||
"cannot add or delete sub-accounts when modify account": "您不能在修改账户时添加或删除子账户",
|
|
||||||
"source account not found": "来源账户不存在",
|
"source account not found": "来源账户不存在",
|
||||||
"destination account not found": "目标账户不存在",
|
"destination account not found": "目标账户不存在",
|
||||||
"account is in use and cannot be deleted": "账户正在被使用,无法删除",
|
"account is in use and cannot be deleted": "账户正在被使用,无法删除",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "子账户不能设置账单日期",
|
"cannot set statement date for sub account": "子账户不能设置账单日期",
|
||||||
"sub-account not found": "子账户不存在",
|
"sub-account not found": "子账户不存在",
|
||||||
"sub-account is in use and cannot be deleted": "子账户正在被使用,无法删除",
|
"sub-account is in use and cannot be deleted": "子账户正在被使用,无法删除",
|
||||||
|
"not supported to modify account currency": "不支持修改账户货币",
|
||||||
|
"not supported to modify account balance": "不支持修改账户余额",
|
||||||
|
"not supported to modify account balance time": "不支持修改账户余额时间",
|
||||||
"transaction id is invalid": "交易ID无效",
|
"transaction id is invalid": "交易ID无效",
|
||||||
"transaction not found": "交易不存在",
|
"transaction not found": "交易不存在",
|
||||||
"transaction type is invalid": "交易类型无效",
|
"transaction type is invalid": "交易类型无效",
|
||||||
|
|||||||
@@ -1063,7 +1063,6 @@
|
|||||||
"parent account cannot set balance": "父帳戶不能設定餘額",
|
"parent account cannot set balance": "父帳戶不能設定餘額",
|
||||||
"sub-account category not equals to parent": "子帳戶類別與父帳戶不同",
|
"sub-account category not equals to parent": "子帳戶類別與父帳戶不同",
|
||||||
"sub-account type invalid": "子帳戶類型無效",
|
"sub-account type invalid": "子帳戶類型無效",
|
||||||
"cannot add or delete sub-accounts when modify account": "您不能在修改帳戶時新增或刪除子帳戶",
|
|
||||||
"source account not found": "來源帳戶不存在",
|
"source account not found": "來源帳戶不存在",
|
||||||
"destination account not found": "目標帳戶不存在",
|
"destination account not found": "目標帳戶不存在",
|
||||||
"account is in use and cannot be deleted": "帳戶正在被使用,無法刪除",
|
"account is in use and cannot be deleted": "帳戶正在被使用,無法刪除",
|
||||||
@@ -1073,6 +1072,9 @@
|
|||||||
"cannot set statement date for sub account": "子帳戶不能設定帳單日期",
|
"cannot set statement date for sub account": "子帳戶不能設定帳單日期",
|
||||||
"sub-account not found": "子帳戶不存在",
|
"sub-account not found": "子帳戶不存在",
|
||||||
"sub-account is in use and cannot be deleted": "子帳戶正在被使用,無法刪除",
|
"sub-account is in use and cannot be deleted": "子帳戶正在被使用,無法刪除",
|
||||||
|
"not supported to modify account currency": "不支援修改帳戶貨幣",
|
||||||
|
"not supported to modify account balance": "不支援修改帳戶餘額",
|
||||||
|
"not supported to modify account balance time": "不支援修改帳戶餘額時間",
|
||||||
"transaction id is invalid": "交易ID無效",
|
"transaction id is invalid": "交易ID無效",
|
||||||
"transaction not found": "交易不存在",
|
"transaction not found": "交易不存在",
|
||||||
"transaction type is invalid": "交易類型無效",
|
"transaction type is invalid": "交易類型無效",
|
||||||
|
|||||||
+11
-3
@@ -186,7 +186,7 @@ export class Account implements AccountInfoResponse {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public toModifyRequest(subAccounts?: Account[], parentAccount?: Account): AccountModifyRequest {
|
public toModifyRequest(clientSessionId: string, subAccounts?: Account[], parentAccount?: Account): AccountModifyRequest {
|
||||||
let subAccountModifyRequests: AccountModifyRequest[] | undefined = undefined;
|
let subAccountModifyRequests: AccountModifyRequest[] | undefined = undefined;
|
||||||
|
|
||||||
if (this.type === AccountType.MultiSubAccounts.type) {
|
if (this.type === AccountType.MultiSubAccounts.type) {
|
||||||
@@ -198,21 +198,25 @@ export class Account implements AccountInfoResponse {
|
|||||||
|
|
||||||
if (subAccounts) {
|
if (subAccounts) {
|
||||||
for (const subAccount of subAccounts) {
|
for (const subAccount of subAccounts) {
|
||||||
subAccountModifyRequests.push(subAccount.toModifyRequest(undefined, this));
|
subAccountModifyRequests.push(subAccount.toModifyRequest(clientSessionId, undefined, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id || '0',
|
||||||
name: this.name,
|
name: this.name,
|
||||||
category: parentAccount ? parentAccount.category : this.category,
|
category: parentAccount ? parentAccount.category : this.category,
|
||||||
icon: this.icon,
|
icon: this.icon,
|
||||||
color: this.color,
|
color: this.color,
|
||||||
|
currency: parentAccount && (!this.id || this.id === '0') ? this.currency : undefined,
|
||||||
|
balance: parentAccount && (!this.id || this.id === '0') ? this.balance : undefined,
|
||||||
|
balanceTime: parentAccount && (!this.id || this.id === '0') ? this.balanceTime : undefined,
|
||||||
comment: this.comment,
|
comment: this.comment,
|
||||||
creditCardStatementDate: !parentAccount && this.category === AccountCategory.CreditCard.type ? this.creditCardStatementDate : undefined,
|
creditCardStatementDate: !parentAccount && this.category === AccountCategory.CreditCard.type ? this.creditCardStatementDate : undefined,
|
||||||
hidden: !this.visible,
|
hidden: !this.visible,
|
||||||
subAccounts: !parentAccount ? subAccountModifyRequests : undefined,
|
subAccounts: !parentAccount ? subAccountModifyRequests : undefined,
|
||||||
|
clientSessionId: !parentAccount ? clientSessionId : undefined
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,10 +583,14 @@ export interface AccountModifyRequest {
|
|||||||
readonly category: number;
|
readonly category: number;
|
||||||
readonly icon: string;
|
readonly icon: string;
|
||||||
readonly color: string;
|
readonly color: string;
|
||||||
|
readonly currency?: string;
|
||||||
|
readonly balance?: number;
|
||||||
|
readonly balanceTime?: number;
|
||||||
readonly comment: string;
|
readonly comment: string;
|
||||||
readonly creditCardStatementDate?: number;
|
readonly creditCardStatementDate?: number;
|
||||||
readonly hidden: boolean;
|
readonly hidden: boolean;
|
||||||
readonly subAccounts?: AccountModifyRequest[];
|
readonly subAccounts?: AccountModifyRequest[];
|
||||||
|
readonly clientSessionId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AccountInfoResponse {
|
export interface AccountInfoResponse {
|
||||||
|
|||||||
+22
-13
@@ -185,29 +185,38 @@ export const useAccountsStore = defineStore('accounts', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateAccountToAccountList(account: Account): void {
|
function updateAccountToAccountList(oldAccount: Account, newAccount: Account): void {
|
||||||
for (let i = 0; i < allAccounts.value.length; i++) {
|
for (let i = 0; i < allAccounts.value.length; i++) {
|
||||||
if (allAccounts.value[i].id === account.id) {
|
if (allAccounts.value[i].id === newAccount.id) {
|
||||||
allAccounts.value.splice(i, 1, account);
|
allAccounts.value.splice(i, 1, newAccount);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allAccountsMap.value[account.id] = account;
|
if (oldAccount.subAccounts) {
|
||||||
|
for (let i = 0; i < oldAccount.subAccounts.length; i++) {
|
||||||
|
const subAccount = oldAccount.subAccounts[i];
|
||||||
|
if (allAccountsMap.value[subAccount.id]) {
|
||||||
|
delete allAccountsMap.value[subAccount.id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (account.subAccounts) {
|
allAccountsMap.value[newAccount.id] = newAccount;
|
||||||
for (let i = 0; i < account.subAccounts.length; i++) {
|
|
||||||
const subAccount = account.subAccounts[i];
|
if (newAccount.subAccounts) {
|
||||||
|
for (let i = 0; i < newAccount.subAccounts.length; i++) {
|
||||||
|
const subAccount = newAccount.subAccounts[i];
|
||||||
allAccountsMap.value[subAccount.id] = subAccount;
|
allAccountsMap.value[subAccount.id] = subAccount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allCategorizedAccountsMap.value[account.category]) {
|
if (allCategorizedAccountsMap.value[newAccount.category]) {
|
||||||
const accountList = allCategorizedAccountsMap.value[account.category].accounts;
|
const accountList = allCategorizedAccountsMap.value[newAccount.category].accounts;
|
||||||
|
|
||||||
for (let i = 0; i < accountList.length; i++) {
|
for (let i = 0; i < accountList.length; i++) {
|
||||||
if (accountList[i].id === account.id) {
|
if (accountList[i].id === newAccount.id) {
|
||||||
accountList.splice(i, 1, account);
|
accountList.splice(i, 1, newAccount);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -847,7 +856,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
|||||||
if (!isEdit) {
|
if (!isEdit) {
|
||||||
promise = services.addAccount(account.toCreateRequest(clientSessionId, subAccounts));
|
promise = services.addAccount(account.toCreateRequest(clientSessionId, subAccounts));
|
||||||
} else {
|
} else {
|
||||||
promise = services.modifyAccount(account.toModifyRequest(subAccounts));
|
promise = services.modifyAccount(account.toModifyRequest(clientSessionId, subAccounts));
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then(response => {
|
promise.then(response => {
|
||||||
@@ -868,7 +877,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
|||||||
addAccountToAccountList(newAccount);
|
addAccountToAccountList(newAccount);
|
||||||
} else {
|
} else {
|
||||||
if (oldAccount && oldAccount.category === newAccount.category) {
|
if (oldAccount && oldAccount.category === newAccount.category) {
|
||||||
updateAccountToAccountList(newAccount);
|
updateAccountToAccountList(oldAccount, newAccount);
|
||||||
} else {
|
} else {
|
||||||
updateAccountListInvalidState(true);
|
updateAccountListInvalidState(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ export function useAccountEditPageBaseBase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isNewAccount(account: Account): boolean {
|
||||||
|
return account.id === '' || account.id === '0';
|
||||||
|
}
|
||||||
|
|
||||||
function isInputEmpty(): boolean {
|
function isInputEmpty(): boolean {
|
||||||
const isAccountEmpty = !!getInputEmptyProblemMessage(account.value, false);
|
const isAccountEmpty = !!getInputEmptyProblemMessage(account.value, false);
|
||||||
|
|
||||||
@@ -172,6 +176,7 @@ export function useAccountEditPageBaseBase() {
|
|||||||
isAccountSupportCreditCardStatementDate,
|
isAccountSupportCreditCardStatementDate,
|
||||||
// functions
|
// functions
|
||||||
getAccountCreditCardStatementDate,
|
getAccountCreditCardStatementDate,
|
||||||
|
isNewAccount,
|
||||||
isInputEmpty,
|
isInputEmpty,
|
||||||
getAccountOrSubAccountProblemMessage,
|
getAccountOrSubAccountProblemMessage,
|
||||||
addSubAccount,
|
addSubAccount,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<v-progress-circular indeterminate size="22" class="ml-2" v-if="loading"></v-progress-circular>
|
<v-progress-circular indeterminate size="22" class="ml-2" v-if="loading"></v-progress-circular>
|
||||||
</div>
|
</div>
|
||||||
<v-btn density="comfortable" color="default" variant="text" class="ml-2" :icon="true"
|
<v-btn density="comfortable" color="default" variant="text" class="ml-2" :icon="true"
|
||||||
:disabled="loading || submitting || !!editAccountId || account.type !== AccountType.MultiSubAccounts.type">
|
:disabled="loading || submitting || account.type !== AccountType.MultiSubAccounts.type">
|
||||||
<v-icon :icon="mdiDotsVertical" />
|
<v-icon :icon="mdiDotsVertical" />
|
||||||
<v-menu activator="parent">
|
<v-menu activator="parent">
|
||||||
<v-list>
|
<v-list>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
<v-tab :key="idx" :value="idx" v-for="(subAccount, idx) in subAccounts">
|
<v-tab :key="idx" :value="idx" v-for="(subAccount, idx) in subAccounts">
|
||||||
<span>{{ tt('Sub Account') + ' #' + (idx + 1) }}</span>
|
<span>{{ tt('Sub Account') + ' #' + (idx + 1) }}</span>
|
||||||
<v-btn class="ml-2" color="error" size="24" variant="text"
|
<v-btn class="ml-2" color="error" size="24" variant="text"
|
||||||
:icon="mdiDeleteOutline" v-if="!editAccountId"
|
:icon="mdiDeleteOutline"
|
||||||
@click="removeSubAccount(subAccount)"></v-btn>
|
@click="removeSubAccount(subAccount)"></v-btn>
|
||||||
</v-tab>
|
</v-tab>
|
||||||
</template>
|
</template>
|
||||||
@@ -109,7 +109,7 @@
|
|||||||
v-model="selectedAccount.color" />
|
v-model="selectedAccount.color" />
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col cols="12" :md="currentAccountIndex < 0 && isAccountSupportCreditCardStatementDate ? 6 : 12" v-if="account.type === AccountType.SingleAccount.type || currentAccountIndex >= 0">
|
<v-col cols="12" :md="currentAccountIndex < 0 && isAccountSupportCreditCardStatementDate ? 6 : 12" v-if="account.type === AccountType.SingleAccount.type || currentAccountIndex >= 0">
|
||||||
<currency-select :disabled="loading || submitting || !!editAccountId"
|
<currency-select :disabled="loading || submitting || (!!editAccountId && !isNewAccount(selectedAccount))"
|
||||||
:label="tt('Currency')"
|
:label="tt('Currency')"
|
||||||
:placeholder="tt('Currency')"
|
:placeholder="tt('Currency')"
|
||||||
v-model="selectedAccount.currency" />
|
v-model="selectedAccount.currency" />
|
||||||
@@ -128,9 +128,9 @@
|
|||||||
v-model="account.creditCardStatementDate"
|
v-model="account.creditCardStatementDate"
|
||||||
></v-autocomplete>
|
></v-autocomplete>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col cols="12" :md="!editAccountId && selectedAccount.balance ? 6 : 12"
|
<v-col cols="12" :md="(!editAccountId || isNewAccount(selectedAccount)) && selectedAccount.balance ? 6 : 12"
|
||||||
v-if="account.type === AccountType.SingleAccount.type || currentAccountIndex >= 0">
|
v-if="account.type === AccountType.SingleAccount.type || currentAccountIndex >= 0">
|
||||||
<amount-input :disabled="loading || submitting || !!editAccountId"
|
<amount-input :disabled="loading || submitting || (!!editAccountId && !isNewAccount(selectedAccount))"
|
||||||
:persistent-placeholder="true"
|
:persistent-placeholder="true"
|
||||||
:currency="selectedAccount.currency"
|
:currency="selectedAccount.currency"
|
||||||
:show-currency="true"
|
:show-currency="true"
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
v-model="selectedAccount.balance"/>
|
v-model="selectedAccount.balance"/>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col cols="12" md="6" v-show="selectedAccount.balance"
|
<v-col cols="12" md="6" v-show="selectedAccount.balance"
|
||||||
v-if="!editAccountId && (account.type === AccountType.SingleAccount.type || currentAccountIndex >= 0)">
|
v-if="(!editAccountId || isNewAccount(selectedAccount)) && (account.type === AccountType.SingleAccount.type || currentAccountIndex >= 0)">
|
||||||
<date-time-select
|
<date-time-select
|
||||||
:disabled="loading || submitting"
|
:disabled="loading || submitting"
|
||||||
:label="tt('Balance Time')"
|
:label="tt('Balance Time')"
|
||||||
@@ -158,7 +158,7 @@
|
|||||||
v-model="selectedAccount.comment"
|
v-model="selectedAccount.comment"
|
||||||
/>
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col class="py-0" cols="12" md="12" v-if="editAccountId">
|
<v-col class="py-0" cols="12" md="12" v-if="editAccountId && !isNewAccount(selectedAccount)">
|
||||||
<v-switch :disabled="loading || submitting"
|
<v-switch :disabled="loading || submitting"
|
||||||
:label="tt('Visible')" v-model="selectedAccount.visible"/>
|
:label="tt('Visible')" v-model="selectedAccount.visible"/>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -236,6 +236,7 @@ const {
|
|||||||
allAccountTypes,
|
allAccountTypes,
|
||||||
allAvailableMonthDays,
|
allAvailableMonthDays,
|
||||||
isAccountSupportCreditCardStatementDate,
|
isAccountSupportCreditCardStatementDate,
|
||||||
|
isNewAccount,
|
||||||
isInputEmpty,
|
isInputEmpty,
|
||||||
getAccountOrSubAccountProblemMessage,
|
getAccountOrSubAccountProblemMessage,
|
||||||
addSubAccount,
|
addSubAccount,
|
||||||
@@ -288,6 +289,7 @@ function open(options?: { id?: string, currentAccount?: Account, category?: numb
|
|||||||
account.value.fillFrom(newAccount);
|
account.value.fillFrom(newAccount);
|
||||||
subAccounts.value = [];
|
subAccounts.value = [];
|
||||||
currentAccountIndex.value = -1;
|
currentAccountIndex.value = -1;
|
||||||
|
clientSessionId.value = generateRandomUUID();
|
||||||
|
|
||||||
if (options && options.id) {
|
if (options && options.id) {
|
||||||
if (options.currentAccount) {
|
if (options.currentAccount) {
|
||||||
@@ -317,7 +319,6 @@ function open(options?: { id?: string, currentAccount?: Account, category?: numb
|
|||||||
}
|
}
|
||||||
|
|
||||||
editAccountId.value = null;
|
editAccountId.value = null;
|
||||||
clientSessionId.value = generateRandomUUID();
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<f7-nav-left :back-link="tt('Back')"></f7-nav-left>
|
<f7-nav-left :back-link="tt('Back')"></f7-nav-left>
|
||||||
<f7-nav-title :title="tt(title)"></f7-nav-title>
|
<f7-nav-title :title="tt(title)"></f7-nav-title>
|
||||||
<f7-nav-right>
|
<f7-nav-right>
|
||||||
<f7-link icon-f7="ellipsis" :class="{ 'disabled': editAccountId || account.type !== AccountType.MultiSubAccounts.type }" @click="showMoreActionSheet = true"></f7-link>
|
<f7-link icon-f7="ellipsis" :class="{ 'disabled': account.type !== AccountType.MultiSubAccounts.type }" @click="showMoreActionSheet = true"></f7-link>
|
||||||
<f7-link :class="{ 'disabled': isInputEmpty() || submitting }" :text="tt(saveButtonTitle)" @click="save"></f7-link>
|
<f7-link :class="{ 'disabled': isInputEmpty() || submitting }" :text="tt(saveButtonTitle)" @click="save"></f7-link>
|
||||||
</f7-nav-right>
|
</f7-nav-right>
|
||||||
</f7-navbar>
|
</f7-navbar>
|
||||||
@@ -354,7 +354,6 @@
|
|||||||
<small>{{ tt('Sub Account') + ' #' + (idx + 1) }}</small>
|
<small>{{ tt('Sub Account') + ' #' + (idx + 1) }}</small>
|
||||||
<f7-button rasied fill class="subaccount-delete-button" color="red" icon-f7="trash" icon-size="16px"
|
<f7-button rasied fill class="subaccount-delete-button" color="red" icon-f7="trash" icon-size="16px"
|
||||||
:tooltip="tt('Remove Sub-account')"
|
:tooltip="tt('Remove Sub-account')"
|
||||||
v-if="!editAccountId"
|
|
||||||
@click="removeSubAccount(subAccount, false)">
|
@click="removeSubAccount(subAccount, false)">
|
||||||
</f7-button>
|
</f7-button>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
@@ -420,9 +419,9 @@
|
|||||||
<f7-list-item
|
<f7-list-item
|
||||||
class="list-item-with-header-and-title list-item-no-item-after"
|
class="list-item-with-header-and-title list-item-no-item-after"
|
||||||
link="#"
|
link="#"
|
||||||
:class="{ 'disabled': editAccountId }"
|
:class="{ 'disabled': editAccountId && !isNewAccount(subAccount) }"
|
||||||
:header="tt('Currency')"
|
:header="tt('Currency')"
|
||||||
:no-chevron="!!editAccountId"
|
:no-chevron="!!editAccountId && !isNewAccount(subAccount)"
|
||||||
@click="subAccountContexts[idx].showCurrencyPopup = true"
|
@click="subAccountContexts[idx].showCurrencyPopup = true"
|
||||||
>
|
>
|
||||||
<template #title>
|
<template #title>
|
||||||
@@ -447,7 +446,7 @@
|
|||||||
<f7-list-item
|
<f7-list-item
|
||||||
link="#" no-chevron
|
link="#" no-chevron
|
||||||
class="list-item-with-header-and-title"
|
class="list-item-with-header-and-title"
|
||||||
:class="{ 'disabled': editAccountId }"
|
:class="{ 'disabled': editAccountId && !isNewAccount(subAccount) }"
|
||||||
:header="account.isLiability ? tt('Sub-account Outstanding Balance') : tt('Sub-account Balance')"
|
:header="account.isLiability ? tt('Sub-account Outstanding Balance') : tt('Sub-account Balance')"
|
||||||
:title="formatAccountDisplayBalance(subAccount)"
|
:title="formatAccountDisplayBalance(subAccount)"
|
||||||
@click="subAccountContexts[idx].showBalanceSheet = true"
|
@click="subAccountContexts[idx].showBalanceSheet = true"
|
||||||
@@ -465,7 +464,7 @@
|
|||||||
class="account-edit-balancetime list-item-with-header-and-title"
|
class="account-edit-balancetime list-item-with-header-and-title"
|
||||||
link="#" no-chevron
|
link="#" no-chevron
|
||||||
v-show="subAccount.balance"
|
v-show="subAccount.balance"
|
||||||
v-if="!editAccountId"
|
v-if="!editAccountId || isNewAccount(subAccount)"
|
||||||
>
|
>
|
||||||
<template #header>
|
<template #header>
|
||||||
<div class="account-edit-balancetime-header" @click="showDateTimeDialog(subAccountContexts[idx], 'time')">{{ tt('Sub-account Balance Time') }}</div>
|
<div class="account-edit-balancetime-header" @click="showDateTimeDialog(subAccountContexts[idx], 'time')">{{ tt('Sub-account Balance Time') }}</div>
|
||||||
@@ -481,7 +480,7 @@
|
|||||||
</date-time-selection-sheet>
|
</date-time-selection-sheet>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
|
|
||||||
<f7-list-item :title="tt('Visible')" v-if="editAccountId">
|
<f7-list-item :title="tt('Visible')" v-if="editAccountId && !isNewAccount(subAccount)">
|
||||||
<f7-toggle :checked="subAccount.visible" @toggle:change="subAccount.visible = $event"></f7-toggle>
|
<f7-toggle :checked="subAccount.visible" @toggle:change="subAccount.visible = $event"></f7-toggle>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
|
|
||||||
@@ -573,6 +572,7 @@ const {
|
|||||||
allAvailableMonthDays,
|
allAvailableMonthDays,
|
||||||
isAccountSupportCreditCardStatementDate,
|
isAccountSupportCreditCardStatementDate,
|
||||||
getAccountCreditCardStatementDate,
|
getAccountCreditCardStatementDate,
|
||||||
|
isNewAccount,
|
||||||
isInputEmpty,
|
isInputEmpty,
|
||||||
getAccountOrSubAccountProblemMessage,
|
getAccountOrSubAccountProblemMessage,
|
||||||
addSubAccount,
|
addSubAccount,
|
||||||
@@ -625,6 +625,7 @@ function formatAccountBalanceTime(account: Account): string {
|
|||||||
|
|
||||||
function init(): void {
|
function init(): void {
|
||||||
const query = props.f7route.query;
|
const query = props.f7route.query;
|
||||||
|
clientSessionId.value = generateRandomUUID();
|
||||||
|
|
||||||
if (query['id']) {
|
if (query['id']) {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
@@ -651,7 +652,6 @@ function init(): void {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
clientSessionId.value = generateRandomUUID();
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user