mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
refactoring: migrating to react-query to manage service-side state.
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
export const ACCOUNT_TYPE = {
|
||||
CASH: 'cash',
|
||||
BANK: 'bank',
|
||||
@@ -42,11 +40,10 @@ export const ACCOUNT_ROOT_TYPE = {
|
||||
ASSET: 'asset',
|
||||
LIABILITY: 'liability',
|
||||
EQUITY: 'equity',
|
||||
EXPENSE: 'expene',
|
||||
EXPENSE: 'expense',
|
||||
INCOME: 'income',
|
||||
};
|
||||
|
||||
|
||||
export const ACCOUNT_NORMAL = {
|
||||
CREDIT: 'credit',
|
||||
DEBIT: 'debit',
|
||||
@@ -223,4 +220,4 @@ export const ACCOUNT_TYPES = [
|
||||
balanceSheet: false,
|
||||
incomeSheet: true,
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
@@ -6,11 +6,11 @@ exports.up = (knex) => {
|
||||
// Inserts seed entries
|
||||
return knex('view_roles').insert([
|
||||
// Accounts
|
||||
{ field_key: 'type', index: 1, comparator: 'equals', value: 'asset', view_id: 1 },
|
||||
{ field_key: 'type', index: 1, comparator: 'equals', value: 'liability', view_id: 2 },
|
||||
{ field_key: 'type', index: 1, comparator: 'equals', value: 'equity', view_id: 3 },
|
||||
{ field_key: 'type', index: 1, comparator: 'equals', value: 'income', view_id: 4 },
|
||||
{ field_key: 'type', index: 1, comparator: 'equals', value: 'expense', view_id: 5 },
|
||||
{ field_key: 'root_type', index: 1, comparator: 'equals', value: 'asset', view_id: 1 },
|
||||
{ field_key: 'root_type', index: 1, comparator: 'equals', value: 'liability', view_id: 2 },
|
||||
{ field_key: 'root_type', index: 1, comparator: 'equals', value: 'equity', view_id: 3 },
|
||||
{ field_key: 'root_type', index: 1, comparator: 'equals', value: 'income', view_id: 4 },
|
||||
{ field_key: 'root_type', index: 1, comparator: 'equals', value: 'expense', view_id: 5 },
|
||||
{ field_key: 'active', index: 1, comparator: 'is', value: 1, view_id: 15 },
|
||||
|
||||
// Items.
|
||||
|
||||
@@ -32,6 +32,7 @@ export default class Account extends TenantModel {
|
||||
return [
|
||||
'accountTypeLabel',
|
||||
'accountParentType',
|
||||
'accountRootType',
|
||||
'accountNormal',
|
||||
'isBalanceSheetAccount',
|
||||
'isPLSheet'
|
||||
@@ -59,6 +60,13 @@ export default class Account extends TenantModel {
|
||||
return AccountTypesUtils.getType(this.accountType, 'parentType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve account root type.
|
||||
*/
|
||||
get accountRootType() {
|
||||
return AccountTypesUtils.getType(this.accountType, 'rootType');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve whether the account is balance sheet account.
|
||||
*/
|
||||
@@ -236,9 +244,6 @@ export default class Account extends TenantModel {
|
||||
},
|
||||
root_type: {
|
||||
label: 'Root type',
|
||||
column: 'account_type_id',
|
||||
relation: 'account_types.id',
|
||||
relationColumn: 'account_types.root_type',
|
||||
options: [
|
||||
{ key: 'asset', label: 'Asset', },
|
||||
{ key: 'liability', label: 'Liability' },
|
||||
@@ -246,7 +251,12 @@ export default class Account extends TenantModel {
|
||||
{ key: 'Income', label: 'Income' },
|
||||
{ key: 'expense', label: 'Expense' },
|
||||
],
|
||||
fieldType: 'options',
|
||||
query: (query, role) => {
|
||||
const accountsTypes = AccountTypesUtils.getTypesByRootType(role.value);
|
||||
const accountsTypesKeys = accountsTypes.map(type => type.key);
|
||||
|
||||
query.whereIn('account_type', accountsTypesKeys);
|
||||
},
|
||||
},
|
||||
created_at: {
|
||||
label: 'Created at',
|
||||
|
||||
@@ -157,7 +157,7 @@ export default class ExpensesService implements IExpensesService {
|
||||
const invalidExpenseAccounts: number[] = [];
|
||||
|
||||
expensesAccounts.forEach((expenseAccount) => {
|
||||
if (expenseAccount.isRootType(ACCOUNT_ROOT_TYPE.EXPENSE)) {
|
||||
if (!expenseAccount.isRootType(ACCOUNT_ROOT_TYPE.EXPENSE)) {
|
||||
invalidExpenseAccounts.push(expenseAccount.id);
|
||||
}
|
||||
});
|
||||
@@ -181,7 +181,7 @@ export default class ExpensesService implements IExpensesService {
|
||||
paymentAccount,
|
||||
});
|
||||
|
||||
if (paymentAccount.isParentType(ACCOUNT_PARENT_TYPE.CURRENT_ASSET)) {
|
||||
if (!paymentAccount.isParentType(ACCOUNT_PARENT_TYPE.CURRENT_ASSET)) {
|
||||
this.logger.info(
|
||||
'[expenses] the given payment account has invalid type',
|
||||
{ tenantId, paymentAccount }
|
||||
|
||||
Reference in New Issue
Block a user