@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
package/.eslintrc
CHANGED
|
@@ -7,18 +7,16 @@
|
|
|
7
7
|
"plugins": ["prettier", "jest"],
|
|
8
8
|
"rules": {
|
|
9
9
|
"no-debugger": 0,
|
|
10
|
-
"import/no-extraneous-dependencies": 0,
|
|
11
10
|
"no-underscore-dangle": 0,
|
|
12
|
-
"import/no-dynamic-require": 0,
|
|
13
11
|
"no-console": 0,
|
|
14
12
|
"global-require": 0,
|
|
15
|
-
"prettier/prettier": [
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
]
|
|
13
|
+
"prettier/prettier": ["error", {
|
|
14
|
+
"singleQuote": true,
|
|
15
|
+
"trailingComma": "es5",
|
|
16
|
+
"bracketSpacing": true,
|
|
17
|
+
"bracketSameLine": false,
|
|
18
|
+
"arrowParens": "avoid",
|
|
19
|
+
"parser": "flow"
|
|
20
|
+
}]
|
|
23
21
|
}
|
|
24
22
|
}
|
package/__TEST__/item.test.js
CHANGED
|
@@ -6,25 +6,37 @@ describe('Item actions', () => {
|
|
|
6
6
|
test('Get calculated Item: included: false && direct: false', () => {
|
|
7
7
|
const modifiers = [
|
|
8
8
|
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
compute: {
|
|
10
|
+
amount: 20,
|
|
11
|
+
type: 'percentage',
|
|
12
|
+
action: 'add',
|
|
13
|
+
},
|
|
12
14
|
name: 'modifier1',
|
|
13
|
-
|
|
15
|
+
type: 'discount',
|
|
16
|
+
direct: false,
|
|
17
|
+
included: false,
|
|
14
18
|
},
|
|
15
19
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
compute: {
|
|
21
|
+
amount: 20,
|
|
22
|
+
type: 'percentage',
|
|
23
|
+
action: 'subtract',
|
|
24
|
+
},
|
|
19
25
|
name: 'modifier2',
|
|
20
|
-
|
|
26
|
+
type: 'discount',
|
|
27
|
+
direct: false,
|
|
28
|
+
included: false,
|
|
21
29
|
},
|
|
22
30
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
compute: {
|
|
32
|
+
amount: 2,
|
|
33
|
+
type: 'fixed',
|
|
34
|
+
action: 'subtract',
|
|
35
|
+
},
|
|
26
36
|
name: 'modifier3',
|
|
27
|
-
|
|
37
|
+
type: 'discount',
|
|
38
|
+
direct: false,
|
|
39
|
+
included: false,
|
|
28
40
|
},
|
|
29
41
|
];
|
|
30
42
|
const orderItem = { price: 30, quantity: 2, modifiers };
|
|
@@ -34,8 +46,8 @@ describe('Item actions', () => {
|
|
|
34
46
|
discount: -4,
|
|
35
47
|
_included: 0,
|
|
36
48
|
_xincluded: -4,
|
|
37
|
-
_direct:
|
|
38
|
-
_xdirect:
|
|
49
|
+
_direct: 0,
|
|
50
|
+
_xdirect: -4,
|
|
39
51
|
_simple: 60,
|
|
40
52
|
_actual: 60,
|
|
41
53
|
});
|
|
@@ -43,28 +55,33 @@ describe('Item actions', () => {
|
|
|
43
55
|
test('Get calculated Item: included: false && direct: true', () => {
|
|
44
56
|
const modifiers = [
|
|
45
57
|
{
|
|
46
|
-
amount: 2,
|
|
47
|
-
type: '
|
|
48
|
-
action: 'subtract',
|
|
49
|
-
properties: {
|
|
50
|
-
direct: false,
|
|
51
|
-
},
|
|
52
|
-
category: 'discount',
|
|
58
|
+
compute: { amount: 2, type: 'fixed', action: 'subtract' },
|
|
59
|
+
type: 'discount',
|
|
53
60
|
name: 'modifier1',
|
|
61
|
+
direct: true,
|
|
62
|
+
included: false,
|
|
54
63
|
},
|
|
55
64
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
compute: {
|
|
66
|
+
amount: 20,
|
|
67
|
+
type: 'percentage',
|
|
68
|
+
action: 'subtract',
|
|
69
|
+
},
|
|
59
70
|
name: 'modifier2',
|
|
60
|
-
|
|
71
|
+
type: 'discount',
|
|
72
|
+
direct: true,
|
|
73
|
+
included: false,
|
|
61
74
|
},
|
|
62
75
|
{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
compute: {
|
|
77
|
+
amount: 2,
|
|
78
|
+
type: 'fixed',
|
|
79
|
+
action: 'add',
|
|
80
|
+
},
|
|
66
81
|
name: 'modifier3',
|
|
67
|
-
|
|
82
|
+
type: 'tax',
|
|
83
|
+
direct: true,
|
|
84
|
+
included: false,
|
|
68
85
|
},
|
|
69
86
|
];
|
|
70
87
|
const orderItem = { price: 30, quantity: 2, modifiers };
|
|
@@ -75,8 +92,8 @@ describe('Item actions', () => {
|
|
|
75
92
|
tax: 4,
|
|
76
93
|
_included: 0,
|
|
77
94
|
_xincluded: -12,
|
|
78
|
-
_direct: -
|
|
79
|
-
_xdirect:
|
|
95
|
+
_direct: -12,
|
|
96
|
+
_xdirect: 0,
|
|
80
97
|
_simple: 60,
|
|
81
98
|
_actual: 60,
|
|
82
99
|
});
|
|
@@ -84,57 +101,63 @@ describe('Item actions', () => {
|
|
|
84
101
|
test('Get calculated Item: included: true && direct: true', () => {
|
|
85
102
|
const modifiers = [
|
|
86
103
|
{
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
category: 'discount',
|
|
92
|
-
properties: {
|
|
93
|
-
direct: false,
|
|
104
|
+
compute: {
|
|
105
|
+
amount: 2,
|
|
106
|
+
type: 'fixed',
|
|
107
|
+
action: 'subtract',
|
|
94
108
|
},
|
|
109
|
+
name: 'modifier1',
|
|
110
|
+
type: 'discount',
|
|
111
|
+
direct: true,
|
|
112
|
+
included: true,
|
|
95
113
|
},
|
|
96
114
|
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
compute: {
|
|
116
|
+
amount: 20,
|
|
117
|
+
type: 'percentage',
|
|
118
|
+
action: 'subtract',
|
|
119
|
+
},
|
|
100
120
|
name: 'modifier2',
|
|
101
|
-
|
|
121
|
+
type: 'discount',
|
|
122
|
+
direct: true,
|
|
123
|
+
included: true,
|
|
102
124
|
},
|
|
103
125
|
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
category: 'upcharge',
|
|
109
|
-
properties: {
|
|
110
|
-
included: true,
|
|
126
|
+
compute: {
|
|
127
|
+
amount: 2,
|
|
128
|
+
type: 'fixed',
|
|
129
|
+
action: 'add',
|
|
111
130
|
},
|
|
131
|
+
name: 'modifier3',
|
|
132
|
+
type: 'upcharge',
|
|
133
|
+
direct: true,
|
|
134
|
+
included: true,
|
|
112
135
|
},
|
|
113
136
|
];
|
|
114
137
|
const orderItem = { price: 30, quantity: 2, modifiers };
|
|
115
138
|
const newItem = pricingService.item.calculate(orderItem);
|
|
116
139
|
expect(newItem).toHaveProperty('total', 48);
|
|
117
140
|
expect(newItem).toHaveProperty('subTotals', {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
_xdirect: -4,
|
|
141
|
+
_included: -12,
|
|
142
|
+
_xincluded: 0,
|
|
143
|
+
_direct: -12,
|
|
144
|
+
_xdirect: 0,
|
|
123
145
|
_simple: 60,
|
|
124
|
-
_actual:
|
|
146
|
+
_actual: 48,
|
|
125
147
|
});
|
|
126
148
|
});
|
|
127
149
|
test('Get calculated Item: included: true, sample 1', () => {
|
|
128
150
|
const modifiers = [
|
|
129
151
|
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
category: 'upcharge',
|
|
135
|
-
properties: {
|
|
136
|
-
included: true,
|
|
152
|
+
compute: {
|
|
153
|
+
amount: 2,
|
|
154
|
+
type: 'fixed',
|
|
155
|
+
action: 'add',
|
|
137
156
|
},
|
|
157
|
+
name: 'modifier1',
|
|
158
|
+
type: 'upcharge',
|
|
159
|
+
included: true,
|
|
160
|
+
direct: true,
|
|
138
161
|
},
|
|
139
162
|
];
|
|
140
163
|
const orderItem = { price: 2, quantity: 1, modifiers };
|
|
@@ -152,96 +175,111 @@ describe('Item actions', () => {
|
|
|
152
175
|
test('Get calculated Item: included: true, sample 2', () => {
|
|
153
176
|
const modifiers = [
|
|
154
177
|
{
|
|
155
|
-
amount: 2,
|
|
156
|
-
type: 'fixed',
|
|
157
|
-
action: 'add',
|
|
178
|
+
compute: { amount: 2, type: 'fixed', action: 'add' },
|
|
158
179
|
name: 'modifier1',
|
|
159
|
-
|
|
180
|
+
type: 'upcharge',
|
|
181
|
+
included: true,
|
|
182
|
+
direct: true,
|
|
160
183
|
properties: {
|
|
161
|
-
included: true,
|
|
162
184
|
sort: 1,
|
|
163
185
|
},
|
|
164
186
|
},
|
|
165
187
|
{
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
compute: {
|
|
189
|
+
amount: 10,
|
|
190
|
+
type: 'percentage',
|
|
191
|
+
action: 'add',
|
|
192
|
+
},
|
|
169
193
|
name: 'modifier2',
|
|
170
|
-
|
|
194
|
+
type: 'tax',
|
|
171
195
|
properties: {
|
|
172
196
|
sort: 2,
|
|
173
197
|
},
|
|
198
|
+
included: true,
|
|
199
|
+
direct: true,
|
|
174
200
|
},
|
|
175
201
|
];
|
|
176
202
|
const orderItem = { price: 2, quantity: 1, modifiers };
|
|
177
203
|
const newItem = pricingService.item.calculate(orderItem);
|
|
178
204
|
expect(newItem).toHaveProperty('total', 4.4);
|
|
179
205
|
expect(newItem).toHaveProperty('subTotals', {
|
|
180
|
-
_included: 2,
|
|
181
|
-
_xincluded: 0
|
|
206
|
+
_included: 2.4,
|
|
207
|
+
_xincluded: 0,
|
|
182
208
|
_direct: 2.4,
|
|
183
209
|
_xdirect: 0,
|
|
184
210
|
_simple: 2,
|
|
185
|
-
_actual: 4,
|
|
186
|
-
tax: 0.4,
|
|
211
|
+
_actual: 4.4,
|
|
187
212
|
});
|
|
188
213
|
});
|
|
189
214
|
test('Get calculated Item: included: true, sample 3', () => {
|
|
190
215
|
const modifiers = [
|
|
191
216
|
{
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
compute: {
|
|
218
|
+
amount: 2,
|
|
219
|
+
type: 'fixed',
|
|
220
|
+
action: 'subtract',
|
|
221
|
+
},
|
|
195
222
|
name: 'modifier1',
|
|
196
|
-
|
|
223
|
+
type: 'discount',
|
|
197
224
|
properties: {
|
|
198
225
|
sort: 1,
|
|
199
226
|
},
|
|
227
|
+
included: true,
|
|
228
|
+
direct: true,
|
|
200
229
|
},
|
|
201
230
|
{
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
231
|
+
compute: {
|
|
232
|
+
amount: 2,
|
|
233
|
+
type: 'fixed',
|
|
234
|
+
action: 'add',
|
|
235
|
+
},
|
|
205
236
|
name: 'modifier1',
|
|
206
|
-
|
|
237
|
+
type: 'upcharge',
|
|
238
|
+
included: true,
|
|
239
|
+
direct: true,
|
|
207
240
|
properties: {
|
|
208
|
-
included: true,
|
|
209
241
|
sort: 1,
|
|
210
242
|
},
|
|
211
243
|
},
|
|
212
244
|
{
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
245
|
+
compute: {
|
|
246
|
+
amount: 10,
|
|
247
|
+
type: 'percentage',
|
|
248
|
+
action: 'add',
|
|
249
|
+
},
|
|
216
250
|
name: 'modifier2',
|
|
217
|
-
|
|
251
|
+
type: 'tax',
|
|
218
252
|
properties: {
|
|
219
253
|
sort: 2,
|
|
220
254
|
},
|
|
255
|
+
included: true,
|
|
256
|
+
direct: true,
|
|
221
257
|
},
|
|
222
258
|
{
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
259
|
+
compute: {
|
|
260
|
+
amount: 6,
|
|
261
|
+
type: 'percentage',
|
|
262
|
+
action: 'add',
|
|
263
|
+
},
|
|
226
264
|
name: 'modifier3',
|
|
227
|
-
|
|
265
|
+
type: 'tax',
|
|
228
266
|
properties: {
|
|
229
267
|
sort: 2,
|
|
230
268
|
},
|
|
269
|
+
included: true,
|
|
270
|
+
direct: true,
|
|
231
271
|
},
|
|
232
272
|
];
|
|
233
273
|
const orderItem = { price: 2, quantity: 1, modifiers };
|
|
234
274
|
const newItem = pricingService.item.calculate(orderItem);
|
|
235
|
-
expect(newItem).toHaveProperty('total', 2.
|
|
275
|
+
expect(newItem).toHaveProperty('total', 2.32);
|
|
236
276
|
expect(newItem).toHaveProperty('subTotals', {
|
|
237
|
-
_included: 2,
|
|
238
|
-
_xincluded: -1.36,
|
|
239
|
-
_direct: 0.64,
|
|
240
277
|
_xdirect: 0,
|
|
241
278
|
_simple: 2,
|
|
242
|
-
_actual:
|
|
243
|
-
|
|
244
|
-
|
|
279
|
+
_actual: 2.32,
|
|
280
|
+
_direct: 0.32,
|
|
281
|
+
_included: 0.32,
|
|
282
|
+
_xincluded: 0,
|
|
245
283
|
});
|
|
246
284
|
});
|
|
247
285
|
});
|
package/__TEST__/order.test.js
CHANGED
|
@@ -6,25 +6,27 @@ describe('Order actions', () => {
|
|
|
6
6
|
test('Get calculated Order, one item', () => {
|
|
7
7
|
const modifiers = [
|
|
8
8
|
{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
compute: {
|
|
10
|
+
amount: 20,
|
|
11
|
+
type: 'percentage',
|
|
12
|
+
action: 'add',
|
|
13
|
+
},
|
|
12
14
|
name: 'modifier1',
|
|
13
|
-
|
|
15
|
+
type: 'discount',
|
|
14
16
|
},
|
|
15
17
|
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
compute: {
|
|
19
|
+
amount: 20,
|
|
20
|
+
type: 'percentage',
|
|
21
|
+
action: 'subtract',
|
|
22
|
+
},
|
|
19
23
|
name: 'modifier2',
|
|
20
|
-
|
|
24
|
+
type: 'discount',
|
|
21
25
|
},
|
|
22
26
|
{
|
|
23
|
-
amount: 2,
|
|
24
|
-
type: 'fixed',
|
|
25
|
-
action: 'subtract',
|
|
27
|
+
compute: { amount: 2, type: 'fixed', action: 'subtract' },
|
|
26
28
|
name: 'modifier3',
|
|
27
|
-
|
|
29
|
+
type: 'discount',
|
|
28
30
|
},
|
|
29
31
|
];
|
|
30
32
|
const orderItem = { price: 30, quantity: 2, modifiers };
|
|
@@ -44,11 +46,13 @@ describe('Order actions', () => {
|
|
|
44
46
|
quantity: 2,
|
|
45
47
|
modifiers: [
|
|
46
48
|
{
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
compute: {
|
|
50
|
+
amount: 2,
|
|
51
|
+
type: 'fixed',
|
|
52
|
+
action: 'subtract',
|
|
53
|
+
},
|
|
50
54
|
name: 'modifier1',
|
|
51
|
-
|
|
55
|
+
type: 'discount',
|
|
52
56
|
},
|
|
53
57
|
],
|
|
54
58
|
};
|
|
@@ -58,11 +62,13 @@ describe('Order actions', () => {
|
|
|
58
62
|
quantity: 1,
|
|
59
63
|
modifiers: [
|
|
60
64
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
compute: {
|
|
66
|
+
amount: 2,
|
|
67
|
+
type: 'fixed',
|
|
68
|
+
action: 'subtract',
|
|
69
|
+
},
|
|
64
70
|
name: 'modifier1',
|
|
65
|
-
|
|
71
|
+
type: 'discount',
|
|
66
72
|
},
|
|
67
73
|
],
|
|
68
74
|
};
|
|
@@ -87,11 +93,13 @@ describe('Order actions', () => {
|
|
|
87
93
|
quantity: 1,
|
|
88
94
|
};
|
|
89
95
|
const modifier1 = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
compute: {
|
|
97
|
+
amount: 2,
|
|
98
|
+
type: 'fixed',
|
|
99
|
+
action: 'subtract',
|
|
100
|
+
},
|
|
93
101
|
name: 'modifier1',
|
|
94
|
-
|
|
102
|
+
type: 'discount',
|
|
95
103
|
};
|
|
96
104
|
|
|
97
105
|
const order = { items: [item1, item2], modifiers: [modifier1] };
|
|
@@ -135,11 +143,13 @@ describe('Order actions', () => {
|
|
|
135
143
|
quantity: 1,
|
|
136
144
|
};
|
|
137
145
|
const modifier1 = {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
compute: {
|
|
147
|
+
amount: 10,
|
|
148
|
+
action: 'subtract',
|
|
149
|
+
type: 'percentage',
|
|
150
|
+
},
|
|
141
151
|
name: 'modifier1',
|
|
142
|
-
|
|
152
|
+
type: 'discount',
|
|
143
153
|
};
|
|
144
154
|
|
|
145
155
|
const order = { items: [item1, item2], modifiers: [modifier1] };
|
|
@@ -188,20 +198,24 @@ describe('Order actions', () => {
|
|
|
188
198
|
};
|
|
189
199
|
const modifier1 = {
|
|
190
200
|
_id: 1,
|
|
201
|
+
compute: {
|
|
202
|
+
amount: 10,
|
|
203
|
+
type: 'percentage',
|
|
204
|
+
action: 'subtract',
|
|
205
|
+
},
|
|
191
206
|
name: `10% Discount`,
|
|
192
|
-
|
|
193
|
-
type: 'percentage',
|
|
194
|
-
action: 'subtract',
|
|
195
|
-
category: 'discount',
|
|
207
|
+
type: 'discount',
|
|
196
208
|
};
|
|
197
209
|
|
|
198
210
|
const modifier2 = {
|
|
199
211
|
_id: 2,
|
|
200
212
|
name: `20% tax`,
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
213
|
+
type: 'tax',
|
|
214
|
+
compute: {
|
|
215
|
+
amount: 20,
|
|
216
|
+
type: 'percentage',
|
|
217
|
+
action: 'add',
|
|
218
|
+
},
|
|
205
219
|
};
|
|
206
220
|
|
|
207
221
|
const order = {
|
package/index.js
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const utils = require('@darkpos/utils');
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
/** services */
|
|
5
|
-
const makeItemService = require('./lib/item');
|
|
6
|
-
const makeOrderService = require('./lib/order');
|
|
7
|
-
|
|
8
|
-
module.exports = (deps = {}) => {
|
|
9
|
-
//
|
|
10
|
-
const modifierService = useModifierService(deps);
|
|
11
|
-
|
|
12
|
-
const itemService = makeItemService({ ...deps, _, utils, modifierService });
|
|
13
|
-
const orderService = makeOrderService({
|
|
14
|
-
...deps,
|
|
15
|
-
_,
|
|
16
|
-
utils,
|
|
17
|
-
modifierService,
|
|
18
|
-
itemService,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
return Object.freeze({
|
|
22
|
-
item: itemService,
|
|
23
|
-
order: orderService,
|
|
24
|
-
});
|
|
25
|
-
};
|
|
1
|
+
module.exports = require('./lib');
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const Order = Object.freeze({
|
|
2
|
+
OPEN: 'open',
|
|
3
|
+
HOLD: 'hold',
|
|
4
|
+
VOID: 'void',
|
|
5
|
+
CLOSED: 'close',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const Invoice = Object.freeze({
|
|
9
|
+
PARTIAL: 'partial',
|
|
10
|
+
PENDING: 'pending',
|
|
11
|
+
CLOSED: 'close',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const Kitchen = Object.freeze({
|
|
15
|
+
OPEN: 'open',
|
|
16
|
+
CLOSED: 'closed',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const Delivery = Object.freeze({
|
|
20
|
+
NONE: 'none',
|
|
21
|
+
BOOKED: 'booked',
|
|
22
|
+
PICKED: 'picked',
|
|
23
|
+
DELIVER: 'deliver',
|
|
24
|
+
DELIVERED: 'delivered',
|
|
25
|
+
DELIVERED_PARTIAL: 'delivered.partial',
|
|
26
|
+
RETURNED: 'returned',
|
|
27
|
+
RETURNED_PARTIAL: 'returned.partial',
|
|
28
|
+
HELD_NOT_READY: 'held.not.ready',
|
|
29
|
+
HELD_FOR_RELEASE_APPROVAL: 'held.for.release.approval',
|
|
30
|
+
CANCELLED: 'cancelled',
|
|
31
|
+
LOST: 'lost',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
module.exports = Object.freeze({
|
|
35
|
+
Order,
|
|
36
|
+
Invoice,
|
|
37
|
+
Kitchen,
|
|
38
|
+
Delivery,
|
|
39
|
+
});
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const makeModifierService = require('@darkpos/modifier');
|
|
2
|
+
const utils = require('@darkpos/utils');
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const moment = require('moment-timezone');
|
|
5
|
+
/** services */
|
|
6
|
+
const makeItemActions = require('./item');
|
|
7
|
+
const makeOrderActions = require('./order');
|
|
8
|
+
|
|
9
|
+
module.exports = session => {
|
|
10
|
+
const { useLocalization } = utils;
|
|
11
|
+
const settings = _.get(session, 'store._settings', {});
|
|
12
|
+
const localization = useLocalization(settings.localization);
|
|
13
|
+
|
|
14
|
+
const deps = {
|
|
15
|
+
settings,
|
|
16
|
+
utils,
|
|
17
|
+
localization,
|
|
18
|
+
_,
|
|
19
|
+
moment,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//
|
|
23
|
+
const modifierActions = makeModifierService(session);
|
|
24
|
+
const itemActions = makeItemActions({ ...deps, modifierActions });
|
|
25
|
+
const orderActions = makeOrderActions({
|
|
26
|
+
...deps,
|
|
27
|
+
itemActions,
|
|
28
|
+
modifierActions,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
item: itemActions,
|
|
33
|
+
order: orderActions,
|
|
34
|
+
modifier: modifierActions,
|
|
35
|
+
};
|
|
36
|
+
};
|