@managesome/eposmatic-toolkit 0.4.10 → 0.4.12
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 +7 -0
- package/esm/constants/enums/delivery.js +8 -0
- package/esm/helpers/materialized-reports/materialized-cash-classification-helpers.js +5 -43
- package/esm/helpers/materialized-reports/materialized-cash-close-day-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-cash-compile-helpers.js +5 -4
- package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +6 -6
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +3 -2
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +12 -14
- package/esm/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +2 -1
- package/esm/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +7 -3
- package/esm/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +2 -1
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +15 -14
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-reports-scope-group-helpers.js +9 -6
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +4 -4
- package/esm/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +5 -6
- package/esm/helpers/materialized-reports/tenant-cash-in-out-formatter.js +2 -1
- package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +2 -2
- package/esm/helpers/materialized-reports/tenant-discount-formatter.js +2 -2
- package/esm/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +3 -2
- package/esm/helpers/materialized-reports/tenant-payments-comparison-formatter.js +7 -4
- package/esm/helpers/materialized-reports/tenant-sales-comparison-formatter.js +7 -4
- package/esm/helpers/reporting-contract/overview-contract.js +5 -4
- package/esm/helpers/rider-earnings/rider-earnings.js +0 -6
- package/esm/helpers/rider-reports/rider-daily-report.js +2 -5
- package/esm/helpers/store/common-order-actions.js +3 -2
- package/esm/helpers/utils/delivery-helpers.js +5 -2
- package/esm/schemas/models/deliveries.js +11 -10
- package/esm/schemas/models/materialized_credit_bills.js +1 -1
- package/esm/schemas/models/materialized_rider_daily_reports.js +10 -2
- package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +1 -1
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +6 -0
- package/lib/constants/MATERIALIZED_REPORTS.js +9 -2
- package/lib/constants/enums/delivery.d.ts +7 -0
- package/lib/constants/enums/delivery.js +9 -1
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.d.ts +55 -3
- package/lib/helpers/materialized-reports/materialized-cash-classification-helpers.js +4 -42
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.d.ts +2 -1
- package/lib/helpers/materialized-reports/materialized-cash-close-day-helpers.js +2 -2
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.d.ts +3 -2
- package/lib/helpers/materialized-reports/materialized-cash-compile-helpers.js +4 -3
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +35 -3
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +5 -5
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +2 -1
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +8 -7
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +4 -3
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +10 -12
- package/lib/helpers/materialized-reports/materialized-discount-accumulator-helpers.js +2 -1
- package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js +6 -2
- package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js +2 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-classification-helpers.d.ts +34 -2
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.d.ts +7 -5
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +14 -13
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.d.ts +2 -1
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +1 -1
- package/lib/helpers/materialized-reports/materialized-reports-scope-group-helpers.d.ts +6 -3
- package/lib/helpers/materialized-reports/materialized-reports-scope-group-helpers.js +8 -5
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +2 -2
- package/lib/helpers/materialized-reports/materialized-sales-comparison-baseline-helpers.js +3 -4
- package/lib/helpers/materialized-reports/tenant-cash-in-out-formatter.js +2 -1
- package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +1 -1
- package/lib/helpers/materialized-reports/tenant-discount-formatter.js +1 -1
- package/lib/helpers/materialized-reports/tenant-hourly-comparison-formatter.js +3 -2
- package/lib/helpers/materialized-reports/tenant-payments-comparison-formatter.js +7 -4
- package/lib/helpers/materialized-reports/tenant-prep-time-formatter.d.ts +2 -1
- package/lib/helpers/materialized-reports/tenant-sales-comparison-formatter.js +7 -4
- package/lib/helpers/reporting-contract/overview-contract.js +5 -4
- package/lib/helpers/rider-earnings/rider-earnings.d.ts +0 -7
- package/lib/helpers/rider-earnings/rider-earnings.js +0 -7
- package/lib/helpers/rider-reports/rider-daily-report.d.ts +4 -3
- package/lib/helpers/rider-reports/rider-daily-report.js +1 -4
- package/lib/helpers/store/common-order-actions.js +3 -2
- package/lib/helpers/types/materialized-reports-apis.d.ts +3 -0
- package/lib/helpers/utils/delivery-helpers.js +5 -2
- package/lib/schemas/models/deliveries.d.ts +10 -10
- package/lib/schemas/models/deliveries.js +10 -9
- package/lib/schemas/models/materialized_credit_bills.d.ts +3 -3
- package/lib/schemas/models/materialized_credit_bills.js +1 -1
- package/lib/schemas/models/materialized_rider_daily_reports.d.ts +12 -2
- package/lib/schemas/models/materialized_rider_daily_reports.js +11 -3
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +1 -1
- package/lib/schemas/types/deliveries.d.ts +6 -7
- package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +7 -0
- package/lib/tests/deliveries-schema.test.d.ts +1 -0
- package/lib/tests/deliveries-schema.test.js +72 -0
- package/lib/tests/materialized-reports/materialized-cash-compile.test.js +2 -1
- package/lib/tests/materialized-reports/materialized-cash-formatter.test.js +2 -1
- package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +2 -1
- package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +9 -8
- package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +2 -1
- package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +4 -2
- package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +2 -1
- package/lib/tests/materialized-reports/materialized-prep-time-close-day.test.js +7 -6
- package/lib/tests/materialized-reports/materialized-reports-scope-group-helpers.test.js +13 -13
- package/lib/tests/materialized-reports/materialized-sales-comparison-compile.test.js +2 -1
- package/lib/tests/rider-daily-report.test.js +3 -6
- package/package.json +1 -1
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { DELIVERY_STATUS_ENUM } from '../../constants/enums/delivery';
|
|
2
|
+
import { IDelivery } from '../../schemas/types/deliveries';
|
|
3
|
+
import { IOrderDeliveryDetails } from '../../schemas/types/orders';
|
|
1
4
|
import { IMaterializedDeliveryCounters } from '../../schemas/types/materialized_tenant_delivery_reports';
|
|
2
5
|
/**
|
|
3
6
|
* M4 delivery - key grammar, the order join, and the accumulators.
|
|
@@ -49,6 +52,35 @@ export declare function deliveryDistanceBucketKey(meters: number): string;
|
|
|
49
52
|
* difference between the orders that had a delivery and those that did not, so it does
|
|
50
53
|
* not matter whether the orders stage or the deliveries stage runs first.
|
|
51
54
|
*/
|
|
55
|
+
/** Raw order fields this classifier reads (source documents are often partial). */
|
|
56
|
+
export interface IDeliveryOrderSource {
|
|
57
|
+
_id: string;
|
|
58
|
+
tenant_id?: string | null;
|
|
59
|
+
updatedAt?: Date | string | null;
|
|
60
|
+
order_number?: number | null;
|
|
61
|
+
platform?: string | null;
|
|
62
|
+
createdAt?: Date | string | null;
|
|
63
|
+
net_sale_amount?: number | null;
|
|
64
|
+
amount_earned?: number | null;
|
|
65
|
+
amount_collected?: number | null;
|
|
66
|
+
amount_refunded?: number | null;
|
|
67
|
+
total_discount_applied?: number | null;
|
|
68
|
+
tip_amount?: number | null;
|
|
69
|
+
gst_amount?: number | null;
|
|
70
|
+
tax_amount?: number | null;
|
|
71
|
+
delivery_details?: (Partial<IOrderDeliveryDetails> & {
|
|
72
|
+
delivery_charge?: number | null;
|
|
73
|
+
delivery_charge_amount?: number | null;
|
|
74
|
+
}) | null;
|
|
75
|
+
}
|
|
76
|
+
/** Raw delivery fields this classifier reads (all optional at the boundary). */
|
|
77
|
+
export type TDeliverySource = Partial<Omit<IDelivery, 'status' | '_id' | 'order_id' | 'rider_earnings'>> & {
|
|
78
|
+
_id?: string;
|
|
79
|
+
order_id?: string;
|
|
80
|
+
status?: DELIVERY_STATUS_ENUM | string;
|
|
81
|
+
rider_earnings?: Partial<NonNullable<IDelivery['rider_earnings']>> | null;
|
|
82
|
+
localHour?: number | null;
|
|
83
|
+
};
|
|
52
84
|
export interface IDeliveryAccumulator {
|
|
53
85
|
counters: IMaterializedDeliveryCounters;
|
|
54
86
|
deliveryOrderIds: Set<string>;
|
|
@@ -58,14 +90,14 @@ export interface IDeliveryAccumulator {
|
|
|
58
90
|
/** A fresh buffer. */
|
|
59
91
|
export declare function freshDeliveryAccumulator(): IDeliveryAccumulator;
|
|
60
92
|
/** True when an order is a DELIVERY order (it has delivery details). */
|
|
61
|
-
export declare function isDeliveryOrder(order:
|
|
93
|
+
export declare function isDeliveryOrder(order: IDeliveryOrderSource): boolean;
|
|
62
94
|
/**
|
|
63
95
|
* Consumes ONE delivery ORDER - the ADOPTION half of the join.
|
|
64
96
|
*
|
|
65
97
|
* Order-side money is counted HERE rather than on the delivery, because a cancelled
|
|
66
98
|
* delivery must not lose the order figures the operator recognises.
|
|
67
99
|
*/
|
|
68
|
-
export declare function addDeliveryOrder(acc: IDeliveryAccumulator, order:
|
|
100
|
+
export declare function addDeliveryOrder(acc: IDeliveryAccumulator, order: IDeliveryOrderSource): void;
|
|
69
101
|
/**
|
|
70
102
|
* Consumes ONE delivery document - the APP-SIDE half of the join.
|
|
71
103
|
*
|
|
@@ -73,7 +105,7 @@ export declare function addDeliveryOrder(acc: IDeliveryAccumulator, order: any):
|
|
|
73
105
|
* adoption and its own fields, but the order-derived money and the area cannot be
|
|
74
106
|
* attributed, so it lands in the UNKNOWN bucket.
|
|
75
107
|
*/
|
|
76
|
-
export declare function addDelivery(acc: IDeliveryAccumulator, delivery:
|
|
108
|
+
export declare function addDelivery(acc: IDeliveryAccumulator, delivery: TDeliverySource, order: IDeliveryOrderSource | null, key: string): void;
|
|
77
109
|
/**
|
|
78
110
|
* Computes the DERIVED adoption figures and prunes the bounded maps.
|
|
79
111
|
*
|
|
@@ -271,9 +271,9 @@ function addDelivery(acc, delivery, order, key) {
|
|
|
271
271
|
// Only a FINAL snapshot is payout. A PENDING snapshot is an estimate shown to
|
|
272
272
|
// the rider before completion and must not inflate the materialized report.
|
|
273
273
|
const earnings = delivery.rider_earnings;
|
|
274
|
-
const
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
274
|
+
const isFinalPayout = earnings?.status === delivery_1.RIDER_EARNINGS_STATUS_ENUM.FINAL;
|
|
275
|
+
const revenue = isFinalPayout ? Number(earnings.amount) || 0 : 0;
|
|
276
|
+
if (isFinalPayout) {
|
|
277
277
|
counters.money.rider_revenue_amount += revenue;
|
|
278
278
|
counters.money.rider_revenue_count += 1;
|
|
279
279
|
}
|
|
@@ -295,7 +295,7 @@ function addDelivery(acc, delivery, order, key) {
|
|
|
295
295
|
row.cancelled_count += 1;
|
|
296
296
|
else if (status === delivery_1.DELIVERY_STATUS_ENUM.IN_PROGRESS)
|
|
297
297
|
row.in_progress_count += 1;
|
|
298
|
-
if (
|
|
298
|
+
if (isFinalPayout)
|
|
299
299
|
row.rider_revenue_amount += revenue;
|
|
300
300
|
row.distance_sum_meters += meters;
|
|
301
301
|
row.first_delivery_at = earlierOf(row.first_delivery_at, delivery.createdAt);
|
|
@@ -311,7 +311,7 @@ function addDelivery(acc, delivery, order, key) {
|
|
|
311
311
|
area.completed_count += 1;
|
|
312
312
|
else if (status === delivery_1.DELIVERY_STATUS_ENUM.CANCELLED)
|
|
313
313
|
area.cancelled_count += 1;
|
|
314
|
-
if (
|
|
314
|
+
if (isFinalPayout)
|
|
315
315
|
area.rider_revenue_amount += revenue;
|
|
316
316
|
area.distance_sum_meters += meters;
|
|
317
317
|
const hour = hourKeyOf(delivery);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
1
2
|
import { IMaterializedDeliveryEntry, IMaterializedTenantDeliveryEntries } from '../../schemas/types/materialized_tenant_delivery_entries';
|
|
2
3
|
import { IMaterializedDeliveryCounters, IMaterializedTenantDeliveryReport } from '../../schemas/types/materialized_tenant_delivery_reports';
|
|
3
4
|
/**
|
|
@@ -17,7 +18,7 @@ import { IMaterializedDeliveryCounters, IMaterializedTenantDeliveryReport } from
|
|
|
17
18
|
* That bug shipped once in the prep time report; it is designed out here from the start.
|
|
18
19
|
*/
|
|
19
20
|
/** Period scopes this report materializes (everything but the day scope). */
|
|
20
|
-
export declare const MATERIALIZED_DELIVERY_PERIOD_SCOPES:
|
|
21
|
+
export declare const MATERIALIZED_DELIVERY_PERIOD_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
21
22
|
/** True when the scope is the plain day scope. */
|
|
22
23
|
export declare const isMaterializedDeliveryDayScope: (scopeContext: string) => boolean;
|
|
23
24
|
/**
|
|
@@ -10,8 +10,9 @@ exports.needsMaterializedDeliveryEntriesWrite = needsMaterializedDeliveryEntries
|
|
|
10
10
|
exports.foldMaterializedDeliveryPeriodCounters = foldMaterializedDeliveryPeriodCounters;
|
|
11
11
|
exports.foldMaterializedDeliveryPeriodRows = foldMaterializedDeliveryPeriodRows;
|
|
12
12
|
exports.buildTenantDeliveryCloseDayPlan = buildTenantDeliveryCloseDayPlan;
|
|
13
|
-
const mongoose_1 = __importDefault(require("mongoose"));
|
|
14
13
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
14
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
15
|
+
const MATERIALIZED_REPORTS_2 = require("../../constants/MATERIALIZED_REPORTS");
|
|
15
16
|
const materialized_tenant_reports_iterations_helpers_1 = require("./materialized-tenant-reports-iterations-helpers");
|
|
16
17
|
const scope_helpers_1 = require("./scope-helpers");
|
|
17
18
|
const materialized_delivery_classification_helpers_1 = require("./materialized-delivery-classification-helpers");
|
|
@@ -33,9 +34,9 @@ const materialized_delivery_accumulator_helpers_1 = require("./materialized-deli
|
|
|
33
34
|
* That bug shipped once in the prep time report; it is designed out here from the start.
|
|
34
35
|
*/
|
|
35
36
|
/** Period scopes this report materializes (everything but the day scope). */
|
|
36
|
-
exports.MATERIALIZED_DELIVERY_PERIOD_SCOPES =
|
|
37
|
+
exports.MATERIALIZED_DELIVERY_PERIOD_SCOPES = MATERIALIZED_REPORTS_2.MATERIALIZED_DELIVERY_REPORT_SCOPES.filter((scope) => String(scope) !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE);
|
|
37
38
|
/** True when the scope is the plain day scope. */
|
|
38
|
-
const isMaterializedDeliveryDayScope = (scopeContext) => String(scopeContext) ===
|
|
39
|
+
const isMaterializedDeliveryDayScope = (scopeContext) => String(scopeContext) === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
39
40
|
exports.isMaterializedDeliveryDayScope = isMaterializedDeliveryDayScope;
|
|
40
41
|
const deliveryScopeKey = (doc) => String(doc.scope_context) + '|' + String(doc.scope_field);
|
|
41
42
|
/**
|
|
@@ -173,7 +174,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
173
174
|
const addWrite = (report) => {
|
|
174
175
|
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
175
176
|
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
176
|
-
reportType:
|
|
177
|
+
reportType: MATERIALIZED_REPORTS_2.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_REPORTS,
|
|
177
178
|
reason,
|
|
178
179
|
computedAt,
|
|
179
180
|
});
|
|
@@ -185,7 +186,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
185
186
|
const addEntryWrite = (report) => {
|
|
186
187
|
const persisted = report.iteration == null ? { ...report, iteration: 1 } : report;
|
|
187
188
|
const iteration = (0, materialized_tenant_reports_iterations_helpers_1.buildMaterializedTenantReportIteration)(persisted, {
|
|
188
|
-
reportType:
|
|
189
|
+
reportType: MATERIALIZED_REPORTS_2.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES,
|
|
189
190
|
reason,
|
|
190
191
|
computedAt,
|
|
191
192
|
});
|
|
@@ -298,7 +299,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
298
299
|
scope_context: scope,
|
|
299
300
|
scope_field: field,
|
|
300
301
|
day_index: null,
|
|
301
|
-
sale_type_key_filters: existing?.sale_type_key_filters ?? [...
|
|
302
|
+
sale_type_key_filters: existing?.sale_type_key_filters ?? [...MATERIALIZED_REPORTS_2.DELIVERY_KEY_FILTERS],
|
|
302
303
|
delivery_counters: counters,
|
|
303
304
|
delivery_counter_rows: counterRows,
|
|
304
305
|
iteration: existing?.iteration,
|
|
@@ -348,7 +349,7 @@ function buildTenantDeliveryCloseDayPlan(input) {
|
|
|
348
349
|
scope_context: scope,
|
|
349
350
|
scope_field: field,
|
|
350
351
|
day_index: null,
|
|
351
|
-
sale_type_key_filters: existing?.sale_type_key_filters ?? [...
|
|
352
|
+
sale_type_key_filters: existing?.sale_type_key_filters ?? [...MATERIALIZED_REPORTS_2.DELIVERY_KEY_FILTERS],
|
|
352
353
|
delivery_entries: Object.keys(sections).length === 0 ? null : sections,
|
|
353
354
|
off_app_order_count: offApp,
|
|
354
355
|
iteration: existing?.iteration,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IMaterializedTenantDeliveryEntries } from '../../schemas/types/materialized_tenant_delivery_entries';
|
|
2
2
|
import { IMaterializedTenantDeliveryReport } from '../../schemas/types/materialized_tenant_delivery_reports';
|
|
3
|
+
import { IDeliveryOrderSource, TDeliverySource } from './materialized-delivery-classification-helpers';
|
|
3
4
|
/**
|
|
4
5
|
* M4 delivery - the day compile.
|
|
5
6
|
*
|
|
@@ -21,13 +22,13 @@ export interface IDeliveryDayCompileInput {
|
|
|
21
22
|
brandId: string;
|
|
22
23
|
localDate: string;
|
|
23
24
|
/** Delivery ORDERS for the day - the adoption denominator. */
|
|
24
|
-
orders?:
|
|
25
|
+
orders?: IDeliveryOrderSource[];
|
|
25
26
|
/** Delivery DOCUMENTS for the day - the rider-app population. */
|
|
26
|
-
deliveries?:
|
|
27
|
+
deliveries?: TDeliverySource[];
|
|
27
28
|
computedAt?: Date;
|
|
28
29
|
}
|
|
29
30
|
/** The key of an ORDER - platform and city, both from the order itself. */
|
|
30
|
-
export declare function deliveryKeyOfOrder(order:
|
|
31
|
+
export declare function deliveryKeyOfOrder(order: Pick<IDeliveryOrderSource, 'platform' | 'delivery_details'>): string;
|
|
31
32
|
/**
|
|
32
33
|
* Compiles one business day into the DATE report document plus the DATE entries document.
|
|
33
34
|
*
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deliveryKeyOfOrder = deliveryKeyOfOrder;
|
|
4
4
|
exports.compileTenantDeliveryReports = compileTenantDeliveryReports;
|
|
5
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
5
6
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
7
|
+
const delivery_1 = require("../../constants/enums/delivery");
|
|
6
8
|
const materialized_tenant_delivery_entries_1 = require("../../schemas/models/materialized_tenant_delivery_entries");
|
|
7
9
|
const materialized_tenant_delivery_reports_1 = require("../../schemas/models/materialized_tenant_delivery_reports");
|
|
8
10
|
const materialized_delivery_classification_helpers_1 = require("./materialized-delivery-classification-helpers");
|
|
@@ -124,7 +126,7 @@ function compileTenantDeliveryReports(input) {
|
|
|
124
126
|
_id: undefined,
|
|
125
127
|
tenant_id: tenantId,
|
|
126
128
|
brand_id: brandId,
|
|
127
|
-
scope_context:
|
|
129
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
128
130
|
scope_field: localDate,
|
|
129
131
|
day_index: dayIndexOf(localDate),
|
|
130
132
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.DELIVERY_KEY_FILTERS],
|
|
@@ -142,7 +144,7 @@ function compileTenantDeliveryReports(input) {
|
|
|
142
144
|
_id: undefined,
|
|
143
145
|
tenant_id: tenantId,
|
|
144
146
|
brand_id: brandId,
|
|
145
|
-
scope_context:
|
|
147
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
146
148
|
scope_field: localDate,
|
|
147
149
|
day_index: dayIndexOf(localDate),
|
|
148
150
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.DELIVERY_KEY_FILTERS],
|
|
@@ -175,18 +177,14 @@ function buildEntryRow(delivery, order, details) {
|
|
|
175
177
|
status: status,
|
|
176
178
|
cancel_reason: delivery?.cancel_reason == null ? null : String(delivery.cancel_reason),
|
|
177
179
|
distance_meters: Number(delivery?.distance_in_meters_from_store) || 0,
|
|
178
|
-
rider_revenue: delivery?.rider_earnings
|
|
179
|
-
? delivery.rider_earnings.
|
|
180
|
-
|
|
181
|
-
: null
|
|
182
|
-
: delivery?.rider_revenue == null
|
|
183
|
-
? null
|
|
184
|
-
: Number(delivery.rider_revenue) || 0,
|
|
180
|
+
rider_revenue: delivery?.rider_earnings?.status === delivery_1.RIDER_EARNINGS_STATUS_ENUM.FINAL
|
|
181
|
+
? Number(delivery.rider_earnings.amount) || 0
|
|
182
|
+
: null,
|
|
185
183
|
tracking_enabled: delivery?.tracking_enabled === true,
|
|
186
184
|
has_pickup_proof: delivery?.pickup_food_image_url != null,
|
|
187
185
|
has_dropoff_proof: delivery?.dropoff_food_image_url != null,
|
|
188
186
|
polyline_point_count: Array.isArray(delivery?.polyline) ? delivery.polyline.length : 0,
|
|
189
|
-
platform: order?.platform == null ?
|
|
187
|
+
platform: order?.platform == null ? materialized_delivery_classification_helpers_1.DELIVERY_UNKNOWN_TOKEN : String(order.platform),
|
|
190
188
|
city: details?.city == null ? null : String(details.city),
|
|
191
189
|
state: details?.state == null ? null : String(details.state),
|
|
192
190
|
street: details?.street == null ? null : String(details.street),
|
|
@@ -199,7 +197,7 @@ function buildEntryRow(delivery, order, details) {
|
|
|
199
197
|
delivered_at: deliveredAt,
|
|
200
198
|
cancelled_at: delivery?.cancelled_at == null ? null : new Date(delivery.cancelled_at),
|
|
201
199
|
dispatch_lag_minutes: minutesBetween(orderCreatedAt, createdAt),
|
|
202
|
-
complete_minutes: status ===
|
|
200
|
+
complete_minutes: status === delivery_1.DELIVERY_STATUS_ENUM.COMPLETED ? minutesBetween(createdAt, completedAt) : null,
|
|
203
201
|
// The proxy is NOT exact: `updatedAt` moves on ANY later mutation, which is why the
|
|
204
202
|
// metrics capture exists. The row says which one it used.
|
|
205
203
|
completion_is_exact: exact,
|
|
@@ -214,5 +212,5 @@ function dayIndexOf(localDate) {
|
|
|
214
212
|
const date = new Date(localDate + 'T00:00:00.000Z');
|
|
215
213
|
if (Number.isNaN(date.getTime()))
|
|
216
214
|
return null;
|
|
217
|
-
return [
|
|
215
|
+
return ENUMS_1.ALL_DAY_INDEX[date.getUTCDay()] ?? null;
|
|
218
216
|
}
|
|
@@ -4,9 +4,10 @@ exports.createEmptyDiscountSlotCounter = exports.toDiscountHourLabel = void 0;
|
|
|
4
4
|
exports.accumulateOrderDiscounts = accumulateOrderDiscounts;
|
|
5
5
|
exports.mergeDiscountSlotCounters = mergeDiscountSlotCounters;
|
|
6
6
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
7
|
+
const payments_1 = require("../../constants/enums/payments");
|
|
7
8
|
const materialized_discount_classification_helpers_1 = require("./materialized-discount-classification-helpers");
|
|
8
9
|
Object.defineProperty(exports, "createEmptyDiscountSlotCounter", { enumerable: true, get: function () { return materialized_discount_classification_helpers_1.createEmptyDiscountSlotCounter; } });
|
|
9
|
-
const isComplimentaryPayment = (payment) => payment?.payment_type ===
|
|
10
|
+
const isComplimentaryPayment = (payment) => payment?.payment_type === payments_1.PAYMENT_TYPE_ENUM.COMPLIMENTARY;
|
|
10
11
|
const nonNegative = (value) => (Number.isFinite(value) && value > 0 ? value : 0);
|
|
11
12
|
/** The line label of a punch hour (null when the hour is unknown). */
|
|
12
13
|
const toDiscountHourLabel = (localDate, hour) => hour == null || hour < 0 || hour > 23 ? null : `${localDate} ${String(hour).padStart(2, '0')}`;
|
package/lib/helpers/materialized-reports/materialized-hourly-comparison-selection-helpers.js
CHANGED
|
@@ -85,7 +85,9 @@ function buildHourlyComparisonScopeGroups(selection) {
|
|
|
85
85
|
return {
|
|
86
86
|
days: [...new Set(days)].sort(),
|
|
87
87
|
hours,
|
|
88
|
-
groups: labels.length === 0
|
|
88
|
+
groups: labels.length === 0
|
|
89
|
+
? []
|
|
90
|
+
: [{ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, scope_field: labels }],
|
|
89
91
|
};
|
|
90
92
|
}
|
|
91
93
|
/**
|
|
@@ -111,6 +113,8 @@ function buildHourlyComparisonBaselineScopeGroups(selection, baseline) {
|
|
|
111
113
|
return {
|
|
112
114
|
days: [...new Set(range.days)].sort(),
|
|
113
115
|
hours,
|
|
114
|
-
groups: labels.length === 0
|
|
116
|
+
groups: labels.length === 0
|
|
117
|
+
? []
|
|
118
|
+
: [{ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, scope_field: labels }],
|
|
115
119
|
};
|
|
116
120
|
}
|
package/lib/helpers/materialized-reports/materialized-payments-comparison-accumulator-helpers.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.buildPaymentsComparisonKey = buildPaymentsComparisonKey;
|
|
|
8
8
|
exports.addPaymentToPaymentsComparisonCounters = addPaymentToPaymentsComparisonCounters;
|
|
9
9
|
exports.addPaymentsComparisonCounters = addPaymentsComparisonCounters;
|
|
10
10
|
exports.isPaymentIncluded = isPaymentIncluded;
|
|
11
|
+
const payments_1 = require("../../constants/enums/payments");
|
|
11
12
|
const key_helpers_1 = require("./key-helpers");
|
|
12
13
|
const tenant_sales_overview_helpers_1 = require("./tenant-sales-overview-helpers");
|
|
13
14
|
Object.defineProperty(exports, "getMaterializedPaymentGross", { enumerable: true, get: function () { return tenant_sales_overview_helpers_1.getMaterializedPaymentGross; } });
|
|
@@ -71,7 +72,7 @@ function addPaymentToPaymentsComparisonCounters(target, payment) {
|
|
|
71
72
|
target.card_charges += cents(payment.card_details?.card_charges);
|
|
72
73
|
if (amountRefunded > 0)
|
|
73
74
|
target.refund_count += 1;
|
|
74
|
-
if (getPaymentsComparisonMethod(payment) ===
|
|
75
|
+
if (getPaymentsComparisonMethod(payment) === payments_1.PAYMENT_TYPE_ENUM.UNPAID)
|
|
75
76
|
target.unpaid_count += 1;
|
|
76
77
|
}
|
|
77
78
|
/** Adds every counter of `source` into `target` (mutates `target`). */
|
|
@@ -17,6 +17,38 @@ import { IMaterializedPrepTimeCounters } from '../../schemas/types/materialized_
|
|
|
17
17
|
* absolute ISO timestamps.
|
|
18
18
|
*/
|
|
19
19
|
/** Context of one order's local time (mirrors the other report accumulators). */
|
|
20
|
+
/** Raw order/item fields the prep classifier reads. */
|
|
21
|
+
export interface IPrepTimeOrderSource {
|
|
22
|
+
_id: string;
|
|
23
|
+
order_number?: number | null;
|
|
24
|
+
order_status?: string | null;
|
|
25
|
+
platform?: string | null;
|
|
26
|
+
order_from?: string | null;
|
|
27
|
+
createdAt?: Date | string | null;
|
|
28
|
+
updatedAt?: Date | string | null;
|
|
29
|
+
tenant_id?: string | null;
|
|
30
|
+
localHour?: number | null;
|
|
31
|
+
staff_details?: {
|
|
32
|
+
_id?: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
} | null;
|
|
35
|
+
categories?: {
|
|
36
|
+
name?: string | null;
|
|
37
|
+
items?: {
|
|
38
|
+
_id?: string;
|
|
39
|
+
name?: string | null;
|
|
40
|
+
is_ready?: boolean;
|
|
41
|
+
ready_minutes?: number | string | null;
|
|
42
|
+
prep_started_at?: Date | string | null;
|
|
43
|
+
}[];
|
|
44
|
+
}[];
|
|
45
|
+
delivery_details?: {
|
|
46
|
+
estimated_delivery_time?: Date | string | null;
|
|
47
|
+
} | null;
|
|
48
|
+
takeaway_details?: {
|
|
49
|
+
estimated_takeaway_time?: Date | string | null;
|
|
50
|
+
} | null;
|
|
51
|
+
}
|
|
20
52
|
export interface IPrepTimeOrderContext {
|
|
21
53
|
local_date: string;
|
|
22
54
|
local_hour_label: string | null;
|
|
@@ -40,7 +72,7 @@ export declare function classifyMaterializedPrepTimeAnchor(item: {
|
|
|
40
72
|
/** A zeroed counter block. */
|
|
41
73
|
export declare function freshMaterializedPrepTimeCounters(): IMaterializedPrepTimeCounters;
|
|
42
74
|
/** The on-time target of one order, and where it came from (decision e2). */
|
|
43
|
-
export declare function resolveMaterializedPrepTimeTarget(order:
|
|
75
|
+
export declare function resolveMaterializedPrepTimeTarget(order: Pick<IPrepTimeOrderSource, 'createdAt' | 'delivery_details' | 'takeaway_details'>, tenantDefaultMinutes?: number | null): {
|
|
44
76
|
target_at: Date | null;
|
|
45
77
|
target_source: MATERIALIZED_PREP_TIME_TARGET_ENUM;
|
|
46
78
|
};
|
|
@@ -60,7 +92,7 @@ export interface IAccumulateOrderPrepTimeResult {
|
|
|
60
92
|
* and only MEASURED items with a target are graded on time.
|
|
61
93
|
*/
|
|
62
94
|
export declare function accumulateOrderPrepTime({ order, context, tenantDefaultMinutes, }: {
|
|
63
|
-
order:
|
|
95
|
+
order: IPrepTimeOrderSource;
|
|
64
96
|
context: IPrepTimeOrderContext;
|
|
65
97
|
tenantDefaultMinutes?: number | null;
|
|
66
98
|
}): IAccumulateOrderPrepTimeResult;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
1
2
|
import { IMaterializedPrepTimeEntry, IMaterializedTenantPrepTimeEntries } from '../../schemas/types/materialized_tenant_prep_time_entries';
|
|
2
3
|
import { IMaterializedPrepTimeCounters, IMaterializedTenantPrepTimeReport } from '../../schemas/types/materialized_tenant_prep_time_reports';
|
|
4
|
+
import { IMaterializedPeriodScopeFields } from './scope-helpers';
|
|
3
5
|
/**
|
|
4
6
|
* Merges a freshly compiled day of prep rows into a PERIOD document's stored
|
|
5
7
|
* rows.
|
|
@@ -49,9 +51,9 @@ export declare function needsMaterializedPrepTimeEntriesWrite(existing: IMateria
|
|
|
49
51
|
*/
|
|
50
52
|
export declare function foldMaterializedPrepTimePeriodCounters({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }: {
|
|
51
53
|
periodScopeField: string;
|
|
52
|
-
periodScope:
|
|
54
|
+
periodScope: keyof IMaterializedPeriodScopeFields;
|
|
53
55
|
dayDocuments: IMaterializedTenantPrepTimeReport[];
|
|
54
|
-
periodFieldsOfDay: (localDate: string) =>
|
|
56
|
+
periodFieldsOfDay: (localDate: string) => IMaterializedPeriodScopeFields | null;
|
|
55
57
|
}): Record<string, IMaterializedPrepTimeCounters> | null;
|
|
56
58
|
/**
|
|
57
59
|
* Folds the day documents of ONE period into that period's ENTRY rows, using the
|
|
@@ -60,14 +62,14 @@ export declare function foldMaterializedPrepTimePeriodCounters({ periodScopeFiel
|
|
|
60
62
|
*/
|
|
61
63
|
export declare function foldMaterializedPrepTimePeriodRows({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }: {
|
|
62
64
|
periodScopeField: string;
|
|
63
|
-
periodScope:
|
|
65
|
+
periodScope: keyof IMaterializedPeriodScopeFields;
|
|
64
66
|
dayDocuments: IMaterializedTenantPrepTimeEntries[];
|
|
65
|
-
periodFieldsOfDay: (localDate: string) =>
|
|
67
|
+
periodFieldsOfDay: (localDate: string) => IMaterializedPeriodScopeFields | null;
|
|
66
68
|
}): Record<string, {
|
|
67
69
|
rows: IMaterializedPrepTimeEntry[];
|
|
68
70
|
}>;
|
|
69
71
|
/** The period scope contexts (everything except the day scope). */
|
|
70
|
-
export declare const MATERIALIZED_PREP_TIME_PERIOD_SCOPES:
|
|
72
|
+
export declare const MATERIALIZED_PREP_TIME_PERIOD_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
71
73
|
/** True when a stored prep counter document equals the incoming one (skip write). */
|
|
72
74
|
export declare function needsMaterializedPrepTimeReportWrite(existing: IMaterializedTenantPrepTimeReport | null | undefined, incoming: IMaterializedTenantPrepTimeReport | null | undefined): boolean;
|
|
73
75
|
/** One planned write: the document plus its shared-history iteration row. */
|
|
@@ -33,7 +33,7 @@ const scope_helpers_1 = require("./scope-helpers");
|
|
|
33
33
|
* contribution and re-folds, so a re-close converges instead of drifting.
|
|
34
34
|
*/
|
|
35
35
|
/** Scopes written wholesale for the compiled day (no hour scope in v1). */
|
|
36
|
-
const PREP_TIME_DAY_SCOPES = [
|
|
36
|
+
const PREP_TIME_DAY_SCOPES = [MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE];
|
|
37
37
|
/** Row identity inside a period document: an order holds many items. */
|
|
38
38
|
const prepEntryRowIdentity = (row) => String(row.order_id) + '|' + String(row.entry_key);
|
|
39
39
|
/**
|
|
@@ -131,7 +131,7 @@ function needsMaterializedPrepTimeEntriesWrite(existing, incoming) {
|
|
|
131
131
|
function foldMaterializedPrepTimePeriodCounters({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }) {
|
|
132
132
|
const folded = {};
|
|
133
133
|
for (const dayDoc of dayDocuments) {
|
|
134
|
-
if (dayDoc.scope_context !==
|
|
134
|
+
if (dayDoc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
135
135
|
continue;
|
|
136
136
|
const fields = periodFieldsOfDay(String(dayDoc.scope_field));
|
|
137
137
|
if (fields == null)
|
|
@@ -153,7 +153,7 @@ function foldMaterializedPrepTimePeriodCounters({ periodScopeField, periodScope,
|
|
|
153
153
|
function foldMaterializedPrepTimePeriodRows({ periodScopeField, periodScope, dayDocuments, periodFieldsOfDay, }) {
|
|
154
154
|
const sections = {};
|
|
155
155
|
for (const dayDoc of dayDocuments) {
|
|
156
|
-
if (dayDoc.scope_context !==
|
|
156
|
+
if (dayDoc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
157
157
|
continue;
|
|
158
158
|
const fields = periodFieldsOfDay(String(dayDoc.scope_field));
|
|
159
159
|
if (fields == null)
|
|
@@ -210,7 +210,7 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
210
210
|
const computedAt = input.computedAt ?? new Date();
|
|
211
211
|
const existing = input.existing ?? [];
|
|
212
212
|
const existingEntries = input.existingEntries ?? [];
|
|
213
|
-
const dateDoc = reports.find((doc) => doc.scope_context ===
|
|
213
|
+
const dateDoc = reports.find((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE) ?? null;
|
|
214
214
|
const localDate = dateDoc?.scope_field ?? input.localDate ?? null;
|
|
215
215
|
if (typeof localDate !== 'string' || localDate.length === 0)
|
|
216
216
|
return null;
|
|
@@ -266,20 +266,20 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
266
266
|
const removedDays = [];
|
|
267
267
|
const nextDayDocs = [];
|
|
268
268
|
for (const doc of existing) {
|
|
269
|
-
if (doc.scope_context !==
|
|
269
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
270
270
|
continue;
|
|
271
271
|
if (String(doc.scope_field) === localDate)
|
|
272
272
|
continue;
|
|
273
273
|
nextDayDocs.push(doc);
|
|
274
274
|
}
|
|
275
|
-
const compiledDateDocs = reports.filter((doc) => doc.scope_context ===
|
|
275
|
+
const compiledDateDocs = reports.filter((doc) => doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE);
|
|
276
276
|
for (const doc of compiledDateDocs)
|
|
277
277
|
nextDayDocs.push(doc);
|
|
278
278
|
// ONLY THE DAY BEING CLOSED can become stale here. Every other day document is
|
|
279
279
|
// owned by ITS OWN close - treating them as stale would delete the whole history
|
|
280
280
|
// on the next close.
|
|
281
281
|
for (const doc of existing) {
|
|
282
|
-
if (doc.scope_context !==
|
|
282
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
283
283
|
continue;
|
|
284
284
|
if (String(doc.scope_field) !== localDate)
|
|
285
285
|
continue;
|
|
@@ -297,10 +297,11 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
297
297
|
if (fields == null)
|
|
298
298
|
return false;
|
|
299
299
|
for (const scope of exports.MATERIALIZED_PREP_TIME_PERIOD_SCOPES) {
|
|
300
|
-
const
|
|
300
|
+
const periodScope = scope;
|
|
301
|
+
const field = fields[periodScope];
|
|
301
302
|
if (field == null)
|
|
302
303
|
continue;
|
|
303
|
-
touchedPeriods.set(String(scope) + '|' + field, { scope:
|
|
304
|
+
touchedPeriods.set(String(scope) + '|' + field, { scope: periodScope, field });
|
|
304
305
|
}
|
|
305
306
|
return true;
|
|
306
307
|
};
|
|
@@ -393,18 +394,18 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
393
394
|
}
|
|
394
395
|
const nextDayEntries = [];
|
|
395
396
|
for (const doc of existingEntries) {
|
|
396
|
-
if (doc.scope_context !==
|
|
397
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
397
398
|
continue;
|
|
398
399
|
if (String(doc.scope_field) === localDate)
|
|
399
400
|
continue;
|
|
400
401
|
nextDayEntries.push(doc);
|
|
401
402
|
}
|
|
402
403
|
for (const doc of entries) {
|
|
403
|
-
if (doc.scope_context ===
|
|
404
|
+
if (doc.scope_context === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
404
405
|
nextDayEntries.push(doc);
|
|
405
406
|
}
|
|
406
407
|
for (const doc of existingEntries) {
|
|
407
|
-
if (doc.scope_context !==
|
|
408
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
408
409
|
continue;
|
|
409
410
|
if (String(doc.scope_field) !== localDate)
|
|
410
411
|
continue;
|
|
@@ -469,7 +470,7 @@ function buildTenantPrepTimeCloseDayPlan(input) {
|
|
|
469
470
|
return null;
|
|
470
471
|
}
|
|
471
472
|
for (const doc of entries) {
|
|
472
|
-
if (doc.scope_context !==
|
|
473
|
+
if (doc.scope_context !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE)
|
|
473
474
|
continue;
|
|
474
475
|
const existingDoc = existingEntriesByScope.get(prepScopeKey(doc)) ?? null;
|
|
475
476
|
if (existingDoc != null && !needsMaterializedPrepTimeEntriesWrite(existingDoc, doc)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IMaterializedTenantPrepTimeEntries } from '../../schemas/types/materialized_tenant_prep_time_entries';
|
|
2
2
|
import { IMaterializedPrepTimeCounters, IMaterializedTenantPrepTimeReport } from '../../schemas/types/materialized_tenant_prep_time_reports';
|
|
3
|
+
import { IPrepTimeOrderSource } from './materialized-prep-time-classification-helpers';
|
|
3
4
|
/**
|
|
4
5
|
* M2 compile - folds one tenant-day of orders into the prep time report + entries
|
|
5
6
|
* documents.
|
|
@@ -14,7 +15,7 @@ export interface ICompileTenantPrepTimeReportsInput {
|
|
|
14
15
|
tenantId: string;
|
|
15
16
|
brandId: string;
|
|
16
17
|
localDate: string;
|
|
17
|
-
orders:
|
|
18
|
+
orders: IPrepTimeOrderSource[];
|
|
18
19
|
/**
|
|
19
20
|
* Tenant default prep target in MINUTES, when the tenant has one. Absent in the
|
|
20
21
|
* dev fixtures, so it is an explicit input rather than something the compile
|
|
@@ -168,7 +168,7 @@ function compileTenantPrepTimeReports(input) {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
const docWatermark = watermark ?? sourceWatermark;
|
|
171
|
-
const isDateScoped = scopeContext ===
|
|
171
|
+
const isDateScoped = scopeContext === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
172
172
|
reports.push({
|
|
173
173
|
_id: new mongoose_1.default.Types.ObjectId().toHexString(),
|
|
174
174
|
tenant_id: tenantId,
|
|
@@ -23,10 +23,13 @@ import { IGetMaterializedReportScopeGroup } from '../types/materialized-reports-
|
|
|
23
23
|
* Returns `null` (never throws) for malformed input — `null` means the
|
|
24
24
|
* caller passed invalid data.
|
|
25
25
|
*/
|
|
26
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Window refinement kinds (see the module docblock).
|
|
28
|
+
* @deprecated use MATERIALIZED_REPORT_WINDOW_KIND_ENUM from constants.
|
|
29
|
+
*/
|
|
27
30
|
export declare const MATERIALIZED_REPORT_WINDOW_KIND: {
|
|
28
|
-
readonly RECURRING:
|
|
29
|
-
readonly SPAN:
|
|
31
|
+
readonly RECURRING: 'RECURRING';
|
|
32
|
+
readonly SPAN: 'SPAN';
|
|
30
33
|
};
|
|
31
34
|
export type TMaterializedReportWindowKind = (typeof MATERIALIZED_REPORT_WINDOW_KIND)[keyof typeof MATERIALIZED_REPORT_WINDOW_KIND];
|
|
32
35
|
export interface IMaterializedReportScopeSelectionSpec {
|
|
@@ -29,10 +29,13 @@ const materialized_reports_read_helpers_1 = require("./materialized-reports-read
|
|
|
29
29
|
* Returns `null` (never throws) for malformed input — `null` means the
|
|
30
30
|
* caller passed invalid data.
|
|
31
31
|
*/
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Window refinement kinds (see the module docblock).
|
|
34
|
+
* @deprecated use MATERIALIZED_REPORT_WINDOW_KIND_ENUM from constants.
|
|
35
|
+
*/
|
|
33
36
|
exports.MATERIALIZED_REPORT_WINDOW_KIND = {
|
|
34
|
-
RECURRING:
|
|
35
|
-
SPAN:
|
|
37
|
+
RECURRING: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
38
|
+
SPAN: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN,
|
|
36
39
|
};
|
|
37
40
|
/* ------------------------------------------------------------------------ */
|
|
38
41
|
/* Date-key math (UTC — keys are timezone-less) */
|
|
@@ -207,7 +210,7 @@ function buildMaterializedReportScopeGroups(spec) {
|
|
|
207
210
|
const uniqueDates = dayKeys.map((key) => keyToDate(key));
|
|
208
211
|
// A SPAN window reads the CONTINUOUS interval first-day → last-day — a day
|
|
209
212
|
// set with gaps would silently pull the gap days in as full middle days.
|
|
210
|
-
if (window != null && window.kind ===
|
|
213
|
+
if (window != null && window.kind === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN) {
|
|
211
214
|
for (let index = 1; index < uniqueDates.length; index += 1) {
|
|
212
215
|
if (daysBetween(uniqueDates[index - 1], uniqueDates[index]) !== 1) {
|
|
213
216
|
return null;
|
|
@@ -222,7 +225,7 @@ function buildMaterializedReportScopeGroups(spec) {
|
|
|
222
225
|
if (!isValidHour(fromHour, 23) || !isValidHour(toHour, 23))
|
|
223
226
|
return null;
|
|
224
227
|
// Recurring: the same hours on every selected day.
|
|
225
|
-
if (kind ===
|
|
228
|
+
if (kind === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING) {
|
|
226
229
|
const labels = (0, materialized_reports_read_helpers_1.getMaterializedHourWindowScopeFields)(dayKeys, fromHour, toHour);
|
|
227
230
|
return labels == null ? null : [{ scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR, scope_field: labels }];
|
|
228
231
|
}
|
|
@@ -667,8 +667,8 @@ const decodeMaterializedReportScopeGroups = (selection) => {
|
|
|
667
667
|
// never compile it. Weekday + window therefore always compiles
|
|
668
668
|
// RECURRING (the same hours on each matching weekday).
|
|
669
669
|
kind: SPAN_VIEWS.has(view) && weekdayFilter == null
|
|
670
|
-
?
|
|
671
|
-
:
|
|
670
|
+
? MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN
|
|
671
|
+
: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
672
672
|
},
|
|
673
673
|
}
|
|
674
674
|
: {}),
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSalesComparisonBaselineRange = getSalesComparisonBaselineRange;
|
|
4
4
|
exports.buildSalesComparisonBaselineScopeGroups = buildSalesComparisonBaselineScopeGroups;
|
|
5
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
5
6
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
6
7
|
const materialized_reports_scope_group_helpers_1 = require("./materialized-reports-scope-group-helpers");
|
|
7
8
|
const materialized_reports_selection_helpers_1 = require("./materialized-reports-selection-helpers");
|
|
@@ -61,11 +62,9 @@ const shiftKeyOneYearBack = (key) => {
|
|
|
61
62
|
const day = Math.min(date.getUTCDate(), lastDayOfMonth);
|
|
62
63
|
return utcDateToKey(new Date(Date.UTC(year, month, day)));
|
|
63
64
|
};
|
|
64
|
-
// `DAY_INDEX_ENUM` values are the three-letter keys (`MON`), not full names.
|
|
65
|
-
const DAY_INDEX_KEYS = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
|
|
66
65
|
const dayIndexKeyOf = (key) => {
|
|
67
66
|
const date = keyToUtcDate(key);
|
|
68
|
-
return date == null ? null : (
|
|
67
|
+
return date == null ? null : (ENUMS_1.ALL_DAY_INDEX[date.getUTCDay()] ?? null);
|
|
69
68
|
};
|
|
70
69
|
/** `'HH:mm'` → whole hour, or null (mirrors the decoder's whole-hour rule). */
|
|
71
70
|
const hourOf = (time) => {
|
|
@@ -154,7 +153,7 @@ function buildSalesComparisonBaselineScopeGroups(selection, baseline) {
|
|
|
154
153
|
spec.window = {
|
|
155
154
|
fromHour: fromHour,
|
|
156
155
|
toHour: toHour,
|
|
157
|
-
kind: span ?
|
|
156
|
+
kind: span ? MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.SPAN : MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_WINDOW_KIND_ENUM.RECURRING,
|
|
158
157
|
};
|
|
159
158
|
}
|
|
160
159
|
return (0, materialized_reports_scope_group_helpers_1.buildMaterializedReportScopeGroups)(spec);
|