turf-common 1.0.2 → 1.0.4
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.
- package/build/exceptions/app-badrequest.exception.d.ts +1 -1
- package/build/exceptions/app-badrequest.exception.js +5 -1
- package/build/interface/charge-model.interface.d.ts +12 -0
- package/build/models/charge-model.d.ts +1 -12
- package/package.json +1 -1
- package/build/modules/app-badrequest-exception-module/app-badrequest-exception-model.d.ts +0 -5
- package/build/modules/app-badrequest-exception-module/app-badrequest-exception-model.js +0 -28
- package/build/modules/app-badrequest-exception-module/types/app-badrequest-exception.type.d.ts +0 -4
- package/build/modules/booking-module/booking-code-model.d.ts +0 -71
- package/build/modules/booking-module/booking-code-model.js +0 -407
- package/build/modules/booking-module/interfaces/get-booking-codes-per-thirty-min.interface.d.ts +0 -4
- package/build/modules/booking-module/interfaces/get-booking-codes-per-thirty-min.interface.js +0 -2
- package/build/modules/charge-module/charge-model.d.ts +0 -44
- package/build/modules/charge-module/charge-model.js +0 -227
- package/build/modules/charge-module/enums/modification-discount-policy.enum.d.ts +0 -5
- package/build/modules/charge-module/enums/modification-discount-policy.enum.js +0 -9
- package/build/modules/charge-module/types/booking-modification.type.d.ts +0 -6
- package/build/modules/charge-module/types/booking-modification.type.js +0 -2
- package/build/modules/date-module/date-code-model.d.ts +0 -8
- package/build/modules/date-module/date-code-model.js +0 -38
- package/build/modules/time-slot-module/time-slot-model.d.ts +0 -18
- package/build/modules/time-slot-module/time-slot-model.js +0 -95
- /package/build/{modules/app-badrequest-exception-module/types/app-badrequest-exception.type.js → interface/charge-model.interface.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAppBadRequestException } from "../types/app-badrequest-exception.type";
|
|
2
2
|
export declare class AppBadRequestException extends Error {
|
|
3
|
-
appBadRequestException: IAppBadRequestException;
|
|
4
3
|
constructor(appBadRequestException: IAppBadRequestException);
|
|
4
|
+
parse(appBadRequestException: IAppBadRequestException): IAppBadRequestException;
|
|
5
5
|
}
|
|
@@ -18,11 +18,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.AppBadRequestException = void 0;
|
|
19
19
|
var AppBadRequestException = /** @class */ (function (_super) {
|
|
20
20
|
__extends(AppBadRequestException, _super);
|
|
21
|
+
// appBadRequestException: IAppBadRequestException;
|
|
21
22
|
function AppBadRequestException(appBadRequestException) {
|
|
22
23
|
var _this = _super.call(this) || this;
|
|
23
|
-
_this.appBadRequestException
|
|
24
|
+
_this.parse(appBadRequestException);
|
|
24
25
|
return _this;
|
|
25
26
|
}
|
|
27
|
+
AppBadRequestException.prototype.parse = function (appBadRequestException) {
|
|
28
|
+
return appBadRequestException;
|
|
29
|
+
};
|
|
26
30
|
return AppBadRequestException;
|
|
27
31
|
}(Error));
|
|
28
32
|
exports.AppBadRequestException = AppBadRequestException;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface IChargeModel {
|
|
2
|
+
initialBookingGrossAmount: number;
|
|
3
|
+
additionalBookingGrossAmount: number;
|
|
4
|
+
cancelledBookingGrossAmount: number;
|
|
5
|
+
totalCancellationCharges: number;
|
|
6
|
+
refundPayable: number;
|
|
7
|
+
netTotal: number;
|
|
8
|
+
amountPaid: number;
|
|
9
|
+
amountPayable: number;
|
|
10
|
+
totalRefundedAmount: number;
|
|
11
|
+
couponCode: string;
|
|
12
|
+
}
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { IBookingModification } from "../types/booking-modification.type";
|
|
2
2
|
import { ModificationDiscountPolicy } from "../enums/modification-discount-policy.enum";
|
|
3
|
-
|
|
4
|
-
initialBookingGrossAmount: number;
|
|
5
|
-
additionalBookingGrossAmount: number;
|
|
6
|
-
cancelledBookingGrossAmount: number;
|
|
7
|
-
totalCancellationCharges: number;
|
|
8
|
-
refundPayable: number;
|
|
9
|
-
netTotal: number;
|
|
10
|
-
amountPaid: number;
|
|
11
|
-
amountPayable: number;
|
|
12
|
-
totalRefundedAmount: number;
|
|
13
|
-
couponCode: string;
|
|
14
|
-
}
|
|
3
|
+
import { IChargeModel } from "../interface/charge-model.interface";
|
|
15
4
|
export declare class ChargesModel implements IChargeModel {
|
|
16
5
|
initialBookingGrossAmount: number;
|
|
17
6
|
additionalBookingGrossAmount: number;
|
package/package.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AppBadRequestException = void 0;
|
|
19
|
-
var AppBadRequestException = /** @class */ (function (_super) {
|
|
20
|
-
__extends(AppBadRequestException, _super);
|
|
21
|
-
function AppBadRequestException(appBadRequestException) {
|
|
22
|
-
var _this = _super.call(this) || this;
|
|
23
|
-
_this.appBadRequestException = appBadRequestException;
|
|
24
|
-
return _this;
|
|
25
|
-
}
|
|
26
|
-
return AppBadRequestException;
|
|
27
|
-
}(Error));
|
|
28
|
-
exports.AppBadRequestException = AppBadRequestException;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { TimeSlot } from "../time-slot-module/time-slot-model";
|
|
2
|
-
import { IGetBookingCodesPerThirtyMinutes } from "./interfaces/get-booking-codes-per-thirty-min.interface";
|
|
3
|
-
export declare class BookingCode {
|
|
4
|
-
code: string;
|
|
5
|
-
turfid: string;
|
|
6
|
-
pitchCode: string;
|
|
7
|
-
slot: string;
|
|
8
|
-
fromTime: string;
|
|
9
|
-
toTime: string;
|
|
10
|
-
date: string;
|
|
11
|
-
cost: string;
|
|
12
|
-
constructor(code: string, cost?: string);
|
|
13
|
-
parse(): BookingCode;
|
|
14
|
-
getBookingTimeInMinutes(): number;
|
|
15
|
-
getPitchNo(): number;
|
|
16
|
-
getHalfHourTimeCodes(): string[];
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @returns {Array<string>} - List of half hour time slot codes between start time & end time inclusive
|
|
20
|
-
* @example fromTime: 0000; toTime: 0130
|
|
21
|
-
* // returns ['00000030','00300100','01000130']
|
|
22
|
-
*/
|
|
23
|
-
getHalfHourTimeRangeCodes(): string[];
|
|
24
|
-
getValidDate(): Date;
|
|
25
|
-
getDateCode(): string;
|
|
26
|
-
getWeekday(): number;
|
|
27
|
-
getMonthCode(): string;
|
|
28
|
-
getDateWithFromTimeCode(): string;
|
|
29
|
-
getCodeWithoutTurfCode(): string;
|
|
30
|
-
static sortByCode(bookingCodes: BookingCode[]): void;
|
|
31
|
-
static getOneSlotBookingCode(turfId: string, bookingDate: string, fhfm: string, thtm: string, pitchCode: string): string;
|
|
32
|
-
static getDiscountedCost(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
33
|
-
static getDiscountAmount(couponCode: string, totalCost: number): number;
|
|
34
|
-
static isValidDate(date: string): boolean;
|
|
35
|
-
static parseDateCode(dateCode: string): Date;
|
|
36
|
-
static getWeekday(dateCode: number): number;
|
|
37
|
-
static convertToDate(str: string): Date;
|
|
38
|
-
static previousDateChecker(fromDate: number, index: number, errorKey?: string): void;
|
|
39
|
-
static previousTimeChecker(fromTime: string, fromDate: number, index: number): void;
|
|
40
|
-
static getDateCodesByWeek(fromDate: number, toDate: number, selectedWeekday: number): string[];
|
|
41
|
-
static getDatesByWeek(fromDate: number, toDate: number, selectedWeekday: number): Date[];
|
|
42
|
-
static isValidTimeRange(timeSlot: string): boolean;
|
|
43
|
-
static dateFormat(dates: Array<Date>): Array<string>;
|
|
44
|
-
static getDateCode(date: Date): string;
|
|
45
|
-
/**
|
|
46
|
-
* Returns list of month codes (YYMM) in the Date range inclusive
|
|
47
|
-
* @param {Date} from - Start Date
|
|
48
|
-
* @param {Date} to - End Date
|
|
49
|
-
* @return {Array<Number>} - The array of month codes (YYMM)
|
|
50
|
-
*/
|
|
51
|
-
static getMonthCodesRange(from: Date, to: Date): number[];
|
|
52
|
-
static getNMonthCodes(n: number): number[];
|
|
53
|
-
static getCodes(fromDate: number, toDate: number, weekday: number, turfId: number, from: string, to: string): string[];
|
|
54
|
-
static getNextDayDateCode(dateCode: number): number;
|
|
55
|
-
getUtcDateWithTime(dateCodeWithTime: string): Date;
|
|
56
|
-
static getUtcDateWithTime(dateCodeWithTime: string): Date;
|
|
57
|
-
getNoOfHoursDifference(): number;
|
|
58
|
-
static getBookingCodesPerThirtyMinutes(from: string, to: string, bookingDate: string): IGetBookingCodesPerThirtyMinutes[];
|
|
59
|
-
static getCostPerThirtyMinutes(bookingCodePerThirtyMinutesPerSlot: {
|
|
60
|
-
slotCodePerThirtyMinute: string;
|
|
61
|
-
bookingDate: string;
|
|
62
|
-
}[], pricePerThirtyMinutesData: {
|
|
63
|
-
[date: string]: {
|
|
64
|
-
[time: string]: number;
|
|
65
|
-
};
|
|
66
|
-
}): string;
|
|
67
|
-
static padBookingCode(bookingCodeWithoutTurfCode: string): string;
|
|
68
|
-
static getInstance(turfId: number, bookingCodeWithoutTurfCode: string): BookingCode;
|
|
69
|
-
getCost(): number;
|
|
70
|
-
getTimeslot(): TimeSlot;
|
|
71
|
-
}
|
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.BookingCode = void 0;
|
|
15
|
-
var time_slot_model_1 = require("../time-slot-module/time-slot-model");
|
|
16
|
-
var charge_model_1 = require("../charge-module/charge-model");
|
|
17
|
-
var date_code_model_1 = require("../date-module/date-code-model");
|
|
18
|
-
var app_badrequest_exception_model_1 = require("../app-badrequest-exception-module/app-badrequest-exception-model");
|
|
19
|
-
var BookingCode = /** @class */ (function () {
|
|
20
|
-
function BookingCode(code, cost) {
|
|
21
|
-
if (cost === void 0) { cost = "-1"; }
|
|
22
|
-
// this.id = turfid;
|
|
23
|
-
if (code.length === 18)
|
|
24
|
-
this.code = code + "00";
|
|
25
|
-
else
|
|
26
|
-
this.code = code;
|
|
27
|
-
this.cost = cost;
|
|
28
|
-
this.parse();
|
|
29
|
-
}
|
|
30
|
-
BookingCode.prototype.parse = function () {
|
|
31
|
-
var regexp = /(\d{4})(\d{6})(\d{8})(\d{2})/g;
|
|
32
|
-
var matches = regexp.exec(this.code);
|
|
33
|
-
if (!matches) {
|
|
34
|
-
throw new Error("Booking slot ".concat(this.code, " is invalid"));
|
|
35
|
-
}
|
|
36
|
-
this.turfid = matches[1];
|
|
37
|
-
this.date = matches[2];
|
|
38
|
-
this.slot = matches[3];
|
|
39
|
-
this.fromTime = matches[3].slice(0, 4);
|
|
40
|
-
this.toTime = matches[3].slice(4, 8);
|
|
41
|
-
this.pitchCode = matches[4];
|
|
42
|
-
return this;
|
|
43
|
-
};
|
|
44
|
-
BookingCode.prototype.getBookingTimeInMinutes = function () {
|
|
45
|
-
//from HHMM to HHMM
|
|
46
|
-
var fromHours = parseInt(this.fromTime.slice(0, 2));
|
|
47
|
-
var fromMinutes = parseInt(this.fromTime.slice(2, 4));
|
|
48
|
-
var toHours = parseInt(this.toTime.slice(0, 2));
|
|
49
|
-
var toMinutes = parseInt(this.toTime.slice(2, 4));
|
|
50
|
-
return toHours * 60 + toMinutes - (fromHours * 60 + fromMinutes);
|
|
51
|
-
};
|
|
52
|
-
BookingCode.prototype.getPitchNo = function () {
|
|
53
|
-
return parseInt(this.pitchCode);
|
|
54
|
-
};
|
|
55
|
-
BookingCode.prototype.getHalfHourTimeCodes = function () {
|
|
56
|
-
return new time_slot_model_1.TimeSlot(this.fromTime, this.toTime).getHalfHourTimeCodes();
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
*
|
|
60
|
-
* @returns {Array<string>} - List of half hour time slot codes between start time & end time inclusive
|
|
61
|
-
* @example fromTime: 0000; toTime: 0130
|
|
62
|
-
* // returns ['00000030','00300100','01000130']
|
|
63
|
-
*/
|
|
64
|
-
BookingCode.prototype.getHalfHourTimeRangeCodes = function () {
|
|
65
|
-
var halfHourCodes = this.getHalfHourTimeCodes();
|
|
66
|
-
var halfHourRangeCodes = [];
|
|
67
|
-
for (var index = 0; index < halfHourCodes.length - 1; index++) {
|
|
68
|
-
halfHourRangeCodes.push(halfHourCodes[index] + halfHourCodes[index + 1]);
|
|
69
|
-
}
|
|
70
|
-
return halfHourRangeCodes;
|
|
71
|
-
};
|
|
72
|
-
BookingCode.prototype.getValidDate = function () {
|
|
73
|
-
// Date format: YYMMDD
|
|
74
|
-
function getDate(dateString) {
|
|
75
|
-
var separators = ["\\.", "\\-", "\\/"];
|
|
76
|
-
var stringBits = dateString.split(new RegExp(separators.join("|"), "g"));
|
|
77
|
-
var intBits = stringBits.map(function (bit) { return parseInt(bit); });
|
|
78
|
-
return new Date(intBits[0], intBits[1] - 1, intBits[2]);
|
|
79
|
-
}
|
|
80
|
-
return getDate("20".concat(this.date.slice(0, 2), ".").concat(this.date.slice(2, 4), ".").concat(this.date.slice(4, 6)));
|
|
81
|
-
};
|
|
82
|
-
BookingCode.prototype.getDateCode = function () {
|
|
83
|
-
var date = this.getValidDate();
|
|
84
|
-
return "".concat(date.getFullYear() % 2000).concat((date.getMonth() + 1)
|
|
85
|
-
.toString()
|
|
86
|
-
.padStart(2, "0")).concat(date.getDate().toString().padStart(2, "0"));
|
|
87
|
-
};
|
|
88
|
-
BookingCode.prototype.getWeekday = function () {
|
|
89
|
-
var dateObj = new Date(2000 + parseInt(this.date.slice(0, 2)), // Year
|
|
90
|
-
parseInt(this.date.toString().slice(2, 4)) - 1, // Month (0-indexed)
|
|
91
|
-
parseInt(this.date.toString().slice(4, 6)) // Day
|
|
92
|
-
);
|
|
93
|
-
return dateObj.getDay() === 0 ? 7 : dateObj.getDay();
|
|
94
|
-
// return weekday;
|
|
95
|
-
};
|
|
96
|
-
BookingCode.prototype.getMonthCode = function () {
|
|
97
|
-
return this.date.slice(0, 4);
|
|
98
|
-
};
|
|
99
|
-
BookingCode.prototype.getDateWithFromTimeCode = function () {
|
|
100
|
-
return "".concat(this.date).concat(this.fromTime);
|
|
101
|
-
};
|
|
102
|
-
BookingCode.prototype.getCodeWithoutTurfCode = function () {
|
|
103
|
-
return "".concat(this.date).concat(this.slot).concat(this.pitchCode);
|
|
104
|
-
};
|
|
105
|
-
BookingCode.sortByCode = function (bookingCodes) {
|
|
106
|
-
bookingCodes.sort(function (_a, _b) {
|
|
107
|
-
var code1 = _a.code;
|
|
108
|
-
var code2 = _b.code;
|
|
109
|
-
return code1 < code2 ? -1 : code1 > code2 ? 1 : 0;
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
|
-
// code: TTTTYYMMDDFHFMTHTMPP;
|
|
113
|
-
BookingCode.getOneSlotBookingCode = function (turfId, bookingDate, fhfm, thtm, pitchCode) {
|
|
114
|
-
var code = turfId + bookingDate + fhfm + thtm + pitchCode;
|
|
115
|
-
return code;
|
|
116
|
-
};
|
|
117
|
-
BookingCode.getDiscountedCost = function (couponCode, totalCost, validationApply) {
|
|
118
|
-
if (validationApply === void 0) { validationApply = true; }
|
|
119
|
-
var discount = 0;
|
|
120
|
-
var discountedCost = 0;
|
|
121
|
-
if (couponCode) {
|
|
122
|
-
if (couponCode.endsWith("P")) {
|
|
123
|
-
var percentDiscount = parseFloat(couponCode);
|
|
124
|
-
if (validationApply) {
|
|
125
|
-
if (percentDiscount > 90) {
|
|
126
|
-
throw new app_badrequest_exception_model_1.AppBadRequestException({
|
|
127
|
-
key: "couponCode",
|
|
128
|
-
message: ["Discount should not be more than 90P"],
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
discount = totalCost * (percentDiscount / 100);
|
|
133
|
-
}
|
|
134
|
-
else if (couponCode.endsWith("U")) {
|
|
135
|
-
discount = parseFloat(couponCode);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
discountedCost = totalCost - discount;
|
|
139
|
-
return Math.round(discountedCost);
|
|
140
|
-
};
|
|
141
|
-
BookingCode.getDiscountAmount = function (couponCode, totalCost) {
|
|
142
|
-
return charge_model_1.ChargesModel.getDiscountAmount(couponCode, totalCost, true);
|
|
143
|
-
};
|
|
144
|
-
//-----------------
|
|
145
|
-
BookingCode.isValidDate = function (date) {
|
|
146
|
-
// Date format: YYMMDD
|
|
147
|
-
function isDate(dateString) {
|
|
148
|
-
var separators = ["\\.", "\\-", "\\/"];
|
|
149
|
-
var stringBits = dateString.split(new RegExp(separators.join("|"), "g"));
|
|
150
|
-
var intBits = stringBits.map(function (bit) { return parseInt(bit); });
|
|
151
|
-
var parsedDate = new Date(intBits[0], intBits[1] - 1, intBits[2]);
|
|
152
|
-
return (parsedDate.getFullYear() === intBits[0] &&
|
|
153
|
-
parsedDate.getMonth() + 1 === intBits[1] &&
|
|
154
|
-
parsedDate.getDate() === intBits[2]);
|
|
155
|
-
}
|
|
156
|
-
return isDate("20".concat(date.slice(0, 2), ".").concat(date.slice(2, 4), ".").concat(date.slice(4, 6)));
|
|
157
|
-
};
|
|
158
|
-
BookingCode.parseDateCode = function (dateCode) {
|
|
159
|
-
// Date format: YYMMDD
|
|
160
|
-
function getDate(dateString) {
|
|
161
|
-
var separators = ["\\.", "\\-", "\\/"];
|
|
162
|
-
var stringBits = dateString.split(new RegExp(separators.join("|"), "g"));
|
|
163
|
-
var intBits = stringBits.map(function (bit) { return parseInt(bit); });
|
|
164
|
-
return new Date(intBits[0], intBits[1] - 1, intBits[2]);
|
|
165
|
-
}
|
|
166
|
-
return getDate("20".concat(dateCode.slice(0, 2), ".").concat(dateCode.slice(2, 4), ".").concat(dateCode.slice(4, 6)));
|
|
167
|
-
};
|
|
168
|
-
//------------------
|
|
169
|
-
BookingCode.getWeekday = function (dateCode) {
|
|
170
|
-
var dateObj = new Date(2000 + parseInt(dateCode.toString().slice(0, 2)), // Year
|
|
171
|
-
parseInt(dateCode.toString().slice(2, 4)) - 1, // Month (0-indexed)
|
|
172
|
-
parseInt(dateCode.toString().slice(4, 6)) // Day
|
|
173
|
-
);
|
|
174
|
-
var weekday = dateObj.getDay();
|
|
175
|
-
return weekday === 0 ? 7 : weekday;
|
|
176
|
-
};
|
|
177
|
-
//---------------------
|
|
178
|
-
BookingCode.convertToDate = function (str) {
|
|
179
|
-
var year = parseInt(20 + str.slice(0, 2));
|
|
180
|
-
var month = parseInt(str.slice(2, 4)) - 1;
|
|
181
|
-
var day = parseInt(str.slice(4, 6));
|
|
182
|
-
var date = new Date(Date.UTC(year, month, day, 0, 0, 0));
|
|
183
|
-
return date;
|
|
184
|
-
};
|
|
185
|
-
//---------------------
|
|
186
|
-
BookingCode.previousDateChecker = function (fromDate, index, errorKey) {
|
|
187
|
-
var slotDate = this.convertToDate(fromDate.toString());
|
|
188
|
-
var currentDateObj = new Date();
|
|
189
|
-
var parsedDate = this.dateFormat([slotDate]);
|
|
190
|
-
var currentDate = this.dateFormat([currentDateObj]);
|
|
191
|
-
if (parsedDate < currentDate) {
|
|
192
|
-
throw new app_badrequest_exception_model_1.AppBadRequestException({
|
|
193
|
-
key: errorKey !== null && errorKey !== void 0 ? errorKey : "slot.".concat(index),
|
|
194
|
-
message: ["date must be present Date or future Date"],
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
else if (parsedDate === currentDate) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
//---------------------
|
|
202
|
-
BookingCode.previousTimeChecker = function (fromTime, fromDate, index) {
|
|
203
|
-
var now = new Date();
|
|
204
|
-
this.convertToDate(fromDate.toString());
|
|
205
|
-
var delayInBooking = 15;
|
|
206
|
-
if (this.convertToDate(fromDate.toString()) > now) {
|
|
207
|
-
return; //do nothing if fromDate is in future
|
|
208
|
-
}
|
|
209
|
-
else if (this.convertToDate(fromDate.toString()) <= now) {
|
|
210
|
-
now.setMinutes(now.getMinutes() - delayInBooking); // 15minutes buffer for late bookings
|
|
211
|
-
var options = {
|
|
212
|
-
timeZone: "Asia/Kolkata",
|
|
213
|
-
};
|
|
214
|
-
var timeFormat = new Intl.DateTimeFormat("en-US", __assign(__assign({}, options), { hour: "2-digit", minute: "2-digit", hour12: false }));
|
|
215
|
-
var currentTimeObj = timeFormat.format(now).replace(/:/g, "");
|
|
216
|
-
if (fromTime < currentTimeObj) {
|
|
217
|
-
throw new app_badrequest_exception_model_1.AppBadRequestException({
|
|
218
|
-
key: "slot.".concat(index),
|
|
219
|
-
message: ["Booking time should be in future"],
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
//---------------------
|
|
225
|
-
BookingCode.getDateCodesByWeek = function (fromDate, toDate, selectedWeekday) {
|
|
226
|
-
return BookingCode.dateFormat(BookingCode.getDatesByWeek(fromDate, toDate, selectedWeekday));
|
|
227
|
-
};
|
|
228
|
-
BookingCode.getDatesByWeek = function (fromDate, toDate, selectedWeekday) {
|
|
229
|
-
if (!BookingCode.isValidDate(fromDate.toString()) ||
|
|
230
|
-
!BookingCode.isValidDate(toDate.toString())) {
|
|
231
|
-
throw new app_badrequest_exception_model_1.AppBadRequestException({
|
|
232
|
-
key: "Date",
|
|
233
|
-
message: ["Invalid Date"],
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
if (selectedWeekday < 0 || selectedWeekday > 7) {
|
|
237
|
-
throw new app_badrequest_exception_model_1.AppBadRequestException({
|
|
238
|
-
key: "weekday",
|
|
239
|
-
message: ["weekday should be between 1-7"],
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
var startDate = BookingCode.convertToDate(fromDate.toString());
|
|
243
|
-
var endDate = BookingCode.convertToDate(toDate.toString());
|
|
244
|
-
var currentDate = startDate;
|
|
245
|
-
var dates = [];
|
|
246
|
-
while (currentDate <= endDate) {
|
|
247
|
-
var weekday = currentDate.getDay();
|
|
248
|
-
if (weekday === selectedWeekday % 7) {
|
|
249
|
-
dates.push(new Date(currentDate.getTime()));
|
|
250
|
-
currentDate.setDate(currentDate.getDate() + 7);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
currentDate.setDate(currentDate.getDate() + 1);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return dates;
|
|
257
|
-
};
|
|
258
|
-
//--------------------
|
|
259
|
-
BookingCode.isValidTimeRange = function (timeSlot) {
|
|
260
|
-
var timeformat = /^(([01]\d|2[0-3])([0-5]\d|60)|2400|0000)$/;
|
|
261
|
-
var isValidTime = timeformat.test(timeSlot) && parseInt(timeSlot, 10) <= 2400;
|
|
262
|
-
return isValidTime;
|
|
263
|
-
};
|
|
264
|
-
//---------------------
|
|
265
|
-
BookingCode.dateFormat = function (dates) {
|
|
266
|
-
var codes = [];
|
|
267
|
-
for (var _i = 0, dates_1 = dates; _i < dates_1.length; _i++) {
|
|
268
|
-
var date = dates_1[_i];
|
|
269
|
-
var dateYear = date.getFullYear() % 2000;
|
|
270
|
-
var dateMonth = date.getMonth() + 1;
|
|
271
|
-
var dateDay = date.getDate();
|
|
272
|
-
var dateFormat = dateYear.toString() +
|
|
273
|
-
dateMonth.toString().padStart(2, "0") +
|
|
274
|
-
dateDay.toString().padStart(2, "0");
|
|
275
|
-
codes.push(dateFormat);
|
|
276
|
-
}
|
|
277
|
-
return codes;
|
|
278
|
-
};
|
|
279
|
-
BookingCode.getDateCode = function (date) {
|
|
280
|
-
return "".concat(date.getFullYear() % 2000).concat((date.getMonth() + 1)
|
|
281
|
-
.toString()
|
|
282
|
-
.padStart(2, "0")).concat(date.getDate().toString().padStart(2, "0"));
|
|
283
|
-
};
|
|
284
|
-
/**
|
|
285
|
-
* Returns list of month codes (YYMM) in the Date range inclusive
|
|
286
|
-
* @param {Date} from - Start Date
|
|
287
|
-
* @param {Date} to - End Date
|
|
288
|
-
* @return {Array<Number>} - The array of month codes (YYMM)
|
|
289
|
-
*/
|
|
290
|
-
BookingCode.getMonthCodesRange = function (from, to) {
|
|
291
|
-
from = new Date(from.getTime());
|
|
292
|
-
to = new Date(to.getTime());
|
|
293
|
-
var monthCodes = [];
|
|
294
|
-
while (from < to) {
|
|
295
|
-
var fromDateCode = BookingCode.getDateCode(from);
|
|
296
|
-
monthCodes.push(parseInt("".concat(fromDateCode.slice(0, 4))));
|
|
297
|
-
from.setMonth(from.getMonth() + 1);
|
|
298
|
-
}
|
|
299
|
-
var toDateCode = BookingCode.getDateCode(to);
|
|
300
|
-
if (!monthCodes.includes(parseInt("".concat(toDateCode.slice(0, 4))))) {
|
|
301
|
-
monthCodes.push(parseInt("".concat(toDateCode.slice(0, 4))));
|
|
302
|
-
}
|
|
303
|
-
return monthCodes;
|
|
304
|
-
};
|
|
305
|
-
BookingCode.getNMonthCodes = function (n) {
|
|
306
|
-
var now = new Date();
|
|
307
|
-
var future = new Date(now.getTime());
|
|
308
|
-
future.setMonth(now.getMonth() + n);
|
|
309
|
-
return BookingCode.getMonthCodesRange(now, future);
|
|
310
|
-
};
|
|
311
|
-
BookingCode.getCodes = function (fromDate, toDate, weekday, turfId, from, to) {
|
|
312
|
-
// const {fromDate, toDate, weekday, turfId, from, to} = bookingSlot
|
|
313
|
-
var dates = this.getDateCodesByWeek(fromDate, toDate, weekday);
|
|
314
|
-
// TTTTYYMMDDFFFFTTTT
|
|
315
|
-
var codes = [];
|
|
316
|
-
for (var _i = 0, dates_2 = dates; _i < dates_2.length; _i++) {
|
|
317
|
-
var date = dates_2[_i];
|
|
318
|
-
codes.push("".concat(turfId.toString().padStart(4, "0")).concat(date).concat(from).concat(to));
|
|
319
|
-
}
|
|
320
|
-
return codes;
|
|
321
|
-
};
|
|
322
|
-
//To check fromDate and toDate present in weekDays and return dateCode
|
|
323
|
-
BookingCode.getNextDayDateCode = function (dateCode) {
|
|
324
|
-
var nextDate = BookingCode.parseDateCode(dateCode.toString());
|
|
325
|
-
nextDate.setDate(nextDate.getDate() + 1);
|
|
326
|
-
return parseInt(BookingCode.getDateCode(nextDate));
|
|
327
|
-
};
|
|
328
|
-
BookingCode.prototype.getUtcDateWithTime = function (dateCodeWithTime) {
|
|
329
|
-
// const dateCodeWithTime = '2305131200';
|
|
330
|
-
var year = parseInt(dateCodeWithTime.slice(0, 2)) + 2000;
|
|
331
|
-
var month = parseInt(dateCodeWithTime.slice(2, 4)) - 1;
|
|
332
|
-
var day = parseInt(dateCodeWithTime.slice(4, 6));
|
|
333
|
-
var hours = parseInt(dateCodeWithTime.slice(6, 8));
|
|
334
|
-
var minutes = parseInt(dateCodeWithTime.slice(8, 10));
|
|
335
|
-
return new Date(Date.UTC(year, month, day, hours, minutes));
|
|
336
|
-
};
|
|
337
|
-
BookingCode.getUtcDateWithTime = function (dateCodeWithTime) {
|
|
338
|
-
// const dateCodeWithTime = '2305131200';
|
|
339
|
-
var year = parseInt(dateCodeWithTime.slice(0, 2)) + 2000;
|
|
340
|
-
var month = parseInt(dateCodeWithTime.slice(2, 4)) - 1;
|
|
341
|
-
var day = parseInt(dateCodeWithTime.slice(4, 6));
|
|
342
|
-
var hours = parseInt(dateCodeWithTime.slice(6, 8));
|
|
343
|
-
var minutes = parseInt(dateCodeWithTime.slice(8, 10));
|
|
344
|
-
return new Date(Date.UTC(year, month, day, hours, minutes));
|
|
345
|
-
};
|
|
346
|
-
BookingCode.prototype.getNoOfHoursDifference = function () {
|
|
347
|
-
var bookingDate = BookingCode.getUtcDateWithTime(this.getDateWithFromTimeCode());
|
|
348
|
-
var date = date_code_model_1.DateCode.getIndianTimeZoneDate();
|
|
349
|
-
var timeDifferenceMs = bookingDate.getTime() - date.getTime();
|
|
350
|
-
return timeDifferenceMs / (1000 * 60 * 60);
|
|
351
|
-
};
|
|
352
|
-
BookingCode.getBookingCodesPerThirtyMinutes = function (from, to, bookingDate) {
|
|
353
|
-
var bookingCodePerThirtyMinutes = [];
|
|
354
|
-
while (from < to) {
|
|
355
|
-
var lastDigit = from.slice(2, 4);
|
|
356
|
-
if (lastDigit == "00") {
|
|
357
|
-
var code = "".concat(from).concat((Number(from) + 30)
|
|
358
|
-
.toString()
|
|
359
|
-
.padStart(4, "0"));
|
|
360
|
-
bookingCodePerThirtyMinutes.push({
|
|
361
|
-
slotCodePerThirtyMinute: code,
|
|
362
|
-
bookingDate: bookingDate,
|
|
363
|
-
});
|
|
364
|
-
from = (Number(from) + 30).toString().padStart(4, "0");
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
var code = "".concat(from).concat((Number(from) + 70)
|
|
368
|
-
.toString()
|
|
369
|
-
.padStart(4, "0"));
|
|
370
|
-
bookingCodePerThirtyMinutes.push({
|
|
371
|
-
slotCodePerThirtyMinute: code,
|
|
372
|
-
bookingDate: bookingDate,
|
|
373
|
-
});
|
|
374
|
-
from = (Number(from) + 70).toString().padStart(4, "0");
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
return bookingCodePerThirtyMinutes;
|
|
378
|
-
};
|
|
379
|
-
BookingCode.getCostPerThirtyMinutes = function (bookingCodePerThirtyMinutesPerSlot, pricePerThirtyMinutesData) {
|
|
380
|
-
var cost = [];
|
|
381
|
-
bookingCodePerThirtyMinutesPerSlot.forEach(function (slot) {
|
|
382
|
-
var weekDay = BookingCode.getWeekday(Number(slot.bookingDate));
|
|
383
|
-
var month = slot.bookingDate.slice(0, 4);
|
|
384
|
-
var monthWeekday = "".concat(month).concat(weekDay);
|
|
385
|
-
var price = pricePerThirtyMinutesData[monthWeekday][slot.slotCodePerThirtyMinute];
|
|
386
|
-
cost.push(price.toString());
|
|
387
|
-
});
|
|
388
|
-
return cost.join(",");
|
|
389
|
-
};
|
|
390
|
-
BookingCode.padBookingCode = function (bookingCodeWithoutTurfCode) {
|
|
391
|
-
return bookingCodeWithoutTurfCode.padStart(20, "0");
|
|
392
|
-
};
|
|
393
|
-
BookingCode.getInstance = function (turfId, bookingCodeWithoutTurfCode) {
|
|
394
|
-
return new BookingCode("".concat(turfId.toString().padStart(4, "0")).concat(bookingCodeWithoutTurfCode));
|
|
395
|
-
};
|
|
396
|
-
BookingCode.prototype.getCost = function () {
|
|
397
|
-
return this.cost
|
|
398
|
-
.split(",")
|
|
399
|
-
.map(function (a) { return parseInt(a); })
|
|
400
|
-
.reduce(function (a, b) { return a + b; }, 0);
|
|
401
|
-
};
|
|
402
|
-
BookingCode.prototype.getTimeslot = function () {
|
|
403
|
-
return new time_slot_model_1.TimeSlot(this.fromTime, this.toTime);
|
|
404
|
-
};
|
|
405
|
-
return BookingCode;
|
|
406
|
-
}());
|
|
407
|
-
exports.BookingCode = BookingCode;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { BookingModification } from "./types/booking-modification.type";
|
|
2
|
-
import { ModificationDiscountPolicy } from "./enums/modification-discount-policy.enum";
|
|
3
|
-
export interface IChargeModel {
|
|
4
|
-
initialBookingGrossAmount: number;
|
|
5
|
-
additionalBookingGrossAmount: number;
|
|
6
|
-
cancelledBookingGrossAmount: number;
|
|
7
|
-
totalCancellationCharges: number;
|
|
8
|
-
refundPayable: number;
|
|
9
|
-
netTotal: number;
|
|
10
|
-
amountPaid: number;
|
|
11
|
-
amountPayable: number;
|
|
12
|
-
totalRefundedAmount: number;
|
|
13
|
-
couponCode: string;
|
|
14
|
-
}
|
|
15
|
-
export declare class ChargesModel implements IChargeModel {
|
|
16
|
-
initialBookingGrossAmount: number;
|
|
17
|
-
additionalBookingGrossAmount: number;
|
|
18
|
-
cancelledBookingGrossAmount: number;
|
|
19
|
-
totalCancellationCharges: number;
|
|
20
|
-
refundPayable: number;
|
|
21
|
-
netTotal: number;
|
|
22
|
-
amountPaid: number;
|
|
23
|
-
amountPayable: number;
|
|
24
|
-
totalRefundedAmount: number;
|
|
25
|
-
couponCode: string;
|
|
26
|
-
discountPolicy: ModificationDiscountPolicy;
|
|
27
|
-
constructor(initialGrossAmount: number, paidAmount: number, couponCode: string, discountPolicy: ModificationDiscountPolicy);
|
|
28
|
-
getGrossAmount(): number;
|
|
29
|
-
getNetAmount(): number;
|
|
30
|
-
getDiscountAmount(): number;
|
|
31
|
-
getPayableRefundAmount(): number;
|
|
32
|
-
static getDiscountAmount(couponCode: string, totalCost: number, validationApply?: boolean): number;
|
|
33
|
-
setValues(values?: Partial<ChargesModel>): ChargesModel;
|
|
34
|
-
modify(bookingModification: BookingModification): ChargesModel | null;
|
|
35
|
-
private modifyExtend;
|
|
36
|
-
private modifyReduce;
|
|
37
|
-
private modifyMove;
|
|
38
|
-
clone(): ChargesModel;
|
|
39
|
-
private modifyDelete;
|
|
40
|
-
static getInstanceByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
|
|
41
|
-
static assignByInterface(bookingDetailsEntity: IChargeModel, discountPolicy?: ModificationDiscountPolicy): ChargesModel;
|
|
42
|
-
getTotalAmount(): number;
|
|
43
|
-
getPaymentStatus(): "Refund" | "Paid" | "Pending";
|
|
44
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChargesModel = void 0;
|
|
4
|
-
var app_badrequest_exception_model_1 = require("../app-badrequest-exception-module/app-badrequest-exception-model");
|
|
5
|
-
var modification_discount_policy_enum_1 = require("./enums/modification-discount-policy.enum");
|
|
6
|
-
var ChargesModel = /** @class */ (function () {
|
|
7
|
-
function ChargesModel(initialGrossAmount, paidAmount, couponCode, discountPolicy) {
|
|
8
|
-
this.initialBookingGrossAmount = initialGrossAmount;
|
|
9
|
-
this.amountPaid = paidAmount;
|
|
10
|
-
this.couponCode = couponCode;
|
|
11
|
-
this.additionalBookingGrossAmount = 0;
|
|
12
|
-
this.cancelledBookingGrossAmount = 0;
|
|
13
|
-
this.totalCancellationCharges = 0;
|
|
14
|
-
this.refundPayable = 0;
|
|
15
|
-
this.totalRefundedAmount = 0;
|
|
16
|
-
this.netTotal = this.getNetAmount();
|
|
17
|
-
this.amountPayable = this.getPayableRefundAmount();
|
|
18
|
-
this.discountPolicy = discountPolicy;
|
|
19
|
-
}
|
|
20
|
-
ChargesModel.prototype.getGrossAmount = function () {
|
|
21
|
-
return (this.initialBookingGrossAmount +
|
|
22
|
-
this.additionalBookingGrossAmount -
|
|
23
|
-
this.cancelledBookingGrossAmount);
|
|
24
|
-
};
|
|
25
|
-
ChargesModel.prototype.getNetAmount = function () {
|
|
26
|
-
return this.getGrossAmount() - this.getDiscountAmount();
|
|
27
|
-
};
|
|
28
|
-
ChargesModel.prototype.getDiscountAmount = function () {
|
|
29
|
-
if ([
|
|
30
|
-
modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL,
|
|
31
|
-
modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_RECALL,
|
|
32
|
-
].includes(this.discountPolicy) &&
|
|
33
|
-
this.cancelledBookingGrossAmount > 0) {
|
|
34
|
-
this.couponCode = "";
|
|
35
|
-
}
|
|
36
|
-
return ChargesModel.getDiscountAmount(this.couponCode, this.getGrossAmount());
|
|
37
|
-
};
|
|
38
|
-
ChargesModel.prototype.getPayableRefundAmount = function () {
|
|
39
|
-
return (this.getNetAmount() +
|
|
40
|
-
this.totalCancellationCharges -
|
|
41
|
-
this.amountPaid +
|
|
42
|
-
this.totalRefundedAmount);
|
|
43
|
-
};
|
|
44
|
-
// setRefundedAmount(refundAmount: number) {
|
|
45
|
-
// this.paidAmount = this.paidAmount - refundAmount;
|
|
46
|
-
// this.totalRefundAmount = this.totalRefundAmount - refundAmount;
|
|
47
|
-
// this.refundedAmount += refundAmount;
|
|
48
|
-
// }
|
|
49
|
-
ChargesModel.getDiscountAmount = function (couponCode, totalCost, validationApply) {
|
|
50
|
-
if (validationApply === void 0) { validationApply = false; }
|
|
51
|
-
var discountAmount = 0;
|
|
52
|
-
if (couponCode) {
|
|
53
|
-
if (couponCode.slice(-1) === "P") {
|
|
54
|
-
var percentDiscount = parseFloat(couponCode);
|
|
55
|
-
if (validationApply && percentDiscount > 90) {
|
|
56
|
-
throw new app_badrequest_exception_model_1.AppBadRequestException({
|
|
57
|
-
key: "couponCode",
|
|
58
|
-
message: ["Discount should not be more than 90P"],
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
discountAmount = totalCost * (percentDiscount / 100);
|
|
62
|
-
}
|
|
63
|
-
else if (couponCode.slice(-1) === "U") {
|
|
64
|
-
discountAmount = parseFloat(couponCode);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return Math.round(discountAmount);
|
|
68
|
-
};
|
|
69
|
-
ChargesModel.prototype.setValues = function (values) {
|
|
70
|
-
if (values === void 0) { values = {}; }
|
|
71
|
-
var that = this.clone();
|
|
72
|
-
if (values.totalRefundedAmount) {
|
|
73
|
-
that.totalRefundedAmount += values.totalRefundedAmount;
|
|
74
|
-
that.refundPayable -= values.totalRefundedAmount;
|
|
75
|
-
}
|
|
76
|
-
if (values.amountPaid) {
|
|
77
|
-
that.amountPaid = that.amountPaid + values.amountPaid;
|
|
78
|
-
that.amountPayable = that.amountPayable - values.amountPaid;
|
|
79
|
-
}
|
|
80
|
-
return that;
|
|
81
|
-
};
|
|
82
|
-
ChargesModel.prototype.modify = function (bookingModification) {
|
|
83
|
-
var oldBookingCode = bookingModification.oldBookingCode, newBookingCode = bookingModification.newBookingCode, cancellationUnit = bookingModification.cancellationUnit;
|
|
84
|
-
if (!newBookingCode) {
|
|
85
|
-
return this.modifyDelete(oldBookingCode, cancellationUnit !== null && cancellationUnit !== void 0 ? cancellationUnit : "");
|
|
86
|
-
}
|
|
87
|
-
if (!newBookingCode)
|
|
88
|
-
return null;
|
|
89
|
-
var oldTimeSlotMinutes = oldBookingCode.getTimeslot().getTotalMinutes();
|
|
90
|
-
var newTimeSlotMinutes = newBookingCode.getTimeslot().getTotalMinutes();
|
|
91
|
-
if (oldTimeSlotMinutes === newTimeSlotMinutes) {
|
|
92
|
-
return this.modifyMove(oldBookingCode, newBookingCode, cancellationUnit !== null && cancellationUnit !== void 0 ? cancellationUnit : "");
|
|
93
|
-
}
|
|
94
|
-
if (oldTimeSlotMinutes > newTimeSlotMinutes) {
|
|
95
|
-
return this.modifyReduce(oldBookingCode, newBookingCode, cancellationUnit !== null && cancellationUnit !== void 0 ? cancellationUnit : "");
|
|
96
|
-
}
|
|
97
|
-
if (oldTimeSlotMinutes < newTimeSlotMinutes) {
|
|
98
|
-
return this.modifyExtend(oldBookingCode, newBookingCode);
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
};
|
|
102
|
-
ChargesModel.prototype.modifyExtend = function (oldBookingCode, newBookingCode) {
|
|
103
|
-
var newChargeModel = this.clone();
|
|
104
|
-
newChargeModel.additionalBookingGrossAmount +=
|
|
105
|
-
newBookingCode.getCost() - oldBookingCode.getCost();
|
|
106
|
-
newChargeModel.netTotal = newChargeModel.getNetAmount();
|
|
107
|
-
newChargeModel.amountPayable = newChargeModel.getPayableRefundAmount();
|
|
108
|
-
// console.log(newChargeModel.payableAmount);
|
|
109
|
-
if (newChargeModel.amountPayable > 0) {
|
|
110
|
-
newChargeModel.refundPayable = 0;
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
newChargeModel.refundPayable = Math.abs(newChargeModel.amountPayable);
|
|
114
|
-
newChargeModel.amountPayable = 0;
|
|
115
|
-
}
|
|
116
|
-
return newChargeModel;
|
|
117
|
-
};
|
|
118
|
-
ChargesModel.prototype.modifyReduce = function (oldBookingCode, newBookingCode, cancellationUnit) {
|
|
119
|
-
var newChargeModel = this.clone();
|
|
120
|
-
newChargeModel.couponCode = "";
|
|
121
|
-
var costDifference = oldBookingCode.getCost() - newBookingCode.getCost();
|
|
122
|
-
// console.log(`costDifference ${costDifference}`);
|
|
123
|
-
newChargeModel.cancelledBookingGrossAmount += costDifference;
|
|
124
|
-
var cancellationCharges = ChargesModel.getDiscountAmount(cancellationUnit, costDifference);
|
|
125
|
-
// console.log(`cancellationCharges ${cancellationCharges}`);
|
|
126
|
-
newChargeModel.totalCancellationCharges += cancellationCharges;
|
|
127
|
-
newChargeModel.netTotal = newChargeModel.getNetAmount();
|
|
128
|
-
// console.log(`newChargeModel.netAmount ${newChargeModel.netAmount}`);
|
|
129
|
-
newChargeModel.amountPayable = newChargeModel.getPayableRefundAmount();
|
|
130
|
-
// console.log(`newChargeModel.payableAmount ${newChargeModel.payableAmount}`);
|
|
131
|
-
if (newChargeModel.amountPayable > 0) {
|
|
132
|
-
newChargeModel.refundPayable = 0;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
newChargeModel.refundPayable = Math.abs(newChargeModel.amountPayable);
|
|
136
|
-
newChargeModel.amountPayable = 0;
|
|
137
|
-
}
|
|
138
|
-
return newChargeModel;
|
|
139
|
-
};
|
|
140
|
-
ChargesModel.prototype.modifyMove = function (oldBookingCode, newBookingCode, cancellationUnit) {
|
|
141
|
-
var newChargeModel = this.clone();
|
|
142
|
-
var costDifference = newBookingCode.getCost() - oldBookingCode.getCost();
|
|
143
|
-
if (costDifference === 0) {
|
|
144
|
-
return newChargeModel;
|
|
145
|
-
}
|
|
146
|
-
if (costDifference > 0) {
|
|
147
|
-
newChargeModel.additionalBookingGrossAmount += costDifference;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
newChargeModel.cancelledBookingGrossAmount += Math.abs(costDifference);
|
|
151
|
-
var cancellationCharges = ChargesModel.getDiscountAmount(cancellationUnit, Math.abs(costDifference));
|
|
152
|
-
newChargeModel.totalCancellationCharges += cancellationCharges;
|
|
153
|
-
}
|
|
154
|
-
newChargeModel.netTotal = newChargeModel.getNetAmount();
|
|
155
|
-
newChargeModel.amountPayable = newChargeModel.getPayableRefundAmount();
|
|
156
|
-
if (newChargeModel.amountPayable > 0) {
|
|
157
|
-
newChargeModel.refundPayable = 0;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
newChargeModel.refundPayable = Math.abs(newChargeModel.amountPayable);
|
|
161
|
-
newChargeModel.amountPayable = 0;
|
|
162
|
-
}
|
|
163
|
-
return newChargeModel;
|
|
164
|
-
};
|
|
165
|
-
ChargesModel.prototype.clone = function () {
|
|
166
|
-
var that = new ChargesModel(this.initialBookingGrossAmount, this.amountPaid, this.couponCode, this.discountPolicy);
|
|
167
|
-
Object.assign(that, this);
|
|
168
|
-
return that;
|
|
169
|
-
};
|
|
170
|
-
ChargesModel.prototype.modifyDelete = function (bookingCode, cancellationUnit) {
|
|
171
|
-
var newChargeModel = this.clone();
|
|
172
|
-
newChargeModel.couponCode = "";
|
|
173
|
-
var costDifference = bookingCode.getCost();
|
|
174
|
-
newChargeModel.cancelledBookingGrossAmount += costDifference;
|
|
175
|
-
var cancellationCharges = ChargesModel.getDiscountAmount(cancellationUnit, costDifference);
|
|
176
|
-
newChargeModel.totalCancellationCharges += cancellationCharges;
|
|
177
|
-
newChargeModel.netTotal = newChargeModel.getNetAmount();
|
|
178
|
-
newChargeModel.amountPayable = newChargeModel.getPayableRefundAmount();
|
|
179
|
-
if (newChargeModel.amountPayable > 0) {
|
|
180
|
-
newChargeModel.refundPayable = 0;
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
newChargeModel.refundPayable = Math.abs(newChargeModel.amountPayable);
|
|
184
|
-
newChargeModel.amountPayable = 0;
|
|
185
|
-
}
|
|
186
|
-
return newChargeModel;
|
|
187
|
-
};
|
|
188
|
-
ChargesModel.getInstanceByInterface = function (bookingDetailsEntity, discountPolicy) {
|
|
189
|
-
if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
|
|
190
|
-
var chargesModel = new ChargesModel(bookingDetailsEntity.initialBookingGrossAmount, bookingDetailsEntity.amountPaid, bookingDetailsEntity.couponCode, discountPolicy);
|
|
191
|
-
Object.assign(chargesModel, bookingDetailsEntity);
|
|
192
|
-
return chargesModel;
|
|
193
|
-
};
|
|
194
|
-
ChargesModel.assignByInterface = function (bookingDetailsEntity, discountPolicy) {
|
|
195
|
-
if (discountPolicy === void 0) { discountPolicy = modification_discount_policy_enum_1.ModificationDiscountPolicy.DISCOUNT_CONDITIONAL; }
|
|
196
|
-
var newChargeModel = new ChargesModel(bookingDetailsEntity.initialBookingGrossAmount, bookingDetailsEntity.amountPaid, bookingDetailsEntity.couponCode, discountPolicy);
|
|
197
|
-
newChargeModel.additionalBookingGrossAmount =
|
|
198
|
-
bookingDetailsEntity.additionalBookingGrossAmount;
|
|
199
|
-
newChargeModel.initialBookingGrossAmount =
|
|
200
|
-
bookingDetailsEntity.initialBookingGrossAmount;
|
|
201
|
-
newChargeModel.cancelledBookingGrossAmount =
|
|
202
|
-
bookingDetailsEntity.cancelledBookingGrossAmount;
|
|
203
|
-
newChargeModel.refundPayable = bookingDetailsEntity.refundPayable;
|
|
204
|
-
newChargeModel.totalRefundedAmount =
|
|
205
|
-
bookingDetailsEntity.totalRefundedAmount;
|
|
206
|
-
newChargeModel.amountPaid = bookingDetailsEntity.amountPaid;
|
|
207
|
-
newChargeModel.totalCancellationCharges =
|
|
208
|
-
bookingDetailsEntity.totalCancellationCharges;
|
|
209
|
-
newChargeModel.netTotal = bookingDetailsEntity.netTotal;
|
|
210
|
-
newChargeModel.couponCode = bookingDetailsEntity.couponCode;
|
|
211
|
-
newChargeModel.amountPayable = bookingDetailsEntity.amountPayable;
|
|
212
|
-
return newChargeModel;
|
|
213
|
-
};
|
|
214
|
-
ChargesModel.prototype.getTotalAmount = function () {
|
|
215
|
-
return this.getNetAmount() + this.totalCancellationCharges;
|
|
216
|
-
};
|
|
217
|
-
ChargesModel.prototype.getPaymentStatus = function () {
|
|
218
|
-
var payableRefundAmount = this.getPayableRefundAmount();
|
|
219
|
-
return payableRefundAmount < 0
|
|
220
|
-
? "Refund"
|
|
221
|
-
: payableRefundAmount === 0
|
|
222
|
-
? "Paid"
|
|
223
|
-
: "Pending";
|
|
224
|
-
};
|
|
225
|
-
return ChargesModel;
|
|
226
|
-
}());
|
|
227
|
-
exports.ChargesModel = ChargesModel;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModificationDiscountPolicy = void 0;
|
|
4
|
-
var ModificationDiscountPolicy;
|
|
5
|
-
(function (ModificationDiscountPolicy) {
|
|
6
|
-
ModificationDiscountPolicy["DISCOUNT_RECALL"] = "discount_recall";
|
|
7
|
-
ModificationDiscountPolicy["DISCOUNT_RELATIVE"] = "discount_relative";
|
|
8
|
-
ModificationDiscountPolicy["DISCOUNT_CONDITIONAL"] = "discount_conditional";
|
|
9
|
-
})(ModificationDiscountPolicy || (exports.ModificationDiscountPolicy = ModificationDiscountPolicy = {}));
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare class DateCode {
|
|
2
|
-
date: Date;
|
|
3
|
-
constructor(date: Date);
|
|
4
|
-
setTimeToDate(hour: number, minute: number): Date;
|
|
5
|
-
static getUtcDate(): Date;
|
|
6
|
-
static getIndianTimeZoneDate(bookingBufferOffsetHour?: number): Date;
|
|
7
|
-
static dateFormat(dateCode: string): string;
|
|
8
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DateCode = void 0;
|
|
4
|
-
var DateCode = /** @class */ (function () {
|
|
5
|
-
function DateCode(date) {
|
|
6
|
-
this.date = date;
|
|
7
|
-
}
|
|
8
|
-
DateCode.prototype.setTimeToDate = function (hour, minute) {
|
|
9
|
-
var newDate = new Date(Date.UTC(this.date.getFullYear(), this.date.getMonth(), this.date.getDate(), hour, minute));
|
|
10
|
-
return newDate;
|
|
11
|
-
};
|
|
12
|
-
DateCode.getUtcDate = function () {
|
|
13
|
-
var currentDate = new Date();
|
|
14
|
-
var year = currentDate.getUTCFullYear();
|
|
15
|
-
var month = currentDate.getUTCMonth();
|
|
16
|
-
var day = currentDate.getUTCDate();
|
|
17
|
-
var utcDate = new Date(Date.UTC(year, month, day));
|
|
18
|
-
return utcDate;
|
|
19
|
-
};
|
|
20
|
-
DateCode.getIndianTimeZoneDate = function (bookingBufferOffsetHour) {
|
|
21
|
-
var now = new Date();
|
|
22
|
-
var utcOffsetMinutes = 330; // Indian Standard Time (IST) offset is UTC+05:30
|
|
23
|
-
var indianTimeMillis = now.getTime() +
|
|
24
|
-
utcOffsetMinutes * 60 * 1000 +
|
|
25
|
-
(bookingBufferOffsetHour || 0) * 60 * 60 * 1000;
|
|
26
|
-
return new Date(indianTimeMillis);
|
|
27
|
-
};
|
|
28
|
-
DateCode.dateFormat = function (dateCode) {
|
|
29
|
-
dateCode = "20".concat(dateCode.slice(0, 2), "-").concat(dateCode.slice(2, 4), "-").concat(dateCode.slice(4, 6));
|
|
30
|
-
var date = new Date(dateCode);
|
|
31
|
-
var day = date.getDate();
|
|
32
|
-
var month = date.toLocaleString("default", { month: "long" });
|
|
33
|
-
var year = date.getFullYear();
|
|
34
|
-
return "".concat(day, " ").concat(month, " ").concat(year);
|
|
35
|
-
};
|
|
36
|
-
return DateCode;
|
|
37
|
-
}());
|
|
38
|
-
exports.DateCode = DateCode;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export declare class TimeSlot {
|
|
2
|
-
fromTime: string;
|
|
3
|
-
toTime: string;
|
|
4
|
-
constructor(fromTime: string, toTime: string);
|
|
5
|
-
isOverLap(timeSlot: TimeSlot): boolean;
|
|
6
|
-
getOverlapTime(timeSlot: TimeSlot): TimeSlot | null;
|
|
7
|
-
getNonOverlapTimeSlots(existingPriceSlot: TimeSlot): string[];
|
|
8
|
-
getStartMinutes(): number;
|
|
9
|
-
getEndMinutes(): number;
|
|
10
|
-
getHalfHourMinutes(): number[];
|
|
11
|
-
getHalfHourTimeCodes(): string[];
|
|
12
|
-
getHalfHourTimeRangeCodes(): string[];
|
|
13
|
-
getTotalMinutes(): number;
|
|
14
|
-
static convertToCode(minute: number): string;
|
|
15
|
-
static _getMinutes(timeCode: string): number;
|
|
16
|
-
static getHalfHourTimeCodes(): string[];
|
|
17
|
-
static getHalfHourTimeRangeCodes(): string[];
|
|
18
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TimeSlot = void 0;
|
|
4
|
-
var TimeSlot = /** @class */ (function () {
|
|
5
|
-
function TimeSlot(fromTime, toTime) {
|
|
6
|
-
this.fromTime = fromTime;
|
|
7
|
-
this.toTime = toTime;
|
|
8
|
-
}
|
|
9
|
-
TimeSlot.prototype.isOverLap = function (timeSlot) {
|
|
10
|
-
return this.fromTime < timeSlot.toTime && this.toTime > timeSlot.fromTime;
|
|
11
|
-
};
|
|
12
|
-
TimeSlot.prototype.getOverlapTime = function (timeSlot) {
|
|
13
|
-
if (!this.isOverLap(timeSlot)) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return new TimeSlot(this.fromTime > timeSlot.fromTime ? this.fromTime : timeSlot.fromTime, this.toTime < timeSlot.toTime ? this.toTime : timeSlot.toTime);
|
|
17
|
-
};
|
|
18
|
-
TimeSlot.prototype.getNonOverlapTimeSlots = function (existingPriceSlot) {
|
|
19
|
-
var overLapFromTime = this.fromTime > existingPriceSlot.fromTime
|
|
20
|
-
? this.fromTime
|
|
21
|
-
: existingPriceSlot.fromTime;
|
|
22
|
-
var overLapToTime = this.toTime < existingPriceSlot.toTime
|
|
23
|
-
? this.toTime
|
|
24
|
-
: existingPriceSlot.toTime;
|
|
25
|
-
var nonOverlapTimeSlots = [];
|
|
26
|
-
if (existingPriceSlot.fromTime < overLapFromTime) {
|
|
27
|
-
nonOverlapTimeSlots.push("".concat(existingPriceSlot.fromTime).concat(overLapFromTime));
|
|
28
|
-
}
|
|
29
|
-
if (existingPriceSlot.toTime > overLapToTime) {
|
|
30
|
-
nonOverlapTimeSlots.push("".concat(overLapToTime).concat(existingPriceSlot.toTime));
|
|
31
|
-
}
|
|
32
|
-
return nonOverlapTimeSlots;
|
|
33
|
-
};
|
|
34
|
-
TimeSlot.prototype.getStartMinutes = function () {
|
|
35
|
-
return TimeSlot._getMinutes(this.fromTime);
|
|
36
|
-
};
|
|
37
|
-
TimeSlot.prototype.getEndMinutes = function () {
|
|
38
|
-
return TimeSlot._getMinutes(this.toTime);
|
|
39
|
-
};
|
|
40
|
-
TimeSlot.prototype.getHalfHourMinutes = function () {
|
|
41
|
-
var minutes = [this.getStartMinutes()];
|
|
42
|
-
var endMinutes = this.getEndMinutes();
|
|
43
|
-
while (minutes[minutes.length - 1] < endMinutes) {
|
|
44
|
-
minutes.push(minutes[minutes.length - 1] + 30);
|
|
45
|
-
}
|
|
46
|
-
return minutes;
|
|
47
|
-
};
|
|
48
|
-
TimeSlot.prototype.getHalfHourTimeCodes = function () {
|
|
49
|
-
return this.getHalfHourMinutes().map(function (minute) {
|
|
50
|
-
return TimeSlot.convertToCode(minute);
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
TimeSlot.prototype.getHalfHourTimeRangeCodes = function () {
|
|
54
|
-
var halfHourCodes = this.getHalfHourTimeCodes();
|
|
55
|
-
var halfHourRangeCodes = [];
|
|
56
|
-
for (var index = 0; index < halfHourCodes.length - 1; index++) {
|
|
57
|
-
halfHourRangeCodes.push(halfHourCodes[index] + halfHourCodes[index + 1]);
|
|
58
|
-
}
|
|
59
|
-
return halfHourRangeCodes;
|
|
60
|
-
};
|
|
61
|
-
TimeSlot.prototype.getTotalMinutes = function () {
|
|
62
|
-
return this.getEndMinutes() - this.getStartMinutes();
|
|
63
|
-
};
|
|
64
|
-
// static padStart(timeCode: string, length: number, padString: string): string {
|
|
65
|
-
// return timeCode.padStart(length, padString);
|
|
66
|
-
// }
|
|
67
|
-
TimeSlot.convertToCode = function (minute) {
|
|
68
|
-
return "".concat(Math.floor(minute / 60)
|
|
69
|
-
.toString()
|
|
70
|
-
.padStart(2, "0")).concat(Math.floor(minute % 60)
|
|
71
|
-
.toString()
|
|
72
|
-
.padStart(2, "0"));
|
|
73
|
-
};
|
|
74
|
-
TimeSlot._getMinutes = function (timeCode) {
|
|
75
|
-
return parseInt(timeCode.slice(0, 2)) * 60 + parseInt(timeCode.slice(2, 4));
|
|
76
|
-
};
|
|
77
|
-
TimeSlot.getHalfHourTimeCodes = function () {
|
|
78
|
-
var minutes = [0];
|
|
79
|
-
var endMinutes = 24 * 60;
|
|
80
|
-
while (minutes[minutes.length - 1] < endMinutes) {
|
|
81
|
-
minutes.push(minutes[minutes.length - 1] + 30);
|
|
82
|
-
}
|
|
83
|
-
return minutes.map(function (minute) { return TimeSlot.convertToCode(minute); });
|
|
84
|
-
};
|
|
85
|
-
TimeSlot.getHalfHourTimeRangeCodes = function () {
|
|
86
|
-
var halfHourCodes = TimeSlot.getHalfHourTimeCodes();
|
|
87
|
-
var halfHourRangeCodes = [];
|
|
88
|
-
for (var index = 0; index < halfHourCodes.length - 1; index++) {
|
|
89
|
-
halfHourRangeCodes.push(halfHourCodes[index] + halfHourCodes[index + 1]);
|
|
90
|
-
}
|
|
91
|
-
return halfHourRangeCodes;
|
|
92
|
-
};
|
|
93
|
-
return TimeSlot;
|
|
94
|
-
}());
|
|
95
|
-
exports.TimeSlot = TimeSlot;
|