turf-common 1.1.1-beta.51 → 1.1.1-beta.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -18,7 +18,9 @@ export declare class SubscribedPricingPlanModel extends PricingPlanModel {
|
|
|
18
18
|
getGrossAmount(config?: {
|
|
19
19
|
roundDown: boolean;
|
|
20
20
|
}): number;
|
|
21
|
-
getNetAmount(
|
|
21
|
+
getNetAmount(config?: {
|
|
22
|
+
roundDown: boolean;
|
|
23
|
+
}): number;
|
|
22
24
|
getBillingDiscount(): number;
|
|
23
25
|
getMonthDifference(that: SubscribedPricingPlanModel): number;
|
|
24
26
|
getGrossAmountByMonth(month: number): number;
|
|
@@ -30,4 +32,6 @@ export declare class SubscribedPricingPlanModel extends PricingPlanModel {
|
|
|
30
32
|
getNextBillingCycleDateRange(date: Date): [Date, Date];
|
|
31
33
|
static getInstanceBySubscriptionData(data: IGetPricingPlanByDateResponse, subscriptionDataModel: SubscriptionModel): SubscribedPricingPlanModel;
|
|
32
34
|
getSelectedPitchSlabBasePrice(): number;
|
|
35
|
+
getBasePriceBySelectedBillingCycleDiscount(): number;
|
|
36
|
+
getTotalHours(): number;
|
|
33
37
|
}
|
|
@@ -17,6 +17,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SubscribedPricingPlanModel = void 0;
|
|
19
19
|
var date_util_1 = require("../utils/date-util");
|
|
20
|
+
var math_util_1 = require("../utils/math-util");
|
|
20
21
|
var pricing_plan_model_1 = require("./pricing-plan-model");
|
|
21
22
|
var SubscribedPricingPlanModel = /** @class */ (function (_super) {
|
|
22
23
|
__extends(SubscribedPricingPlanModel, _super);
|
|
@@ -37,27 +38,34 @@ var SubscribedPricingPlanModel = /** @class */ (function (_super) {
|
|
|
37
38
|
return this.selectedPitchSlabBasePrice;
|
|
38
39
|
};
|
|
39
40
|
SubscribedPricingPlanModel.prototype.getGrossAmount = function (config) {
|
|
40
|
-
if (config === void 0) { config = { roundDown:
|
|
41
|
+
if (config === void 0) { config = { roundDown: false }; }
|
|
41
42
|
var roundDown = config.roundDown;
|
|
42
43
|
if (!roundDown) {
|
|
43
44
|
return Math.round(this.selectedPitchSlabBasePrice *
|
|
44
45
|
this.pitchCount *
|
|
45
|
-
this.
|
|
46
|
-
this.selectedBillingCycle.to);
|
|
46
|
+
this.getTotalHours());
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
-
return
|
|
49
|
+
return Math.floor(this.selectedPitchSlabBasePrice *
|
|
50
50
|
this.pitchCount *
|
|
51
|
-
this.
|
|
52
|
-
this.selectedBillingCycle.to));
|
|
51
|
+
this.getTotalHours());
|
|
53
52
|
}
|
|
54
53
|
};
|
|
55
|
-
SubscribedPricingPlanModel.prototype.getNetAmount = function () {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
this.
|
|
60
|
-
|
|
54
|
+
SubscribedPricingPlanModel.prototype.getNetAmount = function (config) {
|
|
55
|
+
if (config === void 0) { config = { roundDown: false }; }
|
|
56
|
+
var roundDown = config.roundDown;
|
|
57
|
+
if (!roundDown) {
|
|
58
|
+
return Math.round(this.selectedPitchSlabBasePrice *
|
|
59
|
+
(1 - this.getBillingDiscount() / 100) *
|
|
60
|
+
this.pitchCount *
|
|
61
|
+
this.getTotalHours());
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return Math.floor(this.selectedPitchSlabBasePrice *
|
|
65
|
+
(1 - this.getBillingDiscount() / 100) *
|
|
66
|
+
this.pitchCount *
|
|
67
|
+
this.getTotalHours());
|
|
68
|
+
}
|
|
61
69
|
};
|
|
62
70
|
SubscribedPricingPlanModel.prototype.getBillingDiscount = function () {
|
|
63
71
|
return this.selectedBillingCycle.getDiscount();
|
|
@@ -106,6 +114,13 @@ var SubscribedPricingPlanModel = /** @class */ (function (_super) {
|
|
|
106
114
|
SubscribedPricingPlanModel.prototype.getSelectedPitchSlabBasePrice = function () {
|
|
107
115
|
return this.selectedPitchSlabBasePrice;
|
|
108
116
|
};
|
|
117
|
+
SubscribedPricingPlanModel.prototype.getBasePriceBySelectedBillingCycleDiscount = function () {
|
|
118
|
+
return (this.selectedPitchSlabBasePrice -
|
|
119
|
+
math_util_1.mathUtil.getDiscountAmount(this.selectedBillingCycle.discount, this.selectedPitchSlabBasePrice));
|
|
120
|
+
};
|
|
121
|
+
SubscribedPricingPlanModel.prototype.getTotalHours = function () {
|
|
122
|
+
return this.hourInMonth * this.selectedBillingCycle.to;
|
|
123
|
+
};
|
|
109
124
|
return SubscribedPricingPlanModel;
|
|
110
125
|
}(pricing_plan_model_1.PricingPlanModel));
|
|
111
126
|
exports.SubscribedPricingPlanModel = SubscribedPricingPlanModel;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class MathUtil {
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the discount amount based on the provided coupon code and total cost.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} couponCode - The coupon code used for the discount. If the code ends with "P", it's treated as a percentage discount. If it ends with "U", it's treated as a unit discount.
|
|
6
|
+
* @param {number} totalCost - The total cost before any discounts are applied.
|
|
7
|
+
* @param {boolean} [validationApply=false] - Decides whether to validate if the percentage discount is more than 90 or not.
|
|
8
|
+
* @returns {number} The calculated discount amount. If the couponCode ends with "P", the discount amount is the percentage of the totalCost. If the couponCode ends with "U", the discount amount is the parsed float value of the couponCode. If no couponCode is provided, the method returns 0. If the validationApply is true and the percentage discount is more than 90, it throws an AppBadRequestException with a message "Discount should not be more than 90P".
|
|
9
|
+
* @throws {AppBadRequestException} If validationApply is true and the percentage discount is more than 90.
|
|
10
|
+
*/
|
|
11
|
+
getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
12
|
+
}
|
|
13
|
+
export declare const mathUtil: MathUtil;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mathUtil = void 0;
|
|
4
|
+
var app_badrequest_exception_1 = require("../exceptions/app-badrequest.exception");
|
|
5
|
+
var MathUtil = /** @class */ (function () {
|
|
6
|
+
function MathUtil() {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Calculates the discount amount based on the provided coupon code and total cost.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} couponCode - The coupon code used for the discount. If the code ends with "P", it's treated as a percentage discount. If it ends with "U", it's treated as a unit discount.
|
|
12
|
+
* @param {number} totalCost - The total cost before any discounts are applied.
|
|
13
|
+
* @param {boolean} [validationApply=false] - Decides whether to validate if the percentage discount is more than 90 or not.
|
|
14
|
+
* @returns {number} The calculated discount amount. If the couponCode ends with "P", the discount amount is the percentage of the totalCost. If the couponCode ends with "U", the discount amount is the parsed float value of the couponCode. If no couponCode is provided, the method returns 0. If the validationApply is true and the percentage discount is more than 90, it throws an AppBadRequestException with a message "Discount should not be more than 90P".
|
|
15
|
+
* @throws {AppBadRequestException} If validationApply is true and the percentage discount is more than 90.
|
|
16
|
+
*/
|
|
17
|
+
MathUtil.prototype.getDiscountAmount = function (couponCode, totalCost, validationApply) {
|
|
18
|
+
if (validationApply === void 0) { validationApply = false; }
|
|
19
|
+
var discountAmount = 0;
|
|
20
|
+
if (couponCode) {
|
|
21
|
+
if (couponCode.slice(-1) === "P") {
|
|
22
|
+
var percentDiscount = parseFloat(couponCode);
|
|
23
|
+
if (validationApply && percentDiscount > 90) {
|
|
24
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
25
|
+
key: "couponCode",
|
|
26
|
+
message: ["Discount should not be more than 90P"],
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
discountAmount = totalCost * (percentDiscount / 100);
|
|
30
|
+
}
|
|
31
|
+
else if (couponCode.slice(-1) === "U") {
|
|
32
|
+
discountAmount = parseFloat(couponCode);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return discountAmount;
|
|
36
|
+
};
|
|
37
|
+
return MathUtil;
|
|
38
|
+
}());
|
|
39
|
+
exports.mathUtil = new MathUtil();
|