mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
Merge pull request #569 from bigcapitalhq/fix-edit-bank-rule-recognized
fix: Recognize transactions on editing bank rule
This commit is contained in:
@@ -43,8 +43,6 @@ export class BankingRulesController extends BaseController {
|
|||||||
body('assign_account_id').isInt({ min: 0 }),
|
body('assign_account_id').isInt({ min: 0 }),
|
||||||
body('assign_payee').isString().optional({ nullable: true }),
|
body('assign_payee').isString().optional({ nullable: true }),
|
||||||
body('assign_memo').isString().optional({ nullable: true }),
|
body('assign_memo').isString().optional({ nullable: true }),
|
||||||
|
|
||||||
body('recognition').isBoolean().toBoolean().optional({ nullable: true }),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ import { PaymentReceiveMailNotificationJob } from '@/services/Sales/PaymentRecei
|
|||||||
import { PlaidFetchTransactionsJob } from '@/services/Banking/Plaid/PlaidFetchTransactionsJob';
|
import { PlaidFetchTransactionsJob } from '@/services/Banking/Plaid/PlaidFetchTransactionsJob';
|
||||||
import { ImportDeleteExpiredFilesJobs } from '@/services/Import/jobs/ImportDeleteExpiredFilesJob';
|
import { ImportDeleteExpiredFilesJobs } from '@/services/Import/jobs/ImportDeleteExpiredFilesJob';
|
||||||
import { SendVerifyMailJob } from '@/services/Authentication/jobs/SendVerifyMailJob';
|
import { SendVerifyMailJob } from '@/services/Authentication/jobs/SendVerifyMailJob';
|
||||||
import { RegonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/RecognizeTransactionsJob';
|
import { ReregonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/jobs/RerecognizeTransactionsJob';
|
||||||
|
import { RegonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/jobs/RecognizeTransactionsJob';
|
||||||
|
import { RevertRegonizeTransactionsJob } from '@/services/Banking/RegonizeTranasctions/jobs/RevertRecognizedTransactionsJob';
|
||||||
|
|
||||||
export default ({ agenda }: { agenda: Agenda }) => {
|
export default ({ agenda }: { agenda: Agenda }) => {
|
||||||
new ResetPasswordMailJob(agenda);
|
new ResetPasswordMailJob(agenda);
|
||||||
@@ -31,6 +33,8 @@ export default ({ agenda }: { agenda: Agenda }) => {
|
|||||||
new ImportDeleteExpiredFilesJobs(agenda);
|
new ImportDeleteExpiredFilesJobs(agenda);
|
||||||
new SendVerifyMailJob(agenda);
|
new SendVerifyMailJob(agenda);
|
||||||
new RegonizeTransactionsJob(agenda);
|
new RegonizeTransactionsJob(agenda);
|
||||||
|
new ReregonizeTransactionsJob(agenda);
|
||||||
|
new RevertRegonizeTransactionsJob(agenda);
|
||||||
|
|
||||||
agenda.start().then(() => {
|
agenda.start().then(() => {
|
||||||
agenda.every('1 hours', 'delete-expired-imported-files', {});
|
agenda.every('1 hours', 'delete-expired-imported-files', {});
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ export class RecognizeSyncedBankTranasctions extends EventSubscriber {
|
|||||||
runAfterTransaction(trx, async () => {
|
runAfterTransaction(trx, async () => {
|
||||||
await this.recognizeTranasctionsService.recognizeTransactions(
|
await this.recognizeTranasctionsService.recognizeTransactions(
|
||||||
tenantId,
|
tenantId,
|
||||||
batch
|
null,
|
||||||
|
{ batch }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { castArray, isEmpty } from 'lodash';
|
||||||
import UncategorizedCashflowTransaction from '@/models/UncategorizedCashflowTransaction';
|
import UncategorizedCashflowTransaction from '@/models/UncategorizedCashflowTransaction';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { transformToMapBy } from '@/utils';
|
import { transformToMapBy } from '@/utils';
|
||||||
import { PromisePool } from '@supercharge/promise-pool';
|
import { PromisePool } from '@supercharge/promise-pool';
|
||||||
import { BankRule } from '@/models/BankRule';
|
import { BankRule } from '@/models/BankRule';
|
||||||
import { bankRulesMatchTransaction } from './_utils';
|
import { bankRulesMatchTransaction } from './_utils';
|
||||||
|
import { RecognizeTransactionsCriteria } from './_types';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class RecognizeTranasctionsService {
|
export class RecognizeTranasctionsService {
|
||||||
@@ -48,24 +50,42 @@ export class RecognizeTranasctionsService {
|
|||||||
/**
|
/**
|
||||||
* Regonized the uncategorized transactions.
|
* Regonized the uncategorized transactions.
|
||||||
* @param {number} tenantId -
|
* @param {number} tenantId -
|
||||||
|
* @param {number|Array<number>} ruleId - The target rule id/ids.
|
||||||
|
* @param {RecognizeTransactionsCriteria}
|
||||||
* @param {Knex.Transaction} trx -
|
* @param {Knex.Transaction} trx -
|
||||||
*/
|
*/
|
||||||
public async recognizeTransactions(
|
public async recognizeTransactions(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
batch: string = '',
|
ruleId?: number | Array<number>,
|
||||||
|
transactionsCriteria?: RecognizeTransactionsCriteria,
|
||||||
trx?: Knex.Transaction
|
trx?: Knex.Transaction
|
||||||
) {
|
) {
|
||||||
const { UncategorizedCashflowTransaction, BankRule } =
|
const { UncategorizedCashflowTransaction, BankRule } =
|
||||||
this.tenancy.models(tenantId);
|
this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const uncategorizedTranasctions =
|
const uncategorizedTranasctions =
|
||||||
await UncategorizedCashflowTransaction.query().onBuild((query) => {
|
await UncategorizedCashflowTransaction.query(trx).onBuild((query) => {
|
||||||
query.where('recognized_transaction_id', null);
|
query.modify('notRecognized');
|
||||||
query.where('categorized', false);
|
query.modify('notCategorized');
|
||||||
|
|
||||||
if (batch) query.where('batch', batch);
|
// Filter the transactions based on the given criteria.
|
||||||
|
if (transactionsCriteria?.batch) {
|
||||||
|
query.where('batch', transactionsCriteria.batch);
|
||||||
|
}
|
||||||
|
if (transactionsCriteria?.accountId) {
|
||||||
|
query.where('accountId', transactionsCriteria.accountId);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const bankRules = await BankRule.query().withGraphFetched('conditions');
|
|
||||||
|
const bankRules = await BankRule.query(trx).onBuild((q) => {
|
||||||
|
const rulesIds = castArray(ruleId);
|
||||||
|
|
||||||
|
if (!isEmpty(rulesIds)) {
|
||||||
|
q.whereIn('id', rulesIds);
|
||||||
|
}
|
||||||
|
q.withGraphFetched('conditions');
|
||||||
|
});
|
||||||
|
|
||||||
const bankRulesByAccountId = transformToMapBy(
|
const bankRulesByAccountId = transformToMapBy(
|
||||||
bankRules,
|
bankRules,
|
||||||
'applyIfAccountId'
|
'applyIfAccountId'
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
|
import { Knex } from 'knex';
|
||||||
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
|
import UnitOfWork from '@/services/UnitOfWork';
|
||||||
|
import { RevertRecognizedTransactionsCriteria } from './_types';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class RevertRecognizedTransactions {
|
||||||
|
@Inject()
|
||||||
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private uow: UnitOfWork;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revert and unlinks the recognized transactions based on the given bank rule
|
||||||
|
* and transactions criteria..
|
||||||
|
* @param {number} tenantId - Tenant id.
|
||||||
|
* @param {number|Array<number>} bankRuleId - Bank rule id.
|
||||||
|
* @param {RevertRecognizedTransactionsCriteria} transactionsCriteria -
|
||||||
|
* @param {Knex.Transaction} trx - Knex transaction.
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
public async revertRecognizedTransactions(
|
||||||
|
tenantId: number,
|
||||||
|
ruleId?: number | Array<number>,
|
||||||
|
transactionsCriteria?: RevertRecognizedTransactionsCriteria,
|
||||||
|
trx?: Knex.Transaction
|
||||||
|
): Promise<void> {
|
||||||
|
const { UncategorizedCashflowTransaction, RecognizedBankTransaction } =
|
||||||
|
this.tenancy.models(tenantId);
|
||||||
|
|
||||||
|
const rulesIds = castArray(ruleId);
|
||||||
|
|
||||||
|
return this.uow.withTransaction(
|
||||||
|
tenantId,
|
||||||
|
async (trx: Knex.Transaction) => {
|
||||||
|
// Retrieves all the recognized transactions of the banbk rule.
|
||||||
|
const uncategorizedTransactions =
|
||||||
|
await UncategorizedCashflowTransaction.query(trx).onBuild((q) => {
|
||||||
|
q.withGraphJoined('recognizedTransaction');
|
||||||
|
q.whereNotNull('recognizedTransaction.id');
|
||||||
|
|
||||||
|
if (rulesIds.length > 0) {
|
||||||
|
q.whereIn('recognizedTransaction.bankRuleId', rulesIds);
|
||||||
|
}
|
||||||
|
if (transactionsCriteria?.accountId) {
|
||||||
|
q.where('accountId', transactionsCriteria.accountId);
|
||||||
|
}
|
||||||
|
if (transactionsCriteria?.batch) {
|
||||||
|
q.where('batch', transactionsCriteria.batch);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const uncategorizedTransactionIds = uncategorizedTransactions.map(
|
||||||
|
(r) => r.id
|
||||||
|
);
|
||||||
|
// Unlink the recongized transactions out of uncategorized transactions.
|
||||||
|
await UncategorizedCashflowTransaction.query(trx)
|
||||||
|
.whereIn('id', uncategorizedTransactionIds)
|
||||||
|
.patch({
|
||||||
|
recognizedTransactionId: null,
|
||||||
|
});
|
||||||
|
// Delete the recognized bank transactions that assocaited to bank rule.
|
||||||
|
await RecognizedBankTransaction.query(trx)
|
||||||
|
.whereIn('uncategorizedTransactionId', uncategorizedTransactionIds)
|
||||||
|
.delete();
|
||||||
|
},
|
||||||
|
trx
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export interface RevertRecognizedTransactionsCriteria {
|
||||||
|
batch?: string;
|
||||||
|
accountId?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface RecognizeTransactionsCriteria {
|
||||||
|
batch?: string;
|
||||||
|
accountId?: number;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -41,14 +41,10 @@ export class TriggerRecognizedTransactions {
|
|||||||
*/
|
*/
|
||||||
private async recognizedTransactionsOnRuleCreated({
|
private async recognizedTransactionsOnRuleCreated({
|
||||||
tenantId,
|
tenantId,
|
||||||
createRuleDTO,
|
bankRule,
|
||||||
}: IBankRuleEventCreatedPayload) {
|
}: IBankRuleEventCreatedPayload) {
|
||||||
const payload = { tenantId };
|
const payload = { tenantId, ruleId: bankRule.id };
|
||||||
|
|
||||||
// Cannot run recognition if the option is not enabled.
|
|
||||||
if (createRuleDTO.recognition) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +55,14 @@ export class TriggerRecognizedTransactions {
|
|||||||
private async recognizedTransactionsOnRuleEdited({
|
private async recognizedTransactionsOnRuleEdited({
|
||||||
tenantId,
|
tenantId,
|
||||||
editRuleDTO,
|
editRuleDTO,
|
||||||
|
ruleId,
|
||||||
}: IBankRuleEventEditedPayload) {
|
}: IBankRuleEventEditedPayload) {
|
||||||
const payload = { tenantId };
|
const payload = { tenantId, ruleId };
|
||||||
|
|
||||||
// Cannot run recognition if the option is not enabled.
|
await this.agenda.now(
|
||||||
if (!editRuleDTO.recognition) {
|
'rerecognize-uncategorized-transactions-job',
|
||||||
return;
|
payload
|
||||||
}
|
);
|
||||||
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,9 +71,13 @@ export class TriggerRecognizedTransactions {
|
|||||||
*/
|
*/
|
||||||
private async recognizedTransactionsOnRuleDeleted({
|
private async recognizedTransactionsOnRuleDeleted({
|
||||||
tenantId,
|
tenantId,
|
||||||
|
ruleId,
|
||||||
}: IBankRuleEventDeletedPayload) {
|
}: IBankRuleEventDeletedPayload) {
|
||||||
const payload = { tenantId };
|
const payload = { tenantId, ruleId };
|
||||||
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
await this.agenda.now(
|
||||||
|
'revert-recognized-uncategorized-transactions-job',
|
||||||
|
payload
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +91,7 @@ export class TriggerRecognizedTransactions {
|
|||||||
}: IImportFileCommitedEventPayload) {
|
}: IImportFileCommitedEventPayload) {
|
||||||
const importFile = await Import.query().findOne({ importId });
|
const importFile = await Import.query().findOne({ importId });
|
||||||
const batch = importFile.paramsParsed.batch;
|
const batch = importFile.paramsParsed.batch;
|
||||||
const payload = { tenantId, batch };
|
const payload = { tenantId, transactionsCriteria: { batch } };
|
||||||
|
|
||||||
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
await this.agenda.now('recognize-uncategorized-transactions-job', payload);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Container, { Service } from 'typedi';
|
import Container, { Service } from 'typedi';
|
||||||
import { RecognizeTranasctionsService } from './RecognizeTranasctionsService';
|
import { RecognizeTranasctionsService } from '../RecognizeTranasctionsService';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class RegonizeTransactionsJob {
|
export class RegonizeTransactionsJob {
|
||||||
@@ -18,11 +18,15 @@ export class RegonizeTransactionsJob {
|
|||||||
* Triggers sending invoice mail.
|
* Triggers sending invoice mail.
|
||||||
*/
|
*/
|
||||||
private handler = async (job, done: Function) => {
|
private handler = async (job, done: Function) => {
|
||||||
const { tenantId, batch } = job.attrs.data;
|
const { tenantId, ruleId, transactionsCriteria } = job.attrs.data;
|
||||||
const regonizeTransactions = Container.get(RecognizeTranasctionsService);
|
const regonizeTransactions = Container.get(RecognizeTranasctionsService);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await regonizeTransactions.recognizeTransactions(tenantId, batch);
|
await regonizeTransactions.recognizeTransactions(
|
||||||
|
tenantId,
|
||||||
|
ruleId,
|
||||||
|
transactionsCriteria
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import Container, { Service } from 'typedi';
|
||||||
|
import { RecognizeTranasctionsService } from '../RecognizeTranasctionsService';
|
||||||
|
import { RevertRecognizedTransactions } from '../RevertRecognizedTransactions';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class ReregonizeTransactionsJob {
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
*/
|
||||||
|
constructor(agenda) {
|
||||||
|
agenda.define(
|
||||||
|
'rerecognize-uncategorized-transactions-job',
|
||||||
|
{ priority: 'high', concurrency: 2 },
|
||||||
|
this.handler
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers sending invoice mail.
|
||||||
|
*/
|
||||||
|
private handler = async (job, done: Function) => {
|
||||||
|
const { tenantId, ruleId, transactionsCriteria } = job.attrs.data;
|
||||||
|
const regonizeTransactions = Container.get(RecognizeTranasctionsService);
|
||||||
|
const revertRegonizedTransactions = Container.get(
|
||||||
|
RevertRecognizedTransactions
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await revertRegonizedTransactions.revertRecognizedTransactions(
|
||||||
|
tenantId,
|
||||||
|
ruleId,
|
||||||
|
transactionsCriteria
|
||||||
|
);
|
||||||
|
await regonizeTransactions.recognizeTransactions(
|
||||||
|
tenantId,
|
||||||
|
ruleId,
|
||||||
|
transactionsCriteria
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
done(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import Container, { Service } from 'typedi';
|
||||||
|
import { RevertRecognizedTransactions } from '../RevertRecognizedTransactions';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class RevertRegonizeTransactionsJob {
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
*/
|
||||||
|
constructor(agenda) {
|
||||||
|
agenda.define(
|
||||||
|
'revert-recognized-uncategorized-transactions-job',
|
||||||
|
{ priority: 'high', concurrency: 2 },
|
||||||
|
this.handler
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers sending invoice mail.
|
||||||
|
*/
|
||||||
|
private handler = async (job, done: Function) => {
|
||||||
|
const { tenantId, ruleId, transactionsCriteria } = job.attrs.data;
|
||||||
|
const revertRegonizedTransactions = Container.get(
|
||||||
|
RevertRecognizedTransactions
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await revertRegonizedTransactions.revertRecognizedTransactions(
|
||||||
|
tenantId,
|
||||||
|
ruleId,
|
||||||
|
transactionsCriteria
|
||||||
|
);
|
||||||
|
done();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
done(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@ export class CreateBankRuleService {
|
|||||||
await this.eventPublisher.emitAsync(events.bankRules.onCreated, {
|
await this.eventPublisher.emitAsync(events.bankRules.onCreated, {
|
||||||
tenantId,
|
tenantId,
|
||||||
createRuleDTO,
|
createRuleDTO,
|
||||||
|
bankRule,
|
||||||
trx,
|
trx,
|
||||||
} as IBankRuleEventCreatedPayload);
|
} as IBankRuleEventCreatedPayload);
|
||||||
|
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
|
||||||
import { Knex } from 'knex';
|
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
||||||
import UnitOfWork from '@/services/UnitOfWork';
|
|
||||||
|
|
||||||
@Service()
|
|
||||||
export class UnlinkBankRuleRecognizedTransactions {
|
|
||||||
@Inject()
|
|
||||||
private tenancy: HasTenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private uow: UnitOfWork;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unlinks the given bank rule out of recognized transactions.
|
|
||||||
* @param {number} tenantId - Tenant id.
|
|
||||||
* @param {number} bankRuleId - Bank rule id.
|
|
||||||
* @param {Knex.Transaction} trx - Knex transaction.
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
public async unlinkBankRuleOutRecognizedTransactions(
|
|
||||||
tenantId: number,
|
|
||||||
bankRuleId: number,
|
|
||||||
trx?: Knex.Transaction
|
|
||||||
): Promise<void> {
|
|
||||||
const { UncategorizedCashflowTransaction, RecognizedBankTransaction } =
|
|
||||||
this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
return this.uow.withTransaction(
|
|
||||||
tenantId,
|
|
||||||
async (trx: Knex.Transaction) => {
|
|
||||||
// Retrieves all the recognized transactions of the banbk rule.
|
|
||||||
const recognizedTransactions = await RecognizedBankTransaction.query(
|
|
||||||
trx
|
|
||||||
).where('bankRuleId', bankRuleId);
|
|
||||||
|
|
||||||
const uncategorizedTransactionIds = recognizedTransactions.map(
|
|
||||||
(r) => r.uncategorizedTransactionId
|
|
||||||
);
|
|
||||||
// Unlink the recongized transactions out of uncategorized transactions.
|
|
||||||
await UncategorizedCashflowTransaction.query(trx)
|
|
||||||
.whereIn('id', uncategorizedTransactionIds)
|
|
||||||
.patch({
|
|
||||||
recognizedTransactionId: null,
|
|
||||||
});
|
|
||||||
// Delete the recognized bank transactions that assocaited to bank rule.
|
|
||||||
await RecognizedBankTransaction.query(trx)
|
|
||||||
.where({ bankRuleId })
|
|
||||||
.delete();
|
|
||||||
},
|
|
||||||
trx
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import events from '@/subscribers/events';
|
import events from '@/subscribers/events';
|
||||||
import { UnlinkBankRuleRecognizedTransactions } from '../UnlinkBankRuleRecognizedTransactions';
|
|
||||||
import { IBankRuleEventDeletingPayload } from '../types';
|
import { IBankRuleEventDeletingPayload } from '../types';
|
||||||
|
import { RevertRecognizedTransactions } from '../../RegonizeTranasctions/RevertRecognizedTransactions';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class UnlinkBankRuleOnDeleteBankRule {
|
export class UnlinkBankRuleOnDeleteBankRule {
|
||||||
@Inject()
|
@Inject()
|
||||||
private unlinkBankRule: UnlinkBankRuleRecognizedTransactions;
|
private revertRecognizedTransactionsService: RevertRecognizedTransactions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
@@ -26,7 +26,7 @@ export class UnlinkBankRuleOnDeleteBankRule {
|
|||||||
tenantId,
|
tenantId,
|
||||||
ruleId,
|
ruleId,
|
||||||
}: IBankRuleEventDeletingPayload) {
|
}: IBankRuleEventDeletingPayload) {
|
||||||
await this.unlinkBankRule.unlinkBankRuleOutRecognizedTransactions(
|
await this.revertRecognizedTransactionsService.revertRecognizedTransactions(
|
||||||
tenantId,
|
tenantId,
|
||||||
ruleId
|
ruleId
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ export enum BankRuleApplyIfTransactionType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IBankRule {
|
export interface IBankRule {
|
||||||
|
id?: number;
|
||||||
name: string;
|
name: string;
|
||||||
order?: number;
|
order?: number;
|
||||||
applyIfAccountId: number;
|
applyIfAccountId: number;
|
||||||
@@ -71,8 +72,6 @@ export interface IBankRuleCommonDTO {
|
|||||||
assignAccountId: number;
|
assignAccountId: number;
|
||||||
assignPayee?: string;
|
assignPayee?: string;
|
||||||
assignMemo?: string;
|
assignMemo?: string;
|
||||||
|
|
||||||
recognition?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ICreateBankRuleDTO extends IBankRuleCommonDTO {}
|
export interface ICreateBankRuleDTO extends IBankRuleCommonDTO {}
|
||||||
@@ -86,6 +85,7 @@ export interface IBankRuleEventCreatingPayload {
|
|||||||
export interface IBankRuleEventCreatedPayload {
|
export interface IBankRuleEventCreatedPayload {
|
||||||
tenantId: number;
|
tenantId: number;
|
||||||
createRuleDTO: ICreateBankRuleDTO;
|
createRuleDTO: ICreateBankRuleDTO;
|
||||||
|
bankRule: IBankRule;
|
||||||
trx?: Knex.Transaction;
|
trx?: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user