@managesome/eposmatic-toolkit 0.4.58 → 0.4.60
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 +41 -0
- package/esm/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-day-readiness.js +94 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +3 -0
- package/esm/helpers/materialized-reports/report-platform/definition.js +12 -2
- package/esm/helpers/order/generate-warehouse-purchase-order.js +3 -0
- package/esm/helpers/reporting-contract/report-contract.js +12 -0
- package/esm/helpers/store/common-tenant-purchase-order-actions.js +23 -0
- package/esm/helpers/store/common-warehouse-purchase-order-actions.js +21 -0
- package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +60 -12
- package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +58 -13
- package/esm/schemas/models/index.js +1 -0
- package/esm/schemas/models/materialized_tenant_day_readiness.js +66 -0
- package/esm/schemas/models/tenant_purchase_orders.js +36 -0
- package/esm/schemas/models/warehouse_purchase_orders.js +48 -0
- package/esm/schemas/types/index.js +1 -0
- package/esm/schemas/types/materialized_tenant_day_readiness.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +38 -0
- package/lib/constants/MATERIALIZED_REPORTS.js +42 -1
- package/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -0
- package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +84 -0
- package/lib/helpers/materialized-reports/materialized-day-readiness.js +100 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +3 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +12 -2
- package/lib/helpers/order/generate-warehouse-purchase-order.js +3 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +13 -1
- package/lib/helpers/reporting-contract/report-contract.js +12 -0
- package/lib/helpers/store/common-tenant-purchase-order-actions.d.ts +2 -1
- package/lib/helpers/store/common-tenant-purchase-order-actions.js +24 -0
- package/lib/helpers/store/common-warehouse-purchase-order-actions.d.ts +2 -1
- package/lib/helpers/store/common-warehouse-purchase-order-actions.js +22 -0
- package/lib/helpers/store/tenant-purchase-orders-cart-actions.d.ts +15 -1
- package/lib/helpers/store/tenant-purchase-orders-cart-actions.js +61 -12
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.d.ts +10 -1
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +59 -13
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +78 -0
- package/lib/schemas/models/materialized_tenant_day_readiness.js +69 -0
- package/lib/schemas/models/orders.d.ts +240 -240
- package/lib/schemas/models/tenant_purchase_orders.d.ts +132 -0
- package/lib/schemas/models/tenant_purchase_orders.js +36 -0
- package/lib/schemas/models/warehouse_purchase_orders.d.ts +132 -0
- package/lib/schemas/models/warehouse_purchase_orders.js +48 -0
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/materialized_tenant_day_readiness.d.ts +28 -0
- package/lib/schemas/types/materialized_tenant_day_readiness.js +2 -0
- package/lib/schemas/types/tenant_purchase_orders.d.ts +28 -0
- package/lib/schemas/types/warehouse_purchase_orders.d.ts +12 -0
- package/lib/tests/materialized-reports/materialized-day-readiness.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-day-readiness.test.js +64 -0
- package/package.json +1 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { ALL_MATERIALIZED_REPORT_READINESS_STATUSES, MATERIALIZED_READINESS_REPORT_KEYS, MATERIALIZED_REPORT_READINESS_STATUS_ENUM, MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION, } from '../../constants/MATERIALIZED_REPORTS';
|
|
3
|
+
/**
|
|
4
|
+
* Mongoose schema for `materialized_tenant_day_readiness`.
|
|
5
|
+
*
|
|
6
|
+
* The row's identity is the unique compound
|
|
7
|
+
* `(tenant_id, localDate, report_key, schema_version)`. It is written by the
|
|
8
|
+
* shared per-day materialization core on the caller's transaction session, so a
|
|
9
|
+
* rolled-back day leaves no row behind.
|
|
10
|
+
*/
|
|
11
|
+
export const MaterializedTenantDayReadinessSchema = new Schema({
|
|
12
|
+
tenant_id: { type: String, required: true },
|
|
13
|
+
localDate: { type: String, required: true },
|
|
14
|
+
report_key: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: true,
|
|
17
|
+
enum: [...MATERIALIZED_READINESS_REPORT_KEYS],
|
|
18
|
+
},
|
|
19
|
+
schema_version: {
|
|
20
|
+
type: Number,
|
|
21
|
+
required: true,
|
|
22
|
+
immutable: true,
|
|
23
|
+
default: MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION,
|
|
24
|
+
},
|
|
25
|
+
status: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true,
|
|
28
|
+
enum: ALL_MATERIALIZED_REPORT_READINESS_STATUSES,
|
|
29
|
+
default: MATERIALIZED_REPORT_READINESS_STATUS_ENUM.COMMITTED,
|
|
30
|
+
},
|
|
31
|
+
run_id: { type: String, required: true },
|
|
32
|
+
committed_at: { type: Schema.Types.Date, required: true },
|
|
33
|
+
createdAt: {
|
|
34
|
+
type: Schema.Types.Date,
|
|
35
|
+
required: true,
|
|
36
|
+
default: () => new Date(),
|
|
37
|
+
immutable: true,
|
|
38
|
+
},
|
|
39
|
+
updatedAt: { type: Schema.Types.Date, required: true, default: () => new Date() },
|
|
40
|
+
}, { timestamps: true, versionKey: false, minimize: false });
|
|
41
|
+
export const MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_INDEXES = {
|
|
42
|
+
_id: { _id: 1 },
|
|
43
|
+
tenant_id__localDate__report_key__schema_version: {
|
|
44
|
+
tenant_id: 1,
|
|
45
|
+
localDate: 1,
|
|
46
|
+
report_key: 1,
|
|
47
|
+
schema_version: 1,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Index OPTIONS the owner must CREATE (declared here, applied by a separate
|
|
52
|
+
* migration/deploy step — never by a read or a close at runtime).
|
|
53
|
+
*/
|
|
54
|
+
export const MATERIALIZED_TENANT_DAY_READINESS_INDEX_OPTIONS = [
|
|
55
|
+
{
|
|
56
|
+
key: { tenant_id: 1, localDate: 1, report_key: 1, schema_version: 1 },
|
|
57
|
+
name: 'tenant_id__localDate__report_key__schema_version',
|
|
58
|
+
unique: true,
|
|
59
|
+
},
|
|
60
|
+
// Broad range read: every report of the requested days for a tenant list.
|
|
61
|
+
{
|
|
62
|
+
key: { tenant_id: 1, localDate: 1, report_key: 1, status: 1 },
|
|
63
|
+
name: 'tenant_id__localDate__report_key__status',
|
|
64
|
+
unique: false,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
@@ -10,6 +10,30 @@ const StaffDetailsSchema = new Schema({
|
|
|
10
10
|
staff_mobile: { type: String, default: null },
|
|
11
11
|
staff_email: { type: String, default: null },
|
|
12
12
|
}, { _id: false, minimize: false });
|
|
13
|
+
const DiscountDetailsSchema = new Schema({
|
|
14
|
+
special_discount: {
|
|
15
|
+
type: Number,
|
|
16
|
+
},
|
|
17
|
+
special_discount_id: {
|
|
18
|
+
type: String,
|
|
19
|
+
},
|
|
20
|
+
special_discount_name: {
|
|
21
|
+
type: String,
|
|
22
|
+
},
|
|
23
|
+
is_special_discount_percentage: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
},
|
|
26
|
+
special_discount_reason: {
|
|
27
|
+
type: String,
|
|
28
|
+
},
|
|
29
|
+
special_reference_number: {
|
|
30
|
+
type: String,
|
|
31
|
+
},
|
|
32
|
+
total_discount: {
|
|
33
|
+
type: Number,
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
}, { _id: false, minimize: false });
|
|
13
37
|
const ItemsSchema = new Schema({
|
|
14
38
|
_id: { type: Schema.Types.ObjectId, required: true, immutable: true },
|
|
15
39
|
item_id: {
|
|
@@ -54,6 +78,12 @@ const IterationsOrderSchema = new Schema({
|
|
|
54
78
|
price: { type: Number, min: 0, required: true },
|
|
55
79
|
amount_earned: { type: Number, min: 0, required: true },
|
|
56
80
|
grand_total: { type: Number, min: 0, required: true },
|
|
81
|
+
order_discount_details: {
|
|
82
|
+
type: DiscountDetailsSchema,
|
|
83
|
+
required: false,
|
|
84
|
+
},
|
|
85
|
+
total_discount_applied: { type: Number, required: false },
|
|
86
|
+
exclude_discount_from_gst: { type: Boolean, required: false },
|
|
57
87
|
staff_details: { type: StaffDetailsSchema, required: false },
|
|
58
88
|
gst: { type: Number, min: 0, required: false },
|
|
59
89
|
gst_amount: { type: Number, min: 0, required: false },
|
|
@@ -84,6 +114,12 @@ export const TenantPurchaseOrderSchema = new Schema({
|
|
|
84
114
|
amount_collected: { type: Number, min: 0, required: true },
|
|
85
115
|
amount_earned: { type: Number, min: 0, required: true },
|
|
86
116
|
grand_total: { type: Number, min: 0, required: true },
|
|
117
|
+
order_discount_details: {
|
|
118
|
+
type: DiscountDetailsSchema,
|
|
119
|
+
required: false,
|
|
120
|
+
},
|
|
121
|
+
total_discount_applied: { type: Number, required: false },
|
|
122
|
+
exclude_discount_from_gst: { type: Boolean, required: false },
|
|
87
123
|
order_number: { type: Number, min: 0, default: null },
|
|
88
124
|
delete_reason: { type: String, required: false },
|
|
89
125
|
cancel_reason: { type: String, required: false },
|
|
@@ -24,6 +24,30 @@ const StaffDetailsSchema = new Schema({
|
|
|
24
24
|
default: null,
|
|
25
25
|
},
|
|
26
26
|
}, { _id: false, minimize: false });
|
|
27
|
+
const DiscountDetailsSchema = new Schema({
|
|
28
|
+
special_discount: {
|
|
29
|
+
type: Number,
|
|
30
|
+
},
|
|
31
|
+
special_discount_id: {
|
|
32
|
+
type: String,
|
|
33
|
+
},
|
|
34
|
+
special_discount_name: {
|
|
35
|
+
type: String,
|
|
36
|
+
},
|
|
37
|
+
is_special_discount_percentage: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
},
|
|
40
|
+
special_discount_reason: {
|
|
41
|
+
type: String,
|
|
42
|
+
},
|
|
43
|
+
special_reference_number: {
|
|
44
|
+
type: String,
|
|
45
|
+
},
|
|
46
|
+
total_discount: {
|
|
47
|
+
type: Number,
|
|
48
|
+
required: true,
|
|
49
|
+
},
|
|
50
|
+
}, { _id: false, minimize: false });
|
|
27
51
|
const ItemsModal = new Schema({
|
|
28
52
|
_id: {
|
|
29
53
|
type: Schema.Types.ObjectId,
|
|
@@ -141,6 +165,18 @@ const IterationsOrderSchema = new Schema({
|
|
|
141
165
|
min: 0,
|
|
142
166
|
required: true,
|
|
143
167
|
},
|
|
168
|
+
order_discount_details: {
|
|
169
|
+
type: DiscountDetailsSchema,
|
|
170
|
+
required: false,
|
|
171
|
+
},
|
|
172
|
+
total_discount_applied: {
|
|
173
|
+
type: Number,
|
|
174
|
+
required: false,
|
|
175
|
+
},
|
|
176
|
+
exclude_discount_from_gst: {
|
|
177
|
+
type: Boolean,
|
|
178
|
+
required: false,
|
|
179
|
+
},
|
|
144
180
|
staff_details: {
|
|
145
181
|
type: StaffDetailsSchema,
|
|
146
182
|
required: false,
|
|
@@ -242,6 +278,18 @@ export const PurchaseOrderSchema = new Schema({
|
|
|
242
278
|
min: 0,
|
|
243
279
|
required: true,
|
|
244
280
|
},
|
|
281
|
+
order_discount_details: {
|
|
282
|
+
type: DiscountDetailsSchema,
|
|
283
|
+
required: false,
|
|
284
|
+
},
|
|
285
|
+
total_discount_applied: {
|
|
286
|
+
type: Number,
|
|
287
|
+
required: false,
|
|
288
|
+
},
|
|
289
|
+
exclude_discount_from_gst: {
|
|
290
|
+
type: Boolean,
|
|
291
|
+
required: false,
|
|
292
|
+
},
|
|
245
293
|
order_number: {
|
|
246
294
|
type: Number,
|
|
247
295
|
min: 0,
|
|
@@ -39,6 +39,7 @@ export * from './materialized_tenant_delivery_entries';
|
|
|
39
39
|
export * from './materialized_tenant_delivery_geo_cells';
|
|
40
40
|
export * from './materialized_tenant_delivery_geo_scopes';
|
|
41
41
|
export * from './materialized_tenant_delivery_reports';
|
|
42
|
+
export * from './materialized_tenant_day_readiness';
|
|
42
43
|
export * from './materialized_tenant_discount_entries';
|
|
43
44
|
export * from './materialized_tenant_discount_reports';
|
|
44
45
|
export * from './materialized_tenant_dialer_entries';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -733,3 +733,41 @@ export declare const MATERIALIZED_DIALER_HOUR_KEYS: string[];
|
|
|
733
733
|
*/
|
|
734
734
|
export declare const MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES: number;
|
|
735
735
|
export declare const MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES: number;
|
|
736
|
+
/**
|
|
737
|
+
* COMMITTED-READINESS ledger for the five reports written by END_TENANT_DAY and
|
|
738
|
+
* the range sync: Overview, Discounts, Prep Time, Delivery and Dialer.
|
|
739
|
+
*
|
|
740
|
+
* One row per (tenant_id, localDate, report_key, schema_version). The row is
|
|
741
|
+
* written in the SAME transaction/session as the report documents, so it can
|
|
742
|
+
* never disagree with them: a transaction that aborts leaves no readiness row,
|
|
743
|
+
* and a row can only exist when every report document of that day committed
|
|
744
|
+
* together (or the day was genuinely empty).
|
|
745
|
+
*
|
|
746
|
+
* Historical reads check this ledger AFTER the closed-day validation and BEFORE
|
|
747
|
+
* any report document read:
|
|
748
|
+
* - missing row(s) -> 409 HISTORICAL_NOT_MATERIALIZED;
|
|
749
|
+
* - NEEDS_RECONCILIATION -> 409 HISTORICAL_NEEDS_RECONCILIATION.
|
|
750
|
+
*
|
|
751
|
+
* The four out-of-scope reports (Cash In/Out, Sales Comparison, Hourly
|
|
752
|
+
* Comparison, Payments Comparison) deliberately have NO readiness rows.
|
|
753
|
+
*/
|
|
754
|
+
export declare const MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_NAME = "materialized_tenant_day_readiness";
|
|
755
|
+
/** Version of the readiness row shape. Pinned to 1 with the other collections. */
|
|
756
|
+
export declare const MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION = 1;
|
|
757
|
+
/** The readiness state of one tenant-day-report. */
|
|
758
|
+
export declare enum MATERIALIZED_REPORT_READINESS_STATUS_ENUM {
|
|
759
|
+
/** Every document of the tenant-day-report committed together. */
|
|
760
|
+
COMMITTED = "COMMITTED",
|
|
761
|
+
/**
|
|
762
|
+
* The day committed, but a known gap makes the stored report untrustworthy
|
|
763
|
+
* as final. Delivery sets this when a stale cross-day update was skipped.
|
|
764
|
+
*/
|
|
765
|
+
NEEDS_RECONCILIATION = "NEEDS_RECONCILIATION"
|
|
766
|
+
}
|
|
767
|
+
export declare const ALL_MATERIALIZED_REPORT_READINESS_STATUSES: MATERIALIZED_REPORT_READINESS_STATUS_ENUM[];
|
|
768
|
+
/**
|
|
769
|
+
* The ONLY reports that own a readiness row. Adding another report here means
|
|
770
|
+
* giving it a writer that participates in the same day transaction.
|
|
771
|
+
*/
|
|
772
|
+
export declare const MATERIALIZED_READINESS_REPORT_KEYS: readonly ["OVERVIEW", "DISCOUNTS", "PREP_TIME", "DELIVERY", "DIALER"];
|
|
773
|
+
export type TMaterializedReadinessReportKey = (typeof MATERIALIZED_READINESS_REPORT_KEYS)[number];
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.MATERIALIZED_DELIVERY_GEO_SCOPES = exports.MATERIALIZED_DELIVERY_GEO_RESOLUTION = exports.MATERIALIZED_DELIVERY_GEO_MAX_KEYS = exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_SCHEMA_VERSION = exports.MATERIALIZED_DELIVERY_OTHER_TOKEN = exports.MATERIALIZED_DELIVERY_AREA_LIMIT = exports.MATERIALIZED_DELIVERY_RIDER_LIMIT = exports.MATERIALIZED_DELIVERY_DISTANCE_BUCKETS = exports.DELIVERY_KEY_FILTERS = exports.MATERIALIZED_DELIVERY_ENTRY_PAGE_ALL = exports.MATERIALIZED_DELIVERY_ENTRY_SCOPES = exports.MATERIALIZED_DELIVERY_REPORT_SCOPES = exports.MATERIALIZED_CASH_SOURCE_LIMIT = exports.CASH_KEY_FILTERS = exports.MATERIALIZED_CASH_REPORT_SCOPES = exports.ALL_MATERIALIZED_REPORT_CREDIT_BILL_EVENT_TYPES = exports.MATERIALIZED_REPORT_CREDIT_BILL_EVENT_TYPE_ENUM = exports.MATERIALIZED_CREDIT_SETTLEMENT_PAYMENT_TYPE = exports.MATERIALIZED_DISCOUNT_SOURCE_KEY_PREFIX = exports.MATERIALIZED_DISCOUNT_SOURCE_KEY = exports.ALL_MATERIALIZED_DISCOUNT_RATE_KINDS = exports.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SOURCE_CLASSES = exports.MATERIALIZED_DISCOUNT_SOURCE_CLASS_ENUM = exports.MATERIALIZED_DISCOUNT_PRICE_OVERRIDE_PREFIX = exports.MATERIALIZED_DISCOUNT_MANUAL_PREFIX = exports.MATERIALIZED_DISCOUNT_SPECIAL_DISCOUNT_ID = exports.MATERIALIZED_DISCOUNT_SOURCE_LIMIT = exports.ALL_MATERIALIZED_DISCOUNT_LEVELS = exports.MATERIALIZED_DISCOUNT_LEVEL_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_ENTRY_KINDS = exports.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SUB_KINDS = exports.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SLOTS = exports.MATERIALIZED_DISCOUNT_SLOT_ENUM = exports.DISCOUNTS_KEY_FILTERS = exports.MATERIALIZED_DISCOUNT_REPORT_SCOPES = exports.MATERIALIZED_DISCOUNT_ENTRY_PAGE_ALL = exports.SALES_OVERVIEW_KEY_FILTERS = exports.ALL_MATERIALIZED_REPORT_KEY_FILTERS = exports.MATERIALIZED_REPORT_KEY_FILTER_ENUM = exports.MATERIALIZED_CREDIT_BILLS_SCOPES = exports.MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX = exports.ALL_MATERIALIZED_REPORT_WINDOW_KINDS = exports.MATERIALIZED_REPORT_WINDOW_KIND_ENUM = exports.ALL_MATERIALIZED_REPORT_SCOPES = exports.MATERIALIZED_REPORT_SCOPE_ENUM = void 0;
|
|
14
14
|
exports.MATERIALIZED_DIALER_ENTRY_PAGE_ALL = exports.MATERIALIZED_DIALER_ENTRY_SCOPES = exports.MATERIALIZED_DIALER_REPORT_SCOPES = exports.ALL_PAYMENTS_COMPARISON_METRICS = exports.PAYMENTS_COMPARISON_METRIC_ENUM = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_SCHEMA_VERSION = exports.PAYMENTS_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_PAYMENTS_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION = exports.HOURLY_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_HOURLY_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_COLLECTION_NAME = exports.ALL_SALES_COMPARISON_METRICS = exports.SALES_COMPARISON_METRIC_ENUM = exports.ALL_SALES_COMPARISON_BASELINES = exports.SALES_COMPARISON_BASELINE_ENUM = exports.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_SCHEMA_VERSION = exports.SALES_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_SALES_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_NAME = exports.ALL_MATERIALIZED_REPORT_TYPES = exports.MATERIALIZED_REPORT_TYPE_ENUM = exports.ALL_MATERIALIZED_PREP_TIME_TARGETS = exports.MATERIALIZED_PREP_TIME_TARGET_ENUM = exports.MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA = exports.MATERIALIZED_PREP_TIME_TOP_BUCKET = exports.MATERIALIZED_PREP_TIME_MAX_MINUTES = exports.ALL_MATERIALIZED_PREP_TIME_BUCKET_LABELS = exports.MATERIALIZED_PREP_TIME_BUCKETS = exports.ALL_MATERIALIZED_PREP_TIME_ANCHORS = exports.MATERIALIZED_PREP_TIME_ANCHOR_ENUM = exports.PREP_TIME_KEY_FILTERS = exports.MATERIALIZED_PREP_TIME_ITEM_MAX_READ_DAYS = exports.MATERIALIZED_PREP_TIME_ITEM_SCOPES = exports.MATERIALIZED_PREP_TIME_REPORT_SCOPES = exports.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES = exports.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES = exports.MATERIALIZED_DELIVERY_GEO_UNKNOWN_CELL = exports.MATERIALIZED_DELIVERY_GEO_MONTH_RETENTION_MONTHS = exports.MATERIALIZED_DELIVERY_GEO_DAY_RETENTION_DAYS = exports.MATERIALIZED_DELIVERY_GEO_MAX_CELLS = exports.MATERIALIZED_DELIVERY_GEO_MIN_ORDERS = void 0;
|
|
15
|
-
exports.MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_HOUR_KEYS = exports.MATERIALIZED_DIALER_KEY_SEPARATOR = exports.MATERIALIZED_DIALER_UNKNOWN_TOKEN = exports.DIALER_KEY_FILTERS = void 0;
|
|
15
|
+
exports.MATERIALIZED_READINESS_REPORT_KEYS = exports.ALL_MATERIALIZED_REPORT_READINESS_STATUSES = exports.MATERIALIZED_REPORT_READINESS_STATUS_ENUM = exports.MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_NAME = exports.MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_HOUR_KEYS = exports.MATERIALIZED_DIALER_KEY_SEPARATOR = exports.MATERIALIZED_DIALER_UNKNOWN_TOKEN = exports.DIALER_KEY_FILTERS = void 0;
|
|
16
16
|
/**
|
|
17
17
|
* Time-scope of a materialized report document. Every document covers exactly
|
|
18
18
|
* one tenant × one scope context × one scope value (`scope_field`), and the
|
|
@@ -903,3 +903,44 @@ exports.MATERIALIZED_DIALER_HOUR_KEYS = Array.from({ length: 24 }, (_, hour) =>
|
|
|
903
903
|
*/
|
|
904
904
|
exports.MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES = 15 * 1024 * 1024;
|
|
905
905
|
exports.MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES = 15 * 1024 * 1024;
|
|
906
|
+
/* ======================================================================== */
|
|
907
|
+
/* Day readiness (five production writers) */
|
|
908
|
+
/* ======================================================================== */
|
|
909
|
+
/**
|
|
910
|
+
* COMMITTED-READINESS ledger for the five reports written by END_TENANT_DAY and
|
|
911
|
+
* the range sync: Overview, Discounts, Prep Time, Delivery and Dialer.
|
|
912
|
+
*
|
|
913
|
+
* One row per (tenant_id, localDate, report_key, schema_version). The row is
|
|
914
|
+
* written in the SAME transaction/session as the report documents, so it can
|
|
915
|
+
* never disagree with them: a transaction that aborts leaves no readiness row,
|
|
916
|
+
* and a row can only exist when every report document of that day committed
|
|
917
|
+
* together (or the day was genuinely empty).
|
|
918
|
+
*
|
|
919
|
+
* Historical reads check this ledger AFTER the closed-day validation and BEFORE
|
|
920
|
+
* any report document read:
|
|
921
|
+
* - missing row(s) -> 409 HISTORICAL_NOT_MATERIALIZED;
|
|
922
|
+
* - NEEDS_RECONCILIATION -> 409 HISTORICAL_NEEDS_RECONCILIATION.
|
|
923
|
+
*
|
|
924
|
+
* The four out-of-scope reports (Cash In/Out, Sales Comparison, Hourly
|
|
925
|
+
* Comparison, Payments Comparison) deliberately have NO readiness rows.
|
|
926
|
+
*/
|
|
927
|
+
exports.MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_NAME = 'materialized_tenant_day_readiness';
|
|
928
|
+
/** Version of the readiness row shape. Pinned to 1 with the other collections. */
|
|
929
|
+
exports.MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION = 1;
|
|
930
|
+
/** The readiness state of one tenant-day-report. */
|
|
931
|
+
var MATERIALIZED_REPORT_READINESS_STATUS_ENUM;
|
|
932
|
+
(function (MATERIALIZED_REPORT_READINESS_STATUS_ENUM) {
|
|
933
|
+
/** Every document of the tenant-day-report committed together. */
|
|
934
|
+
MATERIALIZED_REPORT_READINESS_STATUS_ENUM["COMMITTED"] = "COMMITTED";
|
|
935
|
+
/**
|
|
936
|
+
* The day committed, but a known gap makes the stored report untrustworthy
|
|
937
|
+
* as final. Delivery sets this when a stale cross-day update was skipped.
|
|
938
|
+
*/
|
|
939
|
+
MATERIALIZED_REPORT_READINESS_STATUS_ENUM["NEEDS_RECONCILIATION"] = "NEEDS_RECONCILIATION";
|
|
940
|
+
})(MATERIALIZED_REPORT_READINESS_STATUS_ENUM || (exports.MATERIALIZED_REPORT_READINESS_STATUS_ENUM = MATERIALIZED_REPORT_READINESS_STATUS_ENUM = {}));
|
|
941
|
+
exports.ALL_MATERIALIZED_REPORT_READINESS_STATUSES = Object.values(MATERIALIZED_REPORT_READINESS_STATUS_ENUM);
|
|
942
|
+
/**
|
|
943
|
+
* The ONLY reports that own a readiness row. Adding another report here means
|
|
944
|
+
* giving it a writer that participates in the same day transaction.
|
|
945
|
+
*/
|
|
946
|
+
exports.MATERIALIZED_READINESS_REPORT_KEYS = ['OVERVIEW', 'DISCOUNTS', 'PREP_TIME', 'DELIVERY', 'DIALER'];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './key-helpers';
|
|
2
2
|
export * from './materialized-credit-bills-helpers';
|
|
3
|
+
export * from './materialized-day-readiness';
|
|
3
4
|
export * from './materialized-index-bootstrap';
|
|
4
5
|
export * from './materialized-integer-contract';
|
|
5
6
|
export * from './materialized-discount-accumulator-helpers';
|
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./key-helpers"), exports);
|
|
18
18
|
__exportStar(require("./materialized-credit-bills-helpers"), exports);
|
|
19
|
+
__exportStar(require("./materialized-day-readiness"), exports);
|
|
19
20
|
__exportStar(require("./materialized-index-bootstrap"), exports);
|
|
20
21
|
__exportStar(require("./materialized-integer-contract"), exports);
|
|
21
22
|
__exportStar(require("./materialized-discount-accumulator-helpers"), exports);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_READINESS_STATUS_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
/**
|
|
3
|
+
* PURE day-readiness helpers shared by the writers (workers-service) and the
|
|
4
|
+
* historical read gate (operations-service).
|
|
5
|
+
*
|
|
6
|
+
* The row identity is `(tenant_id, localDate, report_key, schema_version)`.
|
|
7
|
+
* The gate works on the EXPLICIT cross product of every requested tenant and
|
|
8
|
+
* every requested day: a tenant is never silently dropped, and a reduced
|
|
9
|
+
* denominator can never be rendered as a final 200.
|
|
10
|
+
*/
|
|
11
|
+
export interface IMaterializedDayReadinessRecord {
|
|
12
|
+
tenant_id: string;
|
|
13
|
+
localDate: string;
|
|
14
|
+
report_key: string;
|
|
15
|
+
schema_version: number;
|
|
16
|
+
status: MATERIALIZED_REPORT_READINESS_STATUS_ENUM | string;
|
|
17
|
+
}
|
|
18
|
+
export interface IMaterializedDayReadinessPair {
|
|
19
|
+
tenant_id: string;
|
|
20
|
+
localDate: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IMaterializedDayReadinessGaps {
|
|
23
|
+
/** Tenants with at least one requested day missing a row. */
|
|
24
|
+
missing_tenants: string[];
|
|
25
|
+
/** Days with at least one requested tenant missing a row. */
|
|
26
|
+
missing_dates: string[];
|
|
27
|
+
/** Tenants with at least one requested day marked NEEDS_RECONCILIATION. */
|
|
28
|
+
needs_reconciliation_tenants: string[];
|
|
29
|
+
/** Days with at least one requested tenant marked NEEDS_RECONCILIATION. */
|
|
30
|
+
needs_reconciliation_dates: string[];
|
|
31
|
+
/** Exact missing pairs (for logs / diagnostics; the API exposes the two lists). */
|
|
32
|
+
missing_pairs: IMaterializedDayReadinessPair[];
|
|
33
|
+
/** Exact pairs awaiting reconciliation (for logs / diagnostics). */
|
|
34
|
+
needs_reconciliation_pairs: IMaterializedDayReadinessPair[];
|
|
35
|
+
}
|
|
36
|
+
/** Whether `report` is one of the FIVE reports that own readiness rows. */
|
|
37
|
+
export declare function isMaterializedReadinessReportKey(report: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The readiness doc identity key. Kept as a string so the same helper can index
|
|
40
|
+
* a Map and build a Mongo filter.
|
|
41
|
+
*/
|
|
42
|
+
export declare function materializedDayReadinessKey(parts: {
|
|
43
|
+
tenantId: string;
|
|
44
|
+
localDate: string;
|
|
45
|
+
reportKey: string;
|
|
46
|
+
schemaVersion?: number;
|
|
47
|
+
}): string;
|
|
48
|
+
/**
|
|
49
|
+
* Summarizes the readiness gap of a historical read.
|
|
50
|
+
*
|
|
51
|
+
* - A requested pair with NO record is MISSING.
|
|
52
|
+
* - A requested pair whose record is not COMMITTED (i.e.
|
|
53
|
+
* NEEDS_RECONCILIATION) is not final; it is reported separately.
|
|
54
|
+
* - Records for another report key / schema version are ignored, so a stale
|
|
55
|
+
* writer version can never satisfy a v1 read.
|
|
56
|
+
*
|
|
57
|
+
* The two failure families are mutually exclusive by precedence: the caller
|
|
58
|
+
* answers MISSING first, then NEEDS_RECONCILIATION.
|
|
59
|
+
*/
|
|
60
|
+
export declare function summarizeMaterializedDayReadiness(input: {
|
|
61
|
+
reportKey: string;
|
|
62
|
+
tenants: readonly string[];
|
|
63
|
+
dates: readonly string[];
|
|
64
|
+
records: readonly IMaterializedDayReadinessRecord[];
|
|
65
|
+
schemaVersion?: number;
|
|
66
|
+
}): IMaterializedDayReadinessGaps;
|
|
67
|
+
/**
|
|
68
|
+
* Builds one readiness document. `committed_at` is the instant the committing
|
|
69
|
+
* transaction wrote the row (also used for a NEEDS_RECONCILIATION row: it is
|
|
70
|
+
* the last committed attempt, not a promise of completeness).
|
|
71
|
+
*/
|
|
72
|
+
export interface IMaterializedDayReadinessDocument extends IMaterializedDayReadinessRecord {
|
|
73
|
+
run_id: string;
|
|
74
|
+
committed_at: Date;
|
|
75
|
+
}
|
|
76
|
+
export declare function buildMaterializedDayReadinessDocument(input: {
|
|
77
|
+
tenantId: string;
|
|
78
|
+
localDate: string;
|
|
79
|
+
reportKey: string;
|
|
80
|
+
status: MATERIALIZED_REPORT_READINESS_STATUS_ENUM;
|
|
81
|
+
runId: string;
|
|
82
|
+
committedAt: Date;
|
|
83
|
+
schemaVersion?: number;
|
|
84
|
+
}): IMaterializedDayReadinessDocument;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMaterializedReadinessReportKey = isMaterializedReadinessReportKey;
|
|
4
|
+
exports.materializedDayReadinessKey = materializedDayReadinessKey;
|
|
5
|
+
exports.summarizeMaterializedDayReadiness = summarizeMaterializedDayReadiness;
|
|
6
|
+
exports.buildMaterializedDayReadinessDocument = buildMaterializedDayReadinessDocument;
|
|
7
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
8
|
+
const uniqueSorted = (values) => [...new Set(values)].sort();
|
|
9
|
+
/** Whether `report` is one of the FIVE reports that own readiness rows. */
|
|
10
|
+
function isMaterializedReadinessReportKey(report) {
|
|
11
|
+
return MATERIALIZED_REPORTS_1.MATERIALIZED_READINESS_REPORT_KEYS.includes(report);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The readiness doc identity key. Kept as a string so the same helper can index
|
|
15
|
+
* a Map and build a Mongo filter.
|
|
16
|
+
*/
|
|
17
|
+
function materializedDayReadinessKey(parts) {
|
|
18
|
+
return [
|
|
19
|
+
String(parts.tenantId),
|
|
20
|
+
String(parts.localDate),
|
|
21
|
+
String(parts.reportKey),
|
|
22
|
+
String(parts.schemaVersion ?? MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION),
|
|
23
|
+
].join('|');
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Summarizes the readiness gap of a historical read.
|
|
27
|
+
*
|
|
28
|
+
* - A requested pair with NO record is MISSING.
|
|
29
|
+
* - A requested pair whose record is not COMMITTED (i.e.
|
|
30
|
+
* NEEDS_RECONCILIATION) is not final; it is reported separately.
|
|
31
|
+
* - Records for another report key / schema version are ignored, so a stale
|
|
32
|
+
* writer version can never satisfy a v1 read.
|
|
33
|
+
*
|
|
34
|
+
* The two failure families are mutually exclusive by precedence: the caller
|
|
35
|
+
* answers MISSING first, then NEEDS_RECONCILIATION.
|
|
36
|
+
*/
|
|
37
|
+
function summarizeMaterializedDayReadiness(input) {
|
|
38
|
+
const schemaVersion = input.schemaVersion ?? MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION;
|
|
39
|
+
const tenants = uniqueSorted((input.tenants ?? []).map((tenant) => String(tenant).trim()).filter((tenant) => tenant !== ''));
|
|
40
|
+
const dates = uniqueSorted((input.dates ?? []).map((date) => String(date).trim()).filter((date) => date !== ''));
|
|
41
|
+
const byKey = new Map();
|
|
42
|
+
for (const record of input.records ?? []) {
|
|
43
|
+
if (record == null)
|
|
44
|
+
continue;
|
|
45
|
+
if (String(record.report_key) !== String(input.reportKey))
|
|
46
|
+
continue;
|
|
47
|
+
if (Number(record.schema_version) !== Number(schemaVersion))
|
|
48
|
+
continue;
|
|
49
|
+
byKey.set(materializedDayReadinessKey({
|
|
50
|
+
tenantId: String(record.tenant_id),
|
|
51
|
+
localDate: String(record.localDate),
|
|
52
|
+
reportKey: String(record.report_key),
|
|
53
|
+
schemaVersion: Number(record.schema_version),
|
|
54
|
+
}), record);
|
|
55
|
+
}
|
|
56
|
+
const missingPairs = [];
|
|
57
|
+
const needsPairs = [];
|
|
58
|
+
for (const tenant_id of tenants) {
|
|
59
|
+
for (const localDate of dates) {
|
|
60
|
+
const key = materializedDayReadinessKey({
|
|
61
|
+
tenantId: tenant_id,
|
|
62
|
+
localDate,
|
|
63
|
+
reportKey: input.reportKey,
|
|
64
|
+
schemaVersion,
|
|
65
|
+
});
|
|
66
|
+
const record = byKey.get(key);
|
|
67
|
+
if (record == null) {
|
|
68
|
+
missingPairs.push({ tenant_id, localDate });
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (record.status !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_READINESS_STATUS_ENUM.COMMITTED) {
|
|
72
|
+
needsPairs.push({ tenant_id, localDate });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
missing_tenants: uniqueSorted(missingPairs.map((pair) => pair.tenant_id)),
|
|
78
|
+
missing_dates: uniqueSorted(missingPairs.map((pair) => pair.localDate)),
|
|
79
|
+
needs_reconciliation_tenants: uniqueSorted(needsPairs.map((pair) => pair.tenant_id)),
|
|
80
|
+
needs_reconciliation_dates: uniqueSorted(needsPairs.map((pair) => pair.localDate)),
|
|
81
|
+
missing_pairs: missingPairs,
|
|
82
|
+
needs_reconciliation_pairs: needsPairs,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function buildMaterializedDayReadinessDocument(input) {
|
|
86
|
+
if (!isMaterializedReadinessReportKey(String(input.reportKey))) {
|
|
87
|
+
throw new Error('buildMaterializedDayReadinessDocument: report ' +
|
|
88
|
+
String(input.reportKey) +
|
|
89
|
+
' is outside the five report readiness contract');
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
tenant_id: String(input.tenantId),
|
|
93
|
+
localDate: String(input.localDate),
|
|
94
|
+
report_key: String(input.reportKey),
|
|
95
|
+
schema_version: input.schemaVersion ?? MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION,
|
|
96
|
+
status: input.status,
|
|
97
|
+
run_id: String(input.runId),
|
|
98
|
+
committed_at: input.committedAt,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -9,6 +9,8 @@ const materialized_tenant_delivery_entries_1 = require("../../schemas/models/mat
|
|
|
9
9
|
const materialized_tenant_delivery_geo_cells_1 = require("../../schemas/models/materialized_tenant_delivery_geo_cells");
|
|
10
10
|
const materialized_tenant_delivery_geo_scopes_1 = require("../../schemas/models/materialized_tenant_delivery_geo_scopes");
|
|
11
11
|
const materialized_tenant_delivery_reports_1 = require("../../schemas/models/materialized_tenant_delivery_reports");
|
|
12
|
+
const MATERIALIZED_REPORTS_2 = require("../../constants/MATERIALIZED_REPORTS");
|
|
13
|
+
const materialized_tenant_day_readiness_1 = require("../../schemas/models/materialized_tenant_day_readiness");
|
|
12
14
|
const materialized_tenant_dialer_entries_1 = require("../../schemas/models/materialized_tenant_dialer_entries");
|
|
13
15
|
const materialized_tenant_dialer_reports_1 = require("../../schemas/models/materialized_tenant_dialer_reports");
|
|
14
16
|
const materialized_tenant_discount_entries_1 = require("../../schemas/models/materialized_tenant_discount_entries");
|
|
@@ -48,6 +50,7 @@ const INDEXES = {
|
|
|
48
50
|
[MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_NAME]: materialized_tenant_delivery_geo_scopes_1.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_INDEX_OPTIONS,
|
|
49
51
|
[materialized_tenant_delivery_entries_1.MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_NAME]: materialized_tenant_delivery_entries_1.MATERIALIZED_TENANT_DELIVERY_ENTRIES_INDEX_OPTIONS,
|
|
50
52
|
[materialized_tenant_delivery_reports_1.MATERIALIZED_TENANT_DELIVERY_REPORTS_COLLECTION_NAME]: materialized_tenant_delivery_reports_1.MATERIALIZED_TENANT_DELIVERY_REPORTS_INDEX_OPTIONS,
|
|
53
|
+
[MATERIALIZED_REPORTS_2.MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_NAME]: materialized_tenant_day_readiness_1.MATERIALIZED_TENANT_DAY_READINESS_INDEX_OPTIONS,
|
|
51
54
|
[materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_NAME]: materialized_tenant_dialer_reports_1.MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS,
|
|
52
55
|
[materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_NAME]: materialized_tenant_dialer_entries_1.MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS,
|
|
53
56
|
[materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME]: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS,
|
|
@@ -159,6 +159,7 @@ const OVERVIEW_DEFINITION = {
|
|
|
159
159
|
'Map-only counters: no sales_overview_counter_rows.',
|
|
160
160
|
'LIVE is raw + stored credit ledger and resolves the running day server-side.',
|
|
161
161
|
'Writes the credit ledger and may patch prior issue-day counters.',
|
|
162
|
+
'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
|
|
162
163
|
],
|
|
163
164
|
};
|
|
164
165
|
const DISCOUNTS_DEFINITION = {
|
|
@@ -245,6 +246,7 @@ const DISCOUNTS_DEFINITION = {
|
|
|
245
246
|
'Month-capped scope set; a wider selection is refused, never narrowed.',
|
|
246
247
|
'Page-partitioned entries; no #N splitter and no budget assertion today.',
|
|
247
248
|
'Derived source projection has no independent iteration history.',
|
|
249
|
+
'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
|
|
248
250
|
],
|
|
249
251
|
};
|
|
250
252
|
const PREP_TIME_DEFINITION = {
|
|
@@ -314,6 +316,7 @@ const PREP_TIME_DEFINITION = {
|
|
|
314
316
|
'Coverage-first counters: MEASURED/UNMEASURED anchor split and target provenance.',
|
|
315
317
|
'No hour scope; entries are one document per scope, not pages.',
|
|
316
318
|
'Item reads are capped at 31 effective days at the route.',
|
|
319
|
+
'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
|
|
317
320
|
],
|
|
318
321
|
};
|
|
319
322
|
const DELIVERY_DEFINITION = {
|
|
@@ -412,7 +415,10 @@ const DELIVERY_DEFINITION = {
|
|
|
412
415
|
mode: 'SERVER',
|
|
413
416
|
appliesTo: 'BOTH',
|
|
414
417
|
},
|
|
415
|
-
|
|
418
|
+
// Rider is NOT a delivery request filter. Rider ids are high-cardinality and
|
|
419
|
+
// rider analysis is a bounded `riders` map inside each document; a
|
|
420
|
+
// `rider_id` request is REJECTED (400 INVALID_REQUEST,
|
|
421
|
+
// details.unsupported_filters: ["rider_id"]) instead of silently ignored.
|
|
416
422
|
{ id: 'DETAILS_VIEW', kind: 'REQUEST', mode: 'SERVER', appliesTo: 'DETAILS' },
|
|
417
423
|
],
|
|
418
424
|
cursor: REPORT_CURSOR_KIND.KEYSET_STRUCTURED,
|
|
@@ -427,7 +433,10 @@ const DELIVERY_DEFINITION = {
|
|
|
427
433
|
'Separate H3 geo collection and cap metadata; live geo is computed in memory.',
|
|
428
434
|
'Cross-day completion re-materializes the prior ORDER day within the same transaction.',
|
|
429
435
|
'Page entries split deterministically into #N sub-pages.',
|
|
430
|
-
'Historical totals
|
|
436
|
+
'Historical totals PIN schema_version (mixed-version documents are never summed).',
|
|
437
|
+
'A skipped stale cross-day update writes readiness NEEDS_RECONCILIATION, never COMMITTED.',
|
|
438
|
+
'Writes its materialized_tenant_day_readiness row in the SAME transaction.',
|
|
439
|
+
'Rider is not a request filter; rider_id is rejected with 400 INVALID_REQUEST.',
|
|
431
440
|
],
|
|
432
441
|
};
|
|
433
442
|
const DIALER_DEFINITION = {
|
|
@@ -510,6 +519,7 @@ const DIALER_DEFINITION = {
|
|
|
510
519
|
'Counters are filtered by ACTION / POS_ID / STAFF_ID key components server-side.',
|
|
511
520
|
'Page entries split deterministically into #N sub-pages when over the 15 MiB budget.',
|
|
512
521
|
'Late events are not included until the day is re-closed.',
|
|
522
|
+
'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
|
|
513
523
|
],
|
|
514
524
|
};
|
|
515
525
|
exports.REPORT_DEFINITIONS = {
|
|
@@ -27,6 +27,7 @@ function getCommonOptionalBoolFieldsPurchaseOrderIteration(order, partial) {
|
|
|
27
27
|
const defaultValue = partial ? undefined : false;
|
|
28
28
|
return {
|
|
29
29
|
is_gst_inclusive: order.is_gst_inclusive || defaultValue,
|
|
30
|
+
exclude_discount_from_gst: order.exclude_discount_from_gst || defaultValue,
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
function getCommonOptionalNumFieldsPurchaseOrderIteration(order, partial) {
|
|
@@ -34,6 +35,7 @@ function getCommonOptionalNumFieldsPurchaseOrderIteration(order, partial) {
|
|
|
34
35
|
return {
|
|
35
36
|
gst: order.gst || defaultValue,
|
|
36
37
|
gst_amount: order.gst_amount || defaultValue,
|
|
38
|
+
total_discount_applied: order.total_discount_applied || defaultValue,
|
|
37
39
|
};
|
|
38
40
|
}
|
|
39
41
|
function generateWarehousePurchaseOrderIteration(order, partial = true, skipItemMetadata) {
|
|
@@ -54,6 +56,7 @@ function generateWarehousePurchaseOrderIteration(order, partial = true, skipItem
|
|
|
54
56
|
price: order.price,
|
|
55
57
|
amount_earned: order.amount_earned,
|
|
56
58
|
grand_total: order.grand_total,
|
|
59
|
+
order_discount_details: order.order_discount_details ?? undefined,
|
|
57
60
|
tax_number: order.tax_number,
|
|
58
61
|
updatedAt: order.updatedAt,
|
|
59
62
|
};
|
|
@@ -67,7 +67,19 @@ export declare enum REPORT_ERROR_CODE_ENUM {
|
|
|
67
67
|
TIME_WINDOW_NOT_SUPPORTED_LIVE = "TIME_WINDOW_NOT_SUPPORTED_LIVE",
|
|
68
68
|
INVALID_BASELINE = "INVALID_BASELINE",
|
|
69
69
|
INVALID_CURSOR = "INVALID_CURSOR",
|
|
70
|
-
DRILLDOWN_PROJECTION_UNAVAILABLE = "DRILLDOWN_PROJECTION_UNAVAILABLE"
|
|
70
|
+
DRILLDOWN_PROJECTION_UNAVAILABLE = "DRILLDOWN_PROJECTION_UNAVAILABLE",
|
|
71
|
+
/**
|
|
72
|
+
* Historical read of a report/day that was never materialized (no committed
|
|
73
|
+
* readiness row). HTTP 409; details: { report, missing_tenants, missing_dates }.
|
|
74
|
+
*/
|
|
75
|
+
HISTORICAL_NOT_MATERIALIZED = "HISTORICAL_NOT_MATERIALIZED",
|
|
76
|
+
/**
|
|
77
|
+
* Historical read whose committed readiness row says the report is not final
|
|
78
|
+
* (e.g. Delivery skipped a stale cross-day update). HTTP 409; details:
|
|
79
|
+
* { report, missing_tenants, missing_dates } (the tenants/days awaiting
|
|
80
|
+
* reconciliation).
|
|
81
|
+
*/
|
|
82
|
+
HISTORICAL_NEEDS_RECONCILIATION = "HISTORICAL_NEEDS_RECONCILIATION"
|
|
71
83
|
}
|
|
72
84
|
export interface IReportErrorResponse {
|
|
73
85
|
error: {
|
|
@@ -118,6 +118,18 @@ var REPORT_ERROR_CODE_ENUM;
|
|
|
118
118
|
REPORT_ERROR_CODE_ENUM["INVALID_BASELINE"] = "INVALID_BASELINE";
|
|
119
119
|
REPORT_ERROR_CODE_ENUM["INVALID_CURSOR"] = "INVALID_CURSOR";
|
|
120
120
|
REPORT_ERROR_CODE_ENUM["DRILLDOWN_PROJECTION_UNAVAILABLE"] = "DRILLDOWN_PROJECTION_UNAVAILABLE";
|
|
121
|
+
/**
|
|
122
|
+
* Historical read of a report/day that was never materialized (no committed
|
|
123
|
+
* readiness row). HTTP 409; details: { report, missing_tenants, missing_dates }.
|
|
124
|
+
*/
|
|
125
|
+
REPORT_ERROR_CODE_ENUM["HISTORICAL_NOT_MATERIALIZED"] = "HISTORICAL_NOT_MATERIALIZED";
|
|
126
|
+
/**
|
|
127
|
+
* Historical read whose committed readiness row says the report is not final
|
|
128
|
+
* (e.g. Delivery skipped a stale cross-day update). HTTP 409; details:
|
|
129
|
+
* { report, missing_tenants, missing_dates } (the tenants/days awaiting
|
|
130
|
+
* reconciliation).
|
|
131
|
+
*/
|
|
132
|
+
REPORT_ERROR_CODE_ENUM["HISTORICAL_NEEDS_RECONCILIATION"] = "HISTORICAL_NEEDS_RECONCILIATION";
|
|
121
133
|
})(REPORT_ERROR_CODE_ENUM || (exports.REPORT_ERROR_CODE_ENUM = REPORT_ERROR_CODE_ENUM = {}));
|
|
122
134
|
const isNonEmptyString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
123
135
|
const toIsoString = (value) => {
|