@managesome/eposmatic-toolkit 0.4.32 → 0.4.35
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 +22 -4
- package/esm/constants/enums/offers.js +0 -6
- package/esm/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/esm/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +12 -8
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +141 -10
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +7 -3
- package/esm/helpers/materialized-reports/materialized-prep-time-read-helpers.js +638 -0
- package/esm/helpers/types/materialized-reports-apis.js +10 -0
- package/esm/schemas/models/index.js +0 -1
- package/esm/schemas/models/materialized_tenant_prep_time_entries.js +2 -2
- package/esm/schemas/types/index.js +0 -1
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +17 -4
- package/lib/constants/MATERIALIZED_REPORTS.js +24 -6
- package/lib/constants/enums/offers.d.ts +0 -5
- package/lib/constants/enums/offers.js +1 -7
- 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-index-bootstrap.js +4 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.js +12 -8
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +22 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +142 -9
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +6 -2
- package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.d.ts +198 -0
- package/lib/helpers/materialized-reports/materialized-prep-time-read-helpers.js +666 -0
- package/lib/helpers/types/materialized-reports-apis.d.ts +145 -1
- package/lib/helpers/types/materialized-reports-apis.js +11 -0
- package/lib/schemas/models/index.d.ts +0 -1
- package/lib/schemas/models/index.js +0 -1
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +6 -6
- package/lib/schemas/models/materialized_tenant_prep_time_entries.js +1 -1
- package/lib/schemas/types/index.d.ts +0 -1
- package/lib/schemas/types/index.js +0 -1
- package/lib/schemas/types/materialized_tenant_prep_time_reports.d.ts +7 -5
- package/lib/tests/materialized-reports/materialized-prep-time-classification.test.js +28 -5
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +33 -1
- package/lib/tests/materialized-reports/materialized-prep-time-compile.test.js +10 -1
- package/lib/tests/materialized-reports/materialized-prep-time-constants.test.js +14 -1
- package/lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.js +135 -0
- package/lib/tests/materialized-reports/materialized-prep-time-plan.test.js +106 -0
- package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-prep-time-read-helpers.test.js +620 -0
- package/lib/tests/offers-matrix.test.d.ts +1 -0
- package/lib/tests/offers-matrix.test.js +401 -0
- package/package.json +1 -1
- package/esm/schemas/models/rewards_usage.js +0 -61
- package/lib/schemas/models/rewards_usage.d.ts +0 -53
- package/lib/schemas/models/rewards_usage.js +0 -64
- package/lib/schemas/types/rewards_usage.d.ts +0 -13
- package/lib/schemas/types/rewards_usage.js +0 -2
- /package/{esm/schemas/types/rewards_usage.js → lib/tests/materialized-reports/materialized-prep-time-duration-consistency.test.d.ts} +0 -0
|
@@ -337,14 +337,27 @@ export declare const MATERIALIZED_DELIVERY_RIDER_LIMIT = 50;
|
|
|
337
337
|
/** Cap of the per-document area leaderboard (bounded, display-only). */
|
|
338
338
|
export declare const MATERIALIZED_DELIVERY_AREA_LIMIT = 50;
|
|
339
339
|
/**
|
|
340
|
-
* Scopes materialized by `materialized_tenant_prep_time_reports
|
|
340
|
+
* Scopes materialized by `materialized_tenant_prep_time_reports` — the SUMMARY
|
|
341
|
+
* range (and the writer's COUNTER scopes).
|
|
341
342
|
*
|
|
342
343
|
* NO `localHour` (decision h2): the tracked population per hour is 2-3 items in
|
|
343
|
-
* the dev stores, so an hourly prep time would be noise.
|
|
344
|
-
*
|
|
345
|
-
*
|
|
344
|
+
* the dev stores, so an hourly prep time would be noise.
|
|
345
|
+
*
|
|
346
|
+
* The Summary is CHEAP for a year because it reads these pre-aggregated counters,
|
|
347
|
+
* not item rows. The itemized reads are a DIFFERENT, month-capped list
|
|
348
|
+
* (`MATERIALIZED_PREP_TIME_ITEM_SCOPES`); the writer therefore materializes the
|
|
349
|
+
* full counter range but only month-capped ENTRY rows / flat period rows.
|
|
346
350
|
*/
|
|
347
351
|
export declare const MATERIALIZED_PREP_TIME_REPORT_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
352
|
+
/**
|
|
353
|
+
* Scopes the ITEMIZED prep reads support — Items, Categories and the Details
|
|
354
|
+
* drill-down. Capped at `LOCAL_MONTH` so item rows can never grow into a
|
|
355
|
+
* quarter/year document; the service additionally enforces a 31-effective-day
|
|
356
|
+
* cap (see `MATERIALIZED_PREP_TIME_ITEM_MAX_READ_DAYS`).
|
|
357
|
+
*/
|
|
358
|
+
export declare const MATERIALIZED_PREP_TIME_ITEM_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
359
|
+
/** Max EFFECTIVE days (after weekday/date refinement) an item read may cover. */
|
|
360
|
+
export declare const MATERIALIZED_PREP_TIME_ITEM_MAX_READ_DAYS = 31;
|
|
348
361
|
/** Ordered key filters of the prep time report (`COMPLETED:POS_WALK-IN`). */
|
|
349
362
|
export declare const PREP_TIME_KEY_FILTERS: MATERIALIZED_REPORT_KEY_FILTER_ENUM[];
|
|
350
363
|
/**
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* explicitly-enabled step.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
14
|
-
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 = void 0;
|
|
13
|
+
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_AREA_LIMIT = exports.MATERIALIZED_DELIVERY_RIDER_LIMIT = exports.MATERIALIZED_DELIVERY_DISTANCE_BUCKETS = exports.DELIVERY_KEY_FILTERS = 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
|
+
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 = void 0;
|
|
15
15
|
/**
|
|
16
16
|
* Time-scope of a materialized report document. Every document covers exactly
|
|
17
17
|
* one tenant × one scope context × one scope value (`scope_field`), and the
|
|
@@ -421,12 +421,16 @@ exports.MATERIALIZED_DELIVERY_AREA_LIMIT = 50;
|
|
|
421
421
|
/* Prep time report (M2) */
|
|
422
422
|
/* ======================================================================== */
|
|
423
423
|
/**
|
|
424
|
-
* Scopes materialized by `materialized_tenant_prep_time_reports
|
|
424
|
+
* Scopes materialized by `materialized_tenant_prep_time_reports` — the SUMMARY
|
|
425
|
+
* range (and the writer's COUNTER scopes).
|
|
425
426
|
*
|
|
426
427
|
* NO `localHour` (decision h2): the tracked population per hour is 2-3 items in
|
|
427
|
-
* the dev stores, so an hourly prep time would be noise.
|
|
428
|
-
*
|
|
429
|
-
*
|
|
428
|
+
* the dev stores, so an hourly prep time would be noise.
|
|
429
|
+
*
|
|
430
|
+
* The Summary is CHEAP for a year because it reads these pre-aggregated counters,
|
|
431
|
+
* not item rows. The itemized reads are a DIFFERENT, month-capped list
|
|
432
|
+
* (`MATERIALIZED_PREP_TIME_ITEM_SCOPES`); the writer therefore materializes the
|
|
433
|
+
* full counter range but only month-capped ENTRY rows / flat period rows.
|
|
430
434
|
*/
|
|
431
435
|
exports.MATERIALIZED_PREP_TIME_REPORT_SCOPES = [
|
|
432
436
|
MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
@@ -437,6 +441,20 @@ exports.MATERIALIZED_PREP_TIME_REPORT_SCOPES = [
|
|
|
437
441
|
MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_SEMESTER,
|
|
438
442
|
MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR,
|
|
439
443
|
];
|
|
444
|
+
/**
|
|
445
|
+
* Scopes the ITEMIZED prep reads support — Items, Categories and the Details
|
|
446
|
+
* drill-down. Capped at `LOCAL_MONTH` so item rows can never grow into a
|
|
447
|
+
* quarter/year document; the service additionally enforces a 31-effective-day
|
|
448
|
+
* cap (see `MATERIALIZED_PREP_TIME_ITEM_MAX_READ_DAYS`).
|
|
449
|
+
*/
|
|
450
|
+
exports.MATERIALIZED_PREP_TIME_ITEM_SCOPES = [
|
|
451
|
+
MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
452
|
+
MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK,
|
|
453
|
+
MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK_OF_YEAR,
|
|
454
|
+
MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
455
|
+
];
|
|
456
|
+
/** Max EFFECTIVE days (after weekday/date refinement) an item read may cover. */
|
|
457
|
+
exports.MATERIALIZED_PREP_TIME_ITEM_MAX_READ_DAYS = 31;
|
|
440
458
|
/** Ordered key filters of the prep time report (`COMPLETED:POS_WALK-IN`). */
|
|
441
459
|
exports.PREP_TIME_KEY_FILTERS = [
|
|
442
460
|
MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS,
|
|
@@ -51,11 +51,6 @@ export declare enum PATHWAY_TO_UNLOCK_TYPE_ENUM {
|
|
|
51
51
|
POINTS = "POINTS"
|
|
52
52
|
}
|
|
53
53
|
export declare const ALL_PATHWAY_TO_UNLOCK_TYPES: PATHWAY_TO_UNLOCK_TYPE_ENUM[];
|
|
54
|
-
export declare enum REWARDS_USAGE_REF_TYPE_ENUM {
|
|
55
|
-
VOUCHER = "VOUCHER",
|
|
56
|
-
GIFT_CARD = "GIFT_CARD"
|
|
57
|
-
}
|
|
58
|
-
export declare const ALL_REWARDS_USAGE_REF_TYPES: REWARDS_USAGE_REF_TYPE_ENUM[];
|
|
59
54
|
export declare enum RATING_TYPE_ENUM {
|
|
60
55
|
FOOD_QUALITY_RATING = "FOOD_QUALITY_RATING",
|
|
61
56
|
SERVICE_RATING = "SERVICE_RATING",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Auto-split from constants/ENUMS.ts — see ENUMS.ts barrel for exports.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ALL_DISCOUNT_APPLICABILITY_TYPES = exports.DISCOUNT_APPLICABILITY_ENUM = exports.ALL_DISCOUNT_TYPES = exports.DISCOUNT_TYPE_ENUM = exports.ALL_RATING_TYPES = exports.RATING_TYPE_ENUM = exports.
|
|
4
|
+
exports.ALL_DISCOUNT_APPLICABILITY_TYPES = exports.DISCOUNT_APPLICABILITY_ENUM = exports.ALL_DISCOUNT_TYPES = exports.DISCOUNT_TYPE_ENUM = exports.ALL_RATING_TYPES = exports.RATING_TYPE_ENUM = exports.ALL_PATHWAY_TO_UNLOCK_TYPES = exports.PATHWAY_TO_UNLOCK_TYPE_ENUM = exports.ALL_MYSTERY_GIFT_POPUP_TYPES = exports.MYSTERY_GIFT_POPUP_TYPE_ENUM = exports.ALL_MYSTERY_GIFT_TYPES = exports.MYSTERY_GIFT_TYPE_ENUM = exports.ALL_GIFT_CARD_REWARD_TYPES = exports.GIFT_CARD_REWARD_TYPE_ENUM = exports.ALL_CUSTOMER_REDEMPTION_TYPES = exports.CUSTOMER_REDEMPTION_TYPE_ENUM = exports.ALL_CUSTOMER_REDEMPTION_SOURCE_TYPES = exports.CUSTOMER_REDEMPTION_SOURCE_ENUM = exports.ALL_OFFER_REWARD_TYPES = exports.OFFER_REWARD_TYPE_ENUM = void 0;
|
|
5
5
|
var OFFER_REWARD_TYPE_ENUM;
|
|
6
6
|
(function (OFFER_REWARD_TYPE_ENUM) {
|
|
7
7
|
OFFER_REWARD_TYPE_ENUM["DISCOUNT"] = "DISCOUNT";
|
|
@@ -68,12 +68,6 @@ var PATHWAY_TO_UNLOCK_TYPE_ENUM;
|
|
|
68
68
|
PATHWAY_TO_UNLOCK_TYPE_ENUM["POINTS"] = "POINTS";
|
|
69
69
|
})(PATHWAY_TO_UNLOCK_TYPE_ENUM || (exports.PATHWAY_TO_UNLOCK_TYPE_ENUM = PATHWAY_TO_UNLOCK_TYPE_ENUM = {}));
|
|
70
70
|
exports.ALL_PATHWAY_TO_UNLOCK_TYPES = Object.values(PATHWAY_TO_UNLOCK_TYPE_ENUM);
|
|
71
|
-
var REWARDS_USAGE_REF_TYPE_ENUM;
|
|
72
|
-
(function (REWARDS_USAGE_REF_TYPE_ENUM) {
|
|
73
|
-
REWARDS_USAGE_REF_TYPE_ENUM["VOUCHER"] = "VOUCHER";
|
|
74
|
-
REWARDS_USAGE_REF_TYPE_ENUM["GIFT_CARD"] = "GIFT_CARD";
|
|
75
|
-
})(REWARDS_USAGE_REF_TYPE_ENUM || (exports.REWARDS_USAGE_REF_TYPE_ENUM = REWARDS_USAGE_REF_TYPE_ENUM = {}));
|
|
76
|
-
exports.ALL_REWARDS_USAGE_REF_TYPES = Object.values(REWARDS_USAGE_REF_TYPE_ENUM);
|
|
77
71
|
/* ================><================= */
|
|
78
72
|
var RATING_TYPE_ENUM;
|
|
79
73
|
(function (RATING_TYPE_ENUM) {
|
|
@@ -26,6 +26,7 @@ export * from './materialized-cash-compile-helpers';
|
|
|
26
26
|
export * from './materialized-prep-time-classification-helpers';
|
|
27
27
|
export * from './materialized-prep-time-close-day-helpers';
|
|
28
28
|
export * from './materialized-prep-time-compile-helpers';
|
|
29
|
+
export * from './materialized-prep-time-read-helpers';
|
|
29
30
|
export * from './materialized-report-drilldown-rows';
|
|
30
31
|
export * from './materialized-reports-read-helpers';
|
|
31
32
|
export * from './materialized-reports-scope-group-helpers';
|
|
@@ -42,6 +42,7 @@ __exportStar(require("./materialized-cash-compile-helpers"), exports);
|
|
|
42
42
|
__exportStar(require("./materialized-prep-time-classification-helpers"), exports);
|
|
43
43
|
__exportStar(require("./materialized-prep-time-close-day-helpers"), exports);
|
|
44
44
|
__exportStar(require("./materialized-prep-time-compile-helpers"), exports);
|
|
45
|
+
__exportStar(require("./materialized-prep-time-read-helpers"), exports);
|
|
45
46
|
__exportStar(require("./materialized-report-drilldown-rows"), exports);
|
|
46
47
|
__exportStar(require("./materialized-reports-read-helpers"), exports);
|
|
47
48
|
__exportStar(require("./materialized-reports-scope-group-helpers"), exports);
|
|
@@ -7,6 +7,8 @@ const materialized_tenant_discount_entries_1 = require("../../schemas/models/mat
|
|
|
7
7
|
const materialized_tenant_discount_reports_1 = require("../../schemas/models/materialized_tenant_discount_reports");
|
|
8
8
|
const materialized_tenant_discount_sources_1 = require("../../schemas/models/materialized_tenant_discount_sources");
|
|
9
9
|
const materialized_tenant_reports_iterations_1 = require("../../schemas/models/materialized_tenant_reports_iterations");
|
|
10
|
+
const materialized_tenant_prep_time_entries_1 = require("../../schemas/models/materialized_tenant_prep_time_entries");
|
|
11
|
+
const materialized_tenant_prep_time_reports_1 = require("../../schemas/models/materialized_tenant_prep_time_reports");
|
|
10
12
|
const materialized_tenant_sales_overview_reports_1 = require("../../schemas/models/materialized_tenant_sales_overview_reports");
|
|
11
13
|
const materialized_report_drilldown_rows_1 = require("../../schemas/models/materialized_report_drilldown_rows");
|
|
12
14
|
const tenant_calendar_1 = require("../../schemas/models/tenant_calendar");
|
|
@@ -29,6 +31,8 @@ const INDEXES = {
|
|
|
29
31
|
[materialized_tenant_discount_reports_1.MATERIALIZED_TENANT_DISCOUNT_REPORTS_COLLECTION_NAME]: materialized_tenant_discount_reports_1.MATERIALIZED_TENANT_DISCOUNT_REPORTS_INDEX_OPTIONS,
|
|
30
32
|
[materialized_tenant_discount_entries_1.MATERIALIZED_TENANT_DISCOUNT_ENTRIES_COLLECTION_NAME]: materialized_tenant_discount_entries_1.MATERIALIZED_TENANT_DISCOUNT_ENTRIES_INDEX_OPTIONS,
|
|
31
33
|
[materialized_tenant_discount_sources_1.MATERIALIZED_TENANT_DISCOUNT_SOURCES_COLLECTION_NAME]: materialized_tenant_discount_sources_1.MATERIALIZED_TENANT_DISCOUNT_SOURCES_INDEX_OPTIONS,
|
|
34
|
+
[materialized_tenant_prep_time_reports_1.MATERIALIZED_TENANT_PREP_TIME_REPORTS_COLLECTION_NAME]: materialized_tenant_prep_time_reports_1.MATERIALIZED_TENANT_PREP_TIME_REPORTS_INDEX_OPTIONS,
|
|
35
|
+
[materialized_tenant_prep_time_entries_1.MATERIALIZED_TENANT_PREP_TIME_ENTRIES_COLLECTION_NAME]: materialized_tenant_prep_time_entries_1.MATERIALIZED_TENANT_PREP_TIME_ENTRIES_INDEX_OPTIONS,
|
|
32
36
|
[materialized_tenant_reports_iterations_1.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME]: materialized_tenant_reports_iterations_1.MATERIALIZED_TENANT_REPORTS_ITERATIONS_INDEX_OPTIONS,
|
|
33
37
|
[materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_COLLECTION_NAME]: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_ROWS_INDEX_OPTIONS,
|
|
34
38
|
[materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_SCOPES_COLLECTION_NAME]: materialized_report_drilldown_rows_1.MATERIALIZED_REPORT_DRILLDOWN_SCOPES_INDEX_OPTIONS,
|
|
@@ -151,14 +151,18 @@ function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes = null,
|
|
|
151
151
|
counters.coverage.own_anchor_count += 1;
|
|
152
152
|
// RECONSTRUCTED ready instant - the source field ready_at does not exist.
|
|
153
153
|
readyAt = new Date(prepStartedAt.getTime() + minutes * 60000);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
154
|
+
// ONE canonical duration population: a duration is VALID only when it
|
|
155
|
+
// is finite, >= 0 and <= the outlier cap. Valid durations alone feed
|
|
156
|
+
// count / sum / min / max / buckets / instant count (and therefore
|
|
157
|
+
// avg = sum/count). An artefact must never understate the average by
|
|
158
|
+
// sitting in the denominator while being excluded from the numerator.
|
|
159
|
+
// Coverage still counts the MEASURED row (own_anchor_count above).
|
|
160
|
+
if (minutes >= 0 && minutes <= MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_MAX_MINUTES) {
|
|
161
|
+
counters.duration.count += 1;
|
|
162
|
+
if (minutes === 0)
|
|
163
|
+
counters.duration.instant_count += 1;
|
|
164
|
+
const bucket = resolveMaterializedPrepTimeBucket(minutes);
|
|
165
|
+
counters.duration.buckets[bucket] = (counters.duration.buckets[bucket] ?? 0) + 1;
|
|
162
166
|
counters.duration.sum += minutes;
|
|
163
167
|
if (counters.duration.count === 1 || minutes < counters.duration.min) {
|
|
164
168
|
counters.duration.min = minutes;
|
|
@@ -70,6 +70,22 @@ export declare function foldMaterializedPrepTimePeriodRows({ periodScopeField, p
|
|
|
70
70
|
}>;
|
|
71
71
|
/** The period scope contexts (everything except the day scope). */
|
|
72
72
|
export declare const MATERIALIZED_PREP_TIME_PERIOD_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
73
|
+
/** Period scopes that carry ENTRY rows / flat rows (month-capped). */
|
|
74
|
+
export declare const MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
75
|
+
/**
|
|
76
|
+
* Every `localDate` label whose DAY entry document can contribute to a
|
|
77
|
+
* month-capped period (week / ISO week / month). The worker uses this to fetch
|
|
78
|
+
* exactly the sibling day entries the entry fold needs — never a full-period
|
|
79
|
+
* entry document and never a year-wide scan.
|
|
80
|
+
*/
|
|
81
|
+
export declare function getMaterializedPrepTimePeriodDayScopeFields(localDate: string): string[] | null;
|
|
82
|
+
/**
|
|
83
|
+
* Every `localDate` label whose DAY counter document can contribute to ANY
|
|
84
|
+
* report period the closing day rolls into, including quarter / semester /
|
|
85
|
+
* year. Used by the worker's SUMMARY counter fold only; entry rows stay
|
|
86
|
+
* month-capped.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getMaterializedPrepTimeReportPeriodDayScopeFields(localDate: string): string[] | null;
|
|
73
89
|
/** True when a stored prep counter document equals the incoming one (skip write). */
|
|
74
90
|
export declare function needsMaterializedPrepTimeReportWrite(existing: IMaterializedTenantPrepTimeReport | null | undefined, incoming: IMaterializedTenantPrepTimeReport | null | undefined): boolean;
|
|
75
91
|
/** One planned write: the document plus its shared-history iteration row. */
|
|
@@ -114,6 +130,12 @@ export interface IBuildTenantPrepTimeCloseDayPlanInput {
|
|
|
114
130
|
existing?: IMaterializedTenantPrepTimeReport[];
|
|
115
131
|
existingEntries?: IMaterializedTenantPrepTimeEntries[];
|
|
116
132
|
reason: string;
|
|
133
|
+
/**
|
|
134
|
+
* Structural writes even when the watermark says the day is unchanged
|
|
135
|
+
* (manual range repair). The period folds are idempotent, so a forced run
|
|
136
|
+
* rewrites the same values and advances the iteration.
|
|
137
|
+
*/
|
|
138
|
+
force?: boolean;
|
|
117
139
|
computedAt?: Date;
|
|
118
140
|
}
|
|
119
141
|
/**
|
|
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES = exports.isMaterializedPrepTimeDayScope = exports.mergeMaterializedPrepTimeEntrySections = void 0;
|
|
6
|
+
exports.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES = exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES = exports.isMaterializedPrepTimeDayScope = exports.mergeMaterializedPrepTimeEntrySections = void 0;
|
|
7
7
|
exports.updateMaterializedPrepTimeEntries = updateMaterializedPrepTimeEntries;
|
|
8
8
|
exports.needsMaterializedPrepTimeEntriesWrite = needsMaterializedPrepTimeEntriesWrite;
|
|
9
9
|
exports.foldMaterializedPrepTimePeriodCounters = foldMaterializedPrepTimePeriodCounters;
|
|
10
10
|
exports.foldMaterializedPrepTimePeriodRows = foldMaterializedPrepTimePeriodRows;
|
|
11
|
+
exports.getMaterializedPrepTimePeriodDayScopeFields = getMaterializedPrepTimePeriodDayScopeFields;
|
|
12
|
+
exports.getMaterializedPrepTimeReportPeriodDayScopeFields = getMaterializedPrepTimeReportPeriodDayScopeFields;
|
|
11
13
|
exports.needsMaterializedPrepTimeReportWrite = needsMaterializedPrepTimeReportWrite;
|
|
12
14
|
exports.buildTenantPrepTimeCloseDayPlan = buildTenantPrepTimeCloseDayPlan;
|
|
13
15
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
@@ -168,6 +170,117 @@ function foldMaterializedPrepTimePeriodRows({ periodScopeField, periodScope, day
|
|
|
168
170
|
}
|
|
169
171
|
/** The period scope contexts (everything except the day scope). */
|
|
170
172
|
exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_REPORT_SCOPES.filter((scope) => !(0, exports.isMaterializedPrepTimeDayScope)(String(scope)));
|
|
173
|
+
/** Period scopes that carry ENTRY rows / flat rows (month-capped). */
|
|
174
|
+
exports.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ITEM_SCOPES.filter((scope) => !(0, exports.isMaterializedPrepTimeDayScope)(String(scope)));
|
|
175
|
+
/* ------------------------------------------------------------------------ */
|
|
176
|
+
/* Period sibling-day enumeration */
|
|
177
|
+
/* ------------------------------------------------------------------------ */
|
|
178
|
+
const pad2 = (value) => String(value).padStart(2, '0');
|
|
179
|
+
const toLocalDateKey = (date) => `${date.getUTCFullYear()}-${pad2(date.getUTCMonth() + 1)}-${pad2(date.getUTCDate())}`;
|
|
180
|
+
const addUtcDays = (date, amount) => new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate() + amount));
|
|
181
|
+
const addMonthDays = (year, month, count, days) => {
|
|
182
|
+
if (!Number.isInteger(year) || !Number.isInteger(month) || month < 1 || month > 12)
|
|
183
|
+
return false;
|
|
184
|
+
for (let offset = 0; offset < count; offset += 1) {
|
|
185
|
+
const date = new Date(Date.UTC(year, month - 1 + offset, 1));
|
|
186
|
+
const monthYear = date.getUTCFullYear();
|
|
187
|
+
const monthNumber = date.getUTCMonth() + 1;
|
|
188
|
+
const last = new Date(Date.UTC(monthYear, monthNumber, 0)).getUTCDate();
|
|
189
|
+
for (let day = 1; day <= last; day += 1) {
|
|
190
|
+
days.add(`${monthYear}-${pad2(monthNumber)}-${pad2(day)}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
194
|
+
};
|
|
195
|
+
const addPeriodDays = (scope, scopeField, days) => {
|
|
196
|
+
switch (scope) {
|
|
197
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK: {
|
|
198
|
+
const parts = (0, scope_helpers_1.parseMaterializedLocalDate)(scopeField);
|
|
199
|
+
if (parts == null)
|
|
200
|
+
return false;
|
|
201
|
+
const start = new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
202
|
+
if (start.getUTCDay() !== 0)
|
|
203
|
+
return false;
|
|
204
|
+
for (let offset = 0; offset < 7; offset += 1)
|
|
205
|
+
days.add(toLocalDateKey(addUtcDays(start, offset)));
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK_OF_YEAR: {
|
|
209
|
+
const match = /^(\d{4})-W(\d{2})$/.exec(scopeField);
|
|
210
|
+
if (match == null)
|
|
211
|
+
return false;
|
|
212
|
+
const weekYear = Number(match[1]);
|
|
213
|
+
const week = Number(match[2]);
|
|
214
|
+
if (!Number.isInteger(week) || week < 1 || week > 53)
|
|
215
|
+
return false;
|
|
216
|
+
const jan4 = new Date(Date.UTC(weekYear, 0, 4));
|
|
217
|
+
const isoWeekday = jan4.getUTCDay() || 7;
|
|
218
|
+
const weekOneMonday = addUtcDays(jan4, 1 - isoWeekday);
|
|
219
|
+
const start = addUtcDays(weekOneMonday, (week - 1) * 7);
|
|
220
|
+
for (let offset = 0; offset < 7; offset += 1)
|
|
221
|
+
days.add(toLocalDateKey(addUtcDays(start, offset)));
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH: {
|
|
225
|
+
const match = /^(\d{4})-(\d{2})$/.exec(scopeField);
|
|
226
|
+
if (match == null)
|
|
227
|
+
return false;
|
|
228
|
+
return addMonthDays(Number(match[1]), Number(match[2]), 1, days);
|
|
229
|
+
}
|
|
230
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_QUARTER: {
|
|
231
|
+
const match = /^(\d{4})-Q([1-4])$/.exec(scopeField);
|
|
232
|
+
if (match == null)
|
|
233
|
+
return false;
|
|
234
|
+
return addMonthDays(Number(match[1]), (Number(match[2]) - 1) * 3 + 1, 3, days);
|
|
235
|
+
}
|
|
236
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_SEMESTER: {
|
|
237
|
+
const match = /^(\d{4})-S([12])$/.exec(scopeField);
|
|
238
|
+
if (match == null)
|
|
239
|
+
return false;
|
|
240
|
+
return addMonthDays(Number(match[1]), (Number(match[2]) - 1) * 6 + 1, 6, days);
|
|
241
|
+
}
|
|
242
|
+
case MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR: {
|
|
243
|
+
const match = /^(\d{4})$/.exec(scopeField);
|
|
244
|
+
if (match == null)
|
|
245
|
+
return false;
|
|
246
|
+
return addMonthDays(Number(match[1]), 1, 12, days);
|
|
247
|
+
}
|
|
248
|
+
default:
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
const enumeratePeriodDays = (localDate, scopes) => {
|
|
253
|
+
const periodFields = (0, scope_helpers_1.getMaterializedPeriodScopeFields)(localDate);
|
|
254
|
+
if (periodFields == null)
|
|
255
|
+
return null;
|
|
256
|
+
const days = new Set([localDate]);
|
|
257
|
+
for (const scope of scopes) {
|
|
258
|
+
const scopeField = periodFields[scope];
|
|
259
|
+
if (typeof scopeField !== 'string' || scopeField.length === 0)
|
|
260
|
+
return null;
|
|
261
|
+
if (!addPeriodDays(scope, scopeField, days))
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
return [...days].sort();
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Every `localDate` label whose DAY entry document can contribute to a
|
|
268
|
+
* month-capped period (week / ISO week / month). The worker uses this to fetch
|
|
269
|
+
* exactly the sibling day entries the entry fold needs — never a full-period
|
|
270
|
+
* entry document and never a year-wide scan.
|
|
271
|
+
*/
|
|
272
|
+
function getMaterializedPrepTimePeriodDayScopeFields(localDate) {
|
|
273
|
+
return enumeratePeriodDays(localDate, exports.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Every `localDate` label whose DAY counter document can contribute to ANY
|
|
277
|
+
* report period the closing day rolls into, including quarter / semester /
|
|
278
|
+
* year. Used by the worker's SUMMARY counter fold only; entry rows stay
|
|
279
|
+
* month-capped.
|
|
280
|
+
*/
|
|
281
|
+
function getMaterializedPrepTimeReportPeriodDayScopeFields(localDate) {
|
|
282
|
+
return enumeratePeriodDays(localDate, exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES);
|
|
283
|
+
}
|
|
171
284
|
/** True when a stored prep counter document equals the incoming one (skip write). */
|
|
172
285
|
function needsMaterializedPrepTimeReportWrite(existing, incoming) {
|
|
173
286
|
if (existing == null || incoming == null)
|
|
@@ -208,6 +321,7 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
208
321
|
if (reports.some((doc) => doc == null || doc.tenant_id !== tenantId))
|
|
209
322
|
return null;
|
|
210
323
|
const computedAt = input.computedAt ?? new Date();
|
|
324
|
+
const force = input.force === true;
|
|
211
325
|
const existing = input.existing ?? [];
|
|
212
326
|
const existingEntries = input.existingEntries ?? [];
|
|
213
327
|
const dateDoc = reports.find((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE) ?? null;
|
|
@@ -358,14 +472,14 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
358
472
|
sale_type_key_filters: existingDoc?.sale_type_key_filters ?? reports[0]?.sale_type_key_filters ?? [],
|
|
359
473
|
prep_time_counters: counters,
|
|
360
474
|
prep_time_counter_rows: counterRows,
|
|
361
|
-
iteration: existingDoc
|
|
475
|
+
iteration: existingDoc == null ? 1 : (existingDoc.iteration ?? 1) + 1,
|
|
362
476
|
schema_version: existingDoc?.schema_version ?? 1,
|
|
363
477
|
source_watermark: watermark ?? new Date(computedAt),
|
|
364
478
|
computed_at: computedAt,
|
|
365
479
|
createdAt: existingDoc?.createdAt ?? computedAt,
|
|
366
480
|
updatedAt: computedAt,
|
|
367
481
|
};
|
|
368
|
-
if (existingDoc != null && !needsMaterializedPrepTimeReportWrite(existingDoc, report)) {
|
|
482
|
+
if (!force && existingDoc != null && !needsMaterializedPrepTimeReportWrite(existingDoc, report)) {
|
|
369
483
|
skippedDocuments.push(existingDoc);
|
|
370
484
|
continue;
|
|
371
485
|
}
|
|
@@ -375,11 +489,20 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
375
489
|
// ---- the DAY scope: written straight from the compile --------------------
|
|
376
490
|
for (const doc of compiledDateDocs) {
|
|
377
491
|
const existingDoc = existingByScope.get(prepScopeKey(doc)) ?? null;
|
|
378
|
-
|
|
492
|
+
const report = {
|
|
493
|
+
...doc,
|
|
494
|
+
// A reclose REPLACES the stored day document: preserving its _id and
|
|
495
|
+
// createdAt keeps the identity + immutable fields stable (Mongo rejects a
|
|
496
|
+
// replace that alters _id).
|
|
497
|
+
_id: existingDoc?._id ?? doc._id,
|
|
498
|
+
createdAt: existingDoc?.createdAt ?? doc.createdAt,
|
|
499
|
+
iteration: existingDoc == null ? 1 : (existingDoc.iteration ?? 1) + 1,
|
|
500
|
+
};
|
|
501
|
+
if (!force && existingDoc != null && !needsMaterializedPrepTimeReportWrite(existingDoc, report)) {
|
|
379
502
|
skippedDocuments.push(existingDoc);
|
|
380
503
|
continue;
|
|
381
504
|
}
|
|
382
|
-
if (!addWrite(
|
|
505
|
+
if (!addWrite(report))
|
|
383
506
|
return null;
|
|
384
507
|
}
|
|
385
508
|
// ---- entry documents ------------------------------------------------------
|
|
@@ -413,7 +536,11 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
413
536
|
continue;
|
|
414
537
|
staleEntryDocuments.push(doc);
|
|
415
538
|
}
|
|
539
|
+
const itemPeriodScopes = new Set(exports.MATERIALIZED_PREP_TIME_ITEM_PERIOD_SCOPES);
|
|
416
540
|
for (const { scope, field } of touchedPeriods.values()) {
|
|
541
|
+
// ENTRY documents are month-capped; quarter/semester/year are COUNTER only.
|
|
542
|
+
if (!itemPeriodScopes.has(String(scope)))
|
|
543
|
+
continue;
|
|
417
544
|
const sections = foldMaterializedPrepTimePeriodRows({
|
|
418
545
|
periodScope: scope,
|
|
419
546
|
periodScopeField: field,
|
|
@@ -455,14 +582,14 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
455
582
|
day_index: null,
|
|
456
583
|
sale_type_key_filters: existingDoc?.sale_type_key_filters ?? entries[0]?.sale_type_key_filters ?? [],
|
|
457
584
|
prep_time_entries: sections,
|
|
458
|
-
iteration: existingDoc
|
|
585
|
+
iteration: existingDoc == null ? 1 : (existingDoc.iteration ?? 1) + 1,
|
|
459
586
|
schema_version: existingDoc?.schema_version ?? 1,
|
|
460
587
|
source_watermark: entryWatermark ?? new Date(computedAt),
|
|
461
588
|
computed_at: computedAt,
|
|
462
589
|
createdAt: existingDoc?.createdAt ?? computedAt,
|
|
463
590
|
updatedAt: computedAt,
|
|
464
591
|
};
|
|
465
|
-
if (existingDoc != null && !needsMaterializedPrepTimeEntriesWrite(existingDoc, report)) {
|
|
592
|
+
if (!force && existingDoc != null && !needsMaterializedPrepTimeEntriesWrite(existingDoc, report)) {
|
|
466
593
|
skippedEntryDocuments.push(existingDoc);
|
|
467
594
|
continue;
|
|
468
595
|
}
|
|
@@ -473,11 +600,17 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
473
600
|
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
474
601
|
continue;
|
|
475
602
|
const existingDoc = existingEntriesByScope.get(prepScopeKey(doc)) ?? null;
|
|
476
|
-
|
|
603
|
+
const report = {
|
|
604
|
+
...doc,
|
|
605
|
+
_id: existingDoc?._id ?? doc._id,
|
|
606
|
+
createdAt: existingDoc?.createdAt ?? doc.createdAt,
|
|
607
|
+
iteration: existingDoc == null ? 1 : (existingDoc.iteration ?? 1) + 1,
|
|
608
|
+
};
|
|
609
|
+
if (!force && existingDoc != null && !needsMaterializedPrepTimeEntriesWrite(existingDoc, report)) {
|
|
477
610
|
skippedEntryDocuments.push(existingDoc);
|
|
478
611
|
continue;
|
|
479
612
|
}
|
|
480
|
-
if (!addEntryWrite(
|
|
613
|
+
if (!addEntryWrite(report))
|
|
481
614
|
return null;
|
|
482
615
|
}
|
|
483
616
|
return {
|
|
@@ -93,6 +93,7 @@ function compileTenantPrepTimeReports(input) {
|
|
|
93
93
|
return null;
|
|
94
94
|
const dayIndex = (0, scope_helpers_1.getDayIndexFromLocalDate)(localDate);
|
|
95
95
|
const at = computedAt ?? new Date();
|
|
96
|
+
const itemScopes = new Set(MATERIALIZED_REPORTS_1.MATERIALIZED_PREP_TIME_ITEM_SCOPES);
|
|
96
97
|
const byScope = new Map();
|
|
97
98
|
const scopeContextOf = new Map();
|
|
98
99
|
const bucketFor = (scope, scopeField, key) => {
|
|
@@ -145,7 +146,10 @@ function compileTenantPrepTimeReports(input) {
|
|
|
145
146
|
continue;
|
|
146
147
|
const bucket = bucketFor(scope, scopeField, key);
|
|
147
148
|
mergeMaterializedPrepTimeCounters(bucket.counters, result.counters);
|
|
148
|
-
|
|
149
|
+
// ENTRY rows / flat rows are month-capped; the Summary counters go to the
|
|
150
|
+
// full report range. Never accumulate quarter/semester/year item rows.
|
|
151
|
+
if (itemScopes.has(scope))
|
|
152
|
+
bucket.rows.push(...result.entries);
|
|
149
153
|
foldWatermark(bucket, watermark);
|
|
150
154
|
}
|
|
151
155
|
}
|
|
@@ -186,7 +190,7 @@ function compileTenantPrepTimeReports(input) {
|
|
|
186
190
|
createdAt: at,
|
|
187
191
|
updatedAt: at,
|
|
188
192
|
});
|
|
189
|
-
if (Object.keys(entrySections).length > 0) {
|
|
193
|
+
if (itemScopes.has(scopeContext) && Object.keys(entrySections).length > 0) {
|
|
190
194
|
entries.push({
|
|
191
195
|
_id: new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
192
196
|
tenant_id: tenantId,
|