Skip to content

Commit

Permalink
feat: bng and rules refactor (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongaar committed May 13, 2023
1 parent ffbaa78 commit dca51b6
Show file tree
Hide file tree
Showing 39 changed files with 1,285 additions and 422 deletions.
14 changes: 7 additions & 7 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

| Filename | line # | TODO |
| :---------------------------------------------------------------------------------------------- | :----: | :-------------------------------------------------------------------- |
| [packages/mrb2023/src/index.ts](packages/mrb2023/src/index.ts#L76) | 76 | |
| [packages/mrb2023/src/index.ts](packages/mrb2023/src/index.ts#L77) | 77 | |
| [packages/mrb2023/tests/kampeerauto.test.ts](packages/mrb2023/tests/kampeerauto.test.ts#L49) | 49 | we receive 52 while the baseline gives 65. not sure what is wrong |
| [packages/mrb2023/tests/kampeerauto.test.ts](packages/mrb2023/tests/kampeerauto.test.ts#L81) | 81 | this scenario is not covered in baseline calculator |
| [packages/mrb2023/tests/kampeerauto.test.ts](packages/mrb2023/tests/kampeerauto.test.ts#L88) | 88 | this scenario is not covered in baseline calculator |
| [packages/mrb2023/tests/personenauto.test.ts](packages/mrb2023/tests/personenauto.test.ts#L45) | 45 | indien niet woonachtig in nederland, worden opcenten niet meegerekend |
| [packages/mrb2023/tests/personenauto.test.ts](packages/mrb2023/tests/personenauto.test.ts#L102) | 102 | we receive 1978 while the baseline gives 1977. not sure what is wrong |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L172) | 172 | is this correct? |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L202) | 202 | add 115R-installatie |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L247) | 247 | this should be moved to mrb{revision} as it could change yoy |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L255) | 255 | De bestelauto moet minimaal 12 jaar oud zijn bij het begin van het |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L272) | 272 | bij het motorrijtuig vermeld staat dat het affabriek roetfilter |
| [packages/rdw/types/index.d.ts](packages/rdw/types/index.d.ts#L148) | 148 | this should be moved to mrb{revision} as it could change yoy |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L174) | 174 | is this correct? |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L206) | 206 | add 115R-installatie |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L271) | 271 | this should be moved to mrb{revision} as it could change yoy |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L279) | 279 | De bestelauto moet minimaal 12 jaar oud zijn bij het begin van het |
| [packages/rdw/src/index.ts](packages/rdw/src/index.ts#L296) | 296 | bij het motorrijtuig vermeld staat dat het affabriek roetfilter |
| [packages/rdw/types/index.d.ts](packages/rdw/types/index.d.ts#L151) | 151 | this should be moved to mrb{revision} as it could change yoy |
7 changes: 0 additions & 7 deletions packages/betalennaargebruik/src/index.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@motorrijtuigenbelasting/betalennaargebruik",
"name": "@motorrijtuigenbelasting/bng2030",
"version": "3.1.0",
"repository": "github:hongaar/motorrijtuigenbelasting",
"license": "MIT",
Expand All @@ -20,7 +20,8 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@motorrijtuigenbelasting/core": "workspace:*"
"@motorrijtuigenbelasting/core": "workspace:*",
"@motorrijtuigenbelasting/mrb2023": "workspace:*"
},
"devDependencies": {
"@types/jest": "29.5.1",
Expand Down
83 changes: 83 additions & 0 deletions packages/bng2030/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
BngVariant,
InvalidArgument,
NotImplementedError,
VehicleType,
validateBngVariant,
validateMileage,
validatePropulsions,
type Model,
type ModelOutput,
} from "@motorrijtuigenbelasting/core";
import {
V1a,
V1a_alt1,
V1a_alt2,
V1b,
V2,
V2_alt1,
V2_alt2,
V3,
} from "./rules/index.js";

const model: Model = (params) => {
const { propulsions, mileage, vehicleType, bngVariant } = params;
const output: ModelOutput = [];

validateBngVariant(bngVariant);
validateMileage(mileage);
validatePropulsions(propulsions);

switch (vehicleType) {
case VehicleType.Personenauto:
case VehicleType["Bestelauto gehandicapte"]:
case VehicleType["Bestelauto particulier"]:
case VehicleType["Bestelauto ondernemer"]:
break;
default:
throw new NotImplementedError(
"BNG is only available for Personenauto en Bestelauto"
);
}

switch (params.bngVariant) {
case BngVariant.V1a:
V1a(output, params);
break;

case BngVariant.V1b:
V1b(output, params);
break;

case BngVariant.V1a_alt1:
V1a_alt1(output, params);
break;

case BngVariant.V1a_alt2:
V1a_alt2(output, params);
break;

case BngVariant.V2:
V2(output, params);
break;

case BngVariant.V2_alt1:
V2_alt1(output, params);
break;

case BngVariant.V2_alt2:
V2_alt2(output, params);
break;

case BngVariant.V3:
V3(output, params);
break;

default:
throw new InvalidArgument("bngVariant has an invalid value");
}

return output;
};

export default model;
194 changes: 194 additions & 0 deletions packages/bng2030/src/rates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import { PropulsionType, VehicleType } from "@motorrijtuigenbelasting/core";
import type { Rate } from "@motorrijtuigenbelasting/mrb1995";

type RateMap = Record<VehicleType, Record<PropulsionType, Rate[]>>;

/**
* Varianten voor tariefstructuur Betalen naar Gebruik
* https://www.rijksoverheid.nl/documenten/rapporten/2022/10/27/varianten-voor-tariefstructuur-betalen-naar-gebruik
*/
export const rateMap_V2 = {
[VehicleType.Personenauto]: {
[PropulsionType.Benzine]: [
{
threshold: 0,
fixedAmount: 0.027,
},
{
threshold: 950,
fixedAmount: 0.047,
},
{
threshold: 1150,
fixedAmount: 0.065,
},
{
threshold: 1350,
fixedAmount: 0.083,
},
{
threshold: 1550,
fixedAmount: 0.109,
},
],
[PropulsionType.Diesel]: [
{
threshold: 0,
fixedAmount: 0.068,
},
{
threshold: 950,
fixedAmount: 0.078,
},
{
threshold: 1150,
fixedAmount: 0.089,
},
{
threshold: 1350,
fixedAmount: 0.098,
},
{
threshold: 1550,
fixedAmount: 0.117,
},
],
[PropulsionType.Hybride]: [
{
threshold: 0,
fixedAmount: 0.029,
},
{
threshold: 950,
fixedAmount: 0.048,
},
{
threshold: 1150,
fixedAmount: 0.066,
},
{
threshold: 1350,
fixedAmount: 0.084,
},
{
threshold: 1550,
fixedAmount: 0.12,
},
],
[PropulsionType.Elektrisch]: [
{
threshold: 0,
fixedAmount: 0.03,
},
{
threshold: 950,
fixedAmount: 0.046,
},
{
threshold: 1150,
fixedAmount: 0.063,
},
{
threshold: 1350,
fixedAmount: 0.08,
},
{
threshold: 1550,
fixedAmount: 0.113,
},
],
},
} as RateMap;

export const rateMap_V2_alt1 = {
[VehicleType.Personenauto]: {
[PropulsionType.Benzine]: [
{
threshold: 0,
fixedAmount: 0.029,
},
{
threshold: 950,
fixedAmount: 0.048,
},
{
threshold: 1150,
fixedAmount: 0.065,
},
{
threshold: 1350,
fixedAmount: 0.082,
},
{
threshold: 1550,
fixedAmount: 0.107,
},
],
[PropulsionType.Diesel]: [
{
threshold: 0,
fixedAmount: 0.06,
},
{
threshold: 950,
fixedAmount: 0.067,
},
{
threshold: 1150,
fixedAmount: 0.082,
},
{
threshold: 1350,
fixedAmount: 0.098,
},
{
threshold: 1550,
fixedAmount: 0.129,
},
],
[PropulsionType.Hybride]: [
{
threshold: 0,
fixedAmount: 0.015,
},
{
threshold: 950,
fixedAmount: 0.015,
},
{
threshold: 1150,
fixedAmount: 0.018,
},
{
threshold: 1350,
fixedAmount: 0.027,
},
{
threshold: 1550,
fixedAmount: 0.061,
},
],
[PropulsionType.Elektrisch]: [
{
threshold: 0,
fixedAmount: 0.014,
},
{
threshold: 950,
fixedAmount: 0.017,
},
{
threshold: 1150,
fixedAmount: 0.025,
},
{
threshold: 1350,
fixedAmount: 0.039,
},
{
threshold: 1550,
fixedAmount: 0.071,
},
],
},
} as RateMap;
24 changes: 24 additions & 0 deletions packages/bng2030/src/rules/V1a.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
VehicleType,
validateBngVariant,
type ModelOutput,
type Params,
} from "@motorrijtuigenbelasting/core";
import { kmRateComponent } from "./utils.js";

export function V1a(output: ModelOutput, params: Params) {
/**
* de mrb en de provinciale opcenten worden gevariabiliseerd en
* budgetneutraal omgezet in een kilometertarief gelijk voor alle
* personenauto’s en een tarief gelijk voor alle bestelauto’s.
*/
const { vehicleType, bngVariant } = params;

validateBngVariant(bngVariant);

const kmRate = kmRateComponent(bngVariant);

output.push(
kmRate(vehicleType === VehicleType.Personenauto ? 0.0682 : 0.0416)
);
}
24 changes: 24 additions & 0 deletions packages/bng2030/src/rules/V1a_alt1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
VehicleType,
validateBngVariant,
type ModelOutput,
type Params,
} from "@motorrijtuigenbelasting/core";
import { kmRateComponent } from "./utils.js";

export function V1a_alt1(output: ModelOutput, params: Params) {
/**
* gelijk aan variant V1a maar het tarief is dusdanig verhoogd dat in 2030
* 2,5 Mton reductie aan CO2 resulteert t.o.v. de basispad. Er is dan geen
* sprake meer van budgetneutraliteit.
*/
const { vehicleType, bngVariant } = params;

validateBngVariant(bngVariant);

const kmRate = kmRateComponent(bngVariant);

output.push(
kmRate(vehicleType === VehicleType.Personenauto ? 0.1086 : 0.078)
);
}
Loading

0 comments on commit dca51b6

Please sign in to comment.