mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix: filter the uncategorized transactions out of matched transactions
This commit is contained in:
@@ -2,7 +2,7 @@ import { Inject, Service } from 'typedi';
|
||||
import { GetMatchedTransactions } from './GetMatchedTransactions';
|
||||
import { MatchBankTransactions } from './MatchTransactions';
|
||||
import { UnmatchMatchedBankTransaction } from './UnmatchMatchedTransaction';
|
||||
import { GetMatchedTransactionsFilter, IMatchTransactionDTO } from './types';
|
||||
import { GetMatchedTransactionsFilter, IMatchTransactionsDTO } from './types';
|
||||
|
||||
@Service()
|
||||
export class MatchBankTransactionsApplication {
|
||||
@@ -43,7 +43,7 @@ export class MatchBankTransactionsApplication {
|
||||
public matchTransaction(
|
||||
tenantId: number,
|
||||
uncategorizedTransactionId: number,
|
||||
matchTransactionsDTO: IMatchTransactionDTO
|
||||
matchTransactionsDTO: IMatchTransactionsDTO
|
||||
): Promise<void> {
|
||||
return this.matchTransactionService.matchTransaction(
|
||||
tenantId,
|
||||
|
||||
@@ -105,12 +105,13 @@ export class MatchBankTransactions {
|
||||
* Matches the given uncategorized transaction to the given references.
|
||||
* @param {number} tenantId
|
||||
* @param {number} uncategorizedTransactionId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async matchTransaction(
|
||||
tenantId: number,
|
||||
uncategorizedTransactionId: number,
|
||||
matchTransactionsDTO: IMatchTransactionsDTO
|
||||
) {
|
||||
): Promise<void> {
|
||||
const { matchedTransactions } = matchTransactionsDTO;
|
||||
|
||||
// Validates the given matching transactions DTO.
|
||||
|
||||
@@ -9,10 +9,11 @@ export class ValidateTransactionMatched {
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
*
|
||||
* Validate the given transaction whether is matched with bank transactions.
|
||||
* @param {number} tenantId
|
||||
* @param {string} referenceType
|
||||
* @param {number} referenceId
|
||||
* @param {string} referenceType - Transaction reference type.
|
||||
* @param {number} referenceId - Transaction reference id.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async validateTransactionNoMatchLinking(
|
||||
tenantId: number,
|
||||
|
||||
@@ -14,15 +14,15 @@ export class ValidateMatchingOnCashflowDelete {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.cashflow.onTransactionDeleting,
|
||||
this.validateMatchingOnCashflowDelete.bind(this)
|
||||
this.validateMatchingOnCashflowDeleting.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Validates the cashflow transaction whether matched with bank transaction on deleting.
|
||||
* @param {IManualJournalDeletingPayload}
|
||||
*/
|
||||
public async validateMatchingOnCashflowDelete({
|
||||
public async validateMatchingOnCashflowDeleting({
|
||||
tenantId,
|
||||
oldManualJournal,
|
||||
trx,
|
||||
|
||||
@@ -14,15 +14,15 @@ export class ValidateMatchingOnExpenseDelete {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.expenses.onDeleting,
|
||||
this.validateMatchingOnExpenseDelete.bind(this)
|
||||
this.validateMatchingOnExpenseDeleting.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Validates the expense transaction whether matched with bank transaction on deleting.
|
||||
* @param {IExpenseEventDeletePayload}
|
||||
*/
|
||||
public async validateMatchingOnExpenseDelete({
|
||||
public async validateMatchingOnExpenseDeleting({
|
||||
tenantId,
|
||||
oldExpense,
|
||||
trx,
|
||||
|
||||
@@ -14,15 +14,15 @@ export class ValidateMatchingOnManualJournalDelete {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.manualJournals.onDeleting,
|
||||
this.validateMatchingOnManualJournalDelete.bind(this)
|
||||
this.validateMatchingOnManualJournalDeleting.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Validates the manual journal transaction whether matched with bank transaction on deleting.
|
||||
* @param {IManualJournalDeletingPayload}
|
||||
*/
|
||||
public async validateMatchingOnManualJournalDelete({
|
||||
public async validateMatchingOnManualJournalDeleting({
|
||||
tenantId,
|
||||
oldManualJournal,
|
||||
trx,
|
||||
|
||||
@@ -17,15 +17,15 @@ export class ValidateMatchingOnPaymentMadeDelete {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.billPayment.onDeleting,
|
||||
this.validateMatchingOnPaymentMadeDelete.bind(this)
|
||||
this.validateMatchingOnPaymentMadeDeleting.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Validates the payment made transaction whether matched with bank transaction on deleting.
|
||||
* @param {IPaymentReceiveDeletedPayload}
|
||||
*/
|
||||
public async validateMatchingOnPaymentMadeDelete({
|
||||
public async validateMatchingOnPaymentMadeDeleting({
|
||||
tenantId,
|
||||
oldBillPayment,
|
||||
trx,
|
||||
|
||||
@@ -14,15 +14,15 @@ export class ValidateMatchingOnPaymentReceivedDelete {
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.paymentReceive.onDeleting,
|
||||
this.validateMatchingOnPaymentReceivedDelete.bind(this)
|
||||
this.validateMatchingOnPaymentReceivedDeleting.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Validates the payment received transaction whether matched with bank transaction on deleting.
|
||||
* @param {IPaymentReceiveDeletedPayload}
|
||||
*/
|
||||
public async validateMatchingOnPaymentReceivedDelete({
|
||||
public async validateMatchingOnPaymentReceivedDeleting({
|
||||
tenantId,
|
||||
oldPaymentReceive,
|
||||
trx,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Knex } from 'knex';
|
||||
export enum BankRuleConditionField {
|
||||
Amount = 'Amount',
|
||||
Description = 'Description',
|
||||
Payee = 'Payee'
|
||||
}
|
||||
|
||||
export enum BankRuleConditionComparator {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { initialize } from 'objection';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
import { UncategorizedTransactionTransformer } from './UncategorizedTransactionTransformer';
|
||||
@@ -22,7 +23,13 @@ export class GetUncategorizedTransactions {
|
||||
accountId: number,
|
||||
query: IGetUncategorizedTransactionsQuery
|
||||
) {
|
||||
const { UncategorizedCashflowTransaction } = this.tenancy.models(tenantId);
|
||||
const {
|
||||
UncategorizedCashflowTransaction,
|
||||
RecognizedBankTransaction,
|
||||
MatchedBankTransaction,
|
||||
Account,
|
||||
} = this.tenancy.models(tenantId);
|
||||
const knex = this.tenancy.knex(tenantId);
|
||||
|
||||
// Parsed query with default values.
|
||||
const _query = {
|
||||
@@ -30,6 +37,15 @@ export class GetUncategorizedTransactions {
|
||||
pageSize: 20,
|
||||
...query,
|
||||
};
|
||||
|
||||
// Initialize the ORM models metadata.
|
||||
await initialize(knex, [
|
||||
UncategorizedCashflowTransaction,
|
||||
MatchedBankTransaction,
|
||||
RecognizedBankTransaction,
|
||||
Account,
|
||||
]);
|
||||
|
||||
const { results, pagination } =
|
||||
await UncategorizedCashflowTransaction.query()
|
||||
.onBuild((q) => {
|
||||
@@ -40,6 +56,9 @@ export class GetUncategorizedTransactions {
|
||||
q.withGraphFetched('account');
|
||||
q.withGraphFetched('recognizedTransaction.assignAccount');
|
||||
|
||||
q.withGraphJoined('matchedBankTransactions');
|
||||
|
||||
q.whereNull('matchedBankTransactions.id');
|
||||
q.orderBy('date', 'DESC');
|
||||
})
|
||||
.pagination(_query.page - 1, _query.pageSize);
|
||||
|
||||
Reference in New Issue
Block a user