@darkpos/pricing 1.0.54 → 1.0.56
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__/modifier.test.js +112 -0
- package/__TEST__/order/pickEndDate.test.js +62 -48
- package/lib/item/calculate.js +2 -1
- package/lib/item/index.js +2 -0
- package/lib/item/removeModifiersByQuantity.js +30 -0
- package/lib/modifier/index.js +2 -0
- package/lib/modifier/isCompute.js +10 -0
- package/lib/order/addItemModifier.js +11 -0
- package/lib/store/pickEndDate.js +36 -28
- package/package.json +4 -2
- package/__TEST__/mocks/scripts/calculate-partially-paid/index.js +0 -27
- package/__TEST__/mocks/scripts/calculate-unpaid/index.js +0 -28
- package/__TEST__/mocks/scripts/order-to-string.js +0 -18
|
@@ -24,4 +24,116 @@ describe('Modifier actions', () => {
|
|
|
24
24
|
})
|
|
25
25
|
).toBe(false);
|
|
26
26
|
});
|
|
27
|
+
|
|
28
|
+
test('CU-86dve27tq Should not allow adding a modifier more than once to an item if isQuantityMultiplier={false} QTY={2}', () => {
|
|
29
|
+
const order = {
|
|
30
|
+
id: 'ord-123',
|
|
31
|
+
items: [],
|
|
32
|
+
modifiers: [],
|
|
33
|
+
};
|
|
34
|
+
const modifier = {
|
|
35
|
+
_id: 1,
|
|
36
|
+
compute: {
|
|
37
|
+
amount: 10,
|
|
38
|
+
action: 'subtract',
|
|
39
|
+
type: 'fixed',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
order.items.push({
|
|
43
|
+
quantity: 2,
|
|
44
|
+
itemId: '123',
|
|
45
|
+
price: 100,
|
|
46
|
+
modifiers: [],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const conditionsBag = [];
|
|
50
|
+
|
|
51
|
+
const updatedOrder = pricingService.order.addItemModifier({
|
|
52
|
+
order,
|
|
53
|
+
modifier,
|
|
54
|
+
itemIndex: 0,
|
|
55
|
+
onConditionsNotMet: bag => {
|
|
56
|
+
bag.forEach(condition => {
|
|
57
|
+
conditionsBag.push(condition);
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
let error = '';
|
|
63
|
+
const updatedOrder2 = pricingService.order.addItemModifier({
|
|
64
|
+
order: { ...updatedOrder },
|
|
65
|
+
modifier,
|
|
66
|
+
itemIndex: 0,
|
|
67
|
+
onConditionsNotMet: bag => {
|
|
68
|
+
bag.forEach(condition => {
|
|
69
|
+
conditionsBag.push(condition);
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
onError: errorMessage => {
|
|
73
|
+
error = errorMessage;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
expect(conditionsBag).toEqual([]);
|
|
78
|
+
expect(error).toEqual('modifier.has.reached.the.maximum.amount.of.applies');
|
|
79
|
+
expect(updatedOrder2).toEqual(updatedOrder);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('CU-86dve27tq Should not allow adding a modifier more than once to an item if isQuantityMultiplier={false} QTY={1}', () => {
|
|
83
|
+
const order = {
|
|
84
|
+
id: 'ord-123',
|
|
85
|
+
items: [],
|
|
86
|
+
modifiers: [],
|
|
87
|
+
};
|
|
88
|
+
const modifier = {
|
|
89
|
+
_id: 1,
|
|
90
|
+
compute: {
|
|
91
|
+
amount: 10,
|
|
92
|
+
action: 'subtract',
|
|
93
|
+
type: 'fixed',
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
order.items.push({
|
|
97
|
+
quantity: 1,
|
|
98
|
+
itemId: '123',
|
|
99
|
+
price: 100,
|
|
100
|
+
modifiers: [],
|
|
101
|
+
properties: {
|
|
102
|
+
basePrice: 100,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const conditionsBag = [];
|
|
107
|
+
|
|
108
|
+
const updatedOrder = pricingService.order.addItemModifier({
|
|
109
|
+
order,
|
|
110
|
+
modifier,
|
|
111
|
+
itemIndex: 0,
|
|
112
|
+
onConditionsNotMet: bag => {
|
|
113
|
+
bag.forEach(condition => {
|
|
114
|
+
conditionsBag.push(condition);
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
let error = '';
|
|
120
|
+
const updatedOrder2 = pricingService.order.addItemModifier({
|
|
121
|
+
order: { ...updatedOrder },
|
|
122
|
+
modifier,
|
|
123
|
+
itemIndex: 0,
|
|
124
|
+
onConditionsNotMet: bag => {
|
|
125
|
+
bag.forEach(condition => {
|
|
126
|
+
conditionsBag.push(condition);
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
onError: errorMessage => {
|
|
130
|
+
error = errorMessage;
|
|
131
|
+
},
|
|
132
|
+
cache: { items: [], modifiers: [] },
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(conditionsBag).toEqual([]);
|
|
136
|
+
expect(error).toEqual('');
|
|
137
|
+
expect(updatedOrder2).toEqual(order);
|
|
138
|
+
});
|
|
27
139
|
});
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
const moment = require('moment-timezone');
|
|
2
2
|
const usePricing = require('../../lib/index');
|
|
3
3
|
|
|
4
|
-
const pricingService = usePricing(
|
|
5
|
-
|
|
4
|
+
const pricingService = usePricing({
|
|
5
|
+
store: {
|
|
6
|
+
_settings: {
|
|
7
|
+
schedule: {
|
|
8
|
+
close: [
|
|
9
|
+
{
|
|
10
|
+
date: '2024-09-03',
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
6
17
|
|
|
7
18
|
describe('pickEndDate function', () => {
|
|
8
|
-
test('Get
|
|
19
|
+
test('Get EndDate, today is an Skip date', () => {
|
|
9
20
|
const schedule = {
|
|
10
21
|
addDays: 1,
|
|
11
22
|
hour: 17,
|
|
@@ -16,24 +27,17 @@ describe('pickEndDate function', () => {
|
|
|
16
27
|
};
|
|
17
28
|
|
|
18
29
|
const now = moment('2024-08-25T15:00:00Z').tz('America/New_York');
|
|
19
|
-
|
|
20
30
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
21
|
-
const result = pickEndDate(schedule);
|
|
22
31
|
|
|
23
|
-
const
|
|
24
|
-
.clone()
|
|
25
|
-
.add(2, 'days')
|
|
26
|
-
.set({ hour: schedule.hour, minute: schedule.minute, second: 0 })
|
|
27
|
-
.utc()
|
|
28
|
-
.format();
|
|
32
|
+
const result = pricingService.store.pickEndDate(schedule);
|
|
29
33
|
|
|
30
|
-
expect(result).toBe(
|
|
34
|
+
expect(result).toBe('2024-08-27T21:00:00Z'); // 2024-08-27 17:00:00 EDT
|
|
31
35
|
});
|
|
32
36
|
|
|
33
37
|
test('Order falls on a closed day', () => {
|
|
34
38
|
const schedule = {
|
|
35
39
|
addDays: 1,
|
|
36
|
-
hour:
|
|
40
|
+
hour: 14,
|
|
37
41
|
minute: 0,
|
|
38
42
|
skipDays: [7], // Skip Sunday
|
|
39
43
|
cutHour: { hour: 16, minute: 0 },
|
|
@@ -43,19 +47,12 @@ describe('pickEndDate function', () => {
|
|
|
43
47
|
const now = moment('2024-08-27T15:00:00Z').tz('America/New_York'); // Tuesday
|
|
44
48
|
|
|
45
49
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
46
|
-
const result = pickEndDate(schedule);
|
|
47
|
-
|
|
48
|
-
const expectedDate = now
|
|
49
|
-
.clone()
|
|
50
|
-
.add(2, 'days') // Skips the closed Wednesday, goes to Thursday
|
|
51
|
-
.set({ hour: schedule.hour, minute: 0, second: 0 })
|
|
52
|
-
.utc()
|
|
53
|
-
.format();
|
|
50
|
+
const result = pricingService.store.pickEndDate(schedule);
|
|
54
51
|
|
|
55
|
-
expect(result).toBe(
|
|
52
|
+
expect(result).toBe('2024-08-28T18:00:00Z'); // 2024-08-28 14:00:00 EDT
|
|
56
53
|
});
|
|
57
54
|
|
|
58
|
-
test('
|
|
55
|
+
test('Get endDate if today is friday and Saturday and Sunday are skip days', () => {
|
|
59
56
|
const schedule = {
|
|
60
57
|
addDays: 1,
|
|
61
58
|
hour: 17,
|
|
@@ -68,16 +65,9 @@ describe('pickEndDate function', () => {
|
|
|
68
65
|
const now = moment('2024-08-23T15:00:00Z').tz('America/New_York'); // Friday
|
|
69
66
|
|
|
70
67
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
71
|
-
const result = pickEndDate(schedule);
|
|
68
|
+
const result = pricingService.store.pickEndDate(schedule);
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
.clone()
|
|
75
|
-
.add(3, 'days') // Skips weekend, goes to Monday
|
|
76
|
-
.set({ hour: 17, minute: 0, second: 0 })
|
|
77
|
-
.utc()
|
|
78
|
-
.format();
|
|
79
|
-
|
|
80
|
-
expect(result).toBe(expectedDate);
|
|
70
|
+
expect(result).toBe('2024-08-26T21:00:00Z'); // 2024-08-26 17:00:00 EDT
|
|
81
71
|
});
|
|
82
72
|
|
|
83
73
|
test('Order time before cut-off hour', () => {
|
|
@@ -93,16 +83,11 @@ describe('pickEndDate function', () => {
|
|
|
93
83
|
const now = moment('2024-08-25T15:00:00Z').tz('America/New_York'); // Friday, before cut-off
|
|
94
84
|
|
|
95
85
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
96
|
-
const result = pickEndDate(schedule);
|
|
97
|
-
|
|
98
|
-
const expectedDate = now
|
|
99
|
-
.clone()
|
|
100
|
-
.set({ hour: 17, minute: 0, second: 0 })
|
|
101
|
-
.utc()
|
|
102
|
-
.format();
|
|
86
|
+
const result = pricingService.store.pickEndDate(schedule);
|
|
103
87
|
|
|
104
|
-
expect(result).toBe(
|
|
88
|
+
expect(result).toBe('2024-08-25T21:00:00Z'); // 2024-08-25 17:00:00 EDT
|
|
105
89
|
});
|
|
90
|
+
|
|
106
91
|
test('Order time after cut-off hour', () => {
|
|
107
92
|
const schedule = {
|
|
108
93
|
hour: 17,
|
|
@@ -124,15 +109,44 @@ describe('pickEndDate function', () => {
|
|
|
124
109
|
const now = moment().tz('America/New_York'); // Friday, after cut-off
|
|
125
110
|
|
|
126
111
|
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
127
|
-
const result = pickEndDate(schedule);
|
|
112
|
+
const result = pricingService.store.pickEndDate(schedule);
|
|
113
|
+
|
|
114
|
+
expect(result).toBe('2024-08-31T21:00:00Z'); // 2024-08-31 17:00:00 EDT
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('Get EndDate, there are skip dates in between', () => {
|
|
118
|
+
const schedule = {
|
|
119
|
+
addDays: 1,
|
|
120
|
+
hour: 17,
|
|
121
|
+
minute: 0,
|
|
122
|
+
skipDays: [7, 0],
|
|
123
|
+
cutHour: { hour: 16, minute: 0 },
|
|
124
|
+
cutDay: 2,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const now = moment('2024-08-25T15:00:00Z').tz('America/New_York');
|
|
128
|
+
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
129
|
+
|
|
130
|
+
const result = pricingService.store.pickEndDate(schedule);
|
|
131
|
+
|
|
132
|
+
expect(result).toBe('2024-08-27T21:00:00Z'); // 2024-08-27 17:00:00 EDT
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('Get EndDate, there are skip dates in between and endDate falls in a closed date', () => {
|
|
136
|
+
const schedule = {
|
|
137
|
+
addDays: 1,
|
|
138
|
+
hour: 20,
|
|
139
|
+
minute: 0,
|
|
140
|
+
skipDays: [1, 7],
|
|
141
|
+
cutHour: { hour: 16, minute: 0 },
|
|
142
|
+
cutDay: 2,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const now = moment('2024-09-01T15:00:00Z').tz('America/New_York');
|
|
146
|
+
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
128
147
|
|
|
129
|
-
const
|
|
130
|
-
.clone()
|
|
131
|
-
.add(6, 'days') // Skips weekend, goes to Monday
|
|
132
|
-
.set({ hour: 17, minute: 0, second: 0 })
|
|
133
|
-
.utc()
|
|
134
|
-
.format();
|
|
148
|
+
const result = pricingService.store.pickEndDate(schedule);
|
|
135
149
|
|
|
136
|
-
expect(result).toBe(
|
|
150
|
+
expect(result).toBe('2024-09-06T00:00:00Z'); // 2024-09-05 20:00:00 EDT
|
|
137
151
|
});
|
|
138
152
|
});
|
package/lib/item/calculate.js
CHANGED
|
@@ -29,7 +29,8 @@ module.exports = ({ _, utils, actions, modifierActions }) => {
|
|
|
29
29
|
subTotals._simple = math.mul(price, quantity);
|
|
30
30
|
|
|
31
31
|
const modifiers = [];
|
|
32
|
-
const { modifiers: itemModifiers = [] } =
|
|
32
|
+
const { modifiers: itemModifiers = [] } =
|
|
33
|
+
actions.removeModifiersByQuantity(item);
|
|
33
34
|
|
|
34
35
|
const validatedModifiers = itemModifiers.map(each =>
|
|
35
36
|
modifierActions.validate(each, {
|
package/lib/item/index.js
CHANGED
|
@@ -46,6 +46,7 @@ const getTotalsDifference = require('./getTotalsDifference');
|
|
|
46
46
|
const getTotalNeareastDifference = require('./getTotalNeareastDifference');
|
|
47
47
|
const getNoteTags = require('./getNoteTags');
|
|
48
48
|
const getBasePrice = require('./getBasePrice');
|
|
49
|
+
const removeModifiersByQuantity = require('./removeModifiersByQuantity');
|
|
49
50
|
|
|
50
51
|
const itemActions = (deps = {}) => {
|
|
51
52
|
const actions = {};
|
|
@@ -105,6 +106,7 @@ const itemActions = (deps = {}) => {
|
|
|
105
106
|
getTotalNeareastDifference: getTotalNeareastDifference(innerDeps),
|
|
106
107
|
getNoteTags: getNoteTags(innerDeps),
|
|
107
108
|
getBasePrice: getBasePrice(innerDeps),
|
|
109
|
+
removeModifiersByQuantity: removeModifiersByQuantity(innerDeps),
|
|
108
110
|
});
|
|
109
111
|
|
|
110
112
|
Object.keys(freezedActions).forEach(actionName => {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module.exports = ({ modifierActions }) =>
|
|
2
|
+
function removeModifiersByQuantity(item) {
|
|
3
|
+
if (!item || !Array.isArray(item.modifiers)) {
|
|
4
|
+
return item;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const modifierCounts = {};
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
...item,
|
|
11
|
+
modifiers: item.modifiers.filter(modifier => {
|
|
12
|
+
if (
|
|
13
|
+
modifierActions.isPaymentModifier(modifier) ||
|
|
14
|
+
modifierActions.isCalculatedPaymentModifier(modifier) ||
|
|
15
|
+
!modifier.modifierId ||
|
|
16
|
+
!modifierActions.isDirect(modifier)
|
|
17
|
+
)
|
|
18
|
+
return true;
|
|
19
|
+
|
|
20
|
+
const count = modifierCounts[modifier.modifierId] || 0;
|
|
21
|
+
|
|
22
|
+
if (count < item.quantity) {
|
|
23
|
+
modifierCounts[modifier.modifierId] = count + 1;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
};
|
package/lib/modifier/index.js
CHANGED
|
@@ -149,6 +149,7 @@ const isGroup = require('./isGroup');
|
|
|
149
149
|
const isOptionsSelectedOverride = require('./isOptionsSelectedOverride');
|
|
150
150
|
const isFixedSubtract = require('./isFixedSubtract');
|
|
151
151
|
const isQuantityMultiplier = require('./isQuantityMultiplier');
|
|
152
|
+
const isCompute = require('./isCompute');
|
|
152
153
|
|
|
153
154
|
const modifierActions = (deps = {}) => {
|
|
154
155
|
const actions = {};
|
|
@@ -311,6 +312,7 @@ const modifierActions = (deps = {}) => {
|
|
|
311
312
|
isOptionsSelectedOverride: isOptionsSelectedOverride(innerDeps),
|
|
312
313
|
isFixedSubtract: isFixedSubtract(innerDeps),
|
|
313
314
|
isQuantityMultiplier: isQuantityMultiplier(innerDeps),
|
|
315
|
+
isCompute: isCompute(innerDeps),
|
|
314
316
|
});
|
|
315
317
|
|
|
316
318
|
Object.keys(freezedActions).forEach(actionName => {
|
|
@@ -177,6 +177,7 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
|
|
|
177
177
|
itemIndex,
|
|
178
178
|
cache,
|
|
179
179
|
onConditionsNotMet,
|
|
180
|
+
onError,
|
|
180
181
|
}) {
|
|
181
182
|
let order = _.cloneDeep(orderProp);
|
|
182
183
|
if (!order || itemIndex < 0 || !modifier) return order;
|
|
@@ -223,6 +224,16 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
|
|
|
223
224
|
return order;
|
|
224
225
|
}
|
|
225
226
|
|
|
227
|
+
if (
|
|
228
|
+
contains &&
|
|
229
|
+
modifierActions.isCompute(modifier) &&
|
|
230
|
+
!modifierActions.isQuantityMultiplier(modifier)
|
|
231
|
+
) {
|
|
232
|
+
if (onError)
|
|
233
|
+
onError('modifier.has.reached.the.maximum.amount.of.applies');
|
|
234
|
+
return order;
|
|
235
|
+
}
|
|
236
|
+
|
|
226
237
|
item = addModifier({
|
|
227
238
|
item,
|
|
228
239
|
modifier,
|
package/lib/store/pickEndDate.js
CHANGED
|
@@ -4,21 +4,20 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
4
4
|
const getClosedDays = () => {
|
|
5
5
|
const schedule = _.get(settings, 'schedule', {});
|
|
6
6
|
const { close = [] } = schedule;
|
|
7
|
-
|
|
8
7
|
if (!Array.isArray(close)) return [];
|
|
9
|
-
return close
|
|
10
|
-
date: moment(closedDate.date), // the date is saved with the user timezone, no need to convert it back here (ex: date: '2024-08-27' would become date:'2024-08-26 23:00 -4:00')
|
|
11
|
-
}));
|
|
8
|
+
return close;
|
|
12
9
|
};
|
|
13
10
|
|
|
11
|
+
const MAX_ADD_DAYS = 365;
|
|
12
|
+
|
|
14
13
|
return function pickEndDate(schedule = {}) {
|
|
15
14
|
const {
|
|
16
|
-
addDays
|
|
15
|
+
addDays: addDaysParam,
|
|
17
16
|
hour,
|
|
18
17
|
minute,
|
|
19
18
|
skipDays = [],
|
|
20
19
|
cutHour,
|
|
21
|
-
cutDay =
|
|
20
|
+
cutDay = 0,
|
|
22
21
|
} = schedule;
|
|
23
22
|
|
|
24
23
|
const todayTZ = moment().tz(timezone);
|
|
@@ -26,36 +25,45 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
26
25
|
const closedDays = getClosedDays();
|
|
27
26
|
const todayHours = todayTZ.get('hours');
|
|
28
27
|
const todayMinutes = todayTZ.get('minutes');
|
|
28
|
+
|
|
29
|
+
const addDays =
|
|
30
|
+
typeof addDaysParam !== 'number' || addDaysParam > MAX_ADD_DAYS
|
|
31
|
+
? 0
|
|
32
|
+
: addDaysParam;
|
|
33
|
+
|
|
29
34
|
if (
|
|
30
35
|
(cutHour && todayHours > cutHour.hour) ||
|
|
31
36
|
(todayHours >= cutHour.hour && todayMinutes > cutHour.minute)
|
|
32
37
|
) {
|
|
33
|
-
endDateTZ = endDateTZ.add(cutDay, 'days');
|
|
38
|
+
endDateTZ = endDateTZ.add(cutDay, 'days');
|
|
34
39
|
}
|
|
35
40
|
|
|
36
|
-
endDateTZ.add(addDays, 'days');
|
|
37
|
-
// do the logic related to skipdays
|
|
38
|
-
// if the date already pass the skip day, do nothing
|
|
39
|
-
// if the date is the same as one of the skip day, check the next skip day if any, then add one more day
|
|
40
|
-
skipDays.forEach(day => {
|
|
41
|
-
if (todayTZ.isoWeekday() <= day) {
|
|
42
|
-
endDateTZ.add(1, 'days');
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* setting the hour and minute so we can compare with closedDays
|
|
48
|
-
*/
|
|
49
|
-
closedDays.forEach(closed => {
|
|
50
|
-
const closedDay = moment(closed.date);
|
|
51
|
-
closedDay.set('hour', hour);
|
|
52
|
-
closedDay.set('minute', minute);
|
|
53
|
-
if (endDateTZ.startOf('day').isSame(closedDay, 'day')) {
|
|
54
|
-
endDateTZ.add(1, 'days');
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
41
|
if (hour !== undefined) endDateTZ.set('hour', hour);
|
|
58
42
|
if (minute !== undefined) endDateTZ.set('minute', minute);
|
|
43
|
+
endDateTZ.set('second', 0);
|
|
44
|
+
|
|
45
|
+
const isSkipDay = endDateIsoWeekDay => {
|
|
46
|
+
if (skipDays.length >= 7) return false;
|
|
47
|
+
return skipDays.includes(endDateIsoWeekDay);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const isClosedDay = endDate =>
|
|
51
|
+
closedDays.some(
|
|
52
|
+
closedDate => endDate.format('YYYY-MM-DD') === closedDate.date
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
let addedDays = 0;
|
|
56
|
+
|
|
57
|
+
while (
|
|
58
|
+
addedDays < addDays ||
|
|
59
|
+
isSkipDay(endDateTZ.isoWeekday()) ||
|
|
60
|
+
isClosedDay(endDateTZ)
|
|
61
|
+
) {
|
|
62
|
+
if (!isSkipDay(endDateTZ.isoWeekday()) && !isClosedDay(endDateTZ)) {
|
|
63
|
+
addedDays += 1;
|
|
64
|
+
}
|
|
65
|
+
endDateTZ.add(1, 'days');
|
|
66
|
+
}
|
|
59
67
|
|
|
60
68
|
return moment.utc(endDateTZ).format();
|
|
61
69
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
"test:split": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/split.test.js",
|
|
21
21
|
"test:getModifierTags": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/item/getModifierTags.test.js",
|
|
22
22
|
"test:createIndirectModifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier/createIndirectModifier.test.js",
|
|
23
|
+
"test:conditionsNotMet": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/conditionsNotMet.test.js",
|
|
24
|
+
"test:pickEndDate": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/pickEndDate.test.js",
|
|
23
25
|
"lint": "eslint --quiet lib/"
|
|
24
26
|
},
|
|
25
27
|
"publishConfig": {
|
|
@@ -43,5 +45,5 @@
|
|
|
43
45
|
"supertest": "^6.2.3",
|
|
44
46
|
"supervisor": "^0.12.0"
|
|
45
47
|
},
|
|
46
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "41b3ae5dcaec11195920c3b5f0a97b34b3982815"
|
|
47
49
|
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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.duplicate({
|
|
13
|
-
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);
|
|
@@ -1,28 +0,0 @@
|
|
|
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.duplicate({
|
|
13
|
-
...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);
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
};
|