tripstorekrabi-shared 1.13.46 → 1.13.48

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 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tripstorekrabi-shared",
3
- "version": "1.13.46",
3
+ "version": "1.13.48",
4
4
  "description": "Shared library for Trip Store Krabi",
5
5
  "author": "Stefan Sommer <tonprince@gmail.com>",
6
6
  "repository": {
package/price.js CHANGED
@@ -22,25 +22,26 @@ const PARTNER_MODE = 1;
22
22
  const OPERATOR_MODE = 2;
23
23
 
24
24
  export function calculateProductSellingPrice(booking, pricing) {
25
- return calculateProductPrice(booking, pricing, { mode: SELLING_MODE });
25
+ return booking.customerPaymentStatus === "Refunded" ? 0 : calculateProductPrice(booking, pricing, { mode: SELLING_MODE });
26
26
  }
27
27
 
28
28
  export function calculateProductPartnerNetPrice(booking, pricing) {
29
- return calculateProductPrice(booking, pricing, { mode: PARTNER_MODE });
29
+ return booking.customerPaymentStatus === "Refunded" ? 0 : calculateProductPrice(booking, pricing, { mode: PARTNER_MODE });
30
30
  }
31
31
 
32
32
  export function calculateProductOperatorPrice(booking, pricing) {
33
- return calculateProductPrice(booking, pricing, { mode: OPERATOR_MODE });
33
+ return booking.operatorPaymentStatus === "No Charge" ? 0 : calculateProductPrice(booking, pricing, { mode: OPERATOR_MODE });
34
+ }
35
+
36
+ function calculateSellingPrice(commissionRate, price) {
37
+ return Math.floor(
38
+ (price * 100) /
39
+ (100 -
40
+ commissionRate)
41
+ );
34
42
  }
35
43
 
36
44
  function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE }) {
37
- function calculateRetailPrice(commissionRate, price) {
38
- return Math.floor(
39
- (price * 100) /
40
- (100 -
41
- commissionRate)
42
- );
43
- }
44
45
  let type = pricing.type;
45
46
  let total = 0;
46
47
 
@@ -60,7 +61,7 @@ function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE
60
61
  let commissionRate = pricing.commissionRates?.[bookingType];
61
62
 
62
63
  if (commissionRate && commissionRate > 0) {
63
- total = booking.adults * calculateRetailPrice(commissionRate, customPricing.adult.partnerNetPrice) + (pricing.ageBands.child.active && volume.child && booking.children ? (booking.children * calculateRetailPrice(commissionRate, customPricing.child.partnerNetPrice)) : 0);
64
+ total = booking.adults * calculateSellingPrice(commissionRate, customPricing.adult.partnerNetPrice) + (pricing.ageBands.child.active && volume.child && booking.children ? (booking.children * calculateSellingPrice(commissionRate, customPricing.child.partnerNetPrice)) : 0);
64
65
  } else {
65
66
  total = booking.adults * customPricing.adult.retailPrice + (pricing.ageBands.child.active && volume.child && booking.children ? booking.children * customPricing.child.retailPrice : 0);
66
67
  }
@@ -95,7 +96,7 @@ function calculateProductPrice(booking, pricing, options = { mode: SELLING_MODE
95
96
  let commissionRate = pricing.commissionRates?.[bookingType];
96
97
 
97
98
  if (commissionRate && commissionRate > 0) {
98
- total = calculateRetailPrice(commissionRate, customPricing.partnerNetPrice);
99
+ total = calculateSellingPrice(commissionRate, customPricing.partnerNetPrice);
99
100
  } else {
100
101
  total = customPricing.retailPrice;
101
102
  }
@@ -138,15 +139,7 @@ export function countMaxPeople(pricing) {
138
139
  }
139
140
 
140
141
  export function getTotalAmountToBeReceived(booking, options = {}) {
141
- let total;
142
-
143
- if (booking.customerPaymentStatus === "Refunded") {
144
- total = 0;
145
- } else {
146
- total = booking.partnerNetPrice + calculateExtraPayments(booking, { mode: SELLING_MODE, ...options });
147
- }
148
-
149
- return total;
142
+ return booking.customerPaymentStatus === "Refunded" ? 0 : booking.partnerNetPrice + calculateExtraPayments(booking, { mode: SELLING_MODE, ...options })
150
143
  }
151
144
 
152
145
  export function calculatePartnerNetPrice(booking, product) {