@hyper.software/common-helpers 2.2.51 → 2.2.52
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ICompany, IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
|
|
2
|
-
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company,
|
|
2
|
+
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, }: {
|
|
3
3
|
currentPricing: IRoomTypePricePlanPricingInformation;
|
|
4
4
|
dynamicPricing: IDynamicPricing;
|
|
5
5
|
existingBasePriceMap: Record<string, number>;
|
|
@@ -16,7 +16,3 @@ export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing,
|
|
|
16
16
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
17
17
|
updatedBasePriceMap: Record<string, number>;
|
|
18
18
|
}>;
|
|
19
|
-
export declare const getDynamicMultiplier: ({ availabilityRatio, isNearFuture, }: {
|
|
20
|
-
availabilityRatio: number;
|
|
21
|
-
isNearFuture: boolean;
|
|
22
|
-
}) => number;
|
|
@@ -50,87 +50,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.
|
|
53
|
+
exports.calculateDynamicPricing = void 0;
|
|
54
54
|
var moment_1 = __importDefault(require("moment"));
|
|
55
|
-
var dateService_1 = require("../dateService/dateService");
|
|
56
55
|
var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
57
|
-
var basePriceMap,
|
|
58
|
-
var
|
|
59
|
-
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company
|
|
60
|
-
return __generator(this, function (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
(
|
|
78
|
-
|
|
79
|
-
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
80
|
-
]; }));
|
|
81
|
-
today = (0, moment_1.default)();
|
|
82
|
-
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
83
|
-
dateStr = period_1[_i];
|
|
84
|
-
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
85
|
-
if (!date.isValid())
|
|
86
|
-
continue;
|
|
87
|
-
current = currentPricing[dateStr];
|
|
88
|
-
base = (_g = basePriceMap[dateStr]) !== null && _g !== void 0 ? _g : current;
|
|
89
|
-
availableRooms = (_h = roomTypeAvailability[dateStr]) !== null && _h !== void 0 ? _h : 0;
|
|
90
|
-
availabilityRatio = availableRooms / totalRooms;
|
|
91
|
-
leadTimeDays = date.diff(today, 'days');
|
|
92
|
-
isNearHoliday = leadTimeDays <= 7;
|
|
93
|
-
isNearFuture = leadTimeDays < 30;
|
|
94
|
-
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
95
|
-
if (isAffectedHoliday) {
|
|
96
|
-
if (!(dateStr in basePriceMap)) {
|
|
97
|
-
basePriceMap[dateStr] = base;
|
|
98
|
-
}
|
|
99
|
-
baseForToday = basePriceMap[dateStr];
|
|
100
|
-
occupancyMultiplier = (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture });
|
|
101
|
-
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
102
|
-
rawPrice = baseForToday * occupancyMultiplier * leadTimeMultiplier;
|
|
103
|
-
cappedPrice = isNearHoliday && availableRooms <= 1
|
|
104
|
-
? Math.min(rawPrice, baseForToday + 70)
|
|
105
|
-
: Math.min(rawPrice, baseForToday * 1.45);
|
|
106
|
-
resultPricing[dateStr] = Math.round(cappedPrice);
|
|
107
|
-
}
|
|
108
|
-
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
109
|
-
resultPricing[dateStr] = base;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
expected = base ? Math.round(base * (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture })) : current;
|
|
113
|
-
resultPricing[dateStr] =
|
|
114
|
-
current === expected || current === Math.round((base !== null && base !== void 0 ? base : 0) * 1.2) ? (base !== null && base !== void 0 ? base : current) : current;
|
|
115
|
-
}
|
|
56
|
+
var basePriceMap, updatedPricing, affectedDates, _i, _c, h, date, range, _d, range_1, d, _e, _f, dateStr, manualPrice, basePrice, isAffected, isManuallyOverridden, increased;
|
|
57
|
+
var _g;
|
|
58
|
+
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
59
|
+
return __generator(this, function (_h) {
|
|
60
|
+
basePriceMap = __assign({}, existingBasePriceMap);
|
|
61
|
+
updatedPricing = {};
|
|
62
|
+
affectedDates = new Set();
|
|
63
|
+
for (_i = 0, _c = company.holidays || []; _i < _c.length; _i++) {
|
|
64
|
+
h = _c[_i];
|
|
65
|
+
if (!h.enableDynamicPricing)
|
|
66
|
+
continue;
|
|
67
|
+
date = (0, moment_1.default)(h.date);
|
|
68
|
+
range = [
|
|
69
|
+
date.clone().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
70
|
+
date.clone().format('YYYY-MM-DD'),
|
|
71
|
+
date.clone().add(1, 'day').format('YYYY-MM-DD'),
|
|
72
|
+
];
|
|
73
|
+
for (_d = 0, range_1 = range; _d < range_1.length; _d++) {
|
|
74
|
+
d = range_1[_d];
|
|
75
|
+
if ((!dynamicPricing.startDate || d >= dynamicPricing.startDate) &&
|
|
76
|
+
(!dynamicPricing.endDate || d <= dynamicPricing.endDate)) {
|
|
77
|
+
affectedDates.add(d);
|
|
116
78
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (_e = 0, _f = Object.keys(currentPricing); _e < _f.length; _e++) {
|
|
82
|
+
dateStr = _f[_e];
|
|
83
|
+
manualPrice = currentPricing[dateStr];
|
|
84
|
+
basePrice = (_g = basePriceMap[dateStr]) !== null && _g !== void 0 ? _g : manualPrice;
|
|
85
|
+
isAffected = affectedDates.has(dateStr);
|
|
86
|
+
isManuallyOverridden = manualPrice !== basePrice;
|
|
87
|
+
if (!(dateStr in basePriceMap)) {
|
|
88
|
+
basePriceMap[dateStr] = manualPrice;
|
|
89
|
+
}
|
|
90
|
+
if (!dynamicPricing.isActive || !isAffected) {
|
|
91
|
+
updatedPricing[dateStr] = basePrice;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (isManuallyOverridden) {
|
|
95
|
+
updatedPricing[dateStr] = manualPrice;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
increased = basePrice + (dynamicPricing.amount || Math.round(basePrice * 0.05));
|
|
99
|
+
updatedPricing[dateStr] = Math.round(Math.min(increased, basePrice + 70));
|
|
121
100
|
}
|
|
101
|
+
return [2 /*return*/, {
|
|
102
|
+
updatedPricing: updatedPricing,
|
|
103
|
+
updatedBasePriceMap: basePriceMap,
|
|
104
|
+
}];
|
|
122
105
|
});
|
|
123
106
|
}); };
|
|
124
107
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
125
|
-
var getDynamicMultiplier = function (_a) {
|
|
126
|
-
var availabilityRatio = _a.availabilityRatio, isNearFuture = _a.isNearFuture;
|
|
127
|
-
if (availabilityRatio <= 0.02)
|
|
128
|
-
return isNearFuture ? 1.5 : 1.4;
|
|
129
|
-
if (availabilityRatio <= 0.5)
|
|
130
|
-
return isNearFuture ? 1.4 : 1.2;
|
|
131
|
-
if (availabilityRatio < 1)
|
|
132
|
-
return isNearFuture ? 1.2 : 1.05;
|
|
133
|
-
return isNearFuture ? 1.1 : 1.0;
|
|
134
|
-
};
|
|
135
|
-
exports.getDynamicMultiplier = getDynamicMultiplier;
|
|
136
108
|
//# sourceMappingURL=dynamicPricingService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;
|
|
1
|
+
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAGpB,IAAM,uBAAuB,GAAG,iEAAO,EAc7C;;;QAbC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA;;QAcD,YAAY,gBAAQ,oBAAoB,CAAE,CAAA;QAC1C,cAAc,GAAyC,EAAE,CAAA;QAEzD,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QAEvC,WAAsC,EAAtB,KAAA,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAtB,cAAsB,EAAtB,IAAsB,EAAE,CAAC;YAA9B,CAAC;YACV,IAAI,CAAC,CAAC,CAAC,oBAAoB;gBAAE,SAAQ;YAE/B,IAAI,GAAG,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;YACrB,KAAK,GAAG;gBACZ,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;gBACpD,IAAI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