tripstorekrabi-shared 1.17.6 → 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 +3 -2
- package/price.js +12 -3
- package/utils.js +25 -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,8 @@
|
|
|
15
15
|
"./product": "./product.js"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"dayjs": "^1.11.
|
|
18
|
+
"dayjs": "^1.11.13",
|
|
19
|
+
"libphonenumber-js": "^1.11.7",
|
|
19
20
|
"nanoid": "^5.0.7"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
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
|
@@ -6,6 +6,7 @@ import utc from 'dayjs/plugin/utc.js';
|
|
|
6
6
|
import timezone from 'dayjs/plugin/timezone.js';
|
|
7
7
|
import { findEndPoint, findStartingPoint } from './price.js';
|
|
8
8
|
import { CUSTOMER_NOTE } from './booking.js';
|
|
9
|
+
import { parsePhoneNumber, AsYouType } from 'libphonenumber-js';
|
|
9
10
|
|
|
10
11
|
dayjs.extend(customParseFormat);
|
|
11
12
|
dayjs.extend(advancedFormat);
|
|
@@ -709,6 +710,7 @@ export function getBookingType(referenceNumber) {
|
|
|
709
710
|
if (!referenceNumber) {
|
|
710
711
|
return '';
|
|
711
712
|
}
|
|
713
|
+
|
|
712
714
|
if (isGYGBooking(referenceNumber)) {
|
|
713
715
|
return 'gyg';
|
|
714
716
|
} else if (isViatorBooking(referenceNumber)) {
|
|
@@ -728,6 +730,8 @@ export function getBookingType(referenceNumber) {
|
|
|
728
730
|
} else if (isTSKBooking(referenceNumber)) {
|
|
729
731
|
return 'tsk';
|
|
730
732
|
}
|
|
733
|
+
|
|
734
|
+
return '';
|
|
731
735
|
}
|
|
732
736
|
|
|
733
737
|
export function hasCustomPricing(pricing, bookingType) {
|
|
@@ -749,3 +753,24 @@ export function isJSON(text) {
|
|
|
749
753
|
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')
|
|
750
754
|
);
|
|
751
755
|
}
|
|
756
|
+
|
|
757
|
+
export function formatPhoneNumber(phoneNumber) {
|
|
758
|
+
if (phoneNumber) {
|
|
759
|
+
try {
|
|
760
|
+
let libPhoneNumber = parsePhoneNumber(phoneNumber, 'TH');
|
|
761
|
+
let asYouType = new AsYouType();
|
|
762
|
+
asYouType.input(phoneNumber);
|
|
763
|
+
|
|
764
|
+
if (asYouType.isInternational() && asYouType.getCountry() !== 'TH') {
|
|
765
|
+
return libPhoneNumber.formatInternational();
|
|
766
|
+
} else {
|
|
767
|
+
return libPhoneNumber.formatNational();
|
|
768
|
+
}
|
|
769
|
+
} catch (e) {
|
|
770
|
+
console.error(e);
|
|
771
|
+
return phoneNumber;
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
return phoneNumber;
|
|
775
|
+
}
|
|
776
|
+
}
|