tripstorekrabi-shared 1.13.4 → 1.13.6

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 +22 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.13.4",
3
+ "version": "1.13.6",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
package/price.js CHANGED
@@ -111,31 +111,41 @@ export function countMaxPeople(pricing) {
111
111
  return volume ? volume.reduce((p, v) => p > v ? p : v) : MAX_PAX;
112
112
  }
113
113
 
114
- export function calculateTotalPrice(data, product, mode = "retail") {
115
- let total = calculateProductPrice(data, product.pricing, mode);
116
- total += calculateExtraPayments(data, mode === "retail" || mode === "partner");
117
- total += calculateAddOnsPrice(data, product, mode === "retail" || mode === "partner");
114
+ export function getTotalAmountToBeReceived(booking) {
115
+ return booking.partnerNetPrice + calculateExtraPayments(booking, true);
116
+ }
117
+
118
+ export function getTotalOperatorNetPrice(booking) {
119
+ return booking.operatorNetPrice + calculateExtraPayments(booking, false);
120
+ }
121
+
122
+ export function calculateTotalPrice(booking, product, mode = "retail") {
123
+ let total = calculateProductPrice(booking, product.pricing, mode);
124
+ total += calculateStartEndPointPrice(booking, findStartingPoint(product, booking.startingPointId, false), mode === "retail" || mode === "partner");
125
+ total += calculateStartEndPointPrice(booking, findEndPoint(product, booking.endPointId, false), mode === "retail" || mode === "partner");
126
+ total += calculateNationalParkFee(booking, product);
127
+ total += calculateAddOnsPrice(booking, product, mode === "retail" || mode === "partner");
118
128
  return total;
119
129
  }
120
130
 
121
- export function calculateNationalParkFee(data, product) {
122
- return data.nationalParkFee === ALREADY_PAID && product.nationalPark ? product.nationalPark.pricing.adult * data.adults + product.nationalPark.pricing.child * data.children : 0;
131
+ export function calculateNationalParkFee(booking, product) {
132
+ return booking.nationalParkFee === ALREADY_PAID && product.nationalPark ? product.nationalPark.pricing.adult * booking.adults + product.nationalPark.pricing.child * booking.children : 0;
123
133
  }
124
134
 
125
- export function calculateExtraPayments(data, selling = true) {
135
+ export function calculateExtraPayments(booking, selling = true) {
126
136
  let total = 0;
127
- if (data.extraPayments) {
128
- for (const extraPayment of Object.values(data.extraPayments).filter((item) => !item.disabled && item.paymentMethod !== PAY_ON_TOUR)) {
137
+ if (booking.extraPayments) {
138
+ for (const extraPayment of Object.values(booking.extraPayments).filter((item) => !item.disabled && item.paymentMethod !== PAY_ON_TOUR)) {
129
139
  total += selling ? (extraPayment.receivedAmount ? extraPayment.receivedAmount : extraPayment.price) : extraPayment.operatorPrice;
130
140
  }
131
141
  }
132
142
  return total;
133
143
  }
134
144
 
135
- export function calculateAddOnsPrice(data, product, selling = true) {
145
+ export function calculateAddOnsPrice(booking, product, selling = true) {
136
146
  let total = 0;
137
- if (data.addOns) {
138
- for (const [id, addOn] of Object.entries(data.addOns)) {
147
+ if (booking.addOns) {
148
+ for (const [id, addOn] of Object.entries(booking.addOns)) {
139
149
  let addOnDef = findAddOn(id, product.addOns);
140
150
  if (addOnDef) {
141
151
  total += addOn.adults * (selling ? addOnDef.pricing.adult