mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 04:10:32 +00:00
feat: abstract the pricing plans for setup and billing page
This commit is contained in:
@@ -8,7 +8,7 @@ export class GetSubscriptionsTransformer extends Transformer {
|
||||
public includeAttributes = (): string[] => {
|
||||
return [
|
||||
'canceledAtFormatted',
|
||||
'cancelsAtFormatted',
|
||||
'endsAtFormatted',
|
||||
'trialStartsAtFormatted',
|
||||
'trialEndsAtFormatted',
|
||||
'statusFormatted',
|
||||
@@ -42,13 +42,13 @@ export class GetSubscriptionsTransformer extends Transformer {
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the cancels at formatted.
|
||||
* Retrieves the ends at date formatted.
|
||||
* @param subscription
|
||||
* @returns {string}
|
||||
*/
|
||||
public cancelsAtFormatted = (subscription) => {
|
||||
public endsAtFormatted = (subscription) => {
|
||||
return subscription.cancelsAt
|
||||
? this.formatDate(subscription.cancelsAt)
|
||||
? this.formatDate(subscription.endsAt)
|
||||
: null;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
exports.up = function (knex) {
|
||||
return knex.schema.table('subscription_plan_subscriptions', (table) => {
|
||||
table.dateTime('trial_starts_at').nullable();
|
||||
table.dateTime('trial_ends_at').nullable();
|
||||
table.dropColumn('cancels_at');
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex) {
|
||||
return knex.schema.table('subscription_plan_subscriptions', (table) => {
|
||||
table.dropColumn('trial_starts_at').nullable();
|
||||
table.dropColumn('trial_ends_at').nullable();
|
||||
table.dateTime('cancels_at').nullable();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -4,16 +4,14 @@ import moment from 'moment';
|
||||
import SubscriptionPeriod from '@/services/Subscription/SubscriptionPeriod';
|
||||
|
||||
export default class PlanSubscription extends mixin(SystemModel) {
|
||||
lemonSubscriptionId: number;
|
||||
public lemonSubscriptionId: number;
|
||||
|
||||
canceledAt: Date;
|
||||
cancelsAt: Date;
|
||||
public endsAt: Date;
|
||||
public startsAt: Date;
|
||||
|
||||
trialStartsAt: Date;
|
||||
trialEndsAt: Date;
|
||||
public canceledAt: Date;
|
||||
|
||||
endsAt: Date;
|
||||
startsAt: Date;
|
||||
public trialEndsAt: Date;
|
||||
|
||||
/**
|
||||
* Table name.
|
||||
@@ -109,26 +107,15 @@ export default class PlanSubscription extends mixin(SystemModel) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the subscription is expired.
|
||||
* Expired mens the user his lost the right to use the product.
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
public expired() {
|
||||
return this.ended() && !this.onTrial();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if paid subscription is active.
|
||||
* Check if the subscription is active.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public active() {
|
||||
return (
|
||||
!this.canceled() && !this.onTrial() && !this.ended() && this.started()
|
||||
);
|
||||
return this.onTrial() || !this.ended();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if subscription is inactive.
|
||||
* Check if the subscription is inactive.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public inactive() {
|
||||
@@ -164,11 +151,7 @@ export default class PlanSubscription extends mixin(SystemModel) {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public canceled() {
|
||||
return (
|
||||
this.canceledAt ||
|
||||
(this.cancelsAt && moment().isAfter(this.cancelsAt)) ||
|
||||
false
|
||||
);
|
||||
return !!this.canceledAt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user