tripstorekrabi-shared 1.12.6 → 1.12.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/price.js +14 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.12.6",
3
+ "version": "1.12.8",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
package/price.js CHANGED
@@ -2,6 +2,8 @@
2
2
  import { getBookingType } from "./utils.js";
3
3
 
4
4
  export const MAX_PAX = 30;
5
+ export const PAY_ON_TOUR = 'Pay on tour';
6
+ export const ALREADY_PAID = "Already paid";
5
7
 
6
8
  export function calculateProductPrice(booking, pricing, mode = "retail") {
7
9
  let type = pricing.type;
@@ -113,12 +115,23 @@ export function calculateTotalPrice(data, product, mode = "retail") {
113
115
  total += calculateStartEndPointPrice(data, findStartingPoint(product, data.startingPointId, false), mode === "retail" || mode === "partner");
114
116
  total += calculateStartEndPointPrice(data, findEndPoint(product, data.endPointId, false), mode === "retail" || mode === "partner");
115
117
  total += calculateNationalParkFee(data, product);
118
+ total += calculateExtraPayments(data, mode === "retail" || mode === "partner");
116
119
  total += calculateAddOnsPrice(data, product, mode === "retail" || mode === "partner");
117
120
  return total;
118
121
  }
119
122
 
120
123
  export function calculateNationalParkFee(data, product) {
121
- return data.nationalParkFee === "Already paid" && product.nationalPark ? product.nationalPark.pricing.adult * data.adults + product.nationalPark.pricing.child * data.children : 0;
124
+ return data.nationalParkFee === ALREADY_PAID && product.nationalPark ? product.nationalPark.pricing.adult * data.adults + product.nationalPark.pricing.child * data.children : 0;
125
+ }
126
+
127
+ export function calculateExtraPayments(data, selling = true) {
128
+ let total = 0;
129
+ if (data.extraPayments) {
130
+ for (const extraPayment of Object.values(data.extraPayments)) {
131
+ total += selling ? extraPayment.receivedAmount : extraPayment.operatorPrice;
132
+ }
133
+ }
134
+ return total;
122
135
  }
123
136
 
124
137
  export function calculateAddOnsPrice(data, product, selling = true) {