@unchainedshop/utils 2.7.1 → 2.7.3
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.
|
@@ -18,16 +18,20 @@ export const BasePricingSheet = (params) => {
|
|
|
18
18
|
return 0;
|
|
19
19
|
},
|
|
20
20
|
gross() {
|
|
21
|
+
// Sum contains taxes, thus it's gross when just suming everything
|
|
21
22
|
return this.sum();
|
|
22
23
|
},
|
|
23
24
|
net() {
|
|
25
|
+
// Remove all taxes from gross to get net
|
|
24
26
|
return this.sum() - this.taxSum();
|
|
25
27
|
},
|
|
26
|
-
total({ category, useNetPrice } = { useNetPrice: false }) {
|
|
27
|
-
const
|
|
28
|
-
const taxAmountForCategory = this.taxSum(
|
|
28
|
+
total({ category, useNetPrice, discountId } = { useNetPrice: false }) {
|
|
29
|
+
const amount = this.sum({ category, discountId });
|
|
30
|
+
const taxAmountForCategory = this.taxSum({ baseCategory: category, discountId });
|
|
31
|
+
// Sum does not contain taxes when filtering by category, it's net in that case and gross if there is no category
|
|
32
|
+
const netAmount = !category ? amount - taxAmountForCategory : amount;
|
|
29
33
|
return {
|
|
30
|
-
amount: Math.round(useNetPrice ?
|
|
34
|
+
amount: Math.round(useNetPrice ? netAmount : netAmount + taxAmountForCategory),
|
|
31
35
|
currency: this.currency,
|
|
32
36
|
};
|
|
33
37
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasePricingSheet.js","sourceRoot":"","sources":["../../src/director/BasePricingSheet.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAuC,EACP,EAAE;IAClC,MAAM,YAAY,GAAmC;QACnD,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;QACrC,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QAEzB,kBAAkB;YAChB,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1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AS,CAAC,CAAC,CACrF,EACH,IAAI,CAAC,WAAW,CACjB,CAAC;YAEF,OAAO,mBAAmB,CAAC;QAC7B,CAAC;QAED,gBAAgB,CAAC,gBAAgB;YAC/B,gBAAgB,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,EAAe,EAAE,EAAE;gBACtE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;oBACpB,GAAG,GAAG;oBACN,MAAM,EAAE,MAAM,GAAG,CAAC,CAAC;iBACL,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;KACF,CAAC;IAEF,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/utils",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.3",
|
|
4
4
|
"main": "lib/utils-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/utils-index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unchainedshop/logger": "^2.7.
|
|
33
|
+
"@unchainedshop/logger": "^2.7.3",
|
|
34
34
|
"abort-controller": "3.0.0",
|
|
35
35
|
"hashids": "^2.3.0",
|
|
36
36
|
"locale": "0.1.0",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^20.11.17",
|
|
41
|
-
"@unchainedshop/types": "^2.7.
|
|
41
|
+
"@unchainedshop/types": "^2.7.3",
|
|
42
42
|
"jest": "^29.7.0",
|
|
43
43
|
"typescript": "^5.3.3"
|
|
44
44
|
}
|
|
@@ -31,20 +31,24 @@ export const BasePricingSheet = <Calculation extends PricingCalculation>(
|
|
|
31
31
|
},
|
|
32
32
|
|
|
33
33
|
gross() {
|
|
34
|
+
// Sum contains taxes, thus it's gross when just suming everything
|
|
34
35
|
return this.sum();
|
|
35
36
|
},
|
|
36
37
|
|
|
37
38
|
net() {
|
|
39
|
+
// Remove all taxes from gross to get net
|
|
38
40
|
return this.sum() - this.taxSum();
|
|
39
41
|
},
|
|
40
42
|
|
|
41
|
-
total({ category, useNetPrice } = { useNetPrice: false }) {
|
|
42
|
-
const
|
|
43
|
-
const taxAmountForCategory = this.taxSum(
|
|
43
|
+
total({ category, useNetPrice, discountId } = { useNetPrice: false }) {
|
|
44
|
+
const amount = this.sum({ category, discountId });
|
|
45
|
+
const taxAmountForCategory = this.taxSum({ baseCategory: category, discountId });
|
|
46
|
+
|
|
47
|
+
// Sum does not contain taxes when filtering by category, it's net in that case and gross if there is no category
|
|
48
|
+
const netAmount = !category ? amount - taxAmountForCategory : amount;
|
|
49
|
+
|
|
44
50
|
return {
|
|
45
|
-
amount: Math.round(
|
|
46
|
-
useNetPrice ? grossAmountForCategory - taxAmountForCategory : grossAmountForCategory,
|
|
47
|
-
),
|
|
51
|
+
amount: Math.round(useNetPrice ? netAmount : netAmount + taxAmountForCategory),
|
|
48
52
|
currency: this.currency,
|
|
49
53
|
};
|
|
50
54
|
},
|