@darkpos/pricing 1.0.16 → 1.0.17

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.
@@ -0,0 +1,474 @@
1
+ {
2
+ "_id": "63adbedef1091b185287a590",
3
+ "parentId": null,
4
+ "isParent": false,
5
+ "subTotal": 23,
6
+ "tax": 0,
7
+ "modifiers": [
8
+ {
9
+ "name": "Customer stored credit",
10
+ "sku": "",
11
+ "description": "",
12
+ "group": "",
13
+ "type": "credit",
14
+ "attributes": [],
15
+ "color": "",
16
+ "backgroundColor": "",
17
+ "icon": "",
18
+ "url": "",
19
+ "code": "",
20
+ "tags": [],
21
+ "order": 0,
22
+ "included": false,
23
+ "direct": true,
24
+ "hidden": false,
25
+ "required": false,
26
+ "print": true,
27
+ "delModifiers": [],
28
+ "addModifiers": [],
29
+ "conditions": null,
30
+ "compute": {
31
+ "amount": 100,
32
+ "type": "percentage",
33
+ "action": "subtract"
34
+ },
35
+ "properties": {
36
+ "maxAmount": 20,
37
+ "sort": 999
38
+ },
39
+ "_id": "63ade212dd19604ca368eb23",
40
+ "__typename": "Modifier"
41
+ }
42
+ ],
43
+ "discount": 0,
44
+ "total": 3,
45
+ "description": "",
46
+ "displayId": "",
47
+ "type": "",
48
+ "location": {},
49
+ "status": {
50
+ "order": "open",
51
+ "kitchen": "open",
52
+ "delivery": "none",
53
+ "detailed": true
54
+ },
55
+ "attributes": [],
56
+ "fee": 0,
57
+ "items": [
58
+ {
59
+ "location": {},
60
+ "status": {
61
+ "picked": {
62
+ "value": false,
63
+ "date": ""
64
+ },
65
+ "paid": {
66
+ "value": false,
67
+ "date": ""
68
+ },
69
+ "tracker": []
70
+ },
71
+ "name": "Sport Men's 2pc Suit",
72
+ "description": "",
73
+ "pieces": 2,
74
+ "modifiersTotalAmount": 0,
75
+ "total": 0,
76
+ "totalPaid": 0,
77
+ "price": 9.5,
78
+ "quantity": 1,
79
+ "path": [
80
+ "menuCategories",
81
+ 0
82
+ ],
83
+ "notes": [],
84
+ "menuId": "639b97178e5c8c0019c58e64",
85
+ "serial": null,
86
+ "sku": null,
87
+ "modifiers": [
88
+ {
89
+ "__typename": "Modifier",
90
+ "addModifiers": [],
91
+ "delModifiers": [],
92
+ "conditions": null,
93
+ "compute": null,
94
+ "_createdAt": "2022-12-15T21:52:27.541Z",
95
+ "_updatedAt": "2022-12-15T21:52:27.541Z",
96
+ "_id": "63ade225dd19604ca368eb2c",
97
+ "modifierId": "639b971643d8c80013526fea",
98
+ "_parentId": null,
99
+ "locked": false,
100
+ "name": "Dry Cleaning",
101
+ "sku": "",
102
+ "description": "",
103
+ "group": "",
104
+ "type": null,
105
+ "attributes": [
106
+ "department"
107
+ ],
108
+ "color": "",
109
+ "backgroundColor": null,
110
+ "icon": null,
111
+ "url": "",
112
+ "tags": null,
113
+ "order": 1,
114
+ "included": false,
115
+ "direct": true,
116
+ "hidden": true,
117
+ "print": false,
118
+ "required": true,
119
+ "recommended": false,
120
+ "default": false,
121
+ "code": "D",
122
+ "properties": {
123
+ "department": {
124
+ "tagSize": "Small",
125
+ "customerTagsExtend": null,
126
+ "maxItems": 4
127
+ }
128
+ },
129
+ "_computed": null
130
+ }
131
+ ],
132
+ "__typename": "OrderItem",
133
+ "_createdAt": "2022-12-15T21:52:27.008Z",
134
+ "_updatedAt": "2022-12-29T16:19:27.700Z",
135
+ "_id": "63ade225dd19604ca368eb2b",
136
+ "color": "",
137
+ "url": "",
138
+ "hasInventory": false,
139
+ "inventoryType": "push",
140
+ "priceLevels": [
141
+ {
142
+ "__typename": "ItemPrice",
143
+ "value": 9.5,
144
+ "tags": [
145
+ "default"
146
+ ]
147
+ },
148
+ {
149
+ "__typename": "ItemPrice",
150
+ "value": 9.5,
151
+ "tags": [
152
+ "press only"
153
+ ]
154
+ }
155
+ ],
156
+ "costLevels": [],
157
+ "itemId": "639b971643d8c80013527071",
158
+ "properties": false
159
+ },
160
+ {
161
+ "location": {},
162
+ "status": {
163
+ "picked": {
164
+ "value": false,
165
+ "date": ""
166
+ },
167
+ "paid": {
168
+ "value": false,
169
+ "date": ""
170
+ },
171
+ "tracker": []
172
+ },
173
+ "name": "M-L 3pc Suit",
174
+ "description": null,
175
+ "pieces": 3,
176
+ "modifiersTotalAmount": 0,
177
+ "total": 1.82,
178
+ "totalPaid": 0,
179
+ "price": 14,
180
+ "quantity": 1,
181
+ "path": [
182
+ "menuCategories",
183
+ 0
184
+ ],
185
+ "notes": [],
186
+ "menuId": "639b97178e5c8c0019c58e64",
187
+ "serial": null,
188
+ "sku": null,
189
+ "modifiers": [
190
+ {
191
+ "__typename": "Modifier",
192
+ "addModifiers": [],
193
+ "delModifiers": [],
194
+ "conditions": null,
195
+ "compute": null,
196
+ "_createdAt": "2022-12-15T21:52:27.541Z",
197
+ "_updatedAt": "2022-12-15T21:52:27.541Z",
198
+ "_id": "63ade222dd19604ca368eb28",
199
+ "modifierId": "639b971643d8c80013526fea",
200
+ "_parentId": null,
201
+ "locked": false,
202
+ "name": "Dry Cleaning",
203
+ "sku": "",
204
+ "description": "",
205
+ "group": "",
206
+ "type": null,
207
+ "attributes": [
208
+ "department"
209
+ ],
210
+ "color": "",
211
+ "backgroundColor": null,
212
+ "icon": null,
213
+ "url": "",
214
+ "tags": null,
215
+ "order": 1,
216
+ "included": false,
217
+ "direct": true,
218
+ "hidden": true,
219
+ "print": false,
220
+ "required": true,
221
+ "recommended": false,
222
+ "default": false,
223
+ "code": "D",
224
+ "properties": {
225
+ "department": {
226
+ "tagSize": "Small",
227
+ "customerTagsExtend": null,
228
+ "maxItems": 4
229
+ }
230
+ },
231
+ "_computed": {
232
+ "amount": 0,
233
+ "description": "Dry Cleaning ($0.00)"
234
+ }
235
+ },
236
+ {
237
+ "name": "Customer stored credit",
238
+ "sku": "",
239
+ "description": "",
240
+ "group": "",
241
+ "type": "credit",
242
+ "attributes": [],
243
+ "color": "",
244
+ "backgroundColor": "",
245
+ "icon": "",
246
+ "url": "",
247
+ "code": "",
248
+ "tags": [],
249
+ "order": 0,
250
+ "included": false,
251
+ "direct": false,
252
+ "hidden": false,
253
+ "required": false,
254
+ "print": true,
255
+ "delModifiers": [],
256
+ "addModifiers": [],
257
+ "conditions": null,
258
+ "compute": {
259
+ "type": "fixed",
260
+ "amount": 12.18,
261
+ "action": "subtract"
262
+ },
263
+ "properties": {
264
+ "sort": 999,
265
+ "ignoreQuantity": true
266
+ },
267
+ "_id": "63ade222dd19604ca368eb29",
268
+ "modifierId": "63ade212dd19604ca368eb23",
269
+ "__typename": "Modifier",
270
+ "_parentId": "63ade212dd19604ca368eb23",
271
+ "_computed": {
272
+ "amount": -12.18,
273
+ "description": "Customer stored credit (-$12.18)"
274
+ }
275
+ }
276
+ ],
277
+ "__typename": "OrderItem",
278
+ "_createdAt": "2022-12-15T21:52:26.963Z",
279
+ "_updatedAt": "2022-12-29T16:19:27.722Z",
280
+ "_id": "63ade222dd19604ca368eb27",
281
+ "color": null,
282
+ "url": null,
283
+ "hasInventory": true,
284
+ "inventoryType": "push",
285
+ "priceLevels": [
286
+ {
287
+ "__typename": "ItemPrice",
288
+ "value": 14,
289
+ "tags": [
290
+ "default"
291
+ ]
292
+ },
293
+ {
294
+ "__typename": "ItemPrice",
295
+ "value": 11,
296
+ "tags": [
297
+ "press only"
298
+ ]
299
+ }
300
+ ],
301
+ "costLevels": [],
302
+ "itemId": "639b971643d8c8001352706f",
303
+ "properties": false,
304
+ "subTotals": {
305
+ "_included": 0,
306
+ "_xincluded": -12.18,
307
+ "_direct": 0,
308
+ "_xdirect": -12.18,
309
+ "_simple": 14,
310
+ "_actual": 14,
311
+ "credit": -12.18
312
+ }
313
+ },
314
+ {
315
+ "location": {},
316
+ "status": {
317
+ "picked": {
318
+ "value": false,
319
+ "date": ""
320
+ },
321
+ "paid": {
322
+ "value": false,
323
+ "date": ""
324
+ },
325
+ "tracker": []
326
+ },
327
+ "name": "M-L 2pc Suit",
328
+ "description": null,
329
+ "pieces": 2,
330
+ "modifiersTotalAmount": 0,
331
+ "total": 1.18,
332
+ "totalPaid": 0,
333
+ "price": 9,
334
+ "quantity": 1,
335
+ "path": [
336
+ "menuCategories",
337
+ 0
338
+ ],
339
+ "notes": [],
340
+ "menuId": "639b97178e5c8c0019c58e64",
341
+ "serial": null,
342
+ "sku": null,
343
+ "modifiers": [
344
+ {
345
+ "__typename": "Modifier",
346
+ "addModifiers": [],
347
+ "delModifiers": [],
348
+ "conditions": null,
349
+ "compute": null,
350
+ "_createdAt": "2022-12-15T21:52:27.541Z",
351
+ "_updatedAt": "2022-12-15T21:52:27.541Z",
352
+ "_id": "63ade216dd19604ca368eb25",
353
+ "modifierId": "639b971643d8c80013526fea",
354
+ "_parentId": null,
355
+ "locked": false,
356
+ "name": "Dry Cleaning",
357
+ "sku": "",
358
+ "description": "",
359
+ "group": "",
360
+ "type": null,
361
+ "attributes": [
362
+ "department"
363
+ ],
364
+ "color": "",
365
+ "backgroundColor": null,
366
+ "icon": null,
367
+ "url": "",
368
+ "tags": null,
369
+ "order": 1,
370
+ "included": false,
371
+ "direct": true,
372
+ "hidden": true,
373
+ "print": false,
374
+ "required": true,
375
+ "recommended": false,
376
+ "default": false,
377
+ "code": "D",
378
+ "properties": {
379
+ "department": {
380
+ "tagSize": "Small",
381
+ "customerTagsExtend": null,
382
+ "maxItems": 4
383
+ }
384
+ },
385
+ "_computed": {
386
+ "amount": 0,
387
+ "description": "Dry Cleaning ($0.00)"
388
+ }
389
+ },
390
+ {
391
+ "name": "Customer stored credit",
392
+ "sku": "",
393
+ "description": "",
394
+ "group": "",
395
+ "type": "credit",
396
+ "attributes": [],
397
+ "color": "",
398
+ "backgroundColor": "",
399
+ "icon": "",
400
+ "url": "",
401
+ "code": "",
402
+ "tags": [],
403
+ "order": 0,
404
+ "included": false,
405
+ "direct": false,
406
+ "hidden": false,
407
+ "required": false,
408
+ "print": true,
409
+ "delModifiers": [],
410
+ "addModifiers": [],
411
+ "conditions": null,
412
+ "compute": {
413
+ "type": "fixed",
414
+ "amount": 7.82,
415
+ "action": "subtract"
416
+ },
417
+ "properties": {
418
+ "sort": 999
419
+ },
420
+ "_id": "63ade222dd19604ca368eb2a",
421
+ "modifierId": "63ade212dd19604ca368eb23",
422
+ "__typename": "Modifier",
423
+ "_parentId": "63ade212dd19604ca368eb23",
424
+ "_computed": {
425
+ "amount": -7.82,
426
+ "description": "Customer stored credit (-$7.82)"
427
+ }
428
+ }
429
+ ],
430
+ "__typename": "OrderItem",
431
+ "_createdAt": "2022-12-15T21:52:26.964Z",
432
+ "_updatedAt": "2022-12-29T16:19:27.718Z",
433
+ "_id": "63ade216dd19604ca368eb24",
434
+ "color": null,
435
+ "url": "",
436
+ "hasInventory": true,
437
+ "inventoryType": "push",
438
+ "priceLevels": [
439
+ {
440
+ "__typename": "ItemPrice",
441
+ "value": 9,
442
+ "tags": [
443
+ "default"
444
+ ]
445
+ },
446
+ {
447
+ "__typename": "ItemPrice",
448
+ "value": 8,
449
+ "tags": [
450
+ "press only"
451
+ ]
452
+ }
453
+ ],
454
+ "costLevels": [],
455
+ "itemId": "639b971643d8c8001352706e",
456
+ "properties": false,
457
+ "subTotals": {
458
+ "_included": 0,
459
+ "_xincluded": -7.82,
460
+ "_direct": 0,
461
+ "_xdirect": -7.82,
462
+ "_simple": 9,
463
+ "_actual": 9,
464
+ "credit": -7.82
465
+ }
466
+ }
467
+ ],
468
+ "_storeId": "",
469
+ "__typename": "Order",
470
+ "subTotals": {
471
+ "credit": -20
472
+ },
473
+ "isOrderNew": true
474
+ }
@@ -9,6 +9,8 @@ const orderPartiallyPaid = require('../mocks/partially-paid/order-partially-paid
9
9
  const orderModifiersPartiallyPaid = require('../mocks/partially-paid/order-modifiers.json');
10
10
  const inputItemsPartiallyPaidOrder = require('../mocks/partially-paid/input-items.json');
11
11
 
12
+ const orderCredit = require('../mocks/order-credit.json');
13
+
12
14
  const session = {
13
15
  store: mockStores[0],
14
16
  };
@@ -244,6 +246,21 @@ describe('Order actions', () => {
244
246
  });
245
247
  });
246
248
 
249
+ test('CU-3und87h : Calculate order with 20 USD credit', () => {
250
+ const newOrder = pricingService.order.calculate(orderCredit);
251
+
252
+ const [item1, item2, item3] = newOrder.items;
253
+ expect(newOrder).toHaveProperty('total', 12.5);
254
+ expect(item1).toHaveProperty('total', 3.64);
255
+ expect(item1.modifiers[1].compute).toHaveProperty('amount', 5.86);
256
+
257
+ expect(item2).toHaveProperty('total', 5.39);
258
+ expect(item2.modifiers[1].compute).toHaveProperty('amount', 8.61);
259
+
260
+ expect(item3).toHaveProperty('total', 3.47);
261
+ expect(item3.modifiers[1].compute).toHaveProperty('amount', 5.53);
262
+ });
263
+
247
264
  test('Auto split a Parent Order', () => {
248
265
  const parentOrder = {
249
266
  _id: '6392069cb6c81965a442289d',
@@ -9,12 +9,22 @@ module.exports = ({ _, utils, constants, actions }) => {
9
9
  modifier,
10
10
  options = { orderTotal: 0, itemQuantity: 1, itemTotal: 0 }
11
11
  ) {
12
+ const maxAmount = actions.getProperty(modifier, 'maxAmount');
13
+
12
14
  const { compute = {} } = modifier;
13
15
  const { type, amount = 0 } = compute;
14
16
  let modifierAmount = amount;
15
17
 
16
- if (type === Modifier.Compute.Types.PERCENTAGE)
17
- modifierAmount = math.div(math.mul(options.orderTotal, amount), 100);
18
+ if (type === Modifier.Compute.Types.PERCENTAGE) {
19
+ const modifierAmountByPercentage = math.div(
20
+ math.mul(options.orderTotal, amount),
21
+ 100
22
+ );
23
+ modifierAmount =
24
+ maxAmount !== null && modifierAmountByPercentage > maxAmount
25
+ ? maxAmount
26
+ : modifierAmountByPercentage;
27
+ }
18
28
 
19
29
  let amountToApply = 0;
20
30
 
@@ -34,8 +44,7 @@ module.exports = ({ _, utils, constants, actions }) => {
34
44
  action: compute.action || Modifier.Compute.Actions.SUBTRACT,
35
45
  },
36
46
  });
37
- if (actions.getProperty(modifierToAdd, 'maxAmount') !== null)
38
- delete modifierToAdd.properties.maxAmount;
47
+ if (maxAmount !== null) delete modifierToAdd.properties.maxAmount;
39
48
 
40
49
  return modifierToAdd;
41
50
  };
@@ -52,6 +52,15 @@ module.exports = ({ utils, _, itemActions, modifierActions, settings }) => {
52
52
  displayId,
53
53
  discount: 0,
54
54
  tax: 0,
55
+ totalPaid: 0,
56
+ total: 0,
57
+ status: {
58
+ order: 'open',
59
+ delivery: order.status.delivery,
60
+ detailed: order.status.detailed,
61
+ fullyPaid: false,
62
+ fullyPicked: false,
63
+ },
55
64
  parentId: orderSettings.allowSuborder ? order._id : null,
56
65
  items,
57
66
  modifiers: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -36,5 +36,5 @@
36
36
  "supertest": "^6.2.3",
37
37
  "supervisor": "^0.12.0"
38
38
  },
39
- "gitHead": "b3d759af0bc62a04736bc65fbbf1a6132b669316"
39
+ "gitHead": "0c2f04eff1e46be98a83a5916ee312179ad7f62d"
40
40
  }