@open-tender/store 0.3.57 → 0.3.59
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/dist/cjs/slices/settings.d.ts +1 -1
- package/dist/cjs/types/api/employee.d.ts +7 -1
- package/dist/cjs/utils/helpers.d.ts +4 -0
- package/dist/cjs/utils/helpers.js +13 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/order.d.ts +3 -1
- package/dist/cjs/utils/order.js +17 -1
- package/dist/cjs/utils/punches.d.ts +19 -0
- package/dist/cjs/utils/punches.js +97 -0
- package/dist/cjs/utils/refunds.d.ts +2 -1
- package/dist/cjs/utils/refunds.js +7 -1
- package/dist/esm/slices/settings.d.ts +1 -1
- package/dist/esm/types/api/employee.d.ts +7 -1
- package/dist/esm/utils/helpers.d.ts +4 -0
- package/dist/esm/utils/helpers.js +11 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/order.d.ts +3 -1
- package/dist/esm/utils/order.js +14 -0
- package/dist/esm/utils/punches.d.ts +19 -0
- package/dist/esm/utils/punches.js +91 -0
- package/dist/esm/utils/refunds.d.ts +2 -1
- package/dist/esm/utils/refunds.js +5 -0
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ export declare enum SettingsActionType {
|
|
|
8
8
|
UpdateSetting = "settings/updateSetting",
|
|
9
9
|
UpdateSettings = "settings/updateSettings"
|
|
10
10
|
}
|
|
11
|
-
export declare const updateSetting: import("@reduxjs/toolkit").AsyncThunk<Settings, EntityType, {
|
|
11
|
+
export declare const updateSetting: import("@reduxjs/toolkit").AsyncThunk<Settings, void | EntityType, {
|
|
12
12
|
state: AppState;
|
|
13
13
|
rejectValue: RequestError;
|
|
14
14
|
}>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ISOStringOffset } from '../datetimes';
|
|
1
2
|
import { Money, NegativeMoney } from '../global';
|
|
2
3
|
export declare type PunchAuthType = 'PIN' | 'CARD';
|
|
3
4
|
export declare type PunchType = 'PUNCH_IN' | 'PUNCH_OUT' | 'BREAK_IN' | 'BREAK_OUT';
|
|
@@ -6,7 +7,7 @@ export interface Punch {
|
|
|
6
7
|
department_id: number;
|
|
7
8
|
punch_type: PunchType;
|
|
8
9
|
tips: Money;
|
|
9
|
-
created_at?:
|
|
10
|
+
created_at?: ISOStringOffset;
|
|
10
11
|
created_dt?: string;
|
|
11
12
|
}
|
|
12
13
|
export interface Department {
|
|
@@ -18,6 +19,11 @@ export interface Department {
|
|
|
18
19
|
overtime_pay_rate: string;
|
|
19
20
|
pay_rate: string;
|
|
20
21
|
}
|
|
22
|
+
export interface PunchProcessed extends Punch {
|
|
23
|
+
department?: Department;
|
|
24
|
+
date: Date;
|
|
25
|
+
}
|
|
26
|
+
export declare type PunchesProcessed = PunchProcessed[];
|
|
21
27
|
export declare type Role = 'Manager' | 'Cashier' | 'Employee';
|
|
22
28
|
export interface Employee {
|
|
23
29
|
employee_id: number;
|
|
@@ -29,3 +29,7 @@ export declare const handleRespError: (err: RequestErrorAPI | string) => {
|
|
|
29
29
|
};
|
|
30
30
|
export declare const hexToRgb: (hex: string) => number[];
|
|
31
31
|
export declare const makeContrastColor: (textColors: Record<string, string>, backgroundColor: string | null) => string | null;
|
|
32
|
+
declare type ThrottleArgs = string | number | Record<string, unknown>;
|
|
33
|
+
declare type ThrottleFunc = (...args: any) => void;
|
|
34
|
+
export declare function throttle(func: ThrottleFunc, delay: number): (args?: ThrottleArgs) => void;
|
|
35
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeContrastColor = exports.hexToRgb = exports.handleRespError = exports.pixelsToInt = exports.remsToInt = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.capitalize = exports.serialize = exports.convertStringToArray = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.contains = exports.isEmpty = void 0;
|
|
3
|
+
exports.throttle = exports.makeContrastColor = exports.hexToRgb = exports.handleRespError = exports.pixelsToInt = exports.remsToInt = exports.formatDollars = exports.formatQuantity = exports.addCommas = exports.capitalize = exports.serialize = exports.convertStringToArray = exports.getHeight = exports.getWidth = exports.makeRandomNumberString = exports.contains = exports.isEmpty = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var isEmpty = function (obj) {
|
|
6
6
|
return (!obj || (obj.constructor === Object && Object.entries(obj).length === 0));
|
|
@@ -130,3 +130,15 @@ var makeContrastColor = function (textColors, backgroundColor) {
|
|
|
130
130
|
return textColors[foregroundColor];
|
|
131
131
|
};
|
|
132
132
|
exports.makeContrastColor = makeContrastColor;
|
|
133
|
+
function throttle(func, delay) {
|
|
134
|
+
var timeout = null;
|
|
135
|
+
return function (args) {
|
|
136
|
+
if (!timeout) {
|
|
137
|
+
timeout = setTimeout(function () {
|
|
138
|
+
func(args);
|
|
139
|
+
timeout = null;
|
|
140
|
+
}, delay);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
exports.throttle = throttle;
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -7,4 +7,5 @@ tslib_1.__exportStar(require("./keypad"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./menu"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./order"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./orders"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./punches"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./theme"), exports);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Cart, CartItem, CartItemOption, FullOrderType, GuestItem, MenuItem, NutritionalInfo, OrderChannel, OrderType, OrderTypeMap, ServiceTypeMap, SimpleCart, TenderType, TenderTypeMap } from '../types';
|
|
1
|
+
import { Cart, CartItem, CartItemOption, FullOrderType, GuestItem, MenuItem, NutritionalInfo, OrderChannel, OrderTenders, OrderType, OrderTypeMap, ServiceTypeMap, SimpleCart, TenderType, TenderTypeMap } from '../types';
|
|
2
2
|
export declare const orderTypeNamesMap: OrderTypeMap;
|
|
3
3
|
export declare const normalizeOrderType: (orderType: FullOrderType) => OrderType;
|
|
4
4
|
export declare const serviceTypeNamesMap: ServiceTypeMap;
|
|
5
5
|
export declare const tenderTypeNamesMap: TenderTypeMap;
|
|
6
6
|
export declare const makeTenderTypeName: (tenderType: TenderType) => string;
|
|
7
7
|
export declare const makeChannelName: (channel: OrderChannel) => string | null | undefined;
|
|
8
|
+
export declare const calcCashBack: (tenders: OrderTenders) => string;
|
|
9
|
+
export declare const findCreditCardToken: (tenders: OrderTenders) => string | null;
|
|
8
10
|
export declare const calcPrices: (item: CartItem) => {
|
|
9
11
|
groups: {
|
|
10
12
|
quantity: number;
|
package/dist/cjs/utils/order.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getItemOptions = exports.calcCartCounts = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeCartItem = exports.calcNutrition = exports.calcPrices = exports.makeChannelName = exports.makeTenderTypeName = exports.tenderTypeNamesMap = exports.serviceTypeNamesMap = exports.normalizeOrderType = exports.orderTypeNamesMap = void 0;
|
|
3
|
+
exports.getItemOptions = exports.calcCartCounts = exports.makeSimpleCart = exports.decrementItem = exports.incrementItem = exports.removeItem = exports.addItem = exports.makeCartItemSignature = exports.makeCartItem = exports.calcNutrition = exports.calcPrices = exports.findCreditCardToken = exports.calcCashBack = exports.makeChannelName = exports.makeTenderTypeName = exports.tenderTypeNamesMap = exports.serviceTypeNamesMap = exports.normalizeOrderType = exports.orderTypeNamesMap = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var helpers_1 = require("./helpers");
|
|
6
6
|
exports.orderTypeNamesMap = {
|
|
@@ -50,6 +50,22 @@ var makeChannelName = function (channel) {
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
exports.makeChannelName = makeChannelName;
|
|
53
|
+
var calcCashBack = function (tenders) {
|
|
54
|
+
if (!tenders || !tenders.length)
|
|
55
|
+
return '0.00';
|
|
56
|
+
return tenders
|
|
57
|
+
.filter(function (i) { return i.tender_type === 'CASH'; })
|
|
58
|
+
.reduce(function (t, i) { return (t += i.cash ? parseFloat(i.cash.cash_back) : 0.0); }, 0.0)
|
|
59
|
+
.toFixed(2);
|
|
60
|
+
};
|
|
61
|
+
exports.calcCashBack = calcCashBack;
|
|
62
|
+
var findCreditCardToken = function (tenders) {
|
|
63
|
+
if (!tenders || !tenders.length)
|
|
64
|
+
return null;
|
|
65
|
+
var tender = tenders.find(function (i) { return i.tender_type === 'CREDIT'; });
|
|
66
|
+
return tender && tender.credit_card ? tender.credit_card.token : null;
|
|
67
|
+
};
|
|
68
|
+
exports.findCreditCardToken = findCreditCardToken;
|
|
53
69
|
var makeCartItemGroups = function (optionGroups, isEdit, soldOut) {
|
|
54
70
|
if (isEdit === void 0) { isEdit = false; }
|
|
55
71
|
if (soldOut === void 0) { soldOut = []; }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Employee, PunchesProcessed, PunchType, Timezone } from '../types';
|
|
2
|
+
export declare const punchTypes: {
|
|
3
|
+
PUNCH_IN: string;
|
|
4
|
+
BREAK_IN: string;
|
|
5
|
+
BREAK_OUT: string;
|
|
6
|
+
PUNCH_OUT: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const makePunchMessage: (employee: Employee, punch_type: PunchType) => string;
|
|
9
|
+
export declare const calcBreakSeconds: (breaks: PunchesProcessed) => number;
|
|
10
|
+
export declare const processPunchees: (employee: Employee, tz: Timezone) => {
|
|
11
|
+
department: string;
|
|
12
|
+
punchIn: import("../types").PunchProcessed | undefined;
|
|
13
|
+
punchOut: import("../types").PunchProcessed | undefined;
|
|
14
|
+
breaks: import("../types").PunchProcessed[];
|
|
15
|
+
breakOut: import("../types").PunchProcessed | null;
|
|
16
|
+
totalSeconds: number;
|
|
17
|
+
breakSeconds: number;
|
|
18
|
+
netSeconds: number;
|
|
19
|
+
}[] | null;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processPunchees = exports.calcBreakSeconds = exports.makePunchMessage = exports.punchTypes = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var date_fns_1 = require("date-fns");
|
|
6
|
+
var datetimes_1 = require("./datetimes");
|
|
7
|
+
exports.punchTypes = {
|
|
8
|
+
PUNCH_IN: 'PUNCH_IN',
|
|
9
|
+
BREAK_IN: 'BREAK_IN',
|
|
10
|
+
BREAK_OUT: 'BREAK_OUT',
|
|
11
|
+
PUNCH_OUT: 'PUNCH_OUT'
|
|
12
|
+
};
|
|
13
|
+
var makePunchMessage = function (employee, punch_type) {
|
|
14
|
+
var first_name = employee.first_name;
|
|
15
|
+
switch (punch_type) {
|
|
16
|
+
case exports.punchTypes.PUNCH_IN:
|
|
17
|
+
return "Hi, ".concat(first_name);
|
|
18
|
+
case exports.punchTypes.BREAK_OUT:
|
|
19
|
+
return "Enjoy your break, ".concat(first_name, "!");
|
|
20
|
+
case exports.punchTypes.BREAK_IN:
|
|
21
|
+
return "Welcome back, ".concat(first_name, "!");
|
|
22
|
+
case exports.punchTypes.PUNCH_OUT:
|
|
23
|
+
return "See you next time, ".concat(first_name, "!");
|
|
24
|
+
default:
|
|
25
|
+
return 'Invalid punch type';
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.makePunchMessage = makePunchMessage;
|
|
29
|
+
var calcBreakSeconds = function (breaks) {
|
|
30
|
+
var chunks = [];
|
|
31
|
+
var breaksCopy = tslib_1.__spreadArray([], breaks, true);
|
|
32
|
+
while (breaksCopy.length > 0) {
|
|
33
|
+
chunks.push(breaksCopy.splice(0, 2));
|
|
34
|
+
}
|
|
35
|
+
return chunks.reduce(function (t, _a) {
|
|
36
|
+
var breakIn = _a[0], breakOut = _a[1];
|
|
37
|
+
return breakIn && breakOut
|
|
38
|
+
? t + (0, date_fns_1.differenceInSeconds)(breakOut.date, breakIn.date)
|
|
39
|
+
: 0;
|
|
40
|
+
}, 0);
|
|
41
|
+
};
|
|
42
|
+
exports.calcBreakSeconds = calcBreakSeconds;
|
|
43
|
+
var processPunchees = function (employee, tz) {
|
|
44
|
+
var departments = employee.departments, punches = employee.punches;
|
|
45
|
+
if (!punches)
|
|
46
|
+
return null;
|
|
47
|
+
var chunks = [];
|
|
48
|
+
punches.forEach(function (punch) {
|
|
49
|
+
var department = departments.find(function (i) { return i.id === punch.department_id; });
|
|
50
|
+
if (!punch.created_at)
|
|
51
|
+
return;
|
|
52
|
+
var date = (0, datetimes_1.isoToDate)(punch.created_at, tz);
|
|
53
|
+
var newPunch = tslib_1.__assign(tslib_1.__assign({}, punch), { department: department, date: date });
|
|
54
|
+
var lastChunk = chunks[chunks.length - 1];
|
|
55
|
+
if (!lastChunk || newPunch.punch_type === exports.punchTypes.PUNCH_IN) {
|
|
56
|
+
chunks.push([newPunch]);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
lastChunk.push(newPunch);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return chunks.map(function (chunk) {
|
|
63
|
+
var _a;
|
|
64
|
+
var allBreaks = chunk.filter(function (i) {
|
|
65
|
+
return [exports.punchTypes.BREAK_IN, exports.punchTypes.BREAK_OUT].includes(i.punch_type);
|
|
66
|
+
});
|
|
67
|
+
var lastBreakOut = (Math.floor(allBreaks.length) / 2) * 2;
|
|
68
|
+
var breaks = allBreaks.slice(0, lastBreakOut);
|
|
69
|
+
var breakOut = allBreaks.length - breaks.length === 1
|
|
70
|
+
? allBreaks[allBreaks.length - 1]
|
|
71
|
+
: null;
|
|
72
|
+
var punchIn = chunk.find(function (i) { return i.punch_type === exports.punchTypes.PUNCH_IN; });
|
|
73
|
+
var punchOut = chunk.find(function (i) { return i.punch_type === exports.punchTypes.PUNCH_OUT; });
|
|
74
|
+
var outDate = punchOut
|
|
75
|
+
? punchOut.date
|
|
76
|
+
: breakOut
|
|
77
|
+
? breakOut.date
|
|
78
|
+
: (0, datetimes_1.currentLocalDate)(tz);
|
|
79
|
+
var totalSeconds = punchIn
|
|
80
|
+
? (0, date_fns_1.differenceInSeconds)(outDate, punchIn.date)
|
|
81
|
+
: 0;
|
|
82
|
+
var breakSeconds = (0, exports.calcBreakSeconds)(breaks);
|
|
83
|
+
var netSeconds = totalSeconds - breakSeconds;
|
|
84
|
+
var department = punchIn ? ((_a = punchIn.department) === null || _a === void 0 ? void 0 : _a.name) || 'n/a' : 'n/a';
|
|
85
|
+
return {
|
|
86
|
+
department: department,
|
|
87
|
+
punchIn: punchIn,
|
|
88
|
+
punchOut: punchOut,
|
|
89
|
+
breaks: breaks,
|
|
90
|
+
breakOut: breakOut,
|
|
91
|
+
totalSeconds: totalSeconds,
|
|
92
|
+
breakSeconds: breakSeconds,
|
|
93
|
+
netSeconds: netSeconds
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
exports.processPunchees = processPunchees;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Order, OrderCart } from '../types';
|
|
1
|
+
import { Order, OrderCart, RequestErrorAPI } from '../types';
|
|
2
|
+
export declare const emptyRefund: (error: RequestErrorAPI) => boolean;
|
|
2
3
|
export declare const makeRefundCartLookup: (cart: OrderCart) => Record<string, unknown>;
|
|
3
4
|
export declare const makeRefundLookup: (order: Order) => {
|
|
4
5
|
cart: Record<string, unknown>;
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeRefundLookup = exports.makeRefundCartLookup = void 0;
|
|
3
|
+
exports.makeRefundLookup = exports.makeRefundCartLookup = exports.emptyRefund = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var emptyRefund = function (error) {
|
|
6
|
+
if (!error || !error.params)
|
|
7
|
+
return false;
|
|
8
|
+
return Object.values(error.params).includes('Nothing to refund');
|
|
9
|
+
};
|
|
10
|
+
exports.emptyRefund = emptyRefund;
|
|
5
11
|
var makeRefundCartLookup = function (cart) {
|
|
6
12
|
var lookup = {};
|
|
7
13
|
cart.forEach(function (item) {
|
|
@@ -8,7 +8,7 @@ export declare enum SettingsActionType {
|
|
|
8
8
|
UpdateSetting = "settings/updateSetting",
|
|
9
9
|
UpdateSettings = "settings/updateSettings"
|
|
10
10
|
}
|
|
11
|
-
export declare const updateSetting: import("@reduxjs/toolkit").AsyncThunk<Settings, EntityType, {
|
|
11
|
+
export declare const updateSetting: import("@reduxjs/toolkit").AsyncThunk<Settings, void | EntityType, {
|
|
12
12
|
state: AppState;
|
|
13
13
|
rejectValue: RequestError;
|
|
14
14
|
}>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ISOStringOffset } from '../datetimes';
|
|
1
2
|
import { Money, NegativeMoney } from '../global';
|
|
2
3
|
export declare type PunchAuthType = 'PIN' | 'CARD';
|
|
3
4
|
export declare type PunchType = 'PUNCH_IN' | 'PUNCH_OUT' | 'BREAK_IN' | 'BREAK_OUT';
|
|
@@ -6,7 +7,7 @@ export interface Punch {
|
|
|
6
7
|
department_id: number;
|
|
7
8
|
punch_type: PunchType;
|
|
8
9
|
tips: Money;
|
|
9
|
-
created_at?:
|
|
10
|
+
created_at?: ISOStringOffset;
|
|
10
11
|
created_dt?: string;
|
|
11
12
|
}
|
|
12
13
|
export interface Department {
|
|
@@ -18,6 +19,11 @@ export interface Department {
|
|
|
18
19
|
overtime_pay_rate: string;
|
|
19
20
|
pay_rate: string;
|
|
20
21
|
}
|
|
22
|
+
export interface PunchProcessed extends Punch {
|
|
23
|
+
department?: Department;
|
|
24
|
+
date: Date;
|
|
25
|
+
}
|
|
26
|
+
export declare type PunchesProcessed = PunchProcessed[];
|
|
21
27
|
export declare type Role = 'Manager' | 'Cashier' | 'Employee';
|
|
22
28
|
export interface Employee {
|
|
23
29
|
employee_id: number;
|
|
@@ -29,3 +29,7 @@ export declare const handleRespError: (err: RequestErrorAPI | string) => {
|
|
|
29
29
|
};
|
|
30
30
|
export declare const hexToRgb: (hex: string) => number[];
|
|
31
31
|
export declare const makeContrastColor: (textColors: Record<string, string>, backgroundColor: string | null) => string | null;
|
|
32
|
+
declare type ThrottleArgs = string | number | Record<string, unknown>;
|
|
33
|
+
declare type ThrottleFunc = (...args: any) => void;
|
|
34
|
+
export declare function throttle(func: ThrottleFunc, delay: number): (args?: ThrottleArgs) => void;
|
|
35
|
+
export {};
|
|
@@ -111,3 +111,14 @@ export var makeContrastColor = function (textColors, backgroundColor) {
|
|
|
111
111
|
var foregroundColor = setForegroundColor(rgb);
|
|
112
112
|
return textColors[foregroundColor];
|
|
113
113
|
};
|
|
114
|
+
export function throttle(func, delay) {
|
|
115
|
+
var timeout = null;
|
|
116
|
+
return function (args) {
|
|
117
|
+
if (!timeout) {
|
|
118
|
+
timeout = setTimeout(function () {
|
|
119
|
+
func(args);
|
|
120
|
+
timeout = null;
|
|
121
|
+
}, delay);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Cart, CartItem, CartItemOption, FullOrderType, GuestItem, MenuItem, NutritionalInfo, OrderChannel, OrderType, OrderTypeMap, ServiceTypeMap, SimpleCart, TenderType, TenderTypeMap } from '../types';
|
|
1
|
+
import { Cart, CartItem, CartItemOption, FullOrderType, GuestItem, MenuItem, NutritionalInfo, OrderChannel, OrderTenders, OrderType, OrderTypeMap, ServiceTypeMap, SimpleCart, TenderType, TenderTypeMap } from '../types';
|
|
2
2
|
export declare const orderTypeNamesMap: OrderTypeMap;
|
|
3
3
|
export declare const normalizeOrderType: (orderType: FullOrderType) => OrderType;
|
|
4
4
|
export declare const serviceTypeNamesMap: ServiceTypeMap;
|
|
5
5
|
export declare const tenderTypeNamesMap: TenderTypeMap;
|
|
6
6
|
export declare const makeTenderTypeName: (tenderType: TenderType) => string;
|
|
7
7
|
export declare const makeChannelName: (channel: OrderChannel) => string | null | undefined;
|
|
8
|
+
export declare const calcCashBack: (tenders: OrderTenders) => string;
|
|
9
|
+
export declare const findCreditCardToken: (tenders: OrderTenders) => string | null;
|
|
8
10
|
export declare const calcPrices: (item: CartItem) => {
|
|
9
11
|
groups: {
|
|
10
12
|
quantity: number;
|
package/dist/esm/utils/order.js
CHANGED
|
@@ -44,6 +44,20 @@ export var makeChannelName = function (channel) {
|
|
|
44
44
|
return channel.type;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
+
export var calcCashBack = function (tenders) {
|
|
48
|
+
if (!tenders || !tenders.length)
|
|
49
|
+
return '0.00';
|
|
50
|
+
return tenders
|
|
51
|
+
.filter(function (i) { return i.tender_type === 'CASH'; })
|
|
52
|
+
.reduce(function (t, i) { return (t += i.cash ? parseFloat(i.cash.cash_back) : 0.0); }, 0.0)
|
|
53
|
+
.toFixed(2);
|
|
54
|
+
};
|
|
55
|
+
export var findCreditCardToken = function (tenders) {
|
|
56
|
+
if (!tenders || !tenders.length)
|
|
57
|
+
return null;
|
|
58
|
+
var tender = tenders.find(function (i) { return i.tender_type === 'CREDIT'; });
|
|
59
|
+
return tender && tender.credit_card ? tender.credit_card.token : null;
|
|
60
|
+
};
|
|
47
61
|
var makeCartItemGroups = function (optionGroups, isEdit, soldOut) {
|
|
48
62
|
if (isEdit === void 0) { isEdit = false; }
|
|
49
63
|
if (soldOut === void 0) { soldOut = []; }
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Employee, PunchesProcessed, PunchType, Timezone } from '../types';
|
|
2
|
+
export declare const punchTypes: {
|
|
3
|
+
PUNCH_IN: string;
|
|
4
|
+
BREAK_IN: string;
|
|
5
|
+
BREAK_OUT: string;
|
|
6
|
+
PUNCH_OUT: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const makePunchMessage: (employee: Employee, punch_type: PunchType) => string;
|
|
9
|
+
export declare const calcBreakSeconds: (breaks: PunchesProcessed) => number;
|
|
10
|
+
export declare const processPunchees: (employee: Employee, tz: Timezone) => {
|
|
11
|
+
department: string;
|
|
12
|
+
punchIn: import("../types").PunchProcessed | undefined;
|
|
13
|
+
punchOut: import("../types").PunchProcessed | undefined;
|
|
14
|
+
breaks: import("../types").PunchProcessed[];
|
|
15
|
+
breakOut: import("../types").PunchProcessed | null;
|
|
16
|
+
totalSeconds: number;
|
|
17
|
+
breakSeconds: number;
|
|
18
|
+
netSeconds: number;
|
|
19
|
+
}[] | null;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { __assign, __spreadArray } from "tslib";
|
|
2
|
+
import { differenceInSeconds } from 'date-fns';
|
|
3
|
+
import { currentLocalDate, isoToDate } from './datetimes';
|
|
4
|
+
export var punchTypes = {
|
|
5
|
+
PUNCH_IN: 'PUNCH_IN',
|
|
6
|
+
BREAK_IN: 'BREAK_IN',
|
|
7
|
+
BREAK_OUT: 'BREAK_OUT',
|
|
8
|
+
PUNCH_OUT: 'PUNCH_OUT'
|
|
9
|
+
};
|
|
10
|
+
export var makePunchMessage = function (employee, punch_type) {
|
|
11
|
+
var first_name = employee.first_name;
|
|
12
|
+
switch (punch_type) {
|
|
13
|
+
case punchTypes.PUNCH_IN:
|
|
14
|
+
return "Hi, ".concat(first_name);
|
|
15
|
+
case punchTypes.BREAK_OUT:
|
|
16
|
+
return "Enjoy your break, ".concat(first_name, "!");
|
|
17
|
+
case punchTypes.BREAK_IN:
|
|
18
|
+
return "Welcome back, ".concat(first_name, "!");
|
|
19
|
+
case punchTypes.PUNCH_OUT:
|
|
20
|
+
return "See you next time, ".concat(first_name, "!");
|
|
21
|
+
default:
|
|
22
|
+
return 'Invalid punch type';
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export var calcBreakSeconds = function (breaks) {
|
|
26
|
+
var chunks = [];
|
|
27
|
+
var breaksCopy = __spreadArray([], breaks, true);
|
|
28
|
+
while (breaksCopy.length > 0) {
|
|
29
|
+
chunks.push(breaksCopy.splice(0, 2));
|
|
30
|
+
}
|
|
31
|
+
return chunks.reduce(function (t, _a) {
|
|
32
|
+
var breakIn = _a[0], breakOut = _a[1];
|
|
33
|
+
return breakIn && breakOut
|
|
34
|
+
? t + differenceInSeconds(breakOut.date, breakIn.date)
|
|
35
|
+
: 0;
|
|
36
|
+
}, 0);
|
|
37
|
+
};
|
|
38
|
+
export var processPunchees = function (employee, tz) {
|
|
39
|
+
var departments = employee.departments, punches = employee.punches;
|
|
40
|
+
if (!punches)
|
|
41
|
+
return null;
|
|
42
|
+
var chunks = [];
|
|
43
|
+
punches.forEach(function (punch) {
|
|
44
|
+
var department = departments.find(function (i) { return i.id === punch.department_id; });
|
|
45
|
+
if (!punch.created_at)
|
|
46
|
+
return;
|
|
47
|
+
var date = isoToDate(punch.created_at, tz);
|
|
48
|
+
var newPunch = __assign(__assign({}, punch), { department: department, date: date });
|
|
49
|
+
var lastChunk = chunks[chunks.length - 1];
|
|
50
|
+
if (!lastChunk || newPunch.punch_type === punchTypes.PUNCH_IN) {
|
|
51
|
+
chunks.push([newPunch]);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
lastChunk.push(newPunch);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return chunks.map(function (chunk) {
|
|
58
|
+
var _a;
|
|
59
|
+
var allBreaks = chunk.filter(function (i) {
|
|
60
|
+
return [punchTypes.BREAK_IN, punchTypes.BREAK_OUT].includes(i.punch_type);
|
|
61
|
+
});
|
|
62
|
+
var lastBreakOut = (Math.floor(allBreaks.length) / 2) * 2;
|
|
63
|
+
var breaks = allBreaks.slice(0, lastBreakOut);
|
|
64
|
+
var breakOut = allBreaks.length - breaks.length === 1
|
|
65
|
+
? allBreaks[allBreaks.length - 1]
|
|
66
|
+
: null;
|
|
67
|
+
var punchIn = chunk.find(function (i) { return i.punch_type === punchTypes.PUNCH_IN; });
|
|
68
|
+
var punchOut = chunk.find(function (i) { return i.punch_type === punchTypes.PUNCH_OUT; });
|
|
69
|
+
var outDate = punchOut
|
|
70
|
+
? punchOut.date
|
|
71
|
+
: breakOut
|
|
72
|
+
? breakOut.date
|
|
73
|
+
: currentLocalDate(tz);
|
|
74
|
+
var totalSeconds = punchIn
|
|
75
|
+
? differenceInSeconds(outDate, punchIn.date)
|
|
76
|
+
: 0;
|
|
77
|
+
var breakSeconds = calcBreakSeconds(breaks);
|
|
78
|
+
var netSeconds = totalSeconds - breakSeconds;
|
|
79
|
+
var department = punchIn ? ((_a = punchIn.department) === null || _a === void 0 ? void 0 : _a.name) || 'n/a' : 'n/a';
|
|
80
|
+
return {
|
|
81
|
+
department: department,
|
|
82
|
+
punchIn: punchIn,
|
|
83
|
+
punchOut: punchOut,
|
|
84
|
+
breaks: breaks,
|
|
85
|
+
breakOut: breakOut,
|
|
86
|
+
totalSeconds: totalSeconds,
|
|
87
|
+
breakSeconds: breakSeconds,
|
|
88
|
+
netSeconds: netSeconds
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Order, OrderCart } from '../types';
|
|
1
|
+
import { Order, OrderCart, RequestErrorAPI } from '../types';
|
|
2
|
+
export declare const emptyRefund: (error: RequestErrorAPI) => boolean;
|
|
2
3
|
export declare const makeRefundCartLookup: (cart: OrderCart) => Record<string, unknown>;
|
|
3
4
|
export declare const makeRefundLookup: (order: Order) => {
|
|
4
5
|
cart: Record<string, unknown>;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
|
+
export var emptyRefund = function (error) {
|
|
3
|
+
if (!error || !error.params)
|
|
4
|
+
return false;
|
|
5
|
+
return Object.values(error.params).includes('Nothing to refund');
|
|
6
|
+
};
|
|
2
7
|
export var makeRefundCartLookup = function (cart) {
|
|
3
8
|
var lookup = {};
|
|
4
9
|
cart.forEach(function (item) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/store",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.59",
|
|
4
4
|
"description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our in-store POS API",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|