@managesome/eposmatic-toolkit 0.4.10 → 0.4.11
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 -2
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +3 -2
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +10 -8
- 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 -2
- package/esm/helpers/store/common-order-actions.js +3 -2
- package/esm/schemas/models/deliveries.js +11 -5
- package/esm/schemas/models/materialized_credit_bills.js +1 -1
- 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 +32 -3
- package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +5 -1
- 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 +8 -6
- 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 -2
- package/lib/helpers/rider-reports/rider-daily-report.js +1 -1
- package/lib/helpers/store/common-order-actions.js +3 -2
- package/lib/helpers/types/materialized-reports-apis.d.ts +3 -0
- package/lib/schemas/models/deliveries.d.ts +10 -7
- package/lib/schemas/models/deliveries.js +10 -4
- 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_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 +2 -2
- 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 +70 -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-compile.test.js +7 -6
- package/lib/tests/materialized-reports/materialized-delivery-formatter.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 -3
- package/package.json +1 -1
|
@@ -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],
|
|
@@ -176,7 +178,7 @@ function buildEntryRow(delivery, order, details) {
|
|
|
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
180
|
rider_revenue: delivery?.rider_earnings != null
|
|
179
|
-
? delivery.rider_earnings.status ===
|
|
181
|
+
? delivery.rider_earnings.status === delivery_1.RIDER_EARNINGS_STATUS_ENUM.FINAL
|
|
180
182
|
? Number(delivery.rider_earnings.amount) || 0
|
|
181
183
|
: null
|
|
182
184
|
: delivery?.rider_revenue == null
|
|
@@ -186,7 +188,7 @@ function buildEntryRow(delivery, order, details) {
|
|
|
186
188
|
has_pickup_proof: delivery?.pickup_food_image_url != null,
|
|
187
189
|
has_dropoff_proof: delivery?.dropoff_food_image_url != null,
|
|
188
190
|
polyline_point_count: Array.isArray(delivery?.polyline) ? delivery.polyline.length : 0,
|
|
189
|
-
platform: order?.platform == null ?
|
|
191
|
+
platform: order?.platform == null ? materialized_delivery_classification_helpers_1.DELIVERY_UNKNOWN_TOKEN : String(order.platform),
|
|
190
192
|
city: details?.city == null ? null : String(details.city),
|
|
191
193
|
state: details?.state == null ? null : String(details.state),
|
|
192
194
|
street: details?.street == null ? null : String(details.street),
|
|
@@ -199,7 +201,7 @@ function buildEntryRow(delivery, order, details) {
|
|
|
199
201
|
delivered_at: deliveredAt,
|
|
200
202
|
cancelled_at: delivery?.cancelled_at == null ? null : new Date(delivery.cancelled_at),
|
|
201
203
|
dispatch_lag_minutes: minutesBetween(orderCreatedAt, createdAt),
|
|
202
|
-
complete_minutes: status ===
|
|
204
|
+
complete_minutes: status === delivery_1.DELIVERY_STATUS_ENUM.COMPLETED ? minutesBetween(createdAt, completedAt) : null,
|
|
203
205
|
// The proxy is NOT exact: `updatedAt` moves on ANY later mutation, which is why the
|
|
204
206
|
// metrics capture exists. The row says which one it used.
|
|
205
207
|
completion_is_exact: exact,
|
|
@@ -214,5 +216,5 @@ function dayIndexOf(localDate) {
|
|
|
214
216
|
const date = new Date(localDate + 'T00:00:00.000Z');
|
|
215
217
|
if (Number.isNaN(date.getTime()))
|
|
216
218
|
return null;
|
|
217
|
-
return [
|
|
219
|
+
return ENUMS_1.ALL_DAY_INDEX[date.getUTCDay()] ?? null;
|
|
218
220
|
}
|
|
@@ -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);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFormattedTenantCashInOutReporting = getFormattedTenantCashInOutReporting;
|
|
4
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
5
|
const price_conversion_1 = require("../utils/price-conversion");
|
|
5
6
|
const materialized_cash_compile_helpers_1 = require("./materialized-cash-compile-helpers");
|
|
6
7
|
const materialized_cash_classification_helpers_1 = require("./materialized-cash-classification-helpers");
|
|
7
8
|
const materialized_cash_accumulator_helpers_1 = require("./materialized-cash-accumulator-helpers");
|
|
8
9
|
const toDecimal = (cents) => (0, price_conversion_1.convertPriceFromCents)(cents ?? 0);
|
|
9
|
-
const isDayScope = (scopeContext) => String(scopeContext) ===
|
|
10
|
+
const isDayScope = (scopeContext) => String(scopeContext) === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
10
11
|
/** True when a key passes the caller-supplied drawer / ref-type filters. */
|
|
11
12
|
function keyPassesFilters(key, filters) {
|
|
12
13
|
const parsed = (0, materialized_cash_compile_helpers_1.parseMaterializedCashKey)(key);
|
|
@@ -8,7 +8,7 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
|
8
8
|
const toDecimal = (cents) => (0, price_conversion_1.convertPriceFromCents)(cents ?? 0);
|
|
9
9
|
const km = (meters) => Math.round(((meters ?? 0) / 1000) * 100) / 100;
|
|
10
10
|
const safeAverage = (total, count) => count > 0 ? Math.round((total / count) * 100) / 100 : null;
|
|
11
|
-
const isDayScope = (scopeContext) => String(scopeContext) ===
|
|
11
|
+
const isDayScope = (scopeContext) => String(scopeContext) === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
12
12
|
/** True when a key passes the caller-supplied platform / city filters. */
|
|
13
13
|
function keyPassesFilters(key, filters) {
|
|
14
14
|
const parsed = (0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)(key);
|
|
@@ -63,7 +63,7 @@ const isCancelledKey = (components, keyFilters) => {
|
|
|
63
63
|
const statusIndex = keyFilters.indexOf(MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS);
|
|
64
64
|
if (statusIndex === -1)
|
|
65
65
|
return false;
|
|
66
|
-
return components[statusIndex] ===
|
|
66
|
+
return components[statusIndex] === ENUMS_1.ORDER_STATUS_ENUM.CANCELLED;
|
|
67
67
|
};
|
|
68
68
|
const emptyScopeAccumulator = () => ({
|
|
69
69
|
summary: {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getHourlyComparisonBusinessIndex = exports.getHourlyComparisonHourLabel = void 0;
|
|
4
4
|
exports.getFormattedTenantHourlyComparisonReporting = getFormattedTenantHourlyComparisonReporting;
|
|
5
5
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
6
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
6
7
|
const tenant_sales_comparison_formatter_1 = require("./tenant-sales-comparison-formatter");
|
|
7
8
|
const materialized_sales_comparison_accumulator_helpers_1 = require("./materialized-sales-comparison-accumulator-helpers");
|
|
8
9
|
const key_helpers_1 = require("./key-helpers");
|
|
@@ -57,8 +58,8 @@ exports.getHourlyComparisonHourLabel = getHourlyComparisonHourLabel;
|
|
|
57
58
|
/** Business-hour index: 06 → 0, …, 23 → 17, 00 → 18, …, 05 → 23. */
|
|
58
59
|
const getHourlyComparisonBusinessIndex = (hour) => (hour + 18) % 24;
|
|
59
60
|
exports.getHourlyComparisonBusinessIndex = getHourlyComparisonBusinessIndex;
|
|
60
|
-
const isCancelled = (status) => status ===
|
|
61
|
-
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(
|
|
61
|
+
const isCancelled = (status) => status === ENUMS_1.ORDER_STATUS_ENUM.CANCELLED;
|
|
62
|
+
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(ENUMS_1.ORDER_STATUS_ENUM.CANCELLED);
|
|
62
63
|
const parseKey = (key, keyFilters) => {
|
|
63
64
|
const components = (0, key_helpers_1.parseMaterializedReportKey)(key);
|
|
64
65
|
if (components == null || components.length !== keyFilters.length)
|
|
@@ -4,8 +4,11 @@ exports.formatPaymentsComparisonSeries = exports.createEmptyPaymentsComparisonFo
|
|
|
4
4
|
exports.buildPaymentsComparisonMetrics = buildPaymentsComparisonMetrics;
|
|
5
5
|
exports.getFormattedTenantPaymentsComparisonReporting = getFormattedTenantPaymentsComparisonReporting;
|
|
6
6
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
7
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
7
8
|
const key_helpers_1 = require("./key-helpers");
|
|
8
9
|
const price_conversion_1 = require("../utils/price-conversion");
|
|
10
|
+
const matchedDocumentsOf = (doc) => ('matched_documents' in doc ? doc.matched_documents : 1);
|
|
11
|
+
const updatedAtOf = (doc) => 'max_updated_at' in doc ? doc.max_updated_at : doc.updatedAt;
|
|
9
12
|
const METRICS = [
|
|
10
13
|
MATERIALIZED_REPORTS_1.PAYMENTS_COMPARISON_METRIC_ENUM.PAYMENT_AMOUNT,
|
|
11
14
|
MATERIALIZED_REPORTS_1.PAYMENTS_COMPARISON_METRIC_ENUM.PAYMENT_COUNT,
|
|
@@ -99,8 +102,8 @@ const parseKey = (key, keyFilters) => {
|
|
|
99
102
|
}
|
|
100
103
|
return { payment_method: paymentMethod, order_status: orderStatus };
|
|
101
104
|
};
|
|
102
|
-
const isCancelled = (orderStatus) => orderStatus ===
|
|
103
|
-
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(
|
|
105
|
+
const isCancelled = (orderStatus) => orderStatus === ENUMS_1.ORDER_STATUS_ENUM.CANCELLED;
|
|
106
|
+
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(ENUMS_1.ORDER_STATUS_ENUM.CANCELLED);
|
|
104
107
|
const matchesFilters = (parsed, filters) => {
|
|
105
108
|
if (filters.payment_methods != null &&
|
|
106
109
|
filters.payment_methods.length > 0 &&
|
|
@@ -126,8 +129,8 @@ const buildPage = (group, filters) => {
|
|
|
126
129
|
for (const doc of docs ?? []) {
|
|
127
130
|
if (doc == null)
|
|
128
131
|
continue;
|
|
129
|
-
matchedDocuments +=
|
|
130
|
-
const updatedAt = doc
|
|
132
|
+
matchedDocuments += matchedDocumentsOf(doc);
|
|
133
|
+
const updatedAt = updatedAtOf(doc);
|
|
131
134
|
if (updatedAt != null) {
|
|
132
135
|
const date = new Date(updatedAt);
|
|
133
136
|
if (!Number.isNaN(date.getTime()) && (maxUpdatedAt == null || date.getTime() > maxUpdatedAt.getTime())) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IMaterializedTenantPrepTimeAggregatedReport } from '../types/materialized-reports-apis';
|
|
1
2
|
import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
|
|
2
3
|
import { IMaterializedTenantPrepTimeReport } from '../../schemas/types/materialized_tenant_prep_time_reports';
|
|
3
4
|
/**
|
|
@@ -94,4 +95,4 @@ export declare function getFormattedTenantPrepTimeReporting(reports: IMaterializ
|
|
|
94
95
|
* `weekday` therefore comes back null and a weekday filter is REFUSED rather than
|
|
95
96
|
* silently ignored (returning every weekday would be a wrong answer).
|
|
96
97
|
*/
|
|
97
|
-
export declare function getFormattedTenantPrepTimeAggregatedReporting(reports:
|
|
98
|
+
export declare function getFormattedTenantPrepTimeAggregatedReporting(reports: IMaterializedTenantPrepTimeAggregatedReport[], filters?: IFormattedPrepTimeFilters | null, separate_view_per_tenant?: boolean): [IFormattedPrepTimePageData[], null] | null;
|