@managesome/eposmatic-toolkit 0.4.52 → 0.4.53

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.
Files changed (107) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +106 -2
  2. package/esm/constants/enums/delivery.js +13 -0
  3. package/esm/helpers/materialized-reports/index.js +5 -0
  4. package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
  5. package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +95 -73
  6. package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +118 -146
  7. package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +304 -71
  8. package/esm/helpers/materialized-reports/materialized-delivery-entry-pages.js +307 -0
  9. package/esm/helpers/materialized-reports/materialized-delivery-index-migration.js +103 -0
  10. package/esm/helpers/materialized-reports/materialized-delivery-rows.js +109 -0
  11. package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +32 -0
  12. package/esm/helpers/materialized-reports/materialized-document-size.js +65 -0
  13. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +31 -16
  14. package/esm/helpers/materialized-reports/materialized-integer-contract.js +10 -1
  15. package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -91
  16. package/esm/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +597 -0
  17. package/esm/helpers/materialized-reports/scope-helpers.js +98 -0
  18. package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
  19. package/esm/schemas/models/applied_order_discounts.js +103 -0
  20. package/esm/schemas/models/index.js +12 -10
  21. package/esm/schemas/models/materialized_tenant_delivery_entries.js +33 -12
  22. package/esm/schemas/models/materialized_tenant_delivery_geo_cells.js +83 -0
  23. package/esm/schemas/models/materialized_tenant_delivery_geo_scopes.js +35 -0
  24. package/esm/schemas/models/materialized_tenant_delivery_reports.js +10 -1
  25. package/esm/schemas/types/applied_order_discounts.js +1 -0
  26. package/esm/schemas/types/index.js +14 -12
  27. package/esm/schemas/types/materialized_tenant_delivery_geo_cells.js +1 -0
  28. package/esm/schemas/types/materialized_tenant_delivery_geo_scopes.js +1 -0
  29. package/lib/constants/MATERIALIZED_REPORTS.d.ts +95 -1
  30. package/lib/constants/MATERIALIZED_REPORTS.js +108 -4
  31. package/lib/constants/enums/delivery.d.ts +9 -0
  32. package/lib/constants/enums/delivery.js +14 -1
  33. package/lib/helpers/materialized-reports/index.d.ts +5 -0
  34. package/lib/helpers/materialized-reports/index.js +5 -0
  35. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
  36. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +36 -9
  37. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +94 -72
  38. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +23 -26
  39. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +121 -150
  40. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +44 -5
  41. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +306 -69
  42. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.d.ts +128 -0
  43. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.js +322 -0
  44. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.d.ts +48 -0
  45. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.js +108 -0
  46. package/lib/helpers/materialized-reports/materialized-delivery-rows.d.ts +15 -0
  47. package/lib/helpers/materialized-reports/materialized-delivery-rows.js +115 -0
  48. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +17 -0
  49. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +35 -0
  50. package/lib/helpers/materialized-reports/materialized-document-size.d.ts +47 -0
  51. package/lib/helpers/materialized-reports/materialized-document-size.js +73 -0
  52. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +28 -13
  53. package/lib/helpers/materialized-reports/materialized-integer-contract.js +10 -1
  54. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +2 -90
  55. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.d.ts +186 -0
  56. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +620 -0
  57. package/lib/helpers/materialized-reports/scope-helpers.d.ts +8 -0
  58. package/lib/helpers/materialized-reports/scope-helpers.js +99 -0
  59. package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +41 -0
  60. package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
  61. package/lib/helpers/order/payment-collection.d.ts +25 -0
  62. package/lib/helpers/order/payment-collection.js +51 -0
  63. package/lib/schemas/models/applied_order_discounts.d.ts +80 -0
  64. package/lib/schemas/models/applied_order_discounts.js +106 -0
  65. package/lib/schemas/models/index.d.ts +12 -10
  66. package/lib/schemas/models/index.js +12 -10
  67. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +31 -9
  68. package/lib/schemas/models/materialized_tenant_delivery_entries.js +32 -11
  69. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +129 -0
  70. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.js +86 -0
  71. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +71 -0
  72. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.js +38 -0
  73. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +10 -1
  74. package/lib/schemas/models/materialized_tenant_delivery_reports.js +10 -1
  75. package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +15 -15
  76. package/lib/schemas/types/applied_order_discounts.d.ts +22 -0
  77. package/lib/schemas/types/applied_order_discounts.js +2 -0
  78. package/lib/schemas/types/index.d.ts +14 -12
  79. package/lib/schemas/types/index.js +14 -12
  80. package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +36 -4
  81. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.d.ts +178 -0
  82. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.js +2 -0
  83. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.d.ts +21 -0
  84. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.js +2 -0
  85. package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +49 -7
  86. package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
  87. package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
  88. package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
  89. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +56 -19
  90. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.d.ts +1 -0
  91. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.js +91 -0
  92. package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +271 -15
  93. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.d.ts +1 -0
  94. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.js +128 -0
  95. package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +42 -5
  96. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +13 -1
  97. package/lib/tests/materialized-reports/materialized-delivery-geo.test.d.ts +1 -0
  98. package/lib/tests/materialized-reports/materialized-delivery-geo.test.js +446 -0
  99. package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +117 -25
  100. package/lib/tests/materialized-reports/materialized-delivery-practical.test.d.ts +1 -0
  101. package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +344 -0
  102. package/lib/tests/materialized-reports/materialized-integer-contract.test.js +14 -0
  103. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +1 -1
  104. package/lib/tests/offer-item-resolution.test.js +1 -4
  105. package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
  106. package/lib/tests/payment-collection-timestamps.test.js +71 -0
  107. package/package.json +4 -2
@@ -24,8 +24,8 @@ declare const DiscountSourceKeyMetricsSchema: Schema<any, import("mongoose").Mod
24
24
  discount_amount: number;
25
25
  order_count: number;
26
26
  key: string;
27
- covered_amount: number;
28
27
  row_count: number;
28
+ covered_amount: number;
29
29
  free_item_count: number;
30
30
  free_item_value: number;
31
31
  percentage_row_count: number;
@@ -35,8 +35,8 @@ declare const DiscountSourceKeyMetricsSchema: Schema<any, import("mongoose").Mod
35
35
  discount_amount: number;
36
36
  order_count: number;
37
37
  key: string;
38
- covered_amount: number;
39
38
  row_count: number;
39
+ covered_amount: number;
40
40
  free_item_count: number;
41
41
  free_item_value: number;
42
42
  percentage_row_count: number;
@@ -46,8 +46,8 @@ declare const DiscountSourceKeyMetricsSchema: Schema<any, import("mongoose").Mod
46
46
  discount_amount: number;
47
47
  order_count: number;
48
48
  key: string;
49
- covered_amount: number;
50
49
  row_count: number;
50
+ covered_amount: number;
51
51
  free_item_count: number;
52
52
  free_item_value: number;
53
53
  percentage_row_count: number;
@@ -83,12 +83,12 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
83
83
  schema_version: number;
84
84
  source_watermark: NativeDate;
85
85
  computed_at: NativeDate;
86
+ row_count: number;
86
87
  kind: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM;
87
88
  sub_kind: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_SUB_KIND_ENUM;
88
89
  level: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_LEVEL_ENUM;
89
90
  complimentary_full: boolean;
90
91
  covered_amount: number;
91
- row_count: number;
92
92
  free_item_count: number;
93
93
  free_item_value: number;
94
94
  percentage_row_count: number;
@@ -101,8 +101,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
101
101
  discount_amount: number;
102
102
  order_count: number;
103
103
  key: string;
104
- covered_amount: number;
105
104
  row_count: number;
105
+ covered_amount: number;
106
106
  free_item_count: number;
107
107
  free_item_value: number;
108
108
  percentage_row_count: number;
@@ -112,8 +112,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
112
112
  discount_amount: number;
113
113
  order_count: number;
114
114
  key: string;
115
- covered_amount: number;
116
115
  row_count: number;
116
+ covered_amount: number;
117
117
  free_item_count: number;
118
118
  free_item_value: number;
119
119
  percentage_row_count: number;
@@ -123,8 +123,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
123
123
  discount_amount: number;
124
124
  order_count: number;
125
125
  key: string;
126
- covered_amount: number;
127
126
  row_count: number;
127
+ covered_amount: number;
128
128
  free_item_count: number;
129
129
  free_item_value: number;
130
130
  percentage_row_count: number;
@@ -152,12 +152,12 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
152
152
  schema_version: number;
153
153
  source_watermark: NativeDate;
154
154
  computed_at: NativeDate;
155
+ row_count: number;
155
156
  kind: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM;
156
157
  sub_kind: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_SUB_KIND_ENUM;
157
158
  level: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_LEVEL_ENUM;
158
159
  complimentary_full: boolean;
159
160
  covered_amount: number;
160
- row_count: number;
161
161
  free_item_count: number;
162
162
  free_item_value: number;
163
163
  percentage_row_count: number;
@@ -170,8 +170,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
170
170
  discount_amount: number;
171
171
  order_count: number;
172
172
  key: string;
173
- covered_amount: number;
174
173
  row_count: number;
174
+ covered_amount: number;
175
175
  free_item_count: number;
176
176
  free_item_value: number;
177
177
  percentage_row_count: number;
@@ -181,8 +181,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
181
181
  discount_amount: number;
182
182
  order_count: number;
183
183
  key: string;
184
- covered_amount: number;
185
184
  row_count: number;
185
+ covered_amount: number;
186
186
  free_item_count: number;
187
187
  free_item_value: number;
188
188
  percentage_row_count: number;
@@ -192,8 +192,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
192
192
  discount_amount: number;
193
193
  order_count: number;
194
194
  key: string;
195
- covered_amount: number;
196
195
  row_count: number;
196
+ covered_amount: number;
197
197
  free_item_count: number;
198
198
  free_item_value: number;
199
199
  percentage_row_count: number;
@@ -221,12 +221,12 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
221
221
  schema_version: number;
222
222
  source_watermark: NativeDate;
223
223
  computed_at: NativeDate;
224
+ row_count: number;
224
225
  kind: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM;
225
226
  sub_kind: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_SUB_KIND_ENUM;
226
227
  level: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_DISCOUNT_LEVEL_ENUM;
227
228
  complimentary_full: boolean;
228
229
  covered_amount: number;
229
- row_count: number;
230
230
  free_item_count: number;
231
231
  free_item_value: number;
232
232
  percentage_row_count: number;
@@ -239,8 +239,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
239
239
  discount_amount: number;
240
240
  order_count: number;
241
241
  key: string;
242
- covered_amount: number;
243
242
  row_count: number;
243
+ covered_amount: number;
244
244
  free_item_count: number;
245
245
  free_item_value: number;
246
246
  percentage_row_count: number;
@@ -250,8 +250,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
250
250
  discount_amount: number;
251
251
  order_count: number;
252
252
  key: string;
253
- covered_amount: number;
254
253
  row_count: number;
254
+ covered_amount: number;
255
255
  free_item_count: number;
256
256
  free_item_value: number;
257
257
  percentage_row_count: number;
@@ -261,8 +261,8 @@ export declare const MaterializedTenantDiscountSourceSchema: Schema<any, import(
261
261
  discount_amount: number;
262
262
  order_count: number;
263
263
  key: string;
264
- covered_amount: number;
265
264
  row_count: number;
265
+ covered_amount: number;
266
266
  free_item_count: number;
267
267
  free_item_value: number;
268
268
  percentage_row_count: number;
@@ -0,0 +1,22 @@
1
+ import { DISCOUNT_APPLICABILITY_ENUM, DISCOUNT_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
2
+ export interface IAppliedOrderDiscount {
3
+ _id: string;
4
+ tenant_id: string;
5
+ order_id: string;
6
+ discount_id: string;
7
+ type: DISCOUNT_TYPE_ENUM;
8
+ applicability: DISCOUNT_APPLICABILITY_ENUM;
9
+ platform: PLATFORMS_ENUM;
10
+ name: string;
11
+ order_amount: number;
12
+ discount_amount: number;
13
+ discount_rate: number | null;
14
+ reason: string;
15
+ reference_number: string | null;
16
+ staff_id: string;
17
+ staff_phone: string;
18
+ staff_name: string;
19
+ createdAt_mins: number;
20
+ createdAt: Date;
21
+ updatedAt: Date;
22
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -31,17 +31,26 @@ export * from './item_transactions';
31
31
  export * from './items';
32
32
  export * from './marketing_fingerprints';
33
33
  export * from './materialized_credit_bills';
34
- export * from './materialized_tenant_discount_entries';
35
- export * from './materialized_tenant_discount_reports';
36
- export * from './materialized_tenant_discount_sources';
34
+ export * from './materialized_report_drilldown_rows';
35
+ export * from './materialized_rider_daily_reports';
37
36
  export * from './materialized_tenant_cash_entries';
37
+ export * from './materialized_tenant_cash_reports';
38
38
  export * from './materialized_tenant_delivery_entries';
39
+ export * from './materialized_tenant_delivery_geo_cells';
40
+ export * from './materialized_tenant_delivery_geo_scopes';
39
41
  export * from './materialized_tenant_delivery_reports';
40
- export * from './materialized_rider_daily_reports';
41
- export * from './materialized_tenant_cash_reports';
42
+ export * from './materialized_tenant_discount_entries';
43
+ export * from './materialized_tenant_discount_reports';
44
+ export * from './materialized_tenant_discount_sources';
45
+ export * from './materialized_tenant_hourly_comparison_entries';
46
+ export * from './materialized_tenant_hourly_comparison_reports';
47
+ export * from './materialized_tenant_payments_comparison_entries';
48
+ export * from './materialized_tenant_payments_comparison_reports';
42
49
  export * from './materialized_tenant_prep_time_entries';
43
50
  export * from './materialized_tenant_prep_time_reports';
44
51
  export * from './materialized_tenant_reports_iterations';
52
+ export * from './materialized_tenant_sales_comparison_entries';
53
+ export * from './materialized_tenant_sales_comparison_reports';
45
54
  export * from './materialized_tenant_sales_overview_reports';
46
55
  export * from './menus';
47
56
  export * from './messaging_devices';
@@ -124,10 +133,3 @@ export * from './warehouse_vendors';
124
133
  export * from './warehouse_void_purchase_order_items';
125
134
  export * from './warehouse_void_sale_order_items';
126
135
  export * from './warehouses';
127
- export * from './materialized_tenant_sales_comparison_reports';
128
- export * from './materialized_tenant_sales_comparison_entries';
129
- export * from './materialized_tenant_hourly_comparison_reports';
130
- export * from './materialized_tenant_hourly_comparison_entries';
131
- export * from './materialized_tenant_payments_comparison_reports';
132
- export * from './materialized_tenant_payments_comparison_entries';
133
- export * from './materialized_report_drilldown_rows';
@@ -47,17 +47,26 @@ __exportStar(require("./item_transactions"), exports);
47
47
  __exportStar(require("./items"), exports);
48
48
  __exportStar(require("./marketing_fingerprints"), exports);
49
49
  __exportStar(require("./materialized_credit_bills"), exports);
50
- __exportStar(require("./materialized_tenant_discount_entries"), exports);
51
- __exportStar(require("./materialized_tenant_discount_reports"), exports);
52
- __exportStar(require("./materialized_tenant_discount_sources"), exports);
50
+ __exportStar(require("./materialized_report_drilldown_rows"), exports);
51
+ __exportStar(require("./materialized_rider_daily_reports"), exports);
53
52
  __exportStar(require("./materialized_tenant_cash_entries"), exports);
53
+ __exportStar(require("./materialized_tenant_cash_reports"), exports);
54
54
  __exportStar(require("./materialized_tenant_delivery_entries"), exports);
55
+ __exportStar(require("./materialized_tenant_delivery_geo_cells"), exports);
56
+ __exportStar(require("./materialized_tenant_delivery_geo_scopes"), exports);
55
57
  __exportStar(require("./materialized_tenant_delivery_reports"), exports);
56
- __exportStar(require("./materialized_rider_daily_reports"), exports);
57
- __exportStar(require("./materialized_tenant_cash_reports"), exports);
58
+ __exportStar(require("./materialized_tenant_discount_entries"), exports);
59
+ __exportStar(require("./materialized_tenant_discount_reports"), exports);
60
+ __exportStar(require("./materialized_tenant_discount_sources"), exports);
61
+ __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
62
+ __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
63
+ __exportStar(require("./materialized_tenant_payments_comparison_entries"), exports);
64
+ __exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
58
65
  __exportStar(require("./materialized_tenant_prep_time_entries"), exports);
59
66
  __exportStar(require("./materialized_tenant_prep_time_reports"), exports);
60
67
  __exportStar(require("./materialized_tenant_reports_iterations"), exports);
68
+ __exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
69
+ __exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
61
70
  __exportStar(require("./materialized_tenant_sales_overview_reports"), exports);
62
71
  __exportStar(require("./menus"), exports);
63
72
  __exportStar(require("./messaging_devices"), exports);
@@ -140,10 +149,3 @@ __exportStar(require("./warehouse_vendors"), exports);
140
149
  __exportStar(require("./warehouse_void_purchase_order_items"), exports);
141
150
  __exportStar(require("./warehouse_void_sale_order_items"), exports);
142
151
  __exportStar(require("./warehouses"), exports);
143
- __exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
144
- __exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
145
- __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
146
- __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
147
- __exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
148
- __exportStar(require("./materialized_tenant_payments_comparison_entries"), exports);
149
- __exportStar(require("./materialized_report_drilldown_rows"), exports);
@@ -2,7 +2,7 @@ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
2
  import { DELIVERY_STATUS_ENUM } from '../../constants/enums/delivery';
3
3
  import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
4
4
  /**
5
- * Types for `materialized_tenant_delivery_entries` (M4, decision (e4)).
5
+ * Types for `materialized_tenant_delivery_entries` (M4, page-partitioned).
6
6
  *
7
7
  * The statement rows behind the delivery drill-down. The POLYLINE IS NOT STORED: a GPS
8
8
  * trace per row would dominate the collection, so a row keeps only its POINT COUNT and a
@@ -12,6 +12,19 @@ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } f
12
12
  * `order_id` at compile time, so the read needs no second lookup and the drill-down can
13
13
  * show what an operator recognises.
14
14
  *
15
+ * ## ONE PAGE PER SOURCE DAY
16
+ *
17
+ * A document is bounded by ONE day's rows, never a month's:
18
+ *
19
+ * | scope | page |
20
+ * | --- | --- |
21
+ * | `localDate` | `'all'` |
22
+ * | `localWeek` / `localWeekOfYear` / `localMonth` | `<source localDate>` |
23
+ *
24
+ * There are NO quarter / semester / year entry documents. A broad details selection is
25
+ * served by reading the month pages it touches and filtering rows to the exact selected
26
+ * days.
27
+ *
15
28
  * Null means UNMEASURED, never zero: `assigned_at` / `delivered_at` are null on any
16
29
  * document written before the metrics capture, and every derived duration is null rather
17
30
  * than 0 - reporting 0 would claim the delivery was instantaneous.
@@ -36,9 +49,18 @@ export interface IMaterializedDeliveryEntry {
36
49
  /** Trace SIZE only - the polyline itself is deliberately not stored. */
37
50
  polyline_point_count: number;
38
51
  platform: string;
52
+ /** ORDER_STATUS_ENUM of the joined order (or UNKNOWN). */
53
+ order_status: string;
39
54
  city: string | null;
40
55
  state: string | null;
41
- street: string | null;
56
+ /**
57
+ * Tenant-local source day of the row: the JOINED ORDER's `localDate`.
58
+ * Falls back to `delivery.localDate` only when the order is missing, and then
59
+ * `source_day_unattributed` is true.
60
+ */
61
+ source_local_date: string;
62
+ /** True when the order was missing and the source day fell back to the delivery. */
63
+ source_day_unattributed: boolean;
42
64
  /** CENTS. */
43
65
  net_sale_amount: number;
44
66
  collected_amount: number;
@@ -64,20 +86,30 @@ export interface IMaterializedDeliveryEntry {
64
86
  created_at: Date;
65
87
  /** Time-of-day stamp, mirroring the delivery document field. */
66
88
  created_at_mins: number | null;
67
- /** `YYYY-MM-DD HH` punch hour (null when unresolvable). */
89
+ /**
90
+ * Tenant-local stamp of the joined ORDER: `${YYYY-MM-DD} ${HH:MM}` when the
91
+ * order's minute is known, `${YYYY-MM-DD} ${HH}` when only the hour exists
92
+ * (never a synthetic `:00`), null when unresolvable.
93
+ */
68
94
  local_hour: string | null;
69
95
  }
70
96
  /** Per-key row section of one document. */
71
97
  export interface IMaterializedDeliveryKeySection {
72
98
  rows: IMaterializedDeliveryEntry[];
73
99
  }
74
- /** One `materialized_tenant_delivery_entries` document, capped at `LOCAL_MONTH`. */
100
+ /**
101
+ * One `materialized_tenant_delivery_entries` PAGE - tenant x scope context x scope
102
+ * value x source day. One page holds one day's rows; a month is covered by its days.
103
+ */
75
104
  export interface IMaterializedTenantDeliveryEntries {
76
105
  _id: string;
77
106
  tenant_id: string;
78
107
  brand_id: string;
108
+ /** One of `MATERIALIZED_DELIVERY_ENTRY_SCOPES` (date / week / ISO week / month). */
79
109
  scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
80
110
  scope_field: string;
111
+ /** `'all'` for the day scope; the source `YYYY-MM-DD` for a period scope. */
112
+ page: string;
81
113
  /** Denormalized weekday - set ONLY on `LOCAL_DATE` documents. */
82
114
  day_index?: DAY_INDEX_ENUM | null;
83
115
  sale_type_key_filters: MATERIALIZED_REPORT_KEY_FILTER_ENUM[];
@@ -0,0 +1,178 @@
1
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
+ /**
3
+ * Types for `materialized_tenant_delivery_geo_cells` (delivery demand heat map).
4
+ *
5
+ * ## Why this is a SEPARATE collection
6
+ *
7
+ * The heat map is the only part of the delivery report whose cardinality depends on
8
+ * GEOGRAPHY rather than on a fixed dimension set. Embedding it in the report document
9
+ * would put an unbounded array of cells next to the counters and eventually breach the
10
+ * 16 MiB document limit. So the report document stays counters-only and the cells live
11
+ * here, one document per cell.
12
+ *
13
+ * ## One document per `tenant_id + scope_context + scope_field + h3_cell`
14
+ *
15
+ * `scope_context` is ONLY `localDate` or `localMonth`. Each document is a cell's
16
+ * aggregate for one day or one month - never a raw order, never a raw customer point.
17
+ *
18
+ * ## No raw coordinates, ever
19
+ *
20
+ * The only geometry stored is the cell's DERIVED CENTROID (the H3 cell centre), which
21
+ * is a property of the cell and identical for every order inside it. The unknown bucket
22
+ * (`__UNKNOWN__`) deliberately has NO `location` at all, so an unattributable order can
23
+ * never be plotted.
24
+ *
25
+ * ## Money and counts are integer CENTS / counts
26
+ *
27
+ * `net_sale_amount` / `delivery_charge_amount` / `rider_revenue_amount` are integer
28
+ * cents; every other numeric field is an integer count, per the toolkit's
29
+ * integer-only storage contract.
30
+ */
31
+ export interface IDeliveryGeoPoint {
32
+ type: 'Point';
33
+ /** `[lng, lat]` - GeoJSON order, required by the 2dsphere index. */
34
+ coordinates: [number, number];
35
+ }
36
+ /** The counters of ONE heat cell. All integers; money in CENTS. */
37
+ export interface IMaterializedDeliveryGeoCounters {
38
+ /** Delivery ORDERS in the cell (the adoption denominator / demand unit). */
39
+ orders: number;
40
+ /** Unique orders in the cell that produced at least one delivery document. */
41
+ app_orders: number;
42
+ /** Delivery documents / attempts in the cell (>= `app_orders` on reassignment). */
43
+ delivery_records: number;
44
+ completed: number;
45
+ cancelled: number;
46
+ net_sale_amount: number;
47
+ delivery_charge_amount: number;
48
+ rider_revenue_amount: number;
49
+ }
50
+ /** Counters for one `ORDER_STATUS:PLATFORM:CITY` dimension inside a cell. */
51
+ export type IMaterializedDeliveryGeoKeyCounters = IMaterializedDeliveryGeoCounters;
52
+ /**
53
+ * Bounded per-cell filter map. Key = `ORDER_STATUS:PLATFORM:CITY` - the SAME grammar as
54
+ * the report counters, with the RESOLVED city (top-N + `__OTHER__`, `UNKNOWN` when the
55
+ * order carries no city).
56
+ *
57
+ * Because the city is part of the key, a cell that holds orders from several cities can
58
+ * be filtered by city EXACTLY: the selected city's counters are summed out of the map
59
+ * instead of the cell being attributed to its dominant city.
60
+ *
61
+ * Sum(by_key) equals the cell's top-level counters (including the UNKNOWN token for
62
+ * orphan records). The map is capped (see MATERIALIZED_DELIVERY_GEO_MAX_KEYS).
63
+ */
64
+ export type TMaterializedDeliveryGeoByKey = Record<string, IMaterializedDeliveryGeoKeyCounters>;
65
+ /** One `materialized_tenant_delivery_geo_cells` document. */
66
+ export interface IMaterializedTenantDeliveryGeoCell extends IMaterializedDeliveryGeoCounters {
67
+ _id?: string;
68
+ tenant_id: string;
69
+ brand_id: string;
70
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
71
+ scope_field: string;
72
+ /**
73
+ * Dominant city of the cell's orders (max orders; ties resolved by city ASC), or
74
+ * `null` when the joined orders carry no city. The city is derived, never a key -
75
+ * filtering uses the by_key map, never this label.
76
+ */
77
+ city: string | null;
78
+ /** H3 cell index at `resolution`, or the sentinel `__UNKNOWN__`. */
79
+ h3_cell: string;
80
+ /** H3 resolution; `0` for the unknown bucket (which has no cell). */
81
+ resolution: number;
82
+ /**
83
+ * GeoJSON centroid of the cell. ABSENT for the unknown bucket - a document without
84
+ * `location` is simply not indexed by the 2dsphere index.
85
+ */
86
+ location?: IDeliveryGeoPoint;
87
+ /** Bounded ORDER_STATUS:PLATFORM:CITY map; sum equals the top-level counters. */
88
+ by_key?: TMaterializedDeliveryGeoByKey | null;
89
+ schema_version: number;
90
+ computed_at: Date;
91
+ createdAt?: Date;
92
+ updatedAt?: Date;
93
+ }
94
+ /**
95
+ * The heat-endpoint cell shape: aggregates ONLY.
96
+ *
97
+ * It intentionally omits `tenant_id` / `brand_id` / scope fields - the response is for
98
+ * one selection and one view, and repeating the selection on every cell would balloon
99
+ * the payload without telling the map anything.
100
+ *
101
+ * Only MAPPABLE cells appear: the response never carries a raw point and never carries a
102
+ * cell without a centroid. The difference between `total_orders` and the sum of the
103
+ * returned cells is capped / suppressed / unmappable demand - the totals are explicit so
104
+ * that gap is never mistaken for zero.
105
+ */
106
+ export interface IDeliveryGeoCellResponse {
107
+ h3_cell: string;
108
+ /**
109
+ * `[lng, lat]` derived cell centroid. ALWAYS present: a cell without geometry (the
110
+ * unknown aggregate) is not part of the map payload - the map cannot place it, and
111
+ * exposing it with a null centroid would break the frozen client contract.
112
+ */
113
+ centroid: [number, number];
114
+ resolution: number;
115
+ city: string | null;
116
+ orders: number;
117
+ app_orders: number;
118
+ delivery_records: number;
119
+ completed: number;
120
+ cancelled: number;
121
+ net_sale: number;
122
+ delivery_charge: number;
123
+ rider_revenue: number;
124
+ }
125
+ /**
126
+ * Why the heat map is intentionally disabled for a selection.
127
+ *
128
+ * `OTHER_AREAS`: `__OTHER__` is a KEY-FOLD bucket (cities beyond the report's top-50). It
129
+ * has no geography of its own, so the map cannot isolate it. Totals and tables are still
130
+ * valid; the UI must show the explanation instead of an empty map.
131
+ */
132
+ export type TDeliveryGeoMapDisabledReason = 'OTHER_AREAS';
133
+ /** `POST /reports/delivery/geo` response. */
134
+ export interface IDeliveryGeoResponse {
135
+ cells: IDeliveryGeoCellResponse[];
136
+ /** Cells hidden because `orders < MATERIALIZED_DELIVERY_GEO_MIN_ORDERS`. */
137
+ suppressed_cell_count: number;
138
+ /** Orders inside those hidden cells. */
139
+ suppressed_order_count: number;
140
+ /** Cells dropped because the scope exceeded `MATERIALIZED_DELIVERY_GEO_MAX_CELLS`. */
141
+ capped_cell_count: number;
142
+ /** Orders inside those capped cells. */
143
+ capped_order_count: number;
144
+ /**
145
+ * True when the cap counts describe the same population as the filters. Platform/
146
+ * order-status filters cannot be applied to a write-time cap, so they mark this false
147
+ * rather than silently returning 0.
148
+ */
149
+ capped_counts_exact: boolean;
150
+ /** Delivery ORDERS in the whole selected scope (from the report counters). */
151
+ total_orders: number;
152
+ /** Unique app orders in the whole selected scope. */
153
+ total_app_orders: number;
154
+ /**
155
+ * Granularity actually read for the cells.
156
+ *
157
+ * `DAY` - exact cells for the selected days (all days within day-cell retention);
158
+ * `MONTH` - whole-month cells because at least one selected day is older than the
159
+ * day-cell retention window. The UI must label a `MONTH` map as month-granular.
160
+ */
161
+ granularity: 'DAY' | 'MONTH';
162
+ /** True only when the cells cover exactly the selected days. */
163
+ exact_days: boolean;
164
+ /**
165
+ * Orders in the selected scope whose geometry could not be resolved. They are in the
166
+ * counters/totals but cannot be placed on a map; the UI must report them instead of
167
+ * silently showing a cell/total gap.
168
+ */
169
+ unknown_order_count: number;
170
+ /**
171
+ * True when the selection cannot be geographically isolated. When true, `cells` is
172
+ * ALWAYS empty and the UI must render the reason instead of a map; totals and tables
173
+ * remain valid. This is how a non-zero total with no cells is explained honestly.
174
+ */
175
+ map_disabled?: boolean;
176
+ /** Reason for `map_disabled`; null/absent when the map is available. */
177
+ map_disabled_reason?: TDeliveryGeoMapDisabledReason | null;
178
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
+ /**
3
+ * Small cap metadata document for ONE geo scope.
4
+ *
5
+ * The cell cap drops cells before persistence, so the dropped counts cannot be
6
+ * reconstructed at read time. This collection stores ONLY the counts, one document per
7
+ * tenant + scope + field; it never stores itemized cells or geometry.
8
+ */
9
+ export interface IMaterializedTenantDeliveryGeoScope {
10
+ _id?: string;
11
+ tenant_id: string;
12
+ brand_id: string;
13
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
14
+ scope_field: string;
15
+ capped_cell_count: number;
16
+ capped_order_count: number;
17
+ schema_version: number;
18
+ computed_at: Date;
19
+ createdAt?: Date;
20
+ updatedAt?: Date;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -11,7 +11,7 @@ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } f
11
11
  * (`delivery_order_count` vs `delivered_via_app_count`) before it states any metric, and
12
12
  * `off_app_count` is published as the pool the app can win rather than as an error.
13
13
  *
14
- * KEY GRAMMAR is `<PLATFORM>:<CITY>`, both JOINED FROM THE ORDER: a delivery document
14
+ * KEY GRAMMAR is `<ORDER_STATUS>:<PLATFORM>:<CITY>`, all JOINED FROM THE ORDER: a delivery document
15
15
  * carries neither, so the report joins by `order_id` and keys on the order dimensions.
16
16
  * Rider is deliberately NOT a key dimension - rider ids are high-cardinality, so rider
17
17
  * analysis is a bounded `riders` map inside the document.
@@ -24,7 +24,7 @@ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } f
24
24
  export interface IMaterializedDeliveryAdoption {
25
25
  /** Delivery ORDERS in scope - the denominator, from the orders stage. */
26
26
  delivery_order_count: number;
27
- /** Deliveries present in the `deliveries` collection - the numerator. */
27
+ /** UNIQUE delivery ORDERS with at least one delivery document - the numerator. */
28
28
  delivered_via_app_count: number;
29
29
  /** delivery orders with NO delivery document. NOT an error: the pool to win. */
30
30
  off_app_count: number;
@@ -55,7 +55,13 @@ export interface IMaterializedDeliveryMoney {
55
55
  tip_amount: number;
56
56
  /** Order-level discounts, in cents. */
57
57
  discount_amount: number;
58
- /** Refunded order money, in cents. */
58
+ /**
59
+ * Refunded order money, in cents - Σ `order.payments[].amount_refunded`.
60
+ *
61
+ * `IOrder` does NOT declare an order-level `amount_refunded`; refund money exists only
62
+ * on its payment rows. Reading an undeclared order field would silently report every
63
+ * refund as zero, so the accumulator sums the declared source.
64
+ */
59
65
  refund_amount: number;
60
66
  /** Tax on the delivery order, in cents. */
61
67
  tax_amount: number;
@@ -83,14 +89,44 @@ export interface IMaterializedDeliveryRiderRow {
83
89
  first_delivery_at: Date | null;
84
90
  last_delivery_at: Date | null;
85
91
  }
86
- /** One area row, carrying the hot-area hour histogram. */
92
+ /**
93
+ * One area row.
94
+ *
95
+ * AREA ROWS DISTINGUISH THE TWO POPULATIONS, because they are not the same population:
96
+ *
97
+ * - `delivery_orders` / `net_sale_amount` / `delivery_charge_amount` come from the
98
+ * ORDER side, so an OFF-APP delivery order is present (it is a real delivery sale the
99
+ * operator recognizes even when no rider-app document exists);
100
+ * - `delivery_records` / `completed_count` / `cancelled_count` / `rider_revenue_amount`
101
+ * come from the APP side (delivery documents/attempts).
102
+ *
103
+ * `app_orders` is the unique-order intersection, never the record count - one order may
104
+ * have several attempts after a reassignment and must still count once.
105
+ *
106
+ * `by_hour` is the DEMAND heat map: DELIVERY ORDERS bucketed by the JOINED ORDER's
107
+ * tenant-local `localHour` (`"00"`..`"23"`), NOT by any delivery-side hour. The delivery
108
+ * write path has no `localHour`, and deriving one from a server clock would silently
109
+ * shift the map in every non-UTC tenant.
110
+ */
87
111
  export interface IMaterializedDeliveryAreaRow {
88
- count: number;
112
+ /** All delivery ORDERS in this area - the adoption denominator and the demand unit. */
113
+ delivery_orders: number;
114
+ /** Unique orders in this area with at least one delivery document. */
115
+ app_orders: number;
116
+ /** Delivery orders in this area with NO delivery document. */
117
+ off_app_orders: number;
118
+ /** Delivery documents / attempts in this area (>= `app_orders` on reassignment). */
119
+ delivery_records: number;
89
120
  completed_count: number;
90
121
  cancelled_count: number;
122
+ /** CENTS, order side (includes off-app orders). */
123
+ net_sale_amount: number;
124
+ /** CENTS, order side (includes off-app orders). */
125
+ delivery_charge_amount: number;
126
+ /** CENTS, app side - finalized rider payout only. */
91
127
  rider_revenue_amount: number;
92
128
  distance_sum_meters: number;
93
- /** Keys are `"00"`..`"23"` - the hour dimension, as a heat map. */
129
+ /** Keys are `"00"`..`"23"` - delivery ORDERS by the order's local hour. */
94
130
  by_hour: Record<string, number>;
95
131
  }
96
132
  /**
@@ -98,8 +134,14 @@ export interface IMaterializedDeliveryAreaRow {
98
134
  * the capture has NO timing evidence, and reporting 0 would claim instant delivery.
99
135
  */
100
136
  export interface IMaterializedDeliveryTiming {
101
- /** Deliveries that contributed at least one timing figure. */
137
+ /** Deliveries that contributed at least one timing figure (compatibility total). */
102
138
  graded_count: number;
139
+ /** Deliveries with both an order creation instant and a delivery creation instant. */
140
+ dispatch_lag_count: number;
141
+ /** Completed deliveries whose completion instant is known (exact OR proxy). */
142
+ complete_count: number;
143
+ /** Completed deliveries with both an order creation instant and a completion. */
144
+ total_count: number;
103
145
  /** `delivery.createdAt - order.createdAt` - precise even without the capture. */
104
146
  dispatch_lag_sum_minutes: number;
105
147
  /** `delivered_at - delivery.createdAt`, EXACT once the capture has run. */