@open-tender/store 0.3.92 → 0.3.94
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/pos.d.ts +12 -4
- package/dist/cjs/slices/pos.js +55 -9
- package/dist/cjs/slices/refund.d.ts +2 -2
- package/dist/cjs/types/api/checkout.d.ts +1 -1
- package/dist/cjs/types/api/refund.d.ts +6 -6
- package/dist/cjs/utils/refunds.d.ts +3 -1
- package/dist/cjs/utils/refunds.js +97 -43
- package/dist/esm/slices/pos.d.ts +12 -4
- package/dist/esm/slices/pos.js +52 -8
- package/dist/esm/slices/refund.d.ts +2 -2
- package/dist/esm/types/api/checkout.d.ts +1 -1
- package/dist/esm/types/api/refund.d.ts +6 -6
- package/dist/esm/utils/refunds.d.ts +3 -1
- package/dist/esm/utils/refunds.js +95 -42
- package/package.json +1 -1
package/dist/cjs/slices/pos.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cashier, DeviceColorScheme, DeviceFontSize, Employee, RequestError } from '../types';
|
|
1
|
+
import { Cashier, DeviceColorScheme, DeviceFontSize, Employee, Order, RequestError } from '../types';
|
|
2
2
|
import { AppState } from '../app';
|
|
3
3
|
export interface PosState {
|
|
4
4
|
cashier: Cashier | null;
|
|
@@ -10,12 +10,15 @@ export interface PosState {
|
|
|
10
10
|
notes: string | null;
|
|
11
11
|
fontSize: DeviceFontSize;
|
|
12
12
|
colorScheme: DeviceColorScheme;
|
|
13
|
+
order: Order | null;
|
|
14
|
+
refund: Order | null;
|
|
13
15
|
loading: string | null;
|
|
14
16
|
error: RequestError;
|
|
15
17
|
}
|
|
16
|
-
export declare enum
|
|
18
|
+
export declare enum PosActionType {
|
|
17
19
|
FetchOfflineStatus = "pos/fetchOfflineStatus",
|
|
18
|
-
UpdateOfflineStatus = "pos/updateOfflineStatus"
|
|
20
|
+
UpdateOfflineStatus = "pos/updateOfflineStatus",
|
|
21
|
+
PrintPosOrder = "pos/printPosOrder"
|
|
19
22
|
}
|
|
20
23
|
export declare const fetchOfflineStatus: import("@reduxjs/toolkit").AsyncThunk<boolean, void, {
|
|
21
24
|
state: AppState;
|
|
@@ -25,7 +28,10 @@ export declare const updateOfflineStatus: import("@reduxjs/toolkit").AsyncThunk<
|
|
|
25
28
|
state: AppState;
|
|
26
29
|
rejectValue: RequestError;
|
|
27
30
|
}>;
|
|
28
|
-
export declare const
|
|
31
|
+
export declare const printPosOrder: import("@reduxjs/toolkit").AsyncThunk<void, string, {
|
|
32
|
+
state: AppState;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const resetPos: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, setLastOrderId: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setMenuPage: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosName: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosNotes: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setCashier: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setManager: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosFontSize: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosColorScheme: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosOrder: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosRefund: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
29
35
|
export declare const selectPos: (state: AppState) => PosState;
|
|
30
36
|
export declare const selectLastOrderId: (state: AppState) => string | null;
|
|
31
37
|
export declare const selectMenuPage: (state: AppState) => number | null;
|
|
@@ -40,6 +46,8 @@ export declare const selectCashier: (state: AppState) => {
|
|
|
40
46
|
};
|
|
41
47
|
export declare const selectManager: (state: AppState) => Employee | null;
|
|
42
48
|
export declare const selectIsOffline: (state: AppState) => boolean;
|
|
49
|
+
export declare const selectPosOrder: (state: AppState) => Order | null;
|
|
50
|
+
export declare const selectPosRefund: (state: AppState) => Order | null;
|
|
43
51
|
export declare const selectPosFontSize: (state: AppState) => DeviceFontSize;
|
|
44
52
|
export declare const selectPosColorScheme: (state: AppState) => DeviceColorScheme;
|
|
45
53
|
export declare const posReducer: import("redux").Reducer<PosState, import("redux").AnyAction>;
|
package/dist/cjs/slices/pos.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.posReducer = exports.selectPosColorScheme = exports.selectPosFontSize = exports.selectIsOffline = exports.selectManager = exports.selectCashier = exports.selectPosNotes = exports.selectPosName = exports.selectMenuPage = exports.selectLastOrderId = exports.selectPos = exports.setPosColorScheme = exports.setPosFontSize = exports.setManager = exports.setCashier = exports.setPosNotes = exports.setPosName = exports.setMenuPage = exports.setLastOrderId = exports.resetPos = exports.updateOfflineStatus = exports.fetchOfflineStatus = exports.
|
|
4
|
+
exports.posReducer = exports.selectPosColorScheme = exports.selectPosFontSize = exports.selectPosRefund = exports.selectPosOrder = exports.selectIsOffline = exports.selectManager = exports.selectCashier = exports.selectPosNotes = exports.selectPosName = exports.selectMenuPage = exports.selectLastOrderId = exports.selectPos = exports.setPosRefund = exports.setPosOrder = exports.setPosColorScheme = exports.setPosFontSize = exports.setManager = exports.setCashier = exports.setPosNotes = exports.setPosName = exports.setMenuPage = exports.setLastOrderId = exports.resetPos = exports.printPosOrder = exports.updateOfflineStatus = exports.fetchOfflineStatus = exports.PosActionType = void 0;
|
|
5
5
|
var tslib_1 = require("tslib");
|
|
6
6
|
var toolkit_1 = require("@reduxjs/toolkit");
|
|
7
7
|
var types_1 = require("./types");
|
|
8
8
|
var config_1 = require("./config");
|
|
9
9
|
var utils_1 = require("../utils");
|
|
10
|
+
var alerts_1 = require("./alerts");
|
|
10
11
|
var initialState = {
|
|
11
12
|
cashier: null,
|
|
12
13
|
manager: null,
|
|
@@ -17,15 +18,18 @@ var initialState = {
|
|
|
17
18
|
notes: '',
|
|
18
19
|
fontSize: 'medium',
|
|
19
20
|
colorScheme: 'dark',
|
|
21
|
+
order: null,
|
|
22
|
+
refund: null,
|
|
20
23
|
loading: 'idle',
|
|
21
24
|
error: null
|
|
22
25
|
};
|
|
23
|
-
var
|
|
24
|
-
(function (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
var PosActionType;
|
|
27
|
+
(function (PosActionType) {
|
|
28
|
+
PosActionType["FetchOfflineStatus"] = "pos/fetchOfflineStatus";
|
|
29
|
+
PosActionType["UpdateOfflineStatus"] = "pos/updateOfflineStatus";
|
|
30
|
+
PosActionType["PrintPosOrder"] = "pos/printPosOrder";
|
|
31
|
+
})(PosActionType = exports.PosActionType || (exports.PosActionType = {}));
|
|
32
|
+
exports.fetchOfflineStatus = (0, toolkit_1.createAsyncThunk)(PosActionType.FetchOfflineStatus, function (_, _a) {
|
|
29
33
|
var getState = _a.getState, rejectWithValue = _a.rejectWithValue;
|
|
30
34
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
31
35
|
var api, response, err_1;
|
|
@@ -46,7 +50,7 @@ exports.fetchOfflineStatus = (0, toolkit_1.createAsyncThunk)(POSActionType.Fetch
|
|
|
46
50
|
});
|
|
47
51
|
});
|
|
48
52
|
});
|
|
49
|
-
exports.updateOfflineStatus = (0, toolkit_1.createAsyncThunk)(
|
|
53
|
+
exports.updateOfflineStatus = (0, toolkit_1.createAsyncThunk)(PosActionType.UpdateOfflineStatus, function (is_offline, _a) {
|
|
50
54
|
var getState = _a.getState, rejectWithValue = _a.rejectWithValue;
|
|
51
55
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
52
56
|
var api, response, err_2;
|
|
@@ -67,6 +71,29 @@ exports.updateOfflineStatus = (0, toolkit_1.createAsyncThunk)(POSActionType.Upda
|
|
|
67
71
|
});
|
|
68
72
|
});
|
|
69
73
|
});
|
|
74
|
+
exports.printPosOrder = (0, toolkit_1.createAsyncThunk)(PosActionType.PrintPosOrder, function (orderId, _a) {
|
|
75
|
+
var getState = _a.getState, dispatch = _a.dispatch;
|
|
76
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
77
|
+
var api, err_3, detail;
|
|
78
|
+
return tslib_1.__generator(this, function (_b) {
|
|
79
|
+
switch (_b.label) {
|
|
80
|
+
case 0:
|
|
81
|
+
_b.trys.push([0, 2, , 3]);
|
|
82
|
+
api = getState().config.api;
|
|
83
|
+
return [4 /*yield*/, api.postReceipt(orderId)];
|
|
84
|
+
case 1:
|
|
85
|
+
_b.sent();
|
|
86
|
+
return [3 /*break*/, 3];
|
|
87
|
+
case 2:
|
|
88
|
+
err_3 = _b.sent();
|
|
89
|
+
detail = err_3.detail;
|
|
90
|
+
dispatch((0, alerts_1.addAlert)(detail));
|
|
91
|
+
return [3 /*break*/, 3];
|
|
92
|
+
case 3: return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
});
|
|
70
97
|
var posSlice = (0, toolkit_1.createSlice)({
|
|
71
98
|
name: types_1.ReducerType.Pos,
|
|
72
99
|
initialState: initialState,
|
|
@@ -98,6 +125,12 @@ var posSlice = (0, toolkit_1.createSlice)({
|
|
|
98
125
|
},
|
|
99
126
|
setPosColorScheme: function (state, action) {
|
|
100
127
|
state.colorScheme = action.payload;
|
|
128
|
+
},
|
|
129
|
+
setPosOrder: function (state, action) {
|
|
130
|
+
state.order = action.payload;
|
|
131
|
+
},
|
|
132
|
+
setPosRefund: function (state, action) {
|
|
133
|
+
state.refund = action.payload;
|
|
101
134
|
}
|
|
102
135
|
},
|
|
103
136
|
extraReducers: function (builder) {
|
|
@@ -125,10 +158,19 @@ var posSlice = (0, toolkit_1.createSlice)({
|
|
|
125
158
|
.addCase(exports.updateOfflineStatus.rejected, function (state, action) {
|
|
126
159
|
state.loading = 'idle';
|
|
127
160
|
state.error = action.payload;
|
|
161
|
+
})
|
|
162
|
+
.addCase(exports.printPosOrder.fulfilled, function (state) {
|
|
163
|
+
state.loading = 'idle';
|
|
164
|
+
})
|
|
165
|
+
.addCase(exports.printPosOrder.pending, function (state) {
|
|
166
|
+
state.loading = 'pending';
|
|
167
|
+
})
|
|
168
|
+
.addCase(exports.printPosOrder.rejected, function (state) {
|
|
169
|
+
state.loading = 'idle';
|
|
128
170
|
});
|
|
129
171
|
}
|
|
130
172
|
});
|
|
131
|
-
exports.resetPos = (_a = posSlice.actions, _a.resetPos), exports.setLastOrderId = _a.setLastOrderId, exports.setMenuPage = _a.setMenuPage, exports.setPosName = _a.setPosName, exports.setPosNotes = _a.setPosNotes, exports.setCashier = _a.setCashier, exports.setManager = _a.setManager, exports.setPosFontSize = _a.setPosFontSize, exports.setPosColorScheme = _a.setPosColorScheme;
|
|
173
|
+
exports.resetPos = (_a = posSlice.actions, _a.resetPos), exports.setLastOrderId = _a.setLastOrderId, exports.setMenuPage = _a.setMenuPage, exports.setPosName = _a.setPosName, exports.setPosNotes = _a.setPosNotes, exports.setCashier = _a.setCashier, exports.setManager = _a.setManager, exports.setPosFontSize = _a.setPosFontSize, exports.setPosColorScheme = _a.setPosColorScheme, exports.setPosOrder = _a.setPosOrder, exports.setPosRefund = _a.setPosRefund;
|
|
132
174
|
var selectPos = function (state) { return state.pos; };
|
|
133
175
|
exports.selectPos = selectPos;
|
|
134
176
|
var selectLastOrderId = function (state) { return state.pos.lastOrderId; };
|
|
@@ -155,6 +197,10 @@ var selectManager = function (state) { return state.pos.manager; };
|
|
|
155
197
|
exports.selectManager = selectManager;
|
|
156
198
|
var selectIsOffline = function (state) { return state.pos.isOffline; };
|
|
157
199
|
exports.selectIsOffline = selectIsOffline;
|
|
200
|
+
var selectPosOrder = function (state) { return state.pos.order; };
|
|
201
|
+
exports.selectPosOrder = selectPosOrder;
|
|
202
|
+
var selectPosRefund = function (state) { return state.pos.refund; };
|
|
203
|
+
exports.selectPosRefund = selectPosRefund;
|
|
158
204
|
var selectPosFontSize = function (state) { return state.pos.fontSize; };
|
|
159
205
|
exports.selectPosFontSize = selectPosFontSize;
|
|
160
206
|
var selectPosColorScheme = function (state) { return state.pos.colorScheme; };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Order, Orders,
|
|
1
|
+
import { Order, Orders, RefundArgs, RequestError, RequestStatus } from '../types';
|
|
2
2
|
import { AppState } from '../app';
|
|
3
3
|
export interface RefundState {
|
|
4
4
|
previous: Orders | null;
|
|
5
|
-
refund: Order |
|
|
5
|
+
refund: Order | null;
|
|
6
6
|
loading: RequestStatus;
|
|
7
7
|
error: RequestError;
|
|
8
8
|
compeleted: boolean;
|
|
@@ -9,12 +9,12 @@ export interface RefundSurcharge {
|
|
|
9
9
|
}
|
|
10
10
|
export declare type RefundSurcharges = Array<RefundSurcharge>;
|
|
11
11
|
export interface Refund {
|
|
12
|
-
full_refund
|
|
13
|
-
all_taxes
|
|
14
|
-
items
|
|
15
|
-
surcharges
|
|
16
|
-
tip
|
|
17
|
-
shipping
|
|
12
|
+
full_refund?: boolean;
|
|
13
|
+
all_taxes?: boolean;
|
|
14
|
+
items?: RefundItems;
|
|
15
|
+
surcharges?: RefundSurcharges;
|
|
16
|
+
tip?: Money;
|
|
17
|
+
shipping?: Money;
|
|
18
18
|
}
|
|
19
19
|
export interface RefundArgs {
|
|
20
20
|
orderId: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Order, OrderCart, RequestErrorAPI } from '../types';
|
|
1
|
+
import { Order, OrderCart, Orders, RequestErrorAPI } from '../types';
|
|
2
2
|
export declare const emptyRefund: (error: RequestErrorAPI) => boolean;
|
|
3
3
|
export declare const makeRefundCartLookup: (cart: OrderCart) => Record<string, unknown>;
|
|
4
4
|
export declare const makeRefundLookup: (order: Order) => {
|
|
5
5
|
cart: Record<string, unknown>;
|
|
6
|
+
gift_cards: Record<string, `${number}.${number}`>;
|
|
6
7
|
surcharges: Record<string, `${number}.${number}`>;
|
|
7
8
|
discounts: Record<string, `${number}.${number}`>;
|
|
8
9
|
taxes: Record<string, `${number}.${number}`>;
|
|
@@ -16,3 +17,4 @@ export declare const makeRefundLookup: (order: Order) => {
|
|
|
16
17
|
shipping: `${number}.${number}`;
|
|
17
18
|
total: `${number}.${number}`;
|
|
18
19
|
};
|
|
20
|
+
export declare const makeNetOrder: (order: Order, refunds: Orders) => Order;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeRefundLookup = exports.makeRefundCartLookup = exports.emptyRefund = void 0;
|
|
3
|
+
exports.makeNetOrder = exports.makeRefundLookup = exports.makeRefundCartLookup = exports.emptyRefund = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var emptyRefund = function (error) {
|
|
6
6
|
if (!error || !error.params)
|
|
@@ -23,6 +23,14 @@ var makeRefundCartLookup = function (cart) {
|
|
|
23
23
|
return lookup;
|
|
24
24
|
};
|
|
25
25
|
exports.makeRefundCartLookup = makeRefundCartLookup;
|
|
26
|
+
var makeGiftCardAmountsLookup = function (gift_cards) {
|
|
27
|
+
return gift_cards.reduce(function (obj, i) {
|
|
28
|
+
var _a;
|
|
29
|
+
if (!i.code)
|
|
30
|
+
return obj;
|
|
31
|
+
return tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.code] = i.amount, _a));
|
|
32
|
+
}, {});
|
|
33
|
+
};
|
|
26
34
|
var makeSurchargeAmountsLookup = function (surcharges) {
|
|
27
35
|
return surcharges.reduce(function (obj, i) {
|
|
28
36
|
var _a;
|
|
@@ -35,24 +43,24 @@ var makeDiscountsAmountsLookup = function (discounts) {
|
|
|
35
43
|
return (tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
|
|
36
44
|
}, {});
|
|
37
45
|
};
|
|
38
|
-
var makeTaxesAmountsLookup = function (
|
|
39
|
-
return
|
|
46
|
+
var makeTaxesAmountsLookup = function (taxes) {
|
|
47
|
+
return taxes.reduce(function (obj, i) {
|
|
40
48
|
var _a;
|
|
41
49
|
return (tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
|
|
42
50
|
}, {});
|
|
43
51
|
};
|
|
44
|
-
var makeTendersAmountsLookup = function (
|
|
45
|
-
return
|
|
52
|
+
var makeTendersAmountsLookup = function (tenders) {
|
|
53
|
+
return tenders.reduce(function (obj, i, idx) {
|
|
46
54
|
var _a;
|
|
47
55
|
return (tslib_1.__assign(tslib_1.__assign({}, obj), (_a = {}, _a[i.tender_index || idx] = i.amount, _a)));
|
|
48
56
|
}, {});
|
|
49
57
|
};
|
|
50
58
|
var makeRefundLookup = function (order) {
|
|
51
|
-
var cart = order.cart, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
|
|
59
|
+
var cart = order.cart, gift_cards = order.gift_cards, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
|
|
52
60
|
var subtotal = totals.subtotal, gift_card = totals.gift_card, surcharge = totals.surcharge, discount = totals.discount, tax = totals.tax, tip = totals.tip, shipping = totals.shipping, total = totals.total;
|
|
53
61
|
return {
|
|
54
62
|
cart: (0, exports.makeRefundCartLookup)(cart),
|
|
55
|
-
|
|
63
|
+
gift_cards: makeGiftCardAmountsLookup(gift_cards),
|
|
56
64
|
surcharges: makeSurchargeAmountsLookup(surcharges),
|
|
57
65
|
discounts: makeDiscountsAmountsLookup(discounts),
|
|
58
66
|
taxes: makeTaxesAmountsLookup(taxes),
|
|
@@ -68,11 +76,19 @@ var makeRefundLookup = function (order) {
|
|
|
68
76
|
};
|
|
69
77
|
};
|
|
70
78
|
exports.makeRefundLookup = makeRefundLookup;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
var adjustAmount = function (amount, refundAmount) {
|
|
80
|
+
return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
|
|
81
|
+
};
|
|
82
|
+
var adjustAmountNegative = function (amount, refundAmount) {
|
|
83
|
+
return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
|
|
84
|
+
};
|
|
85
|
+
// export const adjustAmounts = (
|
|
86
|
+
// order: Order,
|
|
87
|
+
// lookup: Record<string, Record<string, Money> | Record<string, unknown>>,
|
|
88
|
+
// list: 'gift_cards' | 'surcharges' | 'discounts' | 'taxes' | 'tenders',
|
|
89
|
+
// key: 'id' | 'code' = 'id'
|
|
90
|
+
// ) => {
|
|
91
|
+
// if (!list || !order[list]) return order
|
|
76
92
|
// order[list].forEach(i => {
|
|
77
93
|
// const amount = lookup[list][i[key]]
|
|
78
94
|
// if (amount) i.amount = adjustAmount(i.amount, amount)
|
|
@@ -89,34 +105,72 @@ exports.makeRefundLookup = makeRefundLookup;
|
|
|
89
105
|
// 'shipping',
|
|
90
106
|
// 'total'
|
|
91
107
|
// ]
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
108
|
+
var makeNetOrder = function (order, refunds) {
|
|
109
|
+
if (!refunds || !refunds.length)
|
|
110
|
+
return order;
|
|
111
|
+
var copy = JSON.parse(JSON.stringify(order));
|
|
112
|
+
refunds.forEach(function (refund) {
|
|
113
|
+
var lookup = (0, exports.makeRefundLookup)(refund);
|
|
114
|
+
// adjust cart
|
|
115
|
+
copy.cart.forEach(function (i) {
|
|
116
|
+
var item = lookup.cart[i.line_no];
|
|
117
|
+
if (item) {
|
|
118
|
+
i.quantity -= item.quantity;
|
|
119
|
+
i.price_total = adjustAmount(i.price_total, item.price_total);
|
|
120
|
+
}
|
|
121
|
+
if (i.quantity === 0 && i.groups) {
|
|
122
|
+
i.groups.forEach(function (group) {
|
|
123
|
+
return group.options.forEach(function (option) {
|
|
124
|
+
option.quantity = 0;
|
|
125
|
+
option.price_total = '0.00';
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
// adjust arrays
|
|
131
|
+
// copy = adjustAmounts(copy, lookup, 'gift_cards', 'code')
|
|
132
|
+
// copy = adjustAmounts(copy, lookup, 'surcharges')
|
|
133
|
+
// copy = adjustAmounts(copy, lookup, 'discounts')
|
|
134
|
+
// copy = adjustAmounts(copy, lookup, 'taxes')
|
|
135
|
+
// copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index')
|
|
136
|
+
order.gift_cards.forEach(function (i) {
|
|
137
|
+
var amount = i.code ? lookup.gift_cards[i.code] : null;
|
|
138
|
+
if (amount)
|
|
139
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
140
|
+
});
|
|
141
|
+
order.surcharges.forEach(function (i) {
|
|
142
|
+
var amount = lookup.surcharges[i.id];
|
|
143
|
+
if (amount)
|
|
144
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
145
|
+
});
|
|
146
|
+
order.discounts.forEach(function (i) {
|
|
147
|
+
var amount = lookup.discounts[i.id];
|
|
148
|
+
if (amount)
|
|
149
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
150
|
+
});
|
|
151
|
+
order.taxes.forEach(function (i) {
|
|
152
|
+
var amount = lookup.taxes[i.id];
|
|
153
|
+
if (amount)
|
|
154
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
155
|
+
});
|
|
156
|
+
order.tenders.forEach(function (i, idx) {
|
|
157
|
+
var amount = lookup.tenders[i.tender_index || idx];
|
|
158
|
+
if (amount)
|
|
159
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
160
|
+
});
|
|
161
|
+
// adjust totals
|
|
162
|
+
// amounts.forEach(i => {
|
|
163
|
+
// copy.totals[i] = adjustAmount(copy.totals[i], lookup[i])
|
|
164
|
+
// })
|
|
165
|
+
copy.totals.subtotal = adjustAmount(copy.totals.subtotal, lookup.subtotal);
|
|
166
|
+
copy.totals.gift_card = adjustAmount(copy.totals.gift_card, lookup.gift_card);
|
|
167
|
+
copy.totals.surcharge = adjustAmount(copy.totals.surcharge, lookup.surcharge);
|
|
168
|
+
copy.totals.discount = adjustAmountNegative(copy.totals.discount, lookup.discount);
|
|
169
|
+
copy.totals.tax = adjustAmount(copy.totals.tax, lookup.tax);
|
|
170
|
+
copy.totals.tip = adjustAmount(copy.totals.tip, lookup.tip);
|
|
171
|
+
copy.totals.shipping = adjustAmount(copy.totals.shipping, lookup.shipping);
|
|
172
|
+
copy.totals.total = adjustAmount(copy.totals.total, lookup.total);
|
|
173
|
+
});
|
|
174
|
+
return copy;
|
|
175
|
+
};
|
|
176
|
+
exports.makeNetOrder = makeNetOrder;
|
package/dist/esm/slices/pos.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Cashier, DeviceColorScheme, DeviceFontSize, Employee, RequestError } from '../types';
|
|
1
|
+
import { Cashier, DeviceColorScheme, DeviceFontSize, Employee, Order, RequestError } from '../types';
|
|
2
2
|
import { AppState } from '../app';
|
|
3
3
|
export interface PosState {
|
|
4
4
|
cashier: Cashier | null;
|
|
@@ -10,12 +10,15 @@ export interface PosState {
|
|
|
10
10
|
notes: string | null;
|
|
11
11
|
fontSize: DeviceFontSize;
|
|
12
12
|
colorScheme: DeviceColorScheme;
|
|
13
|
+
order: Order | null;
|
|
14
|
+
refund: Order | null;
|
|
13
15
|
loading: string | null;
|
|
14
16
|
error: RequestError;
|
|
15
17
|
}
|
|
16
|
-
export declare enum
|
|
18
|
+
export declare enum PosActionType {
|
|
17
19
|
FetchOfflineStatus = "pos/fetchOfflineStatus",
|
|
18
|
-
UpdateOfflineStatus = "pos/updateOfflineStatus"
|
|
20
|
+
UpdateOfflineStatus = "pos/updateOfflineStatus",
|
|
21
|
+
PrintPosOrder = "pos/printPosOrder"
|
|
19
22
|
}
|
|
20
23
|
export declare const fetchOfflineStatus: import("@reduxjs/toolkit").AsyncThunk<boolean, void, {
|
|
21
24
|
state: AppState;
|
|
@@ -25,7 +28,10 @@ export declare const updateOfflineStatus: import("@reduxjs/toolkit").AsyncThunk<
|
|
|
25
28
|
state: AppState;
|
|
26
29
|
rejectValue: RequestError;
|
|
27
30
|
}>;
|
|
28
|
-
export declare const
|
|
31
|
+
export declare const printPosOrder: import("@reduxjs/toolkit").AsyncThunk<void, string, {
|
|
32
|
+
state: AppState;
|
|
33
|
+
}>;
|
|
34
|
+
export declare const resetPos: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, setLastOrderId: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setMenuPage: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosName: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosNotes: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setCashier: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setManager: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosFontSize: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosColorScheme: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosOrder: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>, setPosRefund: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
29
35
|
export declare const selectPos: (state: AppState) => PosState;
|
|
30
36
|
export declare const selectLastOrderId: (state: AppState) => string | null;
|
|
31
37
|
export declare const selectMenuPage: (state: AppState) => number | null;
|
|
@@ -40,6 +46,8 @@ export declare const selectCashier: (state: AppState) => {
|
|
|
40
46
|
};
|
|
41
47
|
export declare const selectManager: (state: AppState) => Employee | null;
|
|
42
48
|
export declare const selectIsOffline: (state: AppState) => boolean;
|
|
49
|
+
export declare const selectPosOrder: (state: AppState) => Order | null;
|
|
50
|
+
export declare const selectPosRefund: (state: AppState) => Order | null;
|
|
43
51
|
export declare const selectPosFontSize: (state: AppState) => DeviceFontSize;
|
|
44
52
|
export declare const selectPosColorScheme: (state: AppState) => DeviceColorScheme;
|
|
45
53
|
export declare const posReducer: import("redux").Reducer<PosState, import("redux").AnyAction>;
|
package/dist/esm/slices/pos.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
|
|
4
4
|
import { ReducerType } from './types';
|
|
5
5
|
import { selectTimezone } from './config';
|
|
6
6
|
import { currentLocalDateStr } from '../utils';
|
|
7
|
+
import { addAlert } from './alerts';
|
|
7
8
|
var initialState = {
|
|
8
9
|
cashier: null,
|
|
9
10
|
manager: null,
|
|
@@ -14,15 +15,18 @@ var initialState = {
|
|
|
14
15
|
notes: '',
|
|
15
16
|
fontSize: 'medium',
|
|
16
17
|
colorScheme: 'dark',
|
|
18
|
+
order: null,
|
|
19
|
+
refund: null,
|
|
17
20
|
loading: 'idle',
|
|
18
21
|
error: null
|
|
19
22
|
};
|
|
20
|
-
export var
|
|
21
|
-
(function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
export var PosActionType;
|
|
24
|
+
(function (PosActionType) {
|
|
25
|
+
PosActionType["FetchOfflineStatus"] = "pos/fetchOfflineStatus";
|
|
26
|
+
PosActionType["UpdateOfflineStatus"] = "pos/updateOfflineStatus";
|
|
27
|
+
PosActionType["PrintPosOrder"] = "pos/printPosOrder";
|
|
28
|
+
})(PosActionType || (PosActionType = {}));
|
|
29
|
+
export var fetchOfflineStatus = createAsyncThunk(PosActionType.FetchOfflineStatus, function (_, _a) {
|
|
26
30
|
var getState = _a.getState, rejectWithValue = _a.rejectWithValue;
|
|
27
31
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
28
32
|
var api, response, err_1;
|
|
@@ -43,7 +47,7 @@ export var fetchOfflineStatus = createAsyncThunk(POSActionType.FetchOfflineStatu
|
|
|
43
47
|
});
|
|
44
48
|
});
|
|
45
49
|
});
|
|
46
|
-
export var updateOfflineStatus = createAsyncThunk(
|
|
50
|
+
export var updateOfflineStatus = createAsyncThunk(PosActionType.UpdateOfflineStatus, function (is_offline, _a) {
|
|
47
51
|
var getState = _a.getState, rejectWithValue = _a.rejectWithValue;
|
|
48
52
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
49
53
|
var api, response, err_2;
|
|
@@ -64,6 +68,29 @@ export var updateOfflineStatus = createAsyncThunk(POSActionType.UpdateOfflineSta
|
|
|
64
68
|
});
|
|
65
69
|
});
|
|
66
70
|
});
|
|
71
|
+
export var printPosOrder = createAsyncThunk(PosActionType.PrintPosOrder, function (orderId, _a) {
|
|
72
|
+
var getState = _a.getState, dispatch = _a.dispatch;
|
|
73
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
+
var api, err_3, detail;
|
|
75
|
+
return __generator(this, function (_b) {
|
|
76
|
+
switch (_b.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
_b.trys.push([0, 2, , 3]);
|
|
79
|
+
api = getState().config.api;
|
|
80
|
+
return [4 /*yield*/, api.postReceipt(orderId)];
|
|
81
|
+
case 1:
|
|
82
|
+
_b.sent();
|
|
83
|
+
return [3 /*break*/, 3];
|
|
84
|
+
case 2:
|
|
85
|
+
err_3 = _b.sent();
|
|
86
|
+
detail = err_3.detail;
|
|
87
|
+
dispatch(addAlert(detail));
|
|
88
|
+
return [3 /*break*/, 3];
|
|
89
|
+
case 3: return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
67
94
|
var posSlice = createSlice({
|
|
68
95
|
name: ReducerType.Pos,
|
|
69
96
|
initialState: initialState,
|
|
@@ -95,6 +122,12 @@ var posSlice = createSlice({
|
|
|
95
122
|
},
|
|
96
123
|
setPosColorScheme: function (state, action) {
|
|
97
124
|
state.colorScheme = action.payload;
|
|
125
|
+
},
|
|
126
|
+
setPosOrder: function (state, action) {
|
|
127
|
+
state.order = action.payload;
|
|
128
|
+
},
|
|
129
|
+
setPosRefund: function (state, action) {
|
|
130
|
+
state.refund = action.payload;
|
|
98
131
|
}
|
|
99
132
|
},
|
|
100
133
|
extraReducers: function (builder) {
|
|
@@ -122,10 +155,19 @@ var posSlice = createSlice({
|
|
|
122
155
|
.addCase(updateOfflineStatus.rejected, function (state, action) {
|
|
123
156
|
state.loading = 'idle';
|
|
124
157
|
state.error = action.payload;
|
|
158
|
+
})
|
|
159
|
+
.addCase(printPosOrder.fulfilled, function (state) {
|
|
160
|
+
state.loading = 'idle';
|
|
161
|
+
})
|
|
162
|
+
.addCase(printPosOrder.pending, function (state) {
|
|
163
|
+
state.loading = 'pending';
|
|
164
|
+
})
|
|
165
|
+
.addCase(printPosOrder.rejected, function (state) {
|
|
166
|
+
state.loading = 'idle';
|
|
125
167
|
});
|
|
126
168
|
}
|
|
127
169
|
});
|
|
128
|
-
export var resetPos = (_a = posSlice.actions, _a.resetPos), setLastOrderId = _a.setLastOrderId, setMenuPage = _a.setMenuPage, setPosName = _a.setPosName, setPosNotes = _a.setPosNotes, setCashier = _a.setCashier, setManager = _a.setManager, setPosFontSize = _a.setPosFontSize, setPosColorScheme = _a.setPosColorScheme;
|
|
170
|
+
export var resetPos = (_a = posSlice.actions, _a.resetPos), setLastOrderId = _a.setLastOrderId, setMenuPage = _a.setMenuPage, setPosName = _a.setPosName, setPosNotes = _a.setPosNotes, setCashier = _a.setCashier, setManager = _a.setManager, setPosFontSize = _a.setPosFontSize, setPosColorScheme = _a.setPosColorScheme, setPosOrder = _a.setPosOrder, setPosRefund = _a.setPosRefund;
|
|
129
171
|
export var selectPos = function (state) { return state.pos; };
|
|
130
172
|
export var selectLastOrderId = function (state) { return state.pos.lastOrderId; };
|
|
131
173
|
export var selectMenuPage = function (state) { return state.pos.page; };
|
|
@@ -144,6 +186,8 @@ export var selectCashier = function (state) {
|
|
|
144
186
|
};
|
|
145
187
|
export var selectManager = function (state) { return state.pos.manager; };
|
|
146
188
|
export var selectIsOffline = function (state) { return state.pos.isOffline; };
|
|
189
|
+
export var selectPosOrder = function (state) { return state.pos.order; };
|
|
190
|
+
export var selectPosRefund = function (state) { return state.pos.refund; };
|
|
147
191
|
export var selectPosFontSize = function (state) { return state.pos.fontSize; };
|
|
148
192
|
export var selectPosColorScheme = function (state) { return state.pos.colorScheme; };
|
|
149
193
|
export var posReducer = posSlice.reducer;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Order, Orders,
|
|
1
|
+
import { Order, Orders, RefundArgs, RequestError, RequestStatus } from '../types';
|
|
2
2
|
import { AppState } from '../app';
|
|
3
3
|
export interface RefundState {
|
|
4
4
|
previous: Orders | null;
|
|
5
|
-
refund: Order |
|
|
5
|
+
refund: Order | null;
|
|
6
6
|
loading: RequestStatus;
|
|
7
7
|
error: RequestError;
|
|
8
8
|
compeleted: boolean;
|
|
@@ -9,12 +9,12 @@ export interface RefundSurcharge {
|
|
|
9
9
|
}
|
|
10
10
|
export declare type RefundSurcharges = Array<RefundSurcharge>;
|
|
11
11
|
export interface Refund {
|
|
12
|
-
full_refund
|
|
13
|
-
all_taxes
|
|
14
|
-
items
|
|
15
|
-
surcharges
|
|
16
|
-
tip
|
|
17
|
-
shipping
|
|
12
|
+
full_refund?: boolean;
|
|
13
|
+
all_taxes?: boolean;
|
|
14
|
+
items?: RefundItems;
|
|
15
|
+
surcharges?: RefundSurcharges;
|
|
16
|
+
tip?: Money;
|
|
17
|
+
shipping?: Money;
|
|
18
18
|
}
|
|
19
19
|
export interface RefundArgs {
|
|
20
20
|
orderId: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Order, OrderCart, RequestErrorAPI } from '../types';
|
|
1
|
+
import { Order, OrderCart, Orders, RequestErrorAPI } from '../types';
|
|
2
2
|
export declare const emptyRefund: (error: RequestErrorAPI) => boolean;
|
|
3
3
|
export declare const makeRefundCartLookup: (cart: OrderCart) => Record<string, unknown>;
|
|
4
4
|
export declare const makeRefundLookup: (order: Order) => {
|
|
5
5
|
cart: Record<string, unknown>;
|
|
6
|
+
gift_cards: Record<string, `${number}.${number}`>;
|
|
6
7
|
surcharges: Record<string, `${number}.${number}`>;
|
|
7
8
|
discounts: Record<string, `${number}.${number}`>;
|
|
8
9
|
taxes: Record<string, `${number}.${number}`>;
|
|
@@ -16,3 +17,4 @@ export declare const makeRefundLookup: (order: Order) => {
|
|
|
16
17
|
shipping: `${number}.${number}`;
|
|
17
18
|
total: `${number}.${number}`;
|
|
18
19
|
};
|
|
20
|
+
export declare const makeNetOrder: (order: Order, refunds: Orders) => Order;
|
|
@@ -18,6 +18,14 @@ export var makeRefundCartLookup = function (cart) {
|
|
|
18
18
|
});
|
|
19
19
|
return lookup;
|
|
20
20
|
};
|
|
21
|
+
var makeGiftCardAmountsLookup = function (gift_cards) {
|
|
22
|
+
return gift_cards.reduce(function (obj, i) {
|
|
23
|
+
var _a;
|
|
24
|
+
if (!i.code)
|
|
25
|
+
return obj;
|
|
26
|
+
return __assign(__assign({}, obj), (_a = {}, _a[i.code] = i.amount, _a));
|
|
27
|
+
}, {});
|
|
28
|
+
};
|
|
21
29
|
var makeSurchargeAmountsLookup = function (surcharges) {
|
|
22
30
|
return surcharges.reduce(function (obj, i) {
|
|
23
31
|
var _a;
|
|
@@ -30,24 +38,24 @@ var makeDiscountsAmountsLookup = function (discounts) {
|
|
|
30
38
|
return (__assign(__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
|
|
31
39
|
}, {});
|
|
32
40
|
};
|
|
33
|
-
var makeTaxesAmountsLookup = function (
|
|
34
|
-
return
|
|
41
|
+
var makeTaxesAmountsLookup = function (taxes) {
|
|
42
|
+
return taxes.reduce(function (obj, i) {
|
|
35
43
|
var _a;
|
|
36
44
|
return (__assign(__assign({}, obj), (_a = {}, _a[i.id] = i.amount, _a)));
|
|
37
45
|
}, {});
|
|
38
46
|
};
|
|
39
|
-
var makeTendersAmountsLookup = function (
|
|
40
|
-
return
|
|
47
|
+
var makeTendersAmountsLookup = function (tenders) {
|
|
48
|
+
return tenders.reduce(function (obj, i, idx) {
|
|
41
49
|
var _a;
|
|
42
50
|
return (__assign(__assign({}, obj), (_a = {}, _a[i.tender_index || idx] = i.amount, _a)));
|
|
43
51
|
}, {});
|
|
44
52
|
};
|
|
45
53
|
export var makeRefundLookup = function (order) {
|
|
46
|
-
var cart = order.cart, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
|
|
54
|
+
var cart = order.cart, gift_cards = order.gift_cards, surcharges = order.surcharges, discounts = order.discounts, taxes = order.taxes, totals = order.totals, tenders = order.tenders;
|
|
47
55
|
var subtotal = totals.subtotal, gift_card = totals.gift_card, surcharge = totals.surcharge, discount = totals.discount, tax = totals.tax, tip = totals.tip, shipping = totals.shipping, total = totals.total;
|
|
48
56
|
return {
|
|
49
57
|
cart: makeRefundCartLookup(cart),
|
|
50
|
-
|
|
58
|
+
gift_cards: makeGiftCardAmountsLookup(gift_cards),
|
|
51
59
|
surcharges: makeSurchargeAmountsLookup(surcharges),
|
|
52
60
|
discounts: makeDiscountsAmountsLookup(discounts),
|
|
53
61
|
taxes: makeTaxesAmountsLookup(taxes),
|
|
@@ -62,11 +70,19 @@ export var makeRefundLookup = function (order) {
|
|
|
62
70
|
total: total
|
|
63
71
|
};
|
|
64
72
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
var adjustAmount = function (amount, refundAmount) {
|
|
74
|
+
return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
|
|
75
|
+
};
|
|
76
|
+
var adjustAmountNegative = function (amount, refundAmount) {
|
|
77
|
+
return (parseFloat(amount) + parseFloat(refundAmount)).toFixed(2);
|
|
78
|
+
};
|
|
79
|
+
// export const adjustAmounts = (
|
|
80
|
+
// order: Order,
|
|
81
|
+
// lookup: Record<string, Record<string, Money> | Record<string, unknown>>,
|
|
82
|
+
// list: 'gift_cards' | 'surcharges' | 'discounts' | 'taxes' | 'tenders',
|
|
83
|
+
// key: 'id' | 'code' = 'id'
|
|
84
|
+
// ) => {
|
|
85
|
+
// if (!list || !order[list]) return order
|
|
70
86
|
// order[list].forEach(i => {
|
|
71
87
|
// const amount = lookup[list][i[key]]
|
|
72
88
|
// if (amount) i.amount = adjustAmount(i.amount, amount)
|
|
@@ -83,34 +99,71 @@ export var makeRefundLookup = function (order) {
|
|
|
83
99
|
// 'shipping',
|
|
84
100
|
// 'total'
|
|
85
101
|
// ]
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
export var makeNetOrder = function (order, refunds) {
|
|
103
|
+
if (!refunds || !refunds.length)
|
|
104
|
+
return order;
|
|
105
|
+
var copy = JSON.parse(JSON.stringify(order));
|
|
106
|
+
refunds.forEach(function (refund) {
|
|
107
|
+
var lookup = makeRefundLookup(refund);
|
|
108
|
+
// adjust cart
|
|
109
|
+
copy.cart.forEach(function (i) {
|
|
110
|
+
var item = lookup.cart[i.line_no];
|
|
111
|
+
if (item) {
|
|
112
|
+
i.quantity -= item.quantity;
|
|
113
|
+
i.price_total = adjustAmount(i.price_total, item.price_total);
|
|
114
|
+
}
|
|
115
|
+
if (i.quantity === 0 && i.groups) {
|
|
116
|
+
i.groups.forEach(function (group) {
|
|
117
|
+
return group.options.forEach(function (option) {
|
|
118
|
+
option.quantity = 0;
|
|
119
|
+
option.price_total = '0.00';
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
// adjust arrays
|
|
125
|
+
// copy = adjustAmounts(copy, lookup, 'gift_cards', 'code')
|
|
126
|
+
// copy = adjustAmounts(copy, lookup, 'surcharges')
|
|
127
|
+
// copy = adjustAmounts(copy, lookup, 'discounts')
|
|
128
|
+
// copy = adjustAmounts(copy, lookup, 'taxes')
|
|
129
|
+
// copy = adjustAmounts(copy, lookup, 'tenders', 'tender_index')
|
|
130
|
+
order.gift_cards.forEach(function (i) {
|
|
131
|
+
var amount = i.code ? lookup.gift_cards[i.code] : null;
|
|
132
|
+
if (amount)
|
|
133
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
134
|
+
});
|
|
135
|
+
order.surcharges.forEach(function (i) {
|
|
136
|
+
var amount = lookup.surcharges[i.id];
|
|
137
|
+
if (amount)
|
|
138
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
139
|
+
});
|
|
140
|
+
order.discounts.forEach(function (i) {
|
|
141
|
+
var amount = lookup.discounts[i.id];
|
|
142
|
+
if (amount)
|
|
143
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
144
|
+
});
|
|
145
|
+
order.taxes.forEach(function (i) {
|
|
146
|
+
var amount = lookup.taxes[i.id];
|
|
147
|
+
if (amount)
|
|
148
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
149
|
+
});
|
|
150
|
+
order.tenders.forEach(function (i, idx) {
|
|
151
|
+
var amount = lookup.tenders[i.tender_index || idx];
|
|
152
|
+
if (amount)
|
|
153
|
+
i.amount = adjustAmount(i.amount, amount);
|
|
154
|
+
});
|
|
155
|
+
// adjust totals
|
|
156
|
+
// amounts.forEach(i => {
|
|
157
|
+
// copy.totals[i] = adjustAmount(copy.totals[i], lookup[i])
|
|
158
|
+
// })
|
|
159
|
+
copy.totals.subtotal = adjustAmount(copy.totals.subtotal, lookup.subtotal);
|
|
160
|
+
copy.totals.gift_card = adjustAmount(copy.totals.gift_card, lookup.gift_card);
|
|
161
|
+
copy.totals.surcharge = adjustAmount(copy.totals.surcharge, lookup.surcharge);
|
|
162
|
+
copy.totals.discount = adjustAmountNegative(copy.totals.discount, lookup.discount);
|
|
163
|
+
copy.totals.tax = adjustAmount(copy.totals.tax, lookup.tax);
|
|
164
|
+
copy.totals.tip = adjustAmount(copy.totals.tip, lookup.tip);
|
|
165
|
+
copy.totals.shipping = adjustAmount(copy.totals.shipping, lookup.shipping);
|
|
166
|
+
copy.totals.total = adjustAmount(copy.totals.total, lookup.total);
|
|
167
|
+
});
|
|
168
|
+
return copy;
|
|
169
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/store",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.94",
|
|
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",
|