@managesome/eposmatic-toolkit 0.4.62 → 0.4.64
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_SCHEMA_VERSIONS.js +17 -0
- package/esm/constants/WORKER_ENDPOINTS.js +2 -2
- package/esm/helpers/materialized-reports/index.js +3 -0
- package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-dialer-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +5 -5
- package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +2 -2
- package/esm/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-document-size.js +2 -2
- package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
- package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
- package/esm/helpers/materialized-reports/report-compile.js +38 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-bson.js +27 -0
- package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +3 -22
- package/esm/helpers/store/common-tenant-purchase-order-actions.js +12 -0
- package/esm/helpers/store/common-warehouse-purchase-order-actions.js +20 -0
- package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +24 -7
- package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +23 -10
- package/esm/helpers/utils/index.js +1 -0
- package/esm/helpers/utils/tenant-purchase-order-engine.js +47 -0
- package/esm/helpers/utils/warehouse-purchase-order-engine.js +63 -4
- package/esm/schemas/models/materialized_credit_bills.js +2 -1
- package/esm/schemas/models/materialized_tenant_delivery_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_delivery_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_dialer_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_dialer_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_dinein_entries.js +2 -1
- package/esm/schemas/models/materialized_tenant_dinein_reports.js +2 -1
- package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +2 -1
- package/esm/schemas/models/tenant_purchase_orders.js +4 -0
- package/esm/schemas/models/warehouse_purchase_orders.js +4 -0
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.d.ts +17 -0
- package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.js +20 -0
- package/lib/constants/WORKER_ENDPOINTS.d.ts +0 -2
- package/lib/constants/WORKER_ENDPOINTS.js +2 -2
- package/lib/helpers/materialized-reports/index.d.ts +2 -0
- package/lib/helpers/materialized-reports/index.js +26 -0
- package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +4 -4
- package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +4 -4
- package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +6 -6
- package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
- package/lib/helpers/materialized-reports/materialized-document-size.js +2 -5
- package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
- package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
- package/lib/helpers/materialized-reports/report-compile.d.ts +38 -0
- package/lib/helpers/materialized-reports/report-compile.js +87 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-bson.d.ts +12 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-bson.js +33 -0
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +1 -12
- package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -24
- package/lib/helpers/store/common-tenant-purchase-order-actions.d.ts +6 -1
- package/lib/helpers/store/common-tenant-purchase-order-actions.js +13 -0
- package/lib/helpers/store/common-warehouse-purchase-order-actions.js +20 -0
- package/lib/helpers/store/tenant-purchase-orders-cart-actions.js +23 -6
- package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +23 -10
- package/lib/helpers/utils/index.d.ts +1 -0
- package/lib/helpers/utils/index.js +1 -0
- package/lib/helpers/utils/tenant-purchase-order-engine.d.ts +24 -0
- package/lib/helpers/utils/tenant-purchase-order-engine.js +51 -0
- package/lib/helpers/utils/warehouse-purchase-order-engine.d.ts +23 -1
- package/lib/helpers/utils/warehouse-purchase-order-engine.js +65 -4
- package/lib/schemas/models/materialized_credit_bills.d.ts +29 -46
- package/lib/schemas/models/materialized_credit_bills.js +3 -2
- package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_delivery_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +6 -6
- package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_delivery_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +8 -7
- package/lib/schemas/models/materialized_tenant_dialer_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_dialer_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +8 -7
- package/lib/schemas/models/materialized_tenant_dinein_entries.js +3 -2
- package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +11 -10
- package/lib/schemas/models/materialized_tenant_dinein_reports.js +3 -2
- package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +9 -9
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +11 -35
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +3 -2
- package/lib/schemas/models/tenant_purchase_orders.d.ts +972 -0
- package/lib/schemas/models/tenant_purchase_orders.js +4 -0
- package/lib/schemas/models/warehouse_purchase_orders.d.ts +972 -0
- package/lib/schemas/models/warehouse_purchase_orders.js +4 -0
- package/lib/schemas/types/tenant_purchase_orders.d.ts +2 -1
- package/lib/schemas/types/warehouse_purchase_orders.d.ts +2 -1
- package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +2 -1
- package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +5 -4
- package/lib/tests/reporting-contract/no-live-transport.test.js +106 -0
- package/package.json +2 -1
- package/lib/helpers/order/payment-collection.d.ts +0 -25
- package/lib/helpers/order/payment-collection.js +0 -51
- package/lib/schemas/models/applied_order_discounts.d.ts +0 -80
- package/lib/schemas/models/applied_order_discounts.js +0 -106
- package/lib/schemas/types/applied_order_discounts.d.ts +0 -22
- package/lib/schemas/types/applied_order_discounts.js +0 -2
- package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +0 -1
- package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +0 -1
- package/lib/tests/payment-collection-timestamps.test.d.ts +0 -1
- package/lib/tests/payment-collection-timestamps.test.js +0 -71
- /package/lib/tests/{materialized-reports/analytics-growth-helpers.test.d.ts → reporting-contract/no-live-transport.test.d.ts} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TENANT_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
|
|
2
|
-
import { IOrderPayment, IStaffDetails } from './orders';
|
|
2
|
+
import { IDiscountDetails, IOrderPayment, IStaffDetails } from './orders';
|
|
3
3
|
/**
|
|
4
4
|
* Order-level discount for a tenant purchase order.
|
|
5
5
|
*
|
|
@@ -30,6 +30,7 @@ export interface ITenantPurchaseOrderItem {
|
|
|
30
30
|
_gross_amount: number;
|
|
31
31
|
_gst_amount: number;
|
|
32
32
|
_discount_amount: number;
|
|
33
|
+
item_discount_details?: IDiscountDetails | null;
|
|
33
34
|
special_instructions: string;
|
|
34
35
|
}
|
|
35
36
|
export interface ITenantPurchaseOrderCategory {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WAREHOUSE_PURCHASE_ORDER_STATUS_ENUM } from '../../constants';
|
|
2
|
-
import { IOrderPayment, IStaffDetails } from './orders';
|
|
2
|
+
import { IDiscountDetails, IOrderPayment, IStaffDetails } from './orders';
|
|
3
3
|
export interface IWarehousePurchaseOrderDiscountDetails {
|
|
4
4
|
special_discount?: number;
|
|
5
5
|
special_discount_id?: string;
|
|
@@ -18,6 +18,7 @@ export type IWarehousePurchaseOrderItem = {
|
|
|
18
18
|
price: number;
|
|
19
19
|
subtotal: number;
|
|
20
20
|
quantity: number;
|
|
21
|
+
item_discount_details?: IDiscountDetails | null;
|
|
21
22
|
_net_amount: number;
|
|
22
23
|
_gross_amount: number;
|
|
23
24
|
_gst_amount: number;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const constants_1 = require("../../constants");
|
|
4
4
|
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
5
5
|
const tenant_sales_overview_close_day_helpers_1 = require("../../helpers/materialized-reports/tenant-sales-overview-close-day-helpers");
|
|
6
|
+
const tenant_sales_overview_bson_1 = require("../../helpers/materialized-reports/tenant-sales-overview-bson");
|
|
6
7
|
const tenant_sales_overview_helpers_1 = require("../../helpers/materialized-reports/tenant-sales-overview-helpers");
|
|
7
8
|
const materialized_credit_bills_helpers_1 = require("../../helpers/materialized-reports/materialized-credit-bills-helpers");
|
|
8
9
|
/** Narrows helper results that are `null` on invalid data (tests expect valid data). */
|
|
@@ -453,7 +454,7 @@ describe('tenant sales overview close-day plan', () => {
|
|
|
453
454
|
// Real hydration shape: `Model.find()` docs carry the `sale_type_metrics` Map
|
|
454
455
|
// with mongoose subdocument values (NOT plain objects).
|
|
455
456
|
const hydratedStored = world1.docs.map((doc) => doc.scope_context === LOCAL_DATE && doc.scope_field === D1
|
|
456
|
-
? (0,
|
|
457
|
+
? (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)(doc).toObject()
|
|
457
458
|
: doc);
|
|
458
459
|
const plan = closeDay(D2, [cashD2, collectedCredit], { docs: hydratedStored, credit: world1.credit }, CT2);
|
|
459
460
|
expect(plan.receivedPatches).toHaveLength(8); // the hydrated D1 date doc is still detected + patched
|
|
@@ -6,6 +6,7 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
|
6
6
|
const key_helpers_1 = require("../../helpers/materialized-reports/key-helpers");
|
|
7
7
|
const materialized_tenant_reports_iterations_helpers_1 = require("../../helpers/materialized-reports/materialized-tenant-reports-iterations-helpers");
|
|
8
8
|
const scope_helpers_1 = require("../../helpers/materialized-reports/scope-helpers");
|
|
9
|
+
const tenant_sales_overview_bson_1 = require("../../helpers/materialized-reports/tenant-sales-overview-bson");
|
|
9
10
|
const tenant_sales_overview_helpers_1 = require("../../helpers/materialized-reports/tenant-sales-overview-helpers");
|
|
10
11
|
const time_helpers_1 = require("../../helpers/utils/time-helpers");
|
|
11
12
|
const fixtures_1 = require("./fixtures");
|
|
@@ -521,14 +522,14 @@ describe('credit-bill lifecycle (synthetic PAY_LATER orders)', () => {
|
|
|
521
522
|
expect(bareCompile.credit_bill_issues[0]?.issued_at).toEqual(computedAt);
|
|
522
523
|
});
|
|
523
524
|
it('converts the JSON document to a mongoose (BSON) document', () => {
|
|
524
|
-
const hydrated = (0,
|
|
525
|
+
const hydrated = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)(issueDateDoc);
|
|
525
526
|
expect(hydrated.get('scope_context')).toBe('localDate');
|
|
526
527
|
expect(hydrated.get('sale_type_metrics')).toBeInstanceOf(Map);
|
|
527
528
|
const metrics = hydrated.get('sale_type_metrics');
|
|
528
529
|
const issued = metrics.get('COMPLETED:POS_WALK-IN')?.[constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS].issued;
|
|
529
530
|
expect(issued?.count).toBe(1);
|
|
530
531
|
expect(issued?.amount).toBe(1200);
|
|
531
|
-
const hydratedCollect = (0,
|
|
532
|
+
const hydratedCollect = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)(collectDateDoc);
|
|
532
533
|
const collectedMetrics = hydratedCollect.get('sale_type_metrics');
|
|
533
534
|
const received = collectedMetrics.get('COMPLETED:POS_WALK-IN')?.[constants_1.REPORT_SALE_TYPE_ENUM.CREDIT_BILLS].received;
|
|
534
535
|
expect(received?.count).toBe(1);
|
|
@@ -901,11 +902,11 @@ describe('subtract + versioned reconcile (iteration bump)', () => {
|
|
|
901
902
|
});
|
|
902
903
|
// Real hydration shapes: `Model.find()` / json→BSON cast docs carry the Map
|
|
903
904
|
// with mongoose subdocument values; `.toObject()` output keeps them too.
|
|
904
|
-
const hydrated = (0,
|
|
905
|
+
const hydrated = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)({
|
|
905
906
|
...stored,
|
|
906
907
|
_id: '68dd3f9c9f1b2c3d4e5f6a7b',
|
|
907
908
|
}).toObject();
|
|
908
|
-
const hydratedFlattened = (0,
|
|
909
|
+
const hydratedFlattened = (0, tenant_sales_overview_bson_1.convertMaterializedTenantSalesOverviewReportJsonToBson)({
|
|
909
910
|
...stored,
|
|
910
911
|
_id: '68dd3f9c9f1b2c3d4e5f6a7b',
|
|
911
912
|
}).toObject({ flattenMaps: true });
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
40
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
41
|
+
const WORKER_ENDPOINTS_1 = require("../../constants/WORKER_ENDPOINTS");
|
|
42
|
+
const reportCompile = __importStar(require("../../helpers/materialized-reports/report-compile"));
|
|
43
|
+
/**
|
|
44
|
+
* SHARED CONTRACT SURFACE — after the live-proxy revert and the direct-API move.
|
|
45
|
+
*
|
|
46
|
+
* - no internal live summary/details transport types;
|
|
47
|
+
* - no WORKER_ENDPOINTS entry for the removed live proxy or the catalog reads
|
|
48
|
+
* that items-service owns now;
|
|
49
|
+
* - the pure `report-compile` subpath still exposes the close compilers.
|
|
50
|
+
*
|
|
51
|
+
* The `report-compile` import graph must stay mongoose-free: it is the worker
|
|
52
|
+
* boundary for BOTH services' Piscina compile threads.
|
|
53
|
+
*/
|
|
54
|
+
const root = process.cwd();
|
|
55
|
+
const readSource = (relative) => node_fs_1.default.readFileSync(node_path_1.default.join(root, relative), 'utf8');
|
|
56
|
+
test('the internal live transport module is removed', () => {
|
|
57
|
+
expect(node_fs_1.default.existsSync(node_path_1.default.join(root, 'src/helpers/reporting-contract/live-reports.ts'))).toBe(false);
|
|
58
|
+
const barrel = readSource('src/helpers/reporting-contract/index.ts');
|
|
59
|
+
expect(barrel).not.toContain('live-reports');
|
|
60
|
+
});
|
|
61
|
+
test('no WORKER_ENDPOINTS entry is a live-proxy or moved catalog path', () => {
|
|
62
|
+
const values = Object.values(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS);
|
|
63
|
+
expect(values.some((value) => value.includes('/live'))).toBe(false);
|
|
64
|
+
expect('ITEMS_USING_MODIFIER' in WORKER_ENDPOINTS_1.WORKER_ENDPOINTS).toBe(false);
|
|
65
|
+
expect('AUDIT_ITEM_MODIFIERS' in WORKER_ENDPOINTS_1.WORKER_ENDPOINTS).toBe(false);
|
|
66
|
+
// The endpoints that MUST stay.
|
|
67
|
+
expect(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS.END_TENANT_DAY).toBe('/end-tenant-day');
|
|
68
|
+
expect(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS.RETRY_MATERIALIZED_REPORT).toBe('/internal/materialization/reports/retry');
|
|
69
|
+
expect(WORKER_ENDPOINTS_1.WORKER_ENDPOINTS.RECONCILE_MATERIALIZED_REPORT_RUNS).toBe('/internal/materialization/reports/reconcile');
|
|
70
|
+
});
|
|
71
|
+
test('the pure report-compile subpath still exports the close compilers', () => {
|
|
72
|
+
expect(typeof reportCompile.compileTenantDineinReports).toBe('function');
|
|
73
|
+
expect(typeof reportCompile.compileTenantDiscountReports).toBe('function');
|
|
74
|
+
expect(typeof reportCompile.compileTenantPrepTimeReports).toBe('function');
|
|
75
|
+
expect(typeof reportCompile.compileTenantDialerReports).toBe('function');
|
|
76
|
+
expect(typeof reportCompile.compileTenantDeliveryReports).toBe('function');
|
|
77
|
+
expect(typeof reportCompile.convertOrdersToMaterializedTenantSalesOverviewReports).toBe('function');
|
|
78
|
+
});
|
|
79
|
+
test('the report-compile import graph contains no mongoose or schema model', () => {
|
|
80
|
+
const entry = 'src/helpers/materialized-reports/report-compile.ts';
|
|
81
|
+
const visited = new Set();
|
|
82
|
+
const queue = [entry];
|
|
83
|
+
while (queue.length > 0) {
|
|
84
|
+
const current = queue.shift();
|
|
85
|
+
if (visited.has(current))
|
|
86
|
+
continue;
|
|
87
|
+
visited.add(current);
|
|
88
|
+
const source = readSource(current);
|
|
89
|
+
// Type-only imports are erased by tsc and never load a module.
|
|
90
|
+
const runtimeSource = source
|
|
91
|
+
.replace(/import\s+type\s+[^;]+?from\s*['"][^'"]+['"];?/gs, '')
|
|
92
|
+
.replace(/export\s+type\s+\{[^}]*\}\s*from\s*['"][^'"]+['"];?/gs, '');
|
|
93
|
+
expect(runtimeSource).not.toContain("from 'mongoose'");
|
|
94
|
+
expect(runtimeSource).not.toContain('from "mongoose"');
|
|
95
|
+
for (const match of runtimeSource.matchAll(/(?:from|import)\s*\(?\s*['"](\.[^'"]+)['"]/g)) {
|
|
96
|
+
const candidate = node_path_1.default.posix.normalize(node_path_1.default.posix.join(node_path_1.default.posix.dirname(current), match[1]));
|
|
97
|
+
// Toolkit sources use extensionless specifiers; services use `.js`.
|
|
98
|
+
const asTs = candidate.endsWith('.js') ? candidate.replace(/\.js$/, '.ts') : `${candidate}.ts`;
|
|
99
|
+
if (node_fs_1.default.existsSync(node_path_1.default.join(root, asTs)))
|
|
100
|
+
queue.push(asTs);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// The graph is real (not an empty walk) and includes the service-facing API.
|
|
104
|
+
expect(visited.size).toBeGreaterThan(5);
|
|
105
|
+
expect([...visited].some((file) => file.includes('materialized-dinein-'))).toBe(true);
|
|
106
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@managesome/eposmatic-toolkit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.64",
|
|
4
4
|
"description": "A Toolkit Library for Eposmatic",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"test:characterization": "jest --config jestconfig.json src/tests/materialized-reports/characterization --runInBand"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"bson": "^6.10.3",
|
|
35
36
|
"bson-objectid": "^2.0.4",
|
|
36
37
|
"crypto-js": "^4.2.0",
|
|
37
38
|
"emoji-strip": "^1.0.1",
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IOrderPayment } from '../../schemas/types/orders';
|
|
2
|
-
/**
|
|
3
|
-
* Server-owned `collected_at` stamping for order payments.
|
|
4
|
-
*
|
|
5
|
-
* A payment line is the unit a credit bill lives on: the sale is issued on the
|
|
6
|
-
* punch day, and money may arrive later (full or partial). `order_settled_at`
|
|
7
|
-
* only moves on FULL settlement, so it cannot anchor a partial collection.
|
|
8
|
-
* This helper records the LAST collection moment on the payment itself,
|
|
9
|
-
* derived by comparing `amount_paid` with the stored previous version.
|
|
10
|
-
*
|
|
11
|
-
* Rules:
|
|
12
|
-
* - never trust the incoming `collected_at` (clients may send anything);
|
|
13
|
-
* - a NEW payment line with money in (`amount_paid > 0`) gets `now`;
|
|
14
|
-
* - an EXISTING line whose `amount_paid` increased gets `now`;
|
|
15
|
-
* - unchanged / decreased / zero-amount lines keep the stored timestamp
|
|
16
|
-
* (`null` when unknown — legacy rows are not backfilled here).
|
|
17
|
-
*
|
|
18
|
-
* Pure and never throws. `previousPayments` must be the SERVER copy of the
|
|
19
|
-
* order's payments before the write (pass none on create).
|
|
20
|
-
*/
|
|
21
|
-
export interface IStampPaymentCollectionTimestampsOptions {
|
|
22
|
-
/** Override for the collection instant (tests / offline replays). */
|
|
23
|
-
now?: Date | string | null;
|
|
24
|
-
}
|
|
25
|
-
export declare function stampPaymentCollectionTimestamps(payments: IOrderPayment[] | null | undefined, previousPayments?: IOrderPayment[] | null | undefined, options?: IStampPaymentCollectionTimestampsOptions): IOrderPayment[];
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stampPaymentCollectionTimestamps = stampPaymentCollectionTimestamps;
|
|
4
|
-
const constants_1 = require("../../constants");
|
|
5
|
-
const toValidDate = (value) => {
|
|
6
|
-
if (value == null)
|
|
7
|
-
return null;
|
|
8
|
-
const date = value instanceof Date ? value : new Date(value);
|
|
9
|
-
return Number.isNaN(date.getTime()) ? null : date;
|
|
10
|
-
};
|
|
11
|
-
/** Stable identity across a merge: subdoc `_id` first, then `payment_id`. */
|
|
12
|
-
const identityOf = (payment) => {
|
|
13
|
-
if (payment._id != null && String(payment._id).trim() !== '') {
|
|
14
|
-
return `id:${String(payment._id)}`;
|
|
15
|
-
}
|
|
16
|
-
if (typeof payment.payment_id === 'string' && payment.payment_id.trim() !== '') {
|
|
17
|
-
return `payment:${payment.payment_id}`;
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
};
|
|
21
|
-
function stampPaymentCollectionTimestamps(payments, previousPayments = null, options = {}) {
|
|
22
|
-
if (!Array.isArray(payments))
|
|
23
|
-
return [];
|
|
24
|
-
const now = toValidDate(options.now) ?? new Date();
|
|
25
|
-
const previousByIdentity = new Map();
|
|
26
|
-
for (const previous of Array.isArray(previousPayments) ? previousPayments : []) {
|
|
27
|
-
if (previous == null)
|
|
28
|
-
continue;
|
|
29
|
-
const identity = identityOf(previous);
|
|
30
|
-
if (identity != null)
|
|
31
|
-
previousByIdentity.set(identity, previous);
|
|
32
|
-
}
|
|
33
|
-
return payments.map((payment) => {
|
|
34
|
-
if (payment == null)
|
|
35
|
-
return payment;
|
|
36
|
-
const identity = identityOf(payment);
|
|
37
|
-
const previous = identity != null ? previousByIdentity.get(identity) : undefined;
|
|
38
|
-
const previousCollectedAt = toValidDate(previous?.collected_at);
|
|
39
|
-
const amountPaid = Number(payment.amount_paid ?? 0);
|
|
40
|
-
const previousAmountPaid = Number(previous?.amount_paid ?? 0);
|
|
41
|
-
const isFailed = payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.FAILED;
|
|
42
|
-
const isNewCollection = !isFailed &&
|
|
43
|
-
Number.isFinite(amountPaid) &&
|
|
44
|
-
amountPaid > 0 &&
|
|
45
|
-
(previous == null || amountPaid > previousAmountPaid);
|
|
46
|
-
return {
|
|
47
|
-
...payment,
|
|
48
|
-
collected_at: isNewCollection ? now : previousCollectedAt,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Schema } from 'mongoose';
|
|
2
|
-
export declare const AppliedOrderDiscountsSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
3
|
-
timestamps: true;
|
|
4
|
-
versionKey: false;
|
|
5
|
-
minimize: false;
|
|
6
|
-
}, {
|
|
7
|
-
createdAt: NativeDate;
|
|
8
|
-
updatedAt: NativeDate;
|
|
9
|
-
} & {
|
|
10
|
-
_id: import("mongoose").Types.ObjectId;
|
|
11
|
-
type: import("../../constants").DISCOUNT_TYPE_ENUM;
|
|
12
|
-
name: string;
|
|
13
|
-
tenant_id: string;
|
|
14
|
-
order_id: import("mongoose").Types.ObjectId;
|
|
15
|
-
discount_id: string;
|
|
16
|
-
applicability: import("../../constants").DISCOUNT_APPLICABILITY_ENUM;
|
|
17
|
-
platform: import("../../constants").PLATFORMS_ENUM;
|
|
18
|
-
order_amount: number;
|
|
19
|
-
discount_amount: number;
|
|
20
|
-
reason: string;
|
|
21
|
-
staff_id: string;
|
|
22
|
-
staff_phone: string;
|
|
23
|
-
staff_name: string;
|
|
24
|
-
createdAt_mins: number;
|
|
25
|
-
createdAt: NativeDate;
|
|
26
|
-
updatedAt: NativeDate;
|
|
27
|
-
discount_rate?: number | null | undefined;
|
|
28
|
-
reference_number?: string | null | undefined;
|
|
29
|
-
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
30
|
-
createdAt: NativeDate;
|
|
31
|
-
updatedAt: NativeDate;
|
|
32
|
-
} & {
|
|
33
|
-
_id: import("mongoose").Types.ObjectId;
|
|
34
|
-
type: import("../../constants").DISCOUNT_TYPE_ENUM;
|
|
35
|
-
name: string;
|
|
36
|
-
tenant_id: string;
|
|
37
|
-
order_id: import("mongoose").Types.ObjectId;
|
|
38
|
-
discount_id: string;
|
|
39
|
-
applicability: import("../../constants").DISCOUNT_APPLICABILITY_ENUM;
|
|
40
|
-
platform: import("../../constants").PLATFORMS_ENUM;
|
|
41
|
-
order_amount: number;
|
|
42
|
-
discount_amount: number;
|
|
43
|
-
reason: string;
|
|
44
|
-
staff_id: string;
|
|
45
|
-
staff_phone: string;
|
|
46
|
-
staff_name: string;
|
|
47
|
-
createdAt_mins: number;
|
|
48
|
-
createdAt: NativeDate;
|
|
49
|
-
updatedAt: NativeDate;
|
|
50
|
-
discount_rate?: number | null | undefined;
|
|
51
|
-
reference_number?: string | null | undefined;
|
|
52
|
-
}>> & import("mongoose").FlatRecord<{
|
|
53
|
-
createdAt: NativeDate;
|
|
54
|
-
updatedAt: NativeDate;
|
|
55
|
-
} & {
|
|
56
|
-
_id: import("mongoose").Types.ObjectId;
|
|
57
|
-
type: import("../../constants").DISCOUNT_TYPE_ENUM;
|
|
58
|
-
name: string;
|
|
59
|
-
tenant_id: string;
|
|
60
|
-
order_id: import("mongoose").Types.ObjectId;
|
|
61
|
-
discount_id: string;
|
|
62
|
-
applicability: import("../../constants").DISCOUNT_APPLICABILITY_ENUM;
|
|
63
|
-
platform: import("../../constants").PLATFORMS_ENUM;
|
|
64
|
-
order_amount: number;
|
|
65
|
-
discount_amount: number;
|
|
66
|
-
reason: string;
|
|
67
|
-
staff_id: string;
|
|
68
|
-
staff_phone: string;
|
|
69
|
-
staff_name: string;
|
|
70
|
-
createdAt_mins: number;
|
|
71
|
-
createdAt: NativeDate;
|
|
72
|
-
updatedAt: NativeDate;
|
|
73
|
-
discount_rate?: number | null | undefined;
|
|
74
|
-
reference_number?: string | null | undefined;
|
|
75
|
-
}> & Required<{
|
|
76
|
-
_id: import("mongoose").Types.ObjectId;
|
|
77
|
-
}> & {
|
|
78
|
-
__v: number;
|
|
79
|
-
}>;
|
|
80
|
-
export declare const APPLIED_ORDER_DISCOUNTS_COLLECTION_NAME = "applied_order_discounts";
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APPLIED_ORDER_DISCOUNTS_COLLECTION_NAME = exports.AppliedOrderDiscountsSchema = void 0;
|
|
4
|
-
const mongoose_1 = require("mongoose");
|
|
5
|
-
const constants_1 = require("../../constants");
|
|
6
|
-
exports.AppliedOrderDiscountsSchema = new mongoose_1.Schema({
|
|
7
|
-
_id: {
|
|
8
|
-
type: mongoose_1.Schema.Types.ObjectId,
|
|
9
|
-
required: true,
|
|
10
|
-
immutable: true,
|
|
11
|
-
},
|
|
12
|
-
tenant_id: {
|
|
13
|
-
type: String,
|
|
14
|
-
required: true,
|
|
15
|
-
immutable: true,
|
|
16
|
-
ref: 'tenants',
|
|
17
|
-
},
|
|
18
|
-
order_id: {
|
|
19
|
-
type: mongoose_1.Schema.Types.ObjectId,
|
|
20
|
-
required: true,
|
|
21
|
-
immutable: true,
|
|
22
|
-
},
|
|
23
|
-
discount_id: {
|
|
24
|
-
type: String,
|
|
25
|
-
required: true,
|
|
26
|
-
},
|
|
27
|
-
type: {
|
|
28
|
-
type: String,
|
|
29
|
-
required: true,
|
|
30
|
-
enum: constants_1.ALL_DISCOUNT_TYPES,
|
|
31
|
-
},
|
|
32
|
-
applicability: {
|
|
33
|
-
type: String,
|
|
34
|
-
required: true,
|
|
35
|
-
enum: constants_1.ALL_DISCOUNT_APPLICABILITY_TYPES,
|
|
36
|
-
},
|
|
37
|
-
platform: {
|
|
38
|
-
type: String,
|
|
39
|
-
enum: constants_1.ALL_PLATFORMS,
|
|
40
|
-
required: true,
|
|
41
|
-
},
|
|
42
|
-
name: {
|
|
43
|
-
type: String,
|
|
44
|
-
required: true,
|
|
45
|
-
},
|
|
46
|
-
order_amount: {
|
|
47
|
-
type: Number,
|
|
48
|
-
required: true,
|
|
49
|
-
min: 0,
|
|
50
|
-
},
|
|
51
|
-
discount_amount: {
|
|
52
|
-
type: Number,
|
|
53
|
-
required: true,
|
|
54
|
-
min: 0,
|
|
55
|
-
},
|
|
56
|
-
discount_rate: {
|
|
57
|
-
type: Number,
|
|
58
|
-
required: false,
|
|
59
|
-
default: null,
|
|
60
|
-
},
|
|
61
|
-
reason: {
|
|
62
|
-
type: String,
|
|
63
|
-
required: true,
|
|
64
|
-
},
|
|
65
|
-
reference_number: {
|
|
66
|
-
type: String,
|
|
67
|
-
required: false,
|
|
68
|
-
},
|
|
69
|
-
staff_id: {
|
|
70
|
-
type: String,
|
|
71
|
-
required: true,
|
|
72
|
-
},
|
|
73
|
-
staff_phone: {
|
|
74
|
-
type: String,
|
|
75
|
-
required: true,
|
|
76
|
-
},
|
|
77
|
-
staff_name: {
|
|
78
|
-
type: String,
|
|
79
|
-
required: true,
|
|
80
|
-
},
|
|
81
|
-
createdAt_mins: {
|
|
82
|
-
type: Number,
|
|
83
|
-
required: true,
|
|
84
|
-
immutable: true,
|
|
85
|
-
default: () => {
|
|
86
|
-
const date = new Date();
|
|
87
|
-
return Math.floor(date.getHours() * 60 + date.getMinutes());
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
createdAt: {
|
|
91
|
-
type: mongoose_1.Schema.Types.Date,
|
|
92
|
-
required: true,
|
|
93
|
-
default: () => new Date(),
|
|
94
|
-
immutable: true,
|
|
95
|
-
},
|
|
96
|
-
updatedAt: {
|
|
97
|
-
type: mongoose_1.Schema.Types.Date,
|
|
98
|
-
required: true,
|
|
99
|
-
default: () => new Date(),
|
|
100
|
-
},
|
|
101
|
-
}, {
|
|
102
|
-
timestamps: true,
|
|
103
|
-
versionKey: false,
|
|
104
|
-
minimize: false,
|
|
105
|
-
});
|
|
106
|
-
exports.APPLIED_ORDER_DISCOUNTS_COLLECTION_NAME = 'applied_order_discounts';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DISCOUNT_APPLICABILITY_ENUM, DISCOUNT_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
|
|
2
|
-
export interface IAppliedOrderDiscount {
|
|
3
|
-
_id: string;
|
|
4
|
-
tenant_id: string;
|
|
5
|
-
order_id: string;
|
|
6
|
-
discount_id: string;
|
|
7
|
-
type: DISCOUNT_TYPE_ENUM;
|
|
8
|
-
applicability: DISCOUNT_APPLICABILITY_ENUM;
|
|
9
|
-
platform: PLATFORMS_ENUM;
|
|
10
|
-
name: string;
|
|
11
|
-
order_amount: number;
|
|
12
|
-
discount_amount: number;
|
|
13
|
-
discount_rate: number | null;
|
|
14
|
-
reason: string;
|
|
15
|
-
reference_number: string | null;
|
|
16
|
-
staff_id: string;
|
|
17
|
-
staff_phone: string;
|
|
18
|
-
staff_name: string;
|
|
19
|
-
createdAt_mins: number;
|
|
20
|
-
createdAt: Date;
|
|
21
|
-
updatedAt: Date;
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const constants_1 = require("../constants");
|
|
4
|
-
const payment_collection_1 = require("../helpers/order/payment-collection");
|
|
5
|
-
const NOW = new Date('2026-10-20T14:00:00.000Z');
|
|
6
|
-
const EARLIER = new Date('2026-10-19T10:00:00.000Z');
|
|
7
|
-
const payment = (over = {}) => ({
|
|
8
|
-
_id: '5f0000000000000000000001',
|
|
9
|
-
payment_type: constants_1.PAYMENT_TYPE_ENUM.CASH,
|
|
10
|
-
payment_status: constants_1.PAYMENT_STATUS_ENUM.SETTLED,
|
|
11
|
-
card_details: null,
|
|
12
|
-
amount_paid: 1000,
|
|
13
|
-
amount_due: 1000,
|
|
14
|
-
amount_refunded: 0,
|
|
15
|
-
payment_id: 'pay-1',
|
|
16
|
-
...over,
|
|
17
|
-
});
|
|
18
|
-
describe('stampPaymentCollectionTimestamps', () => {
|
|
19
|
-
it('stamps new collected money and leaves unpaid PAY_LATER empty', () => {
|
|
20
|
-
const [paid, credit] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([
|
|
21
|
-
payment(),
|
|
22
|
-
payment({
|
|
23
|
-
_id: '5f0000000000000000000002',
|
|
24
|
-
payment_id: 'pay-2',
|
|
25
|
-
payment_type: constants_1.PAYMENT_TYPE_ENUM.PAY_LATER,
|
|
26
|
-
payment_status: constants_1.PAYMENT_STATUS_ENUM.PENDING,
|
|
27
|
-
amount_paid: 0,
|
|
28
|
-
amount_due: 5000,
|
|
29
|
-
}),
|
|
30
|
-
], null, { now: NOW });
|
|
31
|
-
expect(paid.collected_at).toBe(NOW);
|
|
32
|
-
expect(credit.collected_at).toBeNull();
|
|
33
|
-
});
|
|
34
|
-
it('ignores a client-supplied collected_at on create', () => {
|
|
35
|
-
const [paid] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ collected_at: EARLIER })], null, { now: NOW });
|
|
36
|
-
expect(paid.collected_at).toBe(NOW);
|
|
37
|
-
});
|
|
38
|
-
it('preserves the stored timestamp when amount_paid did not increase', () => {
|
|
39
|
-
const previous = payment({ collected_at: EARLIER });
|
|
40
|
-
const [unchanged] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ collected_at: null })], [previous], { now: NOW });
|
|
41
|
-
expect(unchanged.collected_at).toBe(EARLIER);
|
|
42
|
-
});
|
|
43
|
-
it('stamps the latest collection when a partial amount is collected', () => {
|
|
44
|
-
const previous = payment({ amount_paid: 400, collected_at: EARLIER });
|
|
45
|
-
const [partial] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ amount_paid: 700 })], [previous], { now: NOW });
|
|
46
|
-
expect(partial.collected_at).toBe(NOW);
|
|
47
|
-
});
|
|
48
|
-
it('does not rewrite the timestamp on a refund / amount decrease', () => {
|
|
49
|
-
const previous = payment({ amount_paid: 1000, collected_at: EARLIER });
|
|
50
|
-
const [refunded] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ amount_paid: 0, amount_refunded: 1000, payment_status: constants_1.PAYMENT_STATUS_ENUM.REFUNDED })], [previous], { now: NOW });
|
|
51
|
-
expect(refunded.collected_at).toBe(EARLIER);
|
|
52
|
-
});
|
|
53
|
-
it('matches legacy rows by _id when payment_id is null', () => {
|
|
54
|
-
const previous = payment({ payment_id: null, collected_at: EARLIER });
|
|
55
|
-
const [updated] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_id: null, amount_paid: 1200 })], [previous], { now: NOW });
|
|
56
|
-
expect(updated.collected_at).toBe(NOW);
|
|
57
|
-
});
|
|
58
|
-
it('preserves the stamp when the server reassigns payment_id but _id is stable', () => {
|
|
59
|
-
const previous = payment({ payment_id: 'pay-old', collected_at: EARLIER });
|
|
60
|
-
const [updated] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_id: 'pay-new' })], [previous], { now: NOW });
|
|
61
|
-
expect(updated.collected_at).toBe(EARLIER);
|
|
62
|
-
});
|
|
63
|
-
it('does not stamp a failed payment', () => {
|
|
64
|
-
const [failed] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_status: constants_1.PAYMENT_STATUS_ENUM.FAILED })], null, { now: NOW });
|
|
65
|
-
expect(failed.collected_at).toBeNull();
|
|
66
|
-
});
|
|
67
|
-
it('returns an empty array for empty / invalid input', () => {
|
|
68
|
-
expect((0, payment_collection_1.stampPaymentCollectionTimestamps)(null)).toEqual([]);
|
|
69
|
-
expect((0, payment_collection_1.stampPaymentCollectionTimestamps)(undefined)).toEqual([]);
|
|
70
|
-
});
|
|
71
|
-
});
|