add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,390 @@
import KnexFactory from '@/lib/KnexFactory';
import faker from 'faker';
import { hashPassword } from 'utils';
export default (tenantDb) => {
const factory = new KnexFactory(tenantDb);
factory.define('user', 'users', async () => {
// const hashedPassword = await hashPassword('admin');
return {
first_name: faker.name.firstName(),
last_name: faker.name.lastName(),
email: faker.internet.email(),
phone_number: faker.phone.phoneNumberFormat().replace('-', ''),
active: 1,
// password: hashedPassword,
};
});
factory.define('password_reset', 'password_resets', async () => {
return {
user_id: null,
token: faker.lorem.slug,
};
});
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 {
journal_number: faker.random.number(),
transaction_type: '',
amount: faker.random.number(),
date: faker.date.future,
status: 1,
user_id: user.id,
};
});
factory.define('item_category', 'items_categories', () => ({
name: faker.name.firstName(),
description: faker.lorem.text(),
parent_category_id: null,
}));
factory.define('item_metadata', 'items_metadata', async () => {
const item = await factory.create('item');
return {
key: faker.lorem.slug(),
value: faker.lorem.word(),
item_id: item.id,
};
});
factory.define('item', 'items', async () => {
const category = await factory.create('item_category');
const costAccount = await factory.create('account');
const sellAccount = await factory.create('account');
const inventoryAccount = await factory.create('account');
return {
name: faker.lorem.word(),
note: faker.lorem.paragraph(),
cost_price: faker.random.number(),
sell_price: faker.random.number(),
cost_account_id: costAccount.id,
sell_account_id: sellAccount.id,
inventory_account_id: inventoryAccount.id,
category_id: category.id,
};
});
factory.define('setting', 'settings', async () => {
const user = await factory.create('user');
return {
key: faker.lorem.slug(),
user_id: user.id,
type: 'string',
value: faker.lorem.words(),
group: 'default',
};
});
factory.define('role', 'roles', async () => ({
name: faker.lorem.word(),
description: faker.lorem.words(),
predefined: false,
}));
factory.define('user_has_role', 'user_has_roles', async () => {
const user = await factory.create('user');
const role = await factory.create('role');
return {
user_id: user.id,
role_id: role.id,
};
});
factory.define('permission', 'permissions', async () => {
const permissions = ['create', 'edit', 'delete', 'view', 'owner'];
const randomPermission = permissions[Math.floor(Math.random() * permissions.length)];
return {
name: randomPermission,
};
});
factory.define('role_has_permission', 'role_has_permissions', async () => {
const permission = await factory.create('permission');
const role = await factory.create('role');
const resource = await factory.create('resource');
return {
role_id: role.id,
permission_id: permission.id,
resource_id: resource.id,
};
});
factory.define('resource', 'resources', () => ({
name: faker.lorem.word(),
}));
factory.define('view', 'views', async () => {
const resource = await factory.create('resource');
return {
name: faker.lorem.word(),
resource_id: resource.id,
predefined: false,
};
});
factory.define('resource_field', 'resource_fields', async () => {
const resource = await factory.create('resource');
const dataTypes = ['select', 'date', 'text'];
return {
label_name: faker.lorem.words(),
key: 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,
};
});
factory.define('resource_custom_field_metadata', 'resource_custom_fields_metadata', async () => {
const resource = await factory.create('resource');
return {
resource_id: resource.id,
resource_item_id: 1,
key: faker.lorem.words(),
value: faker.lorem.words(),
};
});
factory.define('view_role', 'view_roles', async () => {
const view = await factory.create('view');
const field = await factory.create('resource_field');
return {
view_id: view.id,
index: faker.random.number(),
field_id: field.id,
value: '',
comparator: '',
};
});
factory.define('view_column', 'view_has_columns', async () => {
const view = await factory.create('view');
const field = await factory.create('resource_field');
return {
field_id: field.id,
view_id: view.id,
// index: 1,
};
});
factory.define('expense', 'expenses_transactions', async () => {
const paymentAccount = await factory.create('account');
const expenseAccount = await factory.create('account');
const user = await factory.create('user');
return {
total_amount: faker.random.number(),
currency_code: 'USD',
description: '',
reference_no: faker.random.number(),
payment_account_id: paymentAccount.id,
published: true,
user_id: user.id,
};
});
factory.define('expense_category', 'expense_transaction_categories', async () => {
const expense = await factory.create('expense');
return {
expense_account_id: expense.id,
description: '',
amount: faker.random.number(),
expense_id: expense.id,
};
});
factory.define('option', 'options', async () => {
return {
key: faker.lorem.slug(),
value: faker.lorem.slug(),
group: faker.lorem.slug(),
};
});
factory.define('currency', 'currencies', async () => {
return {
currency_name: faker.lorem.slug(),
currency_code: 'USD',
};
});
factory.define('exchange_rate', 'exchange_rates', async () => {
return {
date: '2020-02-02',
currency_code: 'USD',
exchange_rate: faker.random.number(),
};
});
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,
};
});
factory.define('customer', 'customers', async () => {
return {
customer_type: 'business',
};
});
factory.define('vendor', 'vendors', async () => {
return {
customer_type: 'business',
};
});
factory.define('sale_estimate', 'sales_estimates', async () => {
const customer = await factory.create('customer');
return {
customer_id: customer.id,
estimate_date: faker.date.past,
expiration_date: faker.date.future,
reference: '',
estimate_number: faker.random.number,
note: '',
terms_conditions: '',
};
});
factory.define('sale_estimate_entry', 'sales_estimate_entries', async () => {
const estimate = await factory.create('sale_estimate');
const item = await factory.create('item');
return {
estimate_id: estimate.id,
item_id: item.id,
description: '',
discount: faker.random.number,
quantity: faker.random.number,
rate: faker.random.number,
};
});
factory.define('sale_receipt', 'sales_receipts', async () => {
const depositAccount = await factory.create('account');
const customer = await factory.create('customer');
return {
deposit_account_id: depositAccount.id,
customer_id: customer.id,
reference_no: faker.random.number,
receipt_date: faker.date.past,
};
});
factory.define('sale_receipt_entry', 'sales_receipt_entries', async () => {
const saleReceipt = await factory.create('sale_receipt');
const item = await factory.create('item');
return {
sale_receipt_id: saleReceipt.id,
item_id: item.id,
rate: faker.random.number,
quantity: faker.random.number,
};
});
factory.define('sale_invoice', 'sales_invoices', async () => {
return {
};
});
factory.define('sale_invoice_entry', 'sales_invoices_entries', async () => {
return {
};
});
factory.define('payment_receive', 'payment_receives', async () => {
});
factory.define('payment_receive_entry', 'payment_receives_entries', async () => {
});
factory.define('bill', 'bills', async () => {
return {
}
});
return factory;
}

View File

@@ -0,0 +1,16 @@
import KnexFactory from '@/lib/KnexFactory';
import systemDb from '@/database/knex';
import faker from 'faker';
export default () => {
const factory = new KnexFactory(systemDb);
factory.define('password_reset', 'password_resets', async () => {
return {
email: faker.lorem.email,
token: faker.lorem.slug,
};
});
return factory;
};

View File

@@ -0,0 +1,19 @@
exports.up = function (knex) {
return knex.schema.createTable('accounts', (table) => {
table.increments('id').comment('Auto-generated id');
table.string('name').index();
table.string('slug');
table.string('account_type').index();
table.integer('parent_account_id').unsigned().references('id').inTable('accounts');
table.string('code', 10).index();
table.text('description');
table.boolean('active').defaultTo(true).index();
table.integer('index').unsigned();
table.boolean('predefined').defaultTo(false).index();
table.decimal('amount', 15, 5);
table.string('currency_code', 3).index();
table.timestamps();
}).raw('ALTER TABLE `ACCOUNTS` AUTO_INCREMENT = 1000');
};
exports.down = (knex) => knex.schema.dropTableIfExists('accounts');

View File

@@ -0,0 +1,19 @@
exports.up = function (knex) {
return knex.schema.createTable('items_categories', (table) => {
table.increments();
table.string('name').index();
table.text('description');
table.integer('user_id').unsigned().index();
table.integer('cost_account_id').unsigned().references('id').inTable('accounts');
table.integer('sell_account_id').unsigned().references('id').inTable('accounts');
table.integer('inventory_account_id').unsigned().references('id').inTable('accounts');
table.string('cost_method');
table.timestamps();
});
};
exports.down = (knex) => knex.schema.dropTableIfExists('items_categories');

View File

@@ -0,0 +1,30 @@
exports.up = function (knex) {
return knex.schema.createTable('items', (table) => {
table.increments();
table.string('name').index();
table.string('type').index();
table.string('code');
table.boolean('sellable').index();
table.boolean('purchasable').index();
table.decimal('sell_price', 13, 3).unsigned();
table.decimal('cost_price', 13, 3).unsigned();
table.string('currency_code', 3);
table.string('picture_uri');
table.integer('cost_account_id').nullable().unsigned().references('id').inTable('accounts');
table.integer('sell_account_id').nullable().unsigned().references('id').inTable('accounts');
table.integer('inventory_account_id').unsigned().references('id').inTable('accounts');
table.text('sell_description').nullable();
table.text('purchase_description').nullable();
table.integer('quantity_on_hand');
table.boolean('landed_cost').nullable();
table.text('note').nullable();
table.boolean('active');
table.integer('category_id').unsigned().index().references('id').inTable('items_categories');
table.integer('user_id').unsigned().index();
table.timestamps();
}).raw('ALTER TABLE `ITEMS` AUTO_INCREMENT = 1000');
};
exports.down = (knex) => knex.schema.dropTableIfExists('items');

View File

@@ -0,0 +1,15 @@
exports.up = function (knex) {
return knex.schema.createTable('views', (table) => {
table.increments();
table.string('name').index();
table.string('slug').index();
table.boolean('predefined');
table.string('resource_model').index();
table.boolean('favourite');
table.string('roles_logic_expression');
table.timestamps();
}).raw('ALTER TABLE `VIEWS` AUTO_INCREMENT = 1000');
};
exports.down = (knex) => knex.schema.dropTableIfExists('views');

View File

@@ -0,0 +1,13 @@
exports.up = function (knex) {
return knex.schema.createTable('settings', (table) => {
table.increments();
table.integer('user_id').unsigned().index();
table.string('group').index();
table.string('type');
table.string('key').index();
table.string('value');
}).raw('ALTER TABLE `SETTINGS` AUTO_INCREMENT = 2000');
};
exports.down = (knex) => knex.schema.dropTableIfExists('settings');

View File

@@ -0,0 +1,11 @@
exports.up = function (knex) {
return knex.schema.createTable('view_has_columns', (table) => {
table.increments();
table.integer('view_id').unsigned().index().references('id').inTable('views');
table.string('field_key');
table.integer('index').unsigned();
}).raw('ALTER TABLE `ITEMS_CATEGORIES` AUTO_INCREMENT = 1000');
};
exports.down = (knex) => knex.schema.dropTableIfExists('view_has_columns');

View File

@@ -0,0 +1,19 @@
exports.up = function (knex) {
return knex.schema
.createTable('view_roles', (table) => {
table.increments();
table.integer('index');
table.string('field_key').index();
table.string('comparator');
table.string('value');
table
.integer('view_id')
.unsigned()
.index()
.references('id')
.inTable('views');
})
.raw('ALTER TABLE `VIEW_ROLES` AUTO_INCREMENT = 1000');
};
exports.down = (knex) => knex.schema.dropTableIfExists('view_roles');

View File

@@ -0,0 +1,54 @@
exports.up = function(knex) {
return knex.schema.createTable('contacts', table => {
table.increments();
table.string('contact_service');
table.string('contact_type');
table.decimal('balance', 13, 3).defaultTo(0);
table.string('currency_code', 3);
table.decimal('opening_balance', 13, 3).defaultTo(0);
table.date('opening_balance_at');
table.string('salutation').nullable();
table.string('first_name').nullable();
table.string('last_name').nullable();
table.string('company_name').nullable();
table.string('display_name');
table.string('email').nullable();
table.string('work_phone').nullable();
table.string('personal_phone').nullable();
table.string('website').nullable();
table.string('billing_address_1').nullable();
table.string('billing_address_2').nullable();
table.string('billing_address_city').nullable();
table.string('billing_address_country').nullable();
table.string('billing_address_email').nullable();
table.string('billing_address_postcode').nullable();
table.string('billing_address_phone').nullable();
table.string('billing_address_state').nullable(),
table.string('shipping_address_1').nullable();
table.string('shipping_address_2').nullable();
table.string('shipping_address_city').nullable();
table.string('shipping_address_country').nullable();
table.string('shipping_address_email').nullable();
table.string('shipping_address_postcode').nullable();
table.string('shipping_address_phone').nullable();
table.string('shipping_address_state').nullable();
table.text('note');
table.boolean('active').defaultTo(true);
table.timestamps();
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('contacts');
};

View File

@@ -0,0 +1,36 @@
exports.up = function (knex) {
return knex.schema
.createTable('accounts_transactions', (table) => {
table.increments();
table.decimal('credit', 13, 3);
table.decimal('debit', 13, 3);
table.string('transaction_type').index();
table.string('reference_type').index();
table.integer('reference_id').index();
table
.integer('account_id')
.unsigned()
.index()
.references('id')
.inTable('accounts');
table.string('contact_type').nullable().index();
table.integer('contact_id').unsigned().nullable().index();
table.string('transaction_number').nullable().index();
table.string('reference_number').nullable().index();
table.integer('item_id').unsigned().nullable().index();
table.integer('item_quantity').unsigned().nullable().index(),
table.string('note');
table.integer('user_id').unsigned().index();
table.integer('index_group').unsigned().index();
table.integer('index').unsigned().index();
table.date('date').index();
table.datetime('created_at').index();
})
.raw('ALTER TABLE `ACCOUNTS_TRANSACTIONS` AUTO_INCREMENT = 1000');
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('accounts_transactions');
};

View File

@@ -0,0 +1,29 @@
exports.up = function (knex) {
return knex.schema
.createTable('expenses_transactions', (table) => {
table.increments();
table.string('currency_code', 3);
table.text('description');
table
.integer('payment_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table.integer('payee_id').unsigned().references('id').inTable('contacts');
table.string('reference_no');
table.decimal('total_amount', 13, 3);
table.decimal('landed_cost_amount', 13, 3).defaultTo(0);
table.decimal('allocated_cost_amount', 13, 3).defaultTo(0);
table.date('published_at').index();
table.integer('user_id').unsigned().index();
table.date('payment_date').index();
table.timestamps();
})
.raw('ALTER TABLE `EXPENSES_TRANSACTIONS` AUTO_INCREMENT = 1000');
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('expenses');
};

View File

@@ -0,0 +1,21 @@
exports.up = function(knex) {
return knex.schema.createTable('manual_journals', (table) => {
table.increments();
table.string('journal_number').index();
table.string('reference').index();
table.string('journal_type').index();
table.decimal('amount', 13, 3);
table.string('currency_code', 3);
table.date('date').index();
table.string('description');
table.date('published_at').index();
table.string('attachment_file');
table.integer('user_id').unsigned().index();
table.timestamps();
}).raw('ALTER TABLE `MANUAL_JOURNALS` AUTO_INCREMENT = 1000');
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('manual_journals');
};

View File

@@ -0,0 +1,17 @@
exports.up = function(knex) {
return knex.schema.createTable('manual_journals_entries', (table) => {
table.increments();
table.decimal('credit', 13, 3);
table.decimal('debit', 13, 3);
table.integer('index').unsigned();
table.integer('account_id').unsigned().index().references('id').inTable('accounts');
table.integer('contact_id').unsigned().nullable().index();
table.string('note');
table.integer('manual_journal_id').unsigned().index().references('id').inTable('manual_journals');
}).raw('ALTER TABLE `MANUAL_JOURNALS_ENTRIES` AUTO_INCREMENT = 1000');
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('manual_journals_entries');
};

View File

@@ -0,0 +1,14 @@
exports.up = function(knex) {
return knex.schema.createTable('currencies', table => {
table.increments();
table.string('currency_name').index();
table.string('currency_code', 4).index();
table.string('currency_sign').index();
table.timestamps();
}).raw('ALTER TABLE `CURRENCIES` AUTO_INCREMENT = 1000');
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('currencies');
};

View File

@@ -0,0 +1,14 @@
exports.up = function(knex) {
return knex.schema.createTable('exchange_rates', table => {
table.increments();
table.string('currency_code', 4).index();
table.decimal('exchange_rate');
table.date('date').index();
table.timestamps();
}).raw('ALTER TABLE `EXCHANGE_RATES` AUTO_INCREMENT = 1000');
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('exchange_rates');
};

View File

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

View File

@@ -0,0 +1,13 @@
exports.up = function(knex) {
return knex.schema.createTable('media_links', table => {
table.increments();
table.string('model_name').index();
table.integer('media_id').unsigned().references('id').inTable('media');
table.integer('model_id').unsigned().index();
})
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('media_links');
};

View File

@@ -0,0 +1,29 @@
exports.up = function (knex) {
return knex.schema
.createTable('expense_transaction_categories', (table) => {
table.increments();
table
.integer('expense_account_id')
.unsigned()
.index()
.references('id')
.inTable('accounts');
table.integer('index').unsigned();
table.text('description');
table.decimal('amount', 13, 3);
table.decimal('allocated_cost_amount', 13, 3).defaultTo(0);
table.boolean('landed_cost').defaultTo(false);
table
.integer('expense_id')
.unsigned()
.index()
.references('id')
.inTable('expenses_transactions');
table.timestamps();
})
.raw('ALTER TABLE `EXPENSE_TRANSACTION_CATEGORIES` AUTO_INCREMENT = 1000');
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('expense_transaction_categories');
};

View File

@@ -0,0 +1,35 @@
exports.up = function (knex) {
return knex.schema.createTable('sales_estimates', (table) => {
table.increments();
table.decimal('amount', 13, 3);
table.string('currency_code', 3);
table
.integer('customer_id')
.unsigned()
.index()
.references('id')
.inTable('contacts');
table.date('estimate_date').index();
table.date('expiration_date').index();
table.string('reference');
table.string('estimate_number').index();
table.text('note');
table.text('terms_conditions');
table.text('send_to_email');
table.date('delivered_at').index();
table.date('approved_at').index();
table.date('rejected_at').index();
table.integer('user_id').unsigned().index();
table.integer('converted_to_invoice_id').unsigned();
table.date('converted_to_invoice_at');
table.timestamps();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('sales_estimates');
};

View File

@@ -0,0 +1,22 @@
exports.up = function(knex) {
return knex.schema.createTable('sales_receipts', table => {
table.increments();
table.decimal('amount', 13, 3);
table.string('currency_code', 3);
table.integer('deposit_account_id').unsigned().index().references('id').inTable('accounts');
table.integer('customer_id').unsigned().index().references('id').inTable('contacts');
table.date('receipt_date').index();
table.string('receipt_number').index();
table.string('reference_no').index();
table.string('send_to_email');
table.text('receipt_message');
table.text('statement');
table.date('closed_at').index();
table.timestamps();
})
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('sales_receipts');
};

View File

@@ -0,0 +1,34 @@
exports.up = function (knex) {
return knex.schema.createTable('sales_invoices', (table) => {
table.increments();
table
.integer('customer_id')
.unsigned()
.index()
.references('id')
.inTable('contacts');
table.date('invoice_date').index();
table.date('due_date');
table.string('invoice_no').index();
table.string('reference_no');
table.text('invoice_message');
table.text('terms_conditions');
table.decimal('balance', 13, 3);
table.decimal('payment_amount', 13, 3);
table.string('currency_code', 3);
table.decimal('credited_amount', 13, 3).defaultTo(0);
table.string('inv_lot_number').index();
table.date('delivered_at').index();
table.integer('user_id').unsigned();
table.timestamps();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('sales_invoices');
};

View File

@@ -0,0 +1,30 @@
const { knexSnakeCaseMappers } = require('objection');
exports.up = function (knex) {
return knex.schema.createTable('payment_receives', (table) => {
table.increments();
table
.integer('customer_id')
.unsigned()
.index()
.references('id')
.inTable('contacts');
table.date('payment_date').index();
table.decimal('amount', 13, 3).defaultTo(0);
table.string('currency_code', 3);
table.string('reference_no').index();
table
.integer('deposit_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table.string('payment_receive_no').nullable();
table.text('statement');
table.integer('user_id').unsigned().index();
table.timestamps();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('payment_receives');
};

View File

@@ -0,0 +1,23 @@
exports.up = function (knex) {
return knex.schema.createTable('payment_receives_entries', (table) => {
table.increments();
table
.integer('payment_receive_id')
.unsigned()
.index()
.references('id')
.inTable('payment_receives');
table
.integer('invoice_id')
.unsigned()
.index()
.references('id')
.inTable('sales_invoices');
table.decimal('payment_amount', 13, 3).unsigned();
table.integer('index').unsigned();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('payment_receives_entries');
};

View File

@@ -0,0 +1,31 @@
exports.up = function (knex) {
return knex.schema.createTable('bills', (table) => {
table.increments();
table
.integer('vendor_id')
.unsigned()
.index()
.references('id')
.inTable('contacts');
table.string('bill_number');
table.date('bill_date').index();
table.date('due_date').index();
table.string('reference_no').index();
table.string('status').index();
table.text('note');
table.decimal('amount', 13, 3).defaultTo(0);
table.string('currency_code');
table.decimal('payment_amount', 13, 3).defaultTo(0);
table.decimal('landed_cost_amount', 13, 3).defaultTo(0);
table.decimal('allocated_cost_amount', 13, 3).defaultTo(0);
table.decimal('credited_amount', 13, 3).defaultTo(0);
table.string('inv_lot_number').index();
table.date('opened_at').index();
table.integer('user_id').unsigned();
table.timestamps();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('bills');
};

View File

@@ -0,0 +1,21 @@
exports.up = function(knex) {
return knex.schema.createTable('bills_payments', table => {
table.increments();
table.integer('vendor_id').unsigned().index().references('id').inTable('contacts');
table.decimal('amount', 13, 3).defaultTo(0);
table.string('currency_code');
table.integer('payment_account_id').unsigned().references('id').inTable('accounts');
table.string('payment_number').nullable().index();
table.date('payment_date').index();
table.string('payment_method');
table.string('reference');
table.integer('user_id').unsigned().index();
table.text('statement');
table.timestamps();
});
};
exports.down = function(knex) {
};

View File

@@ -0,0 +1,24 @@
exports.up = function (knex) {
return knex.schema.createTable('inventory_transactions', (table) => {
table.increments('id');
table.date('date').index();
table.string('direction').index();
table
.integer('item_id')
.unsigned()
.index()
.references('id')
.inTable('items');
table.integer('quantity').unsigned();
table.decimal('rate', 13, 3).unsigned();
table.string('transaction_type').index();
table.integer('transaction_id').unsigned().index();
table.integer('entry_id').unsigned().index();
table.integer('cost_account_id').unsigned();
table.timestamps();
});
};
exports.down = function (knex) {};

View File

@@ -0,0 +1,21 @@
exports.up = function (knex) {
return knex.schema.createTable('bill_located_costs', (table) => {
table.increments();
table.decimal('amount', 13, 3).unsigned();
table.integer('fromTransactionId').unsigned();
table.string('fromTransactionType');
table.integer('fromTransactionEntryId').unsigned();
table.string('allocationMethod');
table.integer('costAccountId').unsigned();
table.text('description');
table.integer('billId').unsigned();
table.timestamps();
});
};
exports.down = function (knex) {};

View File

@@ -0,0 +1,11 @@
exports.up = function (knex) {
return knex.schema.createTable('bill_located_cost_entries', (table) => {
table.increments();
table.decimal('cost', 13, 3).unsigned();
table.integer('entry_id').unsigned();
table.integer('bill_located_cost_id').unsigned();
});
};
exports.down = function (knex) {};

View File

@@ -0,0 +1,11 @@
exports.up = function (knex) {
return knex.schema.createTable('inventory_transaction_meta', (table) => {
table.increments('id');
table.string('transaction_number');
table.text('description');
table.integer('inventory_transaction_id').unsigned();
});
};
exports.down = function (knex) {};

View File

@@ -0,0 +1,39 @@
exports.up = function (knex) {
return knex.schema.createTable('items_entries', (table) => {
table.increments();
table.string('reference_type').index();
table.string('reference_id').index();
table.integer('index').unsigned();
table
.integer('item_id')
.unsigned()
.index()
.references('id')
.inTable('items');
table.text('description');
table.integer('discount').unsigned();
table.integer('quantity').unsigned();
table.integer('rate').unsigned();
table
.integer('sell_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table
.integer('cost_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table.boolean('landed_cost').defaultTo(false);
table.decimal('allocated_cost_amount', 13, 3).defaultTo(0);
table.timestamps();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('items_entries');
};

View File

@@ -0,0 +1,23 @@
exports.up = function (knex) {
return knex.schema.createTable('bills_payments_entries', (table) => {
table.increments();
table
.integer('bill_payment_id')
.unsigned()
.index()
.references('id')
.inTable('bills_payments');
table
.integer('bill_id')
.unsigned()
.index()
.references('id')
.inTable('bills');
table.decimal('payment_amount', 13, 3).unsigned();
table.integer('index').unsigned();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('bills_payments_entries');
};

View File

@@ -0,0 +1,26 @@
exports.up = function (knex) {
return knex.schema.createTable('inventory_cost_lot_tracker', (table) => {
table.increments();
table.date('date').index();
table.string('direction').index();
table.integer('item_id').unsigned().index();
table.integer('quantity').unsigned().index();
table.decimal('rate', 13, 3);
table.integer('remaining');
table.decimal('cost', 13, 3);
table.string('transaction_type').index();
table.integer('transaction_id').unsigned().index();
table.integer('entry_id').unsigned().index();
table.integer('cost_account_id').unsigned();
table.integer('inventory_transaction_id').unsigned().index();
table.datetime('created_at').index();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('inventory_cost_lot_tracker');
};

View File

@@ -0,0 +1,19 @@
exports.up = function(knex) {
return knex.schema.createTable('inventory_adjustments', table => {
table.increments();
table.date('date').index();
table.string('type').index();
table.integer('adjustment_account_id').unsigned().references('id').inTable('accounts');
table.string('reason');
table.string('reference_no').index();
table.string('description');
table.integer('user_id').unsigned();
table.date('published_at');
table.timestamps();
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('inventory_adjustments');
};

View File

@@ -0,0 +1,25 @@
exports.up = function (knex) {
return knex.schema.createTable('inventory_adjustments_entries', (table) => {
table.increments();
table
.integer('adjustment_id')
.unsigned()
.index()
.references('id')
.inTable('inventory_adjustments');
table.integer('index').unsigned();
table
.integer('item_id')
.unsigned()
.index()
.references('id')
.inTable('items');
table.integer('quantity');
table.decimal('cost', 13, 3).unsigned();
table.decimal('value', 13, 3).unsigned();
});
};
exports.down = function (knex) {
return knex.schema.dropTableIfExists('inventory_adjustments_entries');
};

View File

@@ -0,0 +1,18 @@
exports.up = (knex) => {
return knex.schema.createTable('cashflow_transactions', (table) => {
table.increments();
table.date('date').index();
table.decimal('amount', 13, 3);
table.string('reference_no').index();
table.string('transaction_type').index();
table.string('transaction_number').index();
table.string('description');
table.date('published_at').index();
table.integer('user_id').unsigned().index();
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('cashflow_transactions');
};

View File

@@ -0,0 +1,23 @@
exports.up = (knex) => {
return knex.schema.createTable('cashflow_transaction_lines', (table) => {
table.increments();
table.integer('cashflow_transaction_id').unsigned();
table
.integer('cashflow_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table
.integer('credit_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table.decimal('amount', 13, 3);
table.integer('index').unsigned();
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('cashflow_transaction_lines');
};

View File

@@ -0,0 +1,13 @@
exports.up = (knex) => {
return knex.schema.table('sales_invoices', (table) => {
table.decimal('writtenoff_amount', 13, 3);
table.date('writtenoff_at').index();
});
};
exports.down = (knex) => {
return knex.schema.table('sales_invoices', (table) => {
table.dropColumn('writtenoff_amount');
table.dropColumn('writtenoff_at');
});
};

View File

@@ -0,0 +1,11 @@
exports.up = (knex) => {
return knex.schema.table('accounts_transactions', (table) => {
table.boolean('costable');
});
};
exports.down = (knex) => {
return knex.schema.table('accounts_transactions', (table) => {
table.dropColumn('costable');
});
};

View File

@@ -0,0 +1,21 @@
exports.up = (knex) => {
return knex.schema
.createTable('roles', (table) => {
table.increments('id');
table.string('name', 255).notNullable();
table.string('slug');
table.text('description');
table.boolean('predefined');
})
.createTable('role_permissions', (table) => {
table.increments('id');
table.integer('role_id').unsigned().references('id').inTable('roles');
table.string('subject');
table.string('ability');
table.boolean('value');
});
};
exports.down = (knex) => {
return knex.schema.dropTable('roles').dropTable('role_permissions');
};

View File

@@ -0,0 +1,19 @@
exports.up = (knex) => {
return knex.schema.createTable('users', (table) => {
table.increments();
table.string('first_name');
table.string('last_name');
table.string('email').index();
table.string('phone_number').index();
table.boolean('active').index();
table.integer('role_id').unsigned().references('id').inTable('roles');
table.integer('system_user_id').unsigned();
table.dateTime('invited_at').index();
table.dateTime('invite_accepted_at').index();
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('users');
};

View File

@@ -0,0 +1,28 @@
exports.up = (knex) => {
return knex.schema.createTable('credit_notes', (table) => {
table.increments();
table
.integer('customer_id')
.unsigned()
.references('id')
.inTable('contacts');
table.date('credit_note_date');
table.string('credit_note_number');
table.string('reference_no');
table.decimal('amount', 13, 3);
table.decimal('refunded_amount', 13, 3).defaultTo(0);
table.decimal('invoices_amount', 13, 3).defaultTo(0);
table.string('currency_code', 3);
table.text('note');
table.text('terms_conditions');
table.date('opened_at').index();
table.integer('user_id').unsigned().references('id').inTable('users');
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('credit_notescredit_notes');
};

View File

@@ -0,0 +1,23 @@
exports.up = (knex) => {
return knex.schema.createTable('vendor_credits', (table) => {
table.increments();
table.integer('vendor_id').unsigned().references('id').inTable('contacts');
table.decimal('amount', 13, 3);
table.string('currency_code', 3);
table.date('vendor_credit_date');
table.string('vendor_credit_number');
table.string('reference_no');
table.decimal('refunded_amount', 13, 3).defaultTo(0);
table.decimal('invoiced_amount', 13, 3).defaultTo(0);
table.text('note');
table.date('opened_at').index();
table.integer('user_id').unsigned().references('id').inTable('users');
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('vendor_credits');
};

View File

@@ -0,0 +1,45 @@
exports.up = (knex) => {
return knex.schema
.createTable('refund_credit_note_transactions', (table) => {
table.increments();
table.date('date');
table
.integer('credit_note_id')
.unsigned()
.references('id')
.inTable('credit_notes');
table.decimal('amount', 13, 3);
table.string('currency_code', 3);
table.string('reference_no');
table
.integer('from_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table.text('description');
table.timestamps();
})
.createTable('refund_vendor_credit_transactions', (table) => {
table.increments();
table.date('date');
table
.integer('vendor_credit_id')
.unsigned()
.references('id')
.inTable('vendor_credits');
table.decimal('amount', 13, 3);
table.string('currency_code', 3);
table.string('reference_no');
table
.integer('deposit_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table.text('description');
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('refund_transactions');
};

View File

@@ -0,0 +1,35 @@
exports.up = (knex) => {
return knex.schema
.createTable('credit_note_applied_invoice', (table) => {
table.increments();
table.decimal('amount', 13, 3);
table
.integer('credit_note_id')
.unsigned()
.references('id')
.inTable('credit_notes');
table
.integer('invoice_id')
.unsigned()
.references('id')
.inTable('sales_invoices');
table.timestamps();
})
.createTable('vendor_credit_applied_bill', (table) => {
table.increments();
table.decimal('amount', 13, 3);
table
.integer('vendor_credit_id')
.unsigned()
.references('id')
.inTable('vendor_credits');
table.integer('bill_id').unsigned().references('id').inTable('bills');
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema
.dropTableIfExists('vendor_credit_applied_bill')
.dropTableIfExists('credit_note_applied_invoice');
};

View File

@@ -0,0 +1,24 @@
exports.up = (knex) => {
return knex.schema.createTable('branches', (table) => {
table.increments();
table.string('name');
table.string('code');
table.string('address');
table.string('city');
table.string('country');
table.string('phone_number');
table.string('email');
table.string('website');
table.boolean('primary');
table.timestamps();
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('branches');
};

View File

@@ -0,0 +1,59 @@
exports.up = (knex) => {
return knex.schema
.createTable('warehouses', (table) => {
table.increments();
table.string('name');
table.string('code');
table.string('address');
table.string('city');
table.string('country');
table.string('phone_number');
table.string('email');
table.string('website');
table.boolean('primary');
table.timestamps();
})
.createTable('warehouses_transfers', (table) => {
table.increments();
table.date('date');
table
.integer('to_warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('from_warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table.string('transaction_number');
table.date('transfer_initiated_at');
table.date('transfer_delivered_at');
table.timestamps();
})
.createTable('warehouses_transfers_entries', (table) => {
table.increments();
table.integer('index');
table
.integer('warehouse_transfer_id')
.unsigned()
.references('id')
.inTable('warehouses_transfers');
table.integer('item_id').unsigned().references('id').inTable('items');
table.string('description');
table.integer('quantity');
table.decimal('cost');
});
};
exports.down = (knex) => {
return knex.schema
.dropTableIfExists('vendor_credit_applied_bill')
.dropTableIfExists('credit_note_applied_invoice');
};

View File

@@ -0,0 +1,16 @@
exports.up = (knex) => {
return knex.schema.createTable('items_warehouses_quantity', (table) => {
table.integer('item_id').unsigned().references('id').inTable('items');
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table.integer('quantity_on_hand');
});
};
exports.down = (knex) => {
return knex.schema.dropTableIfExists('items_warehouses_quantity');
};

View File

@@ -0,0 +1,86 @@
exports.up = (knex) => {
return knex.schema
.table('accounts_transactions', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('manual_journals', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('manual_journals_entries', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('expenses_transactions', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches')
.after('user_id');
})
.table('cashflow_transactions', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches')
.after('user_id');
})
.table('contacts', (table) => {
table
.integer('opening_balance_branch_id')
.unsigned()
.references('id')
.inTable('branches')
.after('opening_balance_at');
})
.table('refund_credit_note_transactions', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches')
.after('description');
})
.table('refund_vendor_credit_transactions', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches')
.after('description');
});
};
exports.down = (knex) => {
return knex.schema
.table('accounts_transactions', (table) => {
table.dropColumn('branch_id');
})
.table('manual_journals', (table) => {
table.dropColumn('branch_id');
})
.table('manual_journals_entries', (table) => {
table.dropColumn('branch_id');
})
.table('cashflow_transactions', (table) => {
table.dropColumn('branch_id');
})
.table('refund_credit_note_transactions', (table) => {
table.dropColumn('branch_id');
})
.table('refund_vendor_credit_transactions', (table) => {
table.dropColumn('branch_id');
});
};

View File

@@ -0,0 +1,65 @@
exports.up = (knex) => {
return knex.schema
.table('bills', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('bills_payments', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('vendor_credits', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
})
.table('inventory_adjustments', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
});
};
exports.down = (knex) => {
return knex.schema
.table('bills', (table) => {
table.dropColumn('warehouse_id');
table.dropColumn('branch_id');
})
.table('bills_payments', (table) => {
table.dropColumn('branch_id');
})
.table('vendor_credits', (table) => {
table.dropColumn('branch_id');
table.dropColumn('warehouse_id');
})
.table('inventory_adjustments', (table) => {
table.dropColumn('branch_id');
table.dropColumn('warehouse_id');
});
};

View File

@@ -0,0 +1,84 @@
exports.up = (knex) => {
return knex.schema
.table('sales_invoices', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('sales_estimates', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('sales_receipts', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('payment_receives', (table) => {
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('credit_notes', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
});
};
exports.down = (knex) => {
return knex.schema
.table('sales_invoices', (table) => {
table.dropColumn('warehouse_id');
table.dropColumn('branch_id');
})
.table('sales_estimates', (table) => {
table.dropColumn('warehouse_id');
table.dropColumn('branch_id');
})
.table('sales_receipts', (table) => {
table.dropColumn('warehouse_id');
table.dropColumn('branch_id');
})
.table('payment_receives', (table) => {
table.dropColumn('branch_id');
})
.table('credit_notes', (table) => {
table.dropColumn('warehouse_id');
table.dropColumn('branch_id');
});
};

View File

@@ -0,0 +1,40 @@
exports.up = (knex) => {
return knex.schema
.table('inventory_transactions', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
})
.table('inventory_cost_lot_tracker', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
table
.integer('branch_id')
.unsigned()
.references('id')
.inTable('branches');
});
};
exports.down = (knex) => {
return knex.schema
.table('inventory_transactions', (table) => {
table.dropColumn('warehouse_id');
table.dropColumn('branch_id');
})
.table('inventory_cost_lot_tracker', (table) => {
table.dropColumn('warehouse_id');
table.dropColumn('branch_id');
});
};

View File

@@ -0,0 +1,15 @@
exports.up = (knex) => {
return knex.schema.table('items_entries', (table) => {
table
.integer('warehouse_id')
.unsigned()
.references('id')
.inTable('warehouses');
});
};
exports.down = (knex) => {
return knex.schema.table('items_entries', (table) => {
table.dropColumn('warehouse_id');
});
};

View File

@@ -0,0 +1,114 @@
exports.up = (knex) => {
return knex.schema
.table('sales_invoices', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('sales_estimates', (table) => {
table.decimal('exchange_rate', 13, 9);
})
.table('sales_receipts', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('payment_receives', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('bills', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('bills_payments', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('credit_notes', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('vendor_credits', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('accounts_transactions', (table) => {
table.string('currency_code', 3).after('debit');
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('manual_journals', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('cashflow_transactions', (table) => {
table.string('currency_code', 3).after('amount');
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('expenses_transactions', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('refund_credit_note_transactions', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('refund_vendor_credit_transactions', (table) => {
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('bill_located_costs', (table) => {
table.string('currency_code', 3).after('amount');
table.decimal('exchange_rate', 13, 9).after('currency_code');
})
.table('contacts', (table) => {
table
.decimal('opening_balance_exchange_rate', 13, 9)
.after('opening_balance_at');
})
.table('items', (table) => {
table.dropColumn('currency_code');
});
};
exports.down = (knex) => {
return knex.schema
.table('sales_invoices', (table) => {
table.dropColumn('exchange_rate');
})
.table('sales_estimates', (table) => {
table.dropColumn('exchange_rate');
})
.table('sales_receipts', (table) => {
table.dropColumn('exchange_rate');
})
.table('payment_receives', (table) => {
table.dropColumn('exchange_rate');
})
.table('bills', (table) => {
table.dropColumn('exchange_rate');
})
.table('bills_payments', (table) => {
table.dropColumn('exchange_rate');
})
.table('credit_notes', (table) => {
table.dropColumn('exchange_rate');
})
.table('vendor_credits', (table) => {
table.dropColumn('exchange_rate');
})
.table('accounts_transactions', (table) => {
table.dropColumn('currency_code');
table.dropColumn('exchange_rate');
})
.table('manual_journals', (table) => {
table.dropColumn('exchange_rate');
})
.table('cashflow_transactions', (table) => {
table.dropColumn('currency_code');
table.dropColumn('exchange_rate');
})
.table('expenses_transactions', (table) => {
table.dropColumn('exchange_rate');
})
.table('refund_credit_note_transactions', (table) => {
table.dropColumn('exchange_rate');
})
.table('refund_vendor_credit_transactions', (table) => {
table.dropColumn('exchange_rate');
})
.table('bill_located_costs', (table) => {
table.dropColumn('currency_code');
table.dropColumn('exchange_rate');
})
.table('contacts', (table) => {
table.dropColumn('opening_balance_exchange_rate');
});
};

View File

@@ -0,0 +1,15 @@
exports.up = (knex) => {
return knex.schema.table('sales_invoices', (table) => {
table
.integer('writtenoff_expense_account_id')
.unsigned()
.references('id')
.inTable('accounts');
});
};
exports.down = (knex) => {
return knex.schema.table('sales_invoices', (table) => {
table.dropColumn('writtenoff_expense_account_id');
});
};

View File

@@ -0,0 +1,19 @@
exports.up = (knex) => {
return knex.schema
.raw(
'ALTER TABLE CONTACTS CHANGE SHIPPING_ADDRESS_1 SHIPPING_ADDRESS1 VARCHAR(255)'
)
.raw(
'ALTER TABLE CONTACTS CHANGE SHIPPING_ADDRESS_2 SHIPPING_ADDRESS2 VARCHAR(255)'
)
.raw(
'ALTER TABLE CONTACTS CHANGE BILLING_ADDRESS_1 BILLING_ADDRESS1 VARCHAR(255)'
)
.raw(
'ALTER TABLE CONTACTS CHANGE BILLING_ADDRESS_2 BILLING_ADDRESS2 VARCHAR(255)'
);
};
exports.down = (knex) => {
return knex.schema.table('contacts', (table) => {});
};

View File

@@ -0,0 +1,18 @@
exports.up = (knex) => {
return knex.schema.table('cashflow_transactions', (table) => {
table
.integer('cashflow_account_id')
.unsigned()
.references('id')
.inTable('accounts');
table
.integer('credit_account_id')
.unsigned()
.references('id')
.inTable('accounts');
});
};
exports.down = (knex) => {
return knex.schema.table('cashflow_transactions', () => {});
};

View File

@@ -0,0 +1,7 @@
exports.up = (knex) => {
return knex.schema.table('accounts', (table) => {
table.date('seeded_at').after('currency_code').nullable();
});
};
exports.down = (knex) => {};

View File

@@ -0,0 +1,93 @@
exports.up = (knex) => {
return knex.schema
.createTable('projects', (table) => {
table.increments('id').comment('Auto-generated id');
table.string('name');
table.integer('contact_id').unsigned();
table.date('deadline');
table.decimal('cost_estimate');
table.string('status');
table.timestamps();
})
.createTable('tasks', (table) => {
table.increments('id').comment('Auto-generated id');
table.string('name');
table.string('charge_type');
table.decimal('rate');
table.decimal('estimate_hours').unsigned();
table.decimal('actual_hours').unsigned();
table.decimal('invoiced_hours').unsigned().default(0);
table
.integer('project_id')
.unsigned()
.references('id')
.inTable('projects');
table.timestamps();
})
.createTable('times', (table) => {
table.increments('id').comment('Auto-generated id');
table.integer('duration').unsigned();
table.string('description');
table.date('date');
table.integer('taskId').unsigned().references('id').inTable('tasks');
table
.integer('project_id')
.unsigned()
.references('id')
.inTable('projects');
table.timestamps();
})
.table('accounts_transactions', (table) => {
table
.integer('projectId')
.unsigned()
.references('id')
.inTable('projects');
})
.table('manual_journals_entries', (table) => {
table
.integer('projectId')
.unsigned()
.references('id')
.inTable('projects');
})
.table('bills', (table) => {
table
.integer('projectId')
.unsigned()
.references('id')
.inTable('projects');
table.decimal('invoiced_amount').unsigned().defaultTo(0);
})
.table('items_entries', (table) => {
table
.integer('projectId')
.unsigned()
.references('id')
.inTable('projects');
table.integer('project_ref_id').unsigned();
table.string('project_ref_type');
table.decimal('project_ref_invoiced_amount').unsigned().defaultTo(0);
})
.table('sales_invoices', (table) => {
table
.integer('projectId')
.unsigned()
.references('id')
.inTable('projects');
})
.table('expenses_transactions', (table) => {
table
.integer('projectId')
.unsigned()
.references('id')
.inTable('projects');
table.decimal('invoiced_amount').unsigned().defaultTo(0);
});
};
exports.down = (knex) => {
return knex.schema.dropTable('tasks');
};

View File

@@ -0,0 +1,7 @@
exports.up = (knex) => {
return knex.schema.table('expense_transaction_categories', (table) => {
table.integer('projectId').unsigned().references('id').inTable('projects');
});
};
exports.down = (knex) => {};

View File

@@ -0,0 +1,8 @@
import { Model } from 'objection';
// Bind all Models to a knex instance. If you only have one database in
// your server this is all you have to do. For multi database systems, see
// the Model.bindKnex() method.
export default ({ knex }) => {
Model.knex(knex);
};

View File

@@ -0,0 +1,22 @@
import { TenantSeeder } from '@/lib/Seeder/TenantSeeder';
import AccountsData from '../data/accounts';
export default class SeedAccounts extends TenantSeeder {
/**
* Seeds initial accounts to the organization.
*/
up(knex) {
const data = AccountsData.map((account) => {
return {
...account,
name: this.i18n.__(account.name),
description: this.i18n.__(account.description),
currencyCode: this.tenant.metadata.baseCurrency,
};
});
return knex('accounts').then(async () => {
// Inserts seed entries.
return knex('accounts').insert(data);
});
}
}

View File

@@ -0,0 +1,52 @@
import { TenantSeeder } from '@/lib/Seeder/TenantSeeder';
export default class SeedSettings extends TenantSeeder {
/**
*
* @returns
*/
up() {
const settings = [
// Orgnization settings.
{ group: 'organization', key: 'accounting_basis', value: 'accural' },
// Accounts settings.
{ group: 'accounts', key: 'account_code_unique', value: true },
// Manual journals settings.
{ group: 'manual_journals', key: 'next_number', value: '00001' },
{ group: 'manual_journals', key: 'auto_increment', value: true },
// Sale invoices settings.
{ group: 'sales_invoices', key: 'next_number', value: '00001' },
{ group: 'sales_invoices', key: 'number_prefix', value: 'INV-' },
{ group: 'sales_invoices', key: 'auto_increment', value: true },
// Sale receipts settings.
{ group: 'sales_receipts', key: 'next_number', value: '00001' },
{ group: 'sales_receipts', key: 'number_prefix', value: 'REC-' },
{ group: 'sales_receipts', key: 'auto_increment', value: true },
// Sale estimates settings.
{ group: 'sales_estimates', key: 'next_number', value: '00001' },
{ group: 'sales_estimates', key: 'number_prefix', value: 'EST-' },
{ group: 'sales_estimates', key: 'auto_increment', value: true },
// Payment receives settings.
{ group: 'payment_receives', key: 'number_prefix', value: 'PAY-' },
{ group: 'payment_receives', key: 'next_number', value: '00001' },
{ group: 'payment_receives', key: 'auto_increment', value: true },
// Cashflow settings.
{ group: 'cashflow', key: 'number_prefix', value: 'CF-' },
{ group: 'cashflow', key: 'next_number', value: '00001' },
{ group: 'cashflow', key: 'auto_increment', value: true },
// warehouse transfers settings.
{ group: 'warehouse_transfers', key: 'next_number', value: '00001' },
{ group: 'warehouse_transfers', key: 'number_prefix', value: 'WT-' },
{ group: 'warehouse_transfers', key: 'auto_increment', value: true },
];
return this.knex('settings').insert(settings);
}
}

View File

@@ -0,0 +1,34 @@
import { TenantSeeder } from '@/lib/Seeder/TenantSeeder';
export default class SeedSettings extends TenantSeeder {
/**
*
* @param knex
* @returns
*/
async up(knex) {
const costAccount = await knex('accounts')
.where('slug', 'cost-of-goods-sold')
.first();
const sellAccount = await knex('accounts')
.where('slug', 'sales-of-product-income')
.first();
const inventoryAccount = await knex('accounts')
.where('slug', 'inventory-asset')
.first();
const settings = [
// Items settings.
{ group: 'items', key: 'preferred_sell_account', value: sellAccount?.id },
{ group: 'items', key: 'preferred_cost_account', value: costAccount?.id },
{
group: 'items',
key: 'preferred_inventory_account',
value: inventoryAccount?.id,
},
];
return knex('settings').insert(settings);
}
}

View File

@@ -0,0 +1,28 @@
import { TenantSeeder } from '@/lib/Seeder/TenantSeeder';
export default class SeedRolesAndPermissions extends TenantSeeder {
/**
* Seeds roles and associated permissiojns.
* @param knex
* @returns
*/
// eslint-disable-next-line class-methods-use-this
async up(knex) {
return knex('roles').insert([
{
id: 1,
name: 'role.admin.name',
predefined: true,
slug: 'admin',
description: 'role.admin.desc',
},
{
id: 2,
name: 'role.staff.name',
predefined: true,
slug: 'staff',
description: 'role.staff.desc',
},
]);
}
}

View File

@@ -0,0 +1,49 @@
import { TenantSeeder } from '@/lib/Seeder/TenantSeeder';
export default class SeedRolesAndPermissions extends TenantSeeder {
/**
* Seeds roles and associated permissiojns.
* @param knex
* @returns
*/
// eslint-disable-next-line class-methods-use-this
async up(knex) {
return knex('role_permissions').insert([
// Assign sale invoice permissions to staff role.
{ roleId: 2, subject: 'SaleInvoice', ability: 'create' },
{ roleId: 2, subject: 'SaleInvoice', ability: 'delete' },
{ roleId: 2, subject: 'SaleInvoice', ability: 'view' },
{ roleId: 2, subject: 'SaleInvoice', ability: 'edit' },
// Assign sale estimate permissions to staff role.
{ roleId: 2, subject: 'SaleEstimate', ability: 'create' },
{ roleId: 2, subject: 'SaleEstimate', ability: 'delete' },
{ roleId: 2, subject: 'SaleEstimate', ability: 'view' },
{ roleId: 2, subject: 'SaleEstimate', ability: 'edit' },
// Assign sale receipt permissions to staff role.
{ roleId: 2, subject: 'SaleReceipt', ability: 'create' },
{ roleId: 2, subject: 'SaleReceipt', ability: 'delete' },
{ roleId: 2, subject: 'SaleReceipt', ability: 'view' },
{ roleId: 2, subject: 'SaleReceipt', ability: 'edit' },
// Assign payment receive permissions to staff role.
{ roleId: 2, subject: 'PaymentReceive', ability: 'create' },
{ roleId: 2, subject: 'PaymentReceive', ability: 'delete' },
{ roleId: 2, subject: 'PaymentReceive', ability: 'view' },
{ roleId: 2, subject: 'PaymentReceive', ability: 'edit' },
// Assign bill permissions to staff role.
{ roleId: 2, subject: 'Bill', ability: 'create' },
{ roleId: 2, subject: 'Bill', ability: 'delete' },
{ roleId: 2, subject: 'Bill', ability: 'view' },
{ roleId: 2, subject: 'Bill', ability: 'edit' },
// Assign payment made permissions to staff role.
{ roleId: 2, subject: 'PaymentMade', ability: 'create' },
{ roleId: 2, subject: 'PaymentMade', ability: 'delete' },
{ roleId: 2, subject: 'PaymentMade', ability: 'view' },
{ roleId: 2, subject: 'PaymentMade', ability: 'edit' },
]);
}
}

View File

@@ -0,0 +1,22 @@
import { TenantSeeder } from '@/lib/Seeder/TenantSeeder';
export default class SeedCustomerVendorCreditSettings extends TenantSeeder {
/**
*
* @returns
*/
up() {
const settings = [
// Credit note.
{ group: 'credit_note', key: 'number_prefix', value: 'CN-' },
{ group: 'credit_note', key: 'next_number', value: '00001' },
{ group: 'credit_note', key: 'auto_increment', value: true },
// Vendor credit.
{ group: 'vendor_credit', key: 'number_prefix', value: 'VC-' },
{ group: 'vendor_credit', key: 'next_number', value: '00001' },
{ group: 'vendor_credit', key: 'auto_increment', value: true },
];
return this.knex('settings').insert(settings);
}
}

View File

@@ -0,0 +1 @@
// .gitkeep

View File

@@ -0,0 +1,318 @@
export default [
{
name:'Bank Account',
slug: 'bank-account',
account_type: 'bank',
code: '10001',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Saving Bank Account',
slug: 'saving-bank-account',
account_type: 'bank',
code: '10002',
description: '',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Undeposited Funds',
slug: 'undeposited-funds',
account_type: 'cash',
code: '10003',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Petty Cash',
slug: 'petty-cash',
account_type: 'cash',
code: '10004',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Computer Equipment',
slug: 'computer-equipment',
code: '10005',
account_type: 'fixed-asset',
predefined: 0,
parent_account_id: null,
index: 1,
active: 1,
description: '',
},
{
name:'Office Equipment',
slug: 'office-equipment',
code: '10006',
account_type: 'fixed-asset',
predefined: 0,
parent_account_id: null,
index: 1,
active: 1,
description: '',
},
{
name:'Accounts Receivable (A/R)',
slug: 'accounts-receivable',
account_type: 'accounts-receivable',
code: '10007',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Inventory Asset',
slug: 'inventory-asset',
code: '10008',
account_type: 'inventory',
predefined: 1,
parent_account_id: null,
index: 1,
active: 1,
description:'An account that holds valuation of products or goods that availiable for sale.',
},
// Libilities
{
name:'Accounts Payable (A/P)',
slug: 'accounts-payable',
account_type: 'accounts-payable',
parent_account_id: null,
code: '20001',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Owner A Drawings',
slug: 'owner-drawings',
account_type: 'other-current-liability',
parent_account_id: null,
code: '20002',
description:'Withdrawals by the owners.',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Loan',
slug: 'owner-drawings',
account_type: 'other-current-liability',
code: '20003',
description:'Money that has been borrowed from a creditor.',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Opening Balance Liabilities',
slug: 'opening-balance-liabilities',
account_type: 'other-current-liability',
code: '20004',
description:'This account will hold the difference in the debits and credits entered during the opening balance..',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Revenue Received in Advance',
slug: 'revenue-received-in-advance',
account_type: 'other-current-liability',
parent_account_id: null,
code: '20005',
description: 'When customers pay in advance for products/services.',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Sales Tax Payable',
slug: 'owner-drawings',
account_type: 'other-current-liability',
code: '20006',
description: '',
active: 1,
index: 1,
predefined: 1,
},
// Equity
{
name:'Retained Earnings',
slug: 'retained-earnings',
account_type: 'equity',
code: '30001',
description:'Retained earnings tracks net income from previous fiscal years.',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Opening Balance Equity',
slug: 'opening-balance-equity',
account_type: 'equity',
code: '30002',
description:'When you enter opening balances to the accounts, the amounts enter in Opening balance equity. This ensures that you have a correct trial balance sheet for your company, without even specific the second credit or debit entry.',
active: 1,
index: 1,
predefined: 1,
},
{
name: "Owner's Equity",
slug: 'owner-equity',
account_type: 'equity',
code: '30003',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:`Drawings`,
slug: 'drawings',
account_type: 'equity',
code: '30003',
description:'Goods purchased with the intention of selling these to customers',
active: 1,
index: 1,
predefined: 1,
},
// Expenses
{
name:'Other Expenses',
slug: 'other-expenses',
account_type: 'other-expense',
parent_account_id: null,
code: '40001',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Cost of Goods Sold',
slug: 'cost-of-goods-sold',
account_type: 'cost-of-goods-sold',
parent_account_id: null,
code: '40002',
description:'Tracks the direct cost of the goods sold.',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Office expenses',
slug: 'office-expenses',
account_type: 'expense',
parent_account_id: null,
code: '40003',
description: '',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Rent',
slug: 'rent',
account_type: 'expense',
parent_account_id: null,
code: '40004',
description: '',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Exchange Gain or Loss',
slug: 'exchange-grain-loss',
account_type: 'other-expense',
parent_account_id: null,
code: '40005',
description:'Tracks the gain and losses of the exchange differences.',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Bank Fees and Charges',
slug: 'bank-fees-and-charges',
account_type: 'expense',
parent_account_id: null,
code: '40006',
description: 'Any bank fees levied is recorded into the bank fees and charges account. A bank account maintenance fee, transaction charges, a late payment fee are some examples.',
active: 1,
index: 1,
predefined: 0,
},
{
name:'Depreciation Expense',
slug: 'depreciation-expense',
account_type: 'expense',
parent_account_id: null,
code: '40007',
description: '',
active: 1,
index: 1,
predefined: 0,
},
// Income
{
name:'Sales of Product Income',
slug: 'sales-of-product-income',
account_type: 'income',
predefined: 1,
parent_account_id: null,
code: '50001',
index: 1,
active: 1,
description: '',
},
{
name:'Sales of Service Income',
slug: 'sales-of-service-income',
account_type: 'income',
predefined: 0,
parent_account_id: null,
code: '50002',
index: 1,
active: 1,
description: '',
},
{
name:'Uncategorized Income',
slug: 'uncategorized-income',
account_type: 'income',
parent_account_id: null,
code: '50003',
description: '',
active: 1,
index: 1,
predefined: 1,
},
{
name:'Other Income',
slug: 'other-income',
account_type: 'other-income',
parent_account_id: null,
code: '50004',
description:'The income activities are not associated to the core business.',
active: 1,
index: 1,
predefined: 0,
}
];