@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
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, SALES_COMPARISON_METRIC_ENUM, } from '../../constants/MATERIALIZED_REPORTS';
|
|
2
|
+
import { ORDER_STATUS_ENUM } from '../../constants/ENUMS';
|
|
2
3
|
import { parseMaterializedReportKey } from './key-helpers';
|
|
3
4
|
import { convertPriceFromCents } from '../utils/price-conversion';
|
|
5
|
+
const matchedDocumentsOf = (doc) => 'matched_documents' in doc ? doc.matched_documents : 1;
|
|
6
|
+
const updatedAtOf = (doc) => 'max_updated_at' in doc ? doc.max_updated_at : doc.updatedAt;
|
|
4
7
|
const ALL_METRICS = [
|
|
5
8
|
SALES_COMPARISON_METRIC_ENUM.NET_SALES,
|
|
6
9
|
SALES_COMPARISON_METRIC_ENUM.GROSS_SALES,
|
|
@@ -135,9 +138,9 @@ const parseKey = (key, keyFilters) => {
|
|
|
135
138
|
}
|
|
136
139
|
return { order_status: orderStatus, platform };
|
|
137
140
|
};
|
|
138
|
-
const isCancelled = (orderStatus) => orderStatus ===
|
|
141
|
+
const isCancelled = (orderStatus) => orderStatus === ORDER_STATUS_ENUM.CANCELLED;
|
|
139
142
|
/** True when a filter list explicitly asks for `CANCELLED`. */
|
|
140
|
-
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(
|
|
143
|
+
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(ORDER_STATUS_ENUM.CANCELLED);
|
|
141
144
|
const foldDocs = (docs, filters, target) => {
|
|
142
145
|
for (const doc of docs ?? []) {
|
|
143
146
|
if (doc == null || doc.sales_counters == null)
|
|
@@ -183,7 +186,7 @@ const buildGroup = (tenantIds, currentDocs, comparisonDocs, filters) => {
|
|
|
183
186
|
comparisonCancelled: createRawCounters(),
|
|
184
187
|
hasComparisonDocuments,
|
|
185
188
|
includeCancelledInTotals: includesCancelled(filters),
|
|
186
|
-
matchedDocuments: currentDocs.reduce((sum, doc) => sum + (
|
|
189
|
+
matchedDocuments: currentDocs.reduce((sum, doc) => sum + matchedDocumentsOf(doc), 0),
|
|
187
190
|
tenantIds: new Set(tenantIds),
|
|
188
191
|
};
|
|
189
192
|
const includeCancelledInTotals = group.includeCancelledInTotals;
|
|
@@ -236,7 +239,7 @@ const buildPage = (group, filters) => {
|
|
|
236
239
|
continue;
|
|
237
240
|
// The platform breakdown must reconcile with the page's total: cancelled
|
|
238
241
|
// revenue is excluded there unless the filter explicitly asked for it.
|
|
239
|
-
if (row.order_status ===
|
|
242
|
+
if (row.order_status === ORDER_STATUS_ENUM.CANCELLED && !group.includeCancelledInTotals)
|
|
240
243
|
continue;
|
|
241
244
|
const existing = platformRows.get(row.platform) ?? {
|
|
242
245
|
platform: row.platform,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ORDER_STATUS_ENUM } from '../../constants/ENUMS';
|
|
1
2
|
import { parseMaterializedReportKey } from '../materialized-reports/key-helpers';
|
|
2
3
|
const emptySummary = () => ({
|
|
3
4
|
order_count: 0,
|
|
@@ -29,7 +30,7 @@ export function normalizeOverviewAggregatedRecord(record) {
|
|
|
29
30
|
continue;
|
|
30
31
|
const [status, platform] = components;
|
|
31
32
|
const orderMetric = metric?.TOTAL_SALES?.orders;
|
|
32
|
-
if (status ===
|
|
33
|
+
if (status === ORDER_STATUS_ENUM.CANCELLED) {
|
|
33
34
|
summary.cancelled_order_count += Number(orderMetric?.count ?? 0);
|
|
34
35
|
continue;
|
|
35
36
|
}
|
|
@@ -81,9 +82,9 @@ export function normalizeOverviewAggregatedRecord(record) {
|
|
|
81
82
|
export function normalizeOverviewAggregatedShape(record) {
|
|
82
83
|
const metrics = {};
|
|
83
84
|
for (const [key, metric] of Object.entries(record.sale_type_metrics ?? {})) {
|
|
84
|
-
const total = metric
|
|
85
|
-
const collected = metric
|
|
86
|
-
const credit = metric
|
|
85
|
+
const total = metric.TOTAL_SALES;
|
|
86
|
+
const collected = metric.AMOUNT_COLLECTED;
|
|
87
|
+
const credit = metric.CREDIT_BILLS;
|
|
87
88
|
const issued = credit.issued ?? {};
|
|
88
89
|
const received = credit.received ?? {};
|
|
89
90
|
metrics[key] = {
|
|
@@ -51,9 +51,3 @@ export function calculateRiderFee(input) {
|
|
|
51
51
|
delivery_charge_cents: deliveryCharge,
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
/** Status written on a newly created delivery; amount is not final yet. */
|
|
55
|
-
export const RIDER_EARNINGS_STATUS = {
|
|
56
|
-
PENDING: 'PENDING',
|
|
57
|
-
FINAL: 'FINAL',
|
|
58
|
-
VOID: 'VOID',
|
|
59
|
-
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DELIVERY_STATUS_ENUM } from '../../constants/enums/delivery';
|
|
1
|
+
import { DELIVERY_STATUS_ENUM, RIDER_EARNINGS_STATUS_ENUM } from '../../constants/enums/delivery';
|
|
2
2
|
import { MATERIALIZED_RIDER_DAILY_REPORTS_SCHEMA_VERSION } from '../../schemas/models/materialized_rider_daily_reports';
|
|
3
3
|
const completedOrCancelled = (status) => status === DELIVERY_STATUS_ENUM.COMPLETED || status === DELIVERY_STATUS_ENUM.CANCELLED;
|
|
4
4
|
const finalEarnings = (delivery) => {
|
|
5
5
|
const earnings = delivery.rider_earnings;
|
|
6
6
|
if (earnings != null) {
|
|
7
|
-
return earnings.status ===
|
|
7
|
+
return earnings.status === RIDER_EARNINGS_STATUS_ENUM.FINAL ? Number(earnings.amount) || 0 : 0;
|
|
8
8
|
}
|
|
9
9
|
return Number(delivery.rider_revenue) || 0;
|
|
10
10
|
};
|
|
@@ -313,9 +313,10 @@ export function generateOrderIteration(order, partial = true, skipItemMetadata,
|
|
|
313
313
|
};
|
|
314
314
|
if (partial) {
|
|
315
315
|
// delete all undefined keys
|
|
316
|
+
const mutable = iteration;
|
|
316
317
|
Object.keys(iteration).forEach((key) => {
|
|
317
|
-
if (
|
|
318
|
-
delete
|
|
318
|
+
if (mutable[key] === undefined) {
|
|
319
|
+
delete mutable[key];
|
|
319
320
|
}
|
|
320
321
|
});
|
|
321
322
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
import { ALL_CURRENCY_SYMBOLS, ALL_DELIVERY_STATUS, CURRENCY_SYMBOL_ENUM, DELIVERY_STATUS_ENUM } from '../../constants';
|
|
2
|
+
import { ALL_CURRENCY_SYMBOLS, ALL_DELIVERY_STATUS, ALL_RIDER_EARNINGS_STATUS, ALL_RIDER_FEE_TYPES, CURRENCY_SYMBOL_ENUM, DELIVERY_STATUS_ENUM, RIDER_EARNINGS_STATUS_ENUM, RIDER_FEE_TYPE_ENUM, } from '../../constants';
|
|
3
3
|
export const DeliveriesSchema = new Schema({
|
|
4
4
|
_id: {
|
|
5
5
|
type: Schema.Types.ObjectId,
|
|
@@ -64,6 +64,12 @@ export const DeliveriesSchema = new Schema({
|
|
|
64
64
|
type: String,
|
|
65
65
|
required: false,
|
|
66
66
|
},
|
|
67
|
+
/** Tenant-local business date, copied from the order at creation. */
|
|
68
|
+
localDate: {
|
|
69
|
+
type: String,
|
|
70
|
+
required: false,
|
|
71
|
+
default: null,
|
|
72
|
+
},
|
|
67
73
|
polyline: {
|
|
68
74
|
type: [[Number, Number]],
|
|
69
75
|
required: true,
|
|
@@ -146,14 +152,14 @@ export const DeliveriesSchema = new Schema({
|
|
|
146
152
|
status: {
|
|
147
153
|
type: String,
|
|
148
154
|
required: true,
|
|
149
|
-
enum:
|
|
150
|
-
default:
|
|
155
|
+
enum: ALL_RIDER_EARNINGS_STATUS,
|
|
156
|
+
default: RIDER_EARNINGS_STATUS_ENUM.PENDING,
|
|
151
157
|
},
|
|
152
158
|
rule_type: {
|
|
153
159
|
type: String,
|
|
154
160
|
required: true,
|
|
155
|
-
enum:
|
|
156
|
-
default:
|
|
161
|
+
enum: ALL_RIDER_FEE_TYPES,
|
|
162
|
+
default: RIDER_FEE_TYPE_ENUM.NONE,
|
|
157
163
|
},
|
|
158
164
|
per_meter: { type: Number, required: true, min: 0, default: 0 },
|
|
159
165
|
distance_step: { type: Number, required: true, min: 0, default: 0 },
|
|
@@ -223,7 +223,7 @@ export const MaterializedTenantSalesOverviewReportSchema = new Schema({
|
|
|
223
223
|
// all-time accumulator document (see MATERIALIZED_REPORTS.md).
|
|
224
224
|
day_index: {
|
|
225
225
|
type: String,
|
|
226
|
-
enum: ALL_DAY_INDEX,
|
|
226
|
+
enum: [...ALL_DAY_INDEX, null],
|
|
227
227
|
default: null,
|
|
228
228
|
},
|
|
229
229
|
sale_type_key_filters: {
|
|
@@ -51,6 +51,12 @@ export declare enum MATERIALIZED_REPORT_SCOPE_ENUM {
|
|
|
51
51
|
LOCAL_YEAR = "localYear"
|
|
52
52
|
}
|
|
53
53
|
export declare const ALL_MATERIALIZED_REPORT_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
54
|
+
/** Time-window refinement used when compiling/reading a report scope. */
|
|
55
|
+
export declare enum MATERIALIZED_REPORT_WINDOW_KIND_ENUM {
|
|
56
|
+
RECURRING = "RECURRING",
|
|
57
|
+
SPAN = "SPAN"
|
|
58
|
+
}
|
|
59
|
+
export declare const ALL_MATERIALIZED_REPORT_WINDOW_KINDS: MATERIALIZED_REPORT_WINDOW_KIND_ENUM[];
|
|
54
60
|
/**
|
|
55
61
|
* Scopes whose documents carry the denormalized `day_index` weekday field
|
|
56
62
|
* (derived from `scope_field` by the materializer, `DAY_INDEX_ENUM`). All
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* explicitly-enabled step.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
14
|
-
exports.ALL_PAYMENTS_COMPARISON_METRICS = exports.PAYMENTS_COMPARISON_METRIC_ENUM = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_SCHEMA_VERSION = exports.PAYMENTS_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_PAYMENTS_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION = exports.HOURLY_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_HOURLY_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_COLLECTION_NAME = exports.ALL_SALES_COMPARISON_METRICS = exports.SALES_COMPARISON_METRIC_ENUM = exports.ALL_SALES_COMPARISON_BASELINES = exports.SALES_COMPARISON_BASELINE_ENUM = exports.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_SCHEMA_VERSION = void 0;
|
|
13
|
+
exports.MATERIALIZED_SALES_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_NAME = exports.ALL_MATERIALIZED_REPORT_TYPES = exports.MATERIALIZED_REPORT_TYPE_ENUM = exports.ALL_MATERIALIZED_PREP_TIME_TARGETS = exports.MATERIALIZED_PREP_TIME_TARGET_ENUM = exports.MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA = exports.MATERIALIZED_PREP_TIME_TOP_BUCKET = exports.MATERIALIZED_PREP_TIME_MAX_MINUTES = exports.ALL_MATERIALIZED_PREP_TIME_BUCKET_LABELS = exports.MATERIALIZED_PREP_TIME_BUCKETS = exports.ALL_MATERIALIZED_PREP_TIME_ANCHORS = exports.MATERIALIZED_PREP_TIME_ANCHOR_ENUM = exports.PREP_TIME_KEY_FILTERS = exports.MATERIALIZED_PREP_TIME_REPORT_SCOPES = exports.MATERIALIZED_DELIVERY_AREA_LIMIT = exports.MATERIALIZED_DELIVERY_RIDER_LIMIT = exports.MATERIALIZED_DELIVERY_DISTANCE_BUCKETS = exports.DELIVERY_KEY_FILTERS = exports.MATERIALIZED_DELIVERY_REPORT_SCOPES = exports.MATERIALIZED_CASH_SOURCE_LIMIT = exports.CASH_KEY_FILTERS = exports.MATERIALIZED_CASH_REPORT_SCOPES = exports.ALL_MATERIALIZED_REPORT_CREDIT_BILL_EVENT_TYPES = exports.MATERIALIZED_REPORT_CREDIT_BILL_EVENT_TYPE_ENUM = exports.MATERIALIZED_CREDIT_SETTLEMENT_PAYMENT_TYPE = exports.MATERIALIZED_DISCOUNT_PRICE_OVERRIDE_PREFIX = exports.MATERIALIZED_DISCOUNT_MANUAL_PREFIX = exports.MATERIALIZED_DISCOUNT_SPECIAL_DISCOUNT_ID = exports.MATERIALIZED_DISCOUNT_SOURCE_LIMIT = exports.ALL_MATERIALIZED_DISCOUNT_LEVELS = exports.MATERIALIZED_DISCOUNT_LEVEL_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_ENTRY_KINDS = exports.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SUB_KINDS = exports.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SLOTS = exports.MATERIALIZED_DISCOUNT_SLOT_ENUM = exports.DISCOUNTS_KEY_FILTERS = exports.MATERIALIZED_DISCOUNT_REPORT_SCOPES = exports.SALES_OVERVIEW_KEY_FILTERS = exports.ALL_MATERIALIZED_REPORT_KEY_FILTERS = exports.MATERIALIZED_REPORT_KEY_FILTER_ENUM = exports.MATERIALIZED_CREDIT_BILLS_SCOPES = exports.MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX = exports.ALL_MATERIALIZED_REPORT_WINDOW_KINDS = exports.MATERIALIZED_REPORT_WINDOW_KIND_ENUM = exports.ALL_MATERIALIZED_REPORT_SCOPES = exports.MATERIALIZED_REPORT_SCOPE_ENUM = void 0;
|
|
14
|
+
exports.ALL_PAYMENTS_COMPARISON_METRICS = exports.PAYMENTS_COMPARISON_METRIC_ENUM = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_SCHEMA_VERSION = exports.PAYMENTS_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_PAYMENTS_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION = exports.HOURLY_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_HOURLY_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_COLLECTION_NAME = exports.ALL_SALES_COMPARISON_METRICS = exports.SALES_COMPARISON_METRIC_ENUM = exports.ALL_SALES_COMPARISON_BASELINES = exports.SALES_COMPARISON_BASELINE_ENUM = exports.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_SCHEMA_VERSION = exports.SALES_COMPARISON_KEY_FILTERS = void 0;
|
|
15
15
|
/**
|
|
16
16
|
* Time-scope of a materialized report document. Every document covers exactly
|
|
17
17
|
* one tenant × one scope context × one scope value (`scope_field`), and the
|
|
@@ -56,6 +56,13 @@ var MATERIALIZED_REPORT_SCOPE_ENUM;
|
|
|
56
56
|
MATERIALIZED_REPORT_SCOPE_ENUM["LOCAL_YEAR"] = "localYear";
|
|
57
57
|
})(MATERIALIZED_REPORT_SCOPE_ENUM || (exports.MATERIALIZED_REPORT_SCOPE_ENUM = MATERIALIZED_REPORT_SCOPE_ENUM = {}));
|
|
58
58
|
exports.ALL_MATERIALIZED_REPORT_SCOPES = Object.values(MATERIALIZED_REPORT_SCOPE_ENUM);
|
|
59
|
+
/** Time-window refinement used when compiling/reading a report scope. */
|
|
60
|
+
var MATERIALIZED_REPORT_WINDOW_KIND_ENUM;
|
|
61
|
+
(function (MATERIALIZED_REPORT_WINDOW_KIND_ENUM) {
|
|
62
|
+
MATERIALIZED_REPORT_WINDOW_KIND_ENUM["RECURRING"] = "RECURRING";
|
|
63
|
+
MATERIALIZED_REPORT_WINDOW_KIND_ENUM["SPAN"] = "SPAN";
|
|
64
|
+
})(MATERIALIZED_REPORT_WINDOW_KIND_ENUM || (exports.MATERIALIZED_REPORT_WINDOW_KIND_ENUM = MATERIALIZED_REPORT_WINDOW_KIND_ENUM = {}));
|
|
65
|
+
exports.ALL_MATERIALIZED_REPORT_WINDOW_KINDS = Object.values(MATERIALIZED_REPORT_WINDOW_KIND_ENUM);
|
|
59
66
|
/**
|
|
60
67
|
* Scopes whose documents carry the denormalized `day_index` weekday field
|
|
61
68
|
* (derived from `scope_field` by the materializer, `DAY_INDEX_ENUM`). All
|
|
@@ -16,6 +16,13 @@ export declare enum RIDER_FEE_TYPE_ENUM {
|
|
|
16
16
|
DISTANCE_RETURN = "DISTANCE_RETURN"
|
|
17
17
|
}
|
|
18
18
|
export declare const ALL_RIDER_FEE_TYPES: RIDER_FEE_TYPE_ENUM[];
|
|
19
|
+
/** Server-owned rider payout lifecycle. */
|
|
20
|
+
export declare enum RIDER_EARNINGS_STATUS_ENUM {
|
|
21
|
+
PENDING = "PENDING",
|
|
22
|
+
FINAL = "FINAL",
|
|
23
|
+
VOID = "VOID"
|
|
24
|
+
}
|
|
25
|
+
export declare const ALL_RIDER_EARNINGS_STATUS: RIDER_EARNINGS_STATUS_ENUM[];
|
|
19
26
|
export declare enum DELIVERY_STATUS_ENUM {
|
|
20
27
|
PENDING = "PENDING",
|
|
21
28
|
ASSIGNED = "ASSIGNED",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Auto-split from constants/ENUMS.ts — see ENUMS.ts barrel for exports.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ALL_DELIVERY_STATUS = exports.DELIVERY_STATUS_ENUM = exports.ALL_RIDER_FEE_TYPES = exports.RIDER_FEE_TYPE_ENUM = exports.ALL_DELIVERY_AREAS_SEARCH_TYPES = exports.DELIVERY_AREAS_SEARCH_TYPE_ENUM = exports.ALL_RESERVATION_STATUS_TYPES = exports.RESERVATION_STATUS_ENUM = void 0;
|
|
4
|
+
exports.ALL_DELIVERY_STATUS = exports.DELIVERY_STATUS_ENUM = exports.ALL_RIDER_EARNINGS_STATUS = exports.RIDER_EARNINGS_STATUS_ENUM = exports.ALL_RIDER_FEE_TYPES = exports.RIDER_FEE_TYPE_ENUM = exports.ALL_DELIVERY_AREAS_SEARCH_TYPES = exports.DELIVERY_AREAS_SEARCH_TYPE_ENUM = exports.ALL_RESERVATION_STATUS_TYPES = exports.RESERVATION_STATUS_ENUM = void 0;
|
|
5
5
|
var RESERVATION_STATUS_ENUM;
|
|
6
6
|
(function (RESERVATION_STATUS_ENUM) {
|
|
7
7
|
RESERVATION_STATUS_ENUM["PENDING"] = "PENDING";
|
|
@@ -25,6 +25,14 @@ var RIDER_FEE_TYPE_ENUM;
|
|
|
25
25
|
RIDER_FEE_TYPE_ENUM["DISTANCE_RETURN"] = "DISTANCE_RETURN";
|
|
26
26
|
})(RIDER_FEE_TYPE_ENUM || (exports.RIDER_FEE_TYPE_ENUM = RIDER_FEE_TYPE_ENUM = {}));
|
|
27
27
|
exports.ALL_RIDER_FEE_TYPES = Object.values(RIDER_FEE_TYPE_ENUM);
|
|
28
|
+
/** Server-owned rider payout lifecycle. */
|
|
29
|
+
var RIDER_EARNINGS_STATUS_ENUM;
|
|
30
|
+
(function (RIDER_EARNINGS_STATUS_ENUM) {
|
|
31
|
+
RIDER_EARNINGS_STATUS_ENUM["PENDING"] = "PENDING";
|
|
32
|
+
RIDER_EARNINGS_STATUS_ENUM["FINAL"] = "FINAL";
|
|
33
|
+
RIDER_EARNINGS_STATUS_ENUM["VOID"] = "VOID";
|
|
34
|
+
})(RIDER_EARNINGS_STATUS_ENUM || (exports.RIDER_EARNINGS_STATUS_ENUM = RIDER_EARNINGS_STATUS_ENUM = {}));
|
|
35
|
+
exports.ALL_RIDER_EARNINGS_STATUS = Object.values(RIDER_EARNINGS_STATUS_ENUM);
|
|
28
36
|
// ======================>> <<====================== //
|
|
29
37
|
var DELIVERY_STATUS_ENUM;
|
|
30
38
|
(function (DELIVERY_STATUS_ENUM) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CASH_DRAWER_STATUS_ENUM, CASH_IN_OUT_REF_ENUM, CASH_IN_OUT_TYPE_ENUM } from '../../constants/enums/cash';
|
|
1
2
|
import { IMaterializedCashCounters } from '../../schemas/types/materialized_tenant_cash_reports';
|
|
2
3
|
/**
|
|
3
4
|
* M3 cash - lifecycle classifier + accumulators.
|
|
@@ -39,6 +40,57 @@ import { IMaterializedCashCounters } from '../../schemas/types/materialized_tena
|
|
|
39
40
|
* (`operator.net == sessions.net_movements_amount` and
|
|
40
41
|
* `system.net == -sessions.variance_amount`) hold exactly.
|
|
41
42
|
*/
|
|
43
|
+
export interface TCashMovementSource {
|
|
44
|
+
_id?: string;
|
|
45
|
+
cash_in_out_id?: string;
|
|
46
|
+
tenant_id?: string;
|
|
47
|
+
drawer_id?: string;
|
|
48
|
+
day_id?: string;
|
|
49
|
+
shift_id?: string | null;
|
|
50
|
+
shift_number?: number | null;
|
|
51
|
+
ref_type?: CASH_IN_OUT_REF_ENUM | string;
|
|
52
|
+
ref_id?: string | null;
|
|
53
|
+
type?: CASH_IN_OUT_TYPE_ENUM | string;
|
|
54
|
+
amount?: number | null;
|
|
55
|
+
drawer_balance_before?: number | null;
|
|
56
|
+
drawer_balance_after?: number | null;
|
|
57
|
+
staff_id?: string | null;
|
|
58
|
+
staff_name?: string | null;
|
|
59
|
+
note?: string | null;
|
|
60
|
+
createdAt?: Date | string | null;
|
|
61
|
+
updatedAt?: Date | string | null;
|
|
62
|
+
localDate?: string | null;
|
|
63
|
+
localHour?: number | null;
|
|
64
|
+
}
|
|
65
|
+
export interface TCashSessionSource {
|
|
66
|
+
_id?: string;
|
|
67
|
+
tenant_id?: string;
|
|
68
|
+
drawer_id?: string;
|
|
69
|
+
day_id?: string;
|
|
70
|
+
status?: CASH_DRAWER_STATUS_ENUM | string;
|
|
71
|
+
opening?: {
|
|
72
|
+
cash_amount?: number | null;
|
|
73
|
+
} | null;
|
|
74
|
+
closing?: {
|
|
75
|
+
expected_cash_amount?: number | null;
|
|
76
|
+
cash_amount?: number | null;
|
|
77
|
+
difference?: number | null;
|
|
78
|
+
} | null;
|
|
79
|
+
net_movements?: number | null;
|
|
80
|
+
reopened_times?: number | null;
|
|
81
|
+
reopened_iterations?: {
|
|
82
|
+
closing?: {
|
|
83
|
+
expected_cash_amount?: number | null;
|
|
84
|
+
cash_amount?: number | null;
|
|
85
|
+
difference?: number | null;
|
|
86
|
+
} | null;
|
|
87
|
+
expected_cash_amount?: number | null;
|
|
88
|
+
cash_amount?: number | null;
|
|
89
|
+
difference?: number | null;
|
|
90
|
+
}[];
|
|
91
|
+
createdAt?: Date | string | null;
|
|
92
|
+
updatedAt?: Date | string | null;
|
|
93
|
+
}
|
|
42
94
|
/** Note prefixes written by the cash drawer repository. */
|
|
43
95
|
export declare const CASH_OPENING_NOTE_PREFIX = "Drawer opened";
|
|
44
96
|
export declare const CASH_REOPEN_NOTE_PREFIX = "Drawer reopened";
|
|
@@ -61,7 +113,7 @@ export interface ICashMovementProvenance {
|
|
|
61
113
|
* an operator cash-in never does - so a row whose note is missing or reworded is
|
|
62
114
|
* still classified correctly rather than silently counted as operator movement.
|
|
63
115
|
*/
|
|
64
|
-
export declare function classifyCashMovement(row:
|
|
116
|
+
export declare function classifyCashMovement(row: TCashMovementSource): ICashMovementProvenance;
|
|
65
117
|
/**
|
|
66
118
|
* A per-key accumulation buffer.
|
|
67
119
|
*
|
|
@@ -78,9 +130,9 @@ export declare function freshCashCounters(): IMaterializedCashCounters;
|
|
|
78
130
|
/** A fresh buffer. */
|
|
79
131
|
export declare function freshCashAccumulator(): ICashAccumulator;
|
|
80
132
|
/** Adds one ledger row. Returns false when it was already counted. */
|
|
81
|
-
export declare function addCashMovement(acc: ICashAccumulator, row:
|
|
133
|
+
export declare function addCashMovement(acc: ICashAccumulator, row: TCashMovementSource): boolean;
|
|
82
134
|
/** Adds one drawer session document. */
|
|
83
|
-
export declare function addCashSession(acc: ICashAccumulator, session:
|
|
135
|
+
export declare function addCashSession(acc: ICashAccumulator, session: TCashSessionSource): void;
|
|
84
136
|
/**
|
|
85
137
|
* Materializes the staff roster into the counter block (call before persisting).
|
|
86
138
|
*
|
|
@@ -8,46 +8,6 @@ exports.addCashMovement = addCashMovement;
|
|
|
8
8
|
exports.addCashSession = addCashSession;
|
|
9
9
|
exports.finalizeCashAccumulator = finalizeCashAccumulator;
|
|
10
10
|
const cash_1 = require("../../constants/enums/cash");
|
|
11
|
-
/**
|
|
12
|
-
* M3 cash - lifecycle classifier + accumulators.
|
|
13
|
-
*
|
|
14
|
-
* ## The classification (decision (i3))
|
|
15
|
-
*
|
|
16
|
-
* Cash ledger rows carry NO explicit lifecycle flag, so provenance is derived from
|
|
17
|
-
* `ref_type` PLUS the note prefix written by the source, with the balance SHAPE as a
|
|
18
|
-
* secondary signal. The source notes are stable, source-verified strings:
|
|
19
|
-
*
|
|
20
|
-
* "Drawer opened - Day ..." -> the opening float
|
|
21
|
-
* "Drawer reopened - ... " -> a reopen re-baseline
|
|
22
|
-
* "Drawer closed - Day ..." -> the count-out
|
|
23
|
-
* "System adjustment - ..." -> an over/short sweep
|
|
24
|
-
*
|
|
25
|
-
* The classifier lives HERE and runs at COMPILE time; the entry rows store the
|
|
26
|
-
* resulting flags, so the read never re-derives them. When the durable
|
|
27
|
-
* `is_lifecycle` write-path stamp lands, only this function changes.
|
|
28
|
-
*
|
|
29
|
-
* ## The three nets, defined EXACTLY
|
|
30
|
-
*
|
|
31
|
-
* - `operator` - pure operator movement. Excludes the float, every reopen, the
|
|
32
|
-
* count-out AND the sweeps. This is the quantity the session
|
|
33
|
-
* document calls `net_movements`, so the two sources must AGREE.
|
|
34
|
-
* - `lifecycle` - float + reopen + count-out, broken out separately.
|
|
35
|
-
* - `system` - the over/short sweeps written at close.
|
|
36
|
-
*
|
|
37
|
-
* NOTE ON THE CONCEPT DOC: section 3.2.2 states the reconciliation as
|
|
38
|
-
* `ledger_net = operator_movement_net + reopen_amount + system_adjustment_net`.
|
|
39
|
-
* That is INCOMPLETE - it omits the float and the count-out, which are also ledger
|
|
40
|
-
* rows. Tracing the close routine shows why they matter: the count-out is written
|
|
41
|
-
* as `CASH_OUT amount = countedCash`, so a fully closed drawer-day nets to ZERO.
|
|
42
|
-
* The identity the harness must assert is therefore:
|
|
43
|
-
*
|
|
44
|
-
* ledger_net = operator.net + lifecycle.float_amount - lifecycle.countout_amount
|
|
45
|
-
* + lifecycle.reopen_amount + system.net
|
|
46
|
-
*
|
|
47
|
-
* which reduces to 0 for a closed day, while BOTH cross-collection checks
|
|
48
|
-
* (`operator.net == sessions.net_movements_amount` and
|
|
49
|
-
* `system.net == -sessions.variance_amount`) hold exactly.
|
|
50
|
-
*/
|
|
51
11
|
/** Note prefixes written by the cash drawer repository. */
|
|
52
12
|
exports.CASH_OPENING_NOTE_PREFIX = 'Drawer opened';
|
|
53
13
|
exports.CASH_REOPEN_NOTE_PREFIX = 'Drawer reopened';
|
|
@@ -247,7 +207,7 @@ function addCashSession(acc, session) {
|
|
|
247
207
|
if (closing == null) {
|
|
248
208
|
// No closing record: a session still IN_USE is normal; anything else is a
|
|
249
209
|
// data-integrity tripwire.
|
|
250
|
-
if (String(session.status) ===
|
|
210
|
+
if (String(session.status) === cash_1.CASH_DRAWER_STATUS_ENUM.IN_USE)
|
|
251
211
|
sessions.open_sessions_count += 1;
|
|
252
212
|
else
|
|
253
213
|
sessions.unmatched_close_count += 1;
|
|
@@ -266,7 +226,9 @@ function addCashSession(acc, session) {
|
|
|
266
226
|
// identity exact again.
|
|
267
227
|
const lifecycles = [closing];
|
|
268
228
|
for (const iteration of Array.isArray(session.reopened_iterations) ? session.reopened_iterations : []) {
|
|
269
|
-
if (iteration != null)
|
|
229
|
+
if (iteration?.closing != null)
|
|
230
|
+
lifecycles.push(iteration.closing);
|
|
231
|
+
else if (iteration != null)
|
|
270
232
|
lifecycles.push(iteration);
|
|
271
233
|
}
|
|
272
234
|
for (const lifecycle of lifecycles) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
|
|
1
2
|
import { IMaterializedCashEntry, IMaterializedTenantCashEntries } from '../../schemas/types/materialized_tenant_cash_entries';
|
|
2
3
|
import { IMaterializedCashCounters, IMaterializedTenantCashReport } from '../../schemas/types/materialized_tenant_cash_reports';
|
|
3
4
|
/**
|
|
@@ -20,7 +21,7 @@ import { IMaterializedCashCounters, IMaterializedTenantCashReport } from '../../
|
|
|
20
21
|
* prep time report and is designed out here from the start.
|
|
21
22
|
*/
|
|
22
23
|
/** Period scopes this report materializes (everything but the day scope). */
|
|
23
|
-
export declare const MATERIALIZED_CASH_PERIOD_SCOPES:
|
|
24
|
+
export declare const MATERIALIZED_CASH_PERIOD_SCOPES: MATERIALIZED_REPORT_SCOPE_ENUM[];
|
|
24
25
|
/** True when the scope is the plain day scope. */
|
|
25
26
|
export declare const isMaterializedCashDayScope: (scopeContext: string) => boolean;
|
|
26
27
|
/**
|
|
@@ -36,9 +36,9 @@ const materialized_cash_accumulator_helpers_1 = require("./materialized-cash-acc
|
|
|
36
36
|
* prep time report and is designed out here from the start.
|
|
37
37
|
*/
|
|
38
38
|
/** Period scopes this report materializes (everything but the day scope). */
|
|
39
|
-
exports.MATERIALIZED_CASH_PERIOD_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_CASH_REPORT_SCOPES.filter((scope) => String(scope) !==
|
|
39
|
+
exports.MATERIALIZED_CASH_PERIOD_SCOPES = MATERIALIZED_REPORTS_1.MATERIALIZED_CASH_REPORT_SCOPES.filter((scope) => String(scope) !== MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE);
|
|
40
40
|
/** True when the scope is the plain day scope. */
|
|
41
|
-
const isMaterializedCashDayScope = (scopeContext) => String(scopeContext) ===
|
|
41
|
+
const isMaterializedCashDayScope = (scopeContext) => String(scopeContext) === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
|
|
42
42
|
exports.isMaterializedCashDayScope = isMaterializedCashDayScope;
|
|
43
43
|
const cashScopeKey = (doc) => String(doc.scope_context) + '|' + String(doc.scope_field);
|
|
44
44
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IMaterializedTenantCashEntries } from '../../schemas/types/materialized_tenant_cash_entries';
|
|
2
2
|
import { IMaterializedTenantCashReport } from '../../schemas/types/materialized_tenant_cash_reports';
|
|
3
|
+
import { TCashMovementSource, TCashSessionSource } from './materialized-cash-classification-helpers';
|
|
3
4
|
/**
|
|
4
5
|
* M3 cash - key grammar and the day compile.
|
|
5
6
|
*
|
|
@@ -50,13 +51,13 @@ export interface ICashDayCompileInput {
|
|
|
50
51
|
* legitimately have sessions but no movements (a drawer opened and closed with
|
|
51
52
|
* nothing in between), and pre-materialization history predates either.
|
|
52
53
|
*/
|
|
53
|
-
movements?:
|
|
54
|
+
movements?: TCashMovementSource[];
|
|
54
55
|
/**
|
|
55
56
|
* `tenant_cash_drawer_sessions` for this day, any drawer. OPTIONAL for the same
|
|
56
57
|
* reason - a movement without its session document is still a real ledger row and
|
|
57
58
|
* must not be dropped.
|
|
58
59
|
*/
|
|
59
|
-
sessions?:
|
|
60
|
+
sessions?: TCashSessionSource[];
|
|
60
61
|
/** Optional `drawer_id -> display name`, for the statement rows. */
|
|
61
62
|
drawerNames?: Record<string, string | null>;
|
|
62
63
|
computedAt: Date;
|
|
@@ -5,6 +5,7 @@ exports.buildMaterializedCashKey = buildMaterializedCashKey;
|
|
|
5
5
|
exports.parseMaterializedCashKey = parseMaterializedCashKey;
|
|
6
6
|
exports.cashSessionKeyForDrawer = cashSessionKeyForDrawer;
|
|
7
7
|
exports.compileTenantCashReports = compileTenantCashReports;
|
|
8
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
8
9
|
const cash_1 = require("../../constants/enums/cash");
|
|
9
10
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
10
11
|
const materialized_tenant_cash_entries_1 = require("../../schemas/models/materialized_tenant_cash_entries");
|
|
@@ -185,7 +186,7 @@ function compileTenantCashReports(input) {
|
|
|
185
186
|
_id: undefined,
|
|
186
187
|
tenant_id: tenantId,
|
|
187
188
|
brand_id: brandId,
|
|
188
|
-
scope_context:
|
|
189
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
189
190
|
scope_field: localDate,
|
|
190
191
|
day_index: dayIndexOf(localDate),
|
|
191
192
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.CASH_KEY_FILTERS],
|
|
@@ -203,7 +204,7 @@ function compileTenantCashReports(input) {
|
|
|
203
204
|
_id: undefined,
|
|
204
205
|
tenant_id: tenantId,
|
|
205
206
|
brand_id: brandId,
|
|
206
|
-
scope_context:
|
|
207
|
+
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
207
208
|
scope_field: localDate,
|
|
208
209
|
day_index: dayIndexOf(localDate),
|
|
209
210
|
sale_type_key_filters: [...MATERIALIZED_REPORTS_1.CASH_KEY_FILTERS],
|
|
@@ -247,5 +248,5 @@ function dayIndexOf(localDate) {
|
|
|
247
248
|
const date = new Date(localDate + 'T00:00:00.000Z');
|
|
248
249
|
if (Number.isNaN(date.getTime()))
|
|
249
250
|
return null;
|
|
250
|
-
return [
|
|
251
|
+
return ENUMS_1.ALL_DAY_INDEX[date.getUTCDay()] ?? null;
|
|
251
252
|
}
|
|
@@ -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,32 @@ 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'>> & {
|
|
78
|
+
status?: DELIVERY_STATUS_ENUM | string;
|
|
79
|
+
localHour?: number | null;
|
|
80
|
+
};
|
|
52
81
|
export interface IDeliveryAccumulator {
|
|
53
82
|
counters: IMaterializedDeliveryCounters;
|
|
54
83
|
deliveryOrderIds: Set<string>;
|
|
@@ -58,14 +87,14 @@ export interface IDeliveryAccumulator {
|
|
|
58
87
|
/** A fresh buffer. */
|
|
59
88
|
export declare function freshDeliveryAccumulator(): IDeliveryAccumulator;
|
|
60
89
|
/** True when an order is a DELIVERY order (it has delivery details). */
|
|
61
|
-
export declare function isDeliveryOrder(order:
|
|
90
|
+
export declare function isDeliveryOrder(order: IDeliveryOrderSource): boolean;
|
|
62
91
|
/**
|
|
63
92
|
* Consumes ONE delivery ORDER - the ADOPTION half of the join.
|
|
64
93
|
*
|
|
65
94
|
* Order-side money is counted HERE rather than on the delivery, because a cancelled
|
|
66
95
|
* delivery must not lose the order figures the operator recognises.
|
|
67
96
|
*/
|
|
68
|
-
export declare function addDeliveryOrder(acc: IDeliveryAccumulator, order:
|
|
97
|
+
export declare function addDeliveryOrder(acc: IDeliveryAccumulator, order: IDeliveryOrderSource): void;
|
|
69
98
|
/**
|
|
70
99
|
* Consumes ONE delivery document - the APP-SIDE half of the join.
|
|
71
100
|
*
|
|
@@ -73,7 +102,7 @@ export declare function addDeliveryOrder(acc: IDeliveryAccumulator, order: any):
|
|
|
73
102
|
* adoption and its own fields, but the order-derived money and the area cannot be
|
|
74
103
|
* attributed, so it lands in the UNKNOWN bucket.
|
|
75
104
|
*/
|
|
76
|
-
export declare function addDelivery(acc: IDeliveryAccumulator, delivery:
|
|
105
|
+
export declare function addDelivery(acc: IDeliveryAccumulator, delivery: TDeliverySource, order: IDeliveryOrderSource | null, key: string): void;
|
|
77
106
|
/**
|
|
78
107
|
* Computes the DERIVED adoption figures and prunes the bounded maps.
|
|
79
108
|
*
|
|
@@ -271,7 +271,11 @@ 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 revenue = Number(earnings != null
|
|
274
|
+
const revenue = Number(earnings != null
|
|
275
|
+
? earnings.status === delivery_1.RIDER_EARNINGS_STATUS_ENUM.FINAL
|
|
276
|
+
? earnings.amount
|
|
277
|
+
: 0
|
|
278
|
+
: delivery.rider_revenue);
|
|
275
279
|
const hasRevenue = Number.isFinite(revenue);
|
|
276
280
|
if (hasRevenue) {
|
|
277
281
|
counters.money.rider_revenue_amount += revenue;
|
|
@@ -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
|
/**
|