@darkpos/pricing 1.0.91 → 1.0.93
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/conditionsNotMet.test.js +124 -0
- package/__TEST__/order/getParentTotals.test.js +79 -0
- package/__TEST__/order/order-payment-modifier.test.js +332 -17
- package/__TEST__/order/order.test.js +60 -6
- package/__TEST__/order/pickEndDate.test.js +111 -25
- package/lib/item/calculate.js +10 -1
- package/lib/item/getTotalsDifference.js +7 -1
- package/lib/item/hasPaymentMethodType.js +7 -1
- package/lib/modifier/areConditionsMet.js +3 -0
- package/lib/modifier/calculatePaymentModifier.js +2 -0
- package/lib/modifier/hasPaymentMethodType.js +21 -6
- package/lib/modifier/index.js +2 -0
- package/lib/modifier/isPaymentModifier.js +2 -1
- package/lib/modifier/isPercentage.js +1 -1
- package/lib/modifier/isPrepayModifier.js +11 -0
- package/lib/modifier/sort.js +16 -27
- package/lib/order/calculate.js +2 -7
- package/lib/order/getTotals.js +21 -22
- package/lib/order/index.js +0 -2
- package/lib/order/splitItems.js +2 -1
- package/lib/store/getScheduleByCustomer.js +25 -0
- package/lib/store/index.js +6 -4
- package/lib/store/pickEndDate.js +40 -6
- package/lib/store/pickEndDateByCustomer.js +5 -0
- package/package.json +3 -2
- package/__TEST__/order/getRecommendedEndDate.test.js +0 -96
- package/lib/order/getScheduleByCustomer.js +0 -19
- package/lib/store/getRecommendedEndDate.js +0 -25
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),
|
package/lib/order/splitItems.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module.exports = ({ actions, modifierActions, itemActions }) =>
|
|
1
|
+
module.exports = ({ actions, modifierActions, itemActions, utils }) =>
|
|
2
2
|
function splitItems({ order }) {
|
|
3
3
|
if (!order || !order.items) return order;
|
|
4
4
|
|
|
@@ -32,6 +32,7 @@ module.exports = ({ actions, modifierActions, itemActions }) =>
|
|
|
32
32
|
...item,
|
|
33
33
|
quantity: splitQty,
|
|
34
34
|
modifiers: [],
|
|
35
|
+
_id: utils.helpers.getObjectID(),
|
|
35
36
|
});
|
|
36
37
|
remaining -= splitQty;
|
|
37
38
|
}
|
|
@@ -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,11 +38,16 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
10
38
|
|
|
11
39
|
const MAX_ADD_DAYS = 365;
|
|
12
40
|
|
|
13
|
-
return function pickEndDate(
|
|
14
|
-
const {
|
|
15
|
-
|
|
41
|
+
return function pickEndDate(schedules, isoWeekday) {
|
|
42
|
+
const {
|
|
43
|
+
addDays: addDaysParam,
|
|
44
|
+
readyHour,
|
|
45
|
+
cutHour,
|
|
46
|
+
cutDay,
|
|
47
|
+
skipDays,
|
|
48
|
+
todayTZ,
|
|
49
|
+
} = getSchedule(schedules, isoWeekday);
|
|
16
50
|
|
|
17
|
-
const todayTZ = moment().tz(timezone);
|
|
18
51
|
let endDateTZ = todayTZ.clone();
|
|
19
52
|
const closedDays = getClosedDays();
|
|
20
53
|
const todayHours = todayTZ.get('hours');
|
|
@@ -40,8 +73,9 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
40
73
|
endDateTZ.set('second', 0);
|
|
41
74
|
|
|
42
75
|
const isSkipDay = endDateIsoWeekDay => {
|
|
43
|
-
if (skipDays.length >= 7) return false;
|
|
44
|
-
|
|
76
|
+
if (skipDays && skipDays.length >= 7) return false;
|
|
77
|
+
|
|
78
|
+
return skipDays && skipDays.includes(endDateIsoWeekDay);
|
|
45
79
|
};
|
|
46
80
|
|
|
47
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.93",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"test:modifier": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/modifier.test.js",
|
|
28
28
|
"test:paymentModifiers": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/order-payment-modifier.test.js",
|
|
29
29
|
"test:addItem": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/addItem.test.js",
|
|
30
|
+
"test:getParentTotals": "jest --runInBand --detectOpenHandles --logHeapUsage --forceExit ./__TEST__/order/getParentTotals.test.js",
|
|
30
31
|
"lint": "eslint --quiet lib/"
|
|
31
32
|
},
|
|
32
33
|
"publishConfig": {
|
|
@@ -51,5 +52,5 @@
|
|
|
51
52
|
"supertest": "^6.2.3",
|
|
52
53
|
"supervisor": "^0.12.0"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "fb466ad4fdad14d593a1ee3dc2814f683b10ec24"
|
|
55
56
|
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
const moment = require('moment-timezone');
|
|
2
|
-
const usePricing = require('../../lib/index');
|
|
3
|
-
|
|
4
|
-
const defaults = {
|
|
5
|
-
store: {
|
|
6
|
-
_settings: {
|
|
7
|
-
order: {
|
|
8
|
-
endDate: {
|
|
9
|
-
readySchedule: [
|
|
10
|
-
{
|
|
11
|
-
_id: '682373ef8256034ae1f2c195',
|
|
12
|
-
dayOfWeek: [2],
|
|
13
|
-
recommended: 'auto_recommended',
|
|
14
|
-
addDays: 1,
|
|
15
|
-
cutDay: 1,
|
|
16
|
-
skipDays: undefined,
|
|
17
|
-
readyHour: null,
|
|
18
|
-
cutHour: null,
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
describe('getRecommendedEndDate function', () => {
|
|
27
|
-
test('getRecommendedEndDate, skipDays undefined', () => {
|
|
28
|
-
const pricingService = usePricing(defaults);
|
|
29
|
-
const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
|
|
30
|
-
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
31
|
-
|
|
32
|
-
const result = pricingService.store.getRecommendedEndDate();
|
|
33
|
-
expect(result).toBe('2025-05-14T15:00:00Z'); // 2025-05-14T15:00:00Z
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('getRecommendedEndDate, skipDays with dayOfWeek undefined', () => {
|
|
37
|
-
const pricingService = usePricing({
|
|
38
|
-
store: {
|
|
39
|
-
_settings: {
|
|
40
|
-
order: {
|
|
41
|
-
endDate: {
|
|
42
|
-
readySchedule: [
|
|
43
|
-
{
|
|
44
|
-
_id: '682373ef8256034ae1f2c195',
|
|
45
|
-
dayOfWeek: null,
|
|
46
|
-
recommended: 'auto_recommended',
|
|
47
|
-
addDays: 1,
|
|
48
|
-
cutDay: 1,
|
|
49
|
-
skipDays: [1],
|
|
50
|
-
readyHour: null,
|
|
51
|
-
cutHour: null,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
|
|
60
|
-
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
61
|
-
|
|
62
|
-
const result = pricingService.store.getRecommendedEndDate();
|
|
63
|
-
|
|
64
|
-
expect(result).toBe(null); // null
|
|
65
|
-
});
|
|
66
|
-
test('getRecommendedEndDate, skipDays with one day', () => {
|
|
67
|
-
const pricingService = usePricing({
|
|
68
|
-
store: {
|
|
69
|
-
_settings: {
|
|
70
|
-
order: {
|
|
71
|
-
endDate: {
|
|
72
|
-
readySchedule: [
|
|
73
|
-
{
|
|
74
|
-
_id: '682373ef8256034ae1f2c195',
|
|
75
|
-
dayOfWeek: [2],
|
|
76
|
-
recommended: 'auto_recommended',
|
|
77
|
-
addDays: 1,
|
|
78
|
-
cutDay: 1,
|
|
79
|
-
skipDays: [1],
|
|
80
|
-
readyHour: null,
|
|
81
|
-
cutHour: null,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
|
|
90
|
-
jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
|
|
91
|
-
|
|
92
|
-
const result = pricingService.store.getRecommendedEndDate();
|
|
93
|
-
|
|
94
|
-
expect(result).toBe('2025-05-14T15:00:00Z'); // 2025-05-14T15:00:00Z
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -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,25 +0,0 @@
|
|
|
1
|
-
module.exports = ({ actions, settings }) => {
|
|
2
|
-
const getReadyScheduleSetting = () =>
|
|
3
|
-
(settings.order &&
|
|
4
|
-
settings.order.endDate &&
|
|
5
|
-
settings.order.endDate.readySchedule) ||
|
|
6
|
-
[];
|
|
7
|
-
return function getRecommendedEndDate() {
|
|
8
|
-
const readySchedule = getReadyScheduleSetting();
|
|
9
|
-
|
|
10
|
-
const dayOfWeek = new Date().getDay();
|
|
11
|
-
const day = dayOfWeek || 7;
|
|
12
|
-
const schedule = readySchedule.find(item => {
|
|
13
|
-
if (item && item.dayOfWeek) {
|
|
14
|
-
return item.dayOfWeek.includes(day);
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return schedule
|
|
20
|
-
? actions.pickEndDate({
|
|
21
|
-
...schedule,
|
|
22
|
-
})
|
|
23
|
-
: null;
|
|
24
|
-
};
|
|
25
|
-
};
|