@managesome/eposmatic-toolkit 0.2.552 → 0.2.553

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.
@@ -1,3 +1,4 @@
1
+ import { ILocalTimeFields } from '../types/common';
1
2
  export declare function getTenantTime(desiredGMTOffset: number, date?: Date): Date;
2
3
  export declare function getDaysDifference(date1: Date, date2: Date, gmtOffset: number): number;
3
4
  export declare function getLocalDocumentFields(gmtOffset: number, date: Date): {
@@ -15,3 +16,18 @@ export declare function getLocalDocumentFields(gmtOffset: number, date: Date): {
15
16
  localTime: string;
16
17
  localDayOfYear: number;
17
18
  };
19
+ /**
20
+ * Builds the full ILocalTimeFields for an order.
21
+ *
22
+ * The date components (day_index, localDate, localDay, localWeek,
23
+ * localWeekOfYear, localMonth, localQuarter, localSemester, localYear,
24
+ * localDayOfYear) come from the tenant's running business day — the same
25
+ * "YYYY-MM-DD" value held by `track_order_numbers.runningLocalDate` /
26
+ * `order.localDate` — so the order belongs to that business day even across
27
+ * midnight.
28
+ *
29
+ * The time components (localSecond, localMinute, localHour, localTime) come
30
+ * from the actual `order_settled_at` timestamp expressed in the tenant's time
31
+ * zone (`operational_time_zone_offset_gmt`).
32
+ */
33
+ export declare function getLocalFieldsFromLocalDate(localDate: string, operational_time_zone_offset_gmt: number, order_settled_at: Date): ILocalTimeFields;
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getTenantTime = getTenantTime;
4
4
  exports.getDaysDifference = getDaysDifference;
5
5
  exports.getLocalDocumentFields = getLocalDocumentFields;
6
+ exports.getLocalFieldsFromLocalDate = getLocalFieldsFromLocalDate;
7
+ const constants_1 = require("../../constants");
6
8
  function getTenantTime(desiredGMTOffset, date = new Date()) {
7
9
  const localGMTOffsetMinutes = -date.getTimezoneOffset();
8
10
  const localGMTOffset = localGMTOffsetMinutes / 60;
@@ -28,13 +30,15 @@ function getLocalDocumentFields(gmtOffset, date) {
28
30
  const localDate = tenantDate.getDate(); // 1 - 31
29
31
  const localMonth = tenantDate.getMonth() + 1; // 1 - 12
30
32
  const localYear = tenantDate.getFullYear(); // YYYY
31
- // Calculate week of month (1-5)
33
+ // Calculate week of month (1-5). Clamped to 5 because a 30/31-day month whose
34
+ // 1st is a Friday/Saturday would otherwise compute to 6 (schema caps at 5).
32
35
  const firstDayOfMonth = new Date(tenantDate.getFullYear(), tenantDate.getMonth(), 1);
33
- const localWeek = Math.ceil((localDate + firstDayOfMonth.getDay()) / 7);
34
- // Calculate week of year (1-53)
36
+ const localWeek = Math.min(Math.ceil((localDate + firstDayOfMonth.getDay()) / 7), 5);
37
+ // Calculate week of year (1-53). Clamped to 53 because a leap year starting
38
+ // on a Saturday (e.g. 2028) would otherwise compute to 54 (schema caps at 53).
35
39
  const startOfYear = new Date(localYear, 0, 1);
36
40
  const dayOfYear = Math.floor((tenantDate.getTime() - startOfYear.getTime()) / (24 * 60 * 60 * 1000)) + 1;
37
- const localWeekOfYear = Math.ceil((dayOfYear + startOfYear.getDay()) / 7);
41
+ const localWeekOfYear = Math.min(Math.ceil((dayOfYear + startOfYear.getDay()) / 7), 53);
38
42
  // Calculate quarter (1-4)
39
43
  const localQuarter = Math.ceil(localMonth / 3);
40
44
  // Calculate semester (1-2)
@@ -58,3 +62,52 @@ function getLocalDocumentFields(gmtOffset, date) {
58
62
  localDayOfYear: dayOfYear,
59
63
  };
60
64
  }
65
+ /**
66
+ * Builds the full ILocalTimeFields for an order.
67
+ *
68
+ * The date components (day_index, localDate, localDay, localWeek,
69
+ * localWeekOfYear, localMonth, localQuarter, localSemester, localYear,
70
+ * localDayOfYear) come from the tenant's running business day — the same
71
+ * "YYYY-MM-DD" value held by `track_order_numbers.runningLocalDate` /
72
+ * `order.localDate` — so the order belongs to that business day even across
73
+ * midnight.
74
+ *
75
+ * The time components (localSecond, localMinute, localHour, localTime) come
76
+ * from the actual `order_settled_at` timestamp expressed in the tenant's time
77
+ * zone (`operational_time_zone_offset_gmt`).
78
+ */
79
+ function getLocalFieldsFromLocalDate(localDate, operational_time_zone_offset_gmt, order_settled_at) {
80
+ const [localYear, localMonth, localDay] = localDate.split('-').map(Number);
81
+ // localDate is already the tenant's local calendar date, so every date
82
+ // component is derived directly from the string using pure calendar math
83
+ // (no dependence on the server's timezone).
84
+ const weekday = new Date(Date.UTC(localYear, localMonth - 1, localDay)).getUTCDay();
85
+ // Week of month (1-5) — same formula as getLocalDocumentFields, clamped to 5.
86
+ const firstDayOfMonthDow = new Date(Date.UTC(localYear, localMonth - 1, 1)).getUTCDay();
87
+ const localWeek = Math.min(Math.ceil((localDay + firstDayOfMonthDow) / 7), 5);
88
+ // Day of year (1-366) and week of year (1-53). Clamped to 53 because a leap
89
+ // year starting on a Saturday (e.g. 2028) would otherwise compute to 54.
90
+ const dayOfYear = Math.floor((Date.UTC(localYear, localMonth - 1, localDay) - Date.UTC(localYear, 0, 1)) / (24 * 60 * 60 * 1000)) + 1;
91
+ const startOfYearDow = new Date(Date.UTC(localYear, 0, 1)).getUTCDay();
92
+ const localWeekOfYear = Math.min(Math.ceil((dayOfYear + startOfYearDow) / 7), 53);
93
+ // Time components come from the actual settle timestamp in the tenant's
94
+ // timezone. The timestamp is normalized with new Date() since callers pass
95
+ // the field straight from the order (which may be a Date or an ISO string).
96
+ const timeFields = getLocalDocumentFields(operational_time_zone_offset_gmt, new Date(order_settled_at));
97
+ return {
98
+ day_index: constants_1.ALL_DAY_INDEX[weekday],
99
+ localDate,
100
+ localTime: timeFields.localTime,
101
+ localSecond: timeFields.localSecond,
102
+ localMinute: timeFields.localMinute,
103
+ localHour: timeFields.localHour,
104
+ localDay: weekday,
105
+ localWeek,
106
+ localWeekOfYear,
107
+ localMonth,
108
+ localQuarter: Math.ceil(localMonth / 3),
109
+ localSemester: Math.ceil(localMonth / 6),
110
+ localYear,
111
+ localDayOfYear: dayOfYear,
112
+ };
113
+ }
@@ -5050,6 +5050,9 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
5050
5050
  tip_amount: number;
5051
5051
  tax_amount: number;
5052
5052
  cancel_reason?: string | null | undefined;
5053
+ localYear?: number | null | undefined;
5054
+ localMonth?: number | null | undefined;
5055
+ localDay?: number | null | undefined;
5053
5056
  delete_reason?: string | null | undefined;
5054
5057
  is_reopened?: boolean | null | undefined;
5055
5058
  staff_details?: {
@@ -5067,13 +5070,10 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
5067
5070
  localSecond?: number | null | undefined;
5068
5071
  localMinute?: number | null | undefined;
5069
5072
  localHour?: number | null | undefined;
5070
- localDay?: number | null | undefined;
5071
5073
  localWeek?: number | null | undefined;
5072
5074
  localWeekOfYear?: number | null | undefined;
5073
- localMonth?: number | null | undefined;
5074
5075
  localQuarter?: number | null | undefined;
5075
5076
  localSemester?: number | null | undefined;
5076
- localYear?: number | null | undefined;
5077
5077
  localDate?: string | null | undefined;
5078
5078
  localTime?: string | null | undefined;
5079
5079
  localDayOfYear?: number | null | undefined;
@@ -10155,6 +10155,9 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
10155
10155
  tip_amount: number;
10156
10156
  tax_amount: number;
10157
10157
  cancel_reason?: string | null | undefined;
10158
+ localYear?: number | null | undefined;
10159
+ localMonth?: number | null | undefined;
10160
+ localDay?: number | null | undefined;
10158
10161
  delete_reason?: string | null | undefined;
10159
10162
  is_reopened?: boolean | null | undefined;
10160
10163
  staff_details?: {
@@ -10172,13 +10175,10 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
10172
10175
  localSecond?: number | null | undefined;
10173
10176
  localMinute?: number | null | undefined;
10174
10177
  localHour?: number | null | undefined;
10175
- localDay?: number | null | undefined;
10176
10178
  localWeek?: number | null | undefined;
10177
10179
  localWeekOfYear?: number | null | undefined;
10178
- localMonth?: number | null | undefined;
10179
10180
  localQuarter?: number | null | undefined;
10180
10181
  localSemester?: number | null | undefined;
10181
- localYear?: number | null | undefined;
10182
10182
  localDate?: string | null | undefined;
10183
10183
  localTime?: string | null | undefined;
10184
10184
  localDayOfYear?: number | null | undefined;
@@ -15260,6 +15260,9 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
15260
15260
  tip_amount: number;
15261
15261
  tax_amount: number;
15262
15262
  cancel_reason?: string | null | undefined;
15263
+ localYear?: number | null | undefined;
15264
+ localMonth?: number | null | undefined;
15265
+ localDay?: number | null | undefined;
15263
15266
  delete_reason?: string | null | undefined;
15264
15267
  is_reopened?: boolean | null | undefined;
15265
15268
  staff_details?: {
@@ -15277,13 +15280,10 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
15277
15280
  localSecond?: number | null | undefined;
15278
15281
  localMinute?: number | null | undefined;
15279
15282
  localHour?: number | null | undefined;
15280
- localDay?: number | null | undefined;
15281
15283
  localWeek?: number | null | undefined;
15282
15284
  localWeekOfYear?: number | null | undefined;
15283
- localMonth?: number | null | undefined;
15284
15285
  localQuarter?: number | null | undefined;
15285
15286
  localSemester?: number | null | undefined;
15286
- localYear?: number | null | undefined;
15287
15287
  localDate?: string | null | undefined;
15288
15288
  localTime?: string | null | undefined;
15289
15289
  localDayOfYear?: number | null | undefined;
@@ -14,17 +14,17 @@ export declare const TenantCashDrawerSessionsSchema: Schema<any, import("mongoos
14
14
  createdAt: NativeDate;
15
15
  updatedAt: NativeDate;
16
16
  status: import("../../constants").CASH_DRAWER_STATUS_ENUM;
17
+ localYear: number;
18
+ localMonth: number;
19
+ localDay: number;
17
20
  day_index: import("../../constants").DAY_INDEX_ENUM;
18
21
  localSecond: number;
19
22
  localMinute: number;
20
23
  localHour: number;
21
- localDay: number;
22
24
  localWeek: number;
23
25
  localWeekOfYear: number;
24
- localMonth: number;
25
26
  localQuarter: number;
26
27
  localSemester: number;
27
- localYear: number;
28
28
  localDate: string;
29
29
  localTime: string;
30
30
  localDayOfYear: number;
@@ -46,17 +46,17 @@ export declare const TenantCashDrawerSessionsSchema: Schema<any, import("mongoos
46
46
  createdAt: NativeDate;
47
47
  updatedAt: NativeDate;
48
48
  status: import("../../constants").CASH_DRAWER_STATUS_ENUM;
49
+ localYear: number;
50
+ localMonth: number;
51
+ localDay: number;
49
52
  day_index: import("../../constants").DAY_INDEX_ENUM;
50
53
  localSecond: number;
51
54
  localMinute: number;
52
55
  localHour: number;
53
- localDay: number;
54
56
  localWeek: number;
55
57
  localWeekOfYear: number;
56
- localMonth: number;
57
58
  localQuarter: number;
58
59
  localSemester: number;
59
- localYear: number;
60
60
  localDate: string;
61
61
  localTime: string;
62
62
  localDayOfYear: number;
@@ -78,17 +78,17 @@ export declare const TenantCashDrawerSessionsSchema: Schema<any, import("mongoos
78
78
  createdAt: NativeDate;
79
79
  updatedAt: NativeDate;
80
80
  status: import("../../constants").CASH_DRAWER_STATUS_ENUM;
81
+ localYear: number;
82
+ localMonth: number;
83
+ localDay: number;
81
84
  day_index: import("../../constants").DAY_INDEX_ENUM;
82
85
  localSecond: number;
83
86
  localMinute: number;
84
87
  localHour: number;
85
- localDay: number;
86
88
  localWeek: number;
87
89
  localWeekOfYear: number;
88
- localMonth: number;
89
90
  localQuarter: number;
90
91
  localSemester: number;
91
- localYear: number;
92
92
  localDate: string;
93
93
  localTime: string;
94
94
  localDayOfYear: number;
@@ -16,17 +16,17 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
16
16
  updatedAt: NativeDate;
17
17
  note: string;
18
18
  amount: number;
19
+ localYear: number;
20
+ localMonth: number;
21
+ localDay: number;
19
22
  day_index: import("../../constants").DAY_INDEX_ENUM;
20
23
  localSecond: number;
21
24
  localMinute: number;
22
25
  localHour: number;
23
- localDay: number;
24
26
  localWeek: number;
25
27
  localWeekOfYear: number;
26
- localMonth: number;
27
28
  localQuarter: number;
28
29
  localSemester: number;
29
- localYear: number;
30
30
  localDate: string;
31
31
  localTime: string;
32
32
  localDayOfYear: number;
@@ -49,17 +49,17 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
49
49
  updatedAt: NativeDate;
50
50
  note: string;
51
51
  amount: number;
52
+ localYear: number;
53
+ localMonth: number;
54
+ localDay: number;
52
55
  day_index: import("../../constants").DAY_INDEX_ENUM;
53
56
  localSecond: number;
54
57
  localMinute: number;
55
58
  localHour: number;
56
- localDay: number;
57
59
  localWeek: number;
58
60
  localWeekOfYear: number;
59
- localMonth: number;
60
61
  localQuarter: number;
61
62
  localSemester: number;
62
- localYear: number;
63
63
  localDate: string;
64
64
  localTime: string;
65
65
  localDayOfYear: number;
@@ -82,17 +82,17 @@ export declare const TenantCashInOutSchema: Schema<any, import("mongoose").Model
82
82
  updatedAt: NativeDate;
83
83
  note: string;
84
84
  amount: number;
85
+ localYear: number;
86
+ localMonth: number;
87
+ localDay: number;
85
88
  day_index: import("../../constants").DAY_INDEX_ENUM;
86
89
  localSecond: number;
87
90
  localMinute: number;
88
91
  localHour: number;
89
- localDay: number;
90
92
  localWeek: number;
91
93
  localWeekOfYear: number;
92
- localMonth: number;
93
94
  localQuarter: number;
94
95
  localSemester: number;
95
- localYear: number;
96
96
  localDate: string;
97
97
  localTime: string;
98
98
  localDayOfYear: number;
@@ -12,17 +12,17 @@ export declare const TenantDaySessionSchema: Schema<any, import("mongoose").Mode
12
12
  createdAt: NativeDate;
13
13
  updatedAt: NativeDate;
14
14
  status: import("../../constants").POS_DAY_STATUS_ENUM;
15
+ localYear: number;
16
+ localMonth: number;
17
+ localDay: number;
15
18
  day_index: import("../../constants").DAY_INDEX_ENUM;
16
19
  localSecond: number;
17
20
  localMinute: number;
18
21
  localHour: number;
19
- localDay: number;
20
22
  localWeek: number;
21
23
  localWeekOfYear: number;
22
- localMonth: number;
23
24
  localQuarter: number;
24
25
  localSemester: number;
25
- localYear: number;
26
26
  localDate: string;
27
27
  localTime: string;
28
28
  localDayOfYear: number;
@@ -67,17 +67,17 @@ export declare const TenantDaySessionSchema: Schema<any, import("mongoose").Mode
67
67
  createdAt: NativeDate;
68
68
  updatedAt: NativeDate;
69
69
  status: import("../../constants").POS_DAY_STATUS_ENUM;
70
+ localYear: number;
71
+ localMonth: number;
72
+ localDay: number;
70
73
  day_index: import("../../constants").DAY_INDEX_ENUM;
71
74
  localSecond: number;
72
75
  localMinute: number;
73
76
  localHour: number;
74
- localDay: number;
75
77
  localWeek: number;
76
78
  localWeekOfYear: number;
77
- localMonth: number;
78
79
  localQuarter: number;
79
80
  localSemester: number;
80
- localYear: number;
81
81
  localDate: string;
82
82
  localTime: string;
83
83
  localDayOfYear: number;
@@ -122,17 +122,17 @@ export declare const TenantDaySessionSchema: Schema<any, import("mongoose").Mode
122
122
  createdAt: NativeDate;
123
123
  updatedAt: NativeDate;
124
124
  status: import("../../constants").POS_DAY_STATUS_ENUM;
125
+ localYear: number;
126
+ localMonth: number;
127
+ localDay: number;
125
128
  day_index: import("../../constants").DAY_INDEX_ENUM;
126
129
  localSecond: number;
127
130
  localMinute: number;
128
131
  localHour: number;
129
- localDay: number;
130
132
  localWeek: number;
131
133
  localWeekOfYear: number;
132
- localMonth: number;
133
134
  localQuarter: number;
134
135
  localSemester: number;
135
- localYear: number;
136
136
  localDate: string;
137
137
  localTime: string;
138
138
  localDayOfYear: number;
@@ -12,17 +12,17 @@ export declare const TenantInstoreShiftSessionSchema: Schema<any, import("mongoo
12
12
  createdAt: NativeDate;
13
13
  updatedAt: NativeDate;
14
14
  status: import("../../constants").POS_SHIFT_STATUS_ENUM;
15
+ localYear: number;
16
+ localMonth: number;
17
+ localDay: number;
15
18
  day_index: import("../../constants").DAY_INDEX_ENUM;
16
19
  localSecond: number;
17
20
  localMinute: number;
18
21
  localHour: number;
19
- localDay: number;
20
22
  localWeek: number;
21
23
  localWeekOfYear: number;
22
- localMonth: number;
23
24
  localQuarter: number;
24
25
  localSemester: number;
25
- localYear: number;
26
26
  localDate: string;
27
27
  localTime: string;
28
28
  localDayOfYear: number;
@@ -71,17 +71,17 @@ export declare const TenantInstoreShiftSessionSchema: Schema<any, import("mongoo
71
71
  createdAt: NativeDate;
72
72
  updatedAt: NativeDate;
73
73
  status: import("../../constants").POS_SHIFT_STATUS_ENUM;
74
+ localYear: number;
75
+ localMonth: number;
76
+ localDay: number;
74
77
  day_index: import("../../constants").DAY_INDEX_ENUM;
75
78
  localSecond: number;
76
79
  localMinute: number;
77
80
  localHour: number;
78
- localDay: number;
79
81
  localWeek: number;
80
82
  localWeekOfYear: number;
81
- localMonth: number;
82
83
  localQuarter: number;
83
84
  localSemester: number;
84
- localYear: number;
85
85
  localDate: string;
86
86
  localTime: string;
87
87
  localDayOfYear: number;
@@ -130,17 +130,17 @@ export declare const TenantInstoreShiftSessionSchema: Schema<any, import("mongoo
130
130
  createdAt: NativeDate;
131
131
  updatedAt: NativeDate;
132
132
  status: import("../../constants").POS_SHIFT_STATUS_ENUM;
133
+ localYear: number;
134
+ localMonth: number;
135
+ localDay: number;
133
136
  day_index: import("../../constants").DAY_INDEX_ENUM;
134
137
  localSecond: number;
135
138
  localMinute: number;
136
139
  localHour: number;
137
- localDay: number;
138
140
  localWeek: number;
139
141
  localWeekOfYear: number;
140
- localMonth: number;
141
142
  localQuarter: number;
142
143
  localSemester: number;
143
- localYear: number;
144
144
  localDate: string;
145
145
  localTime: string;
146
146
  localDayOfYear: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.552",
3
+ "version": "0.2.553",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",