meemup-library 1.1.63 → 1.1.65

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.
@@ -2,7 +2,6 @@ import EnumOrderType from "../enums/EnumOrderType";
2
2
  import IKitchenScreenSetting from "../interfaces/IKitchenScreenSetting";
3
3
  import IKitchenOrderDetail from "../interfaces/IKitchenOrderDetail";
4
4
  import IKitchenTimes from "../interfaces/IKitchenTimes";
5
- import IEmergencyBrake from "../interfaces/IEmergencyBrake";
6
5
  import IKitchenZone from "../interfaces/IKitchenZone";
7
6
  import IKitchenOrderDetailItems from "../interfaces/IKitchenOrderDetailItems";
8
7
  declare const _default: {
@@ -10,8 +9,12 @@ declare const _default: {
10
9
  filterOrderDetailReducer(orders: IKitchenOrderDetail[], setting: IKitchenScreenSetting): IKitchenOrderDetail[];
11
10
  forToday(desiredDate: string): boolean;
12
11
  convertStrToSecond(str?: string | null): number;
12
+ convertStrToMinute(str?: string | null): number;
13
13
  dateToSecond(date: Date): number;
14
- calculateTik(detail: IKitchenOrderDetail, emergency: IEmergencyBrake, times: IKitchenTimes, zones: IKitchenZone[], setting: IKitchenScreenSetting): number;
14
+ calculateTravelTime(detail: IKitchenOrderDetail, times: IKitchenTimes, zones: IKitchenZone[]): number;
15
+ calculateTik(detail: IKitchenOrderDetail, times: IKitchenTimes, zones: IKitchenZone[]): number;
16
+ calculateKitchenTime(detail: IKitchenOrderDetail, times: IKitchenTimes): number;
17
+ idAddvanceOrder(detail: IKitchenOrderDetail, times: IKitchenTimes, zones: IKitchenZone[]): boolean;
15
18
  sortOrders(orders: IKitchenOrderDetail[], setting: IKitchenScreenSetting): IKitchenOrderDetail[];
16
19
  listToMatrix(setting: IKitchenScreenSetting, orders: IKitchenOrderDetail[], page: number): IKitchenOrderDetail[][];
17
20
  calculateTotalPage(listLength: number, pageSize: number): number;
@@ -1,6 +1,7 @@
1
1
  import EnumOrderType from "../enums/EnumOrderType";
2
2
  import EnumKitchenScreenSortOrders from "../enums/EnumKitchenScreenSortOrders";
3
3
  import { initKitchenOrderDetail } from "../interfaces/IKitchenOrderDetail";
4
+ import ZoneController from "./ZoneController";
4
5
  export default new class KitchenController {
5
6
  atLeastOneItemToShowInKitchen(list) {
6
7
  let result = false;
@@ -41,38 +42,87 @@ export default new class KitchenController {
41
42
  hour = +parts[2];
42
43
  return (hour * 60 * 60) + (minute * 60) + second;
43
44
  }
45
+ convertStrToMinute(str = "00:00:00") {
46
+ if (str === null)
47
+ return 0;
48
+ let second = 0;
49
+ let minute = 0;
50
+ let hour = 0;
51
+ let parts = str.split(":").reverse();
52
+ if (parts.length > 0)
53
+ second = +parts[0];
54
+ if (parts.length > 1)
55
+ minute = +parts[1];
56
+ if (parts.length > 2)
57
+ hour = +parts[2];
58
+ return +((hour * 60) + (minute) + (second / 60)).toFixed(2);
59
+ }
44
60
  dateToSecond(date) {
45
61
  return parseInt((date.getTime() / 1000) + "");
46
62
  }
47
- calculateTik(detail, emergency, times, zones, setting) {
48
- let kitchenTime = this.convertStrToSecond(detail.estimatedTime) / 60;
63
+ calculateTravelTime(detail, times, zones) {
64
+ if (detail.type !== EnumOrderType.delivery)
65
+ return 0;
66
+ let travelTime = 0;
67
+ if ((detail === null || detail === void 0 ? void 0 : detail.deliveryLocation) && (detail === null || detail === void 0 ? void 0 : detail.storeLocation))
68
+ travelTime = ZoneController.calculateDuration(detail === null || detail === void 0 ? void 0 : detail.deliveryLocation, detail === null || detail === void 0 ? void 0 : detail.storeLocation, times.transportType);
69
+ let zone = zones.find(i => i.id === detail.zoneId);
70
+ if (zone)
71
+ travelTime += zone === null || zone === void 0 ? void 0 : zone.additionalDeliveryTime;
72
+ return travelTime;
73
+ }
74
+ calculateTik(detail, times, zones) {
49
75
  let desiredDateTime = new Date(detail.desiredDateTime);
50
76
  let currentDateTime = new Date();
51
- let deliveryTime = 0;
77
+ //-----------------------------------------------------------------------------------------------
78
+ let estimatedTime = this.convertStrToMinute(detail.estimatedTime); //in minute
79
+ //-----------------------------------------------------------------------------------------------
80
+ let travelTime = this.calculateTravelTime(detail, times, zones); //in minute
81
+ desiredDateTime.setMinutes((desiredDateTime.getMinutes() + estimatedTime) - travelTime);
82
+ let tik = this.dateToSecond(desiredDateTime) - this.dateToSecond(currentDateTime);
83
+ if (tik > 0)
84
+ return tik;
85
+ return 0;
86
+ }
87
+ calculateKitchenTime(detail, times) {
88
+ let kitchenTime = 0; //in minute
89
+ let productMaxPreparationTime = 0;
52
90
  switch (detail.type) {
53
91
  case EnumOrderType.delivery:
54
- kitchenTime += setting.deliveryPreprationTime;
55
- desiredDateTime.setMinutes(desiredDateTime.getMinutes() + emergency.deliveryDelayTime);
56
- deliveryTime += times.deliveryMinimumTime;
57
- let zone = zones.find(i => i.id === detail.zoneId);
58
- if (zone)
59
- deliveryTime += zone === null || zone === void 0 ? void 0 : zone.additionalDeliveryTime;
92
+ kitchenTime += times.deliveryMinimumTime;
60
93
  break;
61
94
  case EnumOrderType.pickup:
62
- kitchenTime += setting.pickupPreprationTime;
63
- desiredDateTime.setMinutes(desiredDateTime.getMinutes() + emergency.pickupDelayTime);
95
+ kitchenTime += times.pickupMinimumTime;
64
96
  break;
65
97
  case EnumOrderType.dining:
66
- kitchenTime += setting.diningPreprationTime;
98
+ kitchenTime += times.diningMinimumTime;
67
99
  break;
68
100
  default:
101
+ kitchenTime = times.minimumPreparationTime;
69
102
  break;
70
103
  }
71
- desiredDateTime.setMinutes(desiredDateTime.getMinutes() - deliveryTime);
104
+ if (kitchenTime < times.minimumPreparationTime)
105
+ kitchenTime = times.minimumPreparationTime;
106
+ const list = detail.items.map(i => this.convertStrToMinute(i.preparationTime));
107
+ if (list.length > 1)
108
+ productMaxPreparationTime = Math.max(...list);
109
+ else if (list.length === 1)
110
+ productMaxPreparationTime = list[0];
111
+ if (kitchenTime < productMaxPreparationTime)
112
+ kitchenTime = productMaxPreparationTime;
113
+ return kitchenTime + this.convertStrToMinute(detail.estimatedTime);
114
+ }
115
+ idAddvanceOrder(detail, times, zones) {
116
+ let desiredDateTime = new Date(detail.desiredDateTime);
117
+ let currentDateTime = new Date();
118
+ //-----------------------------------------------------------------------------------------------
119
+ let kitchenTime = this.calculateKitchenTime(detail, times); //in minute
120
+ let travelTime = this.calculateTravelTime(detail, times, zones); //in minute
121
+ let estimatedTime = this.convertStrToMinute(detail.estimatedTime); //in minute
122
+ //-----------------------------------------------------------------------------------------------
123
+ desiredDateTime.setMinutes(desiredDateTime.getMinutes() + estimatedTime);
72
124
  let tik = this.dateToSecond(desiredDateTime) - this.dateToSecond(currentDateTime);
73
- if (tik > 0)
74
- return tik;
75
- return 0;
125
+ return tik - ((kitchenTime + travelTime) * 60) > 0;
76
126
  }
77
127
  sortOrders(orders, setting) {
78
128
  if (setting.sortAscending) {
@@ -1,13 +1,31 @@
1
1
  import ILocation from "../interfaces/ILocation";
2
2
  declare const _default: {
3
3
  /**
4
- * Performs the even-odd-rule Algorithm (a raycasting algorithm) to find out whether a point is in a given polygon.
5
- * This runs in O(n) where n is the number of edges of the polygon.
4
+ * Performs the even-odd-rule Algorithm (a raycasting algorithm) to find out whether a point is in a given polygon.
5
+ * This runs in O(n) where n is the number of edges of the polygon.
6
+ *
7
+ * @param {ILocation[]} polygon - An array representation of the polygon where polygon[i][0] is the x Value of the i-th point and polygon[i][1] is the y Value.
8
+ * @param {ILocation} point - An array representation of the point where point[0] is its x Value and point[1] is its y Value.
9
+ * @returns {boolean} - Whether the point is in the polygon (not on the edge, just turn < into <= and > into >= for that).
10
+ */
11
+ pointInPolygon(polygon: ILocation[], point: ILocation): boolean;
12
+ rad(x: number): number;
13
+ /**
14
+ * Calculates the distance between two geographical points using the Haversine formula.
6
15
  *
7
- * @param {Array} polygon an array representation of the polygon where polygon[i][0] is the x Value of the i-th point and polygon[i][1] is the y Value.
8
- * @param {Array} point an array representation of the point where point[0] is its x Value and point[1] is its y Value
9
- * @return {boolean} whether the point is in the polygon (not on the edge, just turn < into <= and > into >= for that)
16
+ * @param {ILocation} p1 - The geographical coordinates of the first point.
17
+ * @param {ILocation} p2 - The geographical coordinates of the second point.
18
+ * @returns {number} - The distance between the two points in meters.
10
19
  */
11
- pointInPolygon(polygon: ILocation[], point: ILocation): boolean;
20
+ calculateDistance(p1: ILocation, p2: ILocation): number;
21
+ /**
22
+ * Calculates the duration needed to travel from a customer location to a store location, considering the transport type.
23
+ *
24
+ * @param {ILocation} customerLocation - The customer's location.
25
+ * @param {ILocation} storeLocation - The store's location.
26
+ * @param {number} [transportType=1] - The transport type (1 for walking, 2 for biking, 3 for driving). Defaults to 1.
27
+ * @returns {number} - The duration of travel in minutes.
28
+ */
29
+ calculateDuration(customerLocation: ILocation, storeLocation: ILocation, transportType?: number): number;
12
30
  };
13
31
  export default _default;
@@ -1,12 +1,13 @@
1
+ import MoneyController from "./MoneyController";
1
2
  export default new class ZoneController {
2
3
  /**
3
- * Performs the even-odd-rule Algorithm (a raycasting algorithm) to find out whether a point is in a given polygon.
4
- * This runs in O(n) where n is the number of edges of the polygon.
5
- *
6
- * @param {Array} polygon an array representation of the polygon where polygon[i][0] is the x Value of the i-th point and polygon[i][1] is the y Value.
7
- * @param {Array} point an array representation of the point where point[0] is its x Value and point[1] is its y Value
8
- * @return {boolean} whether the point is in the polygon (not on the edge, just turn < into <= and > into >= for that)
9
- */
4
+ * Performs the even-odd-rule Algorithm (a raycasting algorithm) to find out whether a point is in a given polygon.
5
+ * This runs in O(n) where n is the number of edges of the polygon.
6
+ *
7
+ * @param {ILocation[]} polygon - An array representation of the polygon where polygon[i][0] is the x Value of the i-th point and polygon[i][1] is the y Value.
8
+ * @param {ILocation} point - An array representation of the point where point[0] is its x Value and point[1] is its y Value.
9
+ * @returns {boolean} - Whether the point is in the polygon (not on the edge, just turn < into <= and > into >= for that).
10
+ */
10
11
  pointInPolygon(polygon, point) {
11
12
  let odd = false;
12
13
  for (let i = 0, j = polygon.length - 1; i < polygon.length; i++) {
@@ -19,4 +20,60 @@ export default new class ZoneController {
19
20
  return odd;
20
21
  }
21
22
  ;
23
+ rad(x) {
24
+ return x * Math.PI / 180;
25
+ }
26
+ /**
27
+ * Calculates the distance between two geographical points using the Haversine formula.
28
+ *
29
+ * @param {ILocation} p1 - The geographical coordinates of the first point.
30
+ * @param {ILocation} p2 - The geographical coordinates of the second point.
31
+ * @returns {number} - The distance between the two points in meters.
32
+ */
33
+ calculateDistance(p1, p2) {
34
+ try {
35
+ let R = 6378137; // Earth’s mean radius in meter
36
+ let dLat = this.rad(p2.latitude - p1.latitude);
37
+ let dLong = this.rad(p2.longitude - p1.longitude);
38
+ let a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
39
+ Math.cos(this.rad(p1.latitude)) * Math.cos(this.rad(p2.latitude)) *
40
+ Math.sin(dLong / 2) * Math.sin(dLong / 2);
41
+ let c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
42
+ return R * c; // returns the distance in meter
43
+ }
44
+ catch (e) {
45
+ return 0;
46
+ }
47
+ }
48
+ /**
49
+ * Calculates the duration needed to travel from a customer location to a store location, considering the transport type.
50
+ *
51
+ * @param {ILocation} customerLocation - The customer's location.
52
+ * @param {ILocation} storeLocation - The store's location.
53
+ * @param {number} [transportType=1] - The transport type (1 for walking, 2 for biking, 3 for driving). Defaults to 1.
54
+ * @returns {number} - The duration of travel in minutes.
55
+ */
56
+ calculateDuration(customerLocation, storeLocation, transportType = 1) {
57
+ try {
58
+ let distance = +MoneyController.round(this.calculateDistance(customerLocation, storeLocation));
59
+ let duration = 5;
60
+ switch (transportType) {
61
+ case 1:
62
+ duration += +MoneyController.round((distance / 1000) * (60 / 70));
63
+ break;
64
+ case 2:
65
+ duration += +MoneyController.round((distance / 1000) * (6 / 15));
66
+ break;
67
+ case 3:
68
+ duration += +MoneyController.round((distance / 1000) * (6 / 2));
69
+ break;
70
+ default:
71
+ break;
72
+ }
73
+ return duration;
74
+ }
75
+ catch (e) {
76
+ return 0;
77
+ }
78
+ }
22
79
  }();
@@ -1,4 +1,5 @@
1
1
  import IKitchenOrderDetailItems from "./IKitchenOrderDetailItems";
2
+ import ILocation from "./ILocation";
2
3
  export default interface IKitchenOrderDetail {
3
4
  id: number;
4
5
  number: number;
@@ -22,5 +23,7 @@ export default interface IKitchenOrderDetail {
22
23
  companyTitle?: any;
23
24
  zoneId: number;
24
25
  items: IKitchenOrderDetailItems[];
26
+ deliveryLocation: ILocation | null;
27
+ storeLocation: ILocation | null;
25
28
  }
26
29
  export declare const initKitchenOrderDetail: IKitchenOrderDetail;
@@ -24,5 +24,7 @@ export const initKitchenOrderDetail = {
24
24
  isCompany: false,
25
25
  companyTitle: "",
26
26
  zoneId: -1,
27
- items: []
27
+ items: [],
28
+ deliveryLocation: null,
29
+ storeLocation: null
28
30
  };
@@ -13,4 +13,5 @@ export default interface IKitchenOrderDetailItems {
13
13
  text: string;
14
14
  extrasNames: string;
15
15
  extras: IKitchenOrderDetailItemsExtras[];
16
+ preparationTime: string;
16
17
  }
@@ -25,13 +25,9 @@ interface IKitchenScreenSetting {
25
25
  headerFontSize: number;
26
26
  orderNumberColor: string;
27
27
  showOrdersViaStatus: EnumOrderState[];
28
- pickupPreprationTime: number;
29
- diningPreprationTime: number;
30
- deliveryPreprationTime: number;
31
28
  alarmWhenOrderComeToKitchen: boolean;
32
29
  alarm: number;
33
30
  advanceOrderBackgroundColor: string;
34
- showOrdersWithPreparationTime: number;
35
31
  }
36
32
  export default IKitchenScreenSetting;
37
33
  export declare const initKitchenScreenSetting: IKitchenScreenSetting;
@@ -25,11 +25,11 @@ export const initKitchenScreenSetting = {
25
25
  orderNumberColor: "#000",
26
26
  flashWhenExpire: true,
27
27
  showOrdersViaStatus: [EnumOrderState.new, EnumOrderState.accepted, EnumOrderState.kitchen],
28
- pickupPreprationTime: 15,
29
- diningPreprationTime: 15,
30
- deliveryPreprationTime: 15,
28
+ // pickupPreprationTime: 15,
29
+ // diningPreprationTime: 15,
30
+ // deliveryPreprationTime: 15,
31
31
  alarmWhenOrderComeToKitchen: true,
32
32
  alarm: 1,
33
33
  advanceOrderBackgroundColor: "#e262ff",
34
- showOrdersWithPreparationTime: 60
34
+ // showOrdersWithPreparationTime : 60
35
35
  };
@@ -3,5 +3,6 @@ export default interface IKitchenTimes {
3
3
  deliveryMinimumTime: number;
4
4
  pickupMinimumTime: number;
5
5
  diningMinimumTime: number;
6
+ transportType: number;
6
7
  }
7
8
  export declare const initKitchenTimes: IKitchenTimes;
@@ -2,5 +2,6 @@ export const initKitchenTimes = {
2
2
  minimumPreparationTime: 0,
3
3
  deliveryMinimumTime: 0,
4
4
  pickupMinimumTime: 0,
5
- diningMinimumTime: 0
5
+ diningMinimumTime: 0,
6
+ transportType: 1
6
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meemup-library",
3
- "version": "1.1.63",
3
+ "version": "1.1.65",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",