@managesome/eposmatic-toolkit 0.4.59 → 0.4.61

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 (74) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +177 -8
  2. package/esm/helpers/materialized-reports/index.js +7 -0
  3. package/esm/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  4. package/esm/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +557 -0
  5. package/esm/helpers/materialized-reports/materialized-dinein-classification-helpers.js +447 -0
  6. package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +372 -0
  7. package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +500 -0
  8. package/esm/helpers/materialized-reports/materialized-dinein-entry-pages.js +218 -0
  9. package/esm/helpers/materialized-reports/materialized-dinein-key-helpers.js +87 -0
  10. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  11. package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  12. package/esm/helpers/materialized-reports/report-platform/definition.js +93 -1
  13. package/esm/helpers/materialized-reports/tenant-dinein-formatter.js +240 -0
  14. package/esm/helpers/reporting-contract/report-contract.js +3 -0
  15. package/esm/schemas/models/index.js +2 -0
  16. package/esm/schemas/models/materialized_tenant_dinein_entries.js +57 -0
  17. package/esm/schemas/models/materialized_tenant_dinein_reports.js +73 -0
  18. package/esm/schemas/types/index.js +2 -0
  19. package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
  20. package/esm/schemas/types/materialized_tenant_dinein_entries.js +1 -0
  21. package/esm/schemas/types/materialized_tenant_dinein_reports.js +6 -0
  22. package/lib/constants/MATERIALIZED_REPORTS.d.ts +160 -8
  23. package/lib/constants/MATERIALIZED_REPORTS.js +178 -9
  24. package/lib/helpers/materialized-reports/index.d.ts +7 -0
  25. package/lib/helpers/materialized-reports/index.js +7 -0
  26. package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +1 -1
  27. package/lib/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  28. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.d.ts +67 -0
  29. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +582 -0
  30. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.d.ts +245 -0
  31. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.js +469 -0
  32. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.d.ts +110 -0
  33. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +384 -0
  34. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.d.ts +73 -0
  35. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +504 -0
  36. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.d.ts +69 -0
  37. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.js +231 -0
  38. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.d.ts +44 -0
  39. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.js +96 -0
  40. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  41. package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  42. package/lib/helpers/materialized-reports/report-platform/definition.js +92 -0
  43. package/lib/helpers/materialized-reports/tenant-dinein-formatter.d.ts +225 -0
  44. package/lib/helpers/materialized-reports/tenant-dinein-formatter.js +243 -0
  45. package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
  46. package/lib/helpers/reporting-contract/report-contract.js +3 -0
  47. package/lib/schemas/models/index.d.ts +2 -0
  48. package/lib/schemas/models/index.js +2 -0
  49. package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +3 -3
  50. package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +100 -0
  51. package/lib/schemas/models/materialized_tenant_dinein_entries.js +60 -0
  52. package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +111 -0
  53. package/lib/schemas/models/materialized_tenant_dinein_reports.js +76 -0
  54. package/lib/schemas/types/index.d.ts +2 -0
  55. package/lib/schemas/types/index.js +2 -0
  56. package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
  57. package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
  58. package/lib/schemas/types/materialized_tenant_dinein_entries.d.ts +127 -0
  59. package/lib/schemas/types/materialized_tenant_dinein_entries.js +2 -0
  60. package/lib/schemas/types/materialized_tenant_dinein_reports.d.ts +326 -0
  61. package/lib/schemas/types/materialized_tenant_dinein_reports.js +9 -0
  62. package/lib/tests/materialized-reports/dinein-fixtures.d.ts +29 -0
  63. package/lib/tests/materialized-reports/dinein-fixtures.js +130 -0
  64. package/lib/tests/materialized-reports/materialized-day-readiness.test.js +3 -2
  65. package/lib/tests/materialized-reports/materialized-dinein-compile.test.d.ts +1 -0
  66. package/lib/tests/materialized-reports/materialized-dinein-compile.test.js +807 -0
  67. package/lib/tests/materialized-reports/materialized-dinein-plan.test.d.ts +1 -0
  68. package/lib/tests/materialized-reports/materialized-dinein-plan.test.js +419 -0
  69. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.d.ts +1 -0
  70. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.js +185 -0
  71. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +15 -2
  72. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.d.ts +1 -0
  73. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +299 -0
  74. package/package.json +1 -1
@@ -0,0 +1,245 @@
1
+ import { MATERIALIZED_DINEIN_ORIGIN_ENUM, MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM, MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
+ import { IDineinSourceDayCounts } from '../../schemas/types/materialized_tenant_dinein_entries';
3
+ import { IMaterializedDineinCounters } from '../../schemas/types/materialized_tenant_dinein_reports';
4
+ /**
5
+ * Dinein classification: the source shapes, the frozen derivations and the
6
+ * per-check accumulator.
7
+ *
8
+ * ## The order is the source; the fingerprint is only the seating truth
9
+ *
10
+ * Sales, items, courses, edits and ratings come from the ORDER. Covers, table
11
+ * sessions and seated occupancy come from the TABLE-CLOSE fingerprint joined by
12
+ * `order_id`. Neither is derivable from the other, and a check with no
13
+ * fingerprint keeps its sale but has NO covers and NO occupancy — the gap is
14
+ * counted (`orders_without_fingerprint`), never invented.
15
+ *
16
+ * ## Split bills
17
+ *
18
+ * The auto-deleted parent is not a collectable check. It is read ONLY for
19
+ * rating/review discovery: a guest rates the visit once, and that rating may
20
+ * live on the parent. A parent rating is credited to exactly ONE child (the
21
+ * smallest order id) so a replicated rating is never counted twice.
22
+ */
23
+ export interface IDineinCourseSource {
24
+ course_id?: string | null;
25
+ name?: string | null;
26
+ item_ids?: string[] | null;
27
+ called?: boolean | null;
28
+ }
29
+ export interface IDineinOrderItemSource {
30
+ _id?: string | null;
31
+ item_id?: string | null;
32
+ quantity?: number | null;
33
+ }
34
+ export interface IDineinOrderCategorySource {
35
+ items?: IDineinOrderItemSource[] | null;
36
+ }
37
+ export interface IDineinOrderPaymentSource {
38
+ payment_type?: string | null;
39
+ amount_paid?: number | null;
40
+ amount_refunded?: number | null;
41
+ }
42
+ /** One previous version of a check (`iterations[last]` is the FIRST version). */
43
+ export interface IDineinOrderIterationSource {
44
+ platform?: string | null;
45
+ staff_details?: unknown;
46
+ order_taker_details?: unknown;
47
+ consumer?: {
48
+ phone?: string | null;
49
+ } | null;
50
+ categories?: IDineinOrderCategorySource[] | null;
51
+ updatedAt?: Date | string | null;
52
+ }
53
+ /** Raw order fields this report reads (source documents are often partial). */
54
+ export interface IDineinOrderSource {
55
+ _id: string;
56
+ tenant_id?: string | null;
57
+ order_number?: number | null;
58
+ /** Tenant-local business day of the ORDER — the report's source day. */
59
+ localDate?: string | null;
60
+ /** Tenant-local hour of the ORDER — the ONLY hour the report may use. */
61
+ localHour?: number | null;
62
+ platform?: string | null;
63
+ order_status?: string | null;
64
+ createdAt?: Date | string | null;
65
+ updatedAt?: Date | string | null;
66
+ is_deleted?: boolean | null;
67
+ delete_reason?: string | null;
68
+ split_parent_id?: string | null;
69
+ split_child_ids?: string[] | null;
70
+ split_type?: string | null;
71
+ synced_offline?: boolean | null;
72
+ rating?: number | null;
73
+ review?: string | null;
74
+ amount_earned?: number | null;
75
+ tip_amount?: number | null;
76
+ tax_amount?: number | null;
77
+ total_discount_applied?: number | null;
78
+ order_discount_details?: {
79
+ total_discount?: number | null;
80
+ } | null;
81
+ surcharge_amount?: number | null;
82
+ service_fee?: number | null;
83
+ service_fee_amount?: number | null;
84
+ is_service_fee_percentage?: boolean | null;
85
+ is_service_fee_taxable?: boolean | null;
86
+ apply_service_fee_on_original_price?: boolean | null;
87
+ categories?: IDineinOrderCategorySource[] | null;
88
+ payments?: IDineinOrderPaymentSource[] | null;
89
+ iterations?: IDineinOrderIterationSource[] | null;
90
+ /** NOTE: `num_of_guests` is deliberately NOT read — covers come from fingerprints. */
91
+ dinein_details?: {
92
+ table_id?: string | null;
93
+ table_name?: string | null;
94
+ floor_id?: string | null;
95
+ start_time?: Date | string | null;
96
+ courses?: IDineinCourseSource[] | null;
97
+ } | null;
98
+ consumer?: {
99
+ phone?: string | null;
100
+ } | null;
101
+ staff_details?: unknown;
102
+ order_taker_details?: unknown;
103
+ }
104
+ /** The subset of `dinein_tables_fingerprints` the report reads. */
105
+ export interface IDineinFingerprintSource {
106
+ _id: string;
107
+ tenant_id?: string | null;
108
+ order_id?: string | null;
109
+ table_id?: string | null;
110
+ name?: string | null;
111
+ dinein_floor_id?: string | null;
112
+ num_of_guests?: number | null;
113
+ createdAt?: Date | string | null;
114
+ updatedAt?: Date | string | null;
115
+ }
116
+ /** The subset of `reservations` the report reads. */
117
+ export interface IDineinReservationSource {
118
+ _id: string;
119
+ tenant_id?: string | null;
120
+ reservation_time?: Date | string | null;
121
+ reservation_duration?: number | null;
122
+ num_of_guests?: number | null;
123
+ reservation_status?: string | null;
124
+ createdAt?: Date | string | null;
125
+ updatedAt?: Date | string | null;
126
+ /** The tenant-local day the CALLER resolved for `reservation_time`. */
127
+ source_local_date?: string | null;
128
+ }
129
+ /** One table session derived from a joined fingerprint. */
130
+ export interface IDineinTableSession {
131
+ fingerprint_id: string;
132
+ order_id: string;
133
+ table_id: string;
134
+ table_name: string;
135
+ floor_id: string;
136
+ guests: number;
137
+ start: Date;
138
+ end: Date;
139
+ duration_minutes: number;
140
+ /** True when the start came from `order.createdAt` because `start_time` was missing. */
141
+ fallback_start: boolean;
142
+ /** The check's key, so the session lands in the right counter block. */
143
+ key: string;
144
+ }
145
+ declare const num: (value: unknown) => number;
146
+ declare const toDate: (value: unknown) => Date | null;
147
+ /** A check belongs to the dine-in population when it carries `dinein_details`. */
148
+ export declare function isDineinOrder(order: IDineinOrderSource | null | undefined): boolean;
149
+ /** An auto-deleted split PARENT: never a collectable check. */
150
+ export declare function isDeletedSplitParent(order: IDineinOrderSource | null | undefined): boolean;
151
+ /** A split CHILD: a collectable check that belongs to a split group. */
152
+ export declare function isSplitChild(order: IDineinOrderSource | null | undefined): boolean;
153
+ /**
154
+ * The FIRST version of a check.
155
+ *
156
+ * `iterations[0]` is the MOST RECENT previous version and `iterations[last]` is
157
+ * the original one, so the first version is the LAST element — or the current
158
+ * order when there are no iterations. Using `iterations[0]` would read an edit
159
+ * as the first version.
160
+ */
161
+ export declare function firstVersionOf(order: IDineinOrderSource): IDineinOrderIterationSource | IDineinOrderSource;
162
+ /**
163
+ * The frozen origin classification.
164
+ *
165
+ * | first version | staff | consumer phone | origin |
166
+ * | --- | --- | --- | --- |
167
+ * | `POS_DINE-IN` | any | any | `POS_DIRECT` |
168
+ * | `APP_DINE-IN` / `WEB_DINE-IN` | yes | any | `STAFF_TABLET` |
169
+ * | `APP_DINE-IN` / `WEB_DINE-IN` | no | yes | `QR_SELF_ORDER` |
170
+ * | anything else | any | any | `UNKNOWN_ORIGIN` |
171
+ *
172
+ * The phone is read as a boolean only — it is NEVER stored.
173
+ */
174
+ export declare function classifyMaterializedDineinOrigin(order: IDineinOrderSource | null | undefined): MATERIALIZED_DINEIN_ORIGIN_ENUM;
175
+ /** The role of a counted check in a split bill (a parent is never counted). */
176
+ export declare function splitRoleOf(order: IDineinOrderSource | null | undefined): MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM;
177
+ /** Total item quantity of one check version. */
178
+ export declare function itemQuantityOf(order: {
179
+ categories?: IDineinOrderCategorySource[] | null;
180
+ } | null | undefined): number;
181
+ /**
182
+ * Item quantity by LINE identity (`_id`, falling back to `item_id`).
183
+ *
184
+ * Two lines of the same menu item are two identities, so an edit that moves one
185
+ * of them is counted on its own line instead of netting against its twin.
186
+ */
187
+ export declare function itemLineQuantities(order: {
188
+ categories?: IDineinOrderCategorySource[] | null;
189
+ } | null | undefined): Map<string, number>;
190
+ /**
191
+ * The line delta between two versions of one check.
192
+ *
193
+ * Identity is the item LINE (`_id`, else `item_id`), so moving one of two lines
194
+ * of the same menu item is measured on its own line. A version without
195
+ * categories cannot be compared and contributes nothing.
196
+ */
197
+ export declare function itemLineDelta(previous: {
198
+ categories?: IDineinOrderCategorySource[] | null;
199
+ } | null | undefined, next: {
200
+ categories?: IDineinOrderCategorySource[] | null;
201
+ } | null | undefined): {
202
+ additions: number;
203
+ removals: number;
204
+ net: number;
205
+ };
206
+ /** A validated rating (1..5) or null. A 0 / 6 / non-numeric value is NOT a rating. */
207
+ export declare function validRatingOf(value: unknown): number | null;
208
+ /** A payment's class: `CASH`, `CARD` (`CARD` + `TERMINAL`), everything else `OTHER`. */
209
+ export declare function paymentClassOf(paymentType: unknown): MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM;
210
+ /**
211
+ * The collected amount of one payment, NET OF REFUNDS.
212
+ *
213
+ * `amount_paid - amount_refunded`, in integer cents. The report uses the
214
+ * COLLECTED amount (not the order count) for card vs cash, so an order that was
215
+ * partially refunded contributes what was actually kept.
216
+ */
217
+ export declare function collectedAmountOf(payment: IDineinOrderPaymentSource | null | undefined): number;
218
+ /** The refunded amount of one check, summed over its payment rows. */
219
+ export declare function refundsOf(order: IDineinOrderSource | null | undefined): number;
220
+ /** The service-charge rate key: `<PCT|FIXED>:<rate>` (bounded by the document cap). */
221
+ export declare function serviceChargeRateKeyOf(order: IDineinOrderSource): string;
222
+ /** The bounded course key of one course row (`course_id`, falling back to the name). */
223
+ export declare function courseKeyOf(course: IDineinCourseSource): string;
224
+ /**
225
+ * Accumulates ONE collectable check into `counters`.
226
+ *
227
+ * `covers` is passed in (already resolved from the fingerprint) because covers
228
+ * are never derived from the order. `tableSessions` are this check's own
229
+ * sessions; the caller already filtered them to joined, deduped fingerprints.
230
+ */
231
+ export declare function addDineinOrderToCounters(input: {
232
+ counters: IMaterializedDineinCounters;
233
+ order: IDineinOrderSource;
234
+ covers: number;
235
+ sessions: IDineinTableSession[];
236
+ /** The rating credited to this check (own, or inherited from the split parent). */
237
+ rating: number | null;
238
+ /** The split type of the check's group (parent's value), or UNKNOWN. */
239
+ splitType: string | null;
240
+ }): void;
241
+ /** A fresh accumulator entry for one key. */
242
+ export declare function freshDineinKeyCounters(): IMaterializedDineinCounters;
243
+ /** The coverage counters of a compiled day, initialized to zero. */
244
+ export declare function freshDineinCoverage(): IDineinSourceDayCounts;
245
+ export { toDate as toDineinDate, num as toDineinInt };