meemup-library 1.2.69 → 1.2.71
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.
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import EnumOrderType from "../enums/EnumOrderType";
|
|
2
|
+
import IOrderItem from "../interfaces/order/IOrderItem";
|
|
3
|
+
import IPointOfSaleSetting from "../interfaces/IPointOfSaleSetting";
|
|
4
|
+
import IOrder from "../interfaces/order/IOrder";
|
|
5
|
+
import EnumPaymentType from "../enums/EnumPaymentType";
|
|
6
|
+
import IOrderDetailProduct from "../interfaces/print/IOrderDetailProduct";
|
|
7
|
+
import IOrderDetailProductsExtra from "../interfaces/print/IOrderDetailProductsExtra";
|
|
8
|
+
import IOrderExtraItem from "../interfaces/order/IOrderExtraItem";
|
|
9
|
+
import IZone from "../interfaces/IZone";
|
|
10
|
+
import IZoneCost from "../interfaces/IZoneCost";
|
|
11
|
+
import ILocation from "../interfaces/ILocation";
|
|
12
|
+
import ICalculateFeeResult from "../interfaces/ICalculateFeeResult";
|
|
13
|
+
import EnumChannels from "../enums/EnumChannels";
|
|
14
|
+
import IPointOfSaleSettingFee from "../interfaces/IPointOfSaleSettingFee";
|
|
15
|
+
import IPointOfSaleOrderSummary from "../interfaces/pos/IPointOfSaleOrderSummary";
|
|
16
|
+
import EnumCustomerMandatory from "../enums/EnumCustomerMandatory";
|
|
17
|
+
import IPointOfSaleSettingRewardProgram from "../interfaces/pos/IPointOfSaleSettingRewardProgram";
|
|
18
|
+
import ITextValue from "../interfaces/ITextValue";
|
|
19
|
+
export default class OrderToolController {
|
|
20
|
+
replaceItem(item: IOrderItem, items: IOrderItem[]): IOrderItem[];
|
|
21
|
+
paymentTypeText(order?: IOrder | IPointOfSaleOrderSummary): string;
|
|
22
|
+
getPaymentTypeText(paymentType: EnumPaymentType, orderType: EnumOrderType): string;
|
|
23
|
+
getPaymentStateText(order?: IOrder | IPointOfSaleOrderSummary): string;
|
|
24
|
+
getOrderTypeText(orderType: EnumOrderType): string;
|
|
25
|
+
getOrderChannelText(channel: EnumChannels): string;
|
|
26
|
+
orderTypeText(order: IOrder | undefined, additionalPickupInstructionsTypes: ITextValue[]): string;
|
|
27
|
+
builtOrderDeliveryCost(form: IOrder, zones: IZone[], checkDeliveryCoverageArea: boolean): IOrder;
|
|
28
|
+
calculateItemsAmount(list: IOrderItem[]): number;
|
|
29
|
+
calculateTax(taxPercentage: number, subTotal: number, discount: number, deliveryCost: number): number;
|
|
30
|
+
calculateDiscount(order: IOrder, subTotal: number): number;
|
|
31
|
+
calculateTip(order: IOrder, subTotal: number): number;
|
|
32
|
+
calculateReward(totalAmount: number, rewardProgram: IPointOfSaleSettingRewardProgram): number;
|
|
33
|
+
customerOrNull(order: IOrder): any;
|
|
34
|
+
locationOrNull(order: IOrder): {
|
|
35
|
+
longitude: number;
|
|
36
|
+
latitude: number;
|
|
37
|
+
} | null;
|
|
38
|
+
convertOrderExtraItemToOrderDetailProductsExtra(item: IOrderExtraItem): IOrderDetailProductsExtra;
|
|
39
|
+
convertOrderItemToOrderDetailProduct(item: IOrderItem, currency: string): IOrderDetailProduct;
|
|
40
|
+
createExtraNames(item: IOrderItem, currency: string): string;
|
|
41
|
+
createExtraItemText(item: IOrderExtraItem, currency: string): string;
|
|
42
|
+
roundCashAmount(price: number, rounding: any): {
|
|
43
|
+
newPrice: number;
|
|
44
|
+
roundingRate: number;
|
|
45
|
+
};
|
|
46
|
+
calcDeliveryCost: (displayTotalAmount: number, zone: IZone) => IZoneCost;
|
|
47
|
+
coveragesAddress(location: ILocation, zones: IZone[], checkDeliveryCoverageArea: boolean): boolean;
|
|
48
|
+
zonesThatCoverageLocation(location: ILocation, zones: IZone[]): IZone[];
|
|
49
|
+
calculateFee(companyFee: IPointOfSaleSettingFee, order: IOrder, orderAmount: number): ICalculateFeeResult;
|
|
50
|
+
formatSetting(_setting: IPointOfSaleSetting): IPointOfSaleSetting;
|
|
51
|
+
customerText(form: IOrder): string;
|
|
52
|
+
isMandatory(orderType: EnumOrderType, value: EnumCustomerMandatory): boolean;
|
|
53
|
+
private round;
|
|
54
|
+
}
|
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import EnumOrderType from "../enums/EnumOrderType";
|
|
2
|
+
import EnumDiscountType from "../enums/EnumDiscountType";
|
|
3
|
+
import { initOrder } from "../interfaces/order/IOrder";
|
|
4
|
+
import EnumTipType from "../enums/EnumTipType";
|
|
5
|
+
import EnumPaymentType from "../enums/EnumPaymentType";
|
|
6
|
+
import MoneyController from "../controllers/MoneyController";
|
|
7
|
+
import EnumPriceMidpointRounding from "../enums/EnumPriceMidpointRounding";
|
|
8
|
+
import EnumPaymentState from "../enums/EnumPaymentState";
|
|
9
|
+
import { CUSTOM_DELIVERY_ZONE_ID } from "../statics";
|
|
10
|
+
import ZoneController from "../controllers/ZoneController";
|
|
11
|
+
import EnumFeeCalculationMode from "../enums/EnumFeeCalculationMode";
|
|
12
|
+
import ToolController from "../controllers/ToolController";
|
|
13
|
+
import EnumPizzaSide from "../enums/EnumPizzaSide";
|
|
14
|
+
import PhoneController from "../controllers/PhoneController";
|
|
15
|
+
import EnumChannels from "../enums/EnumChannels";
|
|
16
|
+
import EnumCustomerMandatory from "../enums/EnumCustomerMandatory";
|
|
17
|
+
import EnumRewardPointType from "../enums/EnumRewardPointType";
|
|
18
|
+
export default class OrderToolController {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.calcDeliveryCost = (displayTotalAmount, zone) => {
|
|
21
|
+
if (displayTotalAmount >= zone.freeFrom)
|
|
22
|
+
return {
|
|
23
|
+
deliveryCost: 0,
|
|
24
|
+
duration: zone.additionalDeliveryTime,
|
|
25
|
+
zoneId: zone.id
|
|
26
|
+
};
|
|
27
|
+
return { deliveryCost: zone.deliveryCost, duration: zone.additionalDeliveryTime, zoneId: zone.id };
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
replaceItem(item, items) {
|
|
31
|
+
let index = items.findIndex(i => i.id === item.id);
|
|
32
|
+
if (index !== -1) {
|
|
33
|
+
items[index] = item;
|
|
34
|
+
}
|
|
35
|
+
return items;
|
|
36
|
+
}
|
|
37
|
+
paymentTypeText(order = initOrder) {
|
|
38
|
+
switch (order.paymentType) {
|
|
39
|
+
case EnumPaymentType.online:
|
|
40
|
+
return "Online";
|
|
41
|
+
case EnumPaymentType.cash:
|
|
42
|
+
return "Cash";
|
|
43
|
+
case EnumPaymentType.debitAt:
|
|
44
|
+
return "Debit machine";
|
|
45
|
+
case EnumPaymentType.debitMachine:
|
|
46
|
+
return "Debit machine";
|
|
47
|
+
case EnumPaymentType.terminal:
|
|
48
|
+
return "Terminal";
|
|
49
|
+
case EnumPaymentType.splitPayments:
|
|
50
|
+
return "Multi payment";
|
|
51
|
+
default:
|
|
52
|
+
return "None";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
getPaymentTypeText(paymentType, orderType) {
|
|
56
|
+
switch (paymentType) {
|
|
57
|
+
case EnumPaymentType.online:
|
|
58
|
+
return "Online";
|
|
59
|
+
case EnumPaymentType.cash:
|
|
60
|
+
return "Cash";
|
|
61
|
+
case EnumPaymentType.debitAt:
|
|
62
|
+
return orderType === EnumOrderType.delivery ? "Credit at door" : "In-store";
|
|
63
|
+
case EnumPaymentType.debitMachine:
|
|
64
|
+
return "Debit machine";
|
|
65
|
+
case EnumPaymentType.terminal:
|
|
66
|
+
return "Terminal";
|
|
67
|
+
case EnumPaymentType.splitPayments:
|
|
68
|
+
return "Multi payment";
|
|
69
|
+
default:
|
|
70
|
+
return "None";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
getPaymentStateText(order = initOrder) {
|
|
74
|
+
switch (order.paymentState) {
|
|
75
|
+
case EnumPaymentState.PAID:
|
|
76
|
+
return "Paid";
|
|
77
|
+
case EnumPaymentState.NOT_PAID:
|
|
78
|
+
return "Not paid";
|
|
79
|
+
case EnumPaymentState.PENDING:
|
|
80
|
+
return "Pending";
|
|
81
|
+
default:
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
getOrderTypeText(orderType) {
|
|
86
|
+
switch (orderType) {
|
|
87
|
+
case EnumOrderType.delivery:
|
|
88
|
+
return "Delivery";
|
|
89
|
+
case EnumOrderType.dining:
|
|
90
|
+
return "Dine-in";
|
|
91
|
+
case EnumOrderType.pickup:
|
|
92
|
+
return "Pickup";
|
|
93
|
+
default:
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
getOrderChannelText(channel) {
|
|
98
|
+
switch (channel) {
|
|
99
|
+
case EnumChannels.DigitalMenu:
|
|
100
|
+
return "Digital menu";
|
|
101
|
+
case EnumChannels.GoogleOrdering:
|
|
102
|
+
return "Google";
|
|
103
|
+
case EnumChannels.POS:
|
|
104
|
+
return "POS";
|
|
105
|
+
case EnumChannels.WebShop:
|
|
106
|
+
return "Online store";
|
|
107
|
+
case EnumChannels.App:
|
|
108
|
+
return "APP";
|
|
109
|
+
case EnumChannels.None:
|
|
110
|
+
return "None";
|
|
111
|
+
default:
|
|
112
|
+
return "";
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
orderTypeText(order = initOrder, additionalPickupInstructionsTypes) {
|
|
116
|
+
switch (order.orderType) {
|
|
117
|
+
case EnumOrderType.delivery:
|
|
118
|
+
return "Delivery";
|
|
119
|
+
case EnumOrderType.dining:
|
|
120
|
+
return "Dine-in";
|
|
121
|
+
case EnumOrderType.pickup:
|
|
122
|
+
let item = additionalPickupInstructionsTypes.find(i => i.value === order.pickupInstructions);
|
|
123
|
+
if (item)
|
|
124
|
+
return item.text;
|
|
125
|
+
return "Pickup";
|
|
126
|
+
default:
|
|
127
|
+
return "";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
builtOrderDeliveryCost(form, zones, checkDeliveryCoverageArea) {
|
|
131
|
+
let zoneInfo = {
|
|
132
|
+
zoneId: form.zoneId,
|
|
133
|
+
duration: form.duration,
|
|
134
|
+
deliveryCost: form.deliveryCost
|
|
135
|
+
};
|
|
136
|
+
// console.log("zoneInfo : ", zoneInfo);
|
|
137
|
+
if (form.orderType === EnumOrderType.delivery) {
|
|
138
|
+
// console.log("if -------------");
|
|
139
|
+
if (checkDeliveryCoverageArea) {
|
|
140
|
+
// console.log("if -------------2");
|
|
141
|
+
if (form.zoneId !== CUSTOM_DELIVERY_ZONE_ID) {
|
|
142
|
+
let point = {
|
|
143
|
+
latitude: +(form.latitude + ""),
|
|
144
|
+
longitude: +(form.longitude + "")
|
|
145
|
+
};
|
|
146
|
+
let enabledZones = this.zonesThatCoverageLocation(point, zones);
|
|
147
|
+
if (enabledZones.length > 0) {
|
|
148
|
+
let basketPriceWithoutDeliveryCost = form.displayTotalAmount - form.deliveryCost;
|
|
149
|
+
let zonesDeliveryForms = enabledZones.filter(zone => zone.deliveryFrom <= basketPriceWithoutDeliveryCost)
|
|
150
|
+
.map(i => this.calcDeliveryCost(basketPriceWithoutDeliveryCost, i));
|
|
151
|
+
if (zonesDeliveryForms.length > 0) {
|
|
152
|
+
zonesDeliveryForms = zonesDeliveryForms.sort((a, b) => {
|
|
153
|
+
return a.deliveryCost < b.deliveryCost ? -1 : 1;
|
|
154
|
+
});
|
|
155
|
+
zoneInfo.zoneId = zonesDeliveryForms[0].zoneId;
|
|
156
|
+
zoneInfo.duration = zonesDeliveryForms[0].duration;
|
|
157
|
+
zoneInfo.deliveryCost = zonesDeliveryForms[0].deliveryCost;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
zoneInfo.zoneId = initOrder.zoneId;
|
|
161
|
+
zoneInfo.duration = 0;
|
|
162
|
+
zoneInfo.deliveryCost = 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
zoneInfo.zoneId = initOrder.zoneId;
|
|
167
|
+
zoneInfo.duration = 0;
|
|
168
|
+
zoneInfo.deliveryCost = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
// else {
|
|
172
|
+
// //here staff entered custom value as delivery cost and not need anything
|
|
173
|
+
// }
|
|
174
|
+
}
|
|
175
|
+
// else {
|
|
176
|
+
//
|
|
177
|
+
// console.log("else -------------2");
|
|
178
|
+
//
|
|
179
|
+
// zoneInfo.zoneId = initOrder.zoneId;
|
|
180
|
+
// zoneInfo.duration = 0;
|
|
181
|
+
// zoneInfo.deliveryCost = 0;
|
|
182
|
+
// }
|
|
183
|
+
form.zoneId = zoneInfo.zoneId;
|
|
184
|
+
form.deliveryCost = zoneInfo.deliveryCost;
|
|
185
|
+
form.duration = zoneInfo.duration;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// console.log("else -------------");
|
|
189
|
+
form.zoneId = initOrder.zoneId;
|
|
190
|
+
form.deliveryCost = 0;
|
|
191
|
+
form.duration = 0;
|
|
192
|
+
}
|
|
193
|
+
// console.log("formInfo : ", {
|
|
194
|
+
// zoneId: form.zoneId,
|
|
195
|
+
// duration: form.duration,
|
|
196
|
+
// deliveryCost: form.deliveryCost
|
|
197
|
+
// });
|
|
198
|
+
return form;
|
|
199
|
+
}
|
|
200
|
+
calculateItemsAmount(list) {
|
|
201
|
+
if (list.length === 0)
|
|
202
|
+
return 0;
|
|
203
|
+
return list.map(i => i.totalAmount).reduce((a, b) => this.round(a + b));
|
|
204
|
+
}
|
|
205
|
+
calculateTax(taxPercentage, subTotal, discount, deliveryCost) {
|
|
206
|
+
return (taxPercentage / 100) * ((+subTotal) + (+deliveryCost) - (+discount));
|
|
207
|
+
}
|
|
208
|
+
calculateDiscount(order, subTotal) {
|
|
209
|
+
if (order.discountType === EnumDiscountType.percent)
|
|
210
|
+
return subTotal * order.discount / 100;
|
|
211
|
+
return order.discount;
|
|
212
|
+
}
|
|
213
|
+
calculateTip(order, subTotal) {
|
|
214
|
+
if (order.tipType === EnumTipType.percent)
|
|
215
|
+
return subTotal * order.tip / 100;
|
|
216
|
+
return order.tip;
|
|
217
|
+
}
|
|
218
|
+
calculateReward(totalAmount, rewardProgram) {
|
|
219
|
+
if (!rewardProgram || !rewardProgram.state)
|
|
220
|
+
return 0;
|
|
221
|
+
let points = 0;
|
|
222
|
+
try {
|
|
223
|
+
switch (rewardProgram.rewardsPoints) {
|
|
224
|
+
case EnumRewardPointType.PerAmount:
|
|
225
|
+
if (rewardProgram.rewardsEveryValue > 0) {
|
|
226
|
+
points = Math.round(totalAmount / rewardProgram.rewardsEveryValue);
|
|
227
|
+
}
|
|
228
|
+
if (rewardProgram.rewardsMaxPointsPerOrder !== 0 && rewardProgram.rewardsMaxPointsPerOrder < points) {
|
|
229
|
+
points = rewardProgram.rewardsMaxPointsPerOrder;
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
232
|
+
case EnumRewardPointType.PerOrder:
|
|
233
|
+
points = rewardProgram.rewardsNumberOfPoints;
|
|
234
|
+
break;
|
|
235
|
+
default:
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
}
|
|
241
|
+
return points;
|
|
242
|
+
}
|
|
243
|
+
customerOrNull(order) {
|
|
244
|
+
// const customer = {
|
|
245
|
+
// email: order.email,
|
|
246
|
+
// phoneNumber: PhoneController.unFormatPhoneNumber(PhoneController.formatPhoneNumber(order.phoneNumber)),
|
|
247
|
+
// firstName: order.firstName,
|
|
248
|
+
// lastName: order.lastName,
|
|
249
|
+
// gender: order.genderType,
|
|
250
|
+
// id: order.customerId
|
|
251
|
+
// }
|
|
252
|
+
// if (order.orderType === EnumOrderType.delivery || order.email !== "" || order.phoneNumber !== "" || order.firstName !== "" || order.lastName !== "" || order.customerId !== null) {
|
|
253
|
+
// return {
|
|
254
|
+
// email: order.email,
|
|
255
|
+
// phoneNumber: PhoneController.unFormatPhoneNumber(PhoneController.formatPhoneNumber(order.phoneNumber)),
|
|
256
|
+
// firstName: order.firstName,
|
|
257
|
+
// lastName: order.lastName,
|
|
258
|
+
// gender: order.genderType,
|
|
259
|
+
// id: order.customerId
|
|
260
|
+
// };
|
|
261
|
+
// }
|
|
262
|
+
return {
|
|
263
|
+
email: order.email,
|
|
264
|
+
phoneNumber: PhoneController.unFormatPhoneNumber(PhoneController.formatPhoneNumber(order.phoneNumber)),
|
|
265
|
+
firstName: order.firstName,
|
|
266
|
+
lastName: order.lastName,
|
|
267
|
+
gender: order.genderType,
|
|
268
|
+
id: order.customerId
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
locationOrNull(order) {
|
|
272
|
+
try {
|
|
273
|
+
if (order.latitude === null)
|
|
274
|
+
order.latitude = 0;
|
|
275
|
+
if (order.longitude === null)
|
|
276
|
+
order.longitude = 0;
|
|
277
|
+
if (!order)
|
|
278
|
+
return null;
|
|
279
|
+
if (typeof order.longitude === "string")
|
|
280
|
+
order.longitude = +order.longitude;
|
|
281
|
+
if (typeof order.latitude === "string")
|
|
282
|
+
order.latitude = +order.latitude;
|
|
283
|
+
if (isNaN(order.longitude))
|
|
284
|
+
order.longitude = 0;
|
|
285
|
+
if (isNaN(order.longitude))
|
|
286
|
+
order.latitude = 0;
|
|
287
|
+
if (order.longitude === 0 && order.latitude === 0 && order.orderType !== EnumOrderType.delivery)
|
|
288
|
+
return null;
|
|
289
|
+
return {
|
|
290
|
+
longitude: +((+(order.longitude + "")).toFixed(6)),
|
|
291
|
+
latitude: +((+(order.latitude + "")).toFixed(6)),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
return {
|
|
296
|
+
longitude: +(order.longitude + ""),
|
|
297
|
+
latitude: +(order.latitude + ""),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
convertOrderExtraItemToOrderDetailProductsExtra(item) {
|
|
302
|
+
return {
|
|
303
|
+
id: item.id,
|
|
304
|
+
extraId: item.extraId,
|
|
305
|
+
extraItemId: item.extraItemId,
|
|
306
|
+
extraTitle: item.extraTitle,
|
|
307
|
+
extraItemTitle: item.extraItemTitle,
|
|
308
|
+
price: item.price,
|
|
309
|
+
quantity: item.quantity,
|
|
310
|
+
totalAmount: item.totalAmount,
|
|
311
|
+
priority: 1,
|
|
312
|
+
pizzaSide: item.pizzaSide,
|
|
313
|
+
text: item.text,
|
|
314
|
+
extraItemOptionId: item.extraItemOptionId,
|
|
315
|
+
extraItemOptionTitle: item.extraItemOptionTitle,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
convertOrderItemToOrderDetailProduct(item, currency) {
|
|
319
|
+
return {
|
|
320
|
+
id: item.id,
|
|
321
|
+
productId: item.productId,
|
|
322
|
+
categoryId: -1,
|
|
323
|
+
categoryTitle: "",
|
|
324
|
+
title: item.title,
|
|
325
|
+
quantity: item.quantity,
|
|
326
|
+
price: item.price,
|
|
327
|
+
note: item.note,
|
|
328
|
+
extrasNames: this.createExtraNames(item, currency),
|
|
329
|
+
totalAmount: item.totalAmount,
|
|
330
|
+
text: "",
|
|
331
|
+
extras: item.extras.map(i => this.convertOrderExtraItemToOrderDetailProductsExtra(i)),
|
|
332
|
+
kitchenReceiptName: item.title,
|
|
333
|
+
additionalText: item.additionalText,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
createExtraNames(item, currency) {
|
|
337
|
+
let list = [];
|
|
338
|
+
item.extras.forEach(i => {
|
|
339
|
+
// let part = "";
|
|
340
|
+
// if (i.quantity > 1) part += i.quantity + "x ";
|
|
341
|
+
//
|
|
342
|
+
// part += i.extraItemTitle + " ";
|
|
343
|
+
//
|
|
344
|
+
// if (i.extraItemOptionId !== -1) part += `[${i.extraItemOptionTitle}] `;
|
|
345
|
+
//
|
|
346
|
+
// if (i.totalAmount > 0) part += `(${MoneyController.format(i.totalAmount, currency)})`;
|
|
347
|
+
list.push(this.createExtraItemText(i, currency));
|
|
348
|
+
});
|
|
349
|
+
return list.join(" , ");
|
|
350
|
+
}
|
|
351
|
+
createExtraItemText(item, currency) {
|
|
352
|
+
let part = "";
|
|
353
|
+
if (item.quantity > 1)
|
|
354
|
+
part += item.quantity + "x ";
|
|
355
|
+
switch (item.pizzaSide) {
|
|
356
|
+
case EnumPizzaSide.all:
|
|
357
|
+
part += "[WHOLE] ";
|
|
358
|
+
break;
|
|
359
|
+
case EnumPizzaSide.left:
|
|
360
|
+
part += "[LEFT] ";
|
|
361
|
+
break;
|
|
362
|
+
case EnumPizzaSide.right:
|
|
363
|
+
part += "[RIGHT] ";
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
part += item.extraItemTitle + " ";
|
|
367
|
+
if (item.extraItemOptionId !== -1)
|
|
368
|
+
part += `[${item.extraItemOptionTitle}] `;
|
|
369
|
+
if (item.totalAmount > 0)
|
|
370
|
+
part += `(${MoneyController.format(item.totalAmount, currency)})`;
|
|
371
|
+
return part;
|
|
372
|
+
}
|
|
373
|
+
roundCashAmount(price, rounding) {
|
|
374
|
+
if (price == 0 || rounding == EnumPriceMidpointRounding.None) {
|
|
375
|
+
return { newPrice: price, roundingRate: 0 };
|
|
376
|
+
}
|
|
377
|
+
let roundingRate;
|
|
378
|
+
if (price === null || price === undefined || (price + "").trim() === "" || isNaN(parseFloat(price + "")))
|
|
379
|
+
price = 0;
|
|
380
|
+
let str = price.toFixed(2);
|
|
381
|
+
let index = str.indexOf(".");
|
|
382
|
+
let number = Number.parseInt(str);
|
|
383
|
+
let tensDigit = +str.substring(index + 1, index + 2);
|
|
384
|
+
let digit = +str.substring(index + 2, index + 3);
|
|
385
|
+
switch (rounding) {
|
|
386
|
+
case EnumPriceMidpointRounding.CeilingFiveCent:
|
|
387
|
+
if (digit > 0 && digit < 5) {
|
|
388
|
+
digit = 5;
|
|
389
|
+
}
|
|
390
|
+
else if (digit > 6 && digit <= 9) {
|
|
391
|
+
digit = 0;
|
|
392
|
+
tensDigit++;
|
|
393
|
+
}
|
|
394
|
+
break;
|
|
395
|
+
case EnumPriceMidpointRounding.CeilingTenCent:
|
|
396
|
+
digit = 0;
|
|
397
|
+
tensDigit++;
|
|
398
|
+
break;
|
|
399
|
+
case EnumPriceMidpointRounding.CeilingFiftyCent:
|
|
400
|
+
digit = 0;
|
|
401
|
+
if (tensDigit > 0 && tensDigit < 5) {
|
|
402
|
+
tensDigit = 5;
|
|
403
|
+
}
|
|
404
|
+
else if (tensDigit > 5 && tensDigit <= 9) {
|
|
405
|
+
tensDigit = 0;
|
|
406
|
+
number++;
|
|
407
|
+
}
|
|
408
|
+
break;
|
|
409
|
+
case EnumPriceMidpointRounding.FloorFiveCent:
|
|
410
|
+
if (digit >= 1 && digit <= 4) {
|
|
411
|
+
digit = 0;
|
|
412
|
+
}
|
|
413
|
+
else if (digit >= 6 && digit <= 9) {
|
|
414
|
+
digit = 5;
|
|
415
|
+
}
|
|
416
|
+
break;
|
|
417
|
+
case EnumPriceMidpointRounding.FloorTenCent:
|
|
418
|
+
digit = 0;
|
|
419
|
+
break;
|
|
420
|
+
case EnumPriceMidpointRounding.FloorFiftyCent:
|
|
421
|
+
digit = 0;
|
|
422
|
+
if (tensDigit >= 1 && tensDigit <= 4) {
|
|
423
|
+
tensDigit = 0;
|
|
424
|
+
}
|
|
425
|
+
else if (tensDigit >= 6 && tensDigit <= 9) {
|
|
426
|
+
tensDigit = 5;
|
|
427
|
+
}
|
|
428
|
+
break;
|
|
429
|
+
case EnumPriceMidpointRounding.MediocrityFiveCent:
|
|
430
|
+
if (digit == 1 || digit == 2) {
|
|
431
|
+
digit = 0;
|
|
432
|
+
}
|
|
433
|
+
else if (digit >= 3 && digit <= 7) {
|
|
434
|
+
digit = 5;
|
|
435
|
+
}
|
|
436
|
+
else if (digit == 8 || digit === 9) {
|
|
437
|
+
digit = 0;
|
|
438
|
+
tensDigit++;
|
|
439
|
+
}
|
|
440
|
+
break;
|
|
441
|
+
case EnumPriceMidpointRounding.MediocrityTenCent:
|
|
442
|
+
if (digit >= 1 && digit <= 4) {
|
|
443
|
+
digit = 0;
|
|
444
|
+
}
|
|
445
|
+
else if (digit >= 5 && digit <= 9) {
|
|
446
|
+
digit = 0;
|
|
447
|
+
tensDigit++;
|
|
448
|
+
}
|
|
449
|
+
break;
|
|
450
|
+
case EnumPriceMidpointRounding.MediocrityFiftyCent:
|
|
451
|
+
let n = (tensDigit * 10) + digit;
|
|
452
|
+
if (n < 35) {
|
|
453
|
+
digit = 0;
|
|
454
|
+
tensDigit = 0;
|
|
455
|
+
}
|
|
456
|
+
else if (n >= 35 && n < 70) {
|
|
457
|
+
digit = 0;
|
|
458
|
+
tensDigit = 5;
|
|
459
|
+
}
|
|
460
|
+
else if (n >= 70) {
|
|
461
|
+
digit = 0;
|
|
462
|
+
tensDigit = 0;
|
|
463
|
+
number++;
|
|
464
|
+
}
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
if (tensDigit >= 10) {
|
|
468
|
+
tensDigit = 0;
|
|
469
|
+
number++;
|
|
470
|
+
}
|
|
471
|
+
let newPrice = +`${number}.${tensDigit}${digit}`;
|
|
472
|
+
roundingRate = newPrice - price;
|
|
473
|
+
return { newPrice: newPrice, roundingRate: roundingRate };
|
|
474
|
+
}
|
|
475
|
+
coveragesAddress(location, zones, checkDeliveryCoverageArea) {
|
|
476
|
+
if (!checkDeliveryCoverageArea)
|
|
477
|
+
return true;
|
|
478
|
+
return zones.filter(zone => zone.enabled)
|
|
479
|
+
.find(zone => ZoneController.pointInPolygon(zone.points, {
|
|
480
|
+
latitude: +(location.latitude + ""),
|
|
481
|
+
longitude: +(location.longitude + "")
|
|
482
|
+
})) !== undefined;
|
|
483
|
+
}
|
|
484
|
+
zonesThatCoverageLocation(location, zones) {
|
|
485
|
+
return zones.filter(zone => zone.enabled).filter(zone => ZoneController.pointInPolygon(zone.points, {
|
|
486
|
+
latitude: +(location.latitude + ""),
|
|
487
|
+
longitude: +(location.longitude + "")
|
|
488
|
+
}));
|
|
489
|
+
}
|
|
490
|
+
calculateFee(companyFee, order, orderAmount) {
|
|
491
|
+
const { orderType, paymentType } = order;
|
|
492
|
+
const { enabled, calculationMode, orderTypes, type, maximumOrderAmount, amount, minimumOrderAmount, minimumFee, maximumFee, paymentTypes, text, taxable, percentage, taxPercentage } = companyFee;
|
|
493
|
+
let result = {
|
|
494
|
+
text: text,
|
|
495
|
+
amount: 0,
|
|
496
|
+
type: type,
|
|
497
|
+
tax: 0
|
|
498
|
+
};
|
|
499
|
+
if (!enabled)
|
|
500
|
+
return result;
|
|
501
|
+
if (calculationMode == EnumFeeCalculationMode.NONE)
|
|
502
|
+
return result;
|
|
503
|
+
if (Array.isArray(orderTypes) && orderTypes.length > 0 && !orderTypes.includes(orderType))
|
|
504
|
+
return result;
|
|
505
|
+
if (paymentType == EnumPaymentType.none)
|
|
506
|
+
return result;
|
|
507
|
+
let notOnOnlinePay = paymentType == EnumPaymentType.online && !ToolController.find_number_to_2(paymentTypes, 1);
|
|
508
|
+
let notOnCashPay = paymentType == EnumPaymentType.cash && !ToolController.find_number_to_2(paymentTypes, 2);
|
|
509
|
+
let notOnDebitAt = paymentType == EnumPaymentType.debitAt && !ToolController.find_number_to_2(paymentTypes, 4);
|
|
510
|
+
let notOnApplePay = paymentType == EnumPaymentType.applePay && !ToolController.find_number_to_2(paymentTypes, 8);
|
|
511
|
+
let notOnGooglePay = paymentType == EnumPaymentType.googlePay && !ToolController.find_number_to_2(paymentTypes, 16);
|
|
512
|
+
let notOnStripeTerminal = paymentType == EnumPaymentType.terminal && !ToolController.find_number_to_2(paymentTypes, 32);
|
|
513
|
+
let notOnWallet = paymentType == EnumPaymentType.wallet && !ToolController.find_number_to_2(paymentTypes, 64);
|
|
514
|
+
let notOnGiftCards = paymentType == EnumPaymentType.wallet && !ToolController.find_number_to_2(paymentTypes, 128);
|
|
515
|
+
//TODO need test and fix
|
|
516
|
+
let notOnElvanPayment = paymentType == EnumPaymentType.debitMachine && !ToolController.find_number_to_2(paymentTypes, 256);
|
|
517
|
+
let notOnSplitPayment = paymentType == EnumPaymentType.splitPayments && !ToolController.find_number_to_2(paymentTypes, 512);
|
|
518
|
+
// let notOnNone = paymentType == EnumPaymentType.terminal && !ToolController.find_number_to_2(paymentTypes, 0);
|
|
519
|
+
if (notOnOnlinePay || notOnCashPay || notOnDebitAt || notOnGooglePay || notOnApplePay || notOnWallet || notOnGiftCards || notOnStripeTerminal || notOnElvanPayment || notOnSplitPayment)
|
|
520
|
+
return result;
|
|
521
|
+
if (minimumOrderAmount != 0 && orderAmount < minimumOrderAmount)
|
|
522
|
+
return result;
|
|
523
|
+
if (maximumOrderAmount != 0 && orderAmount > maximumOrderAmount)
|
|
524
|
+
return result;
|
|
525
|
+
let fee = 0;
|
|
526
|
+
let tax = 0;
|
|
527
|
+
switch (calculationMode) {
|
|
528
|
+
case EnumFeeCalculationMode.FIXED:
|
|
529
|
+
fee = amount;
|
|
530
|
+
break;
|
|
531
|
+
case EnumFeeCalculationMode.MIXED:
|
|
532
|
+
if (percentage > 0)
|
|
533
|
+
fee += +MoneyController.round((percentage * orderAmount) / 100); //Math.Round((((decimal)percentage) *orderAmount) /100, 2);
|
|
534
|
+
break;
|
|
535
|
+
case EnumFeeCalculationMode.BOTH:
|
|
536
|
+
fee = amount;
|
|
537
|
+
if (percentage > 0)
|
|
538
|
+
fee += +MoneyController.round((percentage * orderAmount) / 100); //Math.Round((((decimal)percentage) *orderAmount) /100, 2);
|
|
539
|
+
break;
|
|
540
|
+
default:
|
|
541
|
+
break;
|
|
542
|
+
}
|
|
543
|
+
if (taxable) {
|
|
544
|
+
if (fee > 0 && taxPercentage > 0) {
|
|
545
|
+
tax = +MoneyController.round((taxPercentage * fee) / 100); //Math.Round((fee * (decimal)taxPercentage) /100, 2);
|
|
546
|
+
fee += tax;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (calculationMode == EnumFeeCalculationMode.MIXED || calculationMode == EnumFeeCalculationMode.BOTH) {
|
|
550
|
+
if (minimumFee > 0 && fee < minimumFee)
|
|
551
|
+
fee = minimumFee;
|
|
552
|
+
if (maximumFee > 0 && fee > maximumFee)
|
|
553
|
+
fee = maximumFee;
|
|
554
|
+
}
|
|
555
|
+
result.amount = fee;
|
|
556
|
+
result.tax = tax;
|
|
557
|
+
return result;
|
|
558
|
+
}
|
|
559
|
+
formatSetting(_setting) {
|
|
560
|
+
//TODO this method after update https://core.meemup.com must be removed
|
|
561
|
+
let data = Object.assign({}, _setting);
|
|
562
|
+
if (!data.hasOwnProperty("fees")) {
|
|
563
|
+
data.fees = [];
|
|
564
|
+
}
|
|
565
|
+
return data;
|
|
566
|
+
}
|
|
567
|
+
customerText(form) {
|
|
568
|
+
const label = `${form.firstName} ${form.lastName}`;
|
|
569
|
+
if (label.trim() === "")
|
|
570
|
+
return "Guest";
|
|
571
|
+
return label;
|
|
572
|
+
}
|
|
573
|
+
isMandatory(orderType, value) {
|
|
574
|
+
switch (orderType) {
|
|
575
|
+
case EnumOrderType.dining:
|
|
576
|
+
return value === EnumCustomerMandatory.ON_DELIVERY_AND_DINING || value === EnumCustomerMandatory.ONLY_ON_DINING || value === EnumCustomerMandatory.YES || value === EnumCustomerMandatory.ON_PICKUP_AND_DINING;
|
|
577
|
+
case EnumOrderType.pickup:
|
|
578
|
+
return value === EnumCustomerMandatory.ON_PICKUP_AND_DINING || value === EnumCustomerMandatory.ONLY_ON_PICKUP || value === EnumCustomerMandatory.YES || value === EnumCustomerMandatory.ON_PICKUP_AND_DELIVERY;
|
|
579
|
+
case EnumOrderType.delivery:
|
|
580
|
+
return value === EnumCustomerMandatory.ON_PICKUP_AND_DELIVERY || value === EnumCustomerMandatory.ONLY_ON_DELIVERY || value === EnumCustomerMandatory.YES || value === EnumCustomerMandatory.ON_DELIVERY_AND_DINING;
|
|
581
|
+
default:
|
|
582
|
+
return false;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
round(num) {
|
|
586
|
+
return Math.round(num * 100) / 100;
|
|
587
|
+
}
|
|
588
|
+
}
|