@darkpos/pricing 1.0.5 → 1.0.6
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/.eslintrc +8 -10
- package/__TEST__/item.test.js +137 -99
- package/__TEST__/order.test.js +50 -36
- package/index.js +1 -25
- package/lib/constants/index.js +5 -0
- package/lib/constants/status.js +39 -0
- package/lib/index.js +36 -0
- package/lib/item/addIndirectModifier.js +34 -17
- package/lib/item/calculate.js +41 -19
- package/lib/item/create.js +35 -0
- package/lib/item/filterByDirectModifiers.js +5 -6
- package/lib/item/findOriginalItem.js +8 -0
- package/lib/item/getBalanceToPay.js +12 -0
- package/lib/item/getDepartmentModifiers.js +5 -0
- package/lib/item/getDiscountModifiers.js +7 -0
- package/lib/item/getItemModifiers.js +16 -0
- package/lib/item/getItemModifiersDescription.js +22 -0
- package/lib/item/getItemPrice.js +57 -0
- package/lib/item/getItemsTotalPaid.js +9 -0
- package/lib/item/getItemsTotalPieces.js +7 -0
- package/lib/item/getNotIncludedModifiers.js +11 -0
- package/lib/item/getParentItem.js +5 -0
- package/lib/item/getPendingIndex.js +5 -0
- package/lib/item/getTotal.js +8 -0
- package/lib/item/getTotalPieces.js +7 -0
- package/lib/item/getTotals.js +25 -0
- package/lib/item/hasCreateSubscription.js +7 -0
- package/lib/item/hasModifier.js +15 -0
- package/lib/item/hasModifierWithValue.js +11 -0
- package/lib/item/hasModifiers.js +9 -0
- package/lib/item/hasSubscription.js +5 -0
- package/lib/item/index.js +80 -10
- package/lib/item/isParentIncluded.js +4 -0
- package/lib/item/isRelatedItem.js +4 -0
- package/lib/item/isSelected.js +13 -0
- package/lib/item/openRecommendationDialog.js +4 -0
- package/lib/item/removeModifier.js +84 -0
- package/lib/item/removeModifierById.js +8 -0
- package/lib/item/removeModifiers.js +14 -0
- package/lib/order/addCreditModifier.js +27 -0
- package/lib/order/addDiscountModifier.js +9 -0
- package/lib/order/addItem.js +292 -0
- package/lib/order/addItemModifier.js +214 -0
- package/lib/order/addModifier.js +9 -0
- package/lib/order/addModifierToAllItems.js +16 -0
- package/lib/order/addNote.js +25 -0
- package/lib/order/addTable.js +11 -0
- package/lib/order/calculate.js +51 -16
- package/lib/order/calculateDue.js +15 -0
- package/lib/order/calculateOrdersDue.js +26 -0
- package/lib/order/canSplit.js +4 -0
- package/lib/order/changeEndDate.js +15 -0
- package/lib/order/changeLocation.js +20 -0
- package/lib/order/changeStartDate.js +14 -0
- package/lib/order/combineSubOrders.js +14 -0
- package/lib/order/containsSerial.js +5 -0
- package/lib/order/create.js +67 -0
- package/lib/order/createParent.js +9 -0
- package/lib/order/duplicateItem.js +16 -0
- package/lib/order/findItemIndex.js +6 -0
- package/lib/order/getAppliedCredit.js +5 -0
- package/lib/order/getBalance.js +9 -0
- package/lib/order/getCustomer.js +4 -0
- package/lib/order/getCustomerStoreCredit.js +14 -0
- package/lib/order/getCustomerSubscriptions.js +8 -0
- package/lib/order/getCustomerSubscriptionsByItem.js +14 -0
- package/lib/order/getDepartmentModifiers.js +9 -0
- package/lib/order/getEndDate.js +6 -0
- package/lib/order/getItemByItemId.js +6 -0
- package/lib/order/getItemIndex.js +9 -0
- package/lib/order/getItemsToPay.js +17 -0
- package/lib/order/getMenuItemsByCustomer.js +19 -0
- package/lib/order/getNumberOfItems.js +12 -0
- package/lib/order/getOrdersPieces.js +10 -0
- package/lib/order/getPendingItemIndex.js +5 -0
- package/lib/order/getRelatedItems.js +11 -0
- package/lib/order/getSameItems.js +14 -0
- package/lib/order/getScheduleByCustomer.js +20 -0
- package/lib/order/getScreenCustomerNotes.js +12 -0
- package/lib/order/getSelectedItem.js +6 -0
- package/lib/order/getStartDate.js +4 -0
- package/lib/order/getTip.js +10 -0
- package/lib/order/getTotalPieces.js +17 -0
- package/lib/order/getTotals.js +28 -0
- package/lib/order/hasAggregate.js +20 -0
- package/lib/order/hasItem.js +7 -0
- package/lib/order/hasRemainingSubscription.js +67 -0
- package/lib/order/hold.js +12 -0
- package/lib/order/index.js +166 -5
- package/lib/order/isDetailed.js +4 -0
- package/lib/order/isHold.js +4 -0
- package/lib/order/isNew.js +4 -0
- package/lib/order/isOpen.js +4 -0
- package/lib/order/isParent.js +7 -0
- package/lib/order/merge.js +96 -0
- package/lib/order/open.js +11 -0
- package/lib/order/pickEndDate.js +70 -0
- package/lib/order/removeApplyModifier.js +24 -0
- package/lib/order/removeDiscountModifier.js +16 -0
- package/lib/order/removeItem.js +56 -0
- package/lib/order/removeItemByIndex.js +5 -0
- package/lib/order/removeItemModifier.js +69 -0
- package/lib/order/removeModifier.js +21 -0
- package/lib/order/removeModifierByAttribute.js +23 -0
- package/lib/order/removeModifiersWithPaymentMethods.js +29 -0
- package/lib/order/removeModifiersWithPaymentTypes.js +27 -0
- package/lib/order/setCustomer.js +50 -0
- package/lib/order/splitByDepartments.js +151 -0
- package/lib/order/toggleModifier.js +9 -0
- package/lib/order/updateItem.js +8 -0
- package/lib/order/updateItemQuantity.js +35 -0
- package/lib/order/void.js +11 -0
- package/package.json +16 -18
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function addTable({ order, table }) {
|
|
3
|
+
if (!order || !table) return order;
|
|
4
|
+
const nextOrder = { ...order };
|
|
5
|
+
const { location = {} } = nextOrder;
|
|
6
|
+
nextOrder.location = {
|
|
7
|
+
...location,
|
|
8
|
+
table: { _id: table._id, name: table.name },
|
|
9
|
+
};
|
|
10
|
+
return nextOrder;
|
|
11
|
+
};
|
package/lib/order/calculate.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
1
2
|
/**
|
|
2
3
|
* return calculated Order
|
|
3
4
|
*/
|
|
4
|
-
module.exports = ({ _, utils,
|
|
5
|
+
module.exports = ({ _, utils, itemActions, modifierActions }) => {
|
|
5
6
|
const { math } = utils;
|
|
6
7
|
|
|
7
|
-
const pricing =
|
|
8
|
-
|
|
8
|
+
const pricing = items => {
|
|
9
|
+
let subTotals = {};
|
|
9
10
|
let subTotal = 0;
|
|
10
11
|
|
|
11
|
-
for (item of items) {
|
|
12
|
+
for (const item of items) {
|
|
12
13
|
subTotal = math.add(subTotal, item.subTotals._actual);
|
|
13
14
|
const keys = Object.keys(item.subTotals).filter(
|
|
14
|
-
|
|
15
|
+
key => !key.includes('_')
|
|
15
16
|
);
|
|
16
|
-
for (key of keys) {
|
|
17
|
+
for (const key of keys) {
|
|
17
18
|
subTotals[key] = math.add(subTotals[key] || 0, item.subTotals[key]);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -23,6 +24,14 @@ module.exports = ({ _, utils, itemService }) => {
|
|
|
23
24
|
subTotal
|
|
24
25
|
);
|
|
25
26
|
|
|
27
|
+
subTotals = Object.keys(subTotals).reduce(
|
|
28
|
+
(acc, key) => ({
|
|
29
|
+
...acc,
|
|
30
|
+
[key]: subTotals[key],
|
|
31
|
+
}),
|
|
32
|
+
{}
|
|
33
|
+
);
|
|
34
|
+
|
|
26
35
|
return {
|
|
27
36
|
subTotals,
|
|
28
37
|
subTotal,
|
|
@@ -30,14 +39,33 @@ module.exports = ({ _, utils, itemService }) => {
|
|
|
30
39
|
};
|
|
31
40
|
};
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
const getItems = (items, orderModifiers) => {
|
|
43
|
+
const existsInOrderModifier = modifier =>
|
|
44
|
+
orderModifiers &&
|
|
45
|
+
orderModifiers.find(each => each.modifierId === modifier.modifierId);
|
|
46
|
+
|
|
47
|
+
return items.map(item => {
|
|
48
|
+
const modifiers = (item.modifiers || []).filter(
|
|
49
|
+
modifier => !existsInOrderModifier(modifier)
|
|
50
|
+
);
|
|
51
|
+
return {
|
|
52
|
+
...item,
|
|
53
|
+
modifiers,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return function calculateorder(inputOrder) {
|
|
59
|
+
if (!inputOrder) return inputOrder;
|
|
60
|
+
const order = _.cloneDeep(inputOrder);
|
|
34
61
|
const { items = [] } = order;
|
|
35
|
-
if (!items.length)
|
|
62
|
+
if (!items.length)
|
|
63
|
+
return { ...order, subTotals: {}, subTotal: 0, total: 0 };
|
|
36
64
|
|
|
37
65
|
const modifiers = _.uniqBy(order.modifiers, '_id');
|
|
38
66
|
// if there is no order level modifiers, we have to remove them from items
|
|
39
|
-
let itemsWNIM =
|
|
40
|
-
itemsWNIM =
|
|
67
|
+
let itemsWNIM = getItems(items, modifiers);
|
|
68
|
+
itemsWNIM = itemActions.calculate(itemsWNIM);
|
|
41
69
|
const newOrder = { ...order, ...pricing(itemsWNIM), items: itemsWNIM };
|
|
42
70
|
|
|
43
71
|
if (!modifiers.length) return newOrder;
|
|
@@ -45,22 +73,29 @@ module.exports = ({ _, utils, itemService }) => {
|
|
|
45
73
|
const newItems = itemsWNIM || items;
|
|
46
74
|
let itemsWIM = _.cloneDeep(newItems);
|
|
47
75
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
let computedTotal = newOrder.total;
|
|
77
|
+
const sortedModifiers = modifierActions.sort(modifiers);
|
|
78
|
+
for (const modifier of sortedModifiers) {
|
|
79
|
+
const isCredit = modifierActions.isCredit(modifier);
|
|
80
|
+
if (isCredit) {
|
|
81
|
+
const calculatedItemWIM = itemActions.calculate(itemsWIM);
|
|
82
|
+
({ total: computedTotal } = pricing(calculatedItemWIM));
|
|
83
|
+
}
|
|
84
|
+
const itemsModifiers = itemActions.addIndirectModifier(
|
|
85
|
+
computedTotal,
|
|
51
86
|
newItems,
|
|
52
87
|
modifier
|
|
53
88
|
);
|
|
54
89
|
// adding the modifiers to items
|
|
55
|
-
itemsWIM = itemsWIM.map(
|
|
90
|
+
itemsWIM = itemsWIM.map(item => ({
|
|
56
91
|
...item,
|
|
57
92
|
modifiers: [...(item.modifiers || []), itemsModifiers[item._id]].filter(
|
|
58
93
|
Boolean
|
|
59
94
|
),
|
|
60
95
|
}));
|
|
61
|
-
}
|
|
96
|
+
}
|
|
62
97
|
|
|
63
|
-
const calculatedItemWIM =
|
|
98
|
+
const calculatedItemWIM = itemActions.calculate(itemsWIM);
|
|
64
99
|
return {
|
|
65
100
|
...order,
|
|
66
101
|
...pricing(calculatedItemWIM),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
return function calculateDue(order) {
|
|
4
|
+
if (!order || !Array.isArray(order.items)) return 0;
|
|
5
|
+
let total = 0;
|
|
6
|
+
let totalPaid = 0;
|
|
7
|
+
|
|
8
|
+
order.items.forEach(item => {
|
|
9
|
+
total = math.add(total, item.total);
|
|
10
|
+
totalPaid = math.add(totalPaid, item.totalPaid);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return math.sub(total, totalPaid);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
return function calculateOrdersDue(orders, orderItemsToPay) {
|
|
4
|
+
let total = 0;
|
|
5
|
+
let totalPaid = 0;
|
|
6
|
+
const isPartial = !!(
|
|
7
|
+
orderItemsToPay && Object.keys(orderItemsToPay).length > 0
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
orders.forEach(order => {
|
|
11
|
+
const orderItemIds =
|
|
12
|
+
(orderItemsToPay && orderItemsToPay[order._id]) || [];
|
|
13
|
+
order.items.forEach(it => {
|
|
14
|
+
if (!isPartial) {
|
|
15
|
+
total += it.total;
|
|
16
|
+
totalPaid += it.totalPaid;
|
|
17
|
+
} else if (orderItemIds.includes(it._id)) {
|
|
18
|
+
total += it.total;
|
|
19
|
+
totalPaid += it.totalPaid;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return math.sub(total, totalPaid);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module.exports = ({ utils }) =>
|
|
2
|
+
function changeEndDate({ date, order }) {
|
|
3
|
+
if (!date || !order) return order;
|
|
4
|
+
const nextOrder = { ...order };
|
|
5
|
+
if (!nextOrder.end) nextOrder.end = { __typename: 'OrderEnd' };
|
|
6
|
+
|
|
7
|
+
const isoString = utils.date.toISOString(date);
|
|
8
|
+
nextOrder.end = {
|
|
9
|
+
...nextOrder.end,
|
|
10
|
+
actualDate: utils.date.isToday(date) ? isoString : '',
|
|
11
|
+
requestDate: isoString,
|
|
12
|
+
__typename: 'OrderEnd',
|
|
13
|
+
};
|
|
14
|
+
return nextOrder;
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function changeLocation({ order, location, isStart }) {
|
|
3
|
+
if (!order || !location) return order;
|
|
4
|
+
const nextOrder = { ...order };
|
|
5
|
+
if (isStart) {
|
|
6
|
+
if (!nextOrder.start) nextOrder.start = { __typename: 'OrderStart' };
|
|
7
|
+
nextOrder.start = {
|
|
8
|
+
...nextOrder.start,
|
|
9
|
+
location,
|
|
10
|
+
};
|
|
11
|
+
return nextOrder;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!nextOrder.end) nextOrder.end = { __typename: 'OrderEnd' };
|
|
15
|
+
nextOrder.end = {
|
|
16
|
+
...nextOrder.end,
|
|
17
|
+
location,
|
|
18
|
+
};
|
|
19
|
+
return nextOrder;
|
|
20
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = ({ utils }) =>
|
|
2
|
+
function changeStartDate({ date, order }) {
|
|
3
|
+
if (!date || !order) return order;
|
|
4
|
+
const nextOrder = { ...order };
|
|
5
|
+
if (!nextOrder.start) nextOrder.start = { __typename: 'OrderStart' };
|
|
6
|
+
|
|
7
|
+
const isoString = utils.date.toISOString(date);
|
|
8
|
+
nextOrder.start = {
|
|
9
|
+
...nextOrder.start,
|
|
10
|
+
actualDate: utils.date.isToday(date) ? isoString : '',
|
|
11
|
+
requestDate: isoString,
|
|
12
|
+
};
|
|
13
|
+
return nextOrder;
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function combineSubOrders({ order, subOrders = [] }) {
|
|
3
|
+
if (!order || !subOrders || !subOrders.length) return order;
|
|
4
|
+
|
|
5
|
+
const items = subOrders.reduce(
|
|
6
|
+
(arr, each) => arr.concat(each.items || []),
|
|
7
|
+
[]
|
|
8
|
+
);
|
|
9
|
+
return {
|
|
10
|
+
...order,
|
|
11
|
+
orders: subOrders,
|
|
12
|
+
items,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module.exports = ({ utils, constants = {} }) => {
|
|
2
|
+
const { helpers } = utils;
|
|
3
|
+
|
|
4
|
+
const defaultOrderStatus = {
|
|
5
|
+
order: constants.status.Order.OPEN,
|
|
6
|
+
kitchen: constants.status.Kitchen.OPEN,
|
|
7
|
+
delivery: constants.status.Delivery.NONE,
|
|
8
|
+
detailed: true,
|
|
9
|
+
};
|
|
10
|
+
const orderEnd = {
|
|
11
|
+
actualDate: '',
|
|
12
|
+
requestDate: '',
|
|
13
|
+
location: null,
|
|
14
|
+
__typename: 'OrderEnd',
|
|
15
|
+
};
|
|
16
|
+
const orderStart = {
|
|
17
|
+
actualDate: utils.date.toISOString(),
|
|
18
|
+
requestDate: '',
|
|
19
|
+
location: null,
|
|
20
|
+
__typename: 'OrderStart',
|
|
21
|
+
};
|
|
22
|
+
const defaultOrder = {
|
|
23
|
+
get _id() {
|
|
24
|
+
return helpers.getObjectID();
|
|
25
|
+
},
|
|
26
|
+
parentId: null,
|
|
27
|
+
isParent: false,
|
|
28
|
+
subTotal: 0,
|
|
29
|
+
tax: 0,
|
|
30
|
+
modifiers: [],
|
|
31
|
+
discount: 0,
|
|
32
|
+
total: 0,
|
|
33
|
+
description: '',
|
|
34
|
+
displayId: '',
|
|
35
|
+
type: '',
|
|
36
|
+
location: {},
|
|
37
|
+
status: defaultOrderStatus,
|
|
38
|
+
attributes: [],
|
|
39
|
+
properties: {},
|
|
40
|
+
fee: 0,
|
|
41
|
+
user: null,
|
|
42
|
+
items: [],
|
|
43
|
+
notes: [],
|
|
44
|
+
customer: null,
|
|
45
|
+
start: orderStart,
|
|
46
|
+
end: orderEnd,
|
|
47
|
+
_storeId: '',
|
|
48
|
+
__typename: 'Order',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return function create(params = {}) {
|
|
52
|
+
return {
|
|
53
|
+
...defaultOrder,
|
|
54
|
+
...params,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
TODO: {
|
|
61
|
+
table: {
|
|
62
|
+
_id: locationState?.table._id,
|
|
63
|
+
name: locationState?.table.name,
|
|
64
|
+
},
|
|
65
|
+
type: location || LocationTypes.walkIn,
|
|
66
|
+
}
|
|
67
|
+
* */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { helpers } = utils;
|
|
3
|
+
return function duplicateItem({ order, item }) {
|
|
4
|
+
if (!order || !order.items) return order;
|
|
5
|
+
|
|
6
|
+
const nextOrder = { ...order };
|
|
7
|
+
const newItem = {
|
|
8
|
+
...item,
|
|
9
|
+
serial: '',
|
|
10
|
+
_id: helpers.getObjectID(),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
nextOrder.items.push(newItem);
|
|
14
|
+
return nextOrder;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
return function getCustomerStoreCredit(order) {
|
|
4
|
+
if (!order || !order.customer || !Array.isArray(order.customer.wallet))
|
|
5
|
+
return 0;
|
|
6
|
+
return order.customer.wallet
|
|
7
|
+
.filter(
|
|
8
|
+
each =>
|
|
9
|
+
each && each.provider === 'darkpos' && each.cards && each.cards.length
|
|
10
|
+
)
|
|
11
|
+
.reduce((acc, each) => [...acc, ...each.cards], [])
|
|
12
|
+
.reduce((acc, each) => math.add(acc, each.amount || 0), 0);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
module.exports = ({ modifierActions }) =>
|
|
2
|
+
function getCustomerSubscriptions(customer) {
|
|
3
|
+
if (!customer || !Array.isArray(customer.modifiers)) return [];
|
|
4
|
+
const subscriptions = modifierActions.getSubscriptionModifiers(
|
|
5
|
+
customer.modifiers
|
|
6
|
+
);
|
|
7
|
+
return subscriptions;
|
|
8
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = ({ actions, modifierActions }) =>
|
|
2
|
+
function getCustomerSubscriptionsByItem({ customer, item }) {
|
|
3
|
+
if (!customer || !item) return [];
|
|
4
|
+
const subscriptions = actions.getCustomerSubscriptions(customer);
|
|
5
|
+
return subscriptions.filter(each => {
|
|
6
|
+
const subscribedItem = modifierActions.getSubscriptionItem(each);
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
subscribedItem &&
|
|
10
|
+
subscribedItem.itemId === item.itemId &&
|
|
11
|
+
(!subscribedItem.serial || subscribedItem.serial === item.serial)
|
|
12
|
+
);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getItemIndex({ order, item }) {
|
|
3
|
+
if (!order || !order.items || !item) return -1;
|
|
4
|
+
return order.items.findIndex(each => {
|
|
5
|
+
if (!item.itemId && each.isPending) return item._id === each._id;
|
|
6
|
+
|
|
7
|
+
return each._id === item._id && each.itemId === item.itemId;
|
|
8
|
+
});
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getItemsToPay({ orders, orderItemsToPay }) {
|
|
3
|
+
return (
|
|
4
|
+
(Array.isArray(orders) &&
|
|
5
|
+
orderItemsToPay &&
|
|
6
|
+
Object.keys(orderItemsToPay).reduce((acc, orderId) => {
|
|
7
|
+
const orderItemsIds = orderItemsToPay[orderId];
|
|
8
|
+
const order = orders.find(each => each._id === orderId);
|
|
9
|
+
if (!order || !orderItemsIds) return acc;
|
|
10
|
+
const items = order.items.filter(each =>
|
|
11
|
+
orderItemsIds.includes(each._id)
|
|
12
|
+
);
|
|
13
|
+
return acc.concat(items);
|
|
14
|
+
}, [])) ||
|
|
15
|
+
[]
|
|
16
|
+
);
|
|
17
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module.exports = ({ modifierActions }) =>
|
|
2
|
+
function getMenuItemByCustomer({ order, menuItems }) {
|
|
3
|
+
const { customer } = order || {};
|
|
4
|
+
if (!customer) return [];
|
|
5
|
+
|
|
6
|
+
return menuItems.filter(menuItem => {
|
|
7
|
+
const { item = {} } = menuItem;
|
|
8
|
+
const { priceLevels = [] } = item;
|
|
9
|
+
if (
|
|
10
|
+
!priceLevels.length &&
|
|
11
|
+
(modifierActions.hasAllTag(customer) ||
|
|
12
|
+
modifierActions.hasNoTags(customer))
|
|
13
|
+
)
|
|
14
|
+
return true;
|
|
15
|
+
return priceLevels.some(priceLevel =>
|
|
16
|
+
modifierActions.hasMatchTags(customer, priceLevel)
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { _ } = utils;
|
|
3
|
+
return function getNumberOfItems(orders) {
|
|
4
|
+
if (!orders || !Array.isArray(orders)) return 0;
|
|
5
|
+
const sum = orders.reduce((acc, order) => {
|
|
6
|
+
const items = _.get(order, 'items', []);
|
|
7
|
+
return acc + items.lenght;
|
|
8
|
+
}, 0);
|
|
9
|
+
|
|
10
|
+
return sum;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = ({ actions, utils }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
return function getOrdersPieces(orders) {
|
|
4
|
+
if (!Array.isArray(orders)) return 0;
|
|
5
|
+
return orders.reduce(
|
|
6
|
+
(acc, order) => math.add(acc, actions.getTotalPieces({ order })),
|
|
7
|
+
0
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getRelatedItems({ order, item, compareId = true }) {
|
|
3
|
+
if (!order || !order.items || !item) return [];
|
|
4
|
+
return order.items
|
|
5
|
+
.filter(each => each.properties && each.properties.relatedItem)
|
|
6
|
+
.filter(
|
|
7
|
+
each =>
|
|
8
|
+
each.properties.parentItemId === item.itemId &&
|
|
9
|
+
(compareId ? each.properties.parentId === item._id : true)
|
|
10
|
+
);
|
|
11
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getSameItems({ order, item }) {
|
|
3
|
+
const { items = [] } = order;
|
|
4
|
+
return items.filter(each => {
|
|
5
|
+
let check = each.itemId === item._id && !each.serial && !item.serial;
|
|
6
|
+
if (check && each.menuId && item.menuId) {
|
|
7
|
+
check =
|
|
8
|
+
each.menuId === item.menuId &&
|
|
9
|
+
each.path.toString() === item.path.toString();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return check;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = ({ _, settings }) => {
|
|
2
|
+
const orderSettings = _.get(settings, 'order');
|
|
3
|
+
|
|
4
|
+
return function getScheduleByCustomer(customer = {}) {
|
|
5
|
+
const { tags } = customer;
|
|
6
|
+
const { default: defaultSchedule, ...schedules } =
|
|
7
|
+
orderSettings.endDate || {};
|
|
8
|
+
if (!tags || !tags.length) return defaultSchedule;
|
|
9
|
+
|
|
10
|
+
const scheduleTags = Object.keys(schedules);
|
|
11
|
+
if (!scheduleTags || !scheduleTags.length) return defaultSchedule;
|
|
12
|
+
|
|
13
|
+
const tag = tags
|
|
14
|
+
.filter(each => each !== 'default' && each !== 'all')
|
|
15
|
+
.find(each => scheduleTags.includes(each));
|
|
16
|
+
if (!tag) return defaultSchedule;
|
|
17
|
+
console.log('schedule for the tag', tag, schedules[tag]);
|
|
18
|
+
return schedules[tag];
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = ({ actions }) =>
|
|
2
|
+
function getScreenCustomerNotes(customer) {
|
|
3
|
+
let theCustomer = customer;
|
|
4
|
+
if (!theCustomer) theCustomer = actions.getCustomer();
|
|
5
|
+
if (!theCustomer) return [];
|
|
6
|
+
const { notes = [] } = theCustomer;
|
|
7
|
+
const screenNotes = notes.filter(
|
|
8
|
+
each => each.message && each.attributes.includes('screen')
|
|
9
|
+
);
|
|
10
|
+
if (!screenNotes.length) return [];
|
|
11
|
+
return screenNotes.map(each => each.message);
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
module.exports = ({ modifierActions, utils }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
return function getTip(order) {
|
|
4
|
+
if (!order || !Array.isArray(order.modifiers)) return 0;
|
|
5
|
+
|
|
6
|
+
return order.modifiers
|
|
7
|
+
.filter(each => modifierActions.isGratuity(each))
|
|
8
|
+
.reduce((total, modifier) => math.sum(total, modifier.number || 0), 0);
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = ({ itemActions, utils }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
return function getTotalPieces({ order, subOrders }) {
|
|
4
|
+
if (!order) return 0;
|
|
5
|
+
if (order.items && order.items.length)
|
|
6
|
+
return itemActions.getItemsTotalPieces(order.items);
|
|
7
|
+
if (order.isParent && subOrders && subOrders.length)
|
|
8
|
+
return subOrders.reduce(
|
|
9
|
+
(acc, each) =>
|
|
10
|
+
math.add(acc, itemActions.getItemsTotalPieces(each.items)),
|
|
11
|
+
0
|
|
12
|
+
);
|
|
13
|
+
if (order.properties && order.properties.pieceCount)
|
|
14
|
+
return order.properties.pieceCount;
|
|
15
|
+
return 0;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module.exports = ({ utils }) => {
|
|
2
|
+
const { math } = utils;
|
|
3
|
+
return function getTotals(orders) {
|
|
4
|
+
if (!Array.isArray(orders)) return { total: 0, subTotals: {} };
|
|
5
|
+
return orders
|
|
6
|
+
.filter(each => !!each.parentId || !each.isParent)
|
|
7
|
+
.reduce(
|
|
8
|
+
(acc, order) => {
|
|
9
|
+
const subTotals = {};
|
|
10
|
+
const { subTotals: orderSubTotals } = order;
|
|
11
|
+
if (orderSubTotals) {
|
|
12
|
+
const keys = Object.keys(orderSubTotals);
|
|
13
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
14
|
+
for (const key of keys)
|
|
15
|
+
subTotals[key] = math.add(
|
|
16
|
+
acc.subTotals[key] || 0,
|
|
17
|
+
orderSubTotals[key]
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
total: math.add(acc.total, order.total),
|
|
22
|
+
subTotals,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
{ total: 0, subTotals: {} }
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
};
|