tripstorekrabi-shared 1.13.65 → 1.13.67
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 +1 -1
- package/price.js +44 -0
package/package.json
CHANGED
package/price.js
CHANGED
|
@@ -397,4 +397,48 @@ export function findAddOn(id, addOns) {
|
|
|
397
397
|
|
|
398
398
|
export function inRange(expected, actual, boundary = 10) {
|
|
399
399
|
return ((expected - boundary) <= actual) && ((expected + boundary) >= actual);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export function calculatePhayunPrices(booking, product) {
|
|
403
|
+
let productPrice;
|
|
404
|
+
let cashOnTourAmount = 0;
|
|
405
|
+
let activeExtraPayments = getActiveExtraPayments(Object.entries(booking.extraPayments));
|
|
406
|
+
let bookingType = getBookingType(booking.referenceNumber);
|
|
407
|
+
|
|
408
|
+
if (
|
|
409
|
+
product.operator.default.invoicing?.operator?.create &&
|
|
410
|
+
product.operator.default.invoicing?.operator?.partners?.[
|
|
411
|
+
bookingType
|
|
412
|
+
]?.include
|
|
413
|
+
) {
|
|
414
|
+
productPrice = booking.partnerNetPrice;
|
|
415
|
+
} else {
|
|
416
|
+
productPrice = booking.operatorNetPrice;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
(product.addOns ?? []).forEach((addOnDef) => {
|
|
420
|
+
let addOn = booking.addOns?.[addOnDef.id];
|
|
421
|
+
let pax =
|
|
422
|
+
(addOn?.adults ?? 0) +
|
|
423
|
+
(addOn?.children ?? 0);
|
|
424
|
+
|
|
425
|
+
if (pax > 0) {
|
|
426
|
+
let addOnPrice =
|
|
427
|
+
addOn.adults * addOnDef.pricing.adult.operatorNetPrice +
|
|
428
|
+
(addOn.children ?? 0) *
|
|
429
|
+
addOnDef.pricing.child.operatorNetPrice;
|
|
430
|
+
|
|
431
|
+
// check for extra payment
|
|
432
|
+
let extraPayment = activeExtraPayments.find(([id]) => id === addOnDef.id)?.[1];
|
|
433
|
+
if (!extraPayment) { // add-on paid via partner
|
|
434
|
+
productPrice -= addOnPrice;
|
|
435
|
+
} else if (extraPayment.paymentMethod === PAY_BEFORE) { // add-on paid via extra payment
|
|
436
|
+
productPrice -= addOnPrice;
|
|
437
|
+
} else if (extraPayment.paymentMethod === PAY_ON_TOUR) { // add-on is paid on tour
|
|
438
|
+
cashOnTourAmount += addOnPrice;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
return { productPrice, cashOnTourAmount };
|
|
400
444
|
}
|