@darkpos/pricing 1.0.12 → 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/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
|
}
|