@mj-biz-apps/orders-core-entities-server 5.46.0 → 5.47.0
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.
|
@@ -15,17 +15,37 @@
|
|
|
15
15
|
*
|
|
16
16
|
* WHAT COUNTS AS A COLLISION
|
|
17
17
|
* Same product, same price list, same fee type, same priority, with OVERLAPPING quantity bands AND
|
|
18
|
-
* overlapping absolute windows
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* overlapping absolute windows, unless both rows are revenue bands with disjoint revenue ranges
|
|
19
|
+
* (`ParseRevenueBand`): "$2M-$5M rev" and "$5M-$10M rev" can never both apply, so a product's bands
|
|
20
|
+
* sit at ONE priority, which is also what lets this check catch two bands that do overlap (#1004).
|
|
21
|
+
* Any other When is not consulted: proving that two arbitrary filters are mutually exclusive would
|
|
22
|
+
* mean re-implementing the applicability engine against every possible order, so two rows that differ
|
|
23
|
+
* only by such a When need distinct priorities. Recurrence is not considered either: a monthly and a
|
|
24
|
+
* weekday rule can genuinely never coincide, and proving that here would mean evaluating every date.
|
|
25
|
+
* The order-time check remains the backstop for the cases this cannot see — this catches the
|
|
26
|
+
* common, obvious, avoidable ones.
|
|
22
27
|
*
|
|
23
28
|
* CONNECTS TO:
|
|
24
29
|
* PURE: ./PricingBehavior.ts (PickPriceRule — the reader this protects)
|
|
30
|
+
* @mj-biz-apps/orders-entities pricing/revenueBands.ts (the band contract)
|
|
25
31
|
* DOC: plans/archive/pricing-schema.md
|
|
26
32
|
*/
|
|
27
33
|
import { ValidationResult } from '@memberjunction/core';
|
|
28
34
|
import { ProductPriceEntity } from '@mj-biz-apps/orders-entities';
|
|
35
|
+
/** What the collision check reads from a rule; `Applicability` is the When JSON. */
|
|
36
|
+
export interface CollisionRule {
|
|
37
|
+
MinQuantity: number | null;
|
|
38
|
+
MaxQuantity: number | null;
|
|
39
|
+
EffectiveFrom: Date;
|
|
40
|
+
EffectiveTo: Date | null;
|
|
41
|
+
Applicability: string | null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Can two same-priority rules (same product or category, price list and fee type) both apply to one
|
|
45
|
+
* order line? True when their quantity bands and effective windows overlap, except for two revenue
|
|
46
|
+
* bands whose revenue ranges are disjoint. Exported for the unit test; the entity calls it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function PriceRulesCanCollide(a: CollisionRule, b: CollisionRule): boolean;
|
|
29
49
|
export declare class ProductPriceEntityServer extends ProductPriceEntity {
|
|
30
50
|
/** BaseEntity skips ValidateAsync by default; without this the check never runs. */
|
|
31
51
|
get DefaultSkipAsyncValidation(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductPriceEntityServer.d.ts","sourceRoot":"","sources":["../src/ProductPriceEntityServer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"ProductPriceEntityServer.d.ts","sourceRoot":"","sources":["../src/ProductPriceEntityServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAmC,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEzF,OAAO,EAIH,kBAAkB,EAErB,MAAM,8BAA8B,CAAC;AAItC,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,EAAE,IAAI,CAAC;IACpB,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAyBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAOhF;AAED,qBACa,wBAAyB,SAAQ,kBAAkB;IAC5D,oFAAoF;IACpF,IAAoB,0BAA0B,IAAI,OAAO,CAExD;IAEqB,aAAa,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAuDnE;AAED,0FAA0F;AAC1F,wBAAgB,4BAA4B,IAAI,IAAI,CAEnD"}
|
|
@@ -21,18 +21,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
21
21
|
*
|
|
22
22
|
* WHAT COUNTS AS A COLLISION
|
|
23
23
|
* Same product, same price list, same fee type, same priority, with OVERLAPPING quantity bands AND
|
|
24
|
-
* overlapping absolute windows
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
24
|
+
* overlapping absolute windows, unless both rows are revenue bands with disjoint revenue ranges
|
|
25
|
+
* (`ParseRevenueBand`): "$2M-$5M rev" and "$5M-$10M rev" can never both apply, so a product's bands
|
|
26
|
+
* sit at ONE priority, which is also what lets this check catch two bands that do overlap (#1004).
|
|
27
|
+
* Any other When is not consulted: proving that two arbitrary filters are mutually exclusive would
|
|
28
|
+
* mean re-implementing the applicability engine against every possible order, so two rows that differ
|
|
29
|
+
* only by such a When need distinct priorities. Recurrence is not considered either: a monthly and a
|
|
30
|
+
* weekday rule can genuinely never coincide, and proving that here would mean evaluating every date.
|
|
31
|
+
* The order-time check remains the backstop for the cases this cannot see — this catches the
|
|
32
|
+
* common, obvious, avoidable ones.
|
|
28
33
|
*
|
|
29
34
|
* CONNECTS TO:
|
|
30
35
|
* PURE: ./PricingBehavior.ts (PickPriceRule — the reader this protects)
|
|
36
|
+
* @mj-biz-apps/orders-entities pricing/revenueBands.ts (the band contract)
|
|
31
37
|
* DOC: plans/archive/pricing-schema.md
|
|
32
38
|
*/
|
|
33
39
|
import { BaseEntity, ValidationErrorInfo } from '@memberjunction/core';
|
|
34
40
|
import { RegisterClass } from '@memberjunction/global';
|
|
35
|
-
import { LoadOrdersEngine, OrdersEngine, ProductPriceEntity } from '@mj-biz-apps/orders-entities';
|
|
41
|
+
import { LoadOrdersEngine, OrdersEngine, ParseRevenueBand, ProductPriceEntity, RevenueBandsOverlap, } from '@mj-biz-apps/orders-entities';
|
|
36
42
|
const PRODUCT_PRICE_ENTITY = 'MJ_BizApps_Orders: Product Prices';
|
|
37
43
|
/** Do two [min,max] bands overlap? Null bounds are open. */
|
|
38
44
|
function bandsOverlap(aMin, aMax, bMin, bMax) {
|
|
@@ -50,6 +56,22 @@ function windowsOverlap(aFrom, aTo, bFrom, bTo) {
|
|
|
50
56
|
const e2 = bTo ? new Date(bTo).getTime() : Infinity;
|
|
51
57
|
return s1 <= e2 && s2 <= e1;
|
|
52
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Can two same-priority rules (same product or category, price list and fee type) both apply to one
|
|
61
|
+
* order line? True when their quantity bands and effective windows overlap, except for two revenue
|
|
62
|
+
* bands whose revenue ranges are disjoint. Exported for the unit test; the entity calls it.
|
|
63
|
+
*/
|
|
64
|
+
export function PriceRulesCanCollide(a, b) {
|
|
65
|
+
if (!bandsOverlap(a.MinQuantity, a.MaxQuantity, b.MinQuantity, b.MaxQuantity))
|
|
66
|
+
return false;
|
|
67
|
+
if (!windowsOverlap(a.EffectiveFrom, a.EffectiveTo, b.EffectiveFrom, b.EffectiveTo))
|
|
68
|
+
return false;
|
|
69
|
+
const bandA = ParseRevenueBand(a.Applicability);
|
|
70
|
+
const bandB = ParseRevenueBand(b.Applicability);
|
|
71
|
+
if (bandA && bandB && !RevenueBandsOverlap(bandA, bandB))
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
53
75
|
let ProductPriceEntityServer = class ProductPriceEntityServer extends ProductPriceEntity {
|
|
54
76
|
/** BaseEntity skips ValidateAsync by default; without this the check never runs. */
|
|
55
77
|
get DefaultSkipAsyncValidation() {
|
|
@@ -83,15 +105,26 @@ let ProductPriceEntityServer = class ProductPriceEntityServer extends ProductPri
|
|
|
83
105
|
return (o.ProductID ?? '').toLowerCase() === productKey;
|
|
84
106
|
return (o.ProductCategoryID ?? '').toLowerCase() === catKey;
|
|
85
107
|
});
|
|
86
|
-
const clash = siblings.find((o) =>
|
|
87
|
-
|
|
108
|
+
const clash = siblings.find((o) => PriceRulesCanCollide(this, {
|
|
109
|
+
MinQuantity: o.MinQuantity,
|
|
110
|
+
MaxQuantity: o.MaxQuantity,
|
|
111
|
+
EffectiveFrom: o.EffectiveFrom,
|
|
112
|
+
EffectiveTo: o.EffectiveTo,
|
|
113
|
+
Applicability: o.Applicability ?? null,
|
|
114
|
+
}));
|
|
88
115
|
if (clash) {
|
|
116
|
+
const bothBands = ParseRevenueBand(this.Applicability) && ParseRevenueBand(clash.Applicability);
|
|
117
|
+
const other = clash.Name?.trim() || clash.Description?.trim() || clash.ID;
|
|
89
118
|
result.Success = false;
|
|
90
|
-
result.Errors.push(new ValidationErrorInfo('ProductPriceEntityServer.ValidateAsync',
|
|
91
|
-
`
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
`
|
|
119
|
+
result.Errors.push(new ValidationErrorInfo('ProductPriceEntityServer.ValidateAsync', bothBands
|
|
120
|
+
? `This revenue band overlaps another band on the same product, price list and fee type at priority ` +
|
|
121
|
+
`${this.Priority}: ${other}. An organization whose revenue falls in both would get no price, so ` +
|
|
122
|
+
`move one band's edge until the two ranges meet without overlapping.`
|
|
123
|
+
: `This price rule collides with an existing one: both have priority ${this.Priority}, overlapping ` +
|
|
124
|
+
`quantity bands and overlapping effective windows for the same product or category, price list and fee ` +
|
|
125
|
+
`type. The other is ${other}. Pricing resolves by highest ` +
|
|
126
|
+
`priority and refuses to break a tie, so an order using either quantity would fail. Give one ` +
|
|
127
|
+
`of them a different priority, narrow a quantity band, or separate the date windows.`, null));
|
|
95
128
|
}
|
|
96
129
|
return result;
|
|
97
130
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductPriceEntityServer.js","sourceRoot":"","sources":["../src/ProductPriceEntityServer.ts"],"names":[],"mappings":";;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"ProductPriceEntityServer.js","sourceRoot":"","sources":["../src/ProductPriceEntityServer.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entities-server",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.47.0",
|
|
5
5
|
"description": "Server-side entity subclasses for BizApps Orders — order booking (one JE per line), line computation, and lifecycle hooks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"vitest": "^4.0.18"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@mj-biz-apps/orders-entities": "^5.
|
|
49
|
+
"@mj-biz-apps/orders-entities": "^5.47.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@memberjunction/communication-engine": "^6.2.1",
|