WIP server side.

This commit is contained in:
Ahmed Bouhuolia
2020-01-22 02:09:45 +02:00
parent de905d7e7c
commit 488709088b
123 changed files with 14885 additions and 771 deletions

View File

@@ -27,17 +27,52 @@ factory.define('password_reset', 'password_resets', async () => {
factory.define('account_type', 'account_types', async () => ({
name: faker.lorem.words(2),
normal: 'debit',
}));
factory.define('account_balance', 'account_balances', async () => {
const account = await factory.create('account');
return {
account_id: account.id,
amount: faker.random.number(),
currency_code: 'USD',
};
});
factory.define('account', 'accounts', async () => {
const accountType = await factory.create('account_type');
return {
name: faker.lorem.word(),
code: faker.random.number(),
account_type_id: accountType.id,
description: faker.lorem.paragraph(),
};
});
factory.define('account_transaction', 'accounts_transactions', async () => {
const account = await factory.create('account');
const user = await factory.create('user');
return {
account_id: account.id,
credit: faker.random.number(),
debit: 0,
user_id: user.id,
};
});
factory.define('manual_journal', 'manual_journals', async () => {
const user = await factory.create('user');
return {
reference: faker.random.number(),
amount: faker.random.number(),
// date: faker.random,
user_id: user.id,
};
});
factory.define('item_category', 'items_categories', () => ({
label: faker.name.firstName(),
description: faker.lorem.text(),
@@ -135,11 +170,13 @@ factory.define('resource_field', 'resource_fields', async () => {
return {
label_name: faker.lorem.words(),
slug: faker.lorem.slug(),
data_type: dataTypes[Math.floor(Math.random() * dataTypes.length)],
help_text: faker.lorem.words(),
default: faker.lorem.word(),
resource_id: resource.id,
active: true,
columnable: true,
predefined: false,
};
});
@@ -167,4 +204,47 @@ factory.define('view_has_columns', 'view_has_columns', async () => {
};
});
factory.define('expense', 'expenses', async () => {
const paymentAccount = await factory.create('account');
const expenseAccount = await factory.create('account');
const user = await factory.create('user');
return {
payment_account_id: paymentAccount.id,
expense_account_id: expenseAccount.id,
user_id: user.id,
amount: faker.random.number(),
currency_code: 'USD',
};
});
factory.define('option', 'options', async () => {
return {
key: faker.lorem.slug(),
value: faker.lorem.slug(),
group: faker.lorem.slug(),
};
});
factory.define('budget', 'budgets', async () => {
return {
name: faker.lorem.slug(),
fiscal_year: '2020',
period: 'month',
account_types: 'profit_loss',
};
});
factory.define('budget_entry', 'budget_entries', async () => {
const budget = await factory.create('budget');
const account = await factory.create('account');
return {
account_id: account.id,
budget_id: budget.id,
amount: 1000,
order: 1,
};
});
export default factory;

View File

@@ -1,7 +1,11 @@
import Knex from 'knex';
import { knexSnakeCaseMappers } from 'objection';
import knexfile from '@/../knexfile';
const config = knexfile[process.env.NODE_ENV];
const knex = Knex(config);
const knex = Knex({
...config,
...knexSnakeCaseMappers({ upperCase: true }),
});
export default knex;

View File

@@ -7,6 +7,8 @@ exports.up = function (knex) {
table.integer('parent_account_id');
table.string('code', 10);
table.text('description');
table.boolean('active').defaultTo(true);
table.integer('index').unsigned();
table.timestamps();
});
};

View File

@@ -1,11 +1,11 @@
exports.up = function (knex) {
return knex.schema.createTable('account_balance', (table) => {
return knex.schema.createTable('account_balances', (table) => {
table.increments();
table.integer('account_id');
table.decimal('amount');
table.decimal('amount', 15, 5);
table.string('currency_code', 3);
});
};
exports.down = (knex) => knex.schema.dropTableIfExists('account_balance');
exports.down = (knex) => knex.schema.dropTableIfExists('account_balances');

View File

@@ -3,6 +3,9 @@ exports.up = function (knex) {
return knex.schema.createTable('account_types', (table) => {
table.increments();
table.string('name');
table.string('normal');
table.boolean('balance_sheet');
table.boolean('income_sheet');
});
};

View File

@@ -3,11 +3,13 @@ exports.up = function (knex) {
return knex.schema.createTable('resource_fields', (table) => {
table.increments();
table.string('label_name');
table.string('slug');
table.string('data_type');
table.string('help_text');
table.string('default');
table.boolean('active');
table.boolean('predefined');
table.boolean('columnable');
table.json('options');
table.integer('resource_id').unsigned().references('id').inTable('resources');
});

View File

@@ -5,6 +5,7 @@ exports.up = function (knex) {
table.string('name');
table.boolean('predefined');
table.integer('resource_id').unsigned().references('id').inTable('resources');
table.string('roles_logic_expression');
});
};

View File

@@ -0,0 +1,20 @@
exports.up = function(knex) {
return knex.schema.createTable('accounts_transactions', (table) => {
table.increments();
table.decimal('credit');
table.decimal('debit');
table.string('transaction_type');
table.string('reference_type');
table.integer('reference_id');
table.integer('account_id').unsigned().references('id').inTable('accounts');
table.string('note');
table.integer('user_id').unsigned().references('id').inTable('users');
table.date('date');
table.timestamps();
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('accounts_transactions');
};

View File

@@ -0,0 +1,14 @@
exports.up = function(knex) {
return knex.schema.createTable('options', (table) => {
table.increments();
table.string('key');
table.string('value');
table.string('group');
table.string('type');
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('options');
};

View File

@@ -0,0 +1,20 @@
exports.up = function(knex) {
return knex.schema.createTable('expenses', (table) => {
table.increments();
table.decimal('amount');
table.string('currency_code');
table.decimal('exchange_rate');
table.text('description');
table.integer('expense_account_id').unsigned().references('id').inTable('accounts');
table.integer('payment_account_id').unsigned().references('id').inTable('accounts');
table.string('reference');
table.integer('user_id').unsigned().references('id').inTable('users');
table.date('date');
// table.timestamps();
})
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('expenses');
};

View File

@@ -0,0 +1,14 @@
exports.up = function(knex) {
return knex.schema.createTable('currency_adjustments', (table) => {
table.increments();
table.date('date');
table.string('currency_code');
table.decimal('exchange_rate');
table.string('note');
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('currency_adjustments');
};

View File

@@ -0,0 +1,17 @@
exports.up = function(knex) {
return knex.schema.createTable('manual_journals', (table) => {
table.increments();
table.string('reference');
table.string('transaction_type');
table.decimal('amount');
table.date('date');
table.string('note');
table.integer('user_id').unsigned().references('id').inTable('users');
table.timestamps();
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('manual_journals');
};

View File

@@ -0,0 +1,12 @@
exports.up = function(knex) {
return knex.schema.createTable('recurring_journals', (table) => {
table.increments();
table.string('template_name');
table.timestamps();
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('recurring_journals');
};

View File

@@ -0,0 +1,14 @@
exports.up = function(knex) {
return knex.schema.createTable('budgets', (table) => {
table.increments();
table.string('name');
table.string('fiscal_year');
table.string('period');
table.string('account_types');
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('budgets');
};

View File

@@ -0,0 +1,14 @@
exports.up = function(knex) {
return knex.schema.createTable('budget_entries', (table) => {
table.increments();
table.integer('budget_id').unsigned().references('id').inTable('budgets');
table.integer('account_id').unsigned().references('id').inTable('accounts');
table.decimal('amount', 15, 5);
table.integer('order');
})
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('budget_entries');
};