tripstorekrabi-shared 1.13.40 → 1.13.41
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 +76 -59
package/package.json
CHANGED
package/price.js
CHANGED
|
@@ -17,23 +17,23 @@ export const EXTRA_PAYMENT_CATEGORIES = [STARTING_POINT_EXTRA_PAYMENT,
|
|
|
17
17
|
ADD_ON_EXTRA_PAYMENT,
|
|
18
18
|
OTHER_EXTRA_PAYMENT];
|
|
19
19
|
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
20
|
+
const SELLING_MODE = 0;
|
|
21
|
+
const PARTNER_MODE = 1;
|
|
22
|
+
const OPERATOR_MODE = 2;
|
|
23
23
|
|
|
24
24
|
export function calculateProductSellingPrice(booking, pricing) {
|
|
25
|
-
return calculateProductPrice(booking, pricing, {
|
|
25
|
+
return calculateProductPrice(booking, pricing, { mode: SELLING_MODE });
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function calculateProductPartnerNetPrice(booking, pricing) {
|
|
29
|
-
return calculateProductPrice(booking, pricing, {
|
|
29
|
+
return calculateProductPrice(booking, pricing, { mode: PARTNER_MODE });
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export function calculateProductOperatorPrice(booking, pricing) {
|
|
33
|
-
return calculateProductPrice(booking, pricing, {
|
|
33
|
+
return calculateProductPrice(booking, pricing, { mode: OPERATOR_MODE });
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function calculateProductPrice(booking, pricing, options = {
|
|
36
|
+
function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE }) {
|
|
37
37
|
function calculateRetailPrice(commissionRate, price) {
|
|
38
38
|
return Math.floor(
|
|
39
39
|
(price * 100) /
|
|
@@ -56,7 +56,7 @@ function calculateProductPrice(booking, pricing, options = { paymentMode: SELLIN
|
|
|
56
56
|
if (volume[bookingType]) {
|
|
57
57
|
let customPricing = volume[bookingType];
|
|
58
58
|
|
|
59
|
-
if (options.
|
|
59
|
+
if (options.mode === SELLING_MODE) {
|
|
60
60
|
let commissionRate = pricing.commissionRates?.[bookingType];
|
|
61
61
|
|
|
62
62
|
if (commissionRate && commissionRate > 0) {
|
|
@@ -64,15 +64,15 @@ function calculateProductPrice(booking, pricing, options = { paymentMode: SELLIN
|
|
|
64
64
|
} else {
|
|
65
65
|
total = booking.adults * customPricing.adult.retailPrice + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * customPricing.child.retailPrice : 0);
|
|
66
66
|
}
|
|
67
|
-
} else if (options.
|
|
67
|
+
} else if (options.mode === PARTNER_MODE) {
|
|
68
68
|
total = booking.adults * customPricing.adult.partnerNetPrice + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * customPricing.child.partnerNetPrice : 0);
|
|
69
|
-
} else if (options.
|
|
69
|
+
} else if (options.mode === OPERATOR_MODE) {
|
|
70
70
|
total = booking.adults * (customPricing.adult.operatorNetPrice ?? volume.adult.operatorNetPrice) + (pricing.ageBands.child.active && volume.child && booking.children ? (booking.children * (customPricing.child.operatorNetPrice ?? volume.child.operatorNetPrice)) : 0);
|
|
71
71
|
}
|
|
72
72
|
} else {
|
|
73
|
-
if (options.
|
|
73
|
+
if (options.mode === SELLING_MODE || options.mode === PARTNER_MODE) {
|
|
74
74
|
total = booking.adults * volume.adult.sellingPrice + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * volume.child.sellingPrice : 0);
|
|
75
|
-
} else if (options.
|
|
75
|
+
} else if (options.mode === OPERATOR_MODE) {
|
|
76
76
|
total = booking.adults * volume.adult.operatorNetPrice + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * volume.child.operatorNetPrice : 0);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -91,7 +91,7 @@ function calculateProductPrice(booking, pricing, options = { paymentMode: SELLIN
|
|
|
91
91
|
if (volume[bookingType]) {
|
|
92
92
|
let customPricing = volume[bookingType];
|
|
93
93
|
|
|
94
|
-
if (options.
|
|
94
|
+
if (options.mode === SELLING_MODE) {
|
|
95
95
|
let commissionRate = pricing.commissionRates?.[bookingType];
|
|
96
96
|
|
|
97
97
|
if (commissionRate && commissionRate > 0) {
|
|
@@ -99,15 +99,15 @@ function calculateProductPrice(booking, pricing, options = { paymentMode: SELLIN
|
|
|
99
99
|
} else {
|
|
100
100
|
total = customPricing.retailPrice;
|
|
101
101
|
}
|
|
102
|
-
} else if (options.
|
|
102
|
+
} else if (options.mode === PARTNER_MODE) {
|
|
103
103
|
total = customPricing.partnerNetPrice
|
|
104
|
-
} else if (options.
|
|
104
|
+
} else if (options.mode === OPERATOR_MODE) {
|
|
105
105
|
total = customPricing.operatorNetPrice ?? volume.operatorNetPrice;
|
|
106
106
|
}
|
|
107
107
|
} else {
|
|
108
|
-
if (options.
|
|
108
|
+
if (options.mode === SELLING_MODE || options.mode === PARTNER_MODE) {
|
|
109
109
|
total = volume.sellingPrice;
|
|
110
|
-
} else if (options.
|
|
110
|
+
} else if (options.mode === OPERATOR_MODE) {
|
|
111
111
|
total = volume.operatorNetPrice;
|
|
112
112
|
}
|
|
113
113
|
}
|
|
@@ -155,34 +155,54 @@ export function calculatePartnerNetPrice(booking, product) {
|
|
|
155
155
|
product
|
|
156
156
|
).reduce(
|
|
157
157
|
(prev, curr) => prev + curr.price,
|
|
158
|
-
|
|
158
|
+
calculateProductPartnerNetPrice(
|
|
159
159
|
booking,
|
|
160
|
-
product.pricing
|
|
161
|
-
{
|
|
162
|
-
paymentMode: PARTNER_PAYMENT_MODE,
|
|
163
|
-
}
|
|
160
|
+
product.pricing
|
|
164
161
|
)
|
|
165
162
|
);
|
|
166
163
|
}
|
|
167
164
|
|
|
168
165
|
export function calculateTotalSellingPrice(booking, product) {
|
|
169
|
-
return calculateTotalPrice(booking, product, options = {
|
|
166
|
+
return calculateTotalPrice(booking, product, options = { mode: SELLING_MODE });
|
|
170
167
|
}
|
|
171
168
|
|
|
172
169
|
export function calculateTotalOperatorPrice(booking, product) {
|
|
173
|
-
return calculateTotalPrice(booking, product, options = {
|
|
170
|
+
return calculateTotalPrice(booking, product, options = { mode: OPERATOR_MODE });
|
|
174
171
|
}
|
|
175
172
|
|
|
176
173
|
export function calculateTotalPartnerNetPrice(booking, product) {
|
|
177
|
-
return calculateTotalPrice(booking, product, options = {
|
|
174
|
+
return calculateTotalPrice(booking, product, options = { mode: PARTNER_MODE });
|
|
178
175
|
}
|
|
179
176
|
|
|
180
|
-
function calculateTotalPrice(booking, product, options = {
|
|
177
|
+
function calculateTotalPrice(booking, product, options = { mode: SELLING_MODE }) {
|
|
181
178
|
let total = calculateProductPrice(booking, product.pricing, options);
|
|
182
179
|
total += calculateStartEndPointPrice(booking, findStartingPoint(product, booking.startingPointId, false), options);
|
|
183
180
|
total += calculateStartEndPointPrice(booking, findEndPoint(product, booking.endPointId, false), options);
|
|
184
181
|
total += calculateNationalParkFee(booking, product);
|
|
185
|
-
total += calculateExtraPayments(booking, {
|
|
182
|
+
total += calculateExtraPayments(booking, {
|
|
183
|
+
...options,
|
|
184
|
+
calculationMode: true,
|
|
185
|
+
filter: (item) => {
|
|
186
|
+
if (item.disabled === true) {
|
|
187
|
+
return false;
|
|
188
|
+
} else if (item.paymentMethod === PAY_ON_TOUR) {
|
|
189
|
+
return true;
|
|
190
|
+
} else if (item.paymentMethod === PAY_BEFORE && item.category === OTHER_EXTRA_PAYMENT) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
getPrice: (item, options) => {
|
|
195
|
+
if (item.paymentMethod === PAY_ON_TOUR) {
|
|
196
|
+
if (item.category !== OTHER_EXTRA_PAYMENT) {
|
|
197
|
+
return -getExtraPaymentPrice(item, options);
|
|
198
|
+
} else {
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
return getExtraPaymentPrice(item, options);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
186
206
|
total += calculateAddOnsPrice(booking, product, options);
|
|
187
207
|
return total;
|
|
188
208
|
}
|
|
@@ -191,32 +211,29 @@ export function calculateNationalParkFee(booking, product) {
|
|
|
191
211
|
return booking.nationalParkFee === ALREADY_PAID && product.nationalPark ? product.nationalPark.pricing.adult * booking.adults + product.nationalPark.pricing.child * booking.children : 0;
|
|
192
212
|
}
|
|
193
213
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return item.operatoPrice;
|
|
202
|
-
}
|
|
214
|
+
function getExtraPaymentPrice(item, options) {
|
|
215
|
+
switch (options.mode) {
|
|
216
|
+
case SELLING_MODE:
|
|
217
|
+
case PARTNER_MODE:
|
|
218
|
+
return item.receivedAmount ? item.receivedAmount : item.price;
|
|
219
|
+
case OPERATOR_MODE:
|
|
220
|
+
return item.operatoPrice;
|
|
203
221
|
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function calculateExtraPayments(booking, options = { mode: SELLING_MODE }) {
|
|
225
|
+
let filter = options.filter ?? ((item) => !item.disabled);
|
|
226
|
+
let getPrice = options.getPrice ?? getExtraPaymentPrice;
|
|
204
227
|
|
|
205
228
|
let total = 0;
|
|
206
|
-
for (const item of Object.values(booking.extraPayments).filter(
|
|
207
|
-
|
|
208
|
-
if (options.calculationMode && item.category !== OTHER_EXTRA_PAYMENT) {
|
|
209
|
-
total -= getPrice(item, options);
|
|
210
|
-
}
|
|
229
|
+
for (const item of Object.values(booking.extraPayments).filter(filter)) {
|
|
230
|
+
total += getPrice(item, options);
|
|
211
231
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
232
|
+
if (item.paymentMethod === PAY_ON_TOUR && options.mode === OPERATOR_MODE) {
|
|
233
|
+
let ourCommission = item.price - item.operatorPrice;
|
|
234
|
+
if (ourCommission > 0) {
|
|
235
|
+
total -= ourCommission;
|
|
217
236
|
}
|
|
218
|
-
} else if (!options.calculationMode || item.category === OTHER_EXTRA_PAYMENT) {
|
|
219
|
-
total += getPrice(item, options);
|
|
220
237
|
}
|
|
221
238
|
}
|
|
222
239
|
|
|
@@ -247,14 +264,14 @@ export function getExtraPaymentsPaidWithPartner(booking, product) {
|
|
|
247
264
|
{
|
|
248
265
|
category: STARTING_POINT_EXTRA_PAYMENT,
|
|
249
266
|
description: startingPoint.name,
|
|
250
|
-
price:
|
|
251
|
-
operatorPrice:
|
|
267
|
+
price: calculateStartEndPointSellingPrice(booking, startingPoint),
|
|
268
|
+
operatorPrice: calculateStartEndPointOperatorPrice(booking, startingPoint),
|
|
252
269
|
},
|
|
253
270
|
{
|
|
254
271
|
category: END_POINT_EXTRA_PAYMENT,
|
|
255
272
|
description: endPoint.name,
|
|
256
|
-
price:
|
|
257
|
-
operatorPrice:
|
|
273
|
+
price: calculateStartEndPointSellingPrice(booking, endPoint),
|
|
274
|
+
operatorPrice: calculateStartEndPointOperatorPrice(booking, endPoint),
|
|
258
275
|
},
|
|
259
276
|
{
|
|
260
277
|
category: NATIONAL_PARK_FEE_EXTRA_PAYMENT,
|
|
@@ -273,9 +290,9 @@ export function getExtraPaymentsPaidWithPartner(booking, product) {
|
|
|
273
290
|
);
|
|
274
291
|
}
|
|
275
292
|
|
|
276
|
-
export function calculateAddOnsPrice(booking, product, options = {
|
|
293
|
+
export function calculateAddOnsPrice(booking, product, options = { mode: SELLING_MODE }) {
|
|
277
294
|
let total = 0;
|
|
278
|
-
let isSelling = options.
|
|
295
|
+
let isSelling = options.mode in [SELLING_MODE, PARTNER_MODE];
|
|
279
296
|
for (const [id, addOn] of Object.entries(booking.addOns ?? {})) {
|
|
280
297
|
let addOnDef = findAddOn(id, product.addOns ?? []);
|
|
281
298
|
if (addOnDef) {
|
|
@@ -290,20 +307,20 @@ export function calculateAddOnsPrice(booking, product, options = { paymentMode:
|
|
|
290
307
|
}
|
|
291
308
|
|
|
292
309
|
export function calculateStartEndPointSellingPrice(people, startEndPoint) {
|
|
293
|
-
return calculateStartEndPointPrice(people, startEndPoint, {
|
|
310
|
+
return calculateStartEndPointPrice(people, startEndPoint, { mode: SELLING_MODE });
|
|
294
311
|
}
|
|
295
312
|
|
|
296
313
|
export function calculateStartEndPointOperatorPrice(people, startEndPoint) {
|
|
297
|
-
return calculateStartEndPointPrice(people, startEndPoint, {
|
|
314
|
+
return calculateStartEndPointPrice(people, startEndPoint, { mode: OPERATOR_MODE });
|
|
298
315
|
}
|
|
299
316
|
|
|
300
317
|
export function calculateStartEndPointPartnerNetPrice(people, startEndPoint) {
|
|
301
|
-
return calculateStartEndPointPrice(people, startEndPoint, {
|
|
318
|
+
return calculateStartEndPointPrice(people, startEndPoint, { mode: PARTNER_MODE });
|
|
302
319
|
}
|
|
303
320
|
|
|
304
|
-
function calculateStartEndPointPrice(people, startEndPoint, options = {
|
|
321
|
+
function calculateStartEndPointPrice(people, startEndPoint, options = { mode: SELLING_MODE }) {
|
|
305
322
|
let pricing = startEndPoint?.pricing;
|
|
306
|
-
let isSelling = options.
|
|
323
|
+
let isSelling = options.mode in [SELLING_MODE, PARTNER_MODE];
|
|
307
324
|
if (pricing) {
|
|
308
325
|
if (pricing.type === "group") {
|
|
309
326
|
return (isSelling ? pricing.sellingPrice : pricing.operatorNetPrice) * Math.ceil((people.adults + people.children) / pricing.max);
|