refactoring: custom views service.

fix: constraints of delete item from storage.
fix: constraints of delete item category from storage.
fix: localize database seeds files.
fix: view meta data in accounts list response.
This commit is contained in:
Ahmed Bouhuolia
2020-10-05 19:09:56 +02:00
parent 0114ed9f8b
commit 99e6fe273f
64 changed files with 1593 additions and 1103 deletions

View File

@@ -2,7 +2,6 @@
exports.up = (knex) => {
return knex.schema.createTable('account_types', (table) => {
table.increments();
table.string('name');
table.string('key').index();
table.string('normal').index();
table.string('root_type').index();

View File

@@ -1,8 +1,14 @@
import Container from 'typedi';
import TenancyService from 'services/Tenancy/TenancyService'
import I18nMiddleware from 'api/middleware/I18nMiddleware';
exports.up = function (knex) {
const tenancyService = Container.get(TenancyService);
const i18n = tenancyService.i18n(knex.userParams.tenantId);
return knex('account_types').insert([
{
id: 1,
name: 'Fixed Asset',
key: 'fixed_asset',
normal: 'debit',
root_type: 'asset',
@@ -12,7 +18,6 @@ exports.up = function (knex) {
},
{
id: 2,
name: 'Current Asset',
key: 'current_asset',
normal: 'debit',
root_type: 'asset',
@@ -22,7 +27,6 @@ exports.up = function (knex) {
},
{
id: 14,
name: 'Other Asset',
key: 'other_asset',
normal: 'debit',
root_type: 'asset',
@@ -32,7 +36,6 @@ exports.up = function (knex) {
},
{
id: 3,
name: 'Long Term Liability',
key: 'long_term_liability',
normal: 'credit',
root_type: 'liability',
@@ -42,7 +45,6 @@ exports.up = function (knex) {
},
{
id: 4,
name: 'Current Liability',
key: 'current_liability',
normal: 'credit',
root_type: 'liability',
@@ -52,7 +54,6 @@ exports.up = function (knex) {
},
{
id: 13,
name: 'Other Liability',
key: 'other_liability',
normal: 'credit',
root_type: 'liability',
@@ -62,7 +63,6 @@ exports.up = function (knex) {
},
{
id: 5,
name: 'Equity',
key: 'equity',
normal: 'credit',
root_type: 'equity',
@@ -72,7 +72,6 @@ exports.up = function (knex) {
},
{
id: 6,
name: 'Expense',
key: 'expense',
normal: 'debit',
root_type: 'expense',
@@ -82,7 +81,6 @@ exports.up = function (knex) {
},
{
id: 10,
name: 'Other Expense',
key: 'other_expense',
normal: 'debit',
root_type: 'expense',
@@ -91,7 +89,6 @@ exports.up = function (knex) {
},
{
id: 7,
name: 'Income',
key: 'income',
normal: 'credit',
root_type: 'income',
@@ -101,7 +98,6 @@ exports.up = function (knex) {
},
{
id: 11,
name: 'Other Income',
key: 'other_income',
normal: 'credit',
root_type: 'income',
@@ -111,7 +107,6 @@ exports.up = function (knex) {
},
{
id: 12,
name: 'Cost of Goods Sold (COGS)',
key: 'cost_of_goods_sold',
normal: 'debit',
root_type: 'expenses',
@@ -121,7 +116,6 @@ exports.up = function (knex) {
},
{
id: 8,
name: 'Accounts Receivable (A/R)',
key: 'accounts_receivable',
normal: 'debit',
root_type: 'asset',
@@ -131,7 +125,6 @@ exports.up = function (knex) {
},
{
id: 9,
name: 'Accounts Payable (A/P)',
key: 'accounts_payable',
normal: 'credit',
root_type: 'liability',

View File

@@ -1,16 +1,18 @@
import TenancyService from 'services/Tenancy/TenancyService'
import Container from 'typedi';
import TenancyService from 'services/Tenancy/TenancyService'
exports.up = function (knex) {
const tenancyService = Container.get(TenancyService);
const i18n = tenancyService.i18n(knex.userParams.tenantId);
console.log(i18n);
return knex('accounts').then(() => {
// Inserts seed entries
return knex('accounts').insert([
{
id: 1,
name: 'Petty Cash',
name: i18n.__('Petty Cash'),
slug: 'petty-cash',
account_type_id: 2,
parent_account_id: null,
@@ -22,7 +24,7 @@ exports.up = function (knex) {
},
{
id: 2,
name: 'Bank',
name: i18n.__('Bank'),
slug: 'bank',
account_type_id: 2,
parent_account_id: null,
@@ -34,7 +36,7 @@ exports.up = function (knex) {
},
{
id: 3,
name: 'Other Income',
name: i18n.__('Other Income'),
slug: 'other-income',
account_type_id: 7,
parent_account_id: null,
@@ -46,7 +48,7 @@ exports.up = function (knex) {
},
{
id: 4,
name: 'Interest Income',
name: i18n.__('Interest Income'),
slug: 'interest-income',
account_type_id: 7,
parent_account_id: null,
@@ -58,7 +60,7 @@ exports.up = function (knex) {
},
{
id: 5,
name: 'Opening Balance',
name: i18n.__('Opening Balance'),
slug: 'opening-balance',
account_type_id: 5,
parent_account_id: null,
@@ -70,7 +72,7 @@ exports.up = function (knex) {
},
{
id: 6,
name: 'Depreciation Expense',
name: i18n.__('Depreciation Expense'),
slug: 'depreciation-expense',
account_type_id: 6,
parent_account_id: null,
@@ -82,7 +84,7 @@ exports.up = function (knex) {
},
{
id: 7,
name: 'Interest Expense',
name: i18n.__('Interest Expense'),
slug: 'interest-expense',
account_type_id: 6,
parent_account_id: null,
@@ -94,7 +96,7 @@ exports.up = function (knex) {
},
{
id: 8,
name: 'Payroll Expenses',
name: i18n.__('Payroll Expenses'),
slug: 'payroll-expenses',
account_type_id: 6,
parent_account_id: null,
@@ -106,7 +108,7 @@ exports.up = function (knex) {
},
{
id: 9,
name: 'Other Expenses',
name: i18n.__('Other Expenses'),
slug: 'other-expenses',
account_type_id: 6,
parent_account_id: null,
@@ -118,7 +120,7 @@ exports.up = function (knex) {
},
{
id: 10,
name: 'Accounts Receivable',
name: i18n.__('Accounts Receivable'),
slug: 'accounts-receivable',
account_type_id: 8,
parent_account_id: null,
@@ -130,7 +132,7 @@ exports.up = function (knex) {
},
{
id: 11,
name: 'Accounts Payable',
name: i18n.__('Accounts Payable'),
slug: 'accounts-payable',
account_type_id: 9,
parent_account_id: null,
@@ -142,7 +144,7 @@ exports.up = function (knex) {
},
{
id: 12,
name: 'Cost of Goods Sold (COGS)',
name: i18n.__('Cost of Goods Sold (COGS)'),
slug: 'cost-of-goods-sold',
account_type_id: 12,
predefined: 1,
@@ -153,7 +155,7 @@ exports.up = function (knex) {
},
{
id: 13,
name: 'Inventory Asset',
name: i18n.__('Inventory Asset'),
slug: 'inventory-asset',
account_type_id: 14,
predefined: 1,
@@ -164,7 +166,7 @@ exports.up = function (knex) {
},
{
id: 14,
name: 'Sales of Product Income',
name: i18n.__('Sales of Product Income'),
slug: 'sales-of-product-income',
account_type_id: 7,
predefined: 1,

View File

@@ -1,17 +1,20 @@
exports.up = (knex) => {
const tenancyService = Container.get(TenancyService);
const i18n = tenancyService.i18n(knex.userParams.tenantId);
// Deletes ALL existing entries
return knex('views').del()
.then(() => {
// Inserts seed entries
return knex('views').insert([
// Accounts
{ id: 15, name: 'Inactive', roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 1, name: 'Assets', roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 2, name: 'Liabilities', roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 3, name: 'Equity', roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 4, name: 'Income', roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 5, name: 'Expenses', roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 15, name: i18n.__('Inactive'), roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 1, name: i18n.__('Assets'), roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 2, name: i18n.__('Liabilities'), roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 3, name: i18n.__('Equity'), roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 4, name: i18n.__('Income'), roles_logic_expression: '1', resource_model: 'Account', predefined: true },
{ id: 5, name: i18n.__('Expenses'), roles_logic_expression: '1', resource_model: 'Account', predefined: true },
// Items
// { id: 6, name: 'Services', roles_logic_expression: '1', resource_id: 2, predefined: true },