tripstorekrabi-shared 1.13.13 → 1.13.14

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 +39 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.13.13",
3
+ "version": "1.13.14",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
package/price.js CHANGED
@@ -112,11 +112,27 @@ export function countMaxPeople(pricing) {
112
112
  }
113
113
 
114
114
  export function getTotalAmountToBeReceived(booking) {
115
- return booking.customerPaymentStatus === "Refunded" ? 0 : booking.partnerNetPrice + calculateExtraPayments(booking, true);
115
+ let total;
116
+
117
+ if (booking.customerPaymentStatus === "Refunded") {
118
+ total = 0;
119
+ } else {
120
+ total = calculateExtraPayments(booking, true);
121
+ }
122
+
123
+ return total;
116
124
  }
117
125
 
118
126
  export function getTotalOperatorNetPrice(booking) {
119
- return booking.operatorPaymentStatus === "No Charge" ? 0 : booking.operatorNetPrice + calculateExtraPayments(booking, false);
127
+ let total;
128
+
129
+ if (booking.operatorPaymentStatus === "No Charge") {
130
+ total = 0;
131
+ } else {
132
+ total = calculateExtraPayments(booking, false);
133
+ }
134
+
135
+ return total;
120
136
  }
121
137
 
122
138
  export function calculateTotalPrice(booking, product, mode = "retail") {
@@ -133,18 +149,29 @@ export function calculateNationalParkFee(booking, product) {
133
149
  return booking.nationalParkFee === ALREADY_PAID && product.nationalPark ? product.nationalPark.pricing.adult * booking.adults + product.nationalPark.pricing.child * booking.children : 0;
134
150
  }
135
151
 
136
- export function calculateExtraPayments(booking, selling = true, excludePaymentsWithCategory = false) {
152
+ export function calculateExtraPayments(booking, selling = true, calculationMode = false) {
137
153
  let total = 0;
138
- if (booking.extraPayments) {
139
- for (const extraPayment of Object.values(booking.extraPayments).filter((item) => !item.disabled && (!excludePaymentsWithCategory || item.category === "OTHER"))) {
140
- if (!selling) {
141
- if (extraPayment.paymentMethod === PAY_ON_TOUR) {
142
- total -= extraPayment.price - extraPayment.operatorPrice;
143
- } else {
144
- total += extraPayment.operatorPrice;
154
+ for (const extraPayment of Object.values(booking.extraPayments ?? {}).filter((item) => !item.disabled)) {
155
+ if (selling) {
156
+ if (extraPayment.paymentMethod === PAY_ON_TOUR) {
157
+ if (calculationMode && item.category !== "OTHER") {
158
+ total -= extraPayment.price;
159
+ }
160
+ } else if (!calculationMode || item.category === "OTHER") {
161
+ total += extraPayment.receivedAmount ? extraPayment.receivedAmount : extraPayment.price;
162
+ }
163
+ } else {
164
+ if (extraPayment.paymentMethod === PAY_ON_TOUR) {
165
+ if (calculationMode && item.category !== "OTHER") {
166
+ total -= extraPayment.operatorPrice;
167
+ }
168
+
169
+ let ourCommission = extraPayment.price - extraPayment.operatorPrice;
170
+ if (ourCommission > 0) {
171
+ total -= ourCommission;
145
172
  }
146
- } else if (extraPayment.paymentMethod !== PAY_ON_TOUR) {
147
- total += extraPayment.receivedAmount ? extraPayment.receivedAmount : extraPayment.price
173
+ } else if (!calculationMode || item.category === "OTHER") {
174
+ total += extraPayment.operatorPrice;
148
175
  }
149
176
  }
150
177
  }