feat: Ability to hide/show financial statement header.

This commit is contained in:
Ahmed Bouhuolia
2020-05-27 20:21:05 +02:00
parent 2e8ffa2aa9
commit c1659d191f
47 changed files with 914 additions and 301 deletions

View File

@@ -1,10 +1,16 @@
const commander = require('commander');
const { knexSnakeCaseMappers } = require('objection');
const Knex = require('knex');
const color = require('colorette');
const argv = require('getopts')(process.argv.slice(2));
const systemConfig = require('../config/systemKnexfile');
const config = require('../config/config');
const {
initSystemKnex,
getAllSystemTenants,
initTenantKnex,
exit,
success,
log,
} = require('./utils');
const lincenseCommander = require('./license');
// - bigcapital system:migrate:latest
// - bigcapital system:migrate:rollback
@@ -16,57 +22,8 @@ const config = require('../config/config');
// - bigcapital system:migrate:make
// - bigcapital tenants:list
function initSystemKnex() {
return Knex({
...systemConfig['production'],
...knexSnakeCaseMappers({ upperCase: true }),
});
}
function getAllSystemTenants(knex) {
return knex('tenants');
}
function initTenantKnex(organizationId) {
return Knex({
client: config.tenant.db_client,
connection: {
host: config.tenant.db_host,
user: config.tenant.db_user,
password: config.tenant.db_password,
database: `${config.tenant.db_name_prefix}${organizationId}`,
charset: config.tenant.charset,
},
migrations: {
directory: config.tenant.migrations_dir,
},
seeds: {
directory: config.tenant.seeds_dir,
},
pool: { min: 0, max: 5 },
...knexSnakeCaseMappers({ upperCase: true }),
})
}
function exit(text) {
if (text instanceof Error) {
console.error(
color.red(`${text.detail ? `${text.detail}\n` : ''}${text.stack}`)
);
} else {
console.error(color.red(text));
}
process.exit(1);
}
function success(text) {
console.log(text);
process.exit(0);
}
function log(text) {
console.log(text);
}
// - bigcapital license:generate
// - bigcapital licenses:list
commander
.command('system:migrate:rollback')

57
server/bin/license.js Normal file
View File

@@ -0,0 +1,57 @@
const commander = require('commander');
const color = require('colorette');
const argv = require('getopts')(process.argv.slice(2));
const cryptoRandomString = require('crypto-random-string');
const {
initSystemKnex,
getAllSystemTenants,
initTenantKnex,
exit,
success,
log,
} = require('./utils');
// License generate key.
commander
.command('license:generate <license_period>')
.description('Generates a new license key.')
.action(async (interval) => {
try {
const sysDb = initSystemKnex();
let repeat = true;
while(repeat) {
key = cryptoRandomString(16).toUpperCase();
const license = await sysDb('subscription_licenses').where('key', key);
if (license.length === 0) {
repeat = false;
}
}
const licenseIds = await sysDb('subscription_licenses').insert({
key,
license_period: interval ? parseInt(interval, 10) : 1,
license_interval: 'month',
});
const license = await sysDb('subscription_licenses').where('id', licenseIds[0]).first();
success(`ID: ${license.id} | License: ${license.key} | Interval: ${license.licenseInterval} | Period: ${license.licensePeriod}`);
} catch(error) {
exit(error);
}
});
// Retrieve licenses list.
commander
.command('licenses:list')
.description('Retrieve a list of subscription licenses.')
.action(async () => {
const sysDb = initSystemKnex();
const licenses = await sysDb('subscription_licenses');
licenses.forEach((license) => {
log(`ID: ${license.id} | Key: ${license.key} | Interval: ${license.licenseInterval} | Period: ${license.licensePeriod}`);
});
exit();
});
commander.parse(process.argv);

67
server/bin/utils.js Normal file
View File

@@ -0,0 +1,67 @@
const Knex = require('knex');
const { knexSnakeCaseMappers } = require('objection');
const color = require('colorette');
const config = require('../config/config');
const systemConfig = require('../config/systemKnexfile');
function initSystemKnex() {
return Knex({
...systemConfig['production'],
...knexSnakeCaseMappers({ upperCase: true }),
});
}
function getAllSystemTenants(knex) {
return knex('tenants');
}
function initTenantKnex(organizationId) {
return Knex({
client: config.tenant.db_client,
connection: {
host: config.tenant.db_host,
user: config.tenant.db_user,
password: config.tenant.db_password,
database: `${config.tenant.db_name_prefix}${organizationId}`,
charset: config.tenant.charset,
},
migrations: {
directory: config.tenant.migrations_dir,
},
seeds: {
directory: config.tenant.seeds_dir,
},
pool: { min: 0, max: 5 },
...knexSnakeCaseMappers({ upperCase: true }),
})
}
function exit(text) {
if (text instanceof Error) {
console.error(
color.red(`${text.detail ? `${text.detail}\n` : ''}${text.stack}`)
);
} else {
console.error(color.red(text));
}
process.exit(1);
}
function success(text) {
console.log(text);
process.exit(0);
}
function log(text) {
console.log(text);
}
module.exports = {
initTenantKnex,
initSystemKnex,
getAllSystemTenants,
exit,
success,
log,
}

View File

@@ -0,0 +1,22 @@
exports.seed = (knex) => {
// Deletes ALL existing entries
return knex('subscriptions_plans').del()
.then(() => {
// Inserts seed entries
return knex('subscriptions_plans').insert([
{
id: 1,
name: 'basic',
price: 80,
signup_fee: 0,
currency: 'LYD',
trial_period: 0,
trial_interval: '',
invoice_period: 1,
invoice_interval: 'month',
}
]);
});
};

View File

@@ -0,0 +1,8 @@
const subscriptionObserver = (req, res, next) => {
};
export default subscriptionObserver;

View File

@@ -0,0 +1,22 @@
export default (Model) => {
return class UserSubscription extends Model{
onTrial() {
}
getSubscription() {
}
newSubscription() {
}
isSubcribedTo(plan) {
}
}
};

View File

@@ -0,0 +1,28 @@
exports.up = function(knex) {
return knex.schema.createTable('subscriptions_plans', table => {
table.increments();
table.string('name');
table.string('description');
table.decimal('price');
table.decimal('signup_fee');
table.string('currency', 3);
table.integer('trial_period');
table.string('trial_interval');
table.integer('invoice_period');
table.string('invoice_interval');
table.timestamps();
}).then(() => {
return knex.seed.run({
specific: 'seed_subscriptions_plans.js'
})
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('subscriptions_plans')
};

View File

@@ -0,0 +1,18 @@
exports.up = function(knex) {
return knex.schema.createTable('subscriptions_usage', table => {
table.increments();
table.integer('user_id');
table.integer('plan_id');
table.dateTime('trial_ends_at');
table.dateTime('subscription_starts_at');
table.dateTime('subscription_ends_at');
table.timestamps();
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('subscriptions_usage');
};

View File

@@ -0,0 +1,14 @@
exports.up = function(knex) {
return knex.schema.createTable('subscription_licenses', table => {
table.increments();
table.string('key');
table.integer('license_period');
table.string('license_interval');
table.boolean('used').defaultTo(false);
});
};
exports.down = function(knex) {
return knex.schema.dropTableIfExists('subscription_licenses');
};

View File

@@ -0,0 +1,18 @@
import { Model, mixin } from 'objection';
import SystemModel from '@/system/models/SystemModel';
import DateSession from '@/models/DateSession';
import UserSubscription from '@/services/Subscription/UserSubscription';
export default class SubscriptionLicense extends mixin(SystemModel, [DateSession, UserSubscription]) {
/**
* Table name.
*/
static get tableName() {
return 'subscription_licences';
}
markAsUsed() {
}
}

View File

@@ -0,0 +1,10 @@
import SystemModel from '@/system/models/SystemModel';
export default class SubscriptionPlan extends SystemModel {
/**
* Table name
*/
static get tableName() {
return 'subscriptions_plans';
}
}

View File

@@ -0,0 +1,10 @@
import SystemModel from '@/system/models/SystemModel';
export default class SubscriptionUsage extends SystemModel {
/**
* Table name
*/
static get tableName() {
return 'subscriptions_usage';
}
}

View File

@@ -2,9 +2,10 @@ import { Model, mixin } from 'objection';
import bcrypt from 'bcryptjs';
import SystemModel from '@/system/models/SystemModel';
import DateSession from '@/models/DateSession';
import UserSubscription from '@/services/Subscription/UserSubscription';
export default class SystemUser extends mixin(SystemModel, [DateSession]) {
export default class SystemUser extends mixin(SystemModel, [DateSession, UserSubscription]) {
/**
* Table name.
*/
@@ -17,6 +18,7 @@ export default class SystemUser extends mixin(SystemModel, [DateSession]) {
*/
static get relationMappings() {
const Tenant = require('@/system/models/Tenant');
const SubscriptionUsage = require('@/system/models/SubscriptionUsage');
return {
tenant: {
@@ -27,6 +29,15 @@ export default class SystemUser extends mixin(SystemModel, [DateSession]) {
to: 'tenants.id',
},
},
subscriptionUsage: {
relation: Model.BelongsToOneRelation,
modelClass: SubscriptionUsage.default,
join: {
from: 'users.id',
to: 'subscriptions_usage.user_id',
}
},
};
}