meemup-library 1.5.18 → 1.5.20
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/controllers/OrderToolController.js +2 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/interfaces/ICalculateFeeResult.d.ts +2 -0
- package/dist/interfaces/management/bundle-product/bundle-product.d.ts +0 -1
- package/dist/interfaces/management/bundle-product/bundle-product.js +1 -1
- package/dist/interfaces/pos/IPointOfSaleOrderItem.d.ts +2 -1
- package/dist/interfaces/pos/IPointOfSaleOrderItem.js +27 -1
- package/dist/interfaces/pos/IPointOfSaleSaveOrder.d.ts +1 -0
- package/package.json +2 -2
- package/dist/controllers/ProductModalController.d.ts +0 -34
- package/dist/controllers/ProductModalController.js +0 -399
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export * from "./controllers/MoneyController";
|
|
|
7
7
|
export * from "./controllers/OrderScreenController";
|
|
8
8
|
export * from "./controllers/PhoneController";
|
|
9
9
|
export * from "./controllers/PrintContentController";
|
|
10
|
-
export * from "./controllers/ProductModalController";
|
|
11
10
|
export * from "./controllers/ToolController";
|
|
12
11
|
export * from "./controllers/ZoneController";
|
|
13
12
|
export * from "./controllers/KitchenController";
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,6 @@ export * from "./controllers/MoneyController";
|
|
|
7
7
|
export * from "./controllers/OrderScreenController";
|
|
8
8
|
export * from "./controllers/PhoneController";
|
|
9
9
|
export * from "./controllers/PrintContentController";
|
|
10
|
-
export * from "./controllers/ProductModalController";
|
|
11
10
|
export * from "./controllers/ToolController";
|
|
12
11
|
export * from "./controllers/ZoneController";
|
|
13
12
|
export * from "./controllers/KitchenController";
|
|
@@ -5,7 +5,7 @@ interface IPointOfSaleOrderItem {
|
|
|
5
5
|
productId: number | null;
|
|
6
6
|
bundleId: number | null;
|
|
7
7
|
bundleGroup: string;
|
|
8
|
-
|
|
8
|
+
bundleRatio: number;
|
|
9
9
|
title: string;
|
|
10
10
|
quantity: number;
|
|
11
11
|
price: number;
|
|
@@ -29,3 +29,4 @@ interface IPointOfSaleOrderItem {
|
|
|
29
29
|
discount?: number;
|
|
30
30
|
}
|
|
31
31
|
export default IPointOfSaleOrderItem;
|
|
32
|
+
export declare const initPointOfSaleOrderItem: IPointOfSaleOrderItem;
|
|
@@ -1 +1,27 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export const initPointOfSaleOrderItem = {
|
|
2
|
+
id: -1,
|
|
3
|
+
categoryId: -1,
|
|
4
|
+
productId: -1,
|
|
5
|
+
bundleId: null,
|
|
6
|
+
bundleGroup: "",
|
|
7
|
+
bundleRatio: 1,
|
|
8
|
+
title: "",
|
|
9
|
+
quantity: 1,
|
|
10
|
+
price: 0,
|
|
11
|
+
note: "",
|
|
12
|
+
extras: [],
|
|
13
|
+
extrasNames: "",
|
|
14
|
+
totalAmount: 0,
|
|
15
|
+
minOrderQuantity: 1,
|
|
16
|
+
maxOrderQuantity: 99,
|
|
17
|
+
imageUrl: "",
|
|
18
|
+
relatedItemId: null,
|
|
19
|
+
relatedProductId: null,
|
|
20
|
+
additionalText: "",
|
|
21
|
+
promotionItem: false,
|
|
22
|
+
promotionId: -1,
|
|
23
|
+
stampCardBonusItem: false,
|
|
24
|
+
taxable: false,
|
|
25
|
+
productName: "",
|
|
26
|
+
tags: []
|
|
27
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meemup-library",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"remove:one": "rimraf dist",
|
|
12
12
|
"remove:two": "rimraf ./src/dist",
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
-
"commit": "git add . && git commit -m \"version.1.5.
|
|
14
|
+
"commit": "git add . && git commit -m \"version.1.5.20\" && git push origin "
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"/dist"
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import EnumOrderType from "../enums/EnumOrderType";
|
|
2
|
-
import IExtra from "../interfaces/IExtra";
|
|
3
|
-
import ISelectedExtraItem from "../interfaces/ISelectedExtraItem";
|
|
4
|
-
import ISelectedProductExtra from "../interfaces/ISelectedProductExtra";
|
|
5
|
-
import ITextValue from "../interfaces/ITextValue";
|
|
6
|
-
import TBaseExtra from "../types/TBaseExtra";
|
|
7
|
-
import IPointOfSaleOrderItem from "../interfaces/pos/IPointOfSaleOrderItem";
|
|
8
|
-
import IProduct from "../interfaces/IProduct";
|
|
9
|
-
import IDProductExtra from "../interfaces/database/IDProductExtra";
|
|
10
|
-
import IExtraItem from "../interfaces/IExtraItem";
|
|
11
|
-
declare const _default: {
|
|
12
|
-
getExtraSelectedItems(list: ISelectedProductExtra[], extraId: number): ISelectedExtraItem[];
|
|
13
|
-
canAddToBasket(product: IProduct, selected: ISelectedProductExtra[], extras: IExtra[]): boolean;
|
|
14
|
-
productModalToBasketItem(product: IProduct, selectedExtraList: ISelectedProductExtra[], extras: IExtra[], count: number, price: number, note: string): IPointOfSaleOrderItem;
|
|
15
|
-
productName(product: IProduct): string;
|
|
16
|
-
productImage(product: IProduct): string;
|
|
17
|
-
productPrice(product: IProduct, orderType: EnumOrderType): number;
|
|
18
|
-
baseItem(list: ISelectedProductExtra[], extraList: IExtra[]): TBaseExtra;
|
|
19
|
-
defaultExtraOfProductToSelectedExtras(product: IProduct, extras: IExtra[]): ISelectedProductExtra[];
|
|
20
|
-
defaultExtraOfProductToBasketItem(product: IProduct, extras: IExtra[], orderType: EnumOrderType): IPointOfSaleOrderItem;
|
|
21
|
-
singleSelectExtraItemPrice: (extra: IExtra, base: TBaseExtra, item: IExtraItem) => number;
|
|
22
|
-
multiSelectExtraPrice: (extra: IExtra, base: TBaseExtra, item: IExtraItem, selectedList?: ISelectedExtraItem[]) => number;
|
|
23
|
-
multiSelectExtraItemOptions(item: IExtraItem, max: number, selectedList: ISelectedExtraItem[]): ITextValue[];
|
|
24
|
-
scaleSum(array?: ISelectedExtraItem[]): number;
|
|
25
|
-
calculatePrice(orderType: EnumOrderType, product: any, list: ISelectedProductExtra[], base: TBaseExtra, extraList: IExtra[]): number;
|
|
26
|
-
plusString(first: string, second: string): string;
|
|
27
|
-
getValidateExtras(extras: IDProductExtra[], extraSelected: ISelectedProductExtra[]): IDProductExtra[];
|
|
28
|
-
getProductExtras(pExtras: IDProductExtra[], sExtras: ISelectedProductExtra[], extras: IExtra[]): IExtra[];
|
|
29
|
-
quantitySum(array?: ISelectedExtraItem[]): number;
|
|
30
|
-
productMinAndMaxOptions(product: IProduct): ITextValue[];
|
|
31
|
-
sortByKey(array: any[], key: string, conditionForSort?: boolean): any[];
|
|
32
|
-
extraItemsSortAction: (a: IExtraItem, b: IExtraItem) => 0 | 1 | -1;
|
|
33
|
-
};
|
|
34
|
-
export default _default;
|
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
import EnumOrderType from "../enums/EnumOrderType";
|
|
2
|
-
import EnumSortMode from "../enums/EnumSortMode";
|
|
3
|
-
import EnumPizzaSide from "../enums/EnumPizzaSide";
|
|
4
|
-
import MoneyController from "./MoneyController";
|
|
5
|
-
export default new class ProductModalController {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.singleSelectExtraItemPrice = (extra, base, item) => {
|
|
8
|
-
var _a, _b, _c;
|
|
9
|
-
let p = item.price;
|
|
10
|
-
if (extra.numberOfFreeItems > 0)
|
|
11
|
-
return 0;
|
|
12
|
-
if (base[1] && ((_a = base[1]) === null || _a === void 0 ? void 0 : _a.increasingOtherExtraItemsPrice)) {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
if (+((_b = base[0]) === null || _b === void 0 ? void 0 : _b.extraId) === +extra.id)
|
|
15
|
-
return item.price;
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
const { increasingPriceType, increasingAmount, increasingPercentage } = (_c = base[0]) === null || _c === void 0 ? void 0 : _c.selected[0];
|
|
18
|
-
switch (increasingPriceType) {
|
|
19
|
-
case 1:
|
|
20
|
-
p += (item.price * increasingPercentage) / 100;
|
|
21
|
-
break;
|
|
22
|
-
case 2:
|
|
23
|
-
p += increasingAmount;
|
|
24
|
-
if (p < 0)
|
|
25
|
-
p = 0;
|
|
26
|
-
break;
|
|
27
|
-
default:
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return p;
|
|
32
|
-
};
|
|
33
|
-
this.multiSelectExtraPrice = (extra, base, item, selectedList = []) => {
|
|
34
|
-
var _a, _b, _c;
|
|
35
|
-
let _item = selectedList.find(i => i.id === item.id);
|
|
36
|
-
if (_item !== undefined) {
|
|
37
|
-
let p = +item.price;
|
|
38
|
-
if (base[1] && ((_a = base[1]) === null || _a === void 0 ? void 0 : _a.increasingOtherExtraItemsPrice)) {
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
if (+((_b = base[0]) === null || _b === void 0 ? void 0 : _b.extraId) === +extra.id)
|
|
41
|
-
return p;
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
const { increasingPriceType, increasingAmount, increasingPercentage } = (_c = base[0]) === null || _c === void 0 ? void 0 : _c.selected[0];
|
|
44
|
-
switch (increasingPriceType) {
|
|
45
|
-
case 1:
|
|
46
|
-
p += (item.price * increasingPercentage) / 100;
|
|
47
|
-
break;
|
|
48
|
-
case 2:
|
|
49
|
-
p += increasingAmount;
|
|
50
|
-
if (p < 0)
|
|
51
|
-
p = 0;
|
|
52
|
-
break;
|
|
53
|
-
default:
|
|
54
|
-
break;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (extra.choosablePizzaToppingsSides) {
|
|
58
|
-
if (this.scaleSum(selectedList) <= extra.numberOfFreeItems)
|
|
59
|
-
return 0;
|
|
60
|
-
let index = selectedList.findIndex((element) => +element.id === +item.id);
|
|
61
|
-
if (index === -1)
|
|
62
|
-
return p;
|
|
63
|
-
let sliceArray = selectedList.slice(0, index + 1);
|
|
64
|
-
if (this.scaleSum(sliceArray) <= extra.numberOfFreeItems)
|
|
65
|
-
return 0;
|
|
66
|
-
}
|
|
67
|
-
p = (+p) * _item.quantity;
|
|
68
|
-
if (_item.pizzaSide === EnumPizzaSide.left || _item.pizzaSide === EnumPizzaSide.right)
|
|
69
|
-
return MoneyController.round(p / 2);
|
|
70
|
-
return p;
|
|
71
|
-
}
|
|
72
|
-
return 0;
|
|
73
|
-
};
|
|
74
|
-
this.extraItemsSortAction = (a, b) => {
|
|
75
|
-
if (a.priority == b.priority)
|
|
76
|
-
return 0;
|
|
77
|
-
else if (a.priority > b.priority)
|
|
78
|
-
return 1;
|
|
79
|
-
else
|
|
80
|
-
return -1;
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
getExtraSelectedItems(list, extraId) {
|
|
84
|
-
let item = list.find(i => +i.extraId === extraId);
|
|
85
|
-
if (item)
|
|
86
|
-
return item.selected;
|
|
87
|
-
return [];
|
|
88
|
-
}
|
|
89
|
-
canAddToBasket(product, selected, extras) {
|
|
90
|
-
let flag = true;
|
|
91
|
-
product.extras.forEach((item) => {
|
|
92
|
-
let extra = extras.find(i => i.id === item.extraId);
|
|
93
|
-
if (extra && extra.required && (item.secondExtraId === null || selected.find(i => i.extraId === item.secondExtraId))) {
|
|
94
|
-
if (item.secondExtraId === null ||
|
|
95
|
-
selected.find((i) => i.extraId === item.secondExtraId &&
|
|
96
|
-
i.selected.find((j) => j.id === item.secondExtraItemId))) {
|
|
97
|
-
if (selected.find((i) => i.extraId === item.extraId) === undefined) {
|
|
98
|
-
flag = false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return flag;
|
|
104
|
-
}
|
|
105
|
-
productModalToBasketItem(product, selectedExtraList, extras, count, price, note) {
|
|
106
|
-
let list = this.sortByKey(selectedExtraList, "priority", product.chosenExtraItemsMode === EnumSortMode.BASED_ON_EXTRA_ITEMS_LIST)
|
|
107
|
-
.map((item) => {
|
|
108
|
-
if (product.chosenExtraItemsMode === EnumSortMode.BASED_ON_EXTRA_ITEMS_LIST)
|
|
109
|
-
item.selected = this.sortByKey(item.selected, "priority");
|
|
110
|
-
return item;
|
|
111
|
-
});
|
|
112
|
-
let extraItemList = [];
|
|
113
|
-
let itemIndex = 0;
|
|
114
|
-
list.forEach((extra) => {
|
|
115
|
-
extra.selected.forEach((extraItem) => {
|
|
116
|
-
var _a;
|
|
117
|
-
extraItemList.push({
|
|
118
|
-
id: itemIndex++,
|
|
119
|
-
extraId: extra.extraId,
|
|
120
|
-
extraItemId: extraItem.id,
|
|
121
|
-
totalAmount: extraItem.quantity * extraItem.price,
|
|
122
|
-
quantity: extraItem.quantity,
|
|
123
|
-
price: extraItem.price,
|
|
124
|
-
pizzaSide: extraItem.pizzaSide,
|
|
125
|
-
text: `${extraItem.quantity}x ${extraItem.title}`,
|
|
126
|
-
cartItemId: -1,
|
|
127
|
-
extraItemTitle: extraItem.title,
|
|
128
|
-
extraTitle: ((_a = extras.find(i => i.id === extra.extraId)) === null || _a === void 0 ? void 0 : _a.title) + "",
|
|
129
|
-
extraItemOptionId: extraItem.optionId,
|
|
130
|
-
extraItemOptionTitle: extraItem.optionTitle,
|
|
131
|
-
doNotPrintOnReceipt: extraItem.doNotPrintOnReceipt,
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
return {
|
|
136
|
-
id: -1,
|
|
137
|
-
categoryId: -1,
|
|
138
|
-
productId: product.id,
|
|
139
|
-
title: this.productName(product),
|
|
140
|
-
imageUrl: this.productImage(product),
|
|
141
|
-
price: MoneyController.round(price), //OrderScreenController.productPrice(product, orderType),
|
|
142
|
-
extras: extraItemList,
|
|
143
|
-
quantity: count,
|
|
144
|
-
totalAmount: MoneyController.round(count * price),
|
|
145
|
-
note: note,
|
|
146
|
-
maxOrderQuantity: product.maxOrderQuantity,
|
|
147
|
-
minOrderQuantity: product.minOrderQuantity,
|
|
148
|
-
extrasNames: extraItemList.map(i => i.text).join(", "),
|
|
149
|
-
promotionId: -1,
|
|
150
|
-
promotionItem: false,
|
|
151
|
-
relatedItemId: null,
|
|
152
|
-
relatedProductId: null,
|
|
153
|
-
additionalText: "",
|
|
154
|
-
stampCardBonusItem: false,
|
|
155
|
-
taxable: product.taxable,
|
|
156
|
-
productName: product.name,
|
|
157
|
-
tags: product.tags,
|
|
158
|
-
bundleGroup: "",
|
|
159
|
-
bundleId: null,
|
|
160
|
-
bundleMainItem: false,
|
|
161
|
-
discount: 0,
|
|
162
|
-
_id: ""
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
productName(product) {
|
|
166
|
-
return product.posName === "" ? product.name : product.posName;
|
|
167
|
-
}
|
|
168
|
-
productImage(product) {
|
|
169
|
-
return product.imageFullPath === null ? "" : product.imageFullPath;
|
|
170
|
-
}
|
|
171
|
-
productPrice(product, orderType) {
|
|
172
|
-
switch (orderType) {
|
|
173
|
-
case EnumOrderType.delivery:
|
|
174
|
-
return product.deliveryPrice;
|
|
175
|
-
case EnumOrderType.pickup:
|
|
176
|
-
return product.pickupPrice;
|
|
177
|
-
case EnumOrderType.dining:
|
|
178
|
-
return product.diningPrice;
|
|
179
|
-
default:
|
|
180
|
-
return 0;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
baseItem(list, extraList) {
|
|
184
|
-
let idList = list.map(i => i.extraId);
|
|
185
|
-
let productExtraList = extraList.filter(i => idList.includes(i.id) && i.increasingOtherExtraItemsPrice);
|
|
186
|
-
if (productExtraList.length > 0)
|
|
187
|
-
return [list.find(i => { var _a; return i.extraId === ((_a = productExtraList[0]) === null || _a === void 0 ? void 0 : _a.id); }), productExtraList[0]];
|
|
188
|
-
return [undefined, undefined];
|
|
189
|
-
}
|
|
190
|
-
defaultExtraOfProductToSelectedExtras(product, extras) {
|
|
191
|
-
let list = [];
|
|
192
|
-
let productDefaultExtraModel = product.defaultExtraItems;
|
|
193
|
-
let productExtraModelList = product.extras;
|
|
194
|
-
productDefaultExtraModel.forEach((value) => {
|
|
195
|
-
let item = productExtraModelList.find(i => i.extraId === value.extraId);
|
|
196
|
-
if (item) {
|
|
197
|
-
let extraModel = extras.find(i => i.id === (item === null || item === void 0 ? void 0 : item.extraId));
|
|
198
|
-
let selectedList = [];
|
|
199
|
-
if (extraModel !== undefined) {
|
|
200
|
-
value.items.forEach(it => {
|
|
201
|
-
var _a;
|
|
202
|
-
let extraItemModel = extraModel.items.find((i) => i.id === it.extraItemId);
|
|
203
|
-
if (extraItemModel !== undefined) {
|
|
204
|
-
selectedList.push({
|
|
205
|
-
priority: it.priority,
|
|
206
|
-
quantity: it.quantity,
|
|
207
|
-
pizzaSide: it.side,
|
|
208
|
-
id: it.extraItemId,
|
|
209
|
-
min: extraItemModel.min,
|
|
210
|
-
increasingPriceType: extraItemModel.increasingPriceType,
|
|
211
|
-
scale: extraItemModel.scale,
|
|
212
|
-
isDefaultSelected: extraItemModel.isDefaultSelected,
|
|
213
|
-
title: extraItemModel.title,
|
|
214
|
-
max: extraItemModel.max,
|
|
215
|
-
calories: extraItemModel.calories,
|
|
216
|
-
price: extraItemModel.price,
|
|
217
|
-
available: extraItemModel.available,
|
|
218
|
-
receiptTitle: extraItemModel.receiptTitle,
|
|
219
|
-
increasingAmount: extraItemModel.increasingAmount,
|
|
220
|
-
increasingPercentage: extraItemModel.increasingPercentage,
|
|
221
|
-
tags: extraItemModel.tags,
|
|
222
|
-
extraId: extraItemModel.extraId,
|
|
223
|
-
increasingValue: extraItemModel.increasingValue,
|
|
224
|
-
thumbnailImage: extraItemModel.thumbnailImage,
|
|
225
|
-
color: extraItemModel.color,
|
|
226
|
-
oldId: extraItemModel.oldId,
|
|
227
|
-
packagingCost: extraItemModel.packagingCost,
|
|
228
|
-
weight: extraItemModel.weight,
|
|
229
|
-
options: extraItemModel.options,
|
|
230
|
-
optionId: it.extraItemOptionId,
|
|
231
|
-
doNotPrintOnReceipt: extraItemModel.doNotPrintOnReceipt,
|
|
232
|
-
optionTitle: ((_a = extraItemModel.options.find(i => i.id === it.extraItemOptionId)) === null || _a === void 0 ? void 0 : _a.title) + ""
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
let newItem = {
|
|
238
|
-
extraId: item.extraId,
|
|
239
|
-
selected: selectedList,
|
|
240
|
-
showTypeText: item.showTypeText,
|
|
241
|
-
secondExtraId: item.secondExtraId,
|
|
242
|
-
priority: item.priority,
|
|
243
|
-
showType: item.showType,
|
|
244
|
-
availableTypeText: item.availableTypeText,
|
|
245
|
-
secondExtraItemId: item.secondExtraItemId,
|
|
246
|
-
availableType: item.availableType,
|
|
247
|
-
relatedExtraDisplayMode: item.relatedExtraDisplayMode,
|
|
248
|
-
expandedState: item.expandedState,
|
|
249
|
-
};
|
|
250
|
-
list.push(newItem);
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
return list;
|
|
254
|
-
}
|
|
255
|
-
defaultExtraOfProductToBasketItem(product, extras, orderType) {
|
|
256
|
-
let list = this.defaultExtraOfProductToSelectedExtras(product, extras);
|
|
257
|
-
let base = [undefined, undefined];
|
|
258
|
-
let count = product.minOrderQuantity;
|
|
259
|
-
let price = this.calculatePrice(orderType, product, list, base, extras);
|
|
260
|
-
return this.productModalToBasketItem(product, list, extras, count, price, "");
|
|
261
|
-
}
|
|
262
|
-
multiSelectExtraItemOptions(item, max, selectedList) {
|
|
263
|
-
let currentCount = this.quantitySum(selectedList.filter(i => i.id !== item.id));
|
|
264
|
-
let remind = max - currentCount;
|
|
265
|
-
let maxOption = remind < item.max ? remind : item.max;
|
|
266
|
-
let list = [];
|
|
267
|
-
for (let index = item.min; index <= maxOption; index++) {
|
|
268
|
-
list.push({
|
|
269
|
-
text: index + "X",
|
|
270
|
-
value: index
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
return list;
|
|
274
|
-
}
|
|
275
|
-
scaleSum(array = []) {
|
|
276
|
-
let s = 0;
|
|
277
|
-
array.forEach((item) => {
|
|
278
|
-
let weight = item["quantity"] * item["scale"];
|
|
279
|
-
if (item.pizzaSide === EnumPizzaSide.right || item.pizzaSide === EnumPizzaSide.left)
|
|
280
|
-
weight = parseInt((weight / 2) + "");
|
|
281
|
-
s += weight;
|
|
282
|
-
});
|
|
283
|
-
return s;
|
|
284
|
-
}
|
|
285
|
-
calculatePrice(orderType, product, list, base, extraList) {
|
|
286
|
-
var _a, _b;
|
|
287
|
-
let p = 0;
|
|
288
|
-
for (let i = 0; i < list.length; i++) {
|
|
289
|
-
const { selected, extraId } = list[i];
|
|
290
|
-
let _extra = extraList.find(i => i.id === extraId);
|
|
291
|
-
let free = 0;
|
|
292
|
-
for (let j = 0; j < selected.length; j++) {
|
|
293
|
-
const { price, quantity, scale, pizzaSide } = selected[j];
|
|
294
|
-
let pep = 0;
|
|
295
|
-
for (let k = 0; k < quantity; k++) {
|
|
296
|
-
// @ts-ignore
|
|
297
|
-
if (free < (_extra === null || _extra === void 0 ? void 0 : _extra.numberOfFreeItems)) {
|
|
298
|
-
free += scale;
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
let ep = 0;
|
|
302
|
-
switch (pizzaSide) {
|
|
303
|
-
case EnumPizzaSide.left:
|
|
304
|
-
//left
|
|
305
|
-
ep = price / 2;
|
|
306
|
-
break;
|
|
307
|
-
case EnumPizzaSide.right:
|
|
308
|
-
//right
|
|
309
|
-
ep = price / 2;
|
|
310
|
-
break;
|
|
311
|
-
case EnumPizzaSide.all:
|
|
312
|
-
//all
|
|
313
|
-
ep = price;
|
|
314
|
-
break;
|
|
315
|
-
default:
|
|
316
|
-
//unknown
|
|
317
|
-
ep = price;
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
if (base[0] && +((_a = base[0]) === null || _a === void 0 ? void 0 : _a.extraId) !== +extraId) {
|
|
321
|
-
const { increasingPriceType, increasingAmount, increasingPercentage } = (_b = base[0]) === null || _b === void 0 ? void 0 : _b.selected[0];
|
|
322
|
-
switch (increasingPriceType) {
|
|
323
|
-
case 1:
|
|
324
|
-
ep += ep * (increasingPercentage / 100);
|
|
325
|
-
break;
|
|
326
|
-
case 2:
|
|
327
|
-
ep += increasingAmount;
|
|
328
|
-
if (ep < 0)
|
|
329
|
-
ep = 0;
|
|
330
|
-
break;
|
|
331
|
-
default:
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
pep += ep;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
p += MoneyController.round(pep);
|
|
339
|
-
// console.log(selected[j].title, " : ", pep, " ==> ", MoneyController.round(pep));
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return MoneyController.round(p + this.productPrice(product, +orderType));
|
|
343
|
-
}
|
|
344
|
-
plusString(first, second) {
|
|
345
|
-
return `${first} ${second}`;
|
|
346
|
-
}
|
|
347
|
-
getValidateExtras(extras, extraSelected) {
|
|
348
|
-
let result = [];
|
|
349
|
-
extras.forEach(item => {
|
|
350
|
-
if (item.secondExtraId === null ||
|
|
351
|
-
(extraSelected.filter((i) => i.extraId === item.secondExtraId).length === 1 &&
|
|
352
|
-
extraSelected
|
|
353
|
-
.filter((i) => i.extraId === item.secondExtraId)[0]
|
|
354
|
-
.selected.filter((i) => i.id === item.secondExtraItemId).length === 1)) {
|
|
355
|
-
result.push(item);
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
return result;
|
|
359
|
-
}
|
|
360
|
-
getProductExtras(pExtras, sExtras, extras) {
|
|
361
|
-
let se = this.sortByKey(sExtras, "priority", true);
|
|
362
|
-
let pe = this.sortByKey(pExtras, "priority", true);
|
|
363
|
-
let itemsIdList = this.getValidateExtras(pe, se).map(i => i.extraId);
|
|
364
|
-
// let list: IExtra[] = extras.filter(i => itemsIdList.includes(+i.id));
|
|
365
|
-
let result = [];
|
|
366
|
-
itemsIdList.forEach((id) => {
|
|
367
|
-
let ext = extras.find(i => i.id === id);
|
|
368
|
-
if (ext)
|
|
369
|
-
result.push(ext);
|
|
370
|
-
});
|
|
371
|
-
return result;
|
|
372
|
-
}
|
|
373
|
-
quantitySum(array = []) {
|
|
374
|
-
let s = 0;
|
|
375
|
-
array.forEach((item) => {
|
|
376
|
-
s += item.quantity;
|
|
377
|
-
});
|
|
378
|
-
return s;
|
|
379
|
-
}
|
|
380
|
-
productMinAndMaxOptions(product) {
|
|
381
|
-
let list = [];
|
|
382
|
-
for (let index = product.minOrderQuantity; index <= product.maxOrderQuantity; index++) {
|
|
383
|
-
list.push({
|
|
384
|
-
text: index + "X",
|
|
385
|
-
value: index
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
return list;
|
|
389
|
-
}
|
|
390
|
-
sortByKey(array, key, conditionForSort = true) {
|
|
391
|
-
if (conditionForSort && Array.isArray(array))
|
|
392
|
-
return array.sort((a, b) => {
|
|
393
|
-
let x = a[key];
|
|
394
|
-
let y = b[key];
|
|
395
|
-
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
|
396
|
-
});
|
|
397
|
-
return array;
|
|
398
|
-
}
|
|
399
|
-
}();
|