@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
@@ -1,233 +0,0 @@
1
- const usePricing = require('../index');
2
-
3
- const pricingService = usePricing();
4
-
5
- describe('Order actions', () => {
6
- test('Get calculated Order, one item', () => {
7
- const modifiers = [
8
- {
9
- compute: {
10
- amount: 20,
11
- type: 'percentage',
12
- action: 'add',
13
- },
14
- name: 'modifier1',
15
- type: 'discount',
16
- },
17
- {
18
- compute: {
19
- amount: 20,
20
- type: 'percentage',
21
- action: 'subtract',
22
- },
23
- name: 'modifier2',
24
- type: 'discount',
25
- },
26
- {
27
- compute: { amount: 2, type: 'fixed', action: 'subtract' },
28
- name: 'modifier3',
29
- type: 'discount',
30
- },
31
- ];
32
- const orderItem = { price: 30, quantity: 2, modifiers };
33
- const order = { items: [orderItem] };
34
- const newOrder = pricingService.order.calculate(order);
35
-
36
- expect(newOrder).toHaveProperty('total', 56);
37
- expect(newOrder).toHaveProperty('subTotal', 60);
38
- expect(newOrder).toHaveProperty('subTotals', {
39
- discount: -4,
40
- });
41
- });
42
- test('Get calculated Order, multiple items', () => {
43
- const item1 = {
44
- _id: 1,
45
- price: 30,
46
- quantity: 2,
47
- modifiers: [
48
- {
49
- compute: {
50
- amount: 2,
51
- type: 'fixed',
52
- action: 'subtract',
53
- },
54
- name: 'modifier1',
55
- type: 'discount',
56
- },
57
- ],
58
- };
59
- const item2 = {
60
- _id: 2,
61
- price: 10,
62
- quantity: 1,
63
- modifiers: [
64
- {
65
- compute: {
66
- amount: 2,
67
- type: 'fixed',
68
- action: 'subtract',
69
- },
70
- name: 'modifier1',
71
- type: 'discount',
72
- },
73
- ],
74
- };
75
- const order = { items: [item1, item2] };
76
- const newOrder = pricingService.order.calculate(order);
77
- expect(newOrder).toHaveProperty('total', 64);
78
- expect(newOrder).toHaveProperty('subTotal', 70);
79
- expect(newOrder).toHaveProperty('subTotals', {
80
- discount: -6,
81
- });
82
- // console.log(JSON.stringify(newOrder, 0, 2));
83
- });
84
- test('Get calculated Order, multiple items and indirect modifiers', () => {
85
- const item1 = {
86
- _id: 1,
87
- price: 30,
88
- quantity: 2,
89
- };
90
- const item2 = {
91
- _id: 2,
92
- price: 10,
93
- quantity: 1,
94
- };
95
- const modifier1 = {
96
- compute: {
97
- amount: 2,
98
- type: 'fixed',
99
- action: 'subtract',
100
- },
101
- name: 'modifier1',
102
- type: 'discount',
103
- };
104
-
105
- const order = { items: [item1, item2], modifiers: [modifier1] };
106
-
107
- const newOrder = pricingService.order.calculate(order);
108
- expect(newOrder).toHaveProperty('total', 68);
109
- expect(newOrder).toHaveProperty('subTotal', 70);
110
- expect(newOrder).toHaveProperty('subTotals', {
111
- discount: -2,
112
- });
113
- expect(newOrder.items[0]).toHaveProperty('total', 58.28);
114
- expect(newOrder.items[0]).toHaveProperty('subTotals', {
115
- discount: -1.72,
116
- _included: 0,
117
- _xincluded: -1.72,
118
- _direct: 0,
119
- _xdirect: -1.72,
120
- _simple: 60,
121
- _actual: 60,
122
- });
123
- expect(newOrder.items[1]).toHaveProperty('total', 9.72);
124
- expect(newOrder.items[1]).toHaveProperty('subTotals', {
125
- discount: -0.28,
126
- _included: 0,
127
- _xincluded: -0.28,
128
- _direct: 0,
129
- _xdirect: -0.28,
130
- _simple: 10,
131
- _actual: 10,
132
- });
133
- });
134
- test('Get calculated Order, multiple items and indirect modifiers #2', () => {
135
- const item1 = {
136
- _id: 1,
137
- price: 15.99,
138
- quantity: 1,
139
- };
140
- const item2 = {
141
- _id: 2,
142
- price: 4.65,
143
- quantity: 1,
144
- };
145
- const modifier1 = {
146
- compute: {
147
- amount: 10,
148
- action: 'subtract',
149
- type: 'percentage',
150
- },
151
- name: 'modifier1',
152
- type: 'discount',
153
- };
154
-
155
- const order = { items: [item1, item2], modifiers: [modifier1] };
156
- const newOrder = pricingService.order.calculate(order);
157
- expect(newOrder).toHaveProperty('total', 18.58);
158
- expect(newOrder).toHaveProperty('subTotal', 20.64);
159
- expect(newOrder).toHaveProperty('subTotals', {
160
- discount: -2.06,
161
- });
162
- expect(newOrder.items[0]).toHaveProperty('total', 14.39);
163
- expect(newOrder.items[0]).toHaveProperty('subTotals', {
164
- discount: -1.6,
165
- _included: 0,
166
- _xincluded: -1.6,
167
- _direct: 0,
168
- _xdirect: -1.6,
169
- _simple: 15.99,
170
- _actual: 15.99,
171
- });
172
- expect(newOrder.items[1]).toHaveProperty('total', 4.19);
173
- expect(newOrder.items[1]).toHaveProperty('subTotals', {
174
- discount: -0.46,
175
- _included: 0,
176
- _xincluded: -0.46,
177
- _direct: 0,
178
- _xdirect: -0.46,
179
- _simple: 4.65,
180
- _actual: 4.65,
181
- });
182
- });
183
- test('Get calculated Order, multiple items and indirect modifiers #3', () => {
184
- const item1 = {
185
- _id: 1,
186
- price: 3,
187
- quantity: 1,
188
- };
189
- const item2 = {
190
- _id: 2,
191
- price: 3,
192
- quantity: 1,
193
- };
194
- const item3 = {
195
- _id: 3,
196
- price: 4,
197
- quantity: 1,
198
- };
199
- const modifier1 = {
200
- _id: 1,
201
- compute: {
202
- amount: 10,
203
- type: 'percentage',
204
- action: 'subtract',
205
- },
206
- name: `10% Discount`,
207
- type: 'discount',
208
- };
209
-
210
- const modifier2 = {
211
- _id: 2,
212
- name: `20% tax`,
213
- type: 'tax',
214
- compute: {
215
- amount: 20,
216
- type: 'percentage',
217
- action: 'add',
218
- },
219
- };
220
-
221
- const order = {
222
- items: [item1, item2, item3],
223
- modifiers: [modifier1, modifier2],
224
- };
225
- const newOrder = pricingService.order.calculate(order);
226
- expect(newOrder).toHaveProperty('total', 11);
227
- expect(newOrder).toHaveProperty('subTotal', 10);
228
- expect(newOrder).toHaveProperty('subTotals', {
229
- discount: -1,
230
- tax: 2,
231
- });
232
- });
233
- });
@@ -1,8 +0,0 @@
1
- module.exports = () =>
2
- function isPaymentMethods(modifier) {
3
- return !!(
4
- modifier &&
5
- modifier.conditions &&
6
- (modifier.conditions.paymentMethods || []).length
7
- );
8
- };
@@ -1,8 +0,0 @@
1
- module.exports = () =>
2
- function isPaymentTypes(modifier) {
3
- return !!(
4
- modifier &&
5
- modifier.conditions &&
6
- (modifier.conditions.paymentTypes || []).length
7
- );
8
- };