@darkpos/pricing 1.0.8 → 1.0.11
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/lib/item/removeModifier.js +2 -2
- package/lib/modifier/calculate.js +2 -2
- package/lib/modifier/index.js +2 -0
- package/lib/modifier/isComputedOverride.js +7 -0
- package/lib/order/addItemModifier.js +3 -3
- package/lib/order/pickEndDate.js +30 -42
- package/lib/order/splitByDepartments.js +1 -1
- package/package.json +2 -2
|
@@ -59,7 +59,7 @@ module.exports = ({ modifierActions, _, actions }) => {
|
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
const hasOverride = modifiersToApply.find(each =>
|
|
62
|
-
modifierActions.isOverride(each)
|
|
62
|
+
modifierActions.isOverride(each) || modifierActions.isComputedOverride(each)
|
|
63
63
|
);
|
|
64
64
|
|
|
65
65
|
if (hasOverride) {
|
|
@@ -68,7 +68,7 @@ module.exports = ({ modifierActions, _, actions }) => {
|
|
|
68
68
|
|
|
69
69
|
if (modifierActions.isQuantityOverride(modifier)) nextItem.quantity = 1;
|
|
70
70
|
|
|
71
|
-
if (modifierActions.isPriceOverride(modifier))
|
|
71
|
+
if (modifierActions.isPriceOverride(modifier) || modifierActions.isComputedOverride(modifier))
|
|
72
72
|
nextItem.price = actions.getItemPrice({
|
|
73
73
|
item: originalItem,
|
|
74
74
|
cache,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Get calculated modifier
|
|
3
3
|
*/
|
|
4
|
-
module.exports = ({ _, constants, utils, localization, actions }) => {
|
|
4
|
+
module.exports = ({ _, constants, utils, localization, actions }) => {
|
|
5
5
|
const { math } = utils;
|
|
6
6
|
const { Modifier } = constants;
|
|
7
7
|
|
|
@@ -29,7 +29,7 @@ module.exports = ({ _, constants, utils, localization, actions }) => {
|
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
if (!type || action === Modifier.Compute.Actions.OVERRIDE)
|
|
32
|
-
_computed.amount =
|
|
32
|
+
_computed.amount = 0;
|
|
33
33
|
|
|
34
34
|
if (maxAmount && math.gt(math.abs(_computed.amount), maxAmount))
|
|
35
35
|
_computed.amount = maxAmount;
|
package/lib/modifier/index.js
CHANGED
|
@@ -85,6 +85,7 @@ const isService = require('./isService');
|
|
|
85
85
|
const isSingleValue = require('./isSingleValue');
|
|
86
86
|
const isGroupOfItems = require('./isGroupOfItems');
|
|
87
87
|
const isOverride = require('./isOverride');
|
|
88
|
+
const isComputedOverride = require('./isComputedOverride');
|
|
88
89
|
const isDepartment = require('./isDepartment');
|
|
89
90
|
const isRequired = require('./isRequired');
|
|
90
91
|
const isMultiplier = require('./isMultiplier');
|
|
@@ -207,6 +208,7 @@ const modifierActions = (deps = {}) => {
|
|
|
207
208
|
isSingleValue: isSingleValue(innerDeps),
|
|
208
209
|
isGroupOfItems: isGroupOfItems(innerDeps),
|
|
209
210
|
isOverride: isOverride(innerDeps),
|
|
211
|
+
isComputedOverride: isComputedOverride(innerDeps),
|
|
210
212
|
isDepartment: isDepartment(innerDeps),
|
|
211
213
|
isRequired: isRequired(innerDeps),
|
|
212
214
|
isMultiplier: isMultiplier(innerDeps),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
module.exports = ({ actions, constants }) => {
|
|
2
|
+
const { Modifier } = constants;
|
|
3
|
+
return function isComputedOverride(modifier) {
|
|
4
|
+
const computeAction = modifier && modifier.compute && modifier.compute.action;
|
|
5
|
+
return computeAction === Modifier.Attributes.OVERRIDE;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -76,7 +76,7 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
|
|
|
76
76
|
// group of values use case
|
|
77
77
|
if (
|
|
78
78
|
modifierActions.isGroupOfValues(modifier) ||
|
|
79
|
-
modifierActions.
|
|
79
|
+
modifierActions.isOverride(modifier)
|
|
80
80
|
) {
|
|
81
81
|
if (modifierIndex > -1) item.modifiers[modifierIndex] = modifierToAdd;
|
|
82
82
|
else item.modifiers.push(modifierToAdd);
|
|
@@ -99,7 +99,7 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
|
|
|
99
99
|
item.quantity = modifier.compute.amount || 1;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
if (modifierActions.isPriceOverride(modifier)) {
|
|
102
|
+
if (modifierActions.isPriceOverride(modifier) || modifierActions.isComputedOverride(modifier)) {
|
|
103
103
|
item.price = getPrice({ modifier, item });
|
|
104
104
|
} else {
|
|
105
105
|
item.price = itemActions.getItemPrice({
|
|
@@ -144,7 +144,7 @@ module.exports = ({ actions, itemActions, modifierActions, utils, _ }) => {
|
|
|
144
144
|
usingCount >= item.quantity &&
|
|
145
145
|
!(
|
|
146
146
|
modifierActions.isGroupOfValues(modifier) ||
|
|
147
|
-
modifierActions.
|
|
147
|
+
modifierActions.isOverride(modifier)
|
|
148
148
|
)
|
|
149
149
|
) {
|
|
150
150
|
// console.log('Removing MODIFIER ...');
|
package/lib/order/pickEndDate.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
module.exports = ({ settings, _, moment }) => {
|
|
2
2
|
const timezone = _.get(settings, 'localization.timezone', 'America/New_York');
|
|
3
|
-
const isInSchedule = (each, date) => {
|
|
4
|
-
const isoWeekday = moment(date).tz(timezone).isoWeekday();
|
|
5
|
-
let check = false;
|
|
6
|
-
if (each.day !== undefined && each.day !== null)
|
|
7
|
-
check = String(each.day) === String(isoWeekday === 7 ? 0 : isoWeekday);
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
check =
|
|
11
|
-
moment(date).startOf('day').tz(timezone).format('YYYYMMDD') ===
|
|
12
|
-
moment(each.date).startOf('day').tz(timezone).format('YYYYMMDD');
|
|
13
|
-
return check;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const checkStoreSchedule = date => {
|
|
4
|
+
const getClosedDays = () => {
|
|
17
5
|
const schedule = _.get(settings, 'schedule', {});
|
|
18
6
|
const { close = [] } = schedule;
|
|
19
7
|
|
|
20
|
-
if (close
|
|
8
|
+
if (!Array.isArray(close)) return [];
|
|
9
|
+
return close.map(closedDate => ({
|
|
10
|
+
isoWeekDay: moment(closedDate.date).tz(timezone).isoWeekday(),
|
|
11
|
+
date: moment(closedDate.date).tz(timezone)
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return function pickEndDate(schedule = {}) {
|
|
21
16
|
|
|
22
|
-
return true;
|
|
23
|
-
};
|
|
24
|
-
return function pickEndDate(schedule = {}, skip = 0, date = undefined) {
|
|
25
17
|
const {
|
|
26
18
|
addDays = 1,
|
|
27
19
|
hour,
|
|
@@ -30,41 +22,37 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
30
22
|
cutHour,
|
|
31
23
|
cutDay = 1,
|
|
32
24
|
} = schedule;
|
|
33
|
-
let days = skip || Number(addDays);
|
|
34
25
|
|
|
35
|
-
const
|
|
36
|
-
|
|
26
|
+
const todayTZ = moment().tz(timezone);
|
|
27
|
+
let endDateTZ = todayTZ.clone();
|
|
28
|
+
|
|
29
|
+
const closedDays = getClosedDays();
|
|
37
30
|
|
|
38
31
|
if (
|
|
39
|
-
!skip &&
|
|
40
|
-
!date &&
|
|
41
32
|
cutHour &&
|
|
42
|
-
|
|
33
|
+
todayTZ.isAfter(moment(cutHour, 'hh:mm:ss').tz(timezone))
|
|
43
34
|
) {
|
|
44
|
-
|
|
45
|
-
days += cutDay;
|
|
35
|
+
endDateTZ = endDateTZ.add(cutDay, 'days')
|
|
46
36
|
}
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
console.log('check date => ', endDate.format());
|
|
38
|
+
let addDaysCounter = 0;
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
while (addDaysCounter < addDays) {
|
|
41
|
+
endDateTZ = endDateTZ.add(1, 'days');
|
|
42
|
+
const endDateISOWeekday = endDateTZ.isoWeekday() === 7 ? 0 : endDateTZ.isoWeekday();
|
|
43
|
+
|
|
44
|
+
if (!skipDays.includes(endDateISOWeekday) && !closedDays.some(closedDay => {
|
|
45
|
+
return closedDay.date.isSame(endDateTZ, 'day');
|
|
46
|
+
})) {
|
|
47
|
+
addDaysCounter++;
|
|
48
|
+
}
|
|
53
49
|
|
|
54
|
-
if (skipDays && skipDays.includes(isoWeekday === 7 ? 0 : isoWeekday)) {
|
|
55
|
-
console.log('check next day: in Skip days');
|
|
56
|
-
return pickEndDate(schedule, 1, endDate);
|
|
57
|
-
}
|
|
58
|
-
if (!checkStoreSchedule(endDate)) {
|
|
59
|
-
console.log('check next day: in Close days');
|
|
60
|
-
return pickEndDate(schedule, 1, endDate);
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
if (hour !== undefined)
|
|
64
|
-
if (minute !== undefined)
|
|
65
|
-
|
|
52
|
+
if (hour !== undefined) endDateTZ.set('hour', hour);
|
|
53
|
+
if (minute !== undefined) endDateTZ.set('minute', minute);
|
|
54
|
+
endDateTZ.set('second', 0);
|
|
66
55
|
|
|
67
|
-
|
|
68
|
-
return moment.utc(endDate).format();
|
|
56
|
+
return moment.utc(endDateTZ).format();
|
|
69
57
|
};
|
|
70
|
-
};
|
|
58
|
+
};
|
|
@@ -122,7 +122,7 @@ module.exports = ({
|
|
|
122
122
|
quantity: 1,
|
|
123
123
|
_id: helpers.getObjectID(),
|
|
124
124
|
};
|
|
125
|
-
const totalPieces = itemActions.
|
|
125
|
+
const totalPieces = itemActions.getTotalPieces(item);
|
|
126
126
|
const index = splitOrders.findIndex(
|
|
127
127
|
newOrder =>
|
|
128
128
|
newOrder.items &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"supertest": "^6.2.3",
|
|
36
36
|
"supervisor": "^0.12.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "d839ed87a99ef0c4297ba95cd647e358cba38639"
|
|
39
39
|
}
|