mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: redesign accounts types.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable global-require */
|
||||
import { Model } from 'objection';
|
||||
import { flatten } from 'lodash';
|
||||
import { flatten, castArray } from 'lodash';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
import {
|
||||
buildFilterQuery,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from 'lib/ViewRolesBuilder';
|
||||
import { flatToNestedArray } from 'utils';
|
||||
import DependencyGraph from 'lib/DependencyGraph';
|
||||
import AccountTypesUtils from 'lib/AccountTypes'
|
||||
|
||||
export default class Account extends TenantModel {
|
||||
/**
|
||||
@@ -24,6 +25,54 @@ export default class Account extends TenantModel {
|
||||
return ['createdAt', 'updatedAt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtual attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return [
|
||||
'accountTypeLabel',
|
||||
'accountParentTypeLabel',
|
||||
'accountNormal',
|
||||
'isBalanceSheetAccount',
|
||||
'isPLSheet'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Account normal.
|
||||
*/
|
||||
get accountNormal() {
|
||||
return AccountTypesUtils.getType(this.accountType, 'normal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve account type label.
|
||||
*/
|
||||
get accountTypeLabel() {
|
||||
return AccountTypesUtils.getType(this.accountType, 'label');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve account parent type.
|
||||
*/
|
||||
get accountParentType() {
|
||||
return AccountTypesUtils.getType(this.accountType, 'parentType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether the account is balance sheet account.
|
||||
*/
|
||||
get isBalanceSheetAccount() {
|
||||
return this.isBalanceSheet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether the account is profit/loss sheet account.
|
||||
*/
|
||||
get isPLSheet() {
|
||||
return this.isProfitLossSheet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to mark model as resourceable to viewable and filterable.
|
||||
*/
|
||||
@@ -61,22 +110,9 @@ export default class Account extends TenantModel {
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const AccountType = require('models/AccountType');
|
||||
const AccountTransaction = require('models/AccountTransaction');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Account model may belongs to account type.
|
||||
*/
|
||||
type: {
|
||||
relation: Model.BelongsToOneRelation,
|
||||
modelClass: AccountType.default,
|
||||
join: {
|
||||
from: 'accounts.accountTypeId',
|
||||
to: 'account_types.id',
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Account model may has many transactions.
|
||||
*/
|
||||
@@ -90,6 +126,58 @@ export default class Account extends TenantModel {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines whether the given type equals the account type.
|
||||
* @param {string} accountType
|
||||
* @return {boolean}
|
||||
*/
|
||||
isAccountType(accountType) {
|
||||
const types = castArray(accountType);
|
||||
return types.indexOf(this.accountType) !== -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines whether the given root type equals the account type.
|
||||
* @param {string} rootType
|
||||
* @return {boolean}
|
||||
*/
|
||||
isRootType(rootType) {
|
||||
return AccountTypesUtils.isRootTypeEqualsKey(this.accountType, rootType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmine whether the given parent type equals the account type.
|
||||
* @param {string} parentType
|
||||
* @return {boolean}
|
||||
*/
|
||||
isParentType(parentType) {
|
||||
return AccountTypesUtils.isParentTypeEqualsKey(this.accountType, parentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines whether the account is balance sheet account.
|
||||
* @return {boolean}
|
||||
*/
|
||||
isBalanceSheet() {
|
||||
return AccountTypesUtils.isTypeBalanceSheet(this.accountType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines whether the account is profit/loss account.
|
||||
* @return {boolean}
|
||||
*/
|
||||
isProfitLossSheet() {
|
||||
return AccountTypesUtils.isTypePLSheet(this.accountType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detarmines whether the account is income statement account
|
||||
* @return {boolean}
|
||||
*/
|
||||
isIncomeSheet() {
|
||||
return this.isProfitLossSheet();
|
||||
}
|
||||
|
||||
static collectJournalEntries(accounts) {
|
||||
return flatten(accounts.map((account) => account.transactions.map((transaction) => ({
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
// import path from 'path';
|
||||
import { Model, mixin } from 'objection';
|
||||
import TenantModel from 'models/TenantModel';
|
||||
|
||||
export default class AccountType extends TenantModel {
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
static get tableName() {
|
||||
return 'account_types';
|
||||
}
|
||||
|
||||
/**
|
||||
* Virtaul attributes.
|
||||
*/
|
||||
static get virtualAttributes() {
|
||||
return ['label'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to mark model as resourceable to viewable and filterable.
|
||||
*/
|
||||
static get resourceable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translatable lable.
|
||||
*/
|
||||
label() {
|
||||
return AccountType.labels[this.key] || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship mapping.
|
||||
*/
|
||||
static get relationMappings() {
|
||||
const Account = require('models/Account');
|
||||
|
||||
return {
|
||||
/**
|
||||
* Account type may has many associated accounts.
|
||||
*/
|
||||
accounts: {
|
||||
relation: Model.HasManyRelation,
|
||||
modelClass: Account.default,
|
||||
join: {
|
||||
from: 'account_types.id',
|
||||
to: 'accounts.accountTypeId',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Accounts types labels.
|
||||
*/
|
||||
static get labels() {
|
||||
return {
|
||||
inventory: 'Inventory',
|
||||
other_current_asset: 'Other Current Asset',
|
||||
bank: 'Bank Account',
|
||||
cash: 'Cash',
|
||||
fixed_asset: 'Fixed Asset',
|
||||
non_current_asset: 'Non-Current Asset',
|
||||
accounts_payable: 'Accounts Payable (A/P)',
|
||||
accounts_receivable: 'Accounts Receivable (A/R)',
|
||||
credit_card: 'Credit Card',
|
||||
long_term_liability: 'Long Term Liability',
|
||||
other_current_liability: 'Other Current Liability',
|
||||
other_liability: 'Other Liability',
|
||||
equity: "Equity",
|
||||
expense: "Expense",
|
||||
income: "Income",
|
||||
other_income: "Other Income",
|
||||
other_expense: "Other Expense",
|
||||
cost_of_goods_sold: "Cost of Goods Sold (COGS)",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ import BillPaymentEntry from './BillPaymentEntry';
|
||||
import View from './View';
|
||||
import ItemEntry from './ItemEntry';
|
||||
import InventoryTransaction from './InventoryTransaction';
|
||||
import AccountType from './AccountType';
|
||||
import InventoryLotCostTracker from './InventoryCostLotTracker';
|
||||
import Customer from './Customer';
|
||||
import Contact from './Contact';
|
||||
@@ -45,7 +44,6 @@ export {
|
||||
ItemEntry,
|
||||
InventoryTransaction,
|
||||
InventoryLotCostTracker,
|
||||
AccountType,
|
||||
Option,
|
||||
Contact,
|
||||
ExpenseCategory,
|
||||
|
||||
Reference in New Issue
Block a user