turf-common 1.2.1-beta.10 → 1.2.1-beta.11
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.
|
@@ -33,7 +33,7 @@ export declare class BookingCode {
|
|
|
33
33
|
getCodeWithoutTurfCode(): string;
|
|
34
34
|
static sortByCode(bookingCodes: BookingCode[]): void;
|
|
35
35
|
static getOneSlotBookingCode(turfId: string, bookingDate: string, fhfm: string, thtm: string, pitchCode: string): string;
|
|
36
|
-
static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
36
|
+
static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
|
|
37
37
|
static getDiscountAmount(couponCode: string, totalCost: number): number;
|
|
38
38
|
static isValidDate(date: string): boolean;
|
|
39
39
|
static parseDateCode(dateCode: string): Date;
|
|
@@ -116,12 +116,20 @@ var BookingCode = /** @class */ (function () {
|
|
|
116
116
|
var code = turfId + bookingDate + fhfm + thtm + pitchCode;
|
|
117
117
|
return code;
|
|
118
118
|
};
|
|
119
|
-
BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply) {
|
|
119
|
+
BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply, totalBookingHours) {
|
|
120
120
|
if (validationApply === void 0) { validationApply = true; }
|
|
121
121
|
var discount = 0;
|
|
122
122
|
var discountedCost = 0;
|
|
123
123
|
if (couponCode) {
|
|
124
|
-
|
|
124
|
+
var code = couponCode.match(/[a-zA-Z]+/g);
|
|
125
|
+
var value = couponCode.match(/\d+/g);
|
|
126
|
+
if (validationApply && !code && !value) {
|
|
127
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
128
|
+
key: "couponCode",
|
|
129
|
+
message: ["Coupon with code ".concat(couponCode, " is wrong ")],
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (code && (code[0] === "P" || code[0] === "PHP")) {
|
|
125
133
|
var percentDiscount = parseFloat(couponCode);
|
|
126
134
|
if (validationApply) {
|
|
127
135
|
if (percentDiscount > 90) {
|
|
@@ -133,9 +141,20 @@ var BookingCode = /** @class */ (function () {
|
|
|
133
141
|
}
|
|
134
142
|
discount = totalCost * (percentDiscount / 100);
|
|
135
143
|
}
|
|
136
|
-
else if (
|
|
144
|
+
else if (code && code[0] === "U") {
|
|
137
145
|
discount = parseFloat(couponCode);
|
|
138
146
|
}
|
|
147
|
+
else if (code && code[0] === "PHU") {
|
|
148
|
+
if (!totalBookingHours) {
|
|
149
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
150
|
+
key: "totalBookingHours",
|
|
151
|
+
message: [
|
|
152
|
+
"Total Booking Hours is mandatory to calculate per hour unit",
|
|
153
|
+
],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
discount = parseFloat(couponCode) * totalBookingHours;
|
|
157
|
+
}
|
|
139
158
|
}
|
|
140
159
|
discountedCost = totalCost - discount;
|
|
141
160
|
return Math.round(discountedCost);
|
|
@@ -18,7 +18,7 @@ export declare class ChargesModel implements IChargeModel {
|
|
|
18
18
|
getNetAmount(): number;
|
|
19
19
|
getDiscountAmount(): number;
|
|
20
20
|
getPayableRefundAmount(): number;
|
|
21
|
-
static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
21
|
+
static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean, totalBookingHours?: number): number;
|
|
22
22
|
setValues(values?: Partial<ChargesModel>): ChargesModel;
|
|
23
23
|
modify(bookingModification: IBookingModification): ChargesModel | null;
|
|
24
24
|
private modifyExtend;
|
|
@@ -46,11 +46,19 @@ var ChargesModel = /** @class */ (function () {
|
|
|
46
46
|
// this.totalRefundAmount = this.totalRefundAmount - refundAmount;
|
|
47
47
|
// this.refundedAmount += refundAmount;
|
|
48
48
|
// }
|
|
49
|
-
ChargesModel.getDiscountAmount = function (couponCode, totalCost, validationApply) {
|
|
49
|
+
ChargesModel.getDiscountAmount = function (couponCode, totalCost, validationApply, totalBookingHours) {
|
|
50
50
|
if (validationApply === void 0) { validationApply = false; }
|
|
51
51
|
var discountAmount = 0;
|
|
52
52
|
if (couponCode) {
|
|
53
|
-
|
|
53
|
+
var code = couponCode.match(/[a-zA-Z]+/g);
|
|
54
|
+
var value = couponCode.match(/\d+/g);
|
|
55
|
+
if (validationApply && !code && !value) {
|
|
56
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
57
|
+
key: "couponCode",
|
|
58
|
+
message: ["Coupon with code ".concat(couponCode, " is wrong ")],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (code && (code[0] === "P" || code[0] === "PHP")) {
|
|
54
62
|
var percentDiscount = parseFloat(couponCode);
|
|
55
63
|
if (validationApply && percentDiscount > 90) {
|
|
56
64
|
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
@@ -60,9 +68,20 @@ var ChargesModel = /** @class */ (function () {
|
|
|
60
68
|
}
|
|
61
69
|
discountAmount = totalCost * (percentDiscount / 100);
|
|
62
70
|
}
|
|
63
|
-
else if (
|
|
71
|
+
else if (code && code[0] === "U") {
|
|
64
72
|
discountAmount = parseFloat(couponCode);
|
|
65
73
|
}
|
|
74
|
+
else if (code && code[0] === "PHU") {
|
|
75
|
+
if (!totalBookingHours) {
|
|
76
|
+
throw new app_badrequest_exception_1.AppBadRequestException({
|
|
77
|
+
key: "totalBookingHours",
|
|
78
|
+
message: [
|
|
79
|
+
"Total Booking Hours is mandatory to calculate per hour unit",
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
discountAmount = parseFloat(couponCode) * totalBookingHours;
|
|
84
|
+
}
|
|
66
85
|
}
|
|
67
86
|
return Math.round(discountAmount);
|
|
68
87
|
};
|