@darkpos/pricing 1.0.11 → 1.0.13
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/lib/item/addIndirectModifier.js +6 -2
- package/lib/item/calculate.js +3 -1
- package/lib/modifier/index.js +2 -0
- package/lib/modifier/isIgnoreQuantity.js +5 -0
- package/lib/order/addItem.js +2 -50
- package/lib/order/getOrderItemSubscriptions.js +43 -0
- package/lib/order/index.js +2 -0
- package/package.json +2 -2
|
@@ -41,10 +41,14 @@ module.exports = ({ utils, modifierActions }) => {
|
|
|
41
41
|
compute: {
|
|
42
42
|
...inheritedModifier.compute,
|
|
43
43
|
amount: math.add(
|
|
44
|
-
inheritedModifier.compute.amount,
|
|
45
|
-
|
|
44
|
+
math.mul(inheritedModifier.compute.amount, selectedItem.quantity),
|
|
45
|
+
difference
|
|
46
46
|
),
|
|
47
47
|
},
|
|
48
|
+
properties: {
|
|
49
|
+
...inheritedModifier.properties,
|
|
50
|
+
ignoreQuantity: true,
|
|
51
|
+
},
|
|
48
52
|
};
|
|
49
53
|
}
|
|
50
54
|
return itemsModifiers;
|
package/lib/item/calculate.js
CHANGED
|
@@ -67,7 +67,9 @@ module.exports = ({ _, utils, modifierActions }) => {
|
|
|
67
67
|
modifiers.push(_modifier);
|
|
68
68
|
const { type, _computed } = _modifier;
|
|
69
69
|
// console.log('computedPrice => ', _computed);
|
|
70
|
-
let computedAmount =
|
|
70
|
+
let computedAmount = modifierActions.isIgnoreQuantity(_modifier)
|
|
71
|
+
? _computed.amount
|
|
72
|
+
: math.mul(_computed.amount, quantity);
|
|
71
73
|
// subscription modifiers have fixed amount and can't be multiplied by quantity
|
|
72
74
|
if (modifierActions.isSubscription(_modifier))
|
|
73
75
|
computedAmount = _computed.amount;
|
package/lib/modifier/index.js
CHANGED
|
@@ -99,6 +99,7 @@ const isCustomerTagsExtend = require('./isCustomerTagsExtend');
|
|
|
99
99
|
const isAmountOverride = require('./isAmountOverride');
|
|
100
100
|
const isDiscount = require('./isDiscount');
|
|
101
101
|
const isHidden = require('./isHidden');
|
|
102
|
+
const isIgnoreQuantity = require('./isIgnoreQuantity');
|
|
102
103
|
const isGratuity = require('./isGratuity');
|
|
103
104
|
const isPaymentMethods = require('./isPaymentMethods');
|
|
104
105
|
const isPaymentTypes = require('./isPaymentTypes');
|
|
@@ -221,6 +222,7 @@ const modifierActions = (deps = {}) => {
|
|
|
221
222
|
isAmountOverride: isAmountOverride(innerDeps),
|
|
222
223
|
isDiscount: isDiscount(innerDeps),
|
|
223
224
|
isHidden: isHidden(innerDeps),
|
|
225
|
+
isIgnoreQuantity: isIgnoreQuantity(innerDeps),
|
|
224
226
|
isGratuity: isGratuity(innerDeps),
|
|
225
227
|
isPaymentMethods: isPaymentMethods(innerDeps),
|
|
226
228
|
isPaymentTypes: isPaymentTypes(innerDeps),
|
package/lib/order/addItem.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
module.exports = ({
|
|
2
|
-
actions,
|
|
3
|
-
itemActions,
|
|
4
|
-
modifierActions,
|
|
5
|
-
utils,
|
|
6
|
-
settings,
|
|
7
|
-
_,
|
|
8
|
-
}) => {
|
|
9
|
-
const { math } = utils;
|
|
1
|
+
module.exports = ({ actions, itemActions, modifierActions, settings, _ }) => {
|
|
10
2
|
const orderSettings = _.get(settings, 'order');
|
|
11
3
|
|
|
12
4
|
const getQuantity = ({ order, item, pendingItemIndex = -1 }) => {
|
|
@@ -55,46 +47,6 @@ module.exports = ({
|
|
|
55
47
|
};
|
|
56
48
|
};
|
|
57
49
|
|
|
58
|
-
const getSubscription = ({ order, item, combined, cache }) => {
|
|
59
|
-
const [hasSubscription, remaining, used] = actions.hasRemainingSubscription(
|
|
60
|
-
{
|
|
61
|
-
order,
|
|
62
|
-
item,
|
|
63
|
-
combined,
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
let orderItem = item;
|
|
67
|
-
|
|
68
|
-
if (!hasSubscription) return orderItem;
|
|
69
|
-
|
|
70
|
-
const subscriptionModifiers = modifierActions.getSubscriptionModifiers(
|
|
71
|
-
orderItem.modifiers
|
|
72
|
-
);
|
|
73
|
-
if (!_.isEmpty(subscriptionModifiers)) {
|
|
74
|
-
orderItem = itemActions.removeModifiers({
|
|
75
|
-
item: orderItem,
|
|
76
|
-
modifiers: subscriptionModifiers,
|
|
77
|
-
cache,
|
|
78
|
-
customer: order.customer,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const { quantity, price } = orderItem;
|
|
83
|
-
let numberOfUses = quantity;
|
|
84
|
-
if (remaining) {
|
|
85
|
-
const left = remaining - (used || 0);
|
|
86
|
-
if (quantity > left) numberOfUses = left;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const modifier = modifierActions.createSubscriptionModifier({
|
|
90
|
-
amount: math.mul(numberOfUses, price),
|
|
91
|
-
properties: { subscription: { numberOfUses } },
|
|
92
|
-
});
|
|
93
|
-
orderItem.modifiers.push(modifier);
|
|
94
|
-
|
|
95
|
-
return orderItem;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
50
|
const addOrderItem = ({ itemIndex, order, item }) => {
|
|
99
51
|
if (itemIndex > -1) {
|
|
100
52
|
const updatedOrder = actions.updateItem({
|
|
@@ -241,7 +193,7 @@ module.exports = ({
|
|
|
241
193
|
if (!_.isEmpty(requiredModifiers))
|
|
242
194
|
modifiersToAdd.push(...requiredModifiers);
|
|
243
195
|
|
|
244
|
-
orderItem =
|
|
196
|
+
orderItem = actions.getOrderItemSubscriptions({
|
|
245
197
|
order,
|
|
246
198
|
item: orderItem,
|
|
247
199
|
combined,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
|
|
4
|
+
return ({ order, item, combined, cache }) => {
|
|
5
|
+
const [hasSubscription, remaining, used] = actions.hasRemainingSubscription(
|
|
6
|
+
{
|
|
7
|
+
order,
|
|
8
|
+
item,
|
|
9
|
+
combined,
|
|
10
|
+
}
|
|
11
|
+
);
|
|
12
|
+
let orderItem = item;
|
|
13
|
+
|
|
14
|
+
if (!hasSubscription) return orderItem;
|
|
15
|
+
|
|
16
|
+
const subscriptionModifiers = modifierActions.getSubscriptionModifiers(
|
|
17
|
+
orderItem.modifiers
|
|
18
|
+
);
|
|
19
|
+
if (!_.isEmpty(subscriptionModifiers)) {
|
|
20
|
+
orderItem = itemActions.removeModifiers({
|
|
21
|
+
item: orderItem,
|
|
22
|
+
modifiers: subscriptionModifiers,
|
|
23
|
+
cache,
|
|
24
|
+
customer: order.customer,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { quantity, price } = orderItem;
|
|
29
|
+
let numberOfUses = quantity;
|
|
30
|
+
if (remaining) {
|
|
31
|
+
const left = remaining - (used || 0);
|
|
32
|
+
if (quantity > left) numberOfUses = left;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const modifier = modifierActions.createSubscriptionModifier({
|
|
36
|
+
amount: math.mul(numberOfUses, price),
|
|
37
|
+
properties: { subscription: { numberOfUses } },
|
|
38
|
+
});
|
|
39
|
+
orderItem.modifiers.push(modifier);
|
|
40
|
+
|
|
41
|
+
return orderItem;
|
|
42
|
+
};
|
|
43
|
+
};
|
package/lib/order/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const getSelectedItem = require('./getSelectedItem');
|
|
|
8
8
|
const updateItem = require('./updateItem');
|
|
9
9
|
const removeItemByIndex = require('./removeItemByIndex');
|
|
10
10
|
const addItem = require('./addItem');
|
|
11
|
+
const getOrderItemSubscriptions = require('./getOrderItemSubscriptions');
|
|
11
12
|
const duplicateItem = require('./duplicateItem');
|
|
12
13
|
const getCustomer = require('./getCustomer');
|
|
13
14
|
const setCustomer = require('./setCustomer');
|
|
@@ -90,6 +91,7 @@ const orderActions = (deps = {}) => {
|
|
|
90
91
|
updateItem: updateItem(innerDeps),
|
|
91
92
|
removeItemByIndex: removeItemByIndex(innerDeps),
|
|
92
93
|
addItem: addItem(innerDeps),
|
|
94
|
+
getOrderItemSubscriptions: getOrderItemSubscriptions(innerDeps),
|
|
93
95
|
duplicateItem: duplicateItem(innerDeps),
|
|
94
96
|
getCustomer: getCustomer(innerDeps),
|
|
95
97
|
setCustomer: setCustomer(innerDeps),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"supertest": "^6.2.3",
|
|
36
36
|
"supervisor": "^0.12.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "e70158333e19e0d6106cb2db4efe0a25842c323b"
|
|
39
39
|
}
|