tripstorekrabi-shared 1.17.7 → 1.17.8
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/package.json +2 -2
- package/price.js +12 -3
- package/utils.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tripstorekrabi-shared",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.8",
|
|
4
4
|
"description": "Shared library for Trip Store Krabi",
|
|
5
5
|
"author": "Stefan Sommer <tonprince@gmail.com>",
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"./product": "./product.js"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"dayjs": "^1.11.
|
|
18
|
+
"dayjs": "^1.11.13",
|
|
19
19
|
"libphonenumber-js": "^1.11.7",
|
|
20
20
|
"nanoid": "^5.0.7"
|
|
21
21
|
},
|
package/price.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { CUSTOM_MEETING_POINT, TELL_HOTEL_LATER_STARTING_POINT, getBookingType } from "./utils.js";
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import isBetween from 'dayjs/plugin/isBetween';
|
|
4
|
+
|
|
5
|
+
dayjs.extend(isBetween);
|
|
2
6
|
|
|
3
7
|
export const MAX_PAX = 100;
|
|
4
8
|
export const PAY_ON_TOUR = 'Pay on tour';
|
|
@@ -45,6 +49,10 @@ function calculateSellingPrice(commissionRate, price) {
|
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE }) {
|
|
52
|
+
if (pricing.promotion && dayjs(booking.departureDate.toDate()).isBetween(pricing.promotion.startDate.toDate(), pricing.promotion.endDate.toDate(), "day", "[]")) {
|
|
53
|
+
pricing = { ...pricing, volumes: pricing.promotion.volumes };
|
|
54
|
+
}
|
|
55
|
+
|
|
48
56
|
let type = pricing.type;
|
|
49
57
|
let total = 0;
|
|
50
58
|
|
|
@@ -83,7 +91,6 @@ function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE
|
|
|
83
91
|
break;
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
|
-
|
|
87
94
|
case "group": {
|
|
88
95
|
let volume = findVolume(booking, pricing);
|
|
89
96
|
if (!volume) {
|
|
@@ -157,7 +164,7 @@ export function calculatePartnerNetPrice(booking, product) {
|
|
|
157
164
|
booking,
|
|
158
165
|
product
|
|
159
166
|
).reduce(
|
|
160
|
-
(prev, curr) => prev + curr.price,
|
|
167
|
+
(prev, curr) => (prev ?? 0) + curr.price,
|
|
161
168
|
calculateProductPartnerNetPrice(
|
|
162
169
|
booking,
|
|
163
170
|
product.pricing
|
|
@@ -178,7 +185,7 @@ export function calculateTotalOperatorPrice(booking, product) {
|
|
|
178
185
|
}
|
|
179
186
|
|
|
180
187
|
function calculateTotalPrice(booking, product, options = { mode: SELLING_MODE }) {
|
|
181
|
-
let total = calculateProductPrice(booking, product.pricing, options);
|
|
188
|
+
let total = calculateProductPrice(booking, product.pricing, options) ?? 0;
|
|
182
189
|
total += calculateStartEndPointPrice(booking, findStartingPoint(product, booking.startingPointId, false), options);
|
|
183
190
|
total += calculateStartEndPointPrice(booking, findEndPoint(product, booking.endPointId, false), options);
|
|
184
191
|
total += calculateNationalParkFee(booking, product);
|
|
@@ -374,6 +381,8 @@ function calculateStartEndPointPrice(people, startEndPoint, options = { mode: SE
|
|
|
374
381
|
return (isSelling ? pricing.sellingPrice : pricing.operatorNetPrice) * Math.ceil((people.adults + people.children) / pricing.max);
|
|
375
382
|
} else if (pricing.type === "person") {
|
|
376
383
|
return (isSelling ? pricing.sellingPrice : pricing.operatorNetPrice) * (people.adults + people.children);
|
|
384
|
+
} else {
|
|
385
|
+
return 0;
|
|
377
386
|
}
|
|
378
387
|
} else {
|
|
379
388
|
return 0;
|
package/utils.js
CHANGED
|
@@ -710,6 +710,7 @@ export function getBookingType(referenceNumber) {
|
|
|
710
710
|
if (!referenceNumber) {
|
|
711
711
|
return '';
|
|
712
712
|
}
|
|
713
|
+
|
|
713
714
|
if (isGYGBooking(referenceNumber)) {
|
|
714
715
|
return 'gyg';
|
|
715
716
|
} else if (isViatorBooking(referenceNumber)) {
|
|
@@ -729,6 +730,8 @@ export function getBookingType(referenceNumber) {
|
|
|
729
730
|
} else if (isTSKBooking(referenceNumber)) {
|
|
730
731
|
return 'tsk';
|
|
731
732
|
}
|
|
733
|
+
|
|
734
|
+
return '';
|
|
732
735
|
}
|
|
733
736
|
|
|
734
737
|
export function hasCustomPricing(pricing, bookingType) {
|