onroute-policy-engine 2.23.0 → 2.24.1
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/dist/constants/cost.d.ts +8 -0
- package/dist/constants/cost.js +11 -0
- package/dist/constants/overload.d.ts +9 -0
- package/dist/constants/overload.js +38 -0
- package/dist/constants/stgvwi.d.ts +0 -5
- package/dist/constants/stgvwi.js +1 -6
- package/dist/enum/facts.d.ts +2 -1
- package/dist/enum/facts.js +2 -1
- package/dist/enum/validation-result-code.d.ts +1 -0
- package/dist/enum/validation-result-code.js +1 -0
- package/dist/helper/date.helper.d.ts +28 -0
- package/dist/helper/date.helper.js +51 -0
- package/dist/helper/date.helper.spec.d.ts +1 -0
- package/dist/helper/date.helper.spec.js +26 -0
- package/dist/helper/facts.helper.js +47 -63
- package/dist/helper/rules-engine.helper.js +2 -1
- package/dist/policy-engine.js +17 -5
- package/dist/rule-operator/custom-operators.js +3 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -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;
|
package/dist/constants/stgvwi.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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;
|
package/dist/enum/facts.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare enum CostFacts {
|
|
|
17
17
|
CostPerKilometre = "costPerKilometre",
|
|
18
18
|
CostPerMonth = "costPerMonth",
|
|
19
19
|
FixedCost = "fixedCost",
|
|
20
|
-
|
|
20
|
+
OverloadGvwCost = "overloadGvwCost",
|
|
21
|
+
OverloadWeightCost = "overloadWeightCost",
|
|
21
22
|
RangeMatrixCostLookup = "rangeMatrixCostLookup"
|
|
22
23
|
}
|
package/dist/enum/facts.js
CHANGED
|
@@ -22,6 +22,7 @@ var CostFacts;
|
|
|
22
22
|
CostFacts["CostPerKilometre"] = "costPerKilometre";
|
|
23
23
|
CostFacts["CostPerMonth"] = "costPerMonth";
|
|
24
24
|
CostFacts["FixedCost"] = "fixedCost";
|
|
25
|
-
CostFacts["
|
|
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";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Dayjs } from 'dayjs';
|
|
2
|
+
export declare const TIMEZONE_IDS: {
|
|
3
|
+
PACIFIC: string;
|
|
4
|
+
};
|
|
5
|
+
export declare const DATE_FORMATS: {
|
|
6
|
+
DATE_ONLY: string;
|
|
7
|
+
DATETIME: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Convert a datetime to a specified timezone.
|
|
11
|
+
*
|
|
12
|
+
* @param datetime Datetime to be converted
|
|
13
|
+
* @param timezoneId Timezone identifier (eg. 'Canada/Pacific')
|
|
14
|
+
* @returns Dayjs object in the specified timezone
|
|
15
|
+
*/
|
|
16
|
+
export declare const convertToTimezone: (datetime: string | Dayjs | Date, timezoneId: string) => Dayjs;
|
|
17
|
+
/**
|
|
18
|
+
* Get UTC datetime.
|
|
19
|
+
*
|
|
20
|
+
* @returns Dayjs object representing datetime in UTC
|
|
21
|
+
*/
|
|
22
|
+
export declare const getUtcDatetime: (datetime?: Dayjs | Date | string) => Dayjs;
|
|
23
|
+
/**
|
|
24
|
+
* Get datetime representing the end of the quarter for a given datetime.
|
|
25
|
+
* @param datetime Datetime being used for reference
|
|
26
|
+
* @returns Dayjs object representing the end of the quarter for the inputted datetime
|
|
27
|
+
*/
|
|
28
|
+
export declare const getEndOfQuarter: (datetime: Dayjs) => Dayjs;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getEndOfQuarter = exports.getUtcDatetime = exports.convertToTimezone = exports.DATE_FORMATS = exports.TIMEZONE_IDS = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
9
|
+
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
10
|
+
const duration_1 = __importDefault(require("dayjs/plugin/duration"));
|
|
11
|
+
const quarterOfYear_1 = __importDefault(require("dayjs/plugin/quarterOfYear"));
|
|
12
|
+
dayjs_1.default.extend(utc_1.default);
|
|
13
|
+
dayjs_1.default.extend(timezone_1.default);
|
|
14
|
+
dayjs_1.default.extend(duration_1.default);
|
|
15
|
+
dayjs_1.default.extend(quarterOfYear_1.default);
|
|
16
|
+
exports.TIMEZONE_IDS = {
|
|
17
|
+
PACIFIC: 'Canada/Pacific',
|
|
18
|
+
};
|
|
19
|
+
exports.DATE_FORMATS = {
|
|
20
|
+
DATE_ONLY: 'YYYY-MM-DD',
|
|
21
|
+
DATETIME: 'YYYY-MM-DD HH:mm:ss',
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Convert a datetime to a specified timezone.
|
|
25
|
+
*
|
|
26
|
+
* @param datetime Datetime to be converted
|
|
27
|
+
* @param timezoneId Timezone identifier (eg. 'Canada/Pacific')
|
|
28
|
+
* @returns Dayjs object in the specified timezone
|
|
29
|
+
*/
|
|
30
|
+
const convertToTimezone = (datetime, timezoneId) => {
|
|
31
|
+
return dayjs_1.default.tz(datetime, timezoneId);
|
|
32
|
+
};
|
|
33
|
+
exports.convertToTimezone = convertToTimezone;
|
|
34
|
+
/**
|
|
35
|
+
* Get UTC datetime.
|
|
36
|
+
*
|
|
37
|
+
* @returns Dayjs object representing datetime in UTC
|
|
38
|
+
*/
|
|
39
|
+
const getUtcDatetime = (datetime) => {
|
|
40
|
+
return dayjs_1.default.utc(datetime);
|
|
41
|
+
};
|
|
42
|
+
exports.getUtcDatetime = getUtcDatetime;
|
|
43
|
+
/**
|
|
44
|
+
* Get datetime representing the end of the quarter for a given datetime.
|
|
45
|
+
* @param datetime Datetime being used for reference
|
|
46
|
+
* @returns Dayjs object representing the end of the quarter for the inputted datetime
|
|
47
|
+
*/
|
|
48
|
+
const getEndOfQuarter = (datetime) => {
|
|
49
|
+
return datetime.endOf('quarter');
|
|
50
|
+
};
|
|
51
|
+
exports.getEndOfQuarter = getEndOfQuarter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const date_helper_1 = require("./date.helper");
|
|
4
|
+
describe('Date Helper Tests', () => {
|
|
5
|
+
it('should have correct local datetime components when converting datetime string', () => {
|
|
6
|
+
const localDtStr = '2026-08-10';
|
|
7
|
+
const localTzId = date_helper_1.TIMEZONE_IDS.PACIFIC;
|
|
8
|
+
const localDt = (0, date_helper_1.convertToTimezone)(localDtStr, localTzId);
|
|
9
|
+
expect(localDt.year()).toBe(2026);
|
|
10
|
+
expect(localDt.month()).toBe(7);
|
|
11
|
+
expect(localDt.date()).toBe(10);
|
|
12
|
+
expect(localDt.hour()).toBe(0);
|
|
13
|
+
expect(localDt.minute()).toBe(0);
|
|
14
|
+
expect(localDt.second()).toBe(0);
|
|
15
|
+
});
|
|
16
|
+
it('should have correct local datetime components when converting UTC datetime', () => {
|
|
17
|
+
const utcDtStr = '2026-08-10 22:00:00';
|
|
18
|
+
const utcDt = (0, date_helper_1.getUtcDatetime)(utcDtStr);
|
|
19
|
+
const localTzId = date_helper_1.TIMEZONE_IDS.PACIFIC;
|
|
20
|
+
const localConvertedDt = (0, date_helper_1.convertToTimezone)(utcDt, localTzId);
|
|
21
|
+
expect(utcDt.hour()).toBe(22);
|
|
22
|
+
expect(localConvertedDt.hour()).toBe(15);
|
|
23
|
+
expect(localConvertedDt.date()).toBe(utcDt.date());
|
|
24
|
+
expect(utcDt.diff(localConvertedDt)).toBe(0);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.addRuntimeFacts = addRuntimeFacts;
|
|
7
|
-
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
-
const quarterOfYear_1 = __importDefault(require("dayjs/plugin/quarterOfYear"));
|
|
9
4
|
const enum_1 = require("onroute-policy-engine/enum");
|
|
10
5
|
const policy_check_helper_1 = require("./policy-check.helper");
|
|
11
6
|
const stgvwi_1 = require("../constants/stgvwi");
|
|
12
|
-
|
|
7
|
+
const overload_1 = require("../constants/overload");
|
|
8
|
+
const date_helper_1 = require("./date.helper");
|
|
13
9
|
const getAxleCalculationInputs = async (policy, almanac) => {
|
|
14
10
|
var _a, _b;
|
|
15
11
|
const vehicleDetails = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.VehicleDetails);
|
|
@@ -28,13 +24,38 @@ const getAxleCalculationInputs = async (policy, almanac) => {
|
|
|
28
24
|
licensedGVW: vehicleDetails.licensedGVW || 0,
|
|
29
25
|
};
|
|
30
26
|
};
|
|
27
|
+
const getOverloadCost = (overloadKg, totalDistance) => {
|
|
28
|
+
let ratePer10km = 0;
|
|
29
|
+
if (overloadKg <= overload_1.BASE_OVERLOAD_LIMIT) {
|
|
30
|
+
const match = overload_1.OVERLOAD_RATES_PER_10KM.find((r) => overloadKg <= r.max);
|
|
31
|
+
ratePer10km = match ? match.rate : overload_1.DEFAULT_MAX_RATE;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// For overload greater than BASE_OVERLOAD_LIMIT kg
|
|
35
|
+
const extraWeight = overloadKg - overload_1.BASE_OVERLOAD_LIMIT;
|
|
36
|
+
const intervals = Math.ceil(extraWeight / overload_1.EXTRA_WEIGHT_INTERVAL);
|
|
37
|
+
ratePer10km = overload_1.DEFAULT_MAX_RATE + intervals * overload_1.EXTRA_RATE_INCREMENT;
|
|
38
|
+
}
|
|
39
|
+
// Fee calculation: rate * (totalDistance / 10)
|
|
40
|
+
const distanceUnits = Math.ceil(totalDistance / 10);
|
|
41
|
+
let totalFee = ratePer10km * distanceUnits;
|
|
42
|
+
// Apply minimum fee rule
|
|
43
|
+
if (totalFee < overload_1.MINIMUM_OVERLOAD_FEE) {
|
|
44
|
+
totalFee = overload_1.MINIMUM_OVERLOAD_FEE;
|
|
45
|
+
}
|
|
46
|
+
// Round to the nearest dollar (0.50 rounds up)
|
|
47
|
+
return Math.round(totalFee);
|
|
48
|
+
};
|
|
31
49
|
/**
|
|
32
50
|
* Adds runtime facts for the validation. For example, adds the
|
|
33
51
|
* validation date for comparison against startDate of the permit.
|
|
34
52
|
* @param engine json-rules-engine Engine instance to add facts to.
|
|
35
53
|
*/
|
|
36
54
|
function addRuntimeFacts(engine, policy) {
|
|
37
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Add runtime fact for today's date (based on Pacific timezone)
|
|
57
|
+
*/
|
|
58
|
+
const today = (0, date_helper_1.convertToTimezone)((0, date_helper_1.getUtcDatetime)(), date_helper_1.TIMEZONE_IDS.PACIFIC).format(enum_1.PermitAppInfo.PermitDateFormat);
|
|
38
59
|
engine.addFact(enum_1.PolicyFacts.ValidationDate, today);
|
|
39
60
|
/**
|
|
40
61
|
* Add runtime fact for number of days in the permit year.
|
|
@@ -43,7 +64,7 @@ function addRuntimeFacts(engine, policy) {
|
|
|
43
64
|
*/
|
|
44
65
|
engine.addFact(enum_1.PolicyFacts.DaysInPermitYear, async function (params, almanac) {
|
|
45
66
|
const startDate = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PermitStartDate);
|
|
46
|
-
const dateFrom = (0,
|
|
67
|
+
const dateFrom = (0, date_helper_1.convertToTimezone)(startDate, date_helper_1.TIMEZONE_IDS.PACIFIC);
|
|
47
68
|
const daysInPermitYear = dateFrom.add(1, 'year').diff(dateFrom, 'day');
|
|
48
69
|
return daysInPermitYear;
|
|
49
70
|
});
|
|
@@ -54,8 +75,8 @@ function addRuntimeFacts(engine, policy) {
|
|
|
54
75
|
*/
|
|
55
76
|
engine.addFact(enum_1.PolicyFacts.EndOfPermitQuarter, async function (params, almanac) {
|
|
56
77
|
const startDate = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PermitStartDate);
|
|
57
|
-
const dateFrom = (0,
|
|
58
|
-
const endOfQuarter =
|
|
78
|
+
const dateFrom = (0, date_helper_1.convertToTimezone)(startDate, date_helper_1.TIMEZONE_IDS.PACIFIC);
|
|
79
|
+
const endOfQuarter = (0, date_helper_1.getEndOfQuarter)(dateFrom);
|
|
59
80
|
return endOfQuarter.format(enum_1.PermitAppInfo.PermitDateFormat);
|
|
60
81
|
});
|
|
61
82
|
/**
|
|
@@ -65,7 +86,7 @@ function addRuntimeFacts(engine, policy) {
|
|
|
65
86
|
*/
|
|
66
87
|
engine.addFact(enum_1.PolicyFacts.EndOfPermitYear, async function (params, almanac) {
|
|
67
88
|
const startDate = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.PermitStartDate);
|
|
68
|
-
const dateFrom = (0,
|
|
89
|
+
const dateFrom = (0, date_helper_1.convertToTimezone)(startDate, date_helper_1.TIMEZONE_IDS.PACIFIC);
|
|
69
90
|
const endOfYear = dateFrom
|
|
70
91
|
.endOf('year')
|
|
71
92
|
.format(enum_1.PermitAppInfo.PermitDateFormat);
|
|
@@ -186,8 +207,8 @@ function addRuntimeFacts(engine, policy) {
|
|
|
186
207
|
engine.addFact(enum_1.PolicyFacts.DaysBetween.toString(), async function (params, almanac) {
|
|
187
208
|
const dateFromStr = await almanac.factValue(params.dateFrom.fact, {}, params.dateFrom.path);
|
|
188
209
|
const dateToStr = await almanac.factValue(params.dateTo.fact, {}, params.dateTo.path);
|
|
189
|
-
const dateFrom = (0,
|
|
190
|
-
const dateTo = (0,
|
|
210
|
+
const dateFrom = (0, date_helper_1.convertToTimezone)(dateFromStr, date_helper_1.TIMEZONE_IDS.PACIFIC);
|
|
211
|
+
const dateTo = (0, date_helper_1.convertToTimezone)(dateToStr, date_helper_1.TIMEZONE_IDS.PACIFIC);
|
|
191
212
|
const daysBetween = dateTo.diff(dateFrom, 'day');
|
|
192
213
|
return daysBetween;
|
|
193
214
|
});
|
|
@@ -308,7 +329,7 @@ function addRuntimeFacts(engine, policy) {
|
|
|
308
329
|
* Add runtime fact to calculate the overload fee for STGVWI permits
|
|
309
330
|
* based on the Licensed GVW Increase and Total Distance.
|
|
310
331
|
*/
|
|
311
|
-
engine.addFact(enum_1.CostFacts.
|
|
332
|
+
engine.addFact(enum_1.CostFacts.OverloadGvwCost.toString(), async function (params, almanac) {
|
|
312
333
|
const actualGVW = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, 'vehicleConfiguration.actualGVW');
|
|
313
334
|
const licensedGVW = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, 'vehicleDetails.licensedGVW');
|
|
314
335
|
const distance = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TotalDistance);
|
|
@@ -316,55 +337,18 @@ function addRuntimeFacts(engine, policy) {
|
|
|
316
337
|
if (overloadKg <= 0 || !distance) {
|
|
317
338
|
return 0;
|
|
318
339
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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;
|
|
340
|
+
return getOverloadCost(overloadKg, distance);
|
|
341
|
+
});
|
|
342
|
+
/**
|
|
343
|
+
* Add runtime fact to calculate the overload fee for STWSE permits
|
|
344
|
+
* based on the Weight over 27.5m and Total Distance.
|
|
345
|
+
*/
|
|
346
|
+
engine.addFact(enum_1.CostFacts.OverloadWeightCost.toString(), async function (params, almanac) {
|
|
347
|
+
const overloadWeight = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, 'vehicleConfiguration.overloadWeight');
|
|
348
|
+
const totalDistance = await almanac.factValue(enum_1.PermitAppInfo.PermitData, {}, enum_1.PermitAppInfo.TotalDistance);
|
|
349
|
+
if (overloadWeight <= 0 || !totalDistance) {
|
|
350
|
+
return 0;
|
|
366
351
|
}
|
|
367
|
-
|
|
368
|
-
return Math.round(totalFee);
|
|
352
|
+
return getOverloadCost(overloadWeight, totalDistance);
|
|
369
353
|
});
|
|
370
354
|
}
|
|
@@ -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:
|
|
55
|
+
message: c.params.description || cost_1.DEFAULT_COST_DESCRIPTION,
|
|
55
56
|
code: 'cost-value',
|
|
56
57
|
cost: c,
|
|
57
58
|
},
|
package/dist/policy-engine.js
CHANGED
|
@@ -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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
}
|
|
@@ -14,6 +14,7 @@ exports.CustomOperators = void 0;
|
|
|
14
14
|
const json_rules_engine_1 = require("json-rules-engine");
|
|
15
15
|
const enum_1 = require("onroute-policy-engine/enum");
|
|
16
16
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
17
|
+
const date_helper_1 = require("../helper/date.helper");
|
|
17
18
|
/**
|
|
18
19
|
* Validates that the input is a string type
|
|
19
20
|
* @param a - The value to validate
|
|
@@ -63,8 +64,8 @@ CustomOperators.push(new json_rules_engine_1.Operator(enum_1.CustomOperator.Stri
|
|
|
63
64
|
*/
|
|
64
65
|
CustomOperators.push(new json_rules_engine_1.Operator(enum_1.CustomOperator.DateLessThan, (a, b) => {
|
|
65
66
|
// Parse both dates using the permit application date format
|
|
66
|
-
const firstDate = (0,
|
|
67
|
-
const secondDate = (0,
|
|
67
|
+
const firstDate = (0, date_helper_1.convertToTimezone)(a, date_helper_1.TIMEZONE_IDS.PACIFIC);
|
|
68
|
+
const secondDate = (0, date_helper_1.convertToTimezone)(b, date_helper_1.TIMEZONE_IDS.PACIFIC);
|
|
68
69
|
// Return true if first date is before second date (difference is negative)
|
|
69
70
|
return firstDate.diff(secondDate) < 0;
|
|
70
71
|
}, dateStringValidator));
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "v2.
|
|
1
|
+
export declare const version = "v2.24.1";
|
package/dist/version.js
CHANGED
package/package.json
CHANGED