@medipass/utils 11.54.5-feature-wsv.0 → 11.55.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,39 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [11.55.1](https://github.com/medipass/web/compare/@medipass/utils@11.55.0...@medipass/utils@11.55.1) (2021-10-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * comcare verify endpoint ([#577](https://github.com/medipass/web/issues/577)) ([e9aab21](https://github.com/medipass/web/commit/e9aab21))
12
+
13
+
14
+
15
+
16
+
17
+ # [11.55.0](https://github.com/medipass/web/compare/@medipass/utils@11.54.5...@medipass/utils@11.55.0) (2021-10-22)
18
+
19
+
20
+ ### Features
21
+
22
+ * worksafe victoria ([#573](https://github.com/medipass/web/issues/573)) ([5a329ba](https://github.com/medipass/web/commit/5a329ba))
23
+
24
+
25
+
26
+
27
+
28
+ ## [11.54.5](https://github.com/medipass/web/compare/@medipass/utils@11.54.4...@medipass/utils@11.54.5) (2021-10-22)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * service item totals ([#574](https://github.com/medipass/web/issues/574)) ([04b60ae](https://github.com/medipass/web/commit/04b60ae))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [11.54.4](https://github.com/medipass/web-medicules/compare/@medipass/utils@11.54.3...@medipass/utils@11.54.4) (2021-10-21)
7
40
 
8
41
  **Note:** Version bump only for package @medipass/utils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medipass/utils",
3
- "version": "11.54.5-feature-wsv.0",
3
+ "version": "11.55.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -44,10 +44,10 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@babel/plugin-transform-runtime": "7.8.3",
47
- "@medipass/web-sdk": "^11.18.5-feature-wsv.0",
47
+ "@medipass/web-sdk": "^11.18.7",
48
48
  "redux-mock-store": "^1.3.0",
49
49
  "redux-thunk": "^2.2.0",
50
50
  "rimraf": "^2.6.2"
51
51
  },
52
- "gitHead": "2abed80d5e42153dff8f4052d960a42f3bc3de51"
52
+ "gitHead": "31512948e6b2e351037d9b12fe006aa8abf44bb1"
53
53
  }
package/service-items.js CHANGED
@@ -27,32 +27,25 @@ var calculateTotalAmount = function calculateTotalAmount(serviceItems, opts) {
27
27
  }
28
28
 
29
29
  var total = serviceItems.reduce(function (total, item) {
30
- var itemTotal = parseFloat(_get(item, 'feeAmount', '0'));
31
-
32
- if (parseFloat(_get(item, 'initialGrossAmount', '0'))) {
33
- itemTotal = parseFloat(_get(item, 'initialGrossAmount', '0'));
34
- }
35
-
36
30
  var includeQuantity = _get(opts, 'includeQuantity');
37
31
 
38
32
  if (funders.isIcare(_get(opts, 'funder.code')) && _get(item, 'unit') === 'minutes') {
39
33
  includeQuantity = false;
40
34
  }
41
35
 
42
- if (includeQuantity && item.quantity && !item.isExtendedPrice) {
43
- itemTotal = parseFloat((itemTotal * item.quantity).toFixed(6));
44
- }
36
+ var prices = calculatePrices({
37
+ isTaxable: Boolean(opts.includeGST && item.isTaxable),
38
+ isGross: item.isGross,
39
+ initialFeeAmount: (item == null ? void 0 : item.initialFeeAmount) ? parseFloat((item == null ? void 0 : item.initialFeeAmount) || 0) : parseFloat((item == null ? void 0 : item.feeAmount) || 0),
40
+ isExtendedPrice: item == null ? void 0 : item.isExtendedPrice,
41
+ quantity: includeQuantity ? item.quantity : 1
42
+ });
43
+ var itemTotal = undefined;
45
44
 
46
- if (opts.includeGST && item.isTaxable) {
47
- if (opts.isSubTotal) {
48
- if (item.isGross) {
49
- itemTotal -= parseFloat((itemTotal / 11).toFixed(6));
50
- }
51
- } else {
52
- if (!item.isGross) {
53
- itemTotal = parseFloat((itemTotal * 1.1).toFixed(6));
54
- }
55
- }
45
+ if (opts.isSubTotal) {
46
+ itemTotal = prices == null ? void 0 : prices.feeAmount;
47
+ } else {
48
+ itemTotal = prices == null ? void 0 : prices.grossAmount;
56
49
  }
57
50
 
58
51
  if (opts.includeDiscount && item.discountAmount) {
@@ -81,27 +74,15 @@ var calculateTotalGSTAmount = function calculateTotalGSTAmount(serviceItems, opt
81
74
  includeQuantity = false;
82
75
  }
83
76
 
84
- if (item.isTaxable) {
85
- var itemTotal = parseFloat(_get(item, 'feeAmount', '0'));
86
-
87
- if (parseFloat(_get(item, 'initialGrossAmount', '0'))) {
88
- itemTotal = parseFloat(_get(item, 'initialGrossAmount', '0'));
89
- }
90
-
91
- if (includeQuantity && item.quantity && !item.isExtendedPrice) {
92
- itemTotal = parseFloat((itemTotal * item.quantity).toFixed(6));
93
- }
94
-
95
- if (item.isGross) {
96
- itemTotal = parseFloat((itemTotal / 11).toFixed(6));
97
- } else {
98
- itemTotal = parseFloat((itemTotal * 0.1).toFixed(6));
99
- }
100
-
101
- return total + itemTotal;
102
- }
103
-
104
- return total;
77
+ var prices = calculatePrices({
78
+ isTaxable: item.isTaxable,
79
+ isGross: item.isGross,
80
+ initialFeeAmount: (item == null ? void 0 : item.initialFeeAmount) ? parseFloat((item == null ? void 0 : item.initialFeeAmount) || 0) : parseFloat((item == null ? void 0 : item.feeAmount) || 0),
81
+ isExtendedPrice: item == null ? void 0 : item.isExtendedPrice,
82
+ quantity: includeQuantity ? item.quantity : 1
83
+ });
84
+ var gstAmount = prices == null ? void 0 : prices.taxAmount;
85
+ return total + gstAmount;
105
86
  }, 0);
106
87
  };
107
88
  var applyDiscountToServiceItems = function applyDiscountToServiceItems(serviceItems, _ref) {
@@ -216,7 +197,51 @@ function mapItemsToClaimItems(transaction) {
216
197
  return newItems;
217
198
  }
218
199
 
200
+ var round2DecimalPlaces = function round2DecimalPlaces(num) {
201
+ return Math.round((num + Number.EPSILON) * 100) / 100;
202
+ };
203
+
204
+ var calculatePrices = function calculatePrices(_ref3) {
205
+ var isTaxable = _ref3.isTaxable,
206
+ isGross = _ref3.isGross,
207
+ initialFeeAmount = _ref3.initialFeeAmount,
208
+ isExtendedPrice = _ref3.isExtendedPrice,
209
+ quantity = _ref3.quantity;
210
+ var grossAmount = parseFloat(initialFeeAmount || 0);
211
+ var feeAmount = parseFloat(initialFeeAmount || 0);
212
+ var taxAmount = 0;
213
+
214
+ if (!isTaxable) {
215
+ return {
216
+ grossAmount: grossAmount,
217
+ feeAmount: feeAmount,
218
+ taxAmount: taxAmount
219
+ };
220
+ }
221
+
222
+ if (isGross) {
223
+ taxAmount = parseFloat(round2DecimalPlaces(grossAmount / 11).toFixed(2) || 0);
224
+ feeAmount = grossAmount - taxAmount;
225
+ } else {
226
+ taxAmount = parseFloat((feeAmount * 1.1).toFixed(6)) - feeAmount;
227
+ grossAmount = feeAmount + taxAmount;
228
+ }
229
+
230
+ if (!isExtendedPrice) {
231
+ taxAmount = taxAmount * quantity;
232
+ feeAmount = feeAmount * quantity;
233
+ grossAmount = grossAmount * quantity;
234
+ }
235
+
236
+ return {
237
+ grossAmount: grossAmount,
238
+ feeAmount: feeAmount,
239
+ taxAmount: taxAmount
240
+ };
241
+ };
242
+
219
243
  exports.applyDiscountToServiceItems = applyDiscountToServiceItems;
244
+ exports.calculatePrices = calculatePrices;
220
245
  exports.calculateTotalAmount = calculateTotalAmount;
221
246
  exports.calculateTotalDiscountAmount = calculateTotalDiscountAmount;
222
247
  exports.calculateTotalGSTAmount = calculateTotalGSTAmount;