-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improvements to bank matching transactions
- Loading branch information
Showing
18 changed files
with
188 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
.../server/src/services/Banking/Matching/events/DecrementUncategorizedTransactionsOnMatch.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Inject, Service } from 'typedi'; | ||
import events from '@/subscribers/events'; | ||
import { | ||
IBankTransactionMatchedEventPayload, | ||
IBankTransactionUnmatchedEventPayload, | ||
} from '../types'; | ||
import HasTenancyService from '@/services/Tenancy/TenancyService'; | ||
|
||
@Service() | ||
export class DecrementUncategorizedTransactionOnMatching { | ||
@Inject() | ||
private tenancy: HasTenancyService; | ||
/** | ||
* Constructor method. | ||
*/ | ||
public attach(bus) { | ||
bus.subscribe( | ||
events.bankMatch.onMatched, | ||
this.decrementUnCategorizedTransactionsOnMatching.bind(this) | ||
); | ||
bus.subscribe( | ||
events.bankMatch.onUnmatched, | ||
this.incrementUnCategorizedTransactionsOnUnmatching.bind(this) | ||
); | ||
} | ||
|
||
/** | ||
* Validates the cashflow transaction whether matched with bank transaction on deleting. | ||
* @param {IManualJournalDeletingPayload} | ||
*/ | ||
public async decrementUnCategorizedTransactionsOnMatching({ | ||
tenantId, | ||
uncategorizedTransactionId, | ||
matchTransactionsDTO, | ||
trx, | ||
}: IBankTransactionMatchedEventPayload) { | ||
const { UncategorizedCashflowTransaction, Account } = | ||
this.tenancy.models(tenantId); | ||
|
||
const transaction = await UncategorizedCashflowTransaction.query().findById( | ||
uncategorizedTransactionId | ||
); | ||
// | ||
await Account.query(trx) | ||
.findById(transaction.accountId) | ||
.decrement('uncategorizedTransactions', 1); | ||
} | ||
|
||
/** | ||
* Validates the cashflow transaction whether matched with bank transaction on deleting. | ||
* @param {IManualJournalDeletingPayload} | ||
*/ | ||
public async incrementUnCategorizedTransactionsOnUnmatching({ | ||
tenantId, | ||
uncategorizedTransactionId, | ||
trx, | ||
}: IBankTransactionUnmatchedEventPayload) { | ||
const { UncategorizedCashflowTransaction, Account } = | ||
this.tenancy.models(tenantId); | ||
|
||
const transaction = await UncategorizedCashflowTransaction.query().findById( | ||
uncategorizedTransactionId | ||
); | ||
// | ||
await Account.query(trx) | ||
.findById(transaction.accountId) | ||
.decrement('uncategorizedTransactions', 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.