@managesome/eposmatic-toolkit 0.3.11 → 0.4.1
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/esm/constants/MATERIALIZED_REPORTS.js +105 -0
- package/esm/constants/index.js +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/materialized-reports/index.js +5 -0
- package/esm/helpers/materialized-reports/key-helpers.js +59 -0
- package/esm/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +60 -0
- package/esm/helpers/materialized-reports/scope-helpers.js +107 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +251 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +860 -0
- package/esm/schemas/models/index.js +2 -0
- package/esm/schemas/models/materialized_tenant_reports_iterations.js +82 -0
- package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +399 -0
- package/esm/schemas/types/index.js +2 -0
- package/esm/schemas/types/materialized_tenant_reports_iterations.js +1 -0
- package/esm/schemas/types/materialized_tenant_sales_overview_reports.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +96 -0
- package/lib/constants/MATERIALIZED_REPORTS.js +108 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/helpers/index.d.ts +1 -0
- package/lib/helpers/index.js +1 -0
- package/lib/helpers/materialized-reports/index.d.ts +5 -0
- package/lib/helpers/materialized-reports/index.js +21 -0
- package/lib/helpers/materialized-reports/key-helpers.d.ts +35 -0
- package/lib/helpers/materialized-reports/key-helpers.js +64 -0
- package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.d.ts +66 -0
- package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +63 -0
- package/lib/helpers/materialized-reports/scope-helpers.d.ts +57 -0
- package/lib/helpers/materialized-reports/scope-helpers.js +114 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.d.ts +125 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +256 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +223 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +875 -0
- package/lib/schemas/models/index.d.ts +2 -0
- package/lib/schemas/models/index.js +2 -0
- package/lib/schemas/models/materialized_tenant_reports_iterations.d.ts +80 -0
- package/lib/schemas/models/materialized_tenant_reports_iterations.js +85 -0
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +569 -0
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +402 -0
- package/lib/schemas/models/orders.d.ts +24 -24
- package/lib/schemas/models/tenant_active_jobs.d.ts +3 -3
- package/lib/schemas/models/tenant_calendar.d.ts +3 -3
- package/lib/schemas/models/tenant_cash_drawer_sessions.d.ts +24 -24
- package/lib/schemas/models/tenant_cash_in_out.d.ts +24 -24
- package/lib/schemas/models/tenant_day_sessions.d.ts +24 -24
- package/lib/schemas/models/tenant_instore_shift_sessions.d.ts +24 -24
- package/lib/schemas/types/index.d.ts +2 -0
- package/lib/schemas/types/index.js +2 -0
- package/lib/schemas/types/materialized_tenant_reports_iterations.d.ts +62 -0
- package/lib/schemas/types/materialized_tenant_reports_iterations.js +2 -0
- package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +242 -0
- package/lib/schemas/types/materialized_tenant_sales_overview_reports.js +3 -0
- package/lib/tests/materialized-reports/fixtures.d.ts +81 -0
- package/lib/tests/materialized-reports/fixtures.js +87 -0
- package/lib/tests/materialized-reports/fixtures.test.d.ts +1 -0
- package/lib/tests/materialized-reports/fixtures.test.js +123 -0
- package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.js +75 -0
- package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.js +73 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +207 -0
- package/lib/tests/materialized-reports/sales-overview-baseline.test.d.ts +1 -0
- package/lib/tests/materialized-reports/sales-overview-baseline.test.js +326 -0
- package/lib/tests/materialized-reports/sales-overview-reference.d.ts +63 -0
- package/lib/tests/materialized-reports/sales-overview-reference.js +131 -0
- package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +335 -0
- package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +885 -0
- package/package.json +5 -2
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME = exports.MaterializedTenantSalesOverviewReportSchema = exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
7
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
8
|
+
/**
|
|
9
|
+
* Mongoose schema for `materialized_tenant_sales_overview_reports` — the
|
|
10
|
+
* materialized Reports > Overview data (one document per tenant × scope
|
|
11
|
+
* context × scope value), maintained by the day-end materialization job and
|
|
12
|
+
* read by the analytics API. Scope slices are stamped from the order's
|
|
13
|
+
* business day (`order.localDate`); hour buckets use the punch hour for sales
|
|
14
|
+
* and the settlement hour for credit-bill collections (see
|
|
15
|
+
* `MATERIALIZED_REPORTS.md`). The report's time-bias toggle (Punched At /
|
|
16
|
+
* `createdAt`) is out of scope. `scope_field` formats are documented on
|
|
17
|
+
* `MATERIALIZED_REPORT_SCOPE_ENUM` and in `MATERIALIZED_REPORTS.md`.
|
|
18
|
+
* Credit bills (`PAY_LATER`) live in each `sale_type_metrics` key's
|
|
19
|
+
* `CREDIT_BILLS` slot as a ledger (issued + settled tracking / received);
|
|
20
|
+
* gross stays sales-only and report views are derived by the frontend
|
|
21
|
+
* formatter. Iteration history (every structural write's full post-write
|
|
22
|
+
* snapshot) lives in the shared `materialized_tenant_reports_iterations` collection.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Version of the key grammar + metric rules of this collection. Bump when
|
|
26
|
+
* `sale_type_key_filters`, their order, or metric semantics change —
|
|
27
|
+
* historical documents must then be re-materialized (readers may branch on
|
|
28
|
+
* this value during a rollout).
|
|
29
|
+
*/
|
|
30
|
+
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
|
|
31
|
+
const ReportDiscountByTypeSchema = new mongoose_1.Schema({
|
|
32
|
+
special_discount: {
|
|
33
|
+
type: Number, // cents — Σ order_discount_details.special_discount
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
loyalty_discount: {
|
|
37
|
+
type: Number, // cents — Σ order_discount_details.loyalty_discount
|
|
38
|
+
required: true,
|
|
39
|
+
},
|
|
40
|
+
voucher_discount: {
|
|
41
|
+
type: Number, // cents — Σ order_discount_details.voucher_discount
|
|
42
|
+
required: true,
|
|
43
|
+
},
|
|
44
|
+
}, { _id: false, minimize: false });
|
|
45
|
+
const ReportOrderMetricSchema = new mongoose_1.Schema({
|
|
46
|
+
count: {
|
|
47
|
+
type: Number,
|
|
48
|
+
required: true,
|
|
49
|
+
min: 0,
|
|
50
|
+
},
|
|
51
|
+
gross_amount: {
|
|
52
|
+
type: Number, // cents — Σ amount_earned of the bucket's orders
|
|
53
|
+
required: true,
|
|
54
|
+
},
|
|
55
|
+
discount_amount: {
|
|
56
|
+
type: Number, // cents — Σ total_discount_applied
|
|
57
|
+
required: true,
|
|
58
|
+
},
|
|
59
|
+
discount_by_type: {
|
|
60
|
+
type: ReportDiscountByTypeSchema,
|
|
61
|
+
required: true,
|
|
62
|
+
},
|
|
63
|
+
gst_amount: {
|
|
64
|
+
type: Number, // cents — Σ gst_amount
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
tax_amount: {
|
|
68
|
+
type: Number, // cents — Σ tax_amount
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
tip_amount: {
|
|
72
|
+
type: Number, // cents — Σ tip_amount
|
|
73
|
+
required: true,
|
|
74
|
+
},
|
|
75
|
+
tax_invoice_provider_charges: {
|
|
76
|
+
type: Number, // cents — Σ tax_invoice_provider_charges
|
|
77
|
+
required: true,
|
|
78
|
+
},
|
|
79
|
+
delivery_charges: {
|
|
80
|
+
type: Number, // cents — Σ delivery_details.delivery_cost
|
|
81
|
+
required: true,
|
|
82
|
+
},
|
|
83
|
+
}, { _id: false, minimize: false });
|
|
84
|
+
const ReportPaymentMetricSchema = new mongoose_1.Schema({
|
|
85
|
+
payment_type: {
|
|
86
|
+
type: String,
|
|
87
|
+
// enum: ALL_PAYMENT_TYPE_NAMES, — intentionally NOT enforced: live stores
|
|
88
|
+
// contain legacy/aggregator values (CARD_PAYMENT, FOODPANDA, PLAZA, …)
|
|
89
|
+
// that must pass through reporting untouched.
|
|
90
|
+
required: true,
|
|
91
|
+
},
|
|
92
|
+
count: {
|
|
93
|
+
type: Number,
|
|
94
|
+
required: true,
|
|
95
|
+
min: 0,
|
|
96
|
+
},
|
|
97
|
+
gross_amount: {
|
|
98
|
+
type: Number, // cents — net of refunds & card charges; may be negative
|
|
99
|
+
required: true,
|
|
100
|
+
},
|
|
101
|
+
amount_due: {
|
|
102
|
+
type: Number,
|
|
103
|
+
required: true,
|
|
104
|
+
min: 0,
|
|
105
|
+
},
|
|
106
|
+
amount_paid: {
|
|
107
|
+
type: Number,
|
|
108
|
+
required: true,
|
|
109
|
+
min: 0,
|
|
110
|
+
},
|
|
111
|
+
amount_refunded: {
|
|
112
|
+
type: Number,
|
|
113
|
+
required: true,
|
|
114
|
+
min: 0,
|
|
115
|
+
},
|
|
116
|
+
card_charges: {
|
|
117
|
+
type: Number,
|
|
118
|
+
required: true,
|
|
119
|
+
min: 0,
|
|
120
|
+
},
|
|
121
|
+
}, { _id: false, minimize: false });
|
|
122
|
+
const ReportSaleTypeMetricSchema = new mongoose_1.Schema({
|
|
123
|
+
orders: {
|
|
124
|
+
type: ReportOrderMetricSchema,
|
|
125
|
+
required: true,
|
|
126
|
+
},
|
|
127
|
+
payments: {
|
|
128
|
+
type: [ReportPaymentMetricSchema],
|
|
129
|
+
default: [],
|
|
130
|
+
},
|
|
131
|
+
}, { _id: false, minimize: false });
|
|
132
|
+
const ReportCreditBillSchema = new mongoose_1.Schema({
|
|
133
|
+
order_id: {
|
|
134
|
+
type: String,
|
|
135
|
+
required: true,
|
|
136
|
+
},
|
|
137
|
+
payment_id: {
|
|
138
|
+
type: String,
|
|
139
|
+
required: true,
|
|
140
|
+
},
|
|
141
|
+
amount: {
|
|
142
|
+
type: Number, // cents — the bill's amount at issue
|
|
143
|
+
required: true,
|
|
144
|
+
},
|
|
145
|
+
// Cumulative amount received against this bill so far (0 while unpaid;
|
|
146
|
+
// less than `amount` while partially paid). Replaces the old `is_settled`
|
|
147
|
+
// flag: the bill is settled when `received_amount >= amount` (`settled_at`
|
|
148
|
+
// is stamped by the collection patch). Never an event delta, so patches
|
|
149
|
+
// stay idempotent.
|
|
150
|
+
received_amount: {
|
|
151
|
+
type: Number,
|
|
152
|
+
required: true,
|
|
153
|
+
default: 0,
|
|
154
|
+
},
|
|
155
|
+
credit_note: {
|
|
156
|
+
type: String, // optional note/reference recorded with the collection
|
|
157
|
+
default: null,
|
|
158
|
+
},
|
|
159
|
+
issued_at: {
|
|
160
|
+
type: mongoose_1.Schema.Types.Date,
|
|
161
|
+
required: true,
|
|
162
|
+
},
|
|
163
|
+
// Stamped when the bill is fully collected (received_amount >= amount).
|
|
164
|
+
settled_at: {
|
|
165
|
+
type: mongoose_1.Schema.Types.Date,
|
|
166
|
+
default: null,
|
|
167
|
+
},
|
|
168
|
+
}, { _id: false, minimize: false });
|
|
169
|
+
const ReportReceivedCreditBillSchema = new mongoose_1.Schema({
|
|
170
|
+
order_id: {
|
|
171
|
+
type: String,
|
|
172
|
+
required: true,
|
|
173
|
+
},
|
|
174
|
+
payment_id: {
|
|
175
|
+
type: String,
|
|
176
|
+
required: true,
|
|
177
|
+
},
|
|
178
|
+
amount: {
|
|
179
|
+
type: Number, // cents — the bill's amount at issue
|
|
180
|
+
required: true,
|
|
181
|
+
},
|
|
182
|
+
// Cumulative amount received for this bill as of the collection compile
|
|
183
|
+
// (≤ `amount` while partially paid; reaches `amount` when fully collected).
|
|
184
|
+
received_amount: {
|
|
185
|
+
type: Number,
|
|
186
|
+
required: true,
|
|
187
|
+
},
|
|
188
|
+
credit_note: {
|
|
189
|
+
type: String, // optional note/reference recorded with the collection
|
|
190
|
+
default: null,
|
|
191
|
+
},
|
|
192
|
+
issued_local_date: {
|
|
193
|
+
type: String, // 'YYYY-MM-DD' — the sale's day (bill issue day)
|
|
194
|
+
required: true,
|
|
195
|
+
},
|
|
196
|
+
// Collection timestamp (`order_settled_at`) when known — stamped onto the
|
|
197
|
+
// issue-day bill's `settled_at` by the collection patch.
|
|
198
|
+
settled_at: {
|
|
199
|
+
type: mongoose_1.Schema.Types.Date,
|
|
200
|
+
default: null,
|
|
201
|
+
},
|
|
202
|
+
}, { _id: false, minimize: false });
|
|
203
|
+
const ReportCreditBillsSchema = new mongoose_1.Schema({
|
|
204
|
+
issued: {
|
|
205
|
+
count: {
|
|
206
|
+
type: Number,
|
|
207
|
+
required: true,
|
|
208
|
+
min: 0,
|
|
209
|
+
default: 0,
|
|
210
|
+
},
|
|
211
|
+
amount: {
|
|
212
|
+
type: Number,
|
|
213
|
+
required: true,
|
|
214
|
+
default: 0,
|
|
215
|
+
},
|
|
216
|
+
// How much of the issued bills has been collected since — patched on
|
|
217
|
+
// settlement (tracking only; the money is counted on the collection day).
|
|
218
|
+
settled_count: {
|
|
219
|
+
type: Number,
|
|
220
|
+
required: true,
|
|
221
|
+
min: 0,
|
|
222
|
+
default: 0,
|
|
223
|
+
},
|
|
224
|
+
settled_amount: {
|
|
225
|
+
type: Number,
|
|
226
|
+
required: true,
|
|
227
|
+
default: 0,
|
|
228
|
+
},
|
|
229
|
+
bills: {
|
|
230
|
+
type: [ReportCreditBillSchema],
|
|
231
|
+
default: [],
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
received: {
|
|
235
|
+
count: {
|
|
236
|
+
type: Number,
|
|
237
|
+
required: true,
|
|
238
|
+
min: 0,
|
|
239
|
+
default: 0,
|
|
240
|
+
},
|
|
241
|
+
amount: {
|
|
242
|
+
type: Number,
|
|
243
|
+
required: true,
|
|
244
|
+
default: 0,
|
|
245
|
+
},
|
|
246
|
+
bills: {
|
|
247
|
+
type: [ReportReceivedCreditBillSchema],
|
|
248
|
+
default: [],
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
}, { _id: false, minimize: false });
|
|
252
|
+
// Credit bills carry the PAY_LATER ledger (issued + settled tracking /
|
|
253
|
+
// received) — report views (including the Credit Bills sale-type numbers) are
|
|
254
|
+
// derived by the frontend formatter, not stored separately.
|
|
255
|
+
const ReportKeyMetricsSchema = new mongoose_1.Schema({
|
|
256
|
+
[constants_1.REPORT_SALE_TYPE_ENUM.TOTAL_SALES]: {
|
|
257
|
+
type: ReportSaleTypeMetricSchema,
|
|
258
|
+
required: true,
|
|
259
|
+
},
|
|
260
|
+
[constants_1.REPORT_SALE_TYPE_ENUM.AMOUNT_COLLECTED]: {
|
|
261
|
+
type: ReportSaleTypeMetricSchema,
|
|
262
|
+
required: true,
|
|
263
|
+
},
|
|
264
|
+
[constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS]: {
|
|
265
|
+
type: ReportCreditBillsSchema,
|
|
266
|
+
required: true,
|
|
267
|
+
default: () => ({
|
|
268
|
+
issued: { count: 0, amount: 0, settled_count: 0, settled_amount: 0, bills: [] },
|
|
269
|
+
received: { count: 0, amount: 0, bills: [] },
|
|
270
|
+
}),
|
|
271
|
+
},
|
|
272
|
+
}, { _id: false, minimize: false });
|
|
273
|
+
exports.MaterializedTenantSalesOverviewReportSchema = new mongoose_1.Schema({
|
|
274
|
+
_id: {
|
|
275
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
276
|
+
required: true,
|
|
277
|
+
immutable: true,
|
|
278
|
+
},
|
|
279
|
+
tenant_id: {
|
|
280
|
+
type: String,
|
|
281
|
+
required: true,
|
|
282
|
+
immutable: true,
|
|
283
|
+
ref: 'tenants',
|
|
284
|
+
},
|
|
285
|
+
brand_id: {
|
|
286
|
+
type: String,
|
|
287
|
+
required: true,
|
|
288
|
+
},
|
|
289
|
+
scope_context: {
|
|
290
|
+
type: String,
|
|
291
|
+
enum: MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_SCOPES,
|
|
292
|
+
required: true,
|
|
293
|
+
},
|
|
294
|
+
scope_field: {
|
|
295
|
+
type: String, // format depends on scope_context — see MATERIALIZED_REPORT_SCOPE_ENUM
|
|
296
|
+
required: true,
|
|
297
|
+
},
|
|
298
|
+
// Denormalized weekday of scope_field — set ONLY on LOCAL_HOUR /
|
|
299
|
+
// LOCAL_DATE documents (MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX);
|
|
300
|
+
// null elsewhere. Weekday analysis reads date/hour slices instead of an
|
|
301
|
+
// all-time accumulator document (see MATERIALIZED_REPORTS.md).
|
|
302
|
+
day_index: {
|
|
303
|
+
type: String,
|
|
304
|
+
enum: ENUMS_1.ALL_DAY_INDEX,
|
|
305
|
+
default: null,
|
|
306
|
+
},
|
|
307
|
+
sale_type_key_filters: {
|
|
308
|
+
type: [String],
|
|
309
|
+
enum: MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_KEY_FILTERS,
|
|
310
|
+
required: true,
|
|
311
|
+
default: () => [...MATERIALIZED_REPORTS_1.SALES_OVERVIEW_KEY_FILTERS],
|
|
312
|
+
},
|
|
313
|
+
// Map key = the ordered filter combination, e.g. "PLACED:POS_WALK-IN" —
|
|
314
|
+
// the grammar is declared by `sale_type_key_filters` and must be built /
|
|
315
|
+
// parsed through the shared key helper, never ad hoc.
|
|
316
|
+
sale_type_metrics: {
|
|
317
|
+
type: Map,
|
|
318
|
+
of: ReportKeyMetricsSchema,
|
|
319
|
+
required: true,
|
|
320
|
+
default: {},
|
|
321
|
+
},
|
|
322
|
+
// Versioned writes: bumped by `updateMaterializedTenantSalesOverviewReport`
|
|
323
|
+
// on metric changes (replacement / period deltas) AND on received-payment
|
|
324
|
+
// patches that change the ledger; 1 = first materialization. Every bump is
|
|
325
|
+
// recorded in the shared `materialized_tenant_reports_iterations` history
|
|
326
|
+
// (full post-write snapshot + reason) — this document carries no embedded
|
|
327
|
+
// snapshot.
|
|
328
|
+
iteration: {
|
|
329
|
+
type: Number,
|
|
330
|
+
required: true,
|
|
331
|
+
min: 1,
|
|
332
|
+
default: 1,
|
|
333
|
+
},
|
|
334
|
+
schema_version: {
|
|
335
|
+
type: Number,
|
|
336
|
+
required: true,
|
|
337
|
+
immutable: true,
|
|
338
|
+
default: exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION,
|
|
339
|
+
},
|
|
340
|
+
source_watermark: {
|
|
341
|
+
type: mongoose_1.Schema.Types.Date,
|
|
342
|
+
required: true,
|
|
343
|
+
},
|
|
344
|
+
computed_at: {
|
|
345
|
+
type: mongoose_1.Schema.Types.Date,
|
|
346
|
+
required: true,
|
|
347
|
+
},
|
|
348
|
+
createdAt: {
|
|
349
|
+
type: mongoose_1.Schema.Types.Date,
|
|
350
|
+
required: true,
|
|
351
|
+
default: () => new Date(),
|
|
352
|
+
immutable: true,
|
|
353
|
+
},
|
|
354
|
+
updatedAt: {
|
|
355
|
+
type: mongoose_1.Schema.Types.Date,
|
|
356
|
+
required: true,
|
|
357
|
+
default: () => new Date(),
|
|
358
|
+
},
|
|
359
|
+
}, {
|
|
360
|
+
timestamps: true,
|
|
361
|
+
versionKey: false,
|
|
362
|
+
minimize: false,
|
|
363
|
+
});
|
|
364
|
+
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME = 'materialized_tenant_sales_overview_reports';
|
|
365
|
+
/**
|
|
366
|
+
* Describes the indexes for `materialized_tenant_sales_overview_reports`.
|
|
367
|
+
* Values are Mongo key patterns that can be passed straight to `.hint()`.
|
|
368
|
+
* - `_id`: unique primary key.
|
|
369
|
+
* - `tenant_id__scope_context__scope_field`: UNIQUE index — one document per
|
|
370
|
+
* (tenant, scope context, scope value); also serves the standardized query
|
|
371
|
+
* (`tenant_id` + `scope_context` + `scope_field`).
|
|
372
|
+
* - `brand_id__scope_context__scope_field`: brand-level reads across the
|
|
373
|
+
* brand's tenants (sum across their tenant documents).
|
|
374
|
+
* - `tenant_id__scope_context__day_index__scope_field` (+ brand variant):
|
|
375
|
+
* weekday queries over LOCAL_HOUR / LOCAL_DATE slices
|
|
376
|
+
* (`day_index` + `scope_field` range).
|
|
377
|
+
*/
|
|
378
|
+
exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_INDEXES = {
|
|
379
|
+
_id: { _id: 1 }, // Unique Index
|
|
380
|
+
tenant_id__scope_context__scope_field: {
|
|
381
|
+
tenant_id: 1,
|
|
382
|
+
scope_context: 1,
|
|
383
|
+
scope_field: 1,
|
|
384
|
+
}, // unique — one document per (tenant, scope context, scope value)
|
|
385
|
+
brand_id__scope_context__scope_field: {
|
|
386
|
+
brand_id: 1,
|
|
387
|
+
scope_context: 1,
|
|
388
|
+
scope_field: 1,
|
|
389
|
+
}, // brand-level reads across the brand's tenants
|
|
390
|
+
tenant_id__scope_context__scope_field__day_index: {
|
|
391
|
+
tenant_id: 1,
|
|
392
|
+
scope_context: 1,
|
|
393
|
+
scope_field: 1,
|
|
394
|
+
day_index: 1,
|
|
395
|
+
}, // weekday queries over LOCAL_HOUR / LOCAL_DATE slices
|
|
396
|
+
brand_id__scope_context__scope_field__day_index: {
|
|
397
|
+
brand_id: 1,
|
|
398
|
+
scope_context: 1,
|
|
399
|
+
scope_field: 1,
|
|
400
|
+
day_index: 1,
|
|
401
|
+
}, // brand-level weekday queries over LOCAL_HOUR / LOCAL_DATE slices
|
|
402
|
+
};
|
|
@@ -5527,9 +5527,15 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
5527
5527
|
};
|
|
5528
5528
|
tip_amount: number;
|
|
5529
5529
|
tax_amount: number;
|
|
5530
|
-
|
|
5531
|
-
|
|
5530
|
+
localHour?: number | null | undefined;
|
|
5531
|
+
localDate?: string | null | undefined;
|
|
5532
|
+
localWeek?: number | null | undefined;
|
|
5533
|
+
localWeekOfYear?: number | null | undefined;
|
|
5532
5534
|
localMonth?: number | null | undefined;
|
|
5535
|
+
localQuarter?: number | null | undefined;
|
|
5536
|
+
localSemester?: number | null | undefined;
|
|
5537
|
+
localYear?: number | null | undefined;
|
|
5538
|
+
cancel_reason?: string | null | undefined;
|
|
5533
5539
|
localDay?: number | null | undefined;
|
|
5534
5540
|
delete_reason?: string | null | undefined;
|
|
5535
5541
|
is_reopened?: boolean | null | undefined;
|
|
@@ -5547,12 +5553,6 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
5547
5553
|
day_index?: import("../../constants").DAY_INDEX_ENUM | null | undefined;
|
|
5548
5554
|
localSecond?: number | null | undefined;
|
|
5549
5555
|
localMinute?: number | null | undefined;
|
|
5550
|
-
localHour?: number | null | undefined;
|
|
5551
|
-
localWeek?: number | null | undefined;
|
|
5552
|
-
localWeekOfYear?: number | null | undefined;
|
|
5553
|
-
localQuarter?: number | null | undefined;
|
|
5554
|
-
localSemester?: number | null | undefined;
|
|
5555
|
-
localDate?: string | null | undefined;
|
|
5556
5556
|
localTime?: string | null | undefined;
|
|
5557
5557
|
localDayOfYear?: number | null | undefined;
|
|
5558
5558
|
source_tenant_id?: string | null | undefined;
|
|
@@ -11103,9 +11103,15 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
11103
11103
|
};
|
|
11104
11104
|
tip_amount: number;
|
|
11105
11105
|
tax_amount: number;
|
|
11106
|
-
|
|
11107
|
-
|
|
11106
|
+
localHour?: number | null | undefined;
|
|
11107
|
+
localDate?: string | null | undefined;
|
|
11108
|
+
localWeek?: number | null | undefined;
|
|
11109
|
+
localWeekOfYear?: number | null | undefined;
|
|
11108
11110
|
localMonth?: number | null | undefined;
|
|
11111
|
+
localQuarter?: number | null | undefined;
|
|
11112
|
+
localSemester?: number | null | undefined;
|
|
11113
|
+
localYear?: number | null | undefined;
|
|
11114
|
+
cancel_reason?: string | null | undefined;
|
|
11109
11115
|
localDay?: number | null | undefined;
|
|
11110
11116
|
delete_reason?: string | null | undefined;
|
|
11111
11117
|
is_reopened?: boolean | null | undefined;
|
|
@@ -11123,12 +11129,6 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
11123
11129
|
day_index?: import("../../constants").DAY_INDEX_ENUM | null | undefined;
|
|
11124
11130
|
localSecond?: number | null | undefined;
|
|
11125
11131
|
localMinute?: number | null | undefined;
|
|
11126
|
-
localHour?: number | null | undefined;
|
|
11127
|
-
localWeek?: number | null | undefined;
|
|
11128
|
-
localWeekOfYear?: number | null | undefined;
|
|
11129
|
-
localQuarter?: number | null | undefined;
|
|
11130
|
-
localSemester?: number | null | undefined;
|
|
11131
|
-
localDate?: string | null | undefined;
|
|
11132
11132
|
localTime?: string | null | undefined;
|
|
11133
11133
|
localDayOfYear?: number | null | undefined;
|
|
11134
11134
|
source_tenant_id?: string | null | undefined;
|
|
@@ -16679,9 +16679,15 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
16679
16679
|
};
|
|
16680
16680
|
tip_amount: number;
|
|
16681
16681
|
tax_amount: number;
|
|
16682
|
-
|
|
16683
|
-
|
|
16682
|
+
localHour?: number | null | undefined;
|
|
16683
|
+
localDate?: string | null | undefined;
|
|
16684
|
+
localWeek?: number | null | undefined;
|
|
16685
|
+
localWeekOfYear?: number | null | undefined;
|
|
16684
16686
|
localMonth?: number | null | undefined;
|
|
16687
|
+
localQuarter?: number | null | undefined;
|
|
16688
|
+
localSemester?: number | null | undefined;
|
|
16689
|
+
localYear?: number | null | undefined;
|
|
16690
|
+
cancel_reason?: string | null | undefined;
|
|
16685
16691
|
localDay?: number | null | undefined;
|
|
16686
16692
|
delete_reason?: string | null | undefined;
|
|
16687
16693
|
is_reopened?: boolean | null | undefined;
|
|
@@ -16699,12 +16705,6 @@ export declare const OrderSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
16699
16705
|
day_index?: import("../../constants").DAY_INDEX_ENUM | null | undefined;
|
|
16700
16706
|
localSecond?: number | null | undefined;
|
|
16701
16707
|
localMinute?: number | null | undefined;
|
|
16702
|
-
localHour?: number | null | undefined;
|
|
16703
|
-
localWeek?: number | null | undefined;
|
|
16704
|
-
localWeekOfYear?: number | null | undefined;
|
|
16705
|
-
localQuarter?: number | null | undefined;
|
|
16706
|
-
localSemester?: number | null | undefined;
|
|
16707
|
-
localDate?: string | null | undefined;
|
|
16708
16708
|
localTime?: string | null | undefined;
|
|
16709
16709
|
localDayOfYear?: number | null | undefined;
|
|
16710
16710
|
source_tenant_id?: string | null | undefined;
|
|
@@ -7,11 +7,11 @@ export declare const TenantActiveJobSchema: Schema<any, import("mongoose").Model
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
localDate: string;
|
|
10
11
|
_id: import("mongoose").Types.ObjectId;
|
|
11
12
|
tenant_id: string;
|
|
12
13
|
createdAt: NativeDate;
|
|
13
14
|
updatedAt: NativeDate;
|
|
14
|
-
localDate: string;
|
|
15
15
|
progress: number;
|
|
16
16
|
completed_at: NativeDate;
|
|
17
17
|
jobs_status: Map<string, boolean>;
|
|
@@ -23,11 +23,11 @@ export declare const TenantActiveJobSchema: Schema<any, import("mongoose").Model
|
|
|
23
23
|
createdAt: NativeDate;
|
|
24
24
|
updatedAt: NativeDate;
|
|
25
25
|
} & {
|
|
26
|
+
localDate: string;
|
|
26
27
|
_id: import("mongoose").Types.ObjectId;
|
|
27
28
|
tenant_id: string;
|
|
28
29
|
createdAt: NativeDate;
|
|
29
30
|
updatedAt: NativeDate;
|
|
30
|
-
localDate: string;
|
|
31
31
|
progress: number;
|
|
32
32
|
completed_at: NativeDate;
|
|
33
33
|
jobs_status: Map<string, boolean>;
|
|
@@ -39,11 +39,11 @@ export declare const TenantActiveJobSchema: Schema<any, import("mongoose").Model
|
|
|
39
39
|
createdAt: NativeDate;
|
|
40
40
|
updatedAt: NativeDate;
|
|
41
41
|
} & {
|
|
42
|
+
localDate: string;
|
|
42
43
|
_id: import("mongoose").Types.ObjectId;
|
|
43
44
|
tenant_id: string;
|
|
44
45
|
createdAt: NativeDate;
|
|
45
46
|
updatedAt: NativeDate;
|
|
46
|
-
localDate: string;
|
|
47
47
|
progress: number;
|
|
48
48
|
completed_at: NativeDate;
|
|
49
49
|
jobs_status: Map<string, boolean>;
|
|
@@ -7,11 +7,11 @@ export declare const TenantCalendarSchema: Schema<any, import("mongoose").Model<
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
localYear: number;
|
|
10
11
|
_id: import("mongoose").Types.ObjectId;
|
|
11
12
|
tenant_id: string;
|
|
12
13
|
createdAt: NativeDate;
|
|
13
14
|
updatedAt: NativeDate;
|
|
14
|
-
localYear: number;
|
|
15
15
|
days: Map<string, {
|
|
16
16
|
total_orders: number;
|
|
17
17
|
cancelled_orders_amount: number;
|
|
@@ -27,11 +27,11 @@ export declare const TenantCalendarSchema: Schema<any, import("mongoose").Model<
|
|
|
27
27
|
createdAt: NativeDate;
|
|
28
28
|
updatedAt: NativeDate;
|
|
29
29
|
} & {
|
|
30
|
+
localYear: number;
|
|
30
31
|
_id: import("mongoose").Types.ObjectId;
|
|
31
32
|
tenant_id: string;
|
|
32
33
|
createdAt: NativeDate;
|
|
33
34
|
updatedAt: NativeDate;
|
|
34
|
-
localYear: number;
|
|
35
35
|
days: Map<string, {
|
|
36
36
|
total_orders: number;
|
|
37
37
|
cancelled_orders_amount: number;
|
|
@@ -47,11 +47,11 @@ export declare const TenantCalendarSchema: Schema<any, import("mongoose").Model<
|
|
|
47
47
|
createdAt: NativeDate;
|
|
48
48
|
updatedAt: NativeDate;
|
|
49
49
|
} & {
|
|
50
|
+
localYear: number;
|
|
50
51
|
_id: import("mongoose").Types.ObjectId;
|
|
51
52
|
tenant_id: string;
|
|
52
53
|
createdAt: NativeDate;
|
|
53
54
|
updatedAt: NativeDate;
|
|
54
|
-
localYear: number;
|
|
55
55
|
days: Map<string, {
|
|
56
56
|
total_orders: number;
|
|
57
57
|
cancelled_orders_amount: number;
|
|
@@ -7,23 +7,23 @@ export declare const TenantCashDrawerSessionsSchema: Schema<any, import("mongoos
|
|
|
7
7
|
createdAt: NativeDate;
|
|
8
8
|
updatedAt: NativeDate;
|
|
9
9
|
} & {
|
|
10
|
+
localHour: number;
|
|
11
|
+
localDate: string;
|
|
12
|
+
localWeek: number;
|
|
13
|
+
localWeekOfYear: number;
|
|
14
|
+
localMonth: number;
|
|
15
|
+
localQuarter: number;
|
|
16
|
+
localSemester: number;
|
|
17
|
+
localYear: number;
|
|
10
18
|
_id: import("mongoose").Types.ObjectId;
|
|
11
19
|
tenant_id: string;
|
|
12
20
|
createdAt: NativeDate;
|
|
13
21
|
updatedAt: NativeDate;
|
|
14
22
|
status: import("../../constants").CASH_DRAWER_STATUS_ENUM;
|
|
15
|
-
localYear: number;
|
|
16
|
-
localMonth: number;
|
|
17
23
|
localDay: number;
|
|
18
24
|
day_index: import("../../constants").DAY_INDEX_ENUM;
|
|
19
25
|
localSecond: number;
|
|
20
26
|
localMinute: number;
|
|
21
|
-
localHour: number;
|
|
22
|
-
localWeek: number;
|
|
23
|
-
localWeekOfYear: number;
|
|
24
|
-
localQuarter: number;
|
|
25
|
-
localSemester: number;
|
|
26
|
-
localDate: string;
|
|
27
27
|
localTime: string;
|
|
28
28
|
localDayOfYear: number;
|
|
29
29
|
day_id: import("mongoose").Types.ObjectId;
|
|
@@ -142,23 +142,23 @@ export declare const TenantCashDrawerSessionsSchema: Schema<any, import("mongoos
|
|
|
142
142
|
createdAt: NativeDate;
|
|
143
143
|
updatedAt: NativeDate;
|
|
144
144
|
} & {
|
|
145
|
+
localHour: number;
|
|
146
|
+
localDate: string;
|
|
147
|
+
localWeek: number;
|
|
148
|
+
localWeekOfYear: number;
|
|
149
|
+
localMonth: number;
|
|
150
|
+
localQuarter: number;
|
|
151
|
+
localSemester: number;
|
|
152
|
+
localYear: number;
|
|
145
153
|
_id: import("mongoose").Types.ObjectId;
|
|
146
154
|
tenant_id: string;
|
|
147
155
|
createdAt: NativeDate;
|
|
148
156
|
updatedAt: NativeDate;
|
|
149
157
|
status: import("../../constants").CASH_DRAWER_STATUS_ENUM;
|
|
150
|
-
localYear: number;
|
|
151
|
-
localMonth: number;
|
|
152
158
|
localDay: number;
|
|
153
159
|
day_index: import("../../constants").DAY_INDEX_ENUM;
|
|
154
160
|
localSecond: number;
|
|
155
161
|
localMinute: number;
|
|
156
|
-
localHour: number;
|
|
157
|
-
localWeek: number;
|
|
158
|
-
localWeekOfYear: number;
|
|
159
|
-
localQuarter: number;
|
|
160
|
-
localSemester: number;
|
|
161
|
-
localDate: string;
|
|
162
162
|
localTime: string;
|
|
163
163
|
localDayOfYear: number;
|
|
164
164
|
day_id: import("mongoose").Types.ObjectId;
|
|
@@ -277,23 +277,23 @@ export declare const TenantCashDrawerSessionsSchema: Schema<any, import("mongoos
|
|
|
277
277
|
createdAt: NativeDate;
|
|
278
278
|
updatedAt: NativeDate;
|
|
279
279
|
} & {
|
|
280
|
+
localHour: number;
|
|
281
|
+
localDate: string;
|
|
282
|
+
localWeek: number;
|
|
283
|
+
localWeekOfYear: number;
|
|
284
|
+
localMonth: number;
|
|
285
|
+
localQuarter: number;
|
|
286
|
+
localSemester: number;
|
|
287
|
+
localYear: number;
|
|
280
288
|
_id: import("mongoose").Types.ObjectId;
|
|
281
289
|
tenant_id: string;
|
|
282
290
|
createdAt: NativeDate;
|
|
283
291
|
updatedAt: NativeDate;
|
|
284
292
|
status: import("../../constants").CASH_DRAWER_STATUS_ENUM;
|
|
285
|
-
localYear: number;
|
|
286
|
-
localMonth: number;
|
|
287
293
|
localDay: number;
|
|
288
294
|
day_index: import("../../constants").DAY_INDEX_ENUM;
|
|
289
295
|
localSecond: number;
|
|
290
296
|
localMinute: number;
|
|
291
|
-
localHour: number;
|
|
292
|
-
localWeek: number;
|
|
293
|
-
localWeekOfYear: number;
|
|
294
|
-
localQuarter: number;
|
|
295
|
-
localSemester: number;
|
|
296
|
-
localDate: string;
|
|
297
297
|
localTime: string;
|
|
298
298
|
localDayOfYear: number;
|
|
299
299
|
day_id: import("mongoose").Types.ObjectId;
|