@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,6 +1,9 @@
|
|
|
1
1
|
import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, PAYMENTS_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 METRICS = [
|
|
5
8
|
PAYMENTS_COMPARISON_METRIC_ENUM.PAYMENT_AMOUNT,
|
|
6
9
|
PAYMENTS_COMPARISON_METRIC_ENUM.PAYMENT_COUNT,
|
|
@@ -92,8 +95,8 @@ const parseKey = (key, keyFilters) => {
|
|
|
92
95
|
}
|
|
93
96
|
return { payment_method: paymentMethod, order_status: orderStatus };
|
|
94
97
|
};
|
|
95
|
-
const isCancelled = (orderStatus) => orderStatus ===
|
|
96
|
-
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(
|
|
98
|
+
const isCancelled = (orderStatus) => orderStatus === ORDER_STATUS_ENUM.CANCELLED;
|
|
99
|
+
const includesCancelled = (filters) => Array.isArray(filters.order_statuses) && filters.order_statuses.includes(ORDER_STATUS_ENUM.CANCELLED);
|
|
97
100
|
const matchesFilters = (parsed, filters) => {
|
|
98
101
|
if (filters.payment_methods != null &&
|
|
99
102
|
filters.payment_methods.length > 0 &&
|
|
@@ -119,8 +122,8 @@ const buildPage = (group, filters) => {
|
|
|
119
122
|
for (const doc of docs ?? []) {
|
|
120
123
|
if (doc == null)
|
|
121
124
|
continue;
|
|
122
|
-
matchedDocuments +=
|
|
123
|
-
const updatedAt = doc
|
|
125
|
+
matchedDocuments += matchedDocumentsOf(doc);
|
|
126
|
+
const updatedAt = updatedAtOf(doc);
|
|
124
127
|
if (updatedAt != null) {
|
|
125
128
|
const date = new Date(updatedAt);
|
|
126
129
|
if (!Number.isNaN(date.getTime()) && (maxUpdatedAt == null || date.getTime() > maxUpdatedAt.getTime())) {
|
|
@@ -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,12 +1,9 @@
|
|
|
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
|
-
|
|
7
|
-
return earnings.status === 'FINAL' ? Number(earnings.amount) || 0 : 0;
|
|
8
|
-
}
|
|
9
|
-
return Number(delivery.rider_revenue) || 0;
|
|
6
|
+
return earnings?.status === RIDER_EARNINGS_STATUS_ENUM.FINAL ? Number(earnings.amount) || 0 : 0;
|
|
10
7
|
};
|
|
11
8
|
export function buildRiderDailyReport({ rider_id, local_date, deliveries, computedAt = new Date(), }) {
|
|
12
9
|
if (rider_id.trim() === '' || local_date.trim() === '')
|
|
@@ -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
|
}
|
|
@@ -5,9 +5,12 @@ export function getDeliveryWithPrice(delivery, writeable) {
|
|
|
5
5
|
const convertToPrice = writeable ? convertPriceToCents : convertPriceFromCents;
|
|
6
6
|
return {
|
|
7
7
|
...delivery,
|
|
8
|
-
...(delivery.
|
|
8
|
+
...(delivery.rider_earnings != null
|
|
9
9
|
? {
|
|
10
|
-
|
|
10
|
+
rider_earnings: {
|
|
11
|
+
...delivery.rider_earnings,
|
|
12
|
+
amount: convertToPrice(delivery.rider_earnings.amount),
|
|
13
|
+
},
|
|
11
14
|
}
|
|
12
15
|
: {}),
|
|
13
16
|
};
|
|
@@ -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,
|
|
@@ -73,11 +79,6 @@ export const DeliveriesSchema = new Schema({
|
|
|
73
79
|
type: Number,
|
|
74
80
|
default: 0,
|
|
75
81
|
},
|
|
76
|
-
rider_revenue: {
|
|
77
|
-
type: Number,
|
|
78
|
-
min: 0,
|
|
79
|
-
required: false,
|
|
80
|
-
},
|
|
81
82
|
pickup_food_image_url: {
|
|
82
83
|
type: String,
|
|
83
84
|
required: false,
|
|
@@ -146,14 +147,14 @@ export const DeliveriesSchema = new Schema({
|
|
|
146
147
|
status: {
|
|
147
148
|
type: String,
|
|
148
149
|
required: true,
|
|
149
|
-
enum:
|
|
150
|
-
default:
|
|
150
|
+
enum: ALL_RIDER_EARNINGS_STATUS,
|
|
151
|
+
default: RIDER_EARNINGS_STATUS_ENUM.PENDING,
|
|
151
152
|
},
|
|
152
153
|
rule_type: {
|
|
153
154
|
type: String,
|
|
154
155
|
required: true,
|
|
155
|
-
enum:
|
|
156
|
-
default:
|
|
156
|
+
enum: ALL_RIDER_FEE_TYPES,
|
|
157
|
+
default: RIDER_FEE_TYPE_ENUM.NONE,
|
|
157
158
|
},
|
|
158
159
|
per_meter: { type: Number, required: true, min: 0, default: 0 },
|
|
159
160
|
distance_step: { type: Number, required: true, min: 0, default: 0 },
|
|
@@ -29,10 +29,18 @@ export const MaterializedRiderDailyReportSchema = new Schema({
|
|
|
29
29
|
source_watermark: { type: Schema.Types.Date, required: true },
|
|
30
30
|
computed_at: { type: Schema.Types.Date, required: true },
|
|
31
31
|
}, { timestamps: true, versionKey: false, minimize: false });
|
|
32
|
-
|
|
32
|
+
/** Index patterns for `.hint()` reads. */
|
|
33
|
+
export const MATERIALIZED_RIDER_DAILY_REPORTS_COLLECTION_INDEXES = {
|
|
34
|
+
_id: { _id: 1 },
|
|
35
|
+
rider_id__local_date: { rider_id: 1, local_date: 1 },
|
|
36
|
+
};
|
|
37
|
+
MaterializedRiderDailyReportSchema.index(MATERIALIZED_RIDER_DAILY_REPORTS_COLLECTION_INDEXES.rider_id__local_date, {
|
|
38
|
+
unique: true,
|
|
39
|
+
name: 'rider_id__local_date',
|
|
40
|
+
});
|
|
33
41
|
export const MATERIALIZED_RIDER_DAILY_REPORTS_INDEX_OPTIONS = [
|
|
34
42
|
{
|
|
35
|
-
key:
|
|
43
|
+
key: MATERIALIZED_RIDER_DAILY_REPORTS_COLLECTION_INDEXES.rider_id__local_date,
|
|
36
44
|
name: 'rider_id__local_date',
|
|
37
45
|
unique: true,
|
|
38
46
|
},
|
|
@@ -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
|
}
|