mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: Categorize the bank synced transactions
This commit is contained in:
@@ -12,6 +12,7 @@ export default class CashflowTransaction extends TenantModel {
|
||||
transactionType: string;
|
||||
amount: number;
|
||||
exchangeRate: number;
|
||||
uncategorize: boolean;
|
||||
|
||||
/**
|
||||
* Table name.
|
||||
|
||||
@@ -182,6 +182,7 @@ export default class Expense extends mixin(TenantModel, [
|
||||
const ExpenseCategory = require('models/ExpenseCategory');
|
||||
const Media = require('models/Media');
|
||||
const Branch = require('models/Branch');
|
||||
const UncategorizedCashflowTransaction = require('models/UncategorizedCashflowTransaction');
|
||||
|
||||
return {
|
||||
paymentAccount: {
|
||||
@@ -215,6 +216,10 @@ export default class Expense extends mixin(TenantModel, [
|
||||
to: 'branches.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
media: {
|
||||
relation: Model.ManyToManyRelation,
|
||||
modelClass: Media.default,
|
||||
@@ -230,6 +235,18 @@ export default class Expense extends mixin(TenantModel, [
|
||||
query.where('model_name', 'Expense');
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieves the related uncategorized cashflow transaction.
|
||||
*/
|
||||
categorized: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: UncategorizedCashflowTransaction.default,
|
||||
join: {
|
||||
from: 'expenses_transactions.categorizedTransactionId',
|
||||
to: 'uncategorized_cashflow_transactions.id',
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* eslint-disable global-require */
|
||||
import TenantModel from 'models/TenantModel';
|
||||
import { Model } from 'objection';
|
||||
|
||||
export default class UncategorizedCashflowTransaction extends TenantModel {
|
||||
amount: number;
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'uncategorized_cashflow_transactions';
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamps columns.
|
||||
*/
|
||||
static get timestamps() {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the withdrawal amount.
|
||||
* @returns {number}
|
||||
*/
|
||||
public withdrawal() {
|
||||
return this.amount > 0 ? Math.abs(this.amount) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the deposit amount.
|
||||
* @returns {number}
|
||||
*/
|
||||
public deposit() {
|
||||
return this.amount < 0 ? Math.abs(this.amount) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return ['withdrawal', 'deposit'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Account = require('models/Account');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Transaction may has associated to account.
|
||||
*/
|
||||
account: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: Account.default,
|
||||
join: {
|
||||
from: 'uncategorized_cashflow_transactions.accountId',
|
||||
to: 'accounts.id',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user