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