tripstorekrabi-shared 1.20.4 → 1.21.0
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/ota.js +24 -0
- package/package.json +4 -3
- package/price.js +0 -45
package/ota.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function isCommissionable(operatorId, booking, otas) {
|
|
2
|
+
let ota = otas.find((item) => booking.referenceNumber.startsWith(item.bookingPrefix));
|
|
3
|
+
|
|
4
|
+
// stop checking if it's not an OTA booking
|
|
5
|
+
if (ota === undefined) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// find the account associated with the operator
|
|
10
|
+
let account = (ota.accounts ?? []).find(
|
|
11
|
+
(account) =>
|
|
12
|
+
account.operators.find((item) => item.id === operatorId) &&
|
|
13
|
+
(!booking.gygSupplierId || booking.gygSupplierId === account.gygSupplierId)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// find the default account where all operators apply
|
|
17
|
+
if (!account) {
|
|
18
|
+
account = ((ota ?? {}).accounts ?? []).find(
|
|
19
|
+
(account) => (account.operators ?? []).length === 0
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return account?.commissionable ?? true;
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tripstorekrabi-shared",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Shared library for Trip Store Krabi",
|
|
5
5
|
"author": "Stefan Sommer <tonprince@gmail.com>",
|
|
6
6
|
"repository": {
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
"./price": "./price.js",
|
|
13
13
|
"./availability": "./availability.js",
|
|
14
14
|
"./booking": "./booking.js",
|
|
15
|
-
"./product": "./product.js"
|
|
15
|
+
"./product": "./product.js",
|
|
16
|
+
"./ota": "./ota.js"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
19
|
"dayjs": "^1.11.13",
|
|
19
|
-
"libphonenumber-js": "^1.12.
|
|
20
|
+
"libphonenumber-js": "^1.12.12",
|
|
20
21
|
"nanoid": "^5.1.5"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
package/price.js
CHANGED
|
@@ -27,7 +27,6 @@ const SELLING_MODE = 0;
|
|
|
27
27
|
const PARTNER_MODE = 1;
|
|
28
28
|
const OPERATOR_MODE = 2;
|
|
29
29
|
|
|
30
|
-
|
|
31
30
|
export function calculateProductSellingPrice(booking, pricing) {
|
|
32
31
|
return booking.customerPaymentStatus === "Refunded" ? 0 : calculateProductPrice(booking, pricing, { mode: SELLING_MODE });
|
|
33
32
|
}
|
|
@@ -423,48 +422,4 @@ export function findAddOn(id, addOns) {
|
|
|
423
422
|
|
|
424
423
|
export function inRange(expected, actual, boundary = 10) {
|
|
425
424
|
return ((expected - boundary) <= actual) && ((expected + boundary) >= actual);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
export function calculatePhayunPrices(booking, product) {
|
|
429
|
-
let productPrice;
|
|
430
|
-
let cashOnTourAmount = 0;
|
|
431
|
-
let activeExtraPayments = getActiveExtraPayments(Object.entries(booking.extraPayments));
|
|
432
|
-
let bookingType = getBookingType(booking.referenceNumber);
|
|
433
|
-
|
|
434
|
-
if (
|
|
435
|
-
product.operator.default.invoicing?.operator?.create &&
|
|
436
|
-
product.operator.default.invoicing?.operator?.partners?.[
|
|
437
|
-
bookingType
|
|
438
|
-
]?.include
|
|
439
|
-
) {
|
|
440
|
-
productPrice = booking.partnerNetPrice;
|
|
441
|
-
} else {
|
|
442
|
-
productPrice = booking.operatorNetPrice;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
(product.addOns ?? []).forEach((addOnDef) => {
|
|
446
|
-
let addOn = booking.addOns?.[addOnDef.id];
|
|
447
|
-
let pax =
|
|
448
|
-
(addOn?.adults ?? 0) +
|
|
449
|
-
(addOn?.children ?? 0);
|
|
450
|
-
|
|
451
|
-
if (pax > 0) {
|
|
452
|
-
let addOnPrice =
|
|
453
|
-
addOn.adults * addOnDef.pricing.adult.operatorNetPrice +
|
|
454
|
-
(addOn.children ?? 0) *
|
|
455
|
-
addOnDef.pricing.child.operatorNetPrice;
|
|
456
|
-
|
|
457
|
-
// check for extra payment
|
|
458
|
-
let extraPayment = activeExtraPayments.find(([id]) => id === addOnDef.id)?.[1];
|
|
459
|
-
if (!extraPayment) { // add-on paid via partner
|
|
460
|
-
productPrice -= addOnPrice;
|
|
461
|
-
} else if (extraPayment.paymentMethod === PAY_BEFORE) { // add-on paid via extra payment
|
|
462
|
-
productPrice -= addOnPrice;
|
|
463
|
-
} else if (extraPayment.paymentMethod === PAY_ON_TOUR) { // add-on is paid on tour
|
|
464
|
-
cashOnTourAmount += addOnPrice;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
return { productPrice, cashOnTourAmount };
|
|
470
425
|
}
|