@darkpos/pricing 1.0.90 → 1.0.92
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__/order/order.test.js +60 -6
- package/__TEST__/order/pickEndDate.test.js +124 -23
- package/lib/item/getTotalsDifference.js +7 -1
- package/lib/order/calculate.js +2 -7
- package/lib/order/index.js +0 -2
- package/lib/store/getScheduleByCustomer.js +25 -0
- package/lib/store/index.js +6 -4
- package/lib/store/pickEndDate.js +36 -7
- package/lib/store/pickEndDateByCustomer.js +5 -0
- package/package.json +2 -2
- package/lib/order/getScheduleByCustomer.js +0 -19
- package/lib/store/getRecommendedEndDate.js +0 -22
|
@@ -1960,7 +1960,7 @@ describe('Order actions', () => {
|
|
|
1960
1960
|
expect(newOrder).toHaveProperty('total', 710.36);
|
|
1961
1961
|
expect(newOrder).toHaveProperty('subTotal', 775.6);
|
|
1962
1962
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
1963
|
-
percentage: -116.
|
|
1963
|
+
percentage: -116.344,
|
|
1964
1964
|
tax: 51.09265,
|
|
1965
1965
|
});
|
|
1966
1966
|
expect(newOrder.items[0]).toHaveProperty('total', 65.85);
|
|
@@ -1971,7 +1971,7 @@ describe('Order actions', () => {
|
|
|
1971
1971
|
expect(newOrder.items[5]).toHaveProperty('total', 109.91);
|
|
1972
1972
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
1973
1973
|
'amount',
|
|
1974
|
-
-10.
|
|
1974
|
+
-10.789
|
|
1975
1975
|
);
|
|
1976
1976
|
expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
|
|
1977
1977
|
'amount',
|
|
@@ -2065,17 +2065,17 @@ describe('Order actions', () => {
|
|
|
2065
2065
|
|
|
2066
2066
|
const newOrder = pricingService.order.calculate(order);
|
|
2067
2067
|
|
|
2068
|
-
expect(newOrder).toHaveProperty('total', 137.
|
|
2068
|
+
expect(newOrder).toHaveProperty('total', 137.92);
|
|
2069
2069
|
expect(newOrder).toHaveProperty('subTotal', 128);
|
|
2070
2070
|
expect(newOrder).toHaveProperty('subTotals', {
|
|
2071
|
-
tax: 9.
|
|
2071
|
+
tax: 9.916,
|
|
2072
2072
|
});
|
|
2073
|
-
expect(newOrder.items[0]).toHaveProperty('total', 40.
|
|
2073
|
+
expect(newOrder.items[0]).toHaveProperty('total', 40.94);
|
|
2074
2074
|
expect(newOrder.items[1]).toHaveProperty('total', 45.26);
|
|
2075
2075
|
expect(newOrder.items[2]).toHaveProperty('total', 51.72);
|
|
2076
2076
|
expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
|
|
2077
2077
|
'amount',
|
|
2078
|
-
2.
|
|
2078
|
+
2.941
|
|
2079
2079
|
);
|
|
2080
2080
|
|
|
2081
2081
|
expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
|
|
@@ -3965,4 +3965,58 @@ describe('Order actions', () => {
|
|
|
3965
3965
|
expect(newOrder.items[0].total).toBe(25);
|
|
3966
3966
|
expect(newOrder.items[0].status).toMatchObject({});
|
|
3967
3967
|
});
|
|
3968
|
+
|
|
3969
|
+
test('Calculate order with 7% tax, expect correct decimals and rounding', () => {
|
|
3970
|
+
const taxModifier = {
|
|
3971
|
+
compute: {
|
|
3972
|
+
amount: 7,
|
|
3973
|
+
type: 'percentage',
|
|
3974
|
+
action: 'add',
|
|
3975
|
+
},
|
|
3976
|
+
name: 'tax 7%',
|
|
3977
|
+
type: 'tax',
|
|
3978
|
+
};
|
|
3979
|
+
|
|
3980
|
+
const orderItem1 = {
|
|
3981
|
+
price: 4.5,
|
|
3982
|
+
quantity: 1,
|
|
3983
|
+
modifiers: [taxModifier],
|
|
3984
|
+
};
|
|
3985
|
+
const orderItem2 = {
|
|
3986
|
+
price: 4.25,
|
|
3987
|
+
quantity: 1,
|
|
3988
|
+
modifiers: [taxModifier],
|
|
3989
|
+
};
|
|
3990
|
+
const orderItem3 = {
|
|
3991
|
+
price: 6.95,
|
|
3992
|
+
quantity: 1,
|
|
3993
|
+
modifiers: [taxModifier],
|
|
3994
|
+
};
|
|
3995
|
+
const order = { items: [orderItem1, orderItem2, orderItem3] };
|
|
3996
|
+
const newOrder = pricingService.order.calculate(order);
|
|
3997
|
+
|
|
3998
|
+
expect(newOrder).toHaveProperty('total', 16.8);
|
|
3999
|
+
expect(newOrder).toHaveProperty('subTotal', 15.7);
|
|
4000
|
+
expect(newOrder).toHaveProperty('subTotals', {
|
|
4001
|
+
tax: 1.095,
|
|
4002
|
+
});
|
|
4003
|
+
|
|
4004
|
+
expect(newOrder.items[0].modifiers[0]._computed.amount).toEqual(0.311);
|
|
4005
|
+
expect(newOrder.items[0].modifiers[0]._computed.description).toEqual(
|
|
4006
|
+
'tax 7% ($0.31)'
|
|
4007
|
+
);
|
|
4008
|
+
expect(newOrder.items[0].total).toEqual(4.81);
|
|
4009
|
+
|
|
4010
|
+
expect(newOrder.items[1].modifiers[0]._computed.amount).toEqual(0.2975);
|
|
4011
|
+
expect(newOrder.items[1].modifiers[0]._computed.description).toEqual(
|
|
4012
|
+
'tax 7% ($0.30)'
|
|
4013
|
+
);
|
|
4014
|
+
expect(newOrder.items[1].total).toEqual(4.55);
|
|
4015
|
+
|
|
4016
|
+
expect(newOrder.items[2].modifiers[0]._computed.amount).toEqual(0.4865);
|
|
4017
|
+
expect(newOrder.items[2].modifiers[0]._computed.description).toEqual(
|
|
4018
|
+
'tax 7% ($0.49)'
|
|
4019
|
+
);
|
|
4020
|
+
expect(newOrder.items[2].total).toEqual(7.44);
|
|
4021
|
+
});
|
|
3968
4022
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const moment = require('moment-timezone');
|
|
2
2
|
const usePricing = require('../../lib/index');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const getDefaultSettings = schedules => ({
|
|
5
5
|
store: {
|
|
6
6
|
_settings: {
|
|
7
7
|
schedule: {
|
|
@@ -11,6 +11,20 @@ const pricingService = usePricing({
|
|
|
11
11
|
},
|
|
12
12
|
],
|
|
13
13
|
},
|
|
14
|
+
order: {
|
|
15
|
+
schedules: schedules || [
|
|
16
|
+
{
|
|
17
|
+
_id: '682373ef8256034ae1f2c195',
|
|
18
|
+
dayOfWeek: [2],
|
|
19
|
+
recommended: 'auto_recommended',
|
|
20
|
+
addDays: 1,
|
|
21
|
+
cutDay: 1,
|
|
22
|
+
skipDays: undefined,
|
|
23
|
+
readyHour: null,
|
|
24
|
+
cutHour: null,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
14
28
|
},
|
|
15
29
|
},
|
|
16
30
|
});
|
|
@@ -24,64 +38,68 @@ describe('pickEndDate function', () => {
|
|
|
24
38
|
readyHour: { hour: 17, minute: 0 },
|
|
25
39
|
cutDay: 2,
|
|
26
40
|
};
|
|
41
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
27
42
|
|
|
28
43
|
const now = moment('2024-08-25T15:00:00Z').tz('America/New_York');
|
|
29
44
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
30
45
|
|
|
31
|
-
const result =
|
|
46
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
32
47
|
|
|
33
|
-
expect(result).toBe('2024-08-26T21:00:00Z');
|
|
48
|
+
expect(result).toBe('2024-08-26T21:00:00Z');
|
|
34
49
|
});
|
|
35
50
|
|
|
36
51
|
test('Order falls on a closed day', () => {
|
|
37
52
|
const schedule = {
|
|
38
53
|
addDays: 1,
|
|
39
54
|
readyHour: { hour: 14, minute: 0 },
|
|
40
|
-
skipDays: [7],
|
|
55
|
+
skipDays: [7],
|
|
41
56
|
cutHour: { hour: 16, minute: 0 },
|
|
42
57
|
cutDay: 2,
|
|
43
58
|
};
|
|
44
59
|
|
|
45
|
-
const now = moment('2024-08-27T15:00:00Z').tz('America/New_York');
|
|
60
|
+
const now = moment('2024-08-27T15:00:00Z').tz('America/New_York');
|
|
46
61
|
|
|
47
62
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
48
|
-
const
|
|
63
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
64
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
49
65
|
|
|
50
|
-
expect(result).toBe('2024-08-28T18:00:00Z');
|
|
66
|
+
expect(result).toBe('2024-08-28T18:00:00Z');
|
|
51
67
|
});
|
|
52
68
|
|
|
53
69
|
test('Get endDate if today is friday and Saturday and Sunday are skip days', () => {
|
|
54
70
|
const schedule = {
|
|
55
71
|
addDays: 1,
|
|
56
72
|
readyHour: { hour: 17, minute: 0 },
|
|
57
|
-
skipDays: [6, 7],
|
|
73
|
+
skipDays: [6, 7],
|
|
58
74
|
cutHour: { hour: 16, minute: 0 },
|
|
59
75
|
cutDay: 5,
|
|
60
76
|
};
|
|
61
77
|
|
|
62
|
-
const now = moment('2024-08-23T15:00:00Z').tz('America/New_York');
|
|
78
|
+
const now = moment('2024-08-23T15:00:00Z').tz('America/New_York');
|
|
63
79
|
|
|
64
80
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
65
|
-
const
|
|
81
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
82
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
66
83
|
|
|
67
|
-
expect(result).toBe('2024-08-26T21:00:00Z');
|
|
84
|
+
expect(result).toBe('2024-08-26T21:00:00Z');
|
|
68
85
|
});
|
|
69
86
|
|
|
70
87
|
test('Order time before cut-off hour', () => {
|
|
71
88
|
const schedule = {
|
|
72
|
-
addDays: 0,
|
|
89
|
+
addDays: 0,
|
|
73
90
|
readyHour: { hour: 17, minute: 0 },
|
|
74
91
|
skipDays: [],
|
|
75
|
-
cutHour: { hour: 16, minute: 0 },
|
|
92
|
+
cutHour: { hour: 16, minute: 0 },
|
|
76
93
|
cutDay: 5,
|
|
77
94
|
};
|
|
78
95
|
|
|
79
|
-
const now = moment('2024-08-25T15:00:00Z').tz('America/New_York');
|
|
96
|
+
const now = moment('2024-08-25T15:00:00Z').tz('America/New_York');
|
|
80
97
|
|
|
81
98
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
82
|
-
const
|
|
99
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
100
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
83
101
|
|
|
84
|
-
expect(result).toBe('2024-08-25T21:00:00Z');
|
|
102
|
+
expect(result).toBe('2024-08-25T21:00:00Z');
|
|
85
103
|
});
|
|
86
104
|
|
|
87
105
|
test('Order time after cut-off hour', () => {
|
|
@@ -97,12 +115,13 @@ describe('pickEndDate function', () => {
|
|
|
97
115
|
recommended: 'nothing_recommended',
|
|
98
116
|
};
|
|
99
117
|
|
|
100
|
-
const now = moment().tz('America/New_York');
|
|
118
|
+
const now = moment().tz('America/New_York');
|
|
101
119
|
|
|
102
120
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
103
|
-
const
|
|
121
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
122
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
104
123
|
|
|
105
|
-
expect(result).toBe('2024-08-31T21:00:00Z');
|
|
124
|
+
expect(result).toBe('2024-08-31T21:00:00Z');
|
|
106
125
|
});
|
|
107
126
|
|
|
108
127
|
test('Get EndDate, there are skip dates in between', () => {
|
|
@@ -117,9 +136,10 @@ describe('pickEndDate function', () => {
|
|
|
117
136
|
const now = moment('2024-08-25T15:00:00Z').tz('America/New_York');
|
|
118
137
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
119
138
|
|
|
120
|
-
const
|
|
139
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
140
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
121
141
|
|
|
122
|
-
expect(result).toBe('2024-08-26T21:00:00Z');
|
|
142
|
+
expect(result).toBe('2024-08-26T21:00:00Z');
|
|
123
143
|
});
|
|
124
144
|
|
|
125
145
|
test('Get EndDate, Now date is an skip day', () => {
|
|
@@ -134,8 +154,89 @@ describe('pickEndDate function', () => {
|
|
|
134
154
|
const now = moment('2024-09-01T15:00:00Z').tz('America/New_York');
|
|
135
155
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
136
156
|
|
|
137
|
-
const
|
|
157
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
158
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
159
|
+
|
|
160
|
+
expect(result).toBe('2024-09-05T00:00:00Z');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('Get EndDate, undefined skipdays', () => {
|
|
164
|
+
const schedule = {
|
|
165
|
+
addDays: 1,
|
|
166
|
+
readyHour: { hour: 20, minute: 0 },
|
|
167
|
+
cutHour: { hour: 16, minute: 0 },
|
|
168
|
+
cutDay: 1,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
|
|
172
|
+
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
173
|
+
|
|
174
|
+
const pricingServiceTest = usePricing(getDefaultSettings([schedule]));
|
|
175
|
+
const result = pricingServiceTest.store.pickEndDate();
|
|
176
|
+
|
|
177
|
+
expect(result).toBe('2025-05-15T00:00:00Z');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('pickEndDate, skipDays undefined', () => {
|
|
181
|
+
const pricingServiceSkipDays = usePricing(getDefaultSettings());
|
|
182
|
+
const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
|
|
183
|
+
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
184
|
+
|
|
185
|
+
const result = pricingServiceSkipDays.store.pickEndDate();
|
|
186
|
+
expect(result).toBe('2025-05-14T15:00:00Z');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('pickEndDate - getRecommendedEndDate, skipDays with dayOfWeek undefined', () => {
|
|
190
|
+
const pricingServiceSkipDays2 = usePricing({
|
|
191
|
+
store: {
|
|
192
|
+
_settings: {
|
|
193
|
+
order: {
|
|
194
|
+
endDate: {
|
|
195
|
+
readySchedule: [
|
|
196
|
+
{
|
|
197
|
+
_id: '682373ef8256034ae1f2c195',
|
|
198
|
+
dayOfWeek: null,
|
|
199
|
+
recommended: 'auto_recommended',
|
|
200
|
+
addDays: 1,
|
|
201
|
+
cutDay: 1,
|
|
202
|
+
skipDays: [1],
|
|
203
|
+
readyHour: null,
|
|
204
|
+
cutHour: null,
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
|
|
213
|
+
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
214
|
+
|
|
215
|
+
const result = pricingServiceSkipDays2.store.pickEndDate();
|
|
216
|
+
|
|
217
|
+
expect(result).toBe('2025-05-13T15:00:00Z');
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('pickEndDate - getRecommendedEndDate, skipDays with one day', () => {
|
|
221
|
+
const pricingServiceSkipDays3 = usePricing(
|
|
222
|
+
getDefaultSettings([
|
|
223
|
+
{
|
|
224
|
+
_id: '682373ef8256034ae1f2c195',
|
|
225
|
+
dayOfWeek: [2],
|
|
226
|
+
recommended: 'auto_recommended',
|
|
227
|
+
addDays: 1,
|
|
228
|
+
cutDay: 1,
|
|
229
|
+
skipDays: [1],
|
|
230
|
+
readyHour: null,
|
|
231
|
+
cutHour: null,
|
|
232
|
+
},
|
|
233
|
+
])
|
|
234
|
+
);
|
|
235
|
+
const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
|
|
236
|
+
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
237
|
+
|
|
238
|
+
const result = pricingServiceSkipDays3.store.pickEndDate();
|
|
138
239
|
|
|
139
|
-
expect(result).toBe('
|
|
240
|
+
expect(result).toBe('2025-05-14T15:00:00Z');
|
|
140
241
|
});
|
|
141
242
|
});
|
|
@@ -10,5 +10,11 @@ module.exports = ({ utils }) =>
|
|
|
10
10
|
}),
|
|
11
11
|
{ total: 0, subTotalsTotal: 0 }
|
|
12
12
|
);
|
|
13
|
-
|
|
13
|
+
const difference = utils.math.sub(subTotalsTotal, total);
|
|
14
|
+
|
|
15
|
+
if (difference < -0.005) return -0.004;
|
|
16
|
+
if (difference === -0.005) return 0.005;
|
|
17
|
+
if (difference > 0.005) return 0.004;
|
|
18
|
+
if (difference === 0.005) return -0.005;
|
|
19
|
+
return 0;
|
|
14
20
|
};
|
package/lib/order/calculate.js
CHANGED
|
@@ -114,16 +114,11 @@ module.exports = ({
|
|
|
114
114
|
);
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
-
|
|
118
117
|
if (calculatedItems.length > 0) {
|
|
119
|
-
|
|
118
|
+
const difference = itemActions.getTotalsDifference({
|
|
120
119
|
items: calculatedItems,
|
|
121
120
|
});
|
|
122
121
|
|
|
123
|
-
if (difference < 0) {
|
|
124
|
-
difference = difference < -0.005 ? 0 : utils.math.abs(difference);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
122
|
const itemIndex = calculatedItems.findIndex(
|
|
128
123
|
item =>
|
|
129
124
|
!itemActions.isFullyPaid(item) &&
|
|
@@ -134,7 +129,7 @@ module.exports = ({
|
|
|
134
129
|
)
|
|
135
130
|
);
|
|
136
131
|
|
|
137
|
-
if (itemIndex >= 0 && difference
|
|
132
|
+
if (itemIndex >= 0 && difference !== 0) {
|
|
138
133
|
calculatedItems[itemIndex] = itemActions.patchItem({
|
|
139
134
|
item: calculatedItems[itemIndex],
|
|
140
135
|
difference,
|
package/lib/order/index.js
CHANGED
|
@@ -69,7 +69,6 @@ const addModifierToAllItems = require('./addModifierToAllItems');
|
|
|
69
69
|
const getItemIndex = require('./getItemIndex');
|
|
70
70
|
const getRelatedItems = require('./getRelatedItems');
|
|
71
71
|
const getItemByItemId = require('./getItemByItemId');
|
|
72
|
-
const getScheduleByCustomer = require('./getScheduleByCustomer');
|
|
73
72
|
const getAppliedCredit = require('./getAppliedCredit');
|
|
74
73
|
const addCreditModifier = require('./addCreditModifier');
|
|
75
74
|
const adjustCreditModifiersDifference = require('./adjustCreditModifiersDifference');
|
|
@@ -174,7 +173,6 @@ const orderActions = (deps = {}) => {
|
|
|
174
173
|
addModifierToAllItems: addModifierToAllItems(innerDeps),
|
|
175
174
|
getItemIndex: getItemIndex(innerDeps),
|
|
176
175
|
getRelatedItems: getRelatedItems(innerDeps),
|
|
177
|
-
getScheduleByCustomer: getScheduleByCustomer(innerDeps),
|
|
178
176
|
getAppliedCredit: getAppliedCredit(innerDeps),
|
|
179
177
|
addCreditModifier: addCreditModifier(innerDeps),
|
|
180
178
|
adjustCreditModifiersDifference: adjustCreditModifiersDifference(innerDeps),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module.exports = ({ _, settings }) => {
|
|
2
|
+
const schedules = _.get(settings, 'order.schedules', []);
|
|
3
|
+
|
|
4
|
+
const filterCustomerTags = customer => {
|
|
5
|
+
const { tags } = customer || {};
|
|
6
|
+
if (!tags || !tags.length) return [];
|
|
7
|
+
return tags.filter(each => !['all', 'default'].includes(each));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return function getScheduleByCustomer(customer) {
|
|
11
|
+
const tags = filterCustomerTags(customer);
|
|
12
|
+
if (!tags || !tags.length) return schedules;
|
|
13
|
+
|
|
14
|
+
const scheduleTags = [
|
|
15
|
+
...new Set(schedules.reduce((a, c) => a.concat(...(c.tags || [])), [])),
|
|
16
|
+
];
|
|
17
|
+
if (!scheduleTags || !scheduleTags.length) return schedules;
|
|
18
|
+
|
|
19
|
+
const filteredSchedules = schedules.filter(schedule =>
|
|
20
|
+
tags.find(tag => (schedule.tags || []).includes(tag))
|
|
21
|
+
);
|
|
22
|
+
if (!filteredSchedules.length) return schedules;
|
|
23
|
+
return filteredSchedules;
|
|
24
|
+
};
|
|
25
|
+
};
|
package/lib/store/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
//
|
|
2
|
-
const
|
|
3
|
-
const getRecommendedEndDate = require('./getRecommendedEndDate');
|
|
2
|
+
const getScheduleByCustomer = require('./getScheduleByCustomer');
|
|
4
3
|
const isNeareastMultiple = require('./isNeareastMultiple');
|
|
4
|
+
const pickEndDate = require('./pickEndDate');
|
|
5
|
+
const pickEndDateByCustomer = require('./pickEndDateByCustomer');
|
|
5
6
|
|
|
6
7
|
const storeActions = (deps = {}) => {
|
|
7
8
|
const actions = {};
|
|
@@ -12,9 +13,10 @@ const storeActions = (deps = {}) => {
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
const freezedActions = Object.freeze({
|
|
15
|
-
|
|
16
|
-
getRecommendedEndDate: getRecommendedEndDate(innerDeps),
|
|
16
|
+
getScheduleByCustomer: getScheduleByCustomer(innerDeps),
|
|
17
17
|
isNeareastMultiple: isNeareastMultiple(innerDeps),
|
|
18
|
+
pickEndDate: pickEndDate(innerDeps),
|
|
19
|
+
pickEndDateByCustomer: pickEndDateByCustomer(innerDeps),
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
Object.keys(freezedActions).forEach(actionName => {
|
package/lib/store/pickEndDate.js
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
module.exports = ({ settings, _, moment }) => {
|
|
2
2
|
const timezone = _.get(settings, 'localization.timezone', 'America/New_York');
|
|
3
3
|
|
|
4
|
+
const getSchedule = (schedules, isoWeekday) => {
|
|
5
|
+
const todayTZ = moment().tz(timezone);
|
|
6
|
+
const day = isoWeekday || todayTZ.isoWeekday(); // monday 1 - sunday 7
|
|
7
|
+
const _schedules =
|
|
8
|
+
schedules && schedules.length
|
|
9
|
+
? schedules
|
|
10
|
+
: _.get(settings, 'order.schedules', []);
|
|
11
|
+
|
|
12
|
+
if (!_schedules.length) {
|
|
13
|
+
return {
|
|
14
|
+
todayTZ,
|
|
15
|
+
skipDays: [],
|
|
16
|
+
cutDay: 0,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const schedule = _schedules.find(item => {
|
|
21
|
+
const { dayOfWeek } = item || {};
|
|
22
|
+
if (!dayOfWeek || !dayOfWeek.length) return true;
|
|
23
|
+
return dayOfWeek.includes(day);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
...schedule,
|
|
28
|
+
todayTZ,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
4
32
|
const getClosedDays = () => {
|
|
5
33
|
const schedule = _.get(settings, 'schedule', {});
|
|
6
34
|
const { close = [] } = schedule;
|
|
@@ -10,16 +38,16 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
10
38
|
|
|
11
39
|
const MAX_ADD_DAYS = 365;
|
|
12
40
|
|
|
13
|
-
return function pickEndDate(
|
|
41
|
+
return function pickEndDate(schedules, isoWeekday) {
|
|
14
42
|
const {
|
|
15
43
|
addDays: addDaysParam,
|
|
16
44
|
readyHour,
|
|
17
|
-
skipDays = [],
|
|
18
45
|
cutHour,
|
|
19
|
-
cutDay
|
|
20
|
-
|
|
46
|
+
cutDay,
|
|
47
|
+
skipDays,
|
|
48
|
+
todayTZ,
|
|
49
|
+
} = getSchedule(schedules, isoWeekday);
|
|
21
50
|
|
|
22
|
-
const todayTZ = moment().tz(timezone);
|
|
23
51
|
let endDateTZ = todayTZ.clone();
|
|
24
52
|
const closedDays = getClosedDays();
|
|
25
53
|
const todayHours = todayTZ.get('hours');
|
|
@@ -45,8 +73,9 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
45
73
|
endDateTZ.set('second', 0);
|
|
46
74
|
|
|
47
75
|
const isSkipDay = endDateIsoWeekDay => {
|
|
48
|
-
if (skipDays.length >= 7) return false;
|
|
49
|
-
|
|
76
|
+
if (skipDays && skipDays.length >= 7) return false;
|
|
77
|
+
|
|
78
|
+
return skipDays && skipDays.includes(endDateIsoWeekDay);
|
|
50
79
|
};
|
|
51
80
|
|
|
52
81
|
const isClosedDay = endDate =>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.92",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"supertest": "^6.2.3",
|
|
52
52
|
"supervisor": "^0.12.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "ae4955dc540555ef6c2e4b8c758e9d8df4d0a03c"
|
|
55
55
|
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module.exports = ({ _, settings }) => {
|
|
2
|
-
const orderSettings = _.get(settings, 'order');
|
|
3
|
-
|
|
4
|
-
return function getScheduleByCustomer(customer = {}) {
|
|
5
|
-
const { tags } = customer;
|
|
6
|
-
const { default: defaultSchedule, ...schedules } =
|
|
7
|
-
orderSettings.endDate || {};
|
|
8
|
-
if (!tags || !tags.length) return defaultSchedule;
|
|
9
|
-
|
|
10
|
-
const scheduleTags = Object.keys(schedules);
|
|
11
|
-
if (!scheduleTags || !scheduleTags.length) return defaultSchedule;
|
|
12
|
-
|
|
13
|
-
const tag = tags
|
|
14
|
-
.filter(each => each !== 'default' && each !== 'all')
|
|
15
|
-
.find(each => scheduleTags.includes(each));
|
|
16
|
-
if (!tag) return defaultSchedule;
|
|
17
|
-
return schedules[tag];
|
|
18
|
-
};
|
|
19
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module.exports = ({ actions, settings }) =>
|
|
2
|
-
function getRecommendedEndDate() {
|
|
3
|
-
const readySchedule =
|
|
4
|
-
settings.order &&
|
|
5
|
-
settings.order.endDate &&
|
|
6
|
-
settings.order.endDate.readySchedule;
|
|
7
|
-
|
|
8
|
-
if (readySchedule) {
|
|
9
|
-
const dayOfWeek = new Date().getDay();
|
|
10
|
-
const day = dayOfWeek || 7;
|
|
11
|
-
const schedule = settings.order.endDate.readySchedule.find(item =>
|
|
12
|
-
item.dayOfWeek.includes(day)
|
|
13
|
-
);
|
|
14
|
-
return schedule
|
|
15
|
-
? actions.pickEndDate({
|
|
16
|
-
...schedule,
|
|
17
|
-
})
|
|
18
|
-
: null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return null;
|
|
22
|
-
};
|