tripstorekrabi-shared 1.13.64 → 1.13.65

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 +28 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.13.64",
3
+ "version": "1.13.65",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
package/price.js CHANGED
@@ -311,6 +311,34 @@ export function getExtraPaymentsPaidWithPartner(booking, product) {
311
311
  });
312
312
  }
313
313
 
314
+ export function getActiveExtraPayments(extraPayments) {
315
+ return extraPayments
316
+ .filter(([id, item]) => !item.disabled)
317
+ .sort(([id1, item1], [id2, item2]) =>
318
+ item1.description.localeCompare(item2.description)
319
+ );
320
+ }
321
+
322
+ export function getExtraPaymentsOperatorPrice(extraPayments) {
323
+ return getActiveExtraPayments(extraPayments).reduce(
324
+ (prev, curr) => {
325
+ let price;
326
+ let item = curr[1];
327
+ if (item.paymentMethod === PAY_ON_TOUR) {
328
+ let ourCommission = item.price - item.operatorPrice;
329
+ if (ourCommission > 0) {
330
+ price = -ourCommission;
331
+ }
332
+ } else {
333
+ price = item.operatorPrice;
334
+ }
335
+
336
+ return prev + price;
337
+ },
338
+ 0
339
+ );
340
+ }
341
+
314
342
  export function calculateAddOnsPrice(booking, product, options = { mode: SELLING_MODE }) {
315
343
  let total = 0;
316
344
  let isSelling = options.mode in [SELLING_MODE, PARTNER_MODE];