@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.
Files changed (65) hide show
  1. package/__TEST__/mocks/partially-paid/input-items.json +1 -0
  2. package/__TEST__/mocks/partially-paid/order-modifiers.json +53 -0
  3. package/__TEST__/mocks/partially-paid/order-partially-paid.json +890 -0
  4. package/__TEST__/mocks/scripts/calculate-partially-paid/index.js +27 -0
  5. package/__TEST__/mocks/scripts/calculate-unpaid/index.js +28 -0
  6. package/__TEST__/mocks/scripts/order-to-string.js +18 -0
  7. package/__TEST__/mocks/stores.js +435 -0
  8. package/__TEST__/mocks/unpaid/input-items.json +6 -0
  9. package/__TEST__/mocks/unpaid/order-modifiers.json +53 -0
  10. package/__TEST__/mocks/unpaid/order-not-paid.json +684 -0
  11. package/__TEST__/order/order.test.js +610 -0
  12. package/lib/item/addIndirectModifier.js +2 -3
  13. package/lib/item/calculate.js +1 -2
  14. package/lib/item/getBalance.js +9 -0
  15. package/lib/item/getItemModifiers.js +3 -14
  16. package/lib/item/getItems.js +5 -0
  17. package/lib/item/getTotal.js +1 -1
  18. package/lib/item/getTotalPrice.js +10 -0
  19. package/lib/item/getTotals.js +31 -18
  20. package/lib/item/index.js +12 -0
  21. package/lib/item/isFullyPaid.js +6 -0
  22. package/lib/item/markModifiersAsLocked.js +11 -0
  23. package/lib/item/removeModifier.js +10 -9
  24. package/lib/item/removePaymentModifiers.js +15 -0
  25. package/lib/modifier/create.js +2 -2
  26. package/lib/modifier/createAmountOverrideModifier.js +1 -3
  27. package/lib/modifier/createCreditModifier.js +2 -4
  28. package/lib/modifier/createDiscountModifier.js +1 -3
  29. package/lib/modifier/createIndirectModifier.js +1 -1
  30. package/lib/modifier/createPaymentModifier.js +12 -0
  31. package/lib/modifier/createSubscriptionModifier.js +1 -3
  32. package/lib/modifier/duplicate.js +1 -1
  33. package/lib/modifier/findById.js +4 -1
  34. package/lib/modifier/findByPaymentMethod.js +1 -1
  35. package/lib/modifier/findByPaymentType.js +1 -1
  36. package/lib/modifier/getItemModifiers.js +1 -3
  37. package/lib/modifier/getLockedModifiers.js +5 -0
  38. package/lib/modifier/getSplittedModifiers.js +4 -6
  39. package/lib/modifier/hasItems.js +8 -0
  40. package/lib/modifier/index.js +20 -4
  41. package/lib/modifier/isFixed.js +10 -0
  42. package/lib/modifier/isFixedDiscount.js +4 -0
  43. package/lib/modifier/isPaymentMethodModifier.js +8 -0
  44. package/lib/modifier/isPaymentModifier.js +7 -0
  45. package/lib/modifier/isPaymentTypeModifier.js +8 -0
  46. package/lib/modifier/isSubtract.js +10 -0
  47. package/lib/modifier/removeLocked.js +8 -0
  48. package/lib/order/addItem.js +104 -106
  49. package/lib/order/addItemModifier.js +0 -3
  50. package/lib/order/addModifier.js +14 -2
  51. package/lib/order/addModifiers.js +15 -0
  52. package/lib/order/autoSplit.js +34 -0
  53. package/lib/order/calculate.js +46 -68
  54. package/lib/order/getScheduleByCustomer.js +0 -1
  55. package/lib/order/index.js +10 -0
  56. package/lib/order/markModifiersAsLocked.js +14 -0
  57. package/lib/order/removeItem.js +0 -2
  58. package/lib/order/removeModifier.js +5 -1
  59. package/lib/order/removeModifiers.js +18 -0
  60. package/lib/order/splitByDepartments.js +1 -13
  61. package/lib/order/syncSubOrderItemsFromParent.js +24 -0
  62. package/package.json +3 -2
  63. package/__TEST__/order.test.js +0 -233
  64. package/lib/modifier/isPaymentMethods.js +0 -8
  65. package/lib/modifier/isPaymentTypes.js +0 -8
@@ -0,0 +1,27 @@
1
+ const usePricing = require('../../../../index');
2
+
3
+ const orderToStr = require('../order-to-string');
4
+
5
+ const orderPartiallyPaid = require('../../partially-paid/order-partially-paid.json');
6
+ const orderModifiers = require('../../partially-paid/order-modifiers.json');
7
+ const inputItems = require('../../partially-paid/input-items.json');
8
+
9
+ const pricingService = usePricing();
10
+
11
+ const paymentModifiers = orderModifiers.map(orderMod =>
12
+ pricingService.modifier.createPaymentModifier({
13
+ modifier: orderMod,
14
+ items: inputItems,
15
+ })
16
+ );
17
+
18
+ let order = { ...orderPartiallyPaid };
19
+
20
+ order = pricingService.order.addModifiers({
21
+ modifiers: paymentModifiers,
22
+ order,
23
+ });
24
+
25
+ const resultedOrder = pricingService.order.calculate(order);
26
+
27
+ orderToStr(resultedOrder);
@@ -0,0 +1,28 @@
1
+ const usePricing = require('../../../../index');
2
+
3
+ const orderToStr = require('../order-to-string');
4
+
5
+ const orderUnpaid = require('../../unpaid/order-not-paid.json');
6
+ const orderModifiers = require('../../unpaid/order-modifiers.json');
7
+ const inputItems = require('../../unpaid/input-items.json');
8
+
9
+ const pricingService = usePricing();
10
+
11
+ const paymentModifiers = orderModifiers.map(orderMod =>
12
+ pricingService.modifier.createPaymentModifier({
13
+ modifier: orderMod,
14
+ items: inputItems,
15
+ })
16
+ );
17
+
18
+ let order = { ...orderUnpaid };
19
+
20
+ if (paymentModifiers.length > 0)
21
+ order = pricingService.order.addModifiers({
22
+ modifiers: paymentModifiers,
23
+ order,
24
+ });
25
+
26
+ const resultedOrder = pricingService.order.calculate(order);
27
+
28
+ orderToStr(resultedOrder);
@@ -0,0 +1,18 @@
1
+ module.exports = function orderToString(order) {
2
+ const { total, totalPaid, items } = order;
3
+
4
+ console.log({ total, totalPaid });
5
+ items.map(item => {
6
+ console.log('****');
7
+ console.log({
8
+ name: item.name,
9
+ price: item.price,
10
+ total: item.total,
11
+ totalPaid: item.totalPaid,
12
+ subtotals: item.subTotals,
13
+ });
14
+ item.modifiers.map(mod => {
15
+ console.log('modifier _computed', mod._computed);
16
+ });
17
+ });
18
+ };
@@ -0,0 +1,435 @@
1
+ module.exports = [
2
+ {
3
+ _id: 1,
4
+ name: 'Store #1',
5
+ _settings: {
6
+ version: 1,
7
+ _locked: ['_locked', 'version'],
8
+ message: {
9
+ number: '+14703224772',
10
+ email: 'support@mail.darkpos.io',
11
+ },
12
+ notification: {
13
+ blacklist: {
14
+ sms: ['989126368711', '989122797384', '11111'],
15
+ email: ['nabil@darkpos.com', 'marjan@darkpos.com'],
16
+ },
17
+ methods: {
18
+ sms: {
19
+ config: {
20
+ from: '+14703224772',
21
+ userId: 'u-chyznmhvk2atp7maydzxdtq',
22
+ apiToken: 't-ki5lp5yzvtjpik5q5v3rpfi',
23
+ apiSecret: '7mhybvragwlqk5cj52vulc3iyx74aqe4gfndmhi',
24
+ script: 'bandwidth',
25
+ },
26
+ },
27
+ sms1: {
28
+ config: {
29
+ region: 'us-east-1',
30
+ secretAccessKey: 'XXXXXXXXX',
31
+ accessKeyId: 'XXXXXXX',
32
+ script: 'aws',
33
+ },
34
+ },
35
+ email: {
36
+ config: {
37
+ domain: 'mail.darkpos.io',
38
+ apiKey: 'key-770c869441dfd9ae8c23fd52c1843fca',
39
+ script: 'mailgun',
40
+ },
41
+ },
42
+ },
43
+ },
44
+ payment: {
45
+ methods: {
46
+ cash: {
47
+ label: 'Cash',
48
+ type: 'cash',
49
+ },
50
+ check: {
51
+ label: 'Check',
52
+ type: 'check',
53
+ },
54
+ 'bank-transfer': {
55
+ label: 'Bank Transfer',
56
+ type: 'bank-transfer',
57
+ },
58
+ 'credit-card': {
59
+ label: 'Credit Card Manual',
60
+ type: 'credit-card',
61
+ },
62
+ 'credit-card-ppec': {
63
+ label: 'Credit Card (PPEC)',
64
+ type: 'credit-card',
65
+ config: {
66
+ publishableKey: 'pk_test_Luwi4BLEwuEVwd4GoKa7iAac',
67
+ script: 'stripe',
68
+ currency: 'usd',
69
+ apiKey: 'sk_test_a7NUqKXZU5zEdv5tK5r3qq1f',
70
+ method: 'stripe',
71
+ type: 'script',
72
+ },
73
+ },
74
+ 'credit-card-mxm': {
75
+ label: 'Credit Card MXM',
76
+ type: 'credit-card',
77
+ config: {
78
+ script: 'mxmerchant',
79
+ merchantId: '282060674',
80
+ consumerKey: 'CvhdZl5CxNW1CPhuyZQWDgiG',
81
+ consumerSecret: '0aGwqTT2XmUVuQ5THyh4inrpC+0=',
82
+ serviceUrl: 'https://sandbox.api.mxmerchant.com/checkout/v3/',
83
+ type: 'script',
84
+ method: 'mxmerchant',
85
+ },
86
+ },
87
+ 'credit-card-bluepay': {
88
+ label: 'Credit Card Blue Pay',
89
+ type: 'credit-card',
90
+ config: {
91
+ type: 'script',
92
+ method: 'bluepay',
93
+ accountId: '100463947973',
94
+ secretKey: 'T3N3UPJRGLK0APLP6RXTODX8UX4YU.BZ',
95
+ script: 'bluepay',
96
+ apiAccountId: '5a03e6bb5b284ed5b2ce6785a2f1c760',
97
+ apiSecretKey: '5a03e6bb5b284ed5b2ce6785a2f1c760',
98
+ mode: 'TEST',
99
+ darkApiUrl: 'https://api-dev.darkpos.io',
100
+ darkApiSecretKey: 'Q0UyQUJEMTJFOTJFNEJDQThGNDQzNkY2MjYzN0ZEQzc=',
101
+ },
102
+ },
103
+ 'credit-card-square': {
104
+ label: 'Credit Card Square',
105
+ type: 'credit-card',
106
+ config: {
107
+ type: 'script',
108
+ method: 'square',
109
+ currency: 'USD',
110
+ location: 'BXNVBAX7CEC79',
111
+ account: '2821a140-8875-430e-8cb7-fd67913c8ca0',
112
+ stripe: 'square',
113
+ mode: 'LIVE',
114
+ applicationId: 'sq0idp-EJUDUzYbGvJNY5xFC5zPDw',
115
+ placeholders: {
116
+ number: 'Card Number (4532759734545858)',
117
+ cvv: 'CVC (258)',
118
+ expDate: 'Month/Year (01/20)',
119
+ zipCode: 'Zip Code (94103)',
120
+ },
121
+ },
122
+ },
123
+ 'creadit-card-elavon': {
124
+ label: 'Credit Card Elavon',
125
+ type: 'credit-card',
126
+ config: {
127
+ type: 'script',
128
+ method: 'elavon',
129
+ merchantId: '008099',
130
+ userId: 'webpage',
131
+ pin: '1QG5UN',
132
+ },
133
+ },
134
+ 'credit-card-vantiv': {
135
+ label: 'Credit Card Vantiv',
136
+ type: 'credit-card',
137
+ config: {
138
+ type: 'terminal',
139
+ method: 'vantiv',
140
+ applicationId: '8235',
141
+ acceptorId: '3928907',
142
+ accountId: '1044125',
143
+ token:
144
+ 'B8407759ECBA126AAC5AADAB76C3B426A546FFC7D7C89BB51047C52B995DDC682D9F2C01',
145
+ },
146
+ },
147
+ 'credit-card-datacap': {
148
+ label: 'Credit Card DataCap',
149
+ type: 'credit-card',
150
+ config: {
151
+ type: 'terminal',
152
+ method: 'datacap',
153
+ merchantId: '100463947973',
154
+ tranDeviceId: 'PT7205282705',
155
+ accountId: 'DarkPOSTest',
156
+ authCode: 'VfPYvD9HLWJjrWdgEYARaZqh',
157
+ testMode: 'true',
158
+ },
159
+ },
160
+ gift: {
161
+ label: 'Gift',
162
+ type: 'gift',
163
+ },
164
+ 'stored-credit': {
165
+ label: 'storedCredit',
166
+ type: 'credit',
167
+ },
168
+ },
169
+ currency: '$',
170
+ coins: [0.01, 0.05, 0.1, 0.25, 0.5, 1],
171
+ notes: [1, 5, 10, 20, 50, 100],
172
+ gratuities: [5, 10],
173
+ },
174
+ loyalty: {
175
+ methods: {
176
+ nexus: {
177
+ config: {
178
+ type: 'nexus',
179
+ grant_type: 'password',
180
+ merchant_id: '207',
181
+ username: 'enlite_api',
182
+ password: 'enlite%1378#',
183
+ POSStoreID: 'S1',
184
+ POSUserID: 'E123',
185
+ domain: 'enlite',
186
+ },
187
+ lookupField: 'emails',
188
+ refresh: 86400,
189
+ },
190
+ },
191
+ },
192
+ types: {
193
+ 'modifier-groups': ['Size', 'Extra', 'No', 'Sauces', 'Taxes', 'Toast'],
194
+ orders: ['walk-in', 'dine-in', 'to-go', 'delivery'],
195
+ templates: ['receipt', 'kitchen'],
196
+ payments: ['cash', 'check', 'credit-card', 'bank-transfer'],
197
+ loyalty: ['nexus'],
198
+ automation: {
199
+ schedules: {
200
+ daily: 'Daily',
201
+ weekly: 'Weekly',
202
+ monthly: 'Monthly',
203
+ },
204
+ entities: ['order'],
205
+ trigger: {
206
+ pre: 'Before',
207
+ post: 'After',
208
+ },
209
+ actions: ['create', 'update', 'remove', 'find'],
210
+ events: {
211
+ message: 'Send a Message',
212
+ print: 'Send to Print',
213
+ },
214
+ },
215
+ tags: [
216
+ 'vip',
217
+ 'default',
218
+ 'formal',
219
+ 'dummy-customer',
220
+ 'test',
221
+ 'all',
222
+ 'test3',
223
+ 'tteesstt',
224
+ 'test4',
225
+ 'normal',
226
+ 'ok',
227
+ 'samim',
228
+ 'sdf',
229
+ 'defaults',
230
+ ],
231
+ notes: [
232
+ {
233
+ id: 1,
234
+ value: 'coffee',
235
+ },
236
+ ],
237
+ defaultType: 'dineIn',
238
+ modifierGroups: [
239
+ 'test4',
240
+ 'TestGroup',
241
+ "Naeem's Group",
242
+ 'grouptest',
243
+ 'naa',
244
+ 'samim',
245
+ 'ast',
246
+ 'Add',
247
+ ],
248
+ },
249
+ hooks: {
250
+ order: {
251
+ type: 'post',
252
+ method: 'create',
253
+ events: [
254
+ 'notify',
255
+ 'print',
256
+ 'export',
257
+ {
258
+ config: {
259
+ template: 'receipt',
260
+ },
261
+ name: 'receipt-sms',
262
+ },
263
+ {
264
+ config: {
265
+ printer: 'receipt',
266
+ template: 'receipt',
267
+ },
268
+ name: 'receipt-print',
269
+ },
270
+ {
271
+ config: {
272
+ template: 'receipt',
273
+ },
274
+ name: 'receipt-email',
275
+ },
276
+ ],
277
+ },
278
+ },
279
+ theme: {
280
+ delite: {
281
+ type: 'dark',
282
+ selected: 'true',
283
+ },
284
+ 'delite-red': {
285
+ type: 'light',
286
+ },
287
+ },
288
+ security: {
289
+ pin: {
290
+ type: 'numeric',
291
+ length: 3,
292
+ complexity: 'simple',
293
+ },
294
+ },
295
+ features: {
296
+ tables: {
297
+ name: 'tables',
298
+ label: 'Tables',
299
+ icon: 'table',
300
+ shortcut: false,
301
+ },
302
+ reservations: {
303
+ name: 'reservations',
304
+ label: 'Reservations',
305
+ icon: 'table',
306
+ shortcut: false,
307
+ },
308
+ schedules: {
309
+ name: 'schedules',
310
+ label: 'Schedules',
311
+ icon: 'table',
312
+ shortcut: true,
313
+ },
314
+ orders: [
315
+ {
316
+ name: 'walk-in',
317
+ label: 'Walk In',
318
+ icon: 'store',
319
+ shortcut: true,
320
+ },
321
+ {
322
+ name: 'dine-in',
323
+ label: 'Dine In',
324
+ icon: 'event_seat',
325
+ shortcut: true,
326
+ },
327
+ {
328
+ name: 'to-go',
329
+ label: 'To Go',
330
+ icon: 'shopping_basket',
331
+ shortcut: true,
332
+ },
333
+ {
334
+ name: 'delivery',
335
+ label: 'Delivery',
336
+ icon: 'drive_eta',
337
+ shortcut: false,
338
+ },
339
+ ],
340
+ },
341
+ data: {
342
+ 'display-ids': {
343
+ orders: {
344
+ type: 'numeric',
345
+ length: 3,
346
+ lastValue: 839,
347
+ },
348
+ order: {
349
+ type: 'numeric',
350
+ length: '',
351
+ },
352
+ customer: {
353
+ type: 'numeric',
354
+ length: '',
355
+ },
356
+ invoice: {
357
+ type: 'numeric',
358
+ length: '',
359
+ },
360
+ user: {
361
+ type: 'numeric',
362
+ length: '',
363
+ },
364
+ },
365
+ preload: {
366
+ customer: true,
367
+ item: true,
368
+ category: true,
369
+ modifier: true,
370
+ rawMenu: true,
371
+ table: true,
372
+ area: true,
373
+ },
374
+ },
375
+ general: {
376
+ name: 'store name',
377
+ address: 'store address',
378
+ phone: 'store phone #',
379
+ web: 'store web address',
380
+ email: 'support@mail.darkpos.io',
381
+ notes: 'store notes',
382
+ banner:
383
+ 'https://images.unsplash.com/photo-1536506591919-966afe6f7c09?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&h=400&fit=crop&ixid=eyJhcHBfaWQiOjF9&s=8cf33a0acf87d4348fd1ab14e13fa488',
384
+ logo: 'https://images.unsplash.com/photo-1536506591919-966afe6f7c09?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=400&h=400&fit=crop&ixid=eyJhcHBfaWQiOjF9&s=8cf33a0acf87d4348fd1ab14e13fa488',
385
+ receiptMessage: 'Thanks for buying',
386
+ background:
387
+ 'https://images.unsplash.com/photo-1533137138-ba67dc90d752?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max&ixid=eyJhcHBfaWQiOjF9',
388
+ },
389
+ slack: {
390
+ accessToken:
391
+ 'xoxp-251861074629-425343643221-445864104630-940ef57c8162fded89f88c91eb838ce8',
392
+ botAccessToken:
393
+ 'xoxb-251861074629-436722880101-57QMYYIzG3uMuD5hooGlaAyn',
394
+ botUserId: 'UCUM8RW2Z',
395
+ teamId: 'T7DRB26JH',
396
+ teamName: 'DarkPOS',
397
+ },
398
+ order: {
399
+ allowSuborder: true,
400
+ orderAddToTop: true,
401
+ modifiersHaveColumn: true,
402
+ modifiersHaveColumns: false,
403
+ aggregateItems: true,
404
+ hideBreadcrumbs: false,
405
+ modifierCollapsedDisplay: true,
406
+ itemDetailDisplay: true,
407
+ },
408
+ url: '',
409
+ localization: {
410
+ language: 'en-US',
411
+ currency: 'USD',
412
+ phoneFormat: 'INTERNATIONAL',
413
+ timezone: null,
414
+ defaultCountry: {
415
+ label: 'United States',
416
+ value: 'US',
417
+ },
418
+ },
419
+ defaultTypes: {
420
+ toGo: true,
421
+ walkIn: false,
422
+ dineIn: true,
423
+ },
424
+ forms: {
425
+ required: {
426
+ categorySchema: ['name'],
427
+ itemSchema: ['name', 'price'],
428
+ modifierSchema: ['name'],
429
+ customerSchema: ['firstName', 'lastName'],
430
+ creditCardSchema: ['number', 'cvv', 'expDate', 'zipCode'],
431
+ },
432
+ },
433
+ },
434
+ },
435
+ ];
@@ -0,0 +1,6 @@
1
+ [
2
+ "638f7df903b4c49d135cf33e",
3
+ "638f7dfb03b4c49d135cf344",
4
+ "638f7dfa03b4c49d135cf342",
5
+ "638f7dfa03b4c49d135cf340"
6
+ ]
@@ -0,0 +1,53 @@
1
+ [
2
+ {
3
+ "__typename": "Modifier",
4
+ "addModifiers": [],
5
+ "delModifiers": [],
6
+ "conditions": {
7
+ "__typename": "Conditions",
8
+ "paymentTypes": [
9
+ "cash"
10
+ ],
11
+ "paymentMethods": [],
12
+ "modifiers": [],
13
+ "minItemQuantity": 0,
14
+ "minItemPieces": 0
15
+ },
16
+ "compute": {
17
+ "__typename": "Compute",
18
+ "type": "fixed",
19
+ "action": "add",
20
+ "amount": 2
21
+ },
22
+ "_createdAt": "2022-11-08T16:09:49.227Z",
23
+ "_updatedAt": "2022-11-28T18:44:16.821Z",
24
+ "_id": "636a7f3ec19c040636f3da9a",
25
+ "modifierId": null,
26
+ "_parentId": null,
27
+ "locked": false,
28
+ "name": "Cash fee",
29
+ "sku": "",
30
+ "description": "",
31
+ "group": "",
32
+ "type": "fee",
33
+ "attributes": [],
34
+ "color": "",
35
+ "backgroundColor": "",
36
+ "icon": "",
37
+ "url": "",
38
+ "tags": [
39
+ "default"
40
+ ],
41
+ "order": 0,
42
+ "included": false,
43
+ "direct": true,
44
+ "hidden": false,
45
+ "print": true,
46
+ "required": false,
47
+ "recommended": false,
48
+ "default": false,
49
+ "code": "",
50
+ "properties": null,
51
+ "_computed": null
52
+ }
53
+ ]