@darkpos/pricing 1.0.15 → 1.0.16
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/__TEST__/mocks/partially-paid/input-items.json +1 -0
- package/__TEST__/mocks/partially-paid/order-modifiers.json +53 -0
- package/__TEST__/mocks/partially-paid/order-partially-paid.json +890 -0
- package/__TEST__/mocks/scripts/calculate-partially-paid/index.js +27 -0
- package/__TEST__/mocks/scripts/calculate-unpaid/index.js +28 -0
- package/__TEST__/mocks/scripts/order-to-string.js +18 -0
- package/__TEST__/mocks/stores.js +435 -0
- package/__TEST__/mocks/unpaid/input-items.json +6 -0
- package/__TEST__/mocks/unpaid/order-modifiers.json +53 -0
- package/__TEST__/mocks/unpaid/order-not-paid.json +684 -0
- package/__TEST__/order/order.test.js +610 -0
- package/lib/item/addIndirectModifier.js +2 -3
- package/lib/item/calculate.js +1 -2
- package/lib/item/getBalance.js +9 -0
- package/lib/item/getItemModifiers.js +3 -14
- package/lib/item/getItems.js +5 -0
- package/lib/item/getTotal.js +1 -1
- package/lib/item/getTotalPrice.js +10 -0
- package/lib/item/getTotals.js +31 -18
- package/lib/item/index.js +12 -0
- package/lib/item/isFullyPaid.js +6 -0
- package/lib/item/markModifiersAsLocked.js +11 -0
- package/lib/item/removeModifier.js +10 -9
- package/lib/item/removePaymentModifiers.js +15 -0
- package/lib/modifier/create.js +2 -2
- package/lib/modifier/createAmountOverrideModifier.js +1 -3
- package/lib/modifier/createCreditModifier.js +2 -4
- package/lib/modifier/createDiscountModifier.js +1 -3
- package/lib/modifier/createIndirectModifier.js +1 -1
- package/lib/modifier/createPaymentModifier.js +12 -0
- package/lib/modifier/createSubscriptionModifier.js +1 -3
- package/lib/modifier/duplicate.js +1 -1
- package/lib/modifier/findById.js +4 -1
- package/lib/modifier/findByPaymentMethod.js +1 -1
- package/lib/modifier/findByPaymentType.js +1 -1
- package/lib/modifier/getItemModifiers.js +1 -3
- package/lib/modifier/getLockedModifiers.js +5 -0
- package/lib/modifier/getSplittedModifiers.js +4 -6
- package/lib/modifier/hasItems.js +8 -0
- package/lib/modifier/index.js +20 -4
- package/lib/modifier/isFixed.js +10 -0
- package/lib/modifier/isFixedDiscount.js +4 -0
- package/lib/modifier/isPaymentMethodModifier.js +8 -0
- package/lib/modifier/isPaymentModifier.js +7 -0
- package/lib/modifier/isPaymentTypeModifier.js +8 -0
- package/lib/modifier/isSubtract.js +10 -0
- package/lib/modifier/removeLocked.js +8 -0
- package/lib/order/addItem.js +104 -106
- package/lib/order/addItemModifier.js +0 -3
- package/lib/order/addModifier.js +14 -2
- package/lib/order/addModifiers.js +15 -0
- package/lib/order/autoSplit.js +34 -0
- package/lib/order/calculate.js +46 -68
- package/lib/order/getScheduleByCustomer.js +0 -1
- package/lib/order/index.js +10 -0
- package/lib/order/markModifiersAsLocked.js +14 -0
- package/lib/order/removeItem.js +0 -2
- package/lib/order/removeModifier.js +5 -1
- package/lib/order/removeModifiers.js +18 -0
- package/lib/order/splitByDepartments.js +1 -13
- package/lib/order/syncSubOrderItemsFromParent.js +24 -0
- package/package.json +3 -2
- package/__TEST__/order.test.js +0 -233
- package/lib/modifier/isPaymentMethods.js +0 -8
- package/lib/modifier/isPaymentTypes.js +0 -8
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
const usePricing = require('../../index');
|
|
2
|
+
const mockStores = require('../mocks/stores');
|
|
3
|
+
|
|
4
|
+
const orderNotPaid = require('../mocks/unpaid/order-not-paid.json');
|
|
5
|
+
const orderModifiersNotPaid = require('../mocks/unpaid/order-modifiers.json');
|
|
6
|
+
const inputItemsNotPaidOrder = require('../mocks/unpaid/input-items.json');
|
|
7
|
+
|
|
8
|
+
const orderPartiallyPaid = require('../mocks/partially-paid/order-partially-paid.json');
|
|
9
|
+
const orderModifiersPartiallyPaid = require('../mocks/partially-paid/order-modifiers.json');
|
|
10
|
+
const inputItemsPartiallyPaidOrder = require('../mocks/partially-paid/input-items.json');
|
|
11
|
+
|
|
12
|
+
const session = {
|
|
13
|
+
store: mockStores[0],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const pricingService = usePricing(session);
|
|
17
|
+
|
|
18
|
+
describe('Order actions', () => {
|
|
19
|
+
test('Get calculated Order, one item', () => {
|
|
20
|
+
const modifiers = [
|
|
21
|
+
{
|
|
22
|
+
compute: {
|
|
23
|
+
amount: 20,
|
|
24
|
+
type: 'percentage',
|
|
25
|
+
action: 'add',
|
|
26
|
+
},
|
|
27
|
+
name: 'modifier1',
|
|
28
|
+
type: 'discount',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
compute: {
|
|
32
|
+
amount: 20,
|
|
33
|
+
type: 'percentage',
|
|
34
|
+
action: 'subtract',
|
|
35
|
+
},
|
|
36
|
+
name: 'modifier2',
|
|
37
|
+
type: 'discount',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
compute: { amount: 2, type: 'fixed', action: 'subtract' },
|
|
41
|
+
name: 'modifier3',
|
|
42
|
+
type: 'discount',
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
const orderItem = { price: 30, quantity: 2, modifiers };
|
|
46
|
+
const order = { items: [orderItem] };
|
|
47
|
+
const newOrder = pricingService.order.calculate(order);
|
|
48
|
+
|
|
49
|
+
expect(newOrder).toHaveProperty('total', 56);
|
|
50
|
+
expect(newOrder).toHaveProperty('subTotal', 60);
|
|
51
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
52
|
+
discount: -4,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
test('Get calculated Order, multiple items', () => {
|
|
56
|
+
const item1 = {
|
|
57
|
+
_id: 1,
|
|
58
|
+
price: 30,
|
|
59
|
+
quantity: 2,
|
|
60
|
+
modifiers: [
|
|
61
|
+
{
|
|
62
|
+
compute: {
|
|
63
|
+
amount: 2,
|
|
64
|
+
type: 'fixed',
|
|
65
|
+
action: 'subtract',
|
|
66
|
+
},
|
|
67
|
+
name: 'modifier1',
|
|
68
|
+
type: 'discount',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
const item2 = {
|
|
73
|
+
_id: 2,
|
|
74
|
+
price: 10,
|
|
75
|
+
quantity: 1,
|
|
76
|
+
modifiers: [
|
|
77
|
+
{
|
|
78
|
+
compute: {
|
|
79
|
+
amount: 2,
|
|
80
|
+
type: 'fixed',
|
|
81
|
+
action: 'subtract',
|
|
82
|
+
},
|
|
83
|
+
name: 'modifier1',
|
|
84
|
+
type: 'discount',
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
const order = { items: [item1, item2] };
|
|
89
|
+
const newOrder = pricingService.order.calculate(order);
|
|
90
|
+
expect(newOrder).toHaveProperty('total', 64);
|
|
91
|
+
expect(newOrder).toHaveProperty('subTotal', 70);
|
|
92
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
93
|
+
discount: -6,
|
|
94
|
+
});
|
|
95
|
+
// console.log(JSON.stringify(newOrder, 0, 2));
|
|
96
|
+
});
|
|
97
|
+
test('Get calculated Order, multiple items and indirect modifiers', () => {
|
|
98
|
+
const item1 = {
|
|
99
|
+
_id: 1,
|
|
100
|
+
price: 30,
|
|
101
|
+
quantity: 2,
|
|
102
|
+
};
|
|
103
|
+
const item2 = {
|
|
104
|
+
_id: 2,
|
|
105
|
+
price: 10,
|
|
106
|
+
quantity: 1,
|
|
107
|
+
};
|
|
108
|
+
const modifier1 = {
|
|
109
|
+
compute: {
|
|
110
|
+
amount: 2,
|
|
111
|
+
type: 'fixed',
|
|
112
|
+
action: 'subtract',
|
|
113
|
+
},
|
|
114
|
+
name: 'modifier1',
|
|
115
|
+
type: 'discount',
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const order = { items: [item1, item2], modifiers: [modifier1] };
|
|
119
|
+
|
|
120
|
+
const newOrder = pricingService.order.calculate(order);
|
|
121
|
+
expect(newOrder).toHaveProperty('total', 68);
|
|
122
|
+
expect(newOrder).toHaveProperty('subTotal', 70);
|
|
123
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
124
|
+
discount: -2,
|
|
125
|
+
});
|
|
126
|
+
expect(newOrder.items[0]).toHaveProperty('total', 58.28);
|
|
127
|
+
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
128
|
+
discount: -1.72,
|
|
129
|
+
_included: 0,
|
|
130
|
+
_xincluded: -1.72,
|
|
131
|
+
_direct: 0,
|
|
132
|
+
_xdirect: -1.72,
|
|
133
|
+
_simple: 60,
|
|
134
|
+
_actual: 60,
|
|
135
|
+
});
|
|
136
|
+
expect(newOrder.items[1]).toHaveProperty('total', 9.72);
|
|
137
|
+
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
138
|
+
discount: -0.28,
|
|
139
|
+
_included: 0,
|
|
140
|
+
_xincluded: -0.28,
|
|
141
|
+
_direct: 0,
|
|
142
|
+
_xdirect: -0.28,
|
|
143
|
+
_simple: 10,
|
|
144
|
+
_actual: 10,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
test('Get calculated Order, multiple items and indirect modifiers #2', () => {
|
|
148
|
+
const item1 = {
|
|
149
|
+
_id: 1,
|
|
150
|
+
price: 15.99,
|
|
151
|
+
quantity: 1,
|
|
152
|
+
};
|
|
153
|
+
const item2 = {
|
|
154
|
+
_id: 2,
|
|
155
|
+
price: 4.65,
|
|
156
|
+
quantity: 1,
|
|
157
|
+
};
|
|
158
|
+
const modifier1 = {
|
|
159
|
+
compute: {
|
|
160
|
+
amount: 10,
|
|
161
|
+
action: 'subtract',
|
|
162
|
+
type: 'percentage',
|
|
163
|
+
},
|
|
164
|
+
name: 'modifier1',
|
|
165
|
+
type: 'discount',
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const order = { items: [item1, item2], modifiers: [modifier1] };
|
|
169
|
+
const newOrder = pricingService.order.calculate(order);
|
|
170
|
+
expect(newOrder).toHaveProperty('total', 18.58);
|
|
171
|
+
expect(newOrder).toHaveProperty('subTotal', 20.64);
|
|
172
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
173
|
+
discount: -2.06,
|
|
174
|
+
});
|
|
175
|
+
expect(newOrder.items[0]).toHaveProperty('total', 14.39);
|
|
176
|
+
expect(newOrder.items[0]).toHaveProperty('subTotals', {
|
|
177
|
+
discount: -1.6,
|
|
178
|
+
_included: 0,
|
|
179
|
+
_xincluded: -1.6,
|
|
180
|
+
_direct: 0,
|
|
181
|
+
_xdirect: -1.6,
|
|
182
|
+
_simple: 15.99,
|
|
183
|
+
_actual: 15.99,
|
|
184
|
+
});
|
|
185
|
+
expect(newOrder.items[1]).toHaveProperty('total', 4.19);
|
|
186
|
+
expect(newOrder.items[1]).toHaveProperty('subTotals', {
|
|
187
|
+
discount: -0.46,
|
|
188
|
+
_included: 0,
|
|
189
|
+
_xincluded: -0.46,
|
|
190
|
+
_direct: 0,
|
|
191
|
+
_xdirect: -0.46,
|
|
192
|
+
_simple: 4.65,
|
|
193
|
+
_actual: 4.65,
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
test('Get calculated Order, multiple items and indirect modifiers #3', () => {
|
|
197
|
+
const item1 = {
|
|
198
|
+
_id: 1,
|
|
199
|
+
price: 3,
|
|
200
|
+
quantity: 1,
|
|
201
|
+
};
|
|
202
|
+
const item2 = {
|
|
203
|
+
_id: 2,
|
|
204
|
+
price: 3,
|
|
205
|
+
quantity: 1,
|
|
206
|
+
};
|
|
207
|
+
const item3 = {
|
|
208
|
+
_id: 3,
|
|
209
|
+
price: 4,
|
|
210
|
+
quantity: 1,
|
|
211
|
+
};
|
|
212
|
+
const modifier1 = {
|
|
213
|
+
_id: 1,
|
|
214
|
+
compute: {
|
|
215
|
+
amount: 10,
|
|
216
|
+
type: 'percentage',
|
|
217
|
+
action: 'subtract',
|
|
218
|
+
},
|
|
219
|
+
name: `10% Discount`,
|
|
220
|
+
type: 'discount',
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const modifier2 = {
|
|
224
|
+
_id: 2,
|
|
225
|
+
name: `20% tax`,
|
|
226
|
+
type: 'tax',
|
|
227
|
+
compute: {
|
|
228
|
+
amount: 20,
|
|
229
|
+
type: 'percentage',
|
|
230
|
+
action: 'add',
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const order = {
|
|
235
|
+
items: [item1, item2, item3],
|
|
236
|
+
modifiers: [modifier1, modifier2],
|
|
237
|
+
};
|
|
238
|
+
const newOrder = pricingService.order.calculate(order);
|
|
239
|
+
expect(newOrder).toHaveProperty('total', 11);
|
|
240
|
+
expect(newOrder).toHaveProperty('subTotal', 10);
|
|
241
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
242
|
+
discount: -1,
|
|
243
|
+
tax: 2,
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('Auto split a Parent Order', () => {
|
|
248
|
+
const parentOrder = {
|
|
249
|
+
_id: '6392069cb6c81965a442289d',
|
|
250
|
+
displayId: '1',
|
|
251
|
+
parentId: null,
|
|
252
|
+
isParent: false,
|
|
253
|
+
subTotal: 15,
|
|
254
|
+
tax: 0,
|
|
255
|
+
discount: 0,
|
|
256
|
+
total: 15,
|
|
257
|
+
description: '',
|
|
258
|
+
type: '',
|
|
259
|
+
fee: 0,
|
|
260
|
+
location: {},
|
|
261
|
+
status: {
|
|
262
|
+
order: 'open',
|
|
263
|
+
kitchen: 'open',
|
|
264
|
+
delivery: 'none',
|
|
265
|
+
detailed: true,
|
|
266
|
+
},
|
|
267
|
+
attributes: [],
|
|
268
|
+
properties: {
|
|
269
|
+
pieces: [],
|
|
270
|
+
notify: {
|
|
271
|
+
sms: false,
|
|
272
|
+
},
|
|
273
|
+
print: {},
|
|
274
|
+
split: 'auto',
|
|
275
|
+
},
|
|
276
|
+
subTotals: {},
|
|
277
|
+
user: {
|
|
278
|
+
_id: '5a09fd650cd56e741f78aba6',
|
|
279
|
+
},
|
|
280
|
+
items: [
|
|
281
|
+
{
|
|
282
|
+
_id: '639206f1b6c81965a44228ba',
|
|
283
|
+
itemId: '62cdbfd01ee1b40019328252',
|
|
284
|
+
name: 'Box Shirt - Fold',
|
|
285
|
+
description: '',
|
|
286
|
+
modifiersTotalAmount: 0,
|
|
287
|
+
location: {},
|
|
288
|
+
price: 2,
|
|
289
|
+
pieces: 1,
|
|
290
|
+
quantity: 1,
|
|
291
|
+
path: ['menuCategories', 8],
|
|
292
|
+
menuId: '62cdbfd0aaf93c00193d2efe',
|
|
293
|
+
serial: null,
|
|
294
|
+
sku: null,
|
|
295
|
+
total: 2,
|
|
296
|
+
status: {
|
|
297
|
+
picked: {
|
|
298
|
+
value: false,
|
|
299
|
+
date: '',
|
|
300
|
+
},
|
|
301
|
+
paid: {
|
|
302
|
+
value: false,
|
|
303
|
+
date: '',
|
|
304
|
+
},
|
|
305
|
+
tracker: [],
|
|
306
|
+
},
|
|
307
|
+
subTotals: {
|
|
308
|
+
_included: 0,
|
|
309
|
+
_xincluded: 0,
|
|
310
|
+
_direct: 0,
|
|
311
|
+
_xdirect: 0,
|
|
312
|
+
_simple: 2,
|
|
313
|
+
_actual: 2,
|
|
314
|
+
},
|
|
315
|
+
properties: false,
|
|
316
|
+
modifiers: [
|
|
317
|
+
{
|
|
318
|
+
_id: '639206f1b6c81965a44228bc',
|
|
319
|
+
modifierId: '62cdbfd01ee1b4001932816c',
|
|
320
|
+
name: 'Laundry',
|
|
321
|
+
sku: '',
|
|
322
|
+
description: '',
|
|
323
|
+
group: '',
|
|
324
|
+
type: null,
|
|
325
|
+
attributes: ['department'],
|
|
326
|
+
color: '',
|
|
327
|
+
backgroundColor: null,
|
|
328
|
+
icon: null,
|
|
329
|
+
url: '',
|
|
330
|
+
tags: [],
|
|
331
|
+
order: 2,
|
|
332
|
+
included: false,
|
|
333
|
+
direct: true,
|
|
334
|
+
hidden: true,
|
|
335
|
+
print: false,
|
|
336
|
+
required: true,
|
|
337
|
+
recommended: false,
|
|
338
|
+
default: false,
|
|
339
|
+
code: 'L',
|
|
340
|
+
properties: {
|
|
341
|
+
department: {
|
|
342
|
+
tagSize: 'Small',
|
|
343
|
+
customerTagsExtend: null,
|
|
344
|
+
maxItems: 4,
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
_computed: {
|
|
348
|
+
amount: 0,
|
|
349
|
+
description: 'Laundry ($0.00)',
|
|
350
|
+
},
|
|
351
|
+
addModifiers: [],
|
|
352
|
+
delModifiers: [],
|
|
353
|
+
conditions: null,
|
|
354
|
+
compute: null,
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
notes: [],
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
_id: '639206efb6c81965a44228b7',
|
|
361
|
+
itemId: '62cdbfd01ee1b40019328284',
|
|
362
|
+
name: 'Pants',
|
|
363
|
+
description: '',
|
|
364
|
+
modifiersTotalAmount: 0,
|
|
365
|
+
location: {},
|
|
366
|
+
price: 4,
|
|
367
|
+
pieces: 1,
|
|
368
|
+
quantity: 1,
|
|
369
|
+
path: ['menuCategories', 11],
|
|
370
|
+
menuId: '62cdbfd0aaf93c00193d2efe',
|
|
371
|
+
serial: null,
|
|
372
|
+
sku: null,
|
|
373
|
+
total: 4,
|
|
374
|
+
status: {
|
|
375
|
+
picked: {
|
|
376
|
+
value: false,
|
|
377
|
+
date: '',
|
|
378
|
+
},
|
|
379
|
+
paid: {
|
|
380
|
+
value: false,
|
|
381
|
+
date: '',
|
|
382
|
+
},
|
|
383
|
+
tracker: [],
|
|
384
|
+
},
|
|
385
|
+
subTotals: {
|
|
386
|
+
_included: 0,
|
|
387
|
+
_xincluded: 0,
|
|
388
|
+
_direct: 0,
|
|
389
|
+
_xdirect: 0,
|
|
390
|
+
_simple: 4,
|
|
391
|
+
_actual: 4,
|
|
392
|
+
},
|
|
393
|
+
properties: false,
|
|
394
|
+
modifiers: [
|
|
395
|
+
{
|
|
396
|
+
_id: '639206efb6c81965a44228b9',
|
|
397
|
+
modifierId: '62cdbfd01ee1b4001932816d',
|
|
398
|
+
name: 'Dry Cleaning',
|
|
399
|
+
sku: '',
|
|
400
|
+
description: '',
|
|
401
|
+
group: '',
|
|
402
|
+
type: null,
|
|
403
|
+
attributes: ['department'],
|
|
404
|
+
color: '',
|
|
405
|
+
backgroundColor: null,
|
|
406
|
+
icon: null,
|
|
407
|
+
url: '',
|
|
408
|
+
tags: null,
|
|
409
|
+
order: 1,
|
|
410
|
+
included: false,
|
|
411
|
+
direct: true,
|
|
412
|
+
hidden: true,
|
|
413
|
+
print: false,
|
|
414
|
+
required: true,
|
|
415
|
+
recommended: false,
|
|
416
|
+
default: false,
|
|
417
|
+
code: 'D',
|
|
418
|
+
properties: {
|
|
419
|
+
department: {
|
|
420
|
+
tagSize: 'Small',
|
|
421
|
+
customerTagsExtend: null,
|
|
422
|
+
maxItems: 4,
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
_computed: {
|
|
426
|
+
amount: 0,
|
|
427
|
+
description: 'Dry Cleaning ($0.00)',
|
|
428
|
+
},
|
|
429
|
+
addModifiers: [],
|
|
430
|
+
delModifiers: [],
|
|
431
|
+
conditions: null,
|
|
432
|
+
compute: null,
|
|
433
|
+
},
|
|
434
|
+
],
|
|
435
|
+
notes: [],
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
_id: '639206edb6c81965a44228b4',
|
|
439
|
+
itemId: '62cdbfd01ee1b400193281f1',
|
|
440
|
+
name: 'M-L 2pc Suit',
|
|
441
|
+
description: null,
|
|
442
|
+
modifiersTotalAmount: 0,
|
|
443
|
+
location: {},
|
|
444
|
+
price: 9,
|
|
445
|
+
pieces: 2,
|
|
446
|
+
quantity: 1,
|
|
447
|
+
path: ['menuCategories', 0],
|
|
448
|
+
menuId: '62cdbfd0aaf93c00193d2efe',
|
|
449
|
+
serial: null,
|
|
450
|
+
sku: null,
|
|
451
|
+
total: 9,
|
|
452
|
+
status: {
|
|
453
|
+
picked: {
|
|
454
|
+
value: false,
|
|
455
|
+
date: '',
|
|
456
|
+
},
|
|
457
|
+
paid: {
|
|
458
|
+
value: false,
|
|
459
|
+
date: '',
|
|
460
|
+
},
|
|
461
|
+
tracker: [],
|
|
462
|
+
},
|
|
463
|
+
subTotals: {
|
|
464
|
+
_included: 0,
|
|
465
|
+
_xincluded: 0,
|
|
466
|
+
_direct: 0,
|
|
467
|
+
_xdirect: 0,
|
|
468
|
+
_simple: 9,
|
|
469
|
+
_actual: 9,
|
|
470
|
+
},
|
|
471
|
+
properties: false,
|
|
472
|
+
modifiers: [
|
|
473
|
+
{
|
|
474
|
+
_id: '639206edb6c81965a44228b6',
|
|
475
|
+
modifierId: '62cdbfd01ee1b4001932816d',
|
|
476
|
+
name: 'Dry Cleaning',
|
|
477
|
+
sku: '',
|
|
478
|
+
description: '',
|
|
479
|
+
group: '',
|
|
480
|
+
type: null,
|
|
481
|
+
attributes: ['department'],
|
|
482
|
+
color: '',
|
|
483
|
+
backgroundColor: null,
|
|
484
|
+
icon: null,
|
|
485
|
+
url: '',
|
|
486
|
+
tags: null,
|
|
487
|
+
order: 1,
|
|
488
|
+
included: false,
|
|
489
|
+
direct: true,
|
|
490
|
+
hidden: true,
|
|
491
|
+
print: false,
|
|
492
|
+
required: true,
|
|
493
|
+
recommended: false,
|
|
494
|
+
default: false,
|
|
495
|
+
code: 'D',
|
|
496
|
+
properties: {
|
|
497
|
+
department: {
|
|
498
|
+
tagSize: 'Small',
|
|
499
|
+
customerTagsExtend: null,
|
|
500
|
+
maxItems: 4,
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
_computed: {
|
|
504
|
+
amount: 0,
|
|
505
|
+
description: 'Dry Cleaning ($0.00)',
|
|
506
|
+
},
|
|
507
|
+
addModifiers: [],
|
|
508
|
+
delModifiers: [],
|
|
509
|
+
conditions: null,
|
|
510
|
+
compute: null,
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
notes: [],
|
|
514
|
+
},
|
|
515
|
+
],
|
|
516
|
+
notes: [],
|
|
517
|
+
start: {
|
|
518
|
+
actualDate: '2022-12-08T15:45:27.838Z',
|
|
519
|
+
requestDate: '2022-12-08T15:45:27.838Z',
|
|
520
|
+
location: null,
|
|
521
|
+
},
|
|
522
|
+
end: {
|
|
523
|
+
actualDate: '',
|
|
524
|
+
requestDate: '2022-12-12T22:00:00.000Z',
|
|
525
|
+
location: {
|
|
526
|
+
name: 'Location Name',
|
|
527
|
+
locationType: 'store',
|
|
528
|
+
storeId: '59c042222a985ae70278619f',
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
customer: {
|
|
532
|
+
_id: '5c73d50b213453368dd30422',
|
|
533
|
+
},
|
|
534
|
+
modifiers: [],
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
const subOrders = pricingService.order
|
|
538
|
+
.autoSplit({ parentOrder })
|
|
539
|
+
.sort((a, b) => {
|
|
540
|
+
if (a.displayId < b.displayId) return -1;
|
|
541
|
+
if (a.displayId > b.displayId) return 1;
|
|
542
|
+
return 0;
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
expect(subOrders[0].displayId).toBe('1-1');
|
|
546
|
+
expect(subOrders[0].items.map(item => item.name)).toEqual([
|
|
547
|
+
'Box Shirt - Fold',
|
|
548
|
+
]);
|
|
549
|
+
expect(subOrders[1].displayId).toBe('1-2');
|
|
550
|
+
expect(subOrders[1].items.map(item => item.name)).toEqual([
|
|
551
|
+
'Pants',
|
|
552
|
+
'M-L 2pc Suit',
|
|
553
|
+
]);
|
|
554
|
+
});
|
|
555
|
+
test('Get calculated UNPAID Order, multiple items and paymentModifiers', () => {
|
|
556
|
+
const paymentModifiers = orderModifiersNotPaid.map(orderMod =>
|
|
557
|
+
pricingService.modifier.createPaymentModifier({
|
|
558
|
+
modifier: orderMod,
|
|
559
|
+
items: inputItemsNotPaidOrder,
|
|
560
|
+
})
|
|
561
|
+
);
|
|
562
|
+
|
|
563
|
+
let order = { ...orderNotPaid };
|
|
564
|
+
|
|
565
|
+
order = pricingService.order.addModifiers({
|
|
566
|
+
modifiers: paymentModifiers,
|
|
567
|
+
order,
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
const newOrder = pricingService.order.calculate(order);
|
|
571
|
+
|
|
572
|
+
expect(newOrder).toHaveProperty('total', 34.45);
|
|
573
|
+
expect(newOrder).toHaveProperty('subTotal', 42.45);
|
|
574
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
575
|
+
discount: -10,
|
|
576
|
+
fee: 2,
|
|
577
|
+
});
|
|
578
|
+
expect(newOrder.items[0]).toHaveProperty('total', 8.08);
|
|
579
|
+
expect(newOrder.items[1]).toHaveProperty('total', 7.71);
|
|
580
|
+
expect(newOrder.items[2]).toHaveProperty('total', 11.36);
|
|
581
|
+
expect(newOrder.items[3]).toHaveProperty('total', 7.3);
|
|
582
|
+
});
|
|
583
|
+
test('Get calculated PARTIALLY PAID Order, multiple items and paymentModifiers', () => {
|
|
584
|
+
const paymentModifiers = orderModifiersPartiallyPaid.map(orderMod =>
|
|
585
|
+
pricingService.modifier.createPaymentModifier({
|
|
586
|
+
modifier: orderMod,
|
|
587
|
+
items: inputItemsPartiallyPaidOrder,
|
|
588
|
+
})
|
|
589
|
+
);
|
|
590
|
+
|
|
591
|
+
let order = { ...orderPartiallyPaid };
|
|
592
|
+
|
|
593
|
+
order = pricingService.order.addModifiers({
|
|
594
|
+
modifiers: paymentModifiers,
|
|
595
|
+
order,
|
|
596
|
+
});
|
|
597
|
+
const newOrder = pricingService.order.calculate(order);
|
|
598
|
+
|
|
599
|
+
expect(newOrder).toHaveProperty('total', 36.45);
|
|
600
|
+
expect(newOrder).toHaveProperty('subTotal', 42.45);
|
|
601
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
602
|
+
discount: -10,
|
|
603
|
+
fee: 4,
|
|
604
|
+
});
|
|
605
|
+
expect(newOrder.items[0]).toHaveProperty('total', 8.07);
|
|
606
|
+
expect(newOrder.items[1]).toHaveProperty('total', 7.71);
|
|
607
|
+
expect(newOrder.items[2]).toHaveProperty('total', 11.37);
|
|
608
|
+
expect(newOrder.items[3]).toHaveProperty('total', 9.3);
|
|
609
|
+
});
|
|
610
|
+
});
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
module.exports = ({ utils, modifierActions }) => {
|
|
2
2
|
const { math } = utils;
|
|
3
3
|
|
|
4
|
-
return function addIndirectModifier(orderTotal, items, modifier) {
|
|
4
|
+
return function addIndirectModifier({ orderTotal, items, modifier }) {
|
|
5
5
|
const itemsModifiers = {};
|
|
6
6
|
// get distributed price in order level
|
|
7
7
|
const { _computed } = modifierActions.calculate(modifier, {
|
|
8
8
|
price: orderTotal,
|
|
9
9
|
quantity: 1,
|
|
10
10
|
});
|
|
11
|
-
|
|
12
11
|
const orderModifierTotal = math.abs(_computed.amount);
|
|
13
12
|
const totalDistributed = items.reduce((acc, item) => {
|
|
14
13
|
const inheritedModifier = modifierActions.createIndirectModifier(
|
|
@@ -29,7 +28,6 @@ module.exports = ({ utils, modifierActions }) => {
|
|
|
29
28
|
// check validation
|
|
30
29
|
if (math.abs(totalDistributed) !== math.abs(orderModifierTotal)) {
|
|
31
30
|
const difference = math.sub(orderModifierTotal, totalDistributed);
|
|
32
|
-
// console.log('difference => ', difference);
|
|
33
31
|
const selectedItem = items.find(
|
|
34
32
|
item => math.sub(item.total, difference) > 0
|
|
35
33
|
);
|
|
@@ -51,6 +49,7 @@ module.exports = ({ utils, modifierActions }) => {
|
|
|
51
49
|
},
|
|
52
50
|
};
|
|
53
51
|
}
|
|
52
|
+
|
|
54
53
|
return itemsModifiers;
|
|
55
54
|
}
|
|
56
55
|
|
package/lib/item/calculate.js
CHANGED
|
@@ -66,7 +66,6 @@ module.exports = ({ _, utils, modifierActions }) => {
|
|
|
66
66
|
|
|
67
67
|
modifiers.push(_modifier);
|
|
68
68
|
const { type, _computed } = _modifier;
|
|
69
|
-
// console.log('computedPrice => ', _computed);
|
|
70
69
|
let computedAmount = modifierActions.isIgnoreQuantity(_modifier)
|
|
71
70
|
? _computed.amount
|
|
72
71
|
: math.mul(_computed.amount, quantity);
|
|
@@ -89,7 +88,7 @@ module.exports = ({ _, utils, modifierActions }) => {
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
subTotals._actual = math.add(subTotals._simple, subTotals._included);
|
|
92
|
-
|
|
91
|
+
|
|
93
92
|
const total = math.add(subTotals._actual, subTotals._xincluded);
|
|
94
93
|
|
|
95
94
|
return {
|
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
function getItemModifiers(item
|
|
3
|
-
const existsInOrderModifier = modifier =>
|
|
4
|
-
orderModifiers &&
|
|
5
|
-
orderModifiers.find(each => each.modifierId === modifier.modifierId);
|
|
1
|
+
module.exports = () =>
|
|
2
|
+
function getItemModifiers(item) {
|
|
6
3
|
|
|
7
|
-
|
|
8
|
-
if (!item || !Array.isArray(item.modifiers)) return modifiers;
|
|
9
|
-
|
|
10
|
-
modifiers.push(...item.modifiers);
|
|
11
|
-
|
|
12
|
-
if (Array.isArray(orderModifiers) && orderModifiers.length)
|
|
13
|
-
modifiers = modifiers.filter(each => !existsInOrderModifier(each));
|
|
14
|
-
|
|
15
|
-
return modifiers.filter(modifierActions.isDirect);
|
|
4
|
+
return item.modifiers;
|
|
16
5
|
};
|
package/lib/item/getTotal.js
CHANGED