mirror of
https://github.com/linuxserver/budge.git
synced 2026-02-04 20:19:09 +08:00
activity is only counted if it's not 'inflow', fixed bug where CC transactions weren't getting handled correctly against the budget month
This commit is contained in:
parent
2c5e4f2eb1
commit
699da442da
@ -62,7 +62,12 @@ export class CategoryMonthSubscriber implements EntitySubscriberInterface<Catego
|
||||
const budgetMonth = await manager.findOne(BudgetMonth, categoryMonth.budgetMonthId)
|
||||
|
||||
budgetMonth.budgeted = add(budgetMonth.budgeted, subtract(categoryMonth.budgeted, originalCategoryMonth.budgeted))
|
||||
budgetMonth.activity = add(budgetMonth.activity, subtract(categoryMonth.activity, originalCategoryMonth.activity))
|
||||
|
||||
if (category.inflow === false && category.trackingAccountId === null) {
|
||||
// Don't update budget month activity for CC transactions. These are 'inverse' transactions of other
|
||||
// category transactions, so this would 'negate' them.
|
||||
budgetMonth.activity = add(budgetMonth.activity, subtract(categoryMonth.activity, originalCategoryMonth.activity))
|
||||
}
|
||||
|
||||
const budgetedDifference = subtract(originalCategoryMonth.budgeted, categoryMonth.budgeted)
|
||||
const activityDifference = subtract(categoryMonth.activity, originalCategoryMonth.activity)
|
||||
|
||||
@ -155,11 +155,11 @@ export class TransactionSubscriber implements EntitySubscriberInterface<Transact
|
||||
if (account.type === AccountTypes.CreditCard) {
|
||||
// Update CC category
|
||||
const ccCategory = await manager.findOne(Category, { trackingAccountId: account.id })
|
||||
const ccCategoryMonth = await manager
|
||||
const currentCCMonth = await manager
|
||||
.getCustomRepository(CategoryMonths)
|
||||
.findOrCreate(transaction.budgetId, ccCategory.id, Transaction.getMonth(transaction.date))
|
||||
ccCategoryMonth.update({ activity: multiply(transaction.amount, -1) })
|
||||
await manager.getRepository(CategoryMonth).update(ccCategoryMonth.id, ccCategoryMonth.getUpdatePayload())
|
||||
currentCCMonth.update({ activity: multiply(transaction.amount, -1) })
|
||||
await manager.getRepository(CategoryMonth).update(currentCCMonth.id, currentCCMonth.getUpdatePayload())
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,6 +268,7 @@ export class TransactionSubscriber implements EntitySubscriberInterface<Transact
|
||||
if (!TransactionCache.transfersEnabled(transaction.id)) {
|
||||
return
|
||||
}
|
||||
|
||||
TransactionCache.disableTransfers(transaction.id)
|
||||
|
||||
const originalTransaction = TransactionCache.get(transaction.id)
|
||||
@ -470,7 +471,7 @@ export class TransactionSubscriber implements EntitySubscriberInterface<Transact
|
||||
const currentCCMonth = await manager
|
||||
.getCustomRepository(CategoryMonths)
|
||||
.findOrCreate(transaction.budgetId, ccCategory.id, Transaction.getMonth(transaction.date))
|
||||
currentCCMonth.update({ activity: multiply(transaction.amount, -1) })
|
||||
currentCCMonth.update({ activity: multiply(activity, -1) })
|
||||
await manager.getRepository(CategoryMonth).update(currentCCMonth.id, currentCCMonth.getUpdatePayload())
|
||||
}
|
||||
}
|
||||
@ -502,6 +503,19 @@ export class TransactionSubscriber implements EntitySubscriberInterface<Transact
|
||||
return
|
||||
}
|
||||
|
||||
// Even if there's no category ID, still need to update the CC category month because transfers
|
||||
// affect the balance.
|
||||
if (account.type === AccountTypes.CreditCard) {
|
||||
// Update CC category
|
||||
const ccCategory = await manager.findOne(Category, { trackingAccountId: account.id })
|
||||
const ccCategoryMonth = await manager.findOne(CategoryMonth, {
|
||||
categoryId: ccCategory.id,
|
||||
month: Transaction.getMonth(transaction.date),
|
||||
})
|
||||
ccCategoryMonth.update({ activity: transaction.amount })
|
||||
await manager.getRepository(CategoryMonth).update(ccCategoryMonth.id, ccCategoryMonth.getUpdatePayload())
|
||||
}
|
||||
|
||||
if (!transaction.categoryId) {
|
||||
return
|
||||
}
|
||||
@ -523,17 +537,5 @@ export class TransactionSubscriber implements EntitySubscriberInterface<Transact
|
||||
.getRepository(CategoryMonth)
|
||||
.update(originalCategoryMonth.id, originalCategoryMonth.getUpdatePayload())
|
||||
}
|
||||
|
||||
// Check if we need to update a CC category
|
||||
if (account.type === AccountTypes.CreditCard) {
|
||||
// Update CC category
|
||||
const ccCategory = await manager.findOne(Category, { trackingAccountId: account.id })
|
||||
const ccCategoryMonth = await manager.findOne(CategoryMonth, {
|
||||
categoryId: ccCategory.id,
|
||||
month: Transaction.getMonth(transaction.date),
|
||||
})
|
||||
ccCategoryMonth.update({ activity: transaction.amount })
|
||||
await manager.getRepository(CategoryMonth).update(ccCategoryMonth.id, ccCategoryMonth.getUpdatePayload())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user