feat: match bank transaction

This commit is contained in:
Ahmed Bouhuolia
2024-06-20 23:31:46 +02:00
parent b37002bea6
commit 738a84bb4b
20 changed files with 492 additions and 55 deletions

View File

@@ -404,6 +404,7 @@ export default class Bill extends mixin(TenantModel, [
const Branch = require('models/Branch');
const TaxRateTransaction = require('models/TaxRateTransaction');
const Document = require('models/Document');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
return {
vendor: {
@@ -485,6 +486,21 @@ export default class Bill extends mixin(TenantModel, [
query.where('model_ref', 'Bill');
},
},
/**
* Bill may belongs to matched bank transaction.
*/
matchedBankTransaction: {
relation: Model.HasManyRelation,
modelClass: MatchedBankTransaction,
join: {
from: 'bills.id',
to: 'matched_bank_transactions.referenceId',
},
filter(query) {
query.where('reference_type', 'Bill');
},
},
};
}

View File

@@ -102,6 +102,7 @@ export default class CashflowTransaction extends TenantModel {
const CashflowTransactionLine = require('models/CashflowTransactionLine');
const AccountTransaction = require('models/AccountTransaction');
const Account = require('models/Account');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
return {
/**
@@ -158,6 +159,22 @@ export default class CashflowTransaction extends TenantModel {
to: 'accounts.id',
},
},
/**
* Cashflow transaction may belongs to matched bank transaction.
*/
matchedBankTransaction: {
relation: Model.HasManyRelation,
modelClass: MatchedBankTransaction,
join: {
from: 'cashflow_transactions.id',
to: 'matched_bank_transactions.referenceId',
},
filter: (query) => {
const referenceTypes = getCashflowAccountTransactionsTypes();
query.whereIn('reference_type', referenceTypes);
},
},
};
}
}

View File

@@ -182,6 +182,7 @@ export default class Expense extends mixin(TenantModel, [
const ExpenseCategory = require('models/ExpenseCategory');
const Document = require('models/Document');
const Branch = require('models/Branch');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
return {
paymentAccount: {
@@ -234,6 +235,21 @@ export default class Expense extends mixin(TenantModel, [
query.where('model_ref', 'Expense');
},
},
/**
* Expense may belongs to matched bank transaction.
*/
matchedBankTransaction: {
relation: Model.HasManyRelation,
modelClass: MatchedBankTransaction,
join: {
from: 'expenses_transactions.id',
to: 'matched_bank_transactions.referenceId',
},
filter(query) {
query.where('reference_type', 'Expense');
},
},
};
}

View File

@@ -1,4 +1,5 @@
import TenantModel from 'models/TenantModel';
import { Model } from 'objection';
export class MatchedBankTransaction extends TenantModel {
/**
@@ -12,7 +13,7 @@ export class MatchedBankTransaction extends TenantModel {
* Timestamps columns.
*/
get timestamps() {
return [];
return ['createdAt', 'updatedAt'];
}
/**
@@ -21,4 +22,11 @@ export class MatchedBankTransaction extends TenantModel {
static get virtualAttributes() {
return [];
}
/**
* Relationship mapping.
*/
static get relationMappings() {
return {};
}
}

View File

@@ -411,6 +411,7 @@ export default class SaleInvoice extends mixin(TenantModel, [
const Account = require('models/Account');
const TaxRateTransaction = require('models/TaxRateTransaction');
const Document = require('models/Document');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
return {
/**
@@ -543,6 +544,21 @@ export default class SaleInvoice extends mixin(TenantModel, [
query.where('model_ref', 'SaleInvoice');
},
},
/**
* Sale invocie may belongs to matched bank transaction.
*/
matchedBankTransaction: {
relation: Model.HasManyRelation,
modelClass: MatchedBankTransaction,
join: {
from: 'sales_invoices.id',
to: "matched_bank_transactions.referenceId",
},
filter(query) {
query.where('reference_type', 'SaleInvoice');
},
},
};
}

View File

@@ -97,6 +97,7 @@ export default class UncategorizedCashflowTransaction extends mixin(
const {
RecognizedBankTransaction,
} = require('models/RecognizedBankTransaction');
const { MatchedBankTransaction } = require('models/MatchedBankTransaction');
return {
/**
@@ -122,6 +123,18 @@ export default class UncategorizedCashflowTransaction extends mixin(
to: 'recognized_bank_transactions.id',
},
},
/**
* Uncategorized transaction may has association to matched transaction.
*/
matchedBankTransaction: {
relation: Model.BelongsToOneRelation,
modelClass: MatchedBankTransaction,
join: {
from: 'uncategorized_cashflow_transactions.id',
to: 'matched_bank_transactions.uncategorizedTransactionId',
},
},
};
}