onroute-policy-engine 2.23.0 → 2.24.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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This is the default description used for each cost object,
3
+ * when there is no explicit description provided (eg. Non-STWSE permit costs).
4
+ *
5
+ * NOTE: DO NOT change the value of this constant, as the value is being used elsewhere
6
+ * throughout the backend.
7
+ */
8
+ export declare const DEFAULT_COST_DESCRIPTION = "Calculated permit cost";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_COST_DESCRIPTION = void 0;
4
+ /**
5
+ * This is the default description used for each cost object,
6
+ * when there is no explicit description provided (eg. Non-STWSE permit costs).
7
+ *
8
+ * NOTE: DO NOT change the value of this constant, as the value is being used elsewhere
9
+ * throughout the backend.
10
+ */
11
+ exports.DEFAULT_COST_DESCRIPTION = 'Calculated permit cost';
@@ -0,0 +1,9 @@
1
+ export declare const BASE_OVERLOAD_LIMIT = 28000;
2
+ export declare const EXTRA_WEIGHT_INTERVAL = 900;
3
+ export declare const EXTRA_RATE_INCREMENT = 1.85;
4
+ export declare const DEFAULT_MAX_RATE = 21.4;
5
+ export declare const MINIMUM_OVERLOAD_FEE = 25;
6
+ export declare const OVERLOAD_RATES_PER_10KM: {
7
+ max: number;
8
+ rate: number;
9
+ }[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OVERLOAD_RATES_PER_10KM = exports.MINIMUM_OVERLOAD_FEE = exports.DEFAULT_MAX_RATE = exports.EXTRA_RATE_INCREMENT = exports.EXTRA_WEIGHT_INTERVAL = exports.BASE_OVERLOAD_LIMIT = void 0;
4
+ exports.BASE_OVERLOAD_LIMIT = 28000;
5
+ exports.EXTRA_WEIGHT_INTERVAL = 900;
6
+ exports.EXTRA_RATE_INCREMENT = 1.85;
7
+ exports.DEFAULT_MAX_RATE = 21.4;
8
+ exports.MINIMUM_OVERLOAD_FEE = 25;
9
+ // Overload permit fee rate table mapping up to 28,000 kg
10
+ exports.OVERLOAD_RATES_PER_10KM = [
11
+ { max: 2000, rate: 0.95 },
12
+ { max: 3000, rate: 1.15 },
13
+ { max: 4000, rate: 1.4 },
14
+ { max: 5000, rate: 1.6 },
15
+ { max: 6000, rate: 1.85 },
16
+ { max: 7000, rate: 2.15 },
17
+ { max: 8000, rate: 2.45 },
18
+ { max: 9000, rate: 2.95 },
19
+ { max: 10000, rate: 3.35 },
20
+ { max: 11000, rate: 3.75 },
21
+ { max: 12000, rate: 4.25 },
22
+ { max: 13000, rate: 4.95 },
23
+ { max: 14000, rate: 5.6 },
24
+ { max: 15000, rate: 6.25 },
25
+ { max: 16000, rate: 7.25 },
26
+ { max: 17000, rate: 8.25 },
27
+ { max: 18000, rate: 9.15 },
28
+ { max: 19000, rate: 10.1 },
29
+ { max: 20000, rate: 10.9 },
30
+ { max: 21000, rate: 11.85 },
31
+ { max: 22000, rate: 12.7 },
32
+ { max: 23000, rate: 13.95 },
33
+ { max: 24000, rate: 14.95 },
34
+ { max: 25000, rate: 16.1 },
35
+ { max: 26000, rate: 17.85 },
36
+ { max: 27000, rate: 19.85 },
37
+ { max: 28000, rate: 21.4 },
38
+ ];
@@ -1,6 +1 @@
1
1
  export declare const AXLE_CALC_RESULTS_FACT = "axleCalcResults";
2
- export declare const BASE_OVERLOAD_LIMIT = 28000;
3
- export declare const EXTRA_WEIGHT_INTERVAL = 900;
4
- export declare const EXTRA_RATE_INCREMENT = 1.85;
5
- export declare const DEFAULT_MAX_RATE = 21.4;
6
- export declare const MINIMUM_OVERLOAD_FEE = 25;
@@ -1,9 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MINIMUM_OVERLOAD_FEE = exports.DEFAULT_MAX_RATE = exports.EXTRA_RATE_INCREMENT = exports.EXTRA_WEIGHT_INTERVAL = exports.BASE_OVERLOAD_LIMIT = exports.AXLE_CALC_RESULTS_FACT = void 0;
3
+ exports.AXLE_CALC_RESULTS_FACT = void 0;
4
4
  exports.AXLE_CALC_RESULTS_FACT = 'axleCalcResults';
5
- exports.BASE_OVERLOAD_LIMIT = 28000;
6
- exports.EXTRA_WEIGHT_INTERVAL = 900;
7
- exports.EXTRA_RATE_INCREMENT = 1.85;
8
- exports.DEFAULT_MAX_RATE = 21.4;
9
- exports.MINIMUM_OVERLOAD_FEE = 25;
@@ -17,6 +17,7 @@ export declare enum CostFacts {
17
17
  CostPerKilometre = "costPerKilometre",
18
18
  CostPerMonth = "costPerMonth",
19
19
  FixedCost = "fixedCost",
20
- OverloadCost = "overloadCost",
20
+ OverloadGvwCost = "overloadGvwCost",
21
+ OverloadWeightCost = "overloadWeightCost",
21
22
  RangeMatrixCostLookup = "rangeMatrixCostLookup"
22
23
  }
@@ -22,6 +22,7 @@ var CostFacts;
22
22
  CostFacts["CostPerKilometre"] = "costPerKilometre";
23
23
  CostFacts["CostPerMonth"] = "costPerMonth";
24
24
  CostFacts["FixedCost"] = "fixedCost";
25
- CostFacts["OverloadCost"] = "overloadCost";
25
+ CostFacts["OverloadGvwCost"] = "overloadGvwCost";
26
+ CostFacts["OverloadWeightCost"] = "overloadWeightCost";
26
27
  CostFacts["RangeMatrixCostLookup"] = "rangeMatrixCostLookup";
27
28
  })(CostFacts || (exports.CostFacts = CostFacts = {}));
@@ -4,6 +4,7 @@ export declare enum ValidationResultCode {
4
4
  PolicyValidationError = "policy-validation-error",
5
5
  ConfigurationInvalid = "configuration-invalid",
6
6
  GeneralResult = "general-result",
7
+ DimensionOversize = "dimension-oversize",
7
8
  CostValue = "cost-value",
8
9
  IsLcvCarrier = "lcv-carrier",
9
10
  NoFeeClient = "no-fee-client"
@@ -8,6 +8,7 @@ var ValidationResultCode;
8
8
  ValidationResultCode["PolicyValidationError"] = "policy-validation-error";
9
9
  ValidationResultCode["ConfigurationInvalid"] = "configuration-invalid";
10
10
  ValidationResultCode["GeneralResult"] = "general-result";
11
+ ValidationResultCode["DimensionOversize"] = "dimension-oversize";
11
12
  ValidationResultCode["CostValue"] = "cost-value";
12
13
  ValidationResultCode["IsLcvCarrier"] = "lcv-carrier";
13
14
  ValidationResultCode["NoFeeClient"] = "no-fee-client";
@@ -9,6 +9,7 @@ const quarterOfYear_1 = __importDefault(require("dayjs/plugin/quarterOfYear"));
9
9
  const enum_1 = require("onroute-policy-engine/enum");
10
10
  const policy_check_helper_1 = require("./policy-check.helper");
11
11
  const stgvwi_1 = require("../constants/stgvwi");
12
+ const overload_1 = require("../constants/overload");
12
13
  dayjs_1.default.extend(quarterOfYear_1.default);
13
14
  const getAxleCalculationInputs = async (policy, almanac) => {
14
15
  var _a, _b;
@@ -28,6 +29,28 @@ const getAxleCalculationInputs = async (policy, almanac) => {
28
29
  licensedGVW: vehicleDetails.licensedGVW || 0,
29
30
  };
30
31
  };
32
+ const getOverloadCost = (overloadKg, totalDistance) => {
33
+ let ratePer10km = 0;
34
+ if (overloadKg <= overload_1.BASE_OVERLOAD_LIMIT) {
35
+ const match = overload_1.OVERLOAD_RATES_PER_10KM.find((r) => overloadKg <= r.max);
36
+ ratePer10km = match ? match.rate : overload_1.DEFAULT_MAX_RATE;
37
+ }
38
+ else {
39
+ // For overload greater than BASE_OVERLOAD_LIMIT kg
40
+ const extraWeight = overloadKg - overload_1.BASE_OVERLOAD_LIMIT;
41
+ const intervals = Math.ceil(extraWeight / overload_1.EXTRA_WEIGHT_INTERVAL);
42
+ ratePer10km = overload_1.DEFAULT_MAX_RATE + intervals * overload_1.EXTRA_RATE_INCREMENT;
43
+ }
44
+ // Fee calculation: rate * (totalDistance / 10)
45
+ const distanceUnits = Math.ceil(totalDistance / 10);
46
+ let totalFee = ratePer10km * distanceUnits;
47
+ // Apply minimum fee rule
48
+ if (totalFee < overload_1.MINIMUM_OVERLOAD_FEE) {
49
+ totalFee = overload_1.MINIMUM_OVERLOAD_FEE;
50
+ }
51
+ // Round to the nearest dollar (0.50 rounds up)
52
+ return Math.round(totalFee);
53
+ };
31
54
  /**
32
55
  * Adds runtime facts for the validation. For example, adds the
33
56
  * validation date for comparison against startDate of the permit.
@@ -308,7 +331,7 @@ function addRuntimeFacts(engine, policy) {
308
331
  * Add runtime fact to calculate the overload fee for STGVWI permits
309
332
  * based on the Licensed GVW Increase and Total Distance.
310
333
  */
311
- engine.addFact(enum_1.CostFacts.OverloadCost.toString(), async function (params, almanac) {
334
+ engine.addFact(enum_1.CostFacts.OverloadGvwCost.toString(), async function (params, almanac) {
312
335
  const actualGVW = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, 'vehicleConfiguration.actualGVW');
313
336
  const licensedGVW = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, 'vehicleDetails.licensedGVW');
314
337
  const distance = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TotalDistance);
@@ -316,55 +339,18 @@ function addRuntimeFacts(engine, policy) {
316
339
  if (overloadKg <= 0 || !distance) {
317
340
  return 0;
318
341
  }
319
- let ratePer10km = 0;
320
- if (overloadKg <= stgvwi_1.BASE_OVERLOAD_LIMIT) {
321
- // Overload permit fee rate table mapping up to 28,000 kg
322
- const rates = [
323
- { max: 2000, rate: 0.95 },
324
- { max: 3000, rate: 1.15 },
325
- { max: 4000, rate: 1.4 },
326
- { max: 5000, rate: 1.6 },
327
- { max: 6000, rate: 1.85 },
328
- { max: 7000, rate: 2.15 },
329
- { max: 8000, rate: 2.45 },
330
- { max: 9000, rate: 2.95 },
331
- { max: 10000, rate: 3.35 },
332
- { max: 11000, rate: 3.75 },
333
- { max: 12000, rate: 4.25 },
334
- { max: 13000, rate: 4.95 },
335
- { max: 14000, rate: 5.6 },
336
- { max: 15000, rate: 6.25 },
337
- { max: 16000, rate: 7.25 },
338
- { max: 17000, rate: 8.25 },
339
- { max: 18000, rate: 9.15 },
340
- { max: 19000, rate: 10.1 },
341
- { max: 20000, rate: 10.9 },
342
- { max: 21000, rate: 11.85 },
343
- { max: 22000, rate: 12.7 },
344
- { max: 23000, rate: 13.95 },
345
- { max: 24000, rate: 14.95 },
346
- { max: 25000, rate: 16.1 },
347
- { max: 26000, rate: 17.85 },
348
- { max: 27000, rate: 19.85 },
349
- { max: 28000, rate: 21.4 },
350
- ];
351
- const match = rates.find((r) => overloadKg <= r.max);
352
- ratePer10km = match ? match.rate : stgvwi_1.DEFAULT_MAX_RATE;
353
- }
354
- else {
355
- // For overload greater than BASE_OVERLOAD_LIMIT kg
356
- const extraWeight = overloadKg - stgvwi_1.BASE_OVERLOAD_LIMIT;
357
- const intervals = Math.ceil(extraWeight / stgvwi_1.EXTRA_WEIGHT_INTERVAL);
358
- ratePer10km = stgvwi_1.DEFAULT_MAX_RATE + intervals * stgvwi_1.EXTRA_RATE_INCREMENT;
359
- }
360
- // Fee calculation: rate * (distance / 10)
361
- const distanceUnits = Math.ceil(distance / 10);
362
- let totalFee = ratePer10km * distanceUnits;
363
- // Apply minimum fee rule
364
- if (totalFee < stgvwi_1.MINIMUM_OVERLOAD_FEE) {
365
- totalFee = stgvwi_1.MINIMUM_OVERLOAD_FEE;
342
+ return getOverloadCost(overloadKg, distance);
343
+ });
344
+ /**
345
+ * Add runtime fact to calculate the overload fee for STWSE permits
346
+ * based on the Weight over 27.5m and Total Distance.
347
+ */
348
+ engine.addFact(enum_1.CostFacts.OverloadWeightCost.toString(), async function (params, almanac) {
349
+ const overloadWeight = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, 'vehicleConfiguration.overloadWeight');
350
+ const totalDistance = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TotalDistance);
351
+ if (overloadWeight <= 0 || !totalDistance) {
352
+ return 0;
366
353
  }
367
- // Round to the nearest dollar (0.50 rounds up)
368
- return Math.round(totalFee);
354
+ return getOverloadCost(overloadWeight, totalDistance);
369
355
  });
370
356
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRulesEngines = getRulesEngines;
4
4
  const json_rules_engine_1 = require("json-rules-engine");
5
5
  const custom_operators_1 = require("../rule-operator/custom-operators");
6
+ const cost_1 = require("../constants/cost");
6
7
  /**
7
8
  * Gets a json-rules-engine with all onRouteBC custom operators added,
8
9
  * and all policy rules that apply to all permit types added.
@@ -51,7 +52,7 @@ function getRulesEngines(policy) {
51
52
  event: {
52
53
  type: 'cost',
53
54
  params: {
54
- message: 'Calculated permit cost',
55
+ message: c.params.description || cost_1.DEFAULT_COST_DESCRIPTION,
55
56
  code: 'cost-value',
56
57
  cost: c,
57
58
  },
@@ -21,6 +21,7 @@ const dimensions_helper_1 = require("./helper/dimensions.helper");
21
21
  const dimensions_helper_2 = require("./helper/dimensions.helper");
22
22
  const display_code_helper_1 = require("./helper/display-code-helper");
23
23
  const policy_check_helper_1 = require("./helper/policy-check.helper");
24
+ const cost_1 = require("./constants/cost");
24
25
  /** Class representing commercial vehicle policy. */
25
26
  class Policy {
26
27
  /**
@@ -92,11 +93,22 @@ class Policy {
92
93
  // has a no fee flag set.
93
94
  if ((_d = this.specialAuthorizations) === null || _d === void 0 ? void 0 : _d.noFeeType) {
94
95
  const originalPermitCost = validationResults === null || validationResults === void 0 ? void 0 : validationResults.cost.reduce((accumulator, { cost }) => accumulator + (cost !== null && cost !== void 0 ? cost : 0), 0);
95
- // Clear the cost array and replace with zero cost
96
- validationResults.cost.length = 0;
97
- const newPermitCostResult = new validation_result_1.ValidationResult(enum_1.ValidationResultType.Cost, enum_1.ValidationResultCode.CostValue, 'Calculated permit cost');
98
- newPermitCostResult.cost = 0;
99
- validationResults.cost.push(newPermitCostResult);
96
+ if (permit.permitType !== "STWSE") {
97
+ // Clear the cost array and replace with zero cost
98
+ validationResults.cost.length = 0;
99
+ const newPermitCostResult = new validation_result_1.ValidationResult(enum_1.ValidationResultType.Cost, enum_1.ValidationResultCode.CostValue, cost_1.DEFAULT_COST_DESCRIPTION);
100
+ newPermitCostResult.cost = 0;
101
+ validationResults.cost.push(newPermitCostResult);
102
+ }
103
+ else {
104
+ // If permit type is STWSE, keep each of the cost objects, but set their costs to zero
105
+ const newPermitCosts = validationResults.cost.map(cost => {
106
+ const newPermitCostResult = new validation_result_1.ValidationResult(enum_1.ValidationResultType.Cost, enum_1.ValidationResultCode.CostValue, cost.message);
107
+ newPermitCostResult.cost = 0;
108
+ return newPermitCostResult;
109
+ });
110
+ validationResults.cost = newPermitCosts;
111
+ }
100
112
  // Add an informational message to the results
101
113
  validationResults.information.push(new validation_result_1.ValidationResult(enum_1.ValidationResultType.Information, enum_1.ValidationResultCode.NoFeeClient, `Client '${this.specialAuthorizations.companyId}' has no fee flag, original permit cost would otherwise be '${originalPermitCost}'`));
102
114
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "v2.23.0";
1
+ export declare const version = "v2.24.0";
package/dist/version.js CHANGED
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = 'v2.23.0';
5
+ exports.version = 'v2.24.0';
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  ],
92
92
  "testEnvironment": "node"
93
93
  },
94
- "version": "v2.23.0"
94
+ "version": "v2.24.0"
95
95
  }