@vibe-flats/booking-engine-common-server 1.0.110 → 1.0.111
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,29 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.vibePrice = void 0;
|
|
4
|
-
const app_1 = require("../config/app");
|
|
5
4
|
const monthly_diff_1 = require("./monthly-diff");
|
|
6
5
|
const vibePrice = (obj) => {
|
|
7
6
|
const { unit, stay, excludeCleaning, excludeUtilities, markup } = obj;
|
|
8
7
|
// Additional channel markup, added static because its available only on quotes
|
|
9
8
|
const markupValue = markup || 1;
|
|
10
|
-
const nights = stay.length;
|
|
11
|
-
const multiplier = nights >= app_1.COMMON_SERVER.priceFactor.monthly ? unit.prices.monthlyPriceFactor : 1;
|
|
12
|
-
// Apply multiplier: Guesty's approach to monthly pricing
|
|
13
|
-
const rent = +(stay.reduce((acc, stay) => acc + stay.price, 0) * multiplier * markupValue).toFixed(0);
|
|
14
|
-
const cleaning = excludeCleaning ? 0 : unit.prices.cleaningFee;
|
|
15
|
-
const utilities = excludeUtilities ? 0 : unit.prices.utilities * nights;
|
|
16
|
-
const subTotal = rent + utilities + cleaning;
|
|
17
|
-
const discount = nights >= app_1.COMMON_SERVER.priceFactor.monthly && unit.prices.monthlyPriceFactor !== 1
|
|
18
|
-
? +(subTotal * (1 - unit.prices.monthlyPriceFactor)).toFixed(0)
|
|
19
|
-
: 0;
|
|
20
|
-
const total = subTotal - discount;
|
|
21
9
|
// Get min and max dates from stay array
|
|
22
10
|
const sortedStay = [...stay].sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
23
11
|
const dateFrom = sortedStay[0].date;
|
|
24
12
|
const dateTo = sortedStay[sortedStay.length - 1].date;
|
|
25
13
|
// Calculate exact months difference using dayjs
|
|
26
14
|
const monthsDiff = (0, monthly_diff_1.calculatePreciseMonthDifference)(dateFrom, dateTo);
|
|
15
|
+
// Nights
|
|
16
|
+
const nights = stay.length;
|
|
17
|
+
// Apply multiplier: Guesty's approach to monthly pricing
|
|
18
|
+
const rent = +(stay.reduce((acc, stay) => acc + stay.price, 0) * markupValue).toFixed(0);
|
|
19
|
+
const cleaning = excludeCleaning ? 0 : unit.prices.cleaningFee;
|
|
20
|
+
const utilities = excludeUtilities ? 0 : unit.prices.utilities * nights;
|
|
21
|
+
const subTotal = rent + utilities + cleaning;
|
|
22
|
+
const discount = monthsDiff >= 1 && unit.prices.monthlyPriceFactor !== 1 ? +(rent * (1 - unit.prices.monthlyPriceFactor)).toFixed(0) : 0;
|
|
23
|
+
const total = subTotal - discount;
|
|
27
24
|
const monthly = {
|
|
28
25
|
rent: Math.round(rent / monthsDiff),
|
|
29
26
|
discount: Math.round(discount / monthsDiff),
|